1 /* libs/graphics/animator/SkPathParts.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #include "SkPathParts.h"
19 #include "SkAnimateMaker.h"
20 #include "SkDrawMatrix.h"
21 #include "SkDrawRectangle.h"
22 #include "SkDrawPath.h"
23
SkPathPart()24 SkPathPart::SkPathPart() : fPath(NULL) {
25 }
26
dirty()27 void SkPathPart::dirty() {
28 fPath->dirty();
29 }
30
getParent() const31 SkDisplayable* SkPathPart::getParent() const {
32 return fPath;
33 }
34
setParent(SkDisplayable * parent)35 bool SkPathPart::setParent(SkDisplayable* parent) {
36 SkASSERT(parent != NULL);
37 if (parent->isPath() == false)
38 return true;
39 fPath = (SkDrawPath*) parent;
40 return false;
41 }
42
43 // MoveTo
44 #if SK_USE_CONDENSED_INFO == 0
45
46 const SkMemberInfo SkMoveTo::fInfo[] = {
47 SK_MEMBER(x, Float),
48 SK_MEMBER(y, Float)
49 };
50
51 #endif
52
53 DEFINE_GET_MEMBER(SkMoveTo);
54
SkMoveTo()55 SkMoveTo::SkMoveTo() : x(0), y(0) {
56 }
57
add()58 bool SkMoveTo::add() {
59 fPath->fPath.moveTo(x, y);
60 return false;
61 }
62
63
64 // RMoveTo
65 #if SK_USE_CONDENSED_INFO == 0
66
67 const SkMemberInfo SkRMoveTo::fInfo[] = {
68 SK_MEMBER_INHERITED
69 };
70
71 #endif
72
73 DEFINE_GET_MEMBER(SkRMoveTo);
74
add()75 bool SkRMoveTo::add() {
76 fPath->fPath.rMoveTo(x, y);
77 return false;
78 }
79
80
81 // LineTo
82 #if SK_USE_CONDENSED_INFO == 0
83
84 const SkMemberInfo SkLineTo::fInfo[] = {
85 SK_MEMBER(x, Float),
86 SK_MEMBER(y, Float)
87 };
88
89 #endif
90
91 DEFINE_GET_MEMBER(SkLineTo);
92
SkLineTo()93 SkLineTo::SkLineTo() : x(0), y(0) {
94 }
95
add()96 bool SkLineTo::add() {
97 fPath->fPath.lineTo(x, y);
98 return false;
99 }
100
101
102 // RLineTo
103 #if SK_USE_CONDENSED_INFO == 0
104
105 const SkMemberInfo SkRLineTo::fInfo[] = {
106 SK_MEMBER_INHERITED
107 };
108
109 #endif
110
111 DEFINE_GET_MEMBER(SkRLineTo);
112
add()113 bool SkRLineTo::add() {
114 fPath->fPath.rLineTo(x, y);
115 return false;
116 }
117
118
119 // QuadTo
120 #if SK_USE_CONDENSED_INFO == 0
121
122 const SkMemberInfo SkQuadTo::fInfo[] = {
123 SK_MEMBER(x1, Float),
124 SK_MEMBER(x2, Float),
125 SK_MEMBER(y1, Float),
126 SK_MEMBER(y2, Float)
127 };
128
129 #endif
130
131 DEFINE_GET_MEMBER(SkQuadTo);
132
SkQuadTo()133 SkQuadTo::SkQuadTo() : x1(0), y1(0), x2(0), y2(0) {
134 }
135
add()136 bool SkQuadTo::add() {
137 fPath->fPath.quadTo(x1, y1, x2, y2);
138 return false;
139 }
140
141
142 // RQuadTo
143 #if SK_USE_CONDENSED_INFO == 0
144
145 const SkMemberInfo SkRQuadTo::fInfo[] = {
146 SK_MEMBER_INHERITED
147 };
148
149 #endif
150
151 DEFINE_GET_MEMBER(SkRQuadTo);
152
add()153 bool SkRQuadTo::add() {
154 fPath->fPath.rQuadTo(x1, y1, x2, y2);
155 return false;
156 }
157
158
159 // CubicTo
160 #if SK_USE_CONDENSED_INFO == 0
161
162 const SkMemberInfo SkCubicTo::fInfo[] = {
163 SK_MEMBER(x1, Float),
164 SK_MEMBER(x2, Float),
165 SK_MEMBER(x3, Float),
166 SK_MEMBER(y1, Float),
167 SK_MEMBER(y2, Float),
168 SK_MEMBER(y3, Float)
169 };
170
171 #endif
172
173 DEFINE_GET_MEMBER(SkCubicTo);
174
SkCubicTo()175 SkCubicTo::SkCubicTo() : x1(0), y1(0), x2(0), y2(0), x3(0), y3(0) {
176 }
177
add()178 bool SkCubicTo::add() {
179 fPath->fPath.cubicTo(x1, y1, x2, y2, x3, y3);
180 return false;
181 }
182
183
184 // RCubicTo
185 #if SK_USE_CONDENSED_INFO == 0
186
187 const SkMemberInfo SkRCubicTo::fInfo[] = {
188 SK_MEMBER_INHERITED
189 };
190
191 #endif
192
193 DEFINE_GET_MEMBER(SkRCubicTo);
194
add()195 bool SkRCubicTo::add() {
196 fPath->fPath.rCubicTo(x1, y1, x2, y2, x3, y3);
197 return false;
198 }
199
200
201 // SkClose
add()202 bool SkClose::add() {
203 fPath->fPath.close();
204 return false;
205 }
206
207
208 // SkAddGeom
209 #if SK_USE_CONDENSED_INFO == 0
210
211 const SkMemberInfo SkAddGeom::fInfo[] = {
212 SK_MEMBER(direction, PathDirection)
213 };
214
215 #endif
216
217 DEFINE_GET_MEMBER(SkAddGeom);
218
SkAddGeom()219 SkAddGeom::SkAddGeom() : direction(SkPath::kCCW_Direction) {
220 }
221
222 #if SK_USE_CONDENSED_INFO == 0
223
224 const SkMemberInfo SkAddRect::fInfo[] = {
225 SK_MEMBER_INHERITED,
226 SK_MEMBER_ALIAS(bottom, fRect.fBottom, Float),
227 SK_MEMBER_ALIAS(left, fRect.fLeft, Float),
228 SK_MEMBER_ALIAS(right, fRect.fRight, Float),
229 SK_MEMBER_ALIAS(top, fRect.fTop, Float)
230 };
231
232 #endif
233
234 DEFINE_GET_MEMBER(SkAddRect);
235
SkAddRect()236 SkAddRect::SkAddRect() {
237 fRect.setEmpty();
238 }
239
add()240 bool SkAddRect::add() {
241 fPath->fPath.addRect(fRect, (SkPath::Direction) direction);
242 return false;
243 }
244
245
246 #if SK_USE_CONDENSED_INFO == 0
247
248 const SkMemberInfo SkAddOval::fInfo[] = {
249 SK_MEMBER_INHERITED
250 };
251
252 #endif
253
254 DEFINE_GET_MEMBER(SkAddOval);
255
add()256 bool SkAddOval::add() {
257 fPath->fPath.addOval(fRect, (SkPath::Direction) direction);
258 return false;
259 }
260
261
262 #if SK_USE_CONDENSED_INFO == 0
263
264 const SkMemberInfo SkAddCircle::fInfo[] = {
265 SK_MEMBER_INHERITED,
266 SK_MEMBER(radius, Float),
267 SK_MEMBER(x, Float),
268 SK_MEMBER(y, Float)
269 };
270
271 #endif
272
273 DEFINE_GET_MEMBER(SkAddCircle);
274
SkAddCircle()275 SkAddCircle::SkAddCircle() : radius(0), x(0), y(0) {
276 }
277
add()278 bool SkAddCircle::add() {
279 fPath->fPath.addCircle(x, y, radius, (SkPath::Direction) direction);
280 return false;
281 }
282
283
284 #if SK_USE_CONDENSED_INFO == 0
285
286 const SkMemberInfo SkAddRoundRect::fInfo[] = {
287 SK_MEMBER_INHERITED,
288 SK_MEMBER(rx, Float),
289 SK_MEMBER(ry, Float)
290 };
291
292 #endif
293
294 DEFINE_GET_MEMBER(SkAddRoundRect);
295
SkAddRoundRect()296 SkAddRoundRect::SkAddRoundRect() : rx(0), ry(0) {
297 }
298
add()299 bool SkAddRoundRect::add() {
300 fPath->fPath.addRoundRect(fRect, rx, ry, (SkPath::Direction) direction);
301 return false;
302 }
303
304
305 #if SK_USE_CONDENSED_INFO == 0
306
307 const SkMemberInfo SkAddPath::fInfo[] = {
308 SK_MEMBER(matrix, Matrix),
309 SK_MEMBER(path, Path)
310 };
311
312 #endif
313
314 DEFINE_GET_MEMBER(SkAddPath);
315
SkAddPath()316 SkAddPath::SkAddPath() : matrix(NULL), path(NULL) {
317 }
318
add()319 bool SkAddPath::add() {
320 SkASSERT (path != NULL);
321 if (matrix)
322 fPath->fPath.addPath(path->fPath, matrix->getMatrix());
323 else
324 fPath->fPath.addPath(path->fPath);
325 return false;
326 }
327
328
329