OLD | NEW |
(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 "SampleCode.h" |
| 9 #include "SkCanvas.h" |
| 10 #include "SkPath.h" |
| 11 #include "SkRandom.h" |
| 12 |
| 13 class MegaStrokeView : public SampleView { |
| 14 public: |
| 15 MegaStrokeView() { |
| 16 fClip.set(0, 0, 950, 600); |
| 17 fAngle = 0; |
| 18 fPlusMinus = 0; |
| 19 SkRandom rand; |
| 20 fMegaPath.reset(); |
| 21 for (int index = 0; index < 921; ++index) { |
| 22 for (int segs = 0; segs < 40; ++segs) { |
| 23 fMegaPath.lineTo(SkIntToScalar(index), SkIntToScalar(rand.nextRa
ngeU(500, 600))); |
| 24 } |
| 25 } |
| 26 } |
| 27 |
| 28 protected: |
| 29 // overrides from SkEventSink |
| 30 bool onQuery(SkEvent* evt) override { |
| 31 if (SampleCode::TitleQ(*evt)) { |
| 32 SampleCode::TitleR(evt, "MegaStroke"); |
| 33 return true; |
| 34 } |
| 35 |
| 36 SkUnichar uni; |
| 37 if (SampleCode::CharQ(*evt, &uni)) { |
| 38 fClip.set(0, 0, 950, 600); |
| 39 } |
| 40 SkString str; |
| 41 evt->getType(&str); |
| 42 if (str == SkString("SampleCode_Key_Event")) { |
| 43 fClip.set(0, 0, 950, 600); |
| 44 } |
| 45 return this->INHERITED::onQuery(evt); |
| 46 } |
| 47 |
| 48 void onDrawBackground(SkCanvas* canvas) override { |
| 49 } |
| 50 |
| 51 void onDrawContent(SkCanvas* canvas) override { |
| 52 SkPaint paint; |
| 53 paint.setAntiAlias(true); |
| 54 paint.setARGB(255,255,153,0); |
| 55 paint.setStyle(SkPaint::kStroke_Style); |
| 56 paint.setStrokeWidth(1); |
| 57 |
| 58 canvas->save(); |
| 59 canvas->clipRect(fClip); |
| 60 canvas->clear(SK_ColorWHITE); |
| 61 canvas->drawPath(fMegaPath, paint); |
| 62 canvas->restore(); |
| 63 |
| 64 SkPaint divSimPaint; |
| 65 divSimPaint.setColor(SK_ColorBLUE); |
| 66 SkScalar x = SkScalarSin(fAngle * SK_ScalarPI / 180) * 200 + 250; |
| 67 SkScalar y = SkScalarCos(fAngle * SK_ScalarPI / 180) * 200 + 250; |
| 68 |
| 69 if ((fPlusMinus ^= 1)) { |
| 70 fAngle += 5; |
| 71 } else { |
| 72 fAngle -= 5; |
| 73 } |
| 74 SkRect divSim = SkRect::MakeXYWH(x, y, 100, 100); |
| 75 divSim.outset(30, 30); |
| 76 canvas->drawRect(divSim, divSimPaint); |
| 77 fClip = divSim; |
| 78 } |
| 79 |
| 80 void onSizeChange() override { |
| 81 fClip.set(0, 0, 950, 600); |
| 82 } |
| 83 |
| 84 bool onAnimate(const SkAnimTimer& ) override { |
| 85 return true; |
| 86 } |
| 87 |
| 88 private: |
| 89 SkPath fMegaPath; |
| 90 SkRect fClip; |
| 91 int fAngle; |
| 92 int fPlusMinus; |
| 93 typedef SampleView INHERITED; |
| 94 }; |
| 95 |
| 96 ////////////////////////////////////////////////////////////////////////////// |
| 97 |
| 98 static SkView* MyFactory() { return new MegaStrokeView; } |
| 99 static SkViewRegister reg(MyFactory); |
OLD | NEW |