blob: 37ffb35620bf952f43ccd6002f8be335351545a0 [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000020 virtual uint32_t onGetFlags() const SK_OVERRIDE {
21 return kSkipTiled_Flag;
22 }
23
robertphillips@google.comad4d4992013-06-26 17:06:45 +000024 virtual SkString onShortName() SK_OVERRIDE {
25 return SkString("thinstrokedrects");
26 }
27
28 virtual SkISize onISize() SK_OVERRIDE {
tfarinaf5393182014-06-09 23:59:03 -070029 return SkISize::Make(240, 320);
robertphillips@google.comad4d4992013-06-26 17:06:45 +000030 }
31
32 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
33
34 SkPaint paint;
35 paint.setColor(SK_ColorWHITE);
36 paint.setStyle(SkPaint::kStroke_Style);
37 paint.setAntiAlias(true);
38
39 static const SkRect rect = { 0, 0, 10, 10 };
40 static const SkRect rect2 = { 0, 0, 20, 20 };
41
42 static const SkScalar gStrokeWidths[] = {
43 4, 2, 1, 0.5f, 0.25f, 0.125f, 0
44 };
45
46 canvas->translate(5, 5);
47 for (int i = 0; i < 8; ++i) {
48 canvas->save();
49 canvas->translate(i*0.125f, i*30.0f);
50 for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
51 paint.setStrokeWidth(gStrokeWidths[j]);
52 canvas->drawRect(rect, paint);
53 canvas->translate(15, 0);
54 }
55 canvas->restore();
56 }
57
58 // Draw a second time in red with a scale
59 paint.setColor(SK_ColorRED);
60 canvas->translate(0, 15);
61 for (int i = 0; i < 8; ++i) {
62 canvas->save();
63 canvas->translate(i*0.125f, i*30.0f);
64 canvas->scale(0.5f, 0.5f);
65 for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
66 paint.setStrokeWidth(2.0f * gStrokeWidths[j]);
67 canvas->drawRect(rect2, paint);
68 canvas->translate(30, 0);
69 }
70 canvas->restore();
71 }
72 }
73
74private:
75 typedef GM INHERITED;
76};
77
78//////////////////////////////////////////////////////////////////////////////
79
80DEF_GM( return SkNEW(ThinStrokedRectsGM); )
81
82}