Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
bigrect.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"

Go to the source code of this file.

Functions

static void draw_big_rect (SkCanvas *canvas, SkScalar big, const SkPaint &rectPaint)
 
 DEF_SIMPLE_GM (bigrect, canvas, 325, 125)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( bigrect  ,
canvas  ,
325  ,
125   
)

Definition at line 74 of file bigrect.cpp.

74 {
75 // Test with sizes:
76 // - reasonable size (for comparison),
77 // - outside the range of int32, and
78 // - outside the range of SkFixed.
79 static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
80
81 for (int i = 0; i < 8; i++) {
82 for (int j = 0; j < 3; j++) {
83 canvas->save();
84 canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
85
87 paint.setColor(SK_ColorBLUE);
88 // These are the three parameters that affect the behavior of SkDraw::drawRect.
89 if (i & 1) {
91 } else {
93 }
94 if (i & 2) {
95 paint.setStrokeWidth(1);
96 } else {
97 paint.setStrokeWidth(0);
98 }
99 if (i & 4) {
100 paint.setAntiAlias(true);
101 } else {
102 paint.setAntiAlias(false);
103 }
104
105 draw_big_rect(canvas, sizes[j], paint);
106 canvas->restore();
107 }
108 }
109}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
#define SkIntToScalar(x)
Definition SkScalar.h:57
static void draw_big_rect(SkCanvas *canvas, SkScalar big, const SkPaint &rectPaint)
Definition bigrect.cpp:16
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const Paint & paint
float SkScalar
Definition extension.cpp:12

◆ draw_big_rect()

static void draw_big_rect ( SkCanvas canvas,
SkScalar  big,
const SkPaint rectPaint 
)
static

Definition at line 16 of file bigrect.cpp.

16 {
17 // Looks like this:
18 // +--+-+----+-+----+
19 // | | | | | |
20 // |--+-+----+-+----+
21 // |--+-+----+-+----+
22 // | | | | | |
23 // | | | +-+ |
24 // +--+-+--+ +--+
25 // +--+-+--+ +--+
26 // | | | +-+ |
27 // | | | | | |
28 // +--+-+----+-+----+
29
30 canvas->clipRect({0, 0, 35, 35});
31
32 // Align to pixel boundaries.
33 canvas->translate(0.5, 0.5);
34
35 SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10);
36 canvas->drawRect(horiz, rectPaint);
37
38 SkRect vert = SkRect::MakeLTRB(5, -big, 10, big);
39 canvas->drawRect(vert, rectPaint);
40
41 SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25);
42 canvas->drawRect(fromLeft, rectPaint);
43
44 SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17);
45 canvas->drawRect(fromTop, rectPaint);
46
47 SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25);
48 canvas->drawRect(fromRight, rectPaint);
49
50 SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big);
51 canvas->drawRect(fromBottom, rectPaint);
52
53 SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
54 canvas->drawRect(leftBorder, rectPaint);
55
56 SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
57 canvas->drawRect(topBorder, rectPaint);
58
59 SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
60 canvas->drawRect(rightBorder, rectPaint);
61
62 SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
63 canvas->drawRect(bottomBorder, rectPaint);
64
65 SkPaint outOfBoundsPaint;
66 outOfBoundsPaint.setColor(SK_ColorRED);
67 outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
68 outOfBoundsPaint.setStrokeWidth(0);
69
70 SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
71 canvas->drawRect(outOfBounds, outOfBoundsPaint);
72}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void translate(SkScalar dx, SkScalar dy)
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setStrokeWidth(SkScalar width)
Definition SkPaint.cpp:159
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646