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