Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathEffectsSlide.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
10#include "include/core/SkPath.h"
18#include "src/base/SkRandom.h"
19#include "src/base/SkUTF.h"
21#include "tools/viewer/Slide.h"
22
23#define CORNER_RADIUS 12
24
25static const int gXY[] = {
26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
27};
28
30 if (flags == 1) {
32 }
33
34 SkPath path;
35 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
36 for (unsigned i = 2; i < std::size(gXY); i += 2)
37 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
38 path.close();
39 path.offset(SkIntToScalar(-6), 0);
40
42
43 if (flags == 2)
44 return outer;
45
47
48 return SkPathEffect::MakeCompose(outer, inner);
49}
50
52 SkPath path;
53 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
54 for (unsigned i = 2; i < std::size(gXY); i += 2) {
55 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
56 }
57 path.close();
58 path.offset(SkIntToScalar(-6), 0);
59
60 auto outer = SkPath1DPathEffect::Make(
61 path, 12, phase, SkPath1DPathEffect::kMorph_Style);
63
64 return SkPathEffect::MakeCompose(outer, inner);
65}
66
67///////////////////////////////////////////////////////////
68
70
71class PathEffectSlide : public Slide {
72 SkPath fPath;
73 SkPoint fClickPt;
74 SkScalar fPhase;
75
76public:
77 PathEffectSlide() : fPhase(0) { fName = "PathEffects"; }
78
79 void load(SkScalar w, SkScalar h) override {
80 SkRandom rand;
81 int steps = 20;
82 SkScalar dist = SkIntToScalar(400);
85
86 fPath.moveTo(x, y);
87 for (int i = 0; i < steps; i++) {
88 x += dist/steps;
89 SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25);
90 if (i == steps/2) {
91 fPath.moveTo(x, tmpY);
92 } else {
93 fPath.lineTo(x, tmpY);
94 }
95 }
96
97 {
98 SkRect oval;
99 oval.setLTRB(20, 30, 100, 60);
100 oval.offset(x, 0);
102 }
103
104 fClickPt.set(SkIntToScalar(200), SkIntToScalar(200));
105 }
106
107 void draw(SkCanvas* canvas) override {
108 canvas->clear(0xFFDDDDDD);
109
111
112 canvas->translate(0, 50);
113
114 paint.setColor(SK_ColorBLUE);
115 paint.setPathEffect(make_pe(2, fPhase));
116 canvas->drawPath(fPath, paint);
117
118 canvas->translate(0, 50);
119
120 paint.setARGB(0xFF, 0, 0xBB, 0);
121 paint.setPathEffect(make_pe(3, fPhase));
122 canvas->drawPath(fPath, paint);
123
124 canvas->translate(0, 50);
125
126 paint.setARGB(0xFF, 0, 0, 0);
127 paint.setPathEffect(make_warp_pe(fPhase));
128 canvas->drawPath(fPath, paint);
129 }
130
131 bool animate(double nanos) override {
132 fPhase = TimeUtils::Scaled(1e-9 * nanos, 40);
133 return true;
134 }
135};
136
137//////////////////////////////////////////////////////////////////////////////
138
139DEF_SLIDE( return new PathEffectSlide(); )
SkPath fPath
static sk_sp< SkPathEffect > make_pe(int flags, SkScalar phase)
static sk_sp< SkPathEffect > make_warp_pe(SkScalar phase)
static const int gXY[]
#define CORNER_RADIUS
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define DEF_SLIDE(code)
Definition Slide.h:25
void load(SkScalar w, SkScalar h) override
bool animate(double nanos) override
void draw(SkCanvas *canvas) override
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
static sk_sp< SkPathEffect > Make(SkScalar radius)
static sk_sp< SkPathEffect > Make(const SkPath &path, SkScalar advance, SkScalar phase, Style)
static sk_sp< SkPathEffect > MakeCompose(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
SkPath & addRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:1088
int32_t nextS()
Definition SkRandom.h:50
Definition Slide.h:29
SkString fName
Definition Slide.h:54
const Paint & paint
float SkScalar
Definition extension.cpp:12
FlutterSemanticsFlag flags
double y
double x
static float Scaled(float time, float speed, float period=0)
Definition TimeUtils.h:27
SkScalar w
SkScalar h
void set(float x, float y)
void offset(float dx, float dy)
Definition SkRect.h:1016
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865