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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 data.fPos, data.fCount, tm); | 75 data.fPos, data.fCount, tm); |
76 } | 76 } |
77 | 77 |
78 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader:
:TileMode tm) { | 78 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader:
:TileMode tm) { |
79 SkPoint center; | 79 SkPoint center; |
80 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 80 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
81 SkScalarAve(pts[0].fY, pts[1].fY)); | 81 SkScalarAve(pts[0].fY, pts[1].fY)); |
82 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat
a.fPos, data.fCount); | 82 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat
a.fPos, data.fCount); |
83 } | 83 } |
84 | 84 |
85 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShade
r::TileMode tm) { | 85 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShad
er::TileMode tm) { |
86 SkPoint center0, center1; | 86 SkPoint center0, center1; |
87 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 87 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
88 SkScalarAve(pts[0].fY, pts[1].fY)); | 88 SkScalarAve(pts[0].fY, pts[1].fY)); |
89 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 89 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
90 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 90 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
91 return SkGradientShader::CreateTwoPointRadial( | 91 return SkGradientShader::CreateTwoPointConical( |
92 center1, (pts[1].fX - pts[0].fX) / 7, | 92 center1, (pts[1].fX - pts[0].fX) / 7, |
93 center0, (pts[1].fX - pts[0].fX) / 2, | 93 center0, (pts[1].fX - pts[0].fX) / 2, |
94 data.fColors, data.fPos, data.fCount, tm); | 94 data.fColors, data.fPos, data.fCount, tm); |
95 } | 95 } |
96 | 96 |
97 static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& dat
a, | 97 static SkShader* Make2ConicalConcentric(const SkPoint pts[2], const GradData& da
ta, |
98 SkShader::TileMode tm) { | 98 SkShader::TileMode tm) { |
99 SkPoint center; | 99 SkPoint center; |
100 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 100 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
101 SkScalarAve(pts[0].fY, pts[1].fY)); | 101 SkScalarAve(pts[0].fY, pts[1].fY)); |
102 return SkGradientShader::CreateTwoPointRadial( | 102 return SkGradientShader::CreateTwoPointConical( |
103 center, (pts[1].fX - pts[0].fX) / 7, | 103 center, (pts[1].fX - pts[0].fX) / 7, |
104 center, (pts[1].fX - pts[0].fX) / 2, | 104 center, (pts[1].fX - pts[0].fX) / 2, |
105 data.fColors, data.fPos, data.fCount, tm); | 105 data.fColors, data.fPos, data.fCount, tm); |
106 } | 106 } |
107 | 107 |
108 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha
der::TileMode tm); | 108 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha
der::TileMode tm); |
109 | 109 |
110 static const GradMaker gGradMakers[] = { | 110 static const GradMaker gGradMakers[] = { |
111 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric | 111 MakeLinear, MakeRadial, MakeSweep, Make2Conical, Make2ConicalConcentric |
112 }; | 112 }; |
113 | 113 |
114 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
115 | 115 |
116 class GradientsView : public SampleView { | 116 class GradientsView : public SampleView { |
117 public: | 117 public: |
118 GradientsView() { | 118 GradientsView() { |
119 this->setBGColor(0xFFDDDDDD); | 119 this->setBGColor(0xFFDDDDDD); |
120 } | 120 } |
121 | 121 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 private: | 170 private: |
171 typedef SampleView INHERITED; | 171 typedef SampleView INHERITED; |
172 }; | 172 }; |
173 | 173 |
174 /////////////////////////////////////////////////////////////////////////////// | 174 /////////////////////////////////////////////////////////////////////////////// |
175 | 175 |
176 static SkView* MyFactory() { return new GradientsView; } | 176 static SkView* MyFactory() { return new GradientsView; } |
177 static SkViewRegister reg(MyFactory); | 177 static SkViewRegister reg(MyFactory); |
OLD | NEW |