Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: gm/OverStroke.cpp

Issue 2161633002: Add Overstroke gm (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Completely reorganized code, added cubics and ovals with overstroke Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "SkPaint.h"
10 #include "SkPath.h"
11
12 //////// path and paint builders
13
14 SkPaint make_overstroke_paint() {
15 SkPaint p;
16 p.setAntiAlias(true);
17 p.setStyle(SkPaint::kStroke_Style);
18 p.setStrokeWidth(500);
19
20 return p;
21 }
22
23 SkPath quad_path() {
24 SkPoint p1 = SkPoint::Make(0, 0);
reed1 2016/08/02 15:21:31 nit: I think it hurts readability a little to name
Harry Stern 2016/08/02 15:44:02 I actually think the exact opposite. seeing a bunc
25 SkPoint p2 = SkPoint::Make(100, 0);
26 SkPoint p3 = SkPoint::Make(50, -40);
27
28 SkPath path;
29 path.moveTo(p1);
30 path.lineTo(p2);
31 path.quadTo(p3, p1);
32
33 return path;
34 }
35
36 SkPath cubic_path() {
37 SkPoint p1 = SkPoint::Make(0, 0);
reed1 2016/08/02 15:21:31 ditto
Harry Stern 2016/08/02 15:44:02 Done.
38 SkPoint p2 = SkPoint::Make(25, 75);
39 SkPoint p3 = SkPoint::Make(75, -50);
40 SkPoint p4 = SkPoint::Make(100, 0);
41
42 SkPath path;
43 path.moveTo(p1);
44 path.cubicTo(p2, p3, p4);
45
46 return path;
47 }
48
49 SkPath oval_path() {
50 SkRect oval = SkRect::MakeWH(100, 50);
reed1 2016/08/02 15:21:31 nit: use SkRect::MakeXYWH(0, -25, 100, 50);
Harry Stern 2016/08/02 15:44:02 Done.
51 oval.offset(0, -25);
52
53 SkPath path;
54 path.arcTo(oval, 0, 359, true);
Harry Stern 2016/08/02 15:44:02 There's no way to make a complete oval just with a
55
56 return path;
57 }
58
59 ///////// quads
60
61 void draw_small_quad(SkCanvas *canvas) {
62 // scaled so it's visible
63 canvas->scale(8, 8);
64
65 SkPaint p;
66 p.setAntiAlias(true);
67 p.setStyle(SkPaint::kStroke_Style);
68 p.setStrokeWidth(3);
69
70 SkPath path = quad_path();
71
72 canvas->drawPath(path, p);
73 }
74
75 void draw_large_quad(SkCanvas *canvas) {
76 SkPaint p = make_overstroke_paint();
77 SkPath path = quad_path();
78
79 canvas->drawPath(path, p);
80 }
81
82 void draw_quad_fillpath(SkCanvas *canvas) {
83 SkPath path = quad_path();
84 SkPaint p = make_overstroke_paint();
85
86 SkPaint fillp;
87 fillp.setAntiAlias(true);
88 fillp.setStyle(SkPaint::kStroke_Style);
89 fillp.setColor(SK_ColorMAGENTA);
90
91 SkPath fillpath;
92 p.getFillPath(path, &fillpath);
93
94 canvas->drawPath(fillpath, fillp);
95 }
96
97 void draw_stroked_quad(SkCanvas *canvas) {
98 canvas->translate(200, 0);
99 draw_large_quad(canvas);
100 draw_quad_fillpath(canvas);
101 }
102
103 ////////// cubics
104
105 void draw_small_cubic(SkCanvas *canvas) {
106 // scaled so it's visible
107 canvas->scale(8, 8);
108
109 SkPaint p;
110 p.setAntiAlias(true);
111 p.setStyle(SkPaint::kStroke_Style);
112 p.setStrokeWidth(3);
113
114 SkPath path = cubic_path();
115
116 canvas->drawPath(path, p);
117 }
118
119 void draw_large_cubic(SkCanvas *canvas) {
120 SkPaint p = make_overstroke_paint();
121 SkPath path = cubic_path();
122
123 canvas->drawPath(path, p);
124 }
125
126 void draw_cubic_fillpath(SkCanvas *canvas) {
127 SkPath path = cubic_path();
128 SkPaint p = make_overstroke_paint();
129
130 SkPaint fillp;
131 fillp.setAntiAlias(true);
132 fillp.setStyle(SkPaint::kStroke_Style);
133 fillp.setColor(SK_ColorMAGENTA);
134
135 SkPath fillpath;
136 p.getFillPath(path, &fillpath);
137
138 canvas->drawPath(fillpath, fillp);
139 }
140
141 void draw_stroked_cubic(SkCanvas *canvas) {
142 canvas->translate(400, 0);
143 draw_large_cubic(canvas);
144 draw_cubic_fillpath(canvas);
145 }
146
147 ////////// ovals
148
149 void draw_small_oval(SkCanvas *canvas) {
150 // scaled so it's visible
151 canvas->scale(8, 8);
152
153 SkPaint p;
154 p.setAntiAlias(true);
155 p.setStyle(SkPaint::kStroke_Style);
156 p.setStrokeWidth(3);
157
158 SkPath path = oval_path();
159
160 canvas->drawPath(path, p);
161 }
162
163 void draw_large_oval(SkCanvas *canvas) {
164 SkPaint p = make_overstroke_paint();
165 SkPath path = oval_path();
166
167 canvas->drawPath(path, p);
168 }
169
170 void draw_oval_fillpath(SkCanvas *canvas) {
171 SkPath path = oval_path();
172 SkPaint p = make_overstroke_paint();
173
174 SkPaint fillp;
175 fillp.setAntiAlias(true);
176 fillp.setStyle(SkPaint::kStroke_Style);
177 fillp.setColor(SK_ColorMAGENTA);
178
179 SkPath fillpath;
180 p.getFillPath(path, &fillpath);
181
182 canvas->drawPath(fillpath, fillp);
183 }
184
185 void draw_stroked_oval(SkCanvas *canvas) {
186 canvas->translate(400, 0);
187 draw_large_oval(canvas);
188 draw_oval_fillpath(canvas);
189 }
190
191 ////////// gm
192
193 void (*examples[])(SkCanvas *canvas) = {
194 draw_small_quad, draw_stroked_quad, draw_small_cubic,
195 draw_stroked_cubic, draw_small_oval, draw_stroked_oval,
196 };
197
198 DEF_SIMPLE_GM(OverStroke, canvas, 500, 500) {
reed1 2016/08/02 15:21:31 // overstroke means ... and that's why I want to e
Harry Stern 2016/08/02 15:44:02 Done, at top of file.
199 const size_t length = sizeof(examples) / sizeof(examples[0]);
200 const size_t width = 2;
201
202 printf("length %ld\n", length);
203
204 for (size_t i = 0; i < length; i++) {
205 int x = i % width;
206 int y = i / width;
207
208 canvas->save();
209 canvas->translate(200 * x, 150 * y);
210 canvas->scale(0.25f, 0.25f);
211 canvas->translate(100, 400);
212
213 examples[i](canvas);
214
215 canvas->restore();
216 }
217 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698