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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | d1701ba | 2019-04-30 13:44:26 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkScalar.h" |
| 14 | #include "include/core/SkSize.h" |
| 15 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/utils/SkRandom.h" |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 17 | |
| 18 | namespace skiagm { |
| 19 | |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 20 | // 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] | 21 | // the 'drawArc' code near a singularly of its processing (i.e., near the |
| 22 | // edge of one of its underlying quads). |
| 23 | class ArcOfZorroGM : public GM { |
| 24 | public: |
| 25 | ArcOfZorroGM() { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 26 | this->setBGColor(0xFFCCCCCC); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 30 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 31 | SkString onShortName() override { |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 32 | return SkString("arcofzorro"); |
| 33 | } |
| 34 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 36 | return SkISize::Make(1000, 1000); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 37 | } |
| 38 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 39 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 40 | SkRandom rand; |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 41 | |
| 42 | SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200); |
| 43 | |
| 44 | SkPaint p; |
| 45 | |
| 46 | p.setStyle(SkPaint::kStroke_Style); |
| 47 | p.setStrokeWidth(35); |
| 48 | int xOffset = 0, yOffset = 0; |
| 49 | int direction = 0; |
| 50 | |
| 51 | for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) { |
| 52 | SkColor color = rand.nextU(); |
| 53 | color |= 0xff000000; |
| 54 | p.setColor(color); |
| 55 | |
| 56 | canvas->save(); |
| 57 | canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset)); |
| 58 | canvas->drawArc(rect, 0, arc, false, p); |
| 59 | canvas->restore(); |
| 60 | |
| 61 | switch (direction) { |
| 62 | case 0: |
| 63 | xOffset += 10; |
| 64 | if (xOffset >= 700) { |
| 65 | direction = 1; |
| 66 | } |
| 67 | break; |
| 68 | case 1: |
| 69 | xOffset -= 10; |
| 70 | yOffset += 10; |
| 71 | if (xOffset < 50) { |
| 72 | direction = 2; |
| 73 | } |
| 74 | break; |
| 75 | case 2: |
| 76 | xOffset += 10; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | typedef GM INHERITED; |
| 85 | }; |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 89 | DEF_GM(return new ArcOfZorroGM;) |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 90 | } |