michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #include "SkProgressBarView.h" michael@0: #include "SkAnimator.h" michael@0: #include "SkWidgetViews.h" michael@0: #include "SkTime.h" michael@0: #include "SkSystemEventTypes.h" michael@0: michael@0: SkProgressBarView::SkProgressBarView() michael@0: { michael@0: init_skin_anim(kProgress_SkinEnum, &fAnim); michael@0: fAnim.setHostEventSink(this); michael@0: fProgress = 0; michael@0: fMax = 100; michael@0: michael@0: } michael@0: michael@0: void SkProgressBarView::changeProgress(int diff) michael@0: { michael@0: int newProg = fProgress + diff; michael@0: if (newProg > 0 && newProg < fMax) michael@0: this->setProgress(newProg); michael@0: //otherwise i'll just leave it as it is michael@0: //this implies that if a new max and progress are set, max must be set first michael@0: } michael@0: michael@0: /*virtual*/ void SkProgressBarView::onDraw(SkCanvas* canvas) michael@0: { michael@0: SkPaint paint; michael@0: SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); michael@0: michael@0: if (diff == SkAnimator::kDifferent) michael@0: this->inval(NULL); michael@0: else if (diff == SkAnimator::kPartiallyDifferent) michael@0: { michael@0: SkRect bounds; michael@0: fAnim.getInvalBounds(&bounds); michael@0: this->inval(&bounds); michael@0: } michael@0: } michael@0: michael@0: /*virtual*/ bool SkProgressBarView::onEvent(const SkEvent& evt) michael@0: { michael@0: if (evt.isType(SK_EventType_Inval)) michael@0: { michael@0: this->inval(NULL); michael@0: return true; michael@0: } michael@0: if (evt.isType("recommendDim")) michael@0: { michael@0: SkScalar height; michael@0: michael@0: if (evt.findScalar("y", &height)) michael@0: this->setHeight(height); michael@0: return true; michael@0: } michael@0: return this->INHERITED::onEvent(evt); michael@0: } michael@0: michael@0: /*virtual*/ void SkProgressBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node) michael@0: { michael@0: this->INHERITED::onInflate(dom, node); michael@0: int32_t temp; michael@0: if (dom.findS32(node, "max", &temp)) michael@0: this->setMax(temp); michael@0: if (dom.findS32(node, "progress", &temp)) michael@0: this->setProgress(temp); michael@0: } michael@0: michael@0: /*virtual*/ void SkProgressBarView::onSizeChange() michael@0: { michael@0: this->INHERITED::onSizeChange(); michael@0: SkEvent evt("user"); michael@0: evt.setString("id", "setDim"); michael@0: evt.setScalar("dimX", this->width()); michael@0: evt.setScalar("dimY", this->height()); michael@0: fAnim.doUserEvent(evt); michael@0: } michael@0: michael@0: void SkProgressBarView::reset() michael@0: { michael@0: fProgress = 0; michael@0: SkEvent e("user"); michael@0: e.setString("id", "reset"); michael@0: fAnim.doUserEvent(e); michael@0: } michael@0: michael@0: void SkProgressBarView::setMax(int max) michael@0: { michael@0: fMax = max; michael@0: SkEvent e("user"); michael@0: e.setString("id", "setMax"); michael@0: e.setS32("newMax", max); michael@0: fAnim.doUserEvent(e); michael@0: } michael@0: michael@0: void SkProgressBarView::setProgress(int progress) michael@0: { michael@0: fProgress = progress; michael@0: SkEvent e("user"); michael@0: e.setString("id", "setProgress"); michael@0: e.setS32("newProgress", progress); michael@0: fAnim.doUserEvent(e); michael@0: }