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
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:
20    virtual SkString onShortName() SK_OVERRIDE {
21        return SkString("thinstrokedrects");
22    }
23
24    virtual SkISize onISize() SK_OVERRIDE {
25        return SkISize::Make(240, 320);
26    }
27
28    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
29
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
76DEF_GM( return SkNEW(ThinStrokedRectsGM); )
77
78}
79