| 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkInterpolator.h" | 10 #include "SkInterpolator.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 class ClipDrawMatchView : public SampleView { | 117 class ClipDrawMatchView : public SampleView { |
| 118 public: | 118 public: |
| 119 ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry), fClipFirst(true),
fSign(1) { | 119 ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry), fClipFirst(true),
fSign(1) { |
| 120 SkScalar values[2]; | 120 SkScalar values[2]; |
| 121 | 121 |
| 122 fTrans.setRepeatCount(999); | 122 fTrans.setRepeatCount(999); |
| 123 values[0] = values[1] = 0; | 123 values[0] = values[1] = 0; |
| 124 fTrans.setKeyFrame(0, SkTime::GetMSecs() + 1000, values); | 124 fTrans.setKeyFrame(0, GetMSecs() + 1000, values); |
| 125 values[1] = 1; | 125 values[1] = 1; |
| 126 fTrans.setKeyFrame(1, SkTime::GetMSecs() + 2000, values); | 126 fTrans.setKeyFrame(1, GetMSecs() + 2000, values); |
| 127 values[0] = values[1] = 1; | 127 values[0] = values[1] = 1; |
| 128 fTrans.setKeyFrame(2, SkTime::GetMSecs() + 3000, values); | 128 fTrans.setKeyFrame(2, GetMSecs() + 3000, values); |
| 129 values[1] = 0; | 129 values[1] = 0; |
| 130 fTrans.setKeyFrame(3, SkTime::GetMSecs() + 4000, values); | 130 fTrans.setKeyFrame(3, GetMSecs() + 4000, values); |
| 131 values[0] = 0; | 131 values[0] = 0; |
| 132 fTrans.setKeyFrame(4, SkTime::GetMSecs() + 5000, values); | 132 fTrans.setKeyFrame(4, GetMSecs() + 5000, values); |
| 133 } | 133 } |
| 134 | 134 |
| 135 protected: | 135 protected: |
| 136 bool onQuery(SkEvent* evt) override { | 136 bool onQuery(SkEvent* evt) override { |
| 137 if (SampleCode::TitleQ(*evt)) { | 137 if (SampleCode::TitleQ(*evt)) { |
| 138 SampleCode::TitleR(evt, "ClipDrawMatch"); | 138 SampleCode::TitleR(evt, "ClipDrawMatch"); |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| 141 SkUnichar uni; | 141 SkUnichar uni; |
| 142 if (SampleCode::CharQ(*evt, &uni)) { | 142 if (SampleCode::CharQ(*evt, &uni)) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 draw_normal_geom(canvas, offset, fGeom, useAA); | 225 draw_normal_geom(canvas, offset, fGeom, useAA); |
| 226 | 226 |
| 227 if (!fClipFirst) { | 227 if (!fClipFirst) { |
| 228 this->drawClippedGeom(canvas, offset, useAA); | 228 this->drawClippedGeom(canvas, offset, useAA); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 void onDrawContent(SkCanvas* canvas) override { | 232 void onDrawContent(SkCanvas* canvas) override { |
| 233 SkScalar trans[2]; | 233 SkScalar trans[2]; |
| 234 fTrans.timeToValues(SkTime::GetMSecs(), trans); | 234 fTrans.timeToValues(GetMSecs(), trans); |
| 235 | 235 |
| 236 SkPoint offset; | 236 SkPoint offset; |
| 237 offset.set(trans[0], trans[1]); | 237 offset.set(trans[0], trans[1]); |
| 238 | 238 |
| 239 int saveCount = canvas->save(); | 239 int saveCount = canvas->save(); |
| 240 this->drawGeometry(canvas, offset, false); | 240 this->drawGeometry(canvas, offset, false); |
| 241 canvas->restoreToCount(saveCount); | 241 canvas->restoreToCount(saveCount); |
| 242 | 242 |
| 243 this->inval(nullptr); | 243 this->inval(nullptr); |
| 244 } | 244 } |
| 245 | 245 |
| 246 SkMSec GetMSecs() const { |
| 247 return static_cast<SkMSec>(SkTime::GetMSecs() - fStart); |
| 248 } |
| 249 |
| 246 private: | 250 private: |
| 247 SkInterpolator fTrans; | 251 SkInterpolator fTrans; |
| 248 Geometry fGeom; | 252 Geometry fGeom; |
| 249 bool fClipFirst; | 253 bool fClipFirst; |
| 250 int fSign; | 254 int fSign; |
| 255 const double fStart = SkTime::GetMSecs(); |
| 251 | 256 |
| 252 typedef SampleView INHERITED; | 257 typedef SampleView INHERITED; |
| 253 }; | 258 }; |
| 254 | 259 |
| 255 ////////////////////////////////////////////////////////////////////////////// | 260 ////////////////////////////////////////////////////////////////////////////// |
| 256 | 261 |
| 257 static SkView* MyFactory() { return new ClipDrawMatchView; } | 262 static SkView* MyFactory() { return new ClipDrawMatchView; } |
| 258 static SkViewRegister reg(MyFactory); | 263 static SkViewRegister reg(MyFactory); |
| OLD | NEW |