• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
9 #include "sk_tool_utils.h"
10 #include "SkRandom.h"
11 
12 namespace skiagm {
13 
14 // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
15 // the 'drawArc' code near a singularly of its processing (i.e., near the
16 // edge of one of its underlying quads).
17 class ArcOfZorroGM : public GM {
18 public:
ArcOfZorroGM()19     ArcOfZorroGM() {
20         this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
21     }
22 
23 protected:
24 
onShortName()25     SkString onShortName() override {
26         return SkString("arcofzorro");
27     }
28 
onISize()29     SkISize onISize() override {
30         return SkISize::Make(1000, 1000);
31     }
32 
onDraw(SkCanvas * canvas)33     void onDraw(SkCanvas* canvas) override {
34         SkRandom rand;
35 
36         SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
37 
38         SkPaint p;
39 
40         p.setStyle(SkPaint::kStroke_Style);
41         p.setStrokeWidth(35);
42         int xOffset = 0, yOffset = 0;
43         int direction = 0;
44 
45         for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
46             SkColor color = rand.nextU();
47             color |= 0xff000000;
48             p.setColor(color);
49 
50             canvas->save();
51             canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
52             canvas->drawArc(rect, 0, arc, false, p);
53             canvas->restore();
54 
55             switch (direction) {
56             case 0:
57                 xOffset += 10;
58                 if (xOffset >= 700) {
59                     direction = 1;
60                 }
61                 break;
62             case 1:
63                 xOffset -= 10;
64                 yOffset += 10;
65                 if (xOffset < 50) {
66                     direction = 2;
67                 }
68                 break;
69             case 2:
70                 xOffset += 10;
71                 break;
72             }
73         }
74 
75     }
76 
77 private:
78     typedef GM INHERITED;
79 };
80 
81 //////////////////////////////////////////////////////////////////////////////
82 
83 DEF_GM(return new ArcOfZorroGM;)
84 }
85