blob: 2be32bf19639947c706661723be5d087202bd6a9 [file] [log] [blame]
reed@google.com35a81df2012-05-04 21:49:27 +00001/*
2 * Copyright 2012 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#include "SkCanvas.h"
10#include "SkPaint.h"
11#include "SkDashPathEffect.h"
12
13static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint) {
14 SkPaint p(paint);
15
16 const SkScalar intervals[] = {
17 SkIntToScalar(on),
18 SkIntToScalar(off),
19 };
20
21 p.setPathEffect(new SkDashPathEffect(intervals, 2, 0))->unref();
22 canvas->drawLine(0, 0, SkIntToScalar(600), 0, p);
23}
24
25namespace skiagm {
26
27class DashingGM : public GM {
28public:
29 DashingGM() {}
30
31protected:
32 SkString onShortName() {
33 return SkString("dashing");
34 }
35
36 SkISize onISize() { return make_isize(640, 300); }
37
38 virtual void onDraw(SkCanvas* canvas) {
39 static const struct {
40 int fOnInterval;
41 int fOffInterval;
42 } gData[] = {
43 { 1, 1 },
44 { 4, 1 },
45 };
46
47 SkPaint paint;
48 paint.setStyle(SkPaint::kStroke_Style);
49
50 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
51 canvas->translate(0, SK_ScalarHalf);
52
53 for (int width = 0; width <= 2; ++width) {
54 for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
55 for (int aa = 0; aa <= 1; ++aa) {
56 int w = width * width * width;
57 paint.setAntiAlias(SkToBool(aa));
58 paint.setStrokeWidth(SkIntToScalar(w));
59
60 int scale = w ? w : 1;
61
62 drawline(canvas, gData[data].fOnInterval * scale,
63 gData[data].fOffInterval * scale,
64 paint);
65 canvas->translate(0, SkIntToScalar(20));
66 }
67 }
68 }
69 }
70
71private:
72 typedef GM INHERITED;
73};
74
75//////////////////////////////////////////////////////////////////////////////
76
77static GM* gF(void*) { return new DashingGM; }
78static GMRegistry gR(gF);
79
80}