OLD | NEW |
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 "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 pos, SK_ARRAY_COUNT(pos
), | 30 pos, SK_ARRAY_COUNT(pos
), |
31 SkShader::kClamp_TileMo
de); | 31 SkShader::kClamp_TileMo
de); |
32 SkPaint paint; | 32 SkPaint paint; |
33 paint.setShader(s)->unref(); | 33 paint.setShader(s)->unref(); |
34 | 34 |
35 canvas->drawRect(rect, paint); | 35 canvas->drawRect(rect, paint); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 class DegenerateTwoPtRadialsView : public SampleView { | 39 class DegenerateTwoPtRadialsView : public SampleView { |
40 | |
41 public: | 40 public: |
42 DegenerateTwoPtRadialsView() { | 41 DegenerateTwoPtRadialsView() { |
43 fTime = 0; | 42 fTime = 0; |
44 this->setBGColor(0xFFDDDDDD); | 43 this->setBGColor(0xFFDDDDDD); |
45 } | 44 } |
46 | 45 |
47 protected: | 46 protected: |
48 // overrides from SkEventSink | 47 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
49 virtual bool onQuery(SkEvent* evt) { | |
50 if (SampleCode::TitleQ(*evt)) { | 48 if (SampleCode::TitleQ(*evt)) { |
51 SampleCode::TitleR(evt, "DegenerateTwoPtRadials"); | 49 SampleCode::TitleR(evt, "DegenerateTwoPtRadials"); |
52 return true; | 50 return true; |
53 } | 51 } |
54 return this->INHERITED::onQuery(evt); | 52 return this->INHERITED::onQuery(evt); |
55 } | 53 } |
56 | 54 |
57 virtual void onDrawContent(SkCanvas* canvas) { | 55 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
58 fTime += SampleCode::GetAnimSecondsDelta(); | |
59 SkScalar delta = fTime / 15.f; | 56 SkScalar delta = fTime / 15.f; |
60 int intPart = SkScalarFloorToInt(delta); | 57 int intPart = SkScalarFloorToInt(delta); |
61 delta = delta - SK_Scalar1 * intPart; | 58 delta = delta - SK_Scalar1 * intPart; |
62 if (intPart % 2) { | 59 if (intPart % 2) { |
63 delta = SK_Scalar1 - delta; | 60 delta = SK_Scalar1 - delta; |
64 } | 61 } |
65 delta -= SK_ScalarHalf; | 62 delta -= SK_ScalarHalf; |
66 static const int DELTA_SCALE = 500; | 63 static const int DELTA_SCALE = 500; |
67 delta /= DELTA_SCALE; | 64 delta /= DELTA_SCALE; |
68 | 65 |
69 SkScalar w = SK_Scalar1 * 500; | 66 SkScalar w = SK_Scalar1 * 500; |
70 SkScalar h = SK_Scalar1 * 500; | 67 SkScalar h = SK_Scalar1 * 500; |
71 SkScalar l = SK_Scalar1 * 100; | 68 SkScalar l = SK_Scalar1 * 100; |
72 SkScalar t = SK_Scalar1 * 100; | 69 SkScalar t = SK_Scalar1 * 100; |
73 draw_gradient2(canvas, SkRect::MakeXYWH(l, t, w, h), delta); | 70 draw_gradient2(canvas, SkRect::MakeXYWH(l, t, w, h), delta); |
74 SkString txt; | 71 SkString txt; |
75 txt.appendf("gap at \"tangent\" pt = %f", SkScalarToFloat(delta)); | 72 txt.appendf("gap at \"tangent\" pt = %f", SkScalarToFloat(delta)); |
76 SkPaint paint; | 73 SkPaint paint; |
77 paint.setAntiAlias(true); | 74 paint.setAntiAlias(true); |
78 paint.setColor(SK_ColorBLACK); | 75 paint.setColor(SK_ColorBLACK); |
79 canvas->drawText(txt.c_str(), txt.size(), l + w/2 + w*DELTA_SCALE*delta,
t + h + SK_Scalar1 * 10, paint); | 76 canvas->drawText(txt.c_str(), txt.size(), l + w/2 + w*DELTA_SCALE*delta,
t + h + SK_Scalar1 * 10, paint); |
80 this->inval(NULL); | 77 } |
| 78 |
| 79 bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE { |
| 80 fTime += (curr - prev) * 0.001f; |
| 81 return true; |
81 } | 82 } |
82 | 83 |
83 private: | 84 private: |
84 SkScalar fTime; | 85 SkScalar fTime; |
85 typedef SampleView INHERITED; | 86 typedef SampleView INHERITED; |
86 }; | 87 }; |
87 | 88 |
88 ////////////////////////////////////////////////////////////////////////////// | 89 ////////////////////////////////////////////////////////////////////////////// |
89 | 90 |
90 static SkView* MyFactory() { return new DegenerateTwoPtRadialsView; } | 91 static SkView* MyFactory() { return new DegenerateTwoPtRadialsView; } |
91 static SkViewRegister reg(MyFactory); | 92 static SkViewRegister reg(MyFactory); |
OLD | NEW |