blob: 73e1f529df31e2362a13e71a5481318b86097150 [file] [log] [blame]
robertphillips@google.comad4d4992013-06-26 17:06:45 +00001/*
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
10namespace skiagm {
11
12// Draw rects with various stroke widths at 1/8 pixel increments
13class ThinStrokedRectsGM : public GM {
14public:
15 ThinStrokedRectsGM() {
16 this->setBGColor(0xFF000000);
17 }
18
19protected:
mtklein36352bf2015-03-25 18:17:31 -070020 SkString onShortName() override {
robertphillips@google.comad4d4992013-06-26 17:06:45 +000021 return SkString("thinstrokedrects");
22 }
23
mtklein36352bf2015-03-25 18:17:31 -070024 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070025 return SkISize::Make(240, 320);
robertphillips@google.comad4d4992013-06-26 17:06:45 +000026 }
27
mtklein36352bf2015-03-25 18:17:31 -070028 void onDraw(SkCanvas* canvas) override {
robertphillips@google.comad4d4992013-06-26 17:06:45 +000029
30 SkPaint paint;
31 paint.setColor(SK_ColorWHITE);
32 paint.setStyle(SkPaint::kStroke_Style);
33 paint.setAntiAlias(true);
34
35 static const SkRect rect = { 0, 0, 10, 10 };
36 static const SkRect rect2 = { 0, 0, 20, 20 };
37
38 static const SkScalar gStrokeWidths[] = {
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
70private:
71 typedef GM INHERITED;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
halcanary385fe4d2015-08-26 13:07:48 -070076DEF_GM(return new ThinStrokedRectsGM;)
robertphillips@google.comad4d4992013-06-26 17:06:45 +000077}