| reed@google.com | 35a81df | 2012-05-04 21:49:27 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 13 | static 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 | |
| 25 | namespace skiagm { |
| 26 | |
| 27 | class DashingGM : public GM { |
| 28 | public: |
| 29 | DashingGM() {} |
| 30 | |
| 31 | protected: |
| 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 | |
| 71 | private: |
| 72 | typedef GM INHERITED; |
| 73 | }; |
| 74 | |
| 75 | ////////////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | static GM* gF(void*) { return new DashingGM; } |
| 78 | static GMRegistry gR(gF); |
| 79 | |
| 80 | } |