Debian Codegraph @

tools/viewer/MegaStrokeSlide.cpp

raw
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
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkPath.h"
10 #include "include/core/SkPathBuilder.h"
11 #include "src/base/SkRandom.h"
12 #include "tools/viewer/Slide.h"
13
14 class MegaStrokeSlide : public Slide {
15 public:
16 MegaStrokeSlide() {
17 fClip.setLTRB(0, 0, 950, 600);
18 fAngle = 0;
19 fPlusMinus = 0;
20 SkRandom rand;
21 SkPathBuilder builder;
22 for (int index = 0; index < 921; ++index) {
23 for (int segs = 0; segs < 40; ++segs) {
24 builder.lineTo(SkIntToScalar(index), SkIntToScalar(rand.nextRangeU(500, 600)));
25 }
26 }
27 fMegaPath = builder.detach();
28 fName = "MegaStroke";
29 }
30
31 bool onChar(SkUnichar uni) override {
32 fClip.setLTRB(0, 0, 950, 600);
33 return true;
34 }
35
36 void draw(SkCanvas* canvas) override {
37 SkPaint paint;
38 paint.setAntiAlias(true);
39 paint.setARGB(255,255,153,0);
40 paint.setStyle(SkPaint::kStroke_Style);
41 paint.setStrokeWidth(1);
42
43 canvas->save();
44 canvas->clipRect(fClip);
45 canvas->clear(SK_ColorWHITE);
46 canvas->drawPath(fMegaPath, paint);
47 canvas->restore();
48
49 SkPaint divSimPaint;
50 divSimPaint.setColor(SK_ColorBLUE);
51 SkScalar x = SkScalarSin(fAngle * SK_ScalarPI / 180) * 200 + 250;
52 SkScalar y = SkScalarCos(fAngle * SK_ScalarPI / 180) * 200 + 250;
53
54 if ((fPlusMinus ^= 1)) {
55 fAngle += 5;
56 } else {
57 fAngle -= 5;
58 }
59 SkRect divSim = SkRect::MakeXYWH(x, y, 100, 100);
60 divSim.outset(30, 30);
61 canvas->drawRect(divSim, divSimPaint);
62 fClip = divSim;
63 }
64
65 void resize(SkScalar w, SkScalar h) override { fClip.setWH(950, 600); }
66
67 bool animate(double /*nanos*/) override { return true; }
68
69 private:
70 SkPath fMegaPath;
71 SkRect fClip;
72 int fAngle;
73 int fPlusMinus;
74 };
75
76 //////////////////////////////////////////////////////////////////////////////
77
78 DEF_SLIDE( return new MegaStrokeSlide(); )