robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 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 | |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 13 | // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 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() { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 19 | this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 23 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 24 | SkString onShortName() override { |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 25 | return SkString("arcofzorro"); |
| 26 | } |
| 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 29 | return SkISize::Make(1000, 1000); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 33 | SkRandom rand; |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 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 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 82 | DEF_GM(return new ArcOfZorroGM;) |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 83 | } |