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" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkDevice.h" | 12 #include "SkDevice.h" |
13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
14 #include "SkRandom.h" | 14 #include "SkRandom.h" |
15 | 15 |
16 #define W 150 | 16 #define W 150 |
17 #define H 200 | 17 #define H 200 |
18 | 18 |
19 static void show_text(SkCanvas* canvas, bool doAA) { | 19 static void show_text(SkCanvas* canvas, bool doAA) { |
20 SkMWCRandom rand; | 20 SkRandom rand; |
21 SkPaint paint; | 21 SkPaint paint; |
22 paint.setAntiAlias(doAA); | 22 paint.setAntiAlias(doAA); |
23 paint.setLCDRenderText(true); | 23 paint.setLCDRenderText(true); |
24 paint.setTextSize(SkIntToScalar(20)); | 24 paint.setTextSize(SkIntToScalar(20)); |
25 | 25 |
26 for (int i = 0; i < 200; ++i) { | 26 for (int i = 0; i < 200; ++i) { |
27 paint.setColor((SK_A32_MASK << SK_A32_SHIFT) | rand.nextU()); | 27 paint.setColor((SK_A32_MASK << SK_A32_SHIFT) | rand.nextU()); |
28 canvas->drawText("Hamburgefons", 12, | 28 canvas->drawText("Hamburgefons", 12, |
29 rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20, | 29 rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20, |
30 paint); | 30 paint); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 static void show_fill(SkCanvas* canvas, bool doAA) { | 34 static void show_fill(SkCanvas* canvas, bool doAA) { |
35 SkMWCRandom rand; | 35 SkRandom rand; |
36 SkPaint paint; | 36 SkPaint paint; |
37 paint.setAntiAlias(doAA); | 37 paint.setAntiAlias(doAA); |
38 | 38 |
39 for (int i = 0; i < 50; ++i) { | 39 for (int i = 0; i < 50; ++i) { |
40 SkRect r; | 40 SkRect r; |
41 SkPath p; | 41 SkPath p; |
42 | 42 |
43 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, | 43 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, |
44 rand.nextUScalar1() * W, rand.nextUScalar1() * H); | 44 rand.nextUScalar1() * W, rand.nextUScalar1() * H); |
45 paint.setColor(rand.nextU()); | 45 paint.setColor(rand.nextU()); |
46 canvas->drawRect(r, paint); | 46 canvas->drawRect(r, paint); |
47 | 47 |
48 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, | 48 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, |
49 rand.nextUScalar1() * W, rand.nextUScalar1() * H); | 49 rand.nextUScalar1() * W, rand.nextUScalar1() * H); |
50 paint.setColor(rand.nextU()); | 50 paint.setColor(rand.nextU()); |
51 p.addOval(r); | 51 p.addOval(r); |
52 canvas->drawPath(p, paint); | 52 canvas->drawPath(p, paint); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 static SkScalar randRange(SkMWCRandom& rand, SkScalar min, SkScalar max) { | 56 static SkScalar randRange(SkRandom& rand, SkScalar min, SkScalar max) { |
57 SkASSERT(min <= max); | 57 SkASSERT(min <= max); |
58 return min + SkScalarMul(rand.nextUScalar1(), max - min); | 58 return min + SkScalarMul(rand.nextUScalar1(), max - min); |
59 } | 59 } |
60 | 60 |
61 static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n
) { | 61 static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n
) { |
62 SkMWCRandom rand; | 62 SkRandom rand; |
63 SkPaint paint; | 63 SkPaint paint; |
64 paint.setAntiAlias(doAA); | 64 paint.setAntiAlias(doAA); |
65 paint.setStyle(SkPaint::kStroke_Style); | 65 paint.setStyle(SkPaint::kStroke_Style); |
66 paint.setStrokeWidth(strokeWidth); | 66 paint.setStrokeWidth(strokeWidth); |
67 | 67 |
68 for (int i = 0; i < n; ++i) { | 68 for (int i = 0; i < n; ++i) { |
69 SkRect r; | 69 SkRect r; |
70 SkPath p; | 70 SkPath p; |
71 | 71 |
72 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, | 72 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 private: | 157 private: |
158 typedef SampleView INHERITED; | 158 typedef SampleView INHERITED; |
159 }; | 159 }; |
160 | 160 |
161 ////////////////////////////////////////////////////////////////////////////// | 161 ////////////////////////////////////////////////////////////////////////////// |
162 | 162 |
163 static SkView* MyFactory() { return new ClipView; } | 163 static SkView* MyFactory() { return new ClipView; } |
164 static SkViewRegister reg(MyFactory); | 164 static SkViewRegister reg(MyFactory); |
OLD | NEW |