blob: 9a7d6d7482662a15de7be0101fd2d3c18980dad7 [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000023
reed@google.com8d850be2012-07-13 15:55:15 +000024 virtual SkString onShortName() {
25 return SkString("dashcubics");
26 }
27
28 virtual SkISize onISize() {
29 return SkISize::Make(640, 480);
30 }
31
32 virtual void onDraw(SkCanvas* canvas) {
33 SkPath path;
34 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
35 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
36 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
37 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
38 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
39 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
40 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
41 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
42 "C 283,231 344,195 338,98";
43
44 SkParsePath::FromSVGString(d, &path);
rmistry@google.comae933ce2012-08-23 18:19:56 +000045
reed@google.com8d850be2012-07-13 15:55:15 +000046 SkScalar intervals[] = { 5, 10 };
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000047 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0);
reed@google.com8d850be2012-07-13 15:55:15 +000048
49 SkPaint paint;
50 paint.setAntiAlias(true);
51 paint.setStyle(SkPaint::kStroke_Style);
52
53 paint.setStrokeWidth(42);
54 canvas->drawPath(path, paint);
55
56 paint.setColor(SK_ColorRED);
57 paint.setStrokeWidth(21);
58 paint.setPathEffect(pe)->unref();
59 canvas->drawPath(path, paint);
60
61 paint.setColor(SK_ColorGREEN);
62 paint.setPathEffect(NULL);
63 paint.setStrokeWidth(0);
64 canvas->drawPath(path, paint);
65 }
66
67private:
68 typedef GM INHERITED;
69};
70
71//////////////////////////////////////////////////////////////////////////////
72
73static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; }
74static skiagm::GMRegistry reg(MyFactory);