1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkDrawRectangle.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,142 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkDrawRectangle.h" 1.14 +#include "SkAnimateMaker.h" 1.15 +#include "SkCanvas.h" 1.16 +#include "SkMatrixParts.h" 1.17 +#include "SkPaint.h" 1.18 +#include "SkScript.h" 1.19 + 1.20 +enum SkRectangle_Properties { 1.21 + SK_PROPERTY(height), 1.22 + SK_PROPERTY(needsRedraw), 1.23 + SK_PROPERTY(width) 1.24 +}; 1.25 + 1.26 +#if SK_USE_CONDENSED_INFO == 0 1.27 + 1.28 +const SkMemberInfo SkDrawRect::fInfo[] = { 1.29 + SK_MEMBER_ALIAS(bottom, fRect.fBottom, Float), 1.30 + SK_MEMBER_PROPERTY(height, Float), 1.31 + SK_MEMBER_ALIAS(left, fRect.fLeft, Float), 1.32 + SK_MEMBER_PROPERTY(needsRedraw, Boolean), 1.33 + SK_MEMBER_ALIAS(right, fRect.fRight, Float), 1.34 + SK_MEMBER_ALIAS(top, fRect.fTop, Float), 1.35 + SK_MEMBER_PROPERTY(width, Float) 1.36 +}; 1.37 + 1.38 +#endif 1.39 + 1.40 +DEFINE_GET_MEMBER(SkDrawRect); 1.41 + 1.42 +SkDrawRect::SkDrawRect() : fParent(NULL) { 1.43 + fRect.setEmpty(); 1.44 +} 1.45 + 1.46 +void SkDrawRect::dirty() { 1.47 + if (fParent) 1.48 + fParent->dirty(); 1.49 +} 1.50 + 1.51 +bool SkDrawRect::draw(SkAnimateMaker& maker) { 1.52 + SkBoundableAuto boundable(this, maker); 1.53 + maker.fCanvas->drawRect(fRect, *maker.fPaint); 1.54 + return false; 1.55 +} 1.56 + 1.57 +#ifdef SK_DUMP_ENABLED 1.58 +void SkDrawRect::dump(SkAnimateMaker* maker) { 1.59 + dumpBase(maker); 1.60 + SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" />\n", 1.61 + SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight), 1.62 + SkScalarToFloat(fRect.fBottom)); 1.63 +} 1.64 +#endif 1.65 + 1.66 +SkDisplayable* SkDrawRect::getParent() const { 1.67 + return fParent; 1.68 +} 1.69 + 1.70 +bool SkDrawRect::getProperty(int index, SkScriptValue* value) const { 1.71 + SkScalar result; 1.72 + switch (index) { 1.73 + case SK_PROPERTY(height): 1.74 + result = fRect.height(); 1.75 + break; 1.76 + case SK_PROPERTY(needsRedraw): 1.77 + value->fType = SkType_Boolean; 1.78 + value->fOperand.fS32 = fBounds.isEmpty() == false; 1.79 + return true; 1.80 + case SK_PROPERTY(width): 1.81 + result = fRect.width(); 1.82 + break; 1.83 + default: 1.84 + SkASSERT(0); 1.85 + return false; 1.86 + } 1.87 + value->fType = SkType_Float; 1.88 + value->fOperand.fScalar = result; 1.89 + return true; 1.90 +} 1.91 + 1.92 + 1.93 +bool SkDrawRect::setParent(SkDisplayable* parent) { 1.94 + fParent = parent; 1.95 + return false; 1.96 +} 1.97 + 1.98 +bool SkDrawRect::setProperty(int index, SkScriptValue& value) { 1.99 + SkScalar scalar = value.fOperand.fScalar; 1.100 + switch (index) { 1.101 + case SK_PROPERTY(height): 1.102 + SkASSERT(value.fType == SkType_Float); 1.103 + fRect.fBottom = scalar + fRect.fTop; 1.104 + return true; 1.105 + case SK_PROPERTY(needsRedraw): 1.106 + return false; 1.107 + case SK_PROPERTY(width): 1.108 + SkASSERT(value.fType == SkType_Float); 1.109 + fRect.fRight = scalar + fRect.fLeft; 1.110 + return true; 1.111 + default: 1.112 + SkASSERT(0); 1.113 + } 1.114 + return false; 1.115 +} 1.116 + 1.117 +#if SK_USE_CONDENSED_INFO == 0 1.118 + 1.119 +const SkMemberInfo SkRoundRect::fInfo[] = { 1.120 + SK_MEMBER_INHERITED, 1.121 + SK_MEMBER(rx, Float), 1.122 + SK_MEMBER(ry, Float), 1.123 +}; 1.124 + 1.125 +#endif 1.126 + 1.127 +DEFINE_GET_MEMBER(SkRoundRect); 1.128 + 1.129 +SkRoundRect::SkRoundRect() : rx(0), ry(0) { 1.130 +} 1.131 + 1.132 +bool SkRoundRect::draw(SkAnimateMaker& maker) { 1.133 + SkBoundableAuto boundable(this, maker); 1.134 + maker.fCanvas->drawRoundRect(fRect, rx, ry, *maker.fPaint); 1.135 + return false; 1.136 +} 1.137 + 1.138 +#ifdef SK_DUMP_ENABLED 1.139 +void SkRoundRect::dump(SkAnimateMaker* maker) { 1.140 + dumpBase(maker); 1.141 + SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" rx=\"%g\" ry=\"%g\" />\n", 1.142 + SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight), 1.143 + SkScalarToFloat(fRect.fBottom), SkScalarToFloat(rx), SkScalarToFloat(ry)); 1.144 +} 1.145 +#endif