OLD | NEW |
---|---|
(Empty) | |
1 /* | |
robertphillips
2015/11/18 21:06:51
date ?
jvanverth1
2015/11/18 21:15:51
Done.
| |
2 * Copyright 2011 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "gm.h" | |
9 #include "SkPath.h" | |
10 | |
11 typedef SkScalar (*MakePathProc)(SkPath*); | |
12 | |
13 static SkScalar make_triangle(SkPath* path) { | |
14 static const int gCoord[] = { | |
15 10, 20, 15, 5, 30, 30 | |
16 }; | |
17 path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); | |
18 path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); | |
19 path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); | |
20 path->close(); | |
21 path->offset(SkIntToScalar(10), SkIntToScalar(0)); | |
22 return SkIntToScalar(30); | |
23 } | |
24 | |
25 static SkScalar make_rect(SkPath* path) { | |
26 SkRect r = { SkIntToScalar(10), SkIntToScalar(10), | |
27 SkIntToScalar(30), SkIntToScalar(30) }; | |
28 path->addRect(r); | |
29 path->offset(SkIntToScalar(10), SkIntToScalar(0)); | |
30 return SkIntToScalar(30); | |
31 } | |
32 | |
33 static SkScalar make_oval(SkPath* path) { | |
34 SkRect r = { SkIntToScalar(10), SkIntToScalar(10), | |
35 SkIntToScalar(30), SkIntToScalar(30) }; | |
36 path->addOval(r); | |
37 path->offset(SkIntToScalar(10), SkIntToScalar(0)); | |
38 return SkIntToScalar(30); | |
39 } | |
40 | |
41 static SkScalar make_star(SkPath* path, int n) { | |
42 const SkScalar c = SkIntToScalar(45); | |
43 const SkScalar r = SkIntToScalar(20); | |
44 | |
45 SkScalar rad = -SK_ScalarPI / 2; | |
46 const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n; | |
47 | |
48 path->moveTo(c, c - r); | |
49 for (int i = 1; i < n; i++) { | |
50 rad += drad; | |
51 SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV); | |
52 path->lineTo(c + SkScalarMul(cosV, r), c + SkScalarMul(sinV, r)); | |
53 } | |
54 path->close(); | |
55 return r * 2 * 6 / 5; | |
56 } | |
57 | |
58 static SkScalar make_star_5(SkPath* path) { return make_star(path, 5); } | |
59 static SkScalar make_star_13(SkPath* path) { return make_star(path, 13); } | |
60 | |
61 static SkScalar make_three_line(SkPath* path) { | |
62 static SkScalar xOffset = 34.f; | |
63 static SkScalar yOffset = 50.f; | |
64 path->moveTo(-32.5f + xOffset, 0.0f + yOffset); | |
65 path->lineTo(32.5f + xOffset, 0.0f + yOffset); | |
66 | |
67 path->moveTo(-32.5f + xOffset, 19 + yOffset); | |
68 path->lineTo(32.5f + xOffset, 19 + yOffset); | |
69 | |
70 path->moveTo(-32.5f + xOffset, -19 + yOffset); | |
71 path->lineTo(32.5f + xOffset, -19 + yOffset); | |
72 path->lineTo(-32.5f + xOffset, -19 + yOffset); | |
73 | |
74 path->close(); | |
75 | |
76 return SkIntToScalar(70); | |
77 } | |
78 | |
79 static SkScalar make_arrow(SkPath* path) { | |
80 static SkScalar xOffset = 34.f; | |
81 static SkScalar yOffset = 40.f; | |
82 path->moveTo(-26.f + xOffset, 0.0f + yOffset); | |
83 path->lineTo(26.f + xOffset, 0.0f + yOffset); | |
84 | |
85 path->moveTo(-28.f + xOffset, -2.4748745f + yOffset); | |
86 path->lineTo(0 + xOffset, 25.525126f + yOffset); | |
87 | |
88 path->moveTo(-28.f + xOffset, 2.4748745f + yOffset); | |
89 path->lineTo(0 + xOffset, -25.525126f + yOffset); | |
90 path->lineTo(-28.f + xOffset, 2.4748745f + yOffset); | |
91 | |
92 path->close(); | |
93 | |
94 return SkIntToScalar(70); | |
95 } | |
96 | |
97 static SkScalar make_curve(SkPath* path) { | |
98 static SkScalar xOffset = -382.f; | |
99 static SkScalar yOffset = -50.f; | |
100 path->moveTo(491 + xOffset, 56 + yOffset); | |
101 path->conicTo(435.93292f + xOffset, 56.000031f + yOffset, | |
102 382.61078f + xOffset, 69.752716f + yOffset, | |
103 0.9920463f); | |
104 | |
105 return SkIntToScalar(40); | |
106 } | |
107 | |
108 static SkScalar make_battery(SkPath* path) { | |
109 static SkScalar xOffset = 5.f; | |
robertphillips
2015/11/18 21:06:51
kill this ?
jvanverth1
2015/11/18 21:15:51
Done.
| |
110 // static SkScalar yOffset = -0.f; | |
111 | |
112 path->moveTo(24.67 + xOffset, 0.33000004); | |
113 path->lineTo(8.3299999 + xOffset, 0.33000004); | |
114 path->lineTo(8.3299999 + xOffset, 5.3299999); | |
115 path->lineTo(0.33000004 + xOffset, 5.3299999); | |
116 path->lineTo(0.33000004 + xOffset, 50.669998); | |
117 path->lineTo(32.669998 + xOffset, 50.669998); | |
118 path->lineTo(32.669998 + xOffset, 5.3299999); | |
119 path->lineTo(24.67 + xOffset, 5.3299999); | |
120 path->lineTo(24.67 + xOffset, 0.33000004); | |
121 path->close(); | |
122 | |
123 path->moveTo(25.727224 + xOffset, 12.886665); | |
124 path->lineTo(10.907918 + xOffset, 12.886665); | |
125 path->lineTo(7.5166659 + xOffset, 28.683645); | |
126 path->lineTo(14.810181 + xOffset, 28.683645); | |
127 path->lineTo(7.7024879 + xOffset, 46.135998); | |
128 path->lineTo(28.049999 + xOffset, 25.136419); | |
129 path->lineTo(16.854223 + xOffset, 25.136419); | |
130 path->lineTo(25.727224 + xOffset, 12.886665); | |
131 path->close(); | |
132 return SkIntToScalar(70); | |
133 } | |
134 | |
robertphillips
2015/11/18 21:06:51
make_charging_icon ?
jvanverth1
2015/11/18 21:15:51
Done.
| |
135 static SkScalar make_whatever(SkPath* path) { | |
136 static SkScalar xOffset = 5.f; | |
137 | |
138 path->moveTo(32.669998 + xOffset, 9.8640003); | |
139 path->lineTo(0.33000004 + xOffset, 9.8640003); | |
140 path->lineTo(0.33000004 + xOffset, 50.669998); | |
141 path->lineTo(32.669998 + xOffset, 50.669998); | |
142 path->lineTo(32.669998 + xOffset, 9.8640003); | |
143 path->close(); | |
144 | |
145 path->moveTo(10.907918 + xOffset, 12.886665); | |
146 path->lineTo(25.727224 + xOffset, 12.886665); | |
147 path->lineTo(16.854223 + xOffset, 25.136419); | |
148 path->lineTo(28.049999 + xOffset, 25.136419); | |
149 path->lineTo(7.7024879 + xOffset, 46.135998); | |
150 path->lineTo(14.810181 + xOffset, 28.683645); | |
151 path->lineTo(7.5166659 + xOffset, 28.683645); | |
152 path->lineTo(10.907918 + xOffset, 12.886665); | |
153 path->close(); | |
154 | |
155 return SkIntToScalar(70); | |
156 } | |
157 | |
158 static const MakePathProc gProcs[] = { | |
159 make_triangle, | |
160 make_rect, | |
161 make_oval, | |
162 make_star_5, | |
163 make_star_13, | |
164 make_three_line, | |
165 make_arrow, | |
166 make_curve, | |
167 make_battery, | |
168 make_whatever | |
169 }; | |
170 | |
171 static const SkScalar gWidths[] = { | |
172 2.0f, | |
173 3.0f, | |
174 4.0f, | |
175 5.0f, | |
176 6.0f, | |
177 7.0f, | |
178 7.0f, | |
179 14.0f, | |
180 0.0f, | |
181 0.0f, | |
182 }; | |
183 | |
184 static const SkScalar gMiters[] = { | |
185 2.0f, | |
186 3.0f, | |
187 3.0f, | |
188 3.0f, | |
189 4.0f, | |
190 4.0f, | |
191 4.0f, | |
192 4.0f, | |
193 4.0f, | |
194 4.0f, | |
195 }; | |
196 | |
197 #define N SK_ARRAY_COUNT(gProcs) | |
198 | |
robertphillips
2015/11/18 21:06:51
// This GM tests out drawing small paths (i.e., fo
jvanverth1
2015/11/18 21:15:51
Done.
| |
199 class SmallPathsGM : public skiagm::GM { | |
200 SkPath fPath[N]; | |
201 SkScalar fDY[N]; | |
202 protected: | |
203 void onOnceBeforeDraw() override { | |
204 for (size_t i = 0; i < N; i++) { | |
205 fDY[i] = gProcs[i](&fPath[i]); | |
206 } | |
207 } | |
208 | |
209 SkString onShortName() override { | |
210 return SkString("smallpaths"); | |
211 } | |
212 | |
213 SkISize onISize() override { | |
214 return SkISize::Make(640, 480); | |
215 } | |
216 | |
217 void onDraw(SkCanvas* canvas) override { | |
218 SkPaint paint; | |
219 paint.setAntiAlias(true); | |
220 | |
robertphillips
2015/11/18 21:06:51
// First column is just filled
?
jvanverth1
2015/11/18 21:15:51
Done.
| |
221 canvas->save(); | |
222 for (size_t i = 0; i < N; i++) { | |
223 canvas->drawPath(fPath[i], paint); | |
224 canvas->translate(SkIntToScalar(0), fDY[i]); | |
225 } | |
226 | |
227 canvas->restore(); | |
228 canvas->translate(SkIntToScalar(120), SkIntToScalar(0)); | |
229 | |
robertphillips
2015/11/18 21:06:51
// Second column is stroked
?
jvanverth1
2015/11/18 21:15:51
Done.
| |
230 // now stroke them | |
231 canvas->save(); | |
232 paint.setStyle(SkPaint::kStroke_Style); | |
233 paint.setStrokeCap(SkPaint::kButt_Cap); | |
234 for (size_t i = 0; i < N; i++) { | |
235 paint.setStrokeWidth(gWidths[i]); | |
236 paint.setStrokeMiter(gMiters[i]); | |
237 canvas->drawPath(fPath[i], paint); | |
238 canvas->translate(SkIntToScalar(0), fDY[i]); | |
239 } | |
240 canvas->restore(); | |
241 | |
242 // now stroke and fill | |
243 canvas->translate(SkIntToScalar(120), SkIntToScalar(0)); | |
244 paint.setStyle(SkPaint::kStrokeAndFill_Style); | |
245 paint.setStrokeCap(SkPaint::kButt_Cap); | |
246 for (size_t i = 0; i < N; i++) { | |
247 paint.setStrokeWidth(gWidths[i]); | |
248 paint.setStrokeMiter(gMiters[i]); | |
249 canvas->drawPath(fPath[i], paint); | |
250 canvas->translate(SkIntToScalar(0), fDY[i]); | |
251 } | |
252 | |
253 } | |
254 | |
255 private: | |
256 typedef skiagm::GM INHERITED; | |
257 }; | |
258 | |
259 /////////////////////////////////////////////////////////////////////////////// | |
260 | |
robertphillips
2015/11/18 21:06:51
DEF_GM ?
jvanverth1
2015/11/18 21:15:51
Done.
| |
261 static skiagm::GM* MyFactory(void*) { return new SmallPathsGM; } | |
262 static skiagm::GMRegistry reg(MyFactory); | |
263 | |
OLD | NEW |