• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libs/graphics/animator/SkDrawRectangle.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 "SkDrawRectangle.h"
19 #include "SkAnimateMaker.h"
20 #include "SkCanvas.h"
21 #include "SkMatrixParts.h"
22 #include "SkPaint.h"
23 #include "SkScript.h"
24 
25 enum SkRectangle_Properties {
26     SK_PROPERTY(height),
27     SK_PROPERTY(needsRedraw),
28     SK_PROPERTY(width)
29 };
30 
31 #if SK_USE_CONDENSED_INFO == 0
32 
33 const SkMemberInfo SkDrawRect::fInfo[] = {
34     SK_MEMBER_ALIAS(bottom, fRect.fBottom, Float),
35     SK_MEMBER_PROPERTY(height, Float),
36     SK_MEMBER_ALIAS(left, fRect.fLeft, Float),
37     SK_MEMBER_PROPERTY(needsRedraw, Boolean),
38     SK_MEMBER_ALIAS(right, fRect.fRight, Float),
39     SK_MEMBER_ALIAS(top, fRect.fTop, Float),
40     SK_MEMBER_PROPERTY(width, Float)
41 };
42 
43 #endif
44 
45 DEFINE_GET_MEMBER(SkDrawRect);
46 
SkDrawRect()47 SkDrawRect::SkDrawRect() : fParent(NULL) {
48     fRect.setEmpty();
49 }
50 
dirty()51 void SkDrawRect::dirty() {
52     if (fParent)
53         fParent->dirty();
54 }
55 
draw(SkAnimateMaker & maker)56 bool SkDrawRect::draw(SkAnimateMaker& maker) {
57     SkBoundableAuto boundable(this, maker);
58     maker.fCanvas->drawRect(fRect, *maker.fPaint);
59     return false;
60 }
61 
62 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)63 void SkDrawRect::dump(SkAnimateMaker* maker) {
64     dumpBase(maker);
65     SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" />\n",
66         SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight),
67         SkScalarToFloat(fRect.fBottom));
68 }
69 #endif
70 
getParent() const71 SkDisplayable* SkDrawRect::getParent() const {
72     return fParent;
73 }
74 
getProperty(int index,SkScriptValue * value) const75 bool SkDrawRect::getProperty(int index, SkScriptValue* value) const {
76     SkScalar result;
77     switch (index) {
78         case SK_PROPERTY(height):
79             result = fRect.height();
80             break;
81         case SK_PROPERTY(needsRedraw):
82             value->fType = SkType_Boolean;
83             value->fOperand.fS32 = fBounds.isEmpty() == false;
84             return true;
85         case SK_PROPERTY(width):
86             result = fRect.width();
87             break;
88         default:
89             SkASSERT(0);
90             return false;
91     }
92     value->fType = SkType_Float;
93     value->fOperand.fScalar = result;
94     return true;
95 }
96 
97 
setParent(SkDisplayable * parent)98 bool SkDrawRect::setParent(SkDisplayable* parent) {
99     fParent = parent;
100     return false;
101 }
102 
setProperty(int index,SkScriptValue & value)103 bool SkDrawRect::setProperty(int index, SkScriptValue& value) {
104     SkScalar scalar = value.fOperand.fScalar;
105     switch (index) {
106         case SK_PROPERTY(height):
107             SkASSERT(value.fType == SkType_Float);
108             fRect.fBottom = scalar + fRect.fTop;
109             return true;
110         case SK_PROPERTY(needsRedraw):
111             return false;
112         case SK_PROPERTY(width):
113             SkASSERT(value.fType == SkType_Float);
114             fRect.fRight = scalar + fRect.fLeft;
115             return true;
116         default:
117             SkASSERT(0);
118     }
119     return false;
120 }
121 
122 #if SK_USE_CONDENSED_INFO == 0
123 
124 const SkMemberInfo SkRoundRect::fInfo[] = {
125     SK_MEMBER_INHERITED,
126     SK_MEMBER(rx, Float),
127     SK_MEMBER(ry, Float),
128 };
129 
130 #endif
131 
132 DEFINE_GET_MEMBER(SkRoundRect);
133 
SkRoundRect()134 SkRoundRect::SkRoundRect() : rx(0), ry(0) {
135 }
136 
draw(SkAnimateMaker & maker)137 bool SkRoundRect::draw(SkAnimateMaker& maker) {
138     SkBoundableAuto boundable(this, maker);
139     maker.fCanvas->drawRoundRect(fRect, rx, ry, *maker.fPaint);
140     return false;
141 }
142 
143 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)144 void SkRoundRect::dump(SkAnimateMaker* maker) {
145     dumpBase(maker);
146     SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" rx=\"%g\" ry=\"%g\" />\n",
147             SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight),
148             SkScalarToFloat(fRect.fBottom), SkScalarToFloat(rx), SkScalarToFloat(ry));
149 }
150 #endif
151 
152 
153 
154