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 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: 20 virtual uint32_t onGetFlags() const SK_OVERRIDE { 21 return kSkipTiled_Flag; 22 } 23 24 virtual SkString onShortName() SK_OVERRIDE { 25 return SkString("thinstrokedrects"); 26 } 27 28 virtual SkISize onISize() SK_OVERRIDE { 29 return SkISize::Make(240, 320); 30 } 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 74 private: 75 typedef GM INHERITED; 76 }; 77 78 ////////////////////////////////////////////////////////////////////////////// 79 80 DEF_GM( return SkNEW(ThinStrokedRectsGM); ) 81 82 } 83