| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkDrawable.h" | 10 #include "SkDrawable.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 class PushButtonWig : public HasEventWig { | 50 class PushButtonWig : public HasEventWig { |
| 51 SkString fLabel; | 51 SkString fLabel; |
| 52 SkColor fColor; | 52 SkColor fColor; |
| 53 uint32_t fFast32; | 53 uint32_t fFast32; |
| 54 | 54 |
| 55 public: | 55 public: |
| 56 PushButtonWig(const char label[], uint32_t fast) : fLabel(label) { | 56 PushButtonWig(const char label[], uint32_t fast) : fLabel(label) { |
| 57 fColor = (gRand.nextU() & 0x7F7F7F7F) | SkColorSetARGB(0xFF, 0, 0, 0x80)
; | 57 fColor = (gRand.nextU() & 0x7F7F7F7F) | SkColorSetARGB(0xFF, 0, 0, 0x80)
; |
| 58 fFast32 = fast; | 58 fFast32 = fast; |
| 59 } | 59 } |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 void onPrepareWidEvent(SkEvent* evt) override { | 62 void onPrepareWidEvent(SkEvent* evt) override { |
| 63 evt->setType("push-button"); | 63 evt->setType("push-button"); |
| 64 evt->setFast32(fFast32); | 64 evt->setFast32(fFast32); |
| 65 evt->setString("label", fLabel.c_str()); | 65 evt->setString("label", fLabel.c_str()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // bool onEvent(const SkEvent&) override; | 68 // bool onEvent(const SkEvent&) override; |
| 69 void onDraw(SkCanvas* canvas) override { | 69 void onDraw(SkCanvas* canvas) override { |
| 70 SkRect r; | 70 SkRect r; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 94 } else { | 94 } else { |
| 95 fColor = SkColorSetA(fColor, 0xFF); | 95 fColor = SkColorSetA(fColor, 0xFF); |
| 96 } | 96 } |
| 97 this->inval(nullptr); | 97 this->inval(nullptr); |
| 98 | 98 |
| 99 if (click->fState == SkView::Click::kUp_State) { | 99 if (click->fState == SkView::Click::kUp_State) { |
| 100 this->postWidgetEvent(); | 100 this->postWidgetEvent(); |
| 101 } | 101 } |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 typedef HasEventWig INHERITED; | 106 typedef HasEventWig INHERITED; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 | 109 |
| 110 class ModeDrawable : public SkDrawable { | 110 class ModeDrawable : public SkDrawable { |
| 111 public: | 111 public: |
| 112 ModeDrawable() : fMode(SkXfermode::kSrcOver_Mode), fLoc(SkPoint::Make(0, 0))
{} | 112 ModeDrawable() : fMode(SkXfermode::kSrcOver_Mode), fLoc(SkPoint::Make(0, 0))
{} |
| 113 | 113 |
| 114 SkXfermode::Mode fMode; | 114 SkXfermode::Mode fMode; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 144 canvas->translate(fLoc.x(), fLoc.y()); | 144 canvas->translate(fLoc.x(), fLoc.y()); |
| 145 canvas->drawOval(fBounds, fPaint); | 145 canvas->drawOval(fBounds, fPaint); |
| 146 canvas->restore(); | 146 canvas->restore(); |
| 147 } | 147 } |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 class XferDemo : public SampleView { | 150 class XferDemo : public SampleView { |
| 151 enum { | 151 enum { |
| 152 N = 4 | 152 N = 4 |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 SkRect fModeRect[N_Modes]; | 155 SkRect fModeRect[N_Modes]; |
| 156 SkAutoTUnref<CircDrawable> fDrs[N]; | 156 SkAutoTUnref<CircDrawable> fDrs[N]; |
| 157 CircDrawable* fSelected; | 157 CircDrawable* fSelected; |
| 158 | 158 |
| 159 void addButtons() { | 159 void addButtons() { |
| 160 SkScalar x = 10; | 160 SkScalar x = 10; |
| 161 SkScalar y = 10; | 161 SkScalar y = 10; |
| 162 for (int i = 0; i < N_Modes; ++i) { | 162 for (int i = 0; i < N_Modes; ++i) { |
| 163 SkAutoTUnref<SkView> v(new PushButtonWig(gModes[i].fName, gModes[i].
fMode)); | 163 SkAutoTUnref<SkView> v(new PushButtonWig(gModes[i].fName, gModes[i].
fMode)); |
| 164 v->setSize(70, 25); | 164 v->setSize(70, 25); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 fSelected = nullptr; | 227 fSelected = nullptr; |
| 228 for (int i = N - 1; i >= 0; --i) { | 228 for (int i = N - 1; i >= 0; --i) { |
| 229 if (fDrs[i]->hitTest(x, y)) { | 229 if (fDrs[i]->hitTest(x, y)) { |
| 230 fSelected = fDrs[i]; | 230 fSelected = fDrs[i]; |
| 231 break; | 231 break; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 this->inval(nullptr); | 234 this->inval(nullptr); |
| 235 return fSelected ? new Click(this) : nullptr; | 235 return fSelected ? new Click(this) : nullptr; |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool onClick(Click* click) override { | 238 bool onClick(Click* click) override { |
| 239 fSelected->fLoc.fX += click->fCurr.fX - click->fPrev.fX; | 239 fSelected->fLoc.fX += click->fCurr.fX - click->fPrev.fX; |
| 240 fSelected->fLoc.fY += click->fCurr.fY - click->fPrev.fY; | 240 fSelected->fLoc.fY += click->fCurr.fY - click->fPrev.fY; |
| 241 this->inval(nullptr); | 241 this->inval(nullptr); |
| 242 return true; | 242 return true; |
| 243 } | 243 } |
| 244 | 244 |
| 245 private: | 245 private: |
| 246 typedef SampleView INHERITED; | 246 typedef SampleView INHERITED; |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 ////////////////////////////////////////////////////////////////////////////// | 249 ////////////////////////////////////////////////////////////////////////////// |
| 250 | 250 |
| 251 DEF_SAMPLE( return new XferDemo; ) | 251 DEF_SAMPLE( return new XferDemo; ) |
| OLD | NEW |