| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SampleCode.h" | 9 #include "SampleCode.h" |
| 10 #include "SkAnimTimer.h" | 10 #include "SkAnimTimer.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 fPath[5].moveTo(52, 50); | 136 fPath[5].moveTo(52, 50); |
| 137 fPath[5].lineTo(50, V); | 137 fPath[5].lineTo(50, V); |
| 138 fPath[5].lineTo(50, 50); | 138 fPath[5].lineTo(50, 50); |
| 139 | 139 |
| 140 this->setBGColor(0xFFDDDDDD); | 140 this->setBGColor(0xFFDDDDDD); |
| 141 } | 141 } |
| 142 | 142 |
| 143 protected: | 143 protected: |
| 144 // overrides from SkEventSink | 144 // overrides from SkEventSink |
| 145 virtual bool onQuery(SkEvent* evt) { | 145 bool onQuery(SkEvent* evt) override { |
| 146 if (SampleCode::TitleQ(*evt)) { | 146 if (SampleCode::TitleQ(*evt)) { |
| 147 SampleCode::TitleR(evt, "Paths"); | 147 SampleCode::TitleR(evt, "Paths"); |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 return this->INHERITED::onQuery(evt); | 150 return this->INHERITED::onQuery(evt); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void drawPath(SkCanvas* canvas, const SkPath& path, SkPaint::Join j) { | 153 void drawPath(SkCanvas* canvas, const SkPath& path, SkPaint::Join j) { |
| 154 SkPaint paint; | 154 SkPaint paint; |
| 155 | 155 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 166 canvas->drawPath(fill, paint); | 166 canvas->drawPath(fill, paint); |
| 167 } else { | 167 } else { |
| 168 canvas->drawPath(path, paint); | 168 canvas->drawPath(path, paint); |
| 169 } | 169 } |
| 170 | 170 |
| 171 paint.setColor(SK_ColorRED); | 171 paint.setColor(SK_ColorRED); |
| 172 paint.setStrokeWidth(0); | 172 paint.setStrokeWidth(0); |
| 173 canvas->drawPath(path, paint); | 173 canvas->drawPath(path, paint); |
| 174 } | 174 } |
| 175 | 175 |
| 176 virtual void onDrawContent(SkCanvas* canvas) { | 176 void onDrawContent(SkCanvas* canvas) override { |
| 177 this->init(); | 177 this->init(); |
| 178 canvas->translate(50, 50); | 178 canvas->translate(50, 50); |
| 179 | 179 |
| 180 static const SkPaint::Join gJoins[] = { | 180 static const SkPaint::Join gJoins[] = { |
| 181 SkPaint::kBevel_Join, | 181 SkPaint::kBevel_Join, |
| 182 SkPaint::kMiter_Join, | 182 SkPaint::kMiter_Join, |
| 183 SkPaint::kRound_Join | 183 SkPaint::kRound_Join |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoins); i++) { | 186 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoins); i++) { |
| 187 canvas->save(); | 187 canvas->save(); |
| 188 for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) { | 188 for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) { |
| 189 this->drawPath(canvas, fPath[j], gJoins[i]); | 189 this->drawPath(canvas, fPath[j], gJoins[i]); |
| 190 canvas->translate(200, 0); | 190 canvas->translate(200, 0); |
| 191 } | 191 } |
| 192 canvas->restore(); | 192 canvas->restore(); |
| 193 | 193 |
| 194 canvas->translate(0, 200); | 194 canvas->translate(0, 200); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool onAnimate(const SkAnimTimer& timer) override { | 198 bool onAnimate(const SkAnimTimer& timer) override { |
| 199 SkScalar currSecs = timer.scaled(100); | 199 SkScalar currSecs = timer.scaled(100); |
| 200 SkScalar delta = currSecs - fPrevSecs; | 200 SkScalar delta = currSecs - fPrevSecs; |
| 201 fPrevSecs = currSecs; | 201 fPrevSecs = currSecs; |
| 202 | 202 |
| 203 fStroke += fDStroke * delta; | 203 fStroke += fDStroke * delta; |
| 204 if (fStroke > fMaxStroke || fStroke < fMinStroke) { | 204 if (fStroke > fMaxStroke || fStroke < fMinStroke) { |
| 205 fDStroke = -fDStroke; | 205 fDStroke = -fDStroke; |
| 206 } | 206 } |
| 207 return true; | 207 return true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 234 SkPoint fPts[N]; | 234 SkPoint fPts[N]; |
| 235 | 235 |
| 236 ArcToView() | 236 ArcToView() |
| 237 : fDoFrame(false), fDoArcTo(false), fDoCorner(false), fDoConic(false) | 237 : fDoFrame(false), fDoArcTo(false), fDoCorner(false), fDoConic(false) |
| 238 { | 238 { |
| 239 SkRandom rand; | 239 SkRandom rand; |
| 240 for (int i = 0; i < N; ++i) { | 240 for (int i = 0; i < N; ++i) { |
| 241 fPts[i].fX = 20 + rand.nextUScalar1() * 640; | 241 fPts[i].fX = 20 + rand.nextUScalar1() * 640; |
| 242 fPts[i].fY = 20 + rand.nextUScalar1() * 480; | 242 fPts[i].fY = 20 + rand.nextUScalar1() * 480; |
| 243 } | 243 } |
| 244 | 244 |
| 245 const SkScalar rad = 50; | 245 const SkScalar rad = 50; |
| 246 | 246 |
| 247 fPtsPaint.setAntiAlias(true); | 247 fPtsPaint.setAntiAlias(true); |
| 248 fPtsPaint.setStrokeWidth(15); | 248 fPtsPaint.setStrokeWidth(15); |
| 249 fPtsPaint.setStrokeCap(SkPaint::kRound_Cap); | 249 fPtsPaint.setStrokeCap(SkPaint::kRound_Cap); |
| 250 | 250 |
| 251 fArcToPaint.setAntiAlias(true); | 251 fArcToPaint.setAntiAlias(true); |
| 252 fArcToPaint.setStyle(SkPaint::kStroke_Style); | 252 fArcToPaint.setStyle(SkPaint::kStroke_Style); |
| 253 fArcToPaint.setStrokeWidth(9); | 253 fArcToPaint.setStrokeWidth(9); |
| 254 fArcToPaint.setColor(0x800000FF); | 254 fArcToPaint.setColor(0x800000FF); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 282 switch (uni) { | 282 switch (uni) { |
| 283 case '1': this->toggle(fDoFrame); return true; | 283 case '1': this->toggle(fDoFrame); return true; |
| 284 case '2': this->toggle(fDoArcTo); return true; | 284 case '2': this->toggle(fDoArcTo); return true; |
| 285 case '3': this->toggle(fDoCorner); return true; | 285 case '3': this->toggle(fDoCorner); return true; |
| 286 case '4': this->toggle(fDoConic); return true; | 286 case '4': this->toggle(fDoConic); return true; |
| 287 default: break; | 287 default: break; |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 return this->INHERITED::onQuery(evt); | 290 return this->INHERITED::onQuery(evt); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void makePath(SkPath* path) { | 293 void makePath(SkPath* path) { |
| 294 path->moveTo(fPts[0]); | 294 path->moveTo(fPts[0]); |
| 295 for (int i = 1; i < N; ++i) { | 295 for (int i = 1; i < N; ++i) { |
| 296 path->lineTo(fPts[i]); | 296 path->lineTo(fPts[i]); |
| 297 } | 297 } |
| 298 if (!fDoFrame) { | 298 if (!fDoFrame) { |
| 299 path->close(); | 299 path->close(); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 return this->INHERITED::onFindClickHandler(x, y, modi); | 340 return this->INHERITED::onFindClickHandler(x, y, modi); |
| 341 } | 341 } |
| 342 | 342 |
| 343 private: | 343 private: |
| 344 typedef SampleView INHERITED; | 344 typedef SampleView INHERITED; |
| 345 }; | 345 }; |
| 346 DEF_SAMPLE( return new ArcToView; ) | 346 DEF_SAMPLE( return new ArcToView; ) |
| 347 | 347 |
| OLD | NEW |