robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +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" |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 9 | |
| 10 | namespace skiagm { |
| 11 | |
| 12 | // Draw rects with various stroke widths at 1/8 pixel increments |
| 13 | class ThinStrokedRectsGM : public GM { |
| 14 | public: |
| 15 | ThinStrokedRectsGM() { |
| 16 | this->setBGColor(0xFF000000); |
| 17 | } |
| 18 | |
| 19 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 20 | SkString onShortName() override { |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 21 | return SkString("thinstrokedrects"); |
| 22 | } |
| 23 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 24 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 25 | return SkISize::Make(240, 320); |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 26 | } |
| 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | void onDraw(SkCanvas* canvas) override { |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 29 | |
| 30 | SkPaint paint; |
| 31 | paint.setColor(SK_ColorWHITE); |
| 32 | paint.setStyle(SkPaint::kStroke_Style); |
| 33 | paint.setAntiAlias(true); |
| 34 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 35 | constexpr SkRect rect = { 0, 0, 10, 10 }; |
| 36 | constexpr SkRect rect2 = { 0, 0, 20, 20 }; |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 37 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 38 | constexpr SkScalar gStrokeWidths[] = { |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 39 | 4, 2, 1, 0.5f, 0.25f, 0.125f, 0 |
| 40 | }; |
| 41 | |
| 42 | canvas->translate(5, 5); |
| 43 | for (int i = 0; i < 8; ++i) { |
| 44 | canvas->save(); |
| 45 | canvas->translate(i*0.125f, i*30.0f); |
| 46 | for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) { |
| 47 | paint.setStrokeWidth(gStrokeWidths[j]); |
| 48 | canvas->drawRect(rect, paint); |
| 49 | canvas->translate(15, 0); |
| 50 | } |
| 51 | canvas->restore(); |
| 52 | } |
| 53 | |
| 54 | // Draw a second time in red with a scale |
| 55 | paint.setColor(SK_ColorRED); |
| 56 | canvas->translate(0, 15); |
| 57 | for (int i = 0; i < 8; ++i) { |
| 58 | canvas->save(); |
| 59 | canvas->translate(i*0.125f, i*30.0f); |
| 60 | canvas->scale(0.5f, 0.5f); |
| 61 | for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) { |
| 62 | paint.setStrokeWidth(2.0f * gStrokeWidths[j]); |
| 63 | canvas->drawRect(rect2, paint); |
| 64 | canvas->translate(30, 0); |
| 65 | } |
| 66 | canvas->restore(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | typedef GM INHERITED; |
| 72 | }; |
| 73 | |
| 74 | ////////////////////////////////////////////////////////////////////////////// |
| 75 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 76 | DEF_GM(return new ThinStrokedRectsGM;) |
robertphillips@google.com | ad4d499 | 2013-06-26 17:06:45 +0000 | [diff] [blame] | 77 | } |