blob: bbce9be66ed2c8173f4e9e8c1443afb2483bc146 [file] [log] [blame]
reed@google.com8d850be2012-07-13 15:55:15 +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 "SkPath.h"
11#include "SkParsePath.h"
12#include "SkDashPathEffect.h"
13
14/*
15 * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145
16 */
17
18class DashCubicsGM : public skiagm::GM {
19public:
20 DashCubicsGM() {}
21
22protected:
23 virtual SkString onShortName() {
24 return SkString("dashcubics");
25 }
26
27 virtual SkISize onISize() {
28 return SkISize::Make(640, 480);
29 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkPath path;
33 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
34 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
35 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
36 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
37 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
38 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
39 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
40 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
41 "C 283,231 344,195 338,98";
42
43 SkParsePath::FromSVGString(d, &path);
rmistry@google.comae933ce2012-08-23 18:19:56 +000044
reed@google.com8d850be2012-07-13 15:55:15 +000045 SkScalar intervals[] = { 5, 10 };
46 SkPathEffect* pe = new SkDashPathEffect(intervals, 2, 0);
47
48 SkPaint paint;
49 paint.setAntiAlias(true);
50 paint.setStyle(SkPaint::kStroke_Style);
51
52 paint.setStrokeWidth(42);
53 canvas->drawPath(path, paint);
54
55 paint.setColor(SK_ColorRED);
56 paint.setStrokeWidth(21);
57 paint.setPathEffect(pe)->unref();
58 canvas->drawPath(path, paint);
59
60 paint.setColor(SK_ColorGREEN);
61 paint.setPathEffect(NULL);
62 paint.setStrokeWidth(0);
63 canvas->drawPath(path, paint);
64 }
65
66private:
67 typedef GM INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
72static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; }
73static skiagm::GMRegistry reg(MyFactory);
74