Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
MegaStrokeSlide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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 "src/base/SkRandom.h"
11#include "tools/viewer/Slide.h"
12
13class MegaStrokeSlide : public Slide {
14public:
16 fClip.setLTRB(0, 0, 950, 600);
17 fAngle = 0;
18 fPlusMinus = 0;
19 SkRandom rand;
20 fMegaPath.reset();
21 for (int index = 0; index < 921; ++index) {
22 for (int segs = 0; segs < 40; ++segs) {
23 fMegaPath.lineTo(SkIntToScalar(index), SkIntToScalar(rand.nextRangeU(500, 600)));
24 }
25 }
26 fName = "MegaStroke";
27 }
28
29 bool onChar(SkUnichar uni) override {
30 fClip.setLTRB(0, 0, 950, 600);
31 return true;
32 }
33
34 void draw(SkCanvas* canvas) override {
36 paint.setAntiAlias(true);
37 paint.setARGB(255,255,153,0);
39 paint.setStrokeWidth(1);
40
41 canvas->save();
42 canvas->clipRect(fClip);
43 canvas->clear(SK_ColorWHITE);
44 canvas->drawPath(fMegaPath, paint);
45 canvas->restore();
46
47 SkPaint divSimPaint;
48 divSimPaint.setColor(SK_ColorBLUE);
49 SkScalar x = SkScalarSin(fAngle * SK_ScalarPI / 180) * 200 + 250;
50 SkScalar y = SkScalarCos(fAngle * SK_ScalarPI / 180) * 200 + 250;
51
52 if ((fPlusMinus ^= 1)) {
53 fAngle += 5;
54 } else {
55 fAngle -= 5;
56 }
57 SkRect divSim = SkRect::MakeXYWH(x, y, 100, 100);
58 divSim.outset(30, 30);
59 canvas->drawRect(divSim, divSimPaint);
60 fClip = divSim;
61 }
62
63 void resize(SkScalar w, SkScalar h) override { fClip.setWH(950, 600); }
64
65 bool animate(double /*nanos*/) override { return true; }
66
67private:
68 SkPath fMegaPath;
69 SkRect fClip;
70 int fAngle;
71 int fPlusMinus;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
76DEF_SLIDE( return new MegaStrokeSlide(); )
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
#define SkScalarSin(radians)
Definition SkScalar.h:45
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define SkScalarCos(radians)
Definition SkScalar.h:46
#define SK_ScalarPI
Definition SkScalar.h:21
int32_t SkUnichar
Definition SkTypes.h:175
#define DEF_SLIDE(code)
Definition Slide.h:25
void resize(SkScalar w, SkScalar h) override
bool onChar(SkUnichar uni) override
void draw(SkCanvas *canvas) override
bool animate(double) override
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void clear(SkColor color)
Definition SkCanvas.h:1199
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
void setColor(SkColor color)
Definition SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
SkPath & reset()
Definition SkPath.cpp:360
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition SkRandom.h:80
Definition Slide.h:29
SkString fName
Definition Slide.h:54
const Paint & paint
float SkScalar
Definition extension.cpp:12
double y
double x
SkScalar w
SkScalar h
void outset(float dx, float dy)
Definition SkRect.h:1077
void setWH(float width, float height)
Definition SkRect.h:944
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865