diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-04 21:49:27 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-04 21:49:27 +0000 |
commit | 35a81dfdb2796ca47703b17173c933ece933b953 (patch) | |
tree | d277a415be8a2671ed61fb5fc1a37b577555daf4 | |
parent | 4aa1a70ab74e841def84367d771ac2b2202f41d2 (diff) |
add gm for dashing variations
git-svn-id: http://skia.googlecode.com/svn/trunk@3842 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/dashing.cpp | 80 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 |
2 files changed, 81 insertions, 0 deletions
diff --git a/gm/dashing.cpp b/gm/dashing.cpp new file mode 100644 index 0000000000..2be32bf196 --- /dev/null +++ b/gm/dashing.cpp @@ -0,0 +1,80 @@ +/* + * Copyright 2012 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" +#include "SkCanvas.h" +#include "SkPaint.h" +#include "SkDashPathEffect.h" + +static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint) { + SkPaint p(paint); + + const SkScalar intervals[] = { + SkIntToScalar(on), + SkIntToScalar(off), + }; + + p.setPathEffect(new SkDashPathEffect(intervals, 2, 0))->unref(); + canvas->drawLine(0, 0, SkIntToScalar(600), 0, p); +} + +namespace skiagm { + +class DashingGM : public GM { +public: + DashingGM() {} + +protected: + SkString onShortName() { + return SkString("dashing"); + } + + SkISize onISize() { return make_isize(640, 300); } + + virtual void onDraw(SkCanvas* canvas) { + static const struct { + int fOnInterval; + int fOffInterval; + } gData[] = { + { 1, 1 }, + { 4, 1 }, + }; + + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + + canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); + canvas->translate(0, SK_ScalarHalf); + + for (int width = 0; width <= 2; ++width) { + for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) { + for (int aa = 0; aa <= 1; ++aa) { + int w = width * width * width; + paint.setAntiAlias(SkToBool(aa)); + paint.setStrokeWidth(SkIntToScalar(w)); + + int scale = w ? w : 1; + + drawline(canvas, gData[data].fOnInterval * scale, + gData[data].fOffInterval * scale, + paint); + canvas->translate(0, SkIntToScalar(20)); + } + } + } + } + +private: + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* gF(void*) { return new DashingGM; } +static GMRegistry gR(gF); + +} diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index e3b4b6419d..659fe9f192 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -17,6 +17,7 @@ '../gm/cubicpaths.cpp', '../gm/cmykjpeg.cpp', '../gm/degeneratesegments.cpp', + '../gm/dashing.cpp', '../gm/drawbitmaprect.cpp', '../gm/emptypath.cpp', '../gm/filltypes.cpp', |