blob: 549e9e2a1b6153ce9488fb4c84e4886b3abcc128 [file] [log] [blame]
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +00001
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +00009#include "SampleCode.h"
10#include "SkView.h"
11#include "SkCanvas.h"
12#include "SkGradientShader.h"
13#include "SkGraphics.h"
14#include "SkImageDecoder.h"
15#include "SkPath.h"
16#include "SkRegion.h"
17#include "SkShader.h"
18#include "SkUtils.h"
19#include "SkXfermode.h"
20#include "SkColorPriv.h"
21#include "SkColorFilter.h"
22#include "SkParsePath.h"
23#include "SkTime.h"
24#include "SkTypeface.h"
25
26#include "SkGeometry.h"
27
28class ConcavePathView : public SampleView {
29public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000030 ConcavePathView() {}
31
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +000032protected:
33 // overrides from SkEventSink
34 virtual bool onQuery(SkEvent* evt) {
35 if (SampleCode::TitleQ(*evt)) {
36 SampleCode::TitleR(evt, "ConcavePaths");
37 return true;
38 }
39 return this->INHERITED::onQuery(evt);
40 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000041
42 virtual void onDrawContent(SkCanvas* canvas) {
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +000043 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000044
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +000045 paint.setAntiAlias(true);
46 paint.setStyle(SkPaint::kFill_Style);
47
48 // Concave test
49 if (1) {
50 SkPath path;
51 canvas->translate(0, 0);
52 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
53 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
54 path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
55 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
56 canvas->drawPath(path, paint);
57 }
58 // Reverse concave test
59 if (1) {
60 SkPath path;
61 canvas->save();
62 canvas->translate(100, 0);
63 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
64 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
65 path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
66 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
67 canvas->drawPath(path, paint);
68 canvas->restore();
69 }
70 // Bowtie (intersection)
71 if (1) {
72 SkPath path;
73 canvas->save();
74 canvas->translate(200, 0);
75 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
76 path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
77 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
78 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
79 canvas->drawPath(path, paint);
80 canvas->restore();
81 }
82 // "fake" bowtie (concave, but no intersection)
83 if (1) {
84 SkPath path;
85 canvas->save();
86 canvas->translate(300, 0);
87 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
88 path.lineTo(SkIntToScalar(50), SkIntToScalar(40));
89 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
90 path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
91 path.lineTo(SkIntToScalar(50), SkIntToScalar(60));
92 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
93 canvas->drawPath(path, paint);
94 canvas->restore();
95 }
96 // Fish test (intersection/concave)
97 if (1) {
98 SkPath path;
99 canvas->save();
100 canvas->translate(0, 100);
101 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
102 path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
103 path.lineTo(SkIntToScalar(70), SkIntToScalar(50));
104 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
105 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
106 path.lineTo(SkIntToScalar(0), SkIntToScalar(50));
107 canvas->drawPath(path, paint);
108 canvas->restore();
109 }
110 // Collinear test
111 if (1) {
112 SkPath path;
113 canvas->save();
114 canvas->translate(100, 100);
115 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
116 path.lineTo(SkIntToScalar(50), SkIntToScalar(20));
117 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
118 path.lineTo(SkIntToScalar(50), SkIntToScalar(80));
119 canvas->drawPath(path, paint);
120 canvas->restore();
121 }
122 // Hole test
123 if (1) {
124 SkPath path;
125 canvas->save();
126 canvas->translate(200, 100);
127 path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
128 path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
129 path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
130 path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
131 path.moveTo(SkIntToScalar(30), SkIntToScalar(30));
132 path.lineTo(SkIntToScalar(30), SkIntToScalar(70));
133 path.lineTo(SkIntToScalar(70), SkIntToScalar(70));
134 path.lineTo(SkIntToScalar(70), SkIntToScalar(30));
135 canvas->drawPath(path, paint);
136 canvas->restore();
137 }
138 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000139
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000140 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
141 this->inval(NULL);
142 return this->INHERITED::onFindClickHandler(x, y);
143 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000144
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000145private:
146 typedef SampleView INHERITED;
147};
148
149//////////////////////////////////////////////////////////////////////////////
150
151static SkView* MyFactory() { return new ConcavePathView; }
152static SkViewRegister reg(MyFactory);
153