180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDrawRectangle.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateMaker.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMatrixParts.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPaint.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkScript.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum SkRectangle_Properties { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(height), 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(needsRedraw), 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(width) 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkDrawRect::fInfo[] = { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(bottom, fRect.fBottom, Float), 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_PROPERTY(height, Float), 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(left, fRect.fLeft, Float), 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_PROPERTY(needsRedraw, Boolean), 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(right, fRect.fRight, Float), 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(top, fRect.fTop, Float), 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_PROPERTY(width, Float) 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkDrawRect); 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDrawRect::SkDrawRect() : fParent(NULL) { 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRect.setEmpty(); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDrawRect::dirty() { 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fParent) 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent->dirty(); 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawRect::draw(SkAnimateMaker& maker) { 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkBoundableAuto boundable(this, maker); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fCanvas->drawRect(fRect, *maker.fPaint); 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDrawRect::dump(SkAnimateMaker* maker) { 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpBase(maker); 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" />\n", 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight), 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalarToFloat(fRect.fBottom)); 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayable* SkDrawRect::getParent() const { 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fParent; 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawRect::getProperty(int index, SkScriptValue* value) const { 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar result; 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru switch (index) { 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(height): 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru result = fRect.height(); 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(needsRedraw): 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fType = SkType_Boolean; 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fOperand.fS32 = fBounds.isEmpty() == false; 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(width): 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru result = fRect.width(); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default: 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(0); 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fType = SkType_Float; 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fOperand.fScalar = result; 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawRect::setParent(SkDisplayable* parent) { 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent = parent; 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawRect::setProperty(int index, SkScriptValue& value) { 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar scalar = value.fOperand.fScalar; 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru switch (index) { 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(height): 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(value.fType == SkType_Float); 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRect.fBottom = scalar + fRect.fTop; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(needsRedraw): 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(width): 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(value.fType == SkType_Float); 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRect.fRight = scalar + fRect.fLeft; 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default: 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(0); 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkRoundRect::fInfo[] = { 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_INHERITED, 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(rx, Float), 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(ry, Float), 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkRoundRect); 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkRoundRect::SkRoundRect() : rx(0), ry(0) { 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkRoundRect::draw(SkAnimateMaker& maker) { 13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkBoundableAuto boundable(this, maker); 13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fCanvas->drawRoundRect(fRect, rx, ry, *maker.fPaint); 13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkRoundRect::dump(SkAnimateMaker* maker) { 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpBase(maker); 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("left=\"%g\" top=\"%g\" right=\"%g\" bottom=\"%g\" rx=\"%g\" ry=\"%g\" />\n", 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalarToFloat(fRect.fLeft), SkScalarToFloat(fRect.fTop), SkScalarToFloat(fRect.fRight), 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalarToFloat(fRect.fBottom), SkScalarToFloat(rx), SkScalarToFloat(ry)); 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 143