2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
12 // Draw rects with various stroke widths at 1/8 pixel increments
13 class ThinStrokedRectsGM : public GM {
15 ThinStrokedRectsGM() {
16 this->setBGColor(0xFF000000);
20 SkString onShortName() SK_OVERRIDE {
21 return SkString("thinstrokedrects");
24 SkISize onISize() SK_OVERRIDE {
25 return SkISize::Make(240, 320);
28 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
31 paint.setColor(SK_ColorWHITE);
32 paint.setStyle(SkPaint::kStroke_Style);
33 paint.setAntiAlias(true);
35 static const SkRect rect = { 0, 0, 10, 10 };
36 static const SkRect rect2 = { 0, 0, 20, 20 };
38 static const SkScalar gStrokeWidths[] = {
39 4, 2, 1, 0.5f, 0.25f, 0.125f, 0
42 canvas->translate(5, 5);
43 for (int i = 0; i < 8; ++i) {
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);
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) {
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);
74 //////////////////////////////////////////////////////////////////////////////
76 DEF_GM( return SkNEW(ThinStrokedRectsGM); )