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

Side by Side Diff: samplecode/SampleArc.cpp

Issue 869843006: more gms for conics (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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 | « gm/addarc.cpp ('k') | 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
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 116
117 static void DrawRectWithLines(SkCanvas* canvas, const SkRect& r, const SkPai nt& p) { 117 static void DrawRectWithLines(SkCanvas* canvas, const SkRect& r, const SkPai nt& p) {
118 canvas->drawRect(r, p); 118 canvas->drawRect(r, p);
119 canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p); 119 canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p);
120 canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p); 120 canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p);
121 canvas->drawLine(r.fLeft, r.centerY(), r.fRight, r.centerY(), p); 121 canvas->drawLine(r.fLeft, r.centerY(), r.fRight, r.centerY(), p);
122 canvas->drawLine(r.centerX(), r.fTop, r.centerX(), r.fBottom, p); 122 canvas->drawLine(r.centerX(), r.fTop, r.centerX(), r.fBottom, p);
123 } 123 }
124 124
125 static void DrawLabel(SkCanvas* canvas, const SkRect& rect, 125 static void DrawLabel(SkCanvas* canvas, const SkRect& rect, SkScalar start, SkScalar sweep) {
126 int start, int sweep) {
127 SkPaint paint; 126 SkPaint paint;
128 127
129 paint.setAntiAlias(true); 128 paint.setAntiAlias(true);
130 paint.setTextAlign(SkPaint::kCenter_Align); 129 paint.setTextAlign(SkPaint::kCenter_Align);
131 130
132 SkString str; 131 SkString str;
133 132
134 str.appendS32(start); 133 str.appendScalar(start);
135 str.append(", "); 134 str.append(", ");
136 str.appendS32(sweep); 135 str.appendScalar(sweep);
137 canvas->drawText(str.c_str(), str.size(), rect.centerX(), 136 canvas->drawText(str.c_str(), str.size(), rect.centerX(),
138 rect.fBottom + paint.getTextSize() * 5/4, paint); 137 rect.fBottom + paint.getTextSize() * 5/4, paint);
139 } 138 }
140 139
141 static void DrawArcs(SkCanvas* canvas) { 140 static void DrawArcs(SkCanvas* canvas) {
142 SkPaint paint; 141 SkPaint paint;
143 SkRect r; 142 SkRect r;
144 SkScalar w = SkIntToScalar(75); 143 SkScalar w = 75;
145 SkScalar h = SkIntToScalar(50); 144 SkScalar h = 50;
146 145
147 r.set(0, 0, w, h); 146 r.set(0, 0, w, h);
148 paint.setAntiAlias(true); 147 paint.setAntiAlias(true);
149 paint.setStyle(SkPaint::kStroke_Style); 148 paint.setStyle(SkPaint::kStroke_Style);
150 149
151 canvas->save(); 150 canvas->save();
152 canvas->translate(SkIntToScalar(10), SkIntToScalar(300)); 151 canvas->translate(SkIntToScalar(10), SkIntToScalar(300));
153 152
154 paint.setStrokeWidth(SkIntToScalar(1)); 153 paint.setStrokeWidth(SkIntToScalar(1));
155 154
156 static const int gAngles[] = { 155 static const SkScalar gAngles[] = {
157 0, 360, 156 0, 360,
158 0, 45, 157 0, 45,
159 0, -45, 158 0, -45,
160 720, 135, 159 720, 135,
161 -90, 269, 160 -90, 269,
162 -90, 270, 161 -90, 270,
163 -90, 271, 162 -90, 271,
164 -180, -270, 163 -180, -270,
165 225, 90 164 225, 90
166 }; 165 };
167 166
168 for (size_t i = 0; i < SK_ARRAY_COUNT(gAngles); i += 2) { 167 for (size_t i = 0; i < SK_ARRAY_COUNT(gAngles); i += 2) {
169 paint.setColor(SK_ColorBLACK); 168 paint.setColor(SK_ColorBLACK);
170 DrawRectWithLines(canvas, r, paint); 169 DrawRectWithLines(canvas, r, paint);
171 170
172 paint.setColor(SK_ColorRED); 171 paint.setColor(SK_ColorRED);
173 canvas->drawArc(r, SkIntToScalar(gAngles[i]), 172 canvas->drawArc(r, gAngles[i], gAngles[i+1], false, paint);
174 SkIntToScalar(gAngles[i+1]), false, paint);
175 173
176 DrawLabel(canvas, r, gAngles[i], gAngles[i+1]); 174 DrawLabel(canvas, r, gAngles[i], gAngles[i+1]);
177 175
178 canvas->translate(w * 8 / 7, 0); 176 canvas->translate(w * 8 / 7, 0);
179 } 177 }
180 178
181 canvas->restore(); 179 canvas->restore();
182 } 180 }
183 181
184 void drawRoot(SkCanvas* canvas) { 182 void drawRoot(SkCanvas* canvas) {
(...skipping 28 matching lines...) Expand all
213 private: 211 private:
214 SkScalar fSweep; 212 SkScalar fSweep;
215 213
216 typedef SampleView INHERITED; 214 typedef SampleView INHERITED;
217 }; 215 };
218 216
219 ////////////////////////////////////////////////////////////////////////////// 217 //////////////////////////////////////////////////////////////////////////////
220 218
221 static SkView* MyFactory() { return new ArcsView; } 219 static SkView* MyFactory() { return new ArcsView; }
222 static SkViewRegister reg(MyFactory); 220 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/addarc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698