reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame^] | 1 | #include "SkProgressBarView.h" |
| 2 | #include "SkAnimator.h" |
| 3 | #include "SkWidgetViews.h" |
| 4 | #include "SkTime.h" |
| 5 | #include "SkSystemEventTypes.h" |
| 6 | |
| 7 | SkProgressBarView::SkProgressBarView() |
| 8 | { |
| 9 | init_skin_anim(kProgress_SkinEnum, &fAnim); |
| 10 | fAnim.setHostEventSink(this); |
| 11 | fProgress = 0; |
| 12 | fMax = 100; |
| 13 | |
| 14 | } |
| 15 | |
| 16 | void SkProgressBarView::changeProgress(int diff) |
| 17 | { |
| 18 | int newProg = fProgress + diff; |
| 19 | if (newProg > 0 && newProg < fMax) |
| 20 | this->setProgress(newProg); |
| 21 | //otherwise i'll just leave it as it is |
| 22 | //this implies that if a new max and progress are set, max must be set first |
| 23 | } |
| 24 | |
| 25 | /*virtual*/ void SkProgressBarView::onDraw(SkCanvas* canvas) |
| 26 | { |
| 27 | SkPaint paint; |
| 28 | SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); |
| 29 | |
| 30 | if (diff == SkAnimator::kDifferent) |
| 31 | this->inval(nil); |
| 32 | else if (diff == SkAnimator::kPartiallyDifferent) |
| 33 | { |
| 34 | SkRect bounds; |
| 35 | fAnim.getInvalBounds(&bounds); |
| 36 | this->inval(&bounds); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /*virtual*/ bool SkProgressBarView::onEvent(const SkEvent& evt) |
| 41 | { |
| 42 | if (evt.isType(SK_EventType_Inval)) |
| 43 | { |
| 44 | this->inval(nil); |
| 45 | return true; |
| 46 | } |
| 47 | if (evt.isType("recommendDim")) |
| 48 | { |
| 49 | SkScalar height; |
| 50 | |
| 51 | if (evt.findScalar("y", &height)) |
| 52 | this->setHeight(height); |
| 53 | return true; |
| 54 | } |
| 55 | return this->INHERITED::onEvent(evt); |
| 56 | } |
| 57 | |
| 58 | /*virtual*/ void SkProgressBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
| 59 | { |
| 60 | this->INHERITED::onInflate(dom, node); |
| 61 | int32_t temp; |
| 62 | if (dom.findS32(node, "max", &temp)) |
| 63 | this->setMax(temp); |
| 64 | if (dom.findS32(node, "progress", &temp)) |
| 65 | this->setProgress(temp); |
| 66 | } |
| 67 | |
| 68 | /*virtual*/ void SkProgressBarView::onSizeChange() |
| 69 | { |
| 70 | this->INHERITED::onSizeChange(); |
| 71 | SkEvent evt("user"); |
| 72 | evt.setString("id", "setDim"); |
| 73 | evt.setScalar("dimX", this->width()); |
| 74 | evt.setScalar("dimY", this->height()); |
| 75 | fAnim.doUserEvent(evt); |
| 76 | } |
| 77 | |
| 78 | void SkProgressBarView::reset() |
| 79 | { |
| 80 | fProgress = 0; |
| 81 | SkEvent e("user"); |
| 82 | e.setString("id", "reset"); |
| 83 | fAnim.doUserEvent(e); |
| 84 | } |
| 85 | |
| 86 | void SkProgressBarView::setMax(int max) |
| 87 | { |
| 88 | fMax = max; |
| 89 | SkEvent e("user"); |
| 90 | e.setString("id", "setMax"); |
| 91 | e.setS32("newMax", max); |
| 92 | fAnim.doUserEvent(e); |
| 93 | } |
| 94 | |
| 95 | void SkProgressBarView::setProgress(int progress) |
| 96 | { |
| 97 | fProgress = progress; |
| 98 | SkEvent e("user"); |
| 99 | e.setString("id", "setProgress"); |
| 100 | e.setS32("newProgress", progress); |
| 101 | fAnim.doUserEvent(e); |
| 102 | } |