aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/thinstrokedrects.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 17:06:45 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 17:06:45 +0000
commitad4d499f861b4cbeb870b20728eed88e830cdf4b (patch)
tree33504bb00be73e8611163c602f4025c4bfb6127b /gm/thinstrokedrects.cpp
parentdd68f4533b6ba7310ebec82e2442efb00c583e73 (diff)
Add a new GM for very thin stroke widths
git-svn-id: http://skia.googlecode.com/svn/trunk@9770 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/thinstrokedrects.cpp')
-rw-r--r--gm/thinstrokedrects.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/gm/thinstrokedrects.cpp b/gm/thinstrokedrects.cpp
new file mode 100644
index 0000000000..2f839d1c00
--- /dev/null
+++ b/gm/thinstrokedrects.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+
+namespace skiagm {
+
+// Draw rects with various stroke widths at 1/8 pixel increments
+class ThinStrokedRectsGM : public GM {
+public:
+ ThinStrokedRectsGM() {
+ this->setBGColor(0xFF000000);
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("thinstrokedrects");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return make_isize(240, 320);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+
+ SkPaint paint;
+ paint.setColor(SK_ColorWHITE);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setAntiAlias(true);
+
+ static const SkRect rect = { 0, 0, 10, 10 };
+ static const SkRect rect2 = { 0, 0, 20, 20 };
+
+ static const SkScalar gStrokeWidths[] = {
+ 4, 2, 1, 0.5f, 0.25f, 0.125f, 0
+ };
+
+ canvas->translate(5, 5);
+ for (int i = 0; i < 8; ++i) {
+ canvas->save();
+ canvas->translate(i*0.125f, i*30.0f);
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
+ paint.setStrokeWidth(gStrokeWidths[j]);
+ canvas->drawRect(rect, paint);
+ canvas->translate(15, 0);
+ }
+ canvas->restore();
+ }
+
+ // Draw a second time in red with a scale
+ paint.setColor(SK_ColorRED);
+ canvas->translate(0, 15);
+ for (int i = 0; i < 8; ++i) {
+ canvas->save();
+ canvas->translate(i*0.125f, i*30.0f);
+ canvas->scale(0.5f, 0.5f);
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
+ paint.setStrokeWidth(2.0f * gStrokeWidths[j]);
+ canvas->drawRect(rect2, paint);
+ canvas->translate(30, 0);
+ }
+ canvas->restore();
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return SkNEW(ThinStrokedRectsGM); )
+
+}