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