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 17enum SkRectangle_Properties { 18 SK_PROPERTY(height), 19 SK_PROPERTY(needsRedraw), 20 SK_PROPERTY(width) 21}; 22 23#if SK_USE_CONDENSED_INFO == 0 24 25const 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 37DEFINE_GET_MEMBER(SkDrawRect); 38 39SkDrawRect::SkDrawRect() : fParent(NULL) { 40 fRect.setEmpty(); 41} 42 43void SkDrawRect::dirty() { 44 if (fParent) 45 fParent->dirty(); 46} 47 48bool 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 55void 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 63SkDisplayable* SkDrawRect::getParent() const { 64 return fParent; 65} 66 67bool 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 90bool SkDrawRect::setParent(SkDisplayable* parent) { 91 fParent = parent; 92 return false; 93} 94 95bool 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 116const SkMemberInfo SkRoundRect::fInfo[] = { 117 SK_MEMBER_INHERITED, 118 SK_MEMBER(rx, Float), 119 SK_MEMBER(ry, Float), 120}; 121 122#endif 123 124DEFINE_GET_MEMBER(SkRoundRect); 125 126SkRoundRect::SkRoundRect() : rx(0), ry(0) { 127} 128 129bool 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 136void 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 144 145 146