Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
arcofzorro.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
12#include "include/core/SkRect.h"
14#include "include/core/SkSize.h"
16#include "src/base/SkRandom.h"
17
18namespace skiagm {
19
20// This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
21// the 'drawArc' code near a singularly of its processing (i.e., near the
22// edge of one of its underlying quads).
23class ArcOfZorroGM : public GM {
24public:
26 this->setBGColor(0xFFCCCCCC);
27 }
28
29protected:
30 SkString getName() const override { return SkString("arcofzorro"); }
31
32 SkISize getISize() override { return SkISize::Make(1000, 1000); }
33
34 void onDraw(SkCanvas* canvas) override {
35 SkRandom rand;
36
37 SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
38
39 SkPaint p;
40
41 p.setStyle(SkPaint::kStroke_Style);
42 p.setStrokeWidth(35);
43 int xOffset = 0, yOffset = 0;
44 int direction = 0;
45
46 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
47 SkColor color = rand.nextU();
48 color |= 0xff000000;
49 p.setColor(color);
50
51 canvas->save();
52 canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
53 canvas->drawArc(rect, 0, arc, false, p);
54 canvas->restore();
55
56 switch (direction) {
57 case 0:
58 xOffset += 10;
59 if (xOffset >= 700) {
60 direction = 1;
61 }
62 break;
63 case 1:
64 xOffset -= 10;
65 yOffset += 10;
66 if (xOffset < 50) {
67 direction = 2;
68 }
69 break;
70 case 2:
71 xOffset += 10;
72 break;
73 }
74 }
75
76 }
77
78private:
79 using INHERITED = GM;
80};
81
82//////////////////////////////////////////////////////////////////////////////
83
84DEF_GM(return new ArcOfZorroGM;)
85} // namespace skiagm
SkColor4f color
uint32_t SkColor
Definition SkColor.h:37
#define SkIntToScalar(x)
Definition SkScalar.h:57
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
int save()
Definition SkCanvas.cpp:451
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
uint32_t nextU()
Definition SkRandom.h:42
SkString getName() const override
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
void setBGColor(SkColor)
Definition gm.cpp:159
#define DEF_GM(CODE)
Definition gm.h:40
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659