| 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 "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
| 13 #include "SkString.h" | 13 #include "SkString.h" |
| 14 | 14 |
| 15 static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta)
{ | 15 static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta)
{ |
| 16 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGEN
TA }; | 16 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGEN
TA }; |
| 17 SkScalar pos[] = { 0, 0.25f, 0.75f, SK_Scalar1 }; | 17 SkScalar pos[] = { 0, 0.25f, 0.75f, SK_Scalar1 }; |
| 18 | 18 |
| 19 SkScalar l = rect.fLeft; | 19 SkScalar l = rect.fLeft; |
| 20 SkScalar t = rect.fTop; | 20 SkScalar t = rect.fTop; |
| 21 SkScalar w = rect.width(); | 21 SkScalar w = rect.width(); |
| 22 SkScalar h = rect.height(); | 22 SkScalar h = rect.height(); |
| 23 | 23 |
| 24 SkASSERT(0 == SkScalarMod(w, SK_Scalar1 * 5)); | 24 SkASSERT(0 == SkScalarMod(w, SK_Scalar1 * 5)); |
| 25 | 25 |
| 26 SkPoint c0 = { l + 2 * w / 5 + delta, t + h / 2 }; | 26 SkPoint c0 = { l + 2 * w / 5 + delta, t + h / 2 }; |
| 27 SkPoint c1 = { l + 3 * w / 5, t + h / 2 }; | 27 SkPoint c1 = { l + 3 * w / 5, t + h / 2 }; |
| 28 SkScalar r0 = w / 5; | 28 SkScalar r0 = w / 5; |
| 29 SkScalar r1 = 2 * w / 5; | 29 SkScalar r1 = 2 * w / 5; |
| 30 SkShader* s = SkGradientShader::CreateTwoPointConical(c0, r0, c1, r1, colors
, | |
| 31 pos, SK_ARRAY_COUNT(pos
), | |
| 32 SkShader::kClamp_TileMo
de); | |
| 33 SkPaint paint; | 30 SkPaint paint; |
| 34 paint.setShader(s)->unref(); | 31 paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors
, |
| 35 | 32 pos, SK_ARRAY_COUNT(po
s), |
| 33 SkShader::kClamp_TileM
ode)); |
| 36 canvas->drawRect(rect, paint); | 34 canvas->drawRect(rect, paint); |
| 37 } | 35 } |
| 38 | 36 |
| 39 | 37 |
| 40 class DegenerateTwoPtRadialsView : public SampleView { | 38 class DegenerateTwoPtRadialsView : public SampleView { |
| 41 public: | 39 public: |
| 42 DegenerateTwoPtRadialsView() { | 40 DegenerateTwoPtRadialsView() { |
| 43 fTime = 0; | 41 fTime = 0; |
| 44 this->setBGColor(0xFFDDDDDD); | 42 this->setBGColor(0xFFDDDDDD); |
| 45 } | 43 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 82 |
| 85 private: | 83 private: |
| 86 SkScalar fTime; | 84 SkScalar fTime; |
| 87 typedef SampleView INHERITED; | 85 typedef SampleView INHERITED; |
| 88 }; | 86 }; |
| 89 | 87 |
| 90 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
| 91 | 89 |
| 92 static SkView* MyFactory() { return new DegenerateTwoPtRadialsView; } | 90 static SkView* MyFactory() { return new DegenerateTwoPtRadialsView; } |
| 93 static SkViewRegister reg(MyFactory); | 91 static SkViewRegister reg(MyFactory); |
| OLD | NEW |