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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 data.fPos, data.fCount, tm); | 65 data.fPos, data.fCount, tm); |
66 } | 66 } |
67 | 67 |
68 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader:
:TileMode tm) { | 68 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader:
:TileMode tm) { |
69 SkPoint center; | 69 SkPoint center; |
70 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 70 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
71 SkScalarAve(pts[0].fY, pts[1].fY)); | 71 SkScalarAve(pts[0].fY, pts[1].fY)); |
72 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat
a.fPos, data.fCount); | 72 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat
a.fPos, data.fCount); |
73 } | 73 } |
74 | 74 |
75 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShade
r::TileMode tm) { | 75 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShad
er::TileMode tm) { |
76 SkPoint center0, center1; | 76 SkPoint center0, center1; |
77 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 77 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
78 SkScalarAve(pts[0].fY, pts[1].fY)); | 78 SkScalarAve(pts[0].fY, pts[1].fY)); |
79 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 79 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
80 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 80 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
81 return SkGradientShader::CreateTwoPointRadial( | 81 return SkGradientShader::CreateTwoPointConical( |
82 center1, (pts[1].fX - pts[0].fX) / 7, | 82 center1, (pts[1].fX - pts[0].fX) / 7, |
83 center0, (pts[1].fX - pts[0].fX) / 2, | 83 center0, (pts[1].fX - pts[0].fX) / 2, |
84 data.fColors, data.fPos, data.fCount, tm); | 84 data.fColors, data.fPos, data.fCount, tm); |
85 } | 85 } |
86 | 86 |
87 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha
der::TileMode tm); | 87 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha
der::TileMode tm); |
88 | 88 |
89 static const GradMaker gGradMakers[] = { | 89 static const GradMaker gGradMakers[] = { |
90 MakeLinear, MakeRadial, MakeSweep, Make2Radial | 90 MakeLinear, MakeRadial, MakeSweep, Make2Conical |
91 }; | 91 }; |
92 | 92 |
93 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
94 | 94 |
95 class ShaderTextView : public SampleView { | 95 class ShaderTextView : public SampleView { |
96 public: | 96 public: |
97 ShaderTextView() { | 97 ShaderTextView() { |
98 this->setBGColor(0xFFDDDDDD); | 98 this->setBGColor(0xFFDDDDDD); |
99 } | 99 } |
100 | 100 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 | 189 |
190 private: | 190 private: |
191 typedef SampleView INHERITED; | 191 typedef SampleView INHERITED; |
192 }; | 192 }; |
193 | 193 |
194 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
195 | 195 |
196 static SkView* MyFactory() { return new ShaderTextView; } | 196 static SkView* MyFactory() { return new ShaderTextView; } |
197 static SkViewRegister reg(MyFactory); | 197 static SkViewRegister reg(MyFactory); |
OLD | NEW |