Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
filltypes.cpp
Go to the documentation of this file.
1/*
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 */
7
8#include "gm/gm.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
17
18namespace skiagm {
19
20class FillTypeGM : public GM {
21 SkPath fPath;
22public:
24 this->setBGColor(0xFFDDDDDD);
25 }
26
27 void makePath() {
28 if (fPath.isEmpty()) {
29 const SkScalar radius = SkIntToScalar(45);
31 .addCircle(SkIntToScalar(100), SkIntToScalar(100), radius)
32 .detach();
33 }
34 }
35
36protected:
37 SkString getName() const override { return SkString("filltypes"); }
38
39 SkISize getISize() override { return SkISize::Make(835, 840); }
40
41 void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
42 SkScalar scale, const SkPaint& paint) {
43 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
44
45 canvas->save();
47 canvas->clipRect(r);
48 canvas->drawColor(SK_ColorWHITE);
50 canvas->translate(r.centerX(), r.centerY());
51 canvas->scale(scale, scale);
52 canvas->translate(-r.centerX(), -r.centerY());
53 canvas->drawPath(fPath, paint);
54 canvas->restore();
55 }
56
57 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
59 scale, paint);
60 showPath(canvas, 200, 0, SkPathFillType::kEvenOdd,
61 scale, paint);
63 scale, paint);
65 scale, paint);
66 }
67
68 void onDraw(SkCanvas* canvas) override {
69 this->makePath();
70
71 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
72
74 const SkScalar scale = SkIntToScalar(5)/4;
75
76 paint.setAntiAlias(false);
77
78 showFour(canvas, SK_Scalar1, paint);
79 canvas->translate(SkIntToScalar(450), 0);
80 showFour(canvas, scale, paint);
81
82 paint.setAntiAlias(true);
83
84 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
85 showFour(canvas, SK_Scalar1, paint);
86 canvas->translate(SkIntToScalar(450), 0);
87 showFour(canvas, scale, paint);
88 }
89
90private:
91 using INHERITED = GM;
92};
93
94//////////////////////////////////////////////////////////////////////////////
95
96DEF_GM( return new FillTypeGM; )
97
98} // namespace skiagm
SkPath fPath
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
SkPathFillType
Definition SkPathTypes.h:11
#define SK_Scalar1
Definition SkScalar.h:18
#define SkIntToScalar(x)
Definition SkScalar.h:57
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
void scale(SkScalar sx, SkScalar sy)
SkPathBuilder & addCircle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
bool isEmpty() const
Definition SkPath.cpp:406
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
SkString getName() const override
Definition filltypes.cpp:37
void showPath(SkCanvas *canvas, int x, int y, SkPathFillType ft, SkScalar scale, const SkPaint &paint)
Definition filltypes.cpp:41
SkISize getISize() override
Definition filltypes.cpp:39
void onDraw(SkCanvas *canvas) override
Definition filltypes.cpp:68
void showFour(SkCanvas *canvas, SkScalar scale, const SkPaint &paint)
Definition filltypes.cpp:57
void setBGColor(SkColor)
Definition gm.cpp:159
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
double y
double x
const Scalar scale
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
constexpr float centerX() const
Definition SkRect.h:776
constexpr float centerY() const
Definition SkRect.h:785