blob: f8d74da8cc59fdca2ff59710e1b82c1d0716f95a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
bungemand3ebb482015-08-05 13:57:49 -07007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkRect.h"
14#include "include/core/SkScalar.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
reed@android.com048522d2009-06-23 12:19:41 +000017
18namespace skiagm {
19
20class FillTypeGM : public GM {
21 SkPath fPath;
22public:
rmistry@google.comd6176b02012-08-23 18:14:13 +000023 FillTypeGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040024 this->setBGColor(0xFFDDDDDD);
reed@google.comd42e3f62012-03-30 20:04:21 +000025 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000026
reed@google.comd42e3f62012-03-30 20:04:21 +000027 void makePath() {
28 if (fPath.isEmpty()) {
29 const SkScalar radius = SkIntToScalar(45);
30 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
31 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
32 }
reed@android.com048522d2009-06-23 12:19:41 +000033 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000034
reed@android.com048522d2009-06-23 12:19:41 +000035protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000036
mtklein36352bf2015-03-25 18:17:31 -070037 SkString onShortName() override {
reed@android.com048522d2009-06-23 12:19:41 +000038 return SkString("filltypes");
39 }
40
mtklein36352bf2015-03-25 18:17:31 -070041 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070042 return SkISize::Make(835, 840);
reed@android.com048522d2009-06-23 12:19:41 +000043 }
44
Mike Reed7d34dc72019-11-26 12:17:17 -050045 void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
reed@android.com048522d2009-06-23 12:19:41 +000046 SkScalar scale, const SkPaint& paint) {
reed@android.com048522d2009-06-23 12:19:41 +000047 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
48
49 canvas->save();
50 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
51 canvas->clipRect(r);
52 canvas->drawColor(SK_ColorWHITE);
53 fPath.setFillType(ft);
54 canvas->translate(r.centerX(), r.centerY());
55 canvas->scale(scale, scale);
56 canvas->translate(-r.centerX(), -r.centerY());
57 canvas->drawPath(fPath, paint);
58 canvas->restore();
59 }
60
61 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
Mike Reed7d34dc72019-11-26 12:17:17 -050062 showPath(canvas, 0, 0, SkPathFillType::kWinding,
reed@android.com048522d2009-06-23 12:19:41 +000063 scale, paint);
Mike Reed7d34dc72019-11-26 12:17:17 -050064 showPath(canvas, 200, 0, SkPathFillType::kEvenOdd,
reed@android.com048522d2009-06-23 12:19:41 +000065 scale, paint);
Mike Reed7d34dc72019-11-26 12:17:17 -050066 showPath(canvas, 00, 200, SkPathFillType::kInverseWinding,
reed@android.com048522d2009-06-23 12:19:41 +000067 scale, paint);
Mike Reed7d34dc72019-11-26 12:17:17 -050068 showPath(canvas, 200, 200, SkPathFillType::kInverseEvenOdd,
reed@android.com048522d2009-06-23 12:19:41 +000069 scale, paint);
70 }
71
mtklein36352bf2015-03-25 18:17:31 -070072 void onDraw(SkCanvas* canvas) override {
reed@google.comd42e3f62012-03-30 20:04:21 +000073 this->makePath();
74
reed@android.com048522d2009-06-23 12:19:41 +000075 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
rmistry@google.comd6176b02012-08-23 18:14:13 +000076
reed@android.com048522d2009-06-23 12:19:41 +000077 SkPaint paint;
78 const SkScalar scale = SkIntToScalar(5)/4;
79
80 paint.setAntiAlias(false);
81
82 showFour(canvas, SK_Scalar1, paint);
83 canvas->translate(SkIntToScalar(450), 0);
84 showFour(canvas, scale, paint);
85
86 paint.setAntiAlias(true);
87
88 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
89 showFour(canvas, SK_Scalar1, paint);
90 canvas->translate(SkIntToScalar(450), 0);
91 showFour(canvas, scale, paint);
92 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000093
reed@android.com048522d2009-06-23 12:19:41 +000094private:
95 typedef GM INHERITED;
96};
97
98//////////////////////////////////////////////////////////////////////////////
99
Hal Canarye964c182019-01-23 10:22:01 -0500100DEF_GM( return new FillTypeGM; )
reed@android.com048522d2009-06-23 12:19:41 +0000101
102}