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 "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return SkGradientShader::CreateTwoPointConical( | 73 return SkGradientShader::CreateTwoPointConical( |
74 center1, (pts[1].fX - pts[0].
fX) / 7, | 74 center1, (pts[1].fX - pts[0].
fX) / 7, |
75 center0, (pts[1].fX - pts[0].
fX) / 2, | 75 center0, (pts[1].fX - pts[0].
fX) / 2, |
76 data.fColors, data.fPos, data
.fCount, tm, | 76 data.fColors, data.fPos, data
.fCount, tm, |
77 0, &localMatrix); | 77 0, &localMatrix); |
78 } | 78 } |
79 | 79 |
80 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, | 80 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, |
81 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 81 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
82 SkPoint center0, center1; | 82 SkPoint center0, center1; |
83 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 83 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
84 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 84 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
87 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 87 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
88 center0, radius0, | 88 center0, radius0, |
89 data.fColors, data.fPos, | 89 data.fColors, data.fPos, |
90 data.fCount, tm, 0, &localMat
rix); | 90 data.fCount, tm, 0, &localMat
rix); |
91 } | 91 } |
92 | 92 |
93 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 93 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
94 SkShader::TileMode tm, const SkMatrix& localMatri
x); | 94 SkShader::TileMode tm, const SkMatrix& localMatri
x); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 SkPaint paint; | 178 SkPaint paint; |
179 paint.setAntiAlias(true); | 179 paint.setAntiAlias(true); |
180 | 180 |
181 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 181 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
182 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 182 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
183 canvas->save(); | 183 canvas->save(); |
184 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { | 184 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
185 // apply an increasing y perspective as we move to the right | 185 // apply an increasing y perspective as we move to the right |
186 SkMatrix perspective; | 186 SkMatrix perspective; |
187 perspective.setIdentity(); | 187 perspective.setIdentity(); |
188 perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1), | 188 perspective.setPerspY(SkIntToScalar(i+1) / 500); |
189 SkIntToScalar(500))); | 189 perspective.setSkewX(SkIntToScalar(i+1) / 10); |
190 perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1), | |
191 SkIntToScalar(10))); | |
192 | 190 |
193 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspec
tive); | 191 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspec
tive); |
194 | 192 |
195 paint.setShader(shader); | 193 paint.setShader(shader); |
196 canvas->drawRect(r, paint); | 194 canvas->drawRect(r, paint); |
197 shader->unref(); | 195 shader->unref(); |
198 canvas->translate(0, SkIntToScalar(120)); | 196 canvas->translate(0, SkIntToScalar(120)); |
199 } | 197 } |
200 canvas->restore(); | 198 canvas->restore(); |
201 canvas->translate(SkIntToScalar(120), 0); | 199 canvas->translate(SkIntToScalar(120), 0); |
(...skipping 11 matching lines...) Expand all Loading... |
213 protected: | 211 protected: |
214 SkString onShortName() { | 212 SkString onShortName() { |
215 return SkString("gradients_view_perspective"); | 213 return SkString("gradients_view_perspective"); |
216 } | 214 } |
217 | 215 |
218 virtual SkISize onISize() { return SkISize::Make(840, 500); } | 216 virtual SkISize onISize() { return SkISize::Make(840, 500); } |
219 | 217 |
220 virtual void onDraw(SkCanvas* canvas) { | 218 virtual void onDraw(SkCanvas* canvas) { |
221 SkMatrix perspective; | 219 SkMatrix perspective; |
222 perspective.setIdentity(); | 220 perspective.setIdentity(); |
223 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); | 221 perspective.setPerspY(0.001f); |
224 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25))); | 222 perspective.setSkewX(SkIntToScalar(8) / 25); |
225 canvas->concat(perspective); | 223 canvas->concat(perspective); |
226 INHERITED::onDraw(canvas); | 224 INHERITED::onDraw(canvas); |
227 } | 225 } |
228 | 226 |
229 private: | 227 private: |
230 typedef GradientsGM INHERITED; | 228 typedef GradientsGM INHERITED; |
231 }; | 229 }; |
232 DEF_GM( return new GradientsViewPerspectiveGM; ) | 230 DEF_GM( return new GradientsViewPerspectiveGM; ) |
233 | 231 |
234 /* | 232 /* |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 paint.setShader(fShader); | 454 paint.setShader(fShader); |
457 canvas->drawRect(SkRect::MakeWH(500, 500), paint); | 455 canvas->drawRect(SkRect::MakeWH(500, 500), paint); |
458 } | 456 } |
459 | 457 |
460 private: | 458 private: |
461 typedef GM INHERITED; | 459 typedef GM INHERITED; |
462 }; | 460 }; |
463 DEF_GM( return new RadialGradient3GM; ) | 461 DEF_GM( return new RadialGradient3GM; ) |
464 | 462 |
465 } | 463 } |
OLD | NEW |