blob: e096a6b1fc0df37de43dfbccf8476ea16998e26c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com048522d2009-06-23 12:19:41 +00008#include "gm.h"
9
10namespace skiagm {
11
12class FillTypeGM : public GM {
13 SkPath fPath;
14public:
15 FillTypeGM() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000016 this->setBGColor(0xFFDDDDDD);
reed@google.comd42e3f62012-03-30 20:04:21 +000017 }
18
19 void makePath() {
20 if (fPath.isEmpty()) {
21 const SkScalar radius = SkIntToScalar(45);
22 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
23 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
24 }
reed@android.com048522d2009-06-23 12:19:41 +000025 }
26
27protected:
28 virtual SkString onShortName() {
29 return SkString("filltypes");
30 }
31
32 virtual SkISize onISize() {
33 return make_isize(835, 840);
34 }
35
36 void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
37 SkScalar scale, const SkPaint& paint) {
38
39 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
40
41 canvas->save();
42 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
43 canvas->clipRect(r);
44 canvas->drawColor(SK_ColorWHITE);
45 fPath.setFillType(ft);
46 canvas->translate(r.centerX(), r.centerY());
47 canvas->scale(scale, scale);
48 canvas->translate(-r.centerX(), -r.centerY());
49 canvas->drawPath(fPath, paint);
50 canvas->restore();
51 }
52
53 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
54 showPath(canvas, 0, 0, SkPath::kWinding_FillType,
55 scale, paint);
56 showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType,
57 scale, paint);
58 showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType,
59 scale, paint);
60 showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
61 scale, paint);
62 }
63
64 virtual void onDraw(SkCanvas* canvas) {
reed@google.comd42e3f62012-03-30 20:04:21 +000065 this->makePath();
66
reed@android.com048522d2009-06-23 12:19:41 +000067 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
68
69 SkPaint paint;
70 const SkScalar scale = SkIntToScalar(5)/4;
71
72 paint.setAntiAlias(false);
73
74 showFour(canvas, SK_Scalar1, paint);
75 canvas->translate(SkIntToScalar(450), 0);
76 showFour(canvas, scale, paint);
77
78 paint.setAntiAlias(true);
79
80 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
81 showFour(canvas, SK_Scalar1, paint);
82 canvas->translate(SkIntToScalar(450), 0);
83 showFour(canvas, scale, paint);
84 }
85
86private:
87 typedef GM INHERITED;
88};
89
90//////////////////////////////////////////////////////////////////////////////
91
92static GM* MyFactory(void*) { return new FillTypeGM; }
93static GMRegistry reg(MyFactory);
94
95}
96