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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkUnitMappers.h" | 10 #include "SkUnitMappers.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 localMatrices.append()->fMatrix.reset(); | 88 localMatrices.append()->fMatrix.reset(); |
89 localMatrices.top().fMatrix.setPerspX(-0.007f); | 89 localMatrices.top().fMatrix.setPerspX(-0.007f); |
90 localMatrices.top().fMatrix.setPerspY(+0.008f); | 90 localMatrices.top().fMatrix.setPerspY(+0.008f); |
91 localMatrices.top().fLabel = "Persp"; | 91 localMatrices.top().fLabel = "Persp"; |
92 | 92 |
93 static SkBitmap bmp; | 93 static SkBitmap bmp; |
94 if (bmp.isNull()) { | 94 if (bmp.isNull()) { |
95 makebm(&bmp, kPointSize / 2, kPointSize / 2); | 95 makebm(&bmp, kPointSize / 2, kPointSize / 2); |
96 } | 96 } |
97 | 97 |
98 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(bmp, | |
99 SkShader::kMi
rror_TileMode, | |
100 SkShader::kRe
peat_TileMode)); | |
101 SkPaint fillPaint; | 98 SkPaint fillPaint; |
102 fillPaint.setAntiAlias(true); | 99 fillPaint.setAntiAlias(true); |
103 fillPaint.setTextSize(SkIntToScalar(kPointSize)); | 100 fillPaint.setTextSize(SkIntToScalar(kPointSize)); |
104 fillPaint.setFilterLevel(SkPaint::kLow_FilterLevel); | 101 fillPaint.setFilterLevel(SkPaint::kLow_FilterLevel); |
105 fillPaint.setShader(shader); | |
106 | 102 |
107 SkPaint outlinePaint; | 103 SkPaint outlinePaint; |
108 outlinePaint.setAntiAlias(true); | 104 outlinePaint.setAntiAlias(true); |
109 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); | 105 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); |
110 outlinePaint.setStyle(SkPaint::kStroke_Style); | 106 outlinePaint.setStyle(SkPaint::kStroke_Style); |
111 outlinePaint.setStrokeWidth(0.f); | 107 outlinePaint.setStrokeWidth(0.f); |
112 | 108 |
113 SkScalar w = fillPaint.measureText(kText, kTextLen); | 109 SkScalar w = fillPaint.measureText(kText, kTextLen); |
114 static SkScalar kPadY = 0.5f * kPointSize; | 110 static SkScalar kPadY = 0.5f * kPointSize; |
115 static SkScalar kPadX = 1.5f * kPointSize; | 111 static SkScalar kPadX = 1.5f * kPointSize; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 147 |
152 SkScalar columnH = 0; | 148 SkScalar columnH = 0; |
153 for (int m = 0; m < matrices.count(); ++m) { | 149 for (int m = 0; m < matrices.count(); ++m) { |
154 columnH = 0; | 150 columnH = 0; |
155 canvas->save(); | 151 canvas->save(); |
156 canvas->drawText(matrices[m].fLabel, strlen(matrices[m].fLabel), | 152 canvas->drawText(matrices[m].fLabel, strlen(matrices[m].fLabel), |
157 0, labelPaint.getTextSize() - 1, labelPaint); | 153 0, labelPaint.getTextSize() - 1, labelPaint); |
158 canvas->translate(0, kPadY / 2 + kPointSize); | 154 canvas->translate(0, kPadY / 2 + kPointSize); |
159 columnH += kPadY / 2 + kPointSize; | 155 columnH += kPadY / 2 + kPointSize; |
160 for (int lm = 0; lm < localMatrices.count(); ++lm) { | 156 for (int lm = 0; lm < localMatrices.count(); ++lm) { |
161 shader->setLocalMatrix(localMatrices[lm].fMatrix); | 157 paint.setShader(SkShader::CreateBitmapShader(bmp, |
| 158 SkShader::kMirr
or_TileMode, |
| 159 SkShader::kRepe
at_TileMode, |
| 160 &localMatrices[
lm].fMatrix)); |
162 | 161 |
163 canvas->save(); | 162 canvas->save(); |
164 canvas->concat(matrices[m].fMatrix); | 163 canvas->concat(matrices[m].fMatrix); |
165 canvas->drawText(kText, kTextLen, 0, 0, paint); | 164 canvas->drawText(kText, kTextLen, 0, 0, paint); |
166 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); | 165 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); |
167 canvas->restore(); | 166 canvas->restore(); |
168 | 167 |
169 SkPath path; | 168 SkPath path; |
170 path.arcTo(SkRect::MakeXYWH(-0.1f * w, 0.f, | 169 path.arcTo(SkRect::MakeXYWH(-0.1f * w, 0.f, |
171 1.2f * w, 2.f * kPointSize), | 170 1.2f * w, 2.f * kPointSize), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 209 |
211 private: | 210 private: |
212 typedef GM INHERITED; | 211 typedef GM INHERITED; |
213 }; | 212 }; |
214 | 213 |
215 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
216 | 215 |
217 static GM* MyFactory(void*) { return new ShaderText2GM; } | 216 static GM* MyFactory(void*) { return new ShaderText2GM; } |
218 static GMRegistry reg(MyFactory); | 217 static GMRegistry reg(MyFactory); |
219 } | 218 } |
OLD | NEW |