OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
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" |
11 #include "Sk64.h" | 11 #include "Sk64.h" |
12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
| 13 #include "SkString.h" |
13 | 14 |
14 static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta)
{ | 15 static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta)
{ |
15 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGEN
TA }; | 16 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGEN
TA }; |
16 SkScalar pos[] = { 0, SkFloatToScalar(0.25f), SkFloatToScalar(0.75f), SK_Sca
lar1 }; | 17 SkScalar pos[] = { 0, SkFloatToScalar(0.25f), SkFloatToScalar(0.75f), SK_Sca
lar1 }; |
17 | 18 |
18 SkScalar l = rect.fLeft; | 19 SkScalar l = rect.fLeft; |
19 SkScalar t = rect.fTop; | 20 SkScalar t = rect.fTop; |
20 SkScalar w = rect.width(); | 21 SkScalar w = rect.width(); |
21 SkScalar h = rect.height(); | 22 SkScalar h = rect.height(); |
22 | 23 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 65 } |
65 delta -= SK_ScalarHalf; | 66 delta -= SK_ScalarHalf; |
66 static const int DELTA_SCALE = 500; | 67 static const int DELTA_SCALE = 500; |
67 delta /= DELTA_SCALE; | 68 delta /= DELTA_SCALE; |
68 | 69 |
69 SkScalar w = SK_Scalar1 * 500; | 70 SkScalar w = SK_Scalar1 * 500; |
70 SkScalar h = SK_Scalar1 * 500; | 71 SkScalar h = SK_Scalar1 * 500; |
71 SkScalar l = SK_Scalar1 * 100; | 72 SkScalar l = SK_Scalar1 * 100; |
72 SkScalar t = SK_Scalar1 * 100; | 73 SkScalar t = SK_Scalar1 * 100; |
73 draw_gradient2(canvas, SkRect::MakeXYWH(l, t, w, h), delta); | 74 draw_gradient2(canvas, SkRect::MakeXYWH(l, t, w, h), delta); |
74 char txt[512]; | 75 SkString txt; |
75 sprintf(txt, "gap at \"tangent\" pt = %f", SkScalarToFloat(delta)); | 76 txt.appendf("gap at \"tangent\" pt = %f", SkScalarToFloat(delta)); |
76 SkPaint paint; | 77 SkPaint paint; |
77 paint.setAntiAlias(true); | 78 paint.setAntiAlias(true); |
78 paint.setColor(SK_ColorBLACK); | 79 paint.setColor(SK_ColorBLACK); |
79 canvas->drawText(txt, strlen(txt), l + w/2 + w*DELTA_SCALE*delta, t + h
+ SK_Scalar1 * 10, paint); | 80 canvas->drawText(txt.c_str(), txt.size(), l + w/2 + w*DELTA_SCALE*delta,
t + h + SK_Scalar1 * 10, paint); |
80 this->inval(NULL); | 81 this->inval(NULL); |
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 |