Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
OverstrokeSlide Class Reference
Inheritance diagram for OverstrokeSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 OverstrokeSlide ()
 
bool onChar (SkUnichar uni) override
 
SkPath quadPath (SkPoint p1, SkPoint p2)
 
SkPath cubicPath (SkPoint p1, SkPoint p2)
 
SkPath linSemicirclePath (SkPoint p1, SkPoint p2)
 
SkPath rectPath (SkPoint p1)
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 19 of file PathOverstrokeSlide.cpp.

Constructor & Destructor Documentation

◆ OverstrokeSlide()

OverstrokeSlide::OverstrokeSlide ( )
inline

Definition at line 27 of file PathOverstrokeSlide.cpp.

27 {
28 fStroke = 5;
29 fPathType = 0;
30 fClosePath = false;
31 fDrawFillPath = false;
32 fDumpHex = false;
33 fName = "PathOverstroke";
34 }
SkString fName
Definition Slide.h:54

Member Function Documentation

◆ cubicPath()

SkPath OverstrokeSlide::cubicPath ( SkPoint  p1,
SkPoint  p2 
)
inline

Definition at line 76 of file PathOverstrokeSlide.cpp.

76 {
77 SkASSERT(p1.y() == p2.y());
78
80 path.moveTo(p1);
81
82 SkPoint p3 = SkPoint::Make((p1.x() + p2.x()) / 3.0f, p1.y() * 0.7f);
83 SkPoint p4 = SkPoint::Make(2.0f*(p1.x() + p2.x()) / 3.0f, p1.y() * 1.5f);
84
85 path.cubicTo(p3, p4, p2);
86
87 return path;
88 }
#define SkASSERT(cond)
Definition SkAssert.h:116
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
static constexpr SkPoint Make(float x, float y)
constexpr float y() const
constexpr float x() const

◆ draw()

void OverstrokeSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 119 of file PathOverstrokeSlide.cpp.

119 {
120 canvas->clear(0xFFFFFFFF);
121 const float SCALE = 1;
122
123 canvas->translate(30, 40);
124 canvas->scale(SCALE, SCALE);
125
126 SkPoint p1 = SkPoint::Make(50, 50);
127 SkPoint p2 = SkPoint::Make(80, 50);
128
129 SkPath path;
130 switch (fPathType) {
131 case 0:
132 path = quadPath(p1, p2);
133 break;
134 case 1:
135 path = cubicPath(p1, p2);
136 break;
137 case 2:
138 path = rectPath(p1);
139 break;
140 case 3:
141 path = linSemicirclePath(p1, p2);
142 break;
143 default:
144 path = quadPath(p1, p2);
145 break;
146 }
147
148 if (fClosePath) {
149 path.close();
150 }
151
152 SkPaint p;
153 p.setColor(SK_ColorRED);
154 p.setAntiAlias(true);
155 p.setStyle(SkPaint::kStroke_Style);
156 p.setStrokeWidth(fStroke);
157
158 canvas->drawPath(path, p);
159
160 if (fDumpHex) {
161 std::cerr << "path dumpHex" << std::endl;
162 path.dumpHex();
163 }
164
165 SkPaint hairp;
166 hairp.setColor(SK_ColorBLACK);
167 hairp.setAntiAlias(true);
169
170 if (fDrawFillPath) {
171 SkPath fillpath;
172 skpathutils::FillPathWithPaint(path, p, &fillpath);
173
174 canvas->drawPath(fillpath, hairp);
175
176 if (fDumpHex) {
177 std::cerr << "fillpath dumpHex" << std::endl;
178 fillpath.dumpHex();
179 }
180 }
181
182 if (fDumpHex) {
183 std::cerr << std::endl;
184
185 fDumpHex = false;
186 }
187
188 // draw original path with green hairline
189 hairp.setColor(SK_ColorGREEN);
190 canvas->drawPath(path, hairp);
191 }
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define SCALE
SkPath quadPath(SkPoint p1, SkPoint p2)
SkPath rectPath(SkPoint p1)
SkPath cubicPath(SkPoint p1, SkPoint p2)
SkPath linSemicirclePath(SkPoint p1, SkPoint p2)
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
void scale(SkScalar sx, SkScalar sy)
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
void dumpHex() const
Definition SkPath.h:1727
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)

◆ linSemicirclePath()

SkPath OverstrokeSlide::linSemicirclePath ( SkPoint  p1,
SkPoint  p2 
)
inline

Definition at line 90 of file PathOverstrokeSlide.cpp.

90 {
91 SkASSERT(p1.y() == p2.y());
92
94 path.moveTo(p1);
95 path.lineTo(p2);
96
97 SkPoint pt;
98
99 for (int i = 0; i < LIN_SEGMENTS; i++) {
100 float theta = i * PI / (LIN_SEGMENTS);
101 SkScalar x = 65 + 15 * cos(theta);
102 SkScalar y = 50 - 15 * sin(theta);
103 pt = SkPoint::Make(x, y);
104 path.lineTo(pt);
105 }
106 path.lineTo(p1);
107
108 return path;
109 }
#define PI
#define LIN_SEGMENTS
float SkScalar
Definition extension.cpp:12
double y
double x

◆ onChar()

bool OverstrokeSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 36 of file PathOverstrokeSlide.cpp.

36 {
37 switch (uni) {
38 case ',':
39 fStroke += 1.0;
40 return true;
41 case '.':
42 fStroke -= 1.0;
43 return true;
44 case 'x':
45 fPathType = (fPathType + 1) % 4;
46 return true;
47 case 'c':
48 fClosePath = !fClosePath;
49 return true;
50 case 'f':
51 fDrawFillPath = !fDrawFillPath;
52 return true;
53 case 'D':
54 fDumpHex = !fDumpHex;
55 return true;
56 default:
57 break;
58 }
59 return false;
60 }

◆ quadPath()

SkPath OverstrokeSlide::quadPath ( SkPoint  p1,
SkPoint  p2 
)
inline

Definition at line 62 of file PathOverstrokeSlide.cpp.

62 {
63 SkASSERT(p1.y() == p2.y());
64
66 path.moveTo(p1);
67 path.lineTo(p2);
68
69 SkPoint p3 = SkPoint::Make((p1.x() + p2.x()) / 2.0f, p1.y() * 0.7f);
70
71 path.quadTo(p3, p1);
72
73 return path;
74 }

◆ rectPath()

SkPath OverstrokeSlide::rectPath ( SkPoint  p1)
inline

Definition at line 111 of file PathOverstrokeSlide.cpp.

111 {
112 SkRect r = SkRect::MakeXYWH(p1.fX, p1.fY, 20, 20);
113 SkPath path;
114 path.addRect(r);
115
116 return path;
117 }
float fX
x-axis value
float fY
y-axis value
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

The documentation for this class was generated from the following file: