From 35a81dfdb2796ca47703b17173c933ece933b953 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Fri, 4 May 2012 21:49:27 +0000 Subject: add gm for dashing variations git-svn-id: http://skia.googlecode.com/svn/trunk@3842 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/dashing.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 gm/dashing.cpp (limited to 'gm/dashing.cpp') 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); + +} -- cgit v1.2.3