Flutter Engine
The Flutter Engine
Functions | Variables
overstroke.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/SkPathBuilder.h"
#include "include/core/SkPathMeasure.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "src/core/SkPointPriv.h"
#include <cstddef>

Go to the source code of this file.

Functions

SkPaint make_normal_paint ()
 
SkPaint make_overstroke_paint ()
 
SkPath quad_path ()
 
SkPath cubic_path ()
 
SkPath oval_path ()
 
SkPath ribs_path (SkPath path, SkScalar radius)
 
void draw_ribs (SkCanvas *canvas, SkPath path)
 
void draw_small_quad (SkCanvas *canvas)
 
void draw_large_quad (SkCanvas *canvas)
 
void draw_quad_fillpath (SkCanvas *canvas)
 
void draw_stroked_quad (SkCanvas *canvas)
 
void draw_small_cubic (SkCanvas *canvas)
 
void draw_large_cubic (SkCanvas *canvas)
 
void draw_cubic_fillpath (SkCanvas *canvas)
 
void draw_stroked_cubic (SkCanvas *canvas)
 
void draw_small_oval (SkCanvas *canvas)
 
void draw_large_oval (SkCanvas *canvas)
 
void draw_oval_fillpath (SkCanvas *canvas)
 
void draw_stroked_oval (SkCanvas *canvas)
 
 DEF_SIMPLE_GM (OverStroke, canvas, 500, 500)
 

Variables

const SkScalar OVERSTROKE_WIDTH = 500.0f
 
const SkScalar NORMALSTROKE_WIDTH = 3.0f
 
void(* examples [])(SkCanvas *canvas)
 

Function Documentation

◆ cubic_path()

SkPath cubic_path ( )

Definition at line 68 of file overstroke.cpp.

68 {
70 path.moveTo(0, 0);
71 path.cubicTo(25, 75,
72 75, -50,
73 100, 0);
74
75 return path;
76}
Definition: SkPath.h:59
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( OverStroke  ,
canvas  ,
500  ,
500   
)

Definition at line 240 of file overstroke.cpp.

240 {
241 const size_t length = sizeof(examples) / sizeof(examples[0]);
242 const size_t width = 2;
243
244 for (size_t i = 0; i < length; i++) {
245 int x = (int)(i % width);
246 int y = (int)(i / width);
247
248 canvas->save();
249 canvas->translate(150.0f * x, 150.0f * y);
250 canvas->scale(0.2f, 0.2f);
251 canvas->translate(300.0f, 400.0f);
252
253 examples[i](canvas);
254
255 canvas->restore();
256 }
257}
size_t length
double y
double x
void(* examples[])(SkCanvas *canvas)
Definition: overstroke.cpp:235
int32_t width

◆ draw_cubic_fillpath()

void draw_cubic_fillpath ( SkCanvas canvas)

Definition at line 176 of file overstroke.cpp.

176 {
179
180 SkPaint fillp = make_normal_paint();
182
183 SkPath fillpath;
185
186 canvas->drawPath(fillpath, fillp);
187}
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void setColor(SkColor color)
Definition: SkPaint.cpp:119
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23
SkPaint make_normal_paint()
Definition: overstroke.cpp:41
SkPath cubic_path()
Definition: overstroke.cpp:68
SkPaint make_overstroke_paint()
Definition: overstroke.cpp:51

◆ draw_large_cubic()

void draw_large_cubic ( SkCanvas canvas)

Definition at line 168 of file overstroke.cpp.

168 {
171
172 canvas->drawPath(path, p);
173 draw_ribs(canvas, path);
174}
void draw_ribs(SkCanvas *canvas, SkPath path)
Definition: overstroke.cpp:108

◆ draw_large_oval()

void draw_large_oval ( SkCanvas canvas)

Definition at line 206 of file overstroke.cpp.

206 {
209
210 canvas->drawPath(path, p);
211 draw_ribs(canvas, path);
212}
SkPath oval_path()
Definition: overstroke.cpp:78

◆ draw_large_quad()

void draw_large_quad ( SkCanvas canvas)

Definition at line 131 of file overstroke.cpp.

131 {
134
135 canvas->drawPath(path, p);
136 draw_ribs(canvas, path);
137}
SkPath quad_path()
Definition: overstroke.cpp:60

◆ draw_oval_fillpath()

void draw_oval_fillpath ( SkCanvas canvas)

Definition at line 214 of file overstroke.cpp.

214 {
217
218 SkPaint fillp = make_normal_paint();
220
221 SkPath fillpath;
223
224 canvas->drawPath(fillpath, fillp);
225}

◆ draw_quad_fillpath()

void draw_quad_fillpath ( SkCanvas canvas)

Definition at line 139 of file overstroke.cpp.

139 {
142
143 SkPaint fillp = make_normal_paint();
145
146 SkPath fillpath;
148
149 canvas->drawPath(fillpath, fillp);
150}

◆ draw_ribs()

void draw_ribs ( SkCanvas canvas,
SkPath  path 
)

Definition at line 108 of file overstroke.cpp.

108 {
111 p.setStrokeWidth(1);
112 p.setColor(SK_ColorBLUE);
113 p.setColor(SK_ColorGREEN);
114
115 canvas->drawPath(ribs, p);
116}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
const SkScalar OVERSTROKE_WIDTH
Definition: overstroke.cpp:36
SkPath ribs_path(SkPath path, SkScalar radius)
Definition: overstroke.cpp:84

◆ draw_small_cubic()

void draw_small_cubic ( SkCanvas canvas)

Definition at line 160 of file overstroke.cpp.

160 {
163
164 draw_ribs(canvas, path);
165 canvas->drawPath(path, p);
166}

◆ draw_small_oval()

void draw_small_oval ( SkCanvas canvas)

Definition at line 197 of file overstroke.cpp.

197 {
199
201
202 draw_ribs(canvas, path);
203 canvas->drawPath(path, p);
204}

◆ draw_small_quad()

void draw_small_quad ( SkCanvas canvas)

Definition at line 120 of file overstroke.cpp.

120 {
121 // scaled so it's visible
122 // canvas->scale(8, 8);
123
126
127 draw_ribs(canvas, path);
128 canvas->drawPath(path, p);
129}

◆ draw_stroked_cubic()

void draw_stroked_cubic ( SkCanvas canvas)

Definition at line 189 of file overstroke.cpp.

189 {
190 canvas->translate(400, 0);
191 draw_large_cubic(canvas);
192 draw_cubic_fillpath(canvas);
193}
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void draw_large_cubic(SkCanvas *canvas)
Definition: overstroke.cpp:168
void draw_cubic_fillpath(SkCanvas *canvas)
Definition: overstroke.cpp:176

◆ draw_stroked_oval()

void draw_stroked_oval ( SkCanvas canvas)

Definition at line 227 of file overstroke.cpp.

227 {
228 canvas->translate(400, 0);
229 draw_large_oval(canvas);
230 draw_oval_fillpath(canvas);
231}
void draw_oval_fillpath(SkCanvas *canvas)
Definition: overstroke.cpp:214
void draw_large_oval(SkCanvas *canvas)
Definition: overstroke.cpp:206

◆ draw_stroked_quad()

void draw_stroked_quad ( SkCanvas canvas)

Definition at line 152 of file overstroke.cpp.

152 {
153 canvas->translate(400, 0);
154 draw_large_quad(canvas);
155 draw_quad_fillpath(canvas);
156}
void draw_large_quad(SkCanvas *canvas)
Definition: overstroke.cpp:131
void draw_quad_fillpath(SkCanvas *canvas)
Definition: overstroke.cpp:139

◆ make_normal_paint()

SkPaint make_normal_paint ( )

Definition at line 41 of file overstroke.cpp.

41 {
42 SkPaint p;
43 p.setAntiAlias(true);
44 p.setStyle(SkPaint::kStroke_Style);
45 p.setStrokeWidth(NORMALSTROKE_WIDTH);
46 p.setColor(SK_ColorBLUE);
47
48 return p;
49}
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const SkScalar NORMALSTROKE_WIDTH
Definition: overstroke.cpp:37

◆ make_overstroke_paint()

SkPaint make_overstroke_paint ( )

Definition at line 51 of file overstroke.cpp.

51 {
52 SkPaint p;
53 p.setAntiAlias(true);
54 p.setStyle(SkPaint::kStroke_Style);
55 p.setStrokeWidth(OVERSTROKE_WIDTH);
56
57 return p;
58}

◆ oval_path()

SkPath oval_path ( )

Definition at line 78 of file overstroke.cpp.

78 {
79 SkRect oval = SkRect::MakeXYWH(0, -25, 100, 50);
80
81 return SkPathBuilder().arcTo(oval, 0, 359, true).close().detach();
82}
SkPathBuilder & close()
SkPathBuilder & arcTo(const SkRect &oval, SkScalar startAngleDeg, SkScalar sweepAngleDeg, bool forceMoveTo)
SkRect oval
Definition: SkRecords.h:249
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ quad_path()

SkPath quad_path ( )

Definition at line 60 of file overstroke.cpp.

60 {
61 return SkPathBuilder().moveTo(0, 0)
62 .lineTo(100, 0)
63 .quadTo(50, -40, 0, 0)
64 .close()
65 .detach();
66}
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
SkPathBuilder & quadTo(SkPoint pt1, SkPoint pt2)

◆ ribs_path()

SkPath ribs_path ( SkPath  path,
SkScalar  radius 
)

Definition at line 84 of file overstroke.cpp.

84 {
85 SkPath ribs;
86
87 const SkScalar spacing = 5.0f;
88 float accum = 0.0f;
89
90 SkPathMeasure meas(path, false);
91 SkScalar length = meas.getLength();
93 SkVector tan;
94 while (accum < length) {
95 if (meas.getPosTan(accum, &pos, &tan)) {
96 tan.scale(radius);
98
99 ribs.moveTo(pos.x() + tan.x(), pos.y() + tan.y());
100 ribs.lineTo(pos.x() - tan.x(), pos.y() - tan.y());
101 }
102 accum += spacing;
103 }
104
105 return ribs;
106}
SkPoint pos
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
static void RotateCCW(const SkPoint &src, SkPoint *dst)
Definition: SkPointPriv.h:72
float SkScalar
Definition: extension.cpp:12
void scale(float scale, SkPoint *dst) const
Definition: SkPoint.cpp:17
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

Variable Documentation

◆ examples

void(* examples[])(SkCanvas *canvas) ( SkCanvas canvas)
Initial value:
= {
}
void draw_stroked_quad(SkCanvas *canvas)
Definition: overstroke.cpp:152
void draw_stroked_oval(SkCanvas *canvas)
Definition: overstroke.cpp:227
void draw_small_quad(SkCanvas *canvas)
Definition: overstroke.cpp:120
void draw_small_oval(SkCanvas *canvas)
Definition: overstroke.cpp:197
void draw_stroked_cubic(SkCanvas *canvas)
Definition: overstroke.cpp:189
void draw_small_cubic(SkCanvas *canvas)
Definition: overstroke.cpp:160

Definition at line 235 of file overstroke.cpp.

◆ NORMALSTROKE_WIDTH

const SkScalar NORMALSTROKE_WIDTH = 3.0f

Definition at line 37 of file overstroke.cpp.

◆ OVERSTROKE_WIDTH

const SkScalar OVERSTROKE_WIDTH = 500.0f

Definition at line 36 of file overstroke.cpp.