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() { |
| 19 | this->setBGColor(0xFFCCCCCC); |
| 20 | } |
| 21 | |
| 22 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 23 | uint32_t onGetFlags() const SK_OVERRIDE { |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 24 | return kSkipTiled_Flag; |
| 25 | } |
| 26 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 27 | SkString onShortName() SK_OVERRIDE { |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 28 | return SkString("arcofzorro"); |
| 29 | } |
| 30 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 31 | SkISize onISize() SK_OVERRIDE { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 32 | return SkISize::Make(1000, 1000); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 33 | } |
| 34 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 35 | void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 36 | SkRandom rand; |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 37 | |
| 38 | SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200); |
| 39 | |
| 40 | SkPaint p; |
| 41 | |
| 42 | p.setStyle(SkPaint::kStroke_Style); |
| 43 | p.setStrokeWidth(35); |
| 44 | int xOffset = 0, yOffset = 0; |
| 45 | int direction = 0; |
| 46 | |
| 47 | for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) { |
| 48 | SkColor color = rand.nextU(); |
| 49 | color |= 0xff000000; |
| 50 | p.setColor(color); |
| 51 | |
| 52 | canvas->save(); |
| 53 | canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset)); |
| 54 | canvas->drawArc(rect, 0, arc, false, p); |
| 55 | canvas->restore(); |
| 56 | |
| 57 | switch (direction) { |
| 58 | case 0: |
| 59 | xOffset += 10; |
| 60 | if (xOffset >= 700) { |
| 61 | direction = 1; |
| 62 | } |
| 63 | break; |
| 64 | case 1: |
| 65 | xOffset -= 10; |
| 66 | yOffset += 10; |
| 67 | if (xOffset < 50) { |
| 68 | direction = 2; |
| 69 | } |
| 70 | break; |
| 71 | case 2: |
| 72 | xOffset += 10; |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | typedef GM INHERITED; |
| 81 | }; |
| 82 | |
| 83 | ////////////////////////////////////////////////////////////////////////////// |
| 84 | |
| 85 | DEF_GM( return SkNEW(ArcOfZorroGM); ) |
| 86 | |
| 87 | } |