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