1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/views/animated/SkProgressBarView.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 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 +#include "SkProgressBarView.h" 1.12 +#include "SkAnimator.h" 1.13 +#include "SkWidgetViews.h" 1.14 +#include "SkTime.h" 1.15 +#include "SkSystemEventTypes.h" 1.16 + 1.17 +SkProgressBarView::SkProgressBarView() 1.18 +{ 1.19 + init_skin_anim(kProgress_SkinEnum, &fAnim); 1.20 + fAnim.setHostEventSink(this); 1.21 + fProgress = 0; 1.22 + fMax = 100; 1.23 + 1.24 +} 1.25 + 1.26 +void SkProgressBarView::changeProgress(int diff) 1.27 +{ 1.28 + int newProg = fProgress + diff; 1.29 + if (newProg > 0 && newProg < fMax) 1.30 + this->setProgress(newProg); 1.31 + //otherwise i'll just leave it as it is 1.32 + //this implies that if a new max and progress are set, max must be set first 1.33 +} 1.34 + 1.35 +/*virtual*/ void SkProgressBarView::onDraw(SkCanvas* canvas) 1.36 +{ 1.37 + SkPaint paint; 1.38 + SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); 1.39 + 1.40 + if (diff == SkAnimator::kDifferent) 1.41 + this->inval(NULL); 1.42 + else if (diff == SkAnimator::kPartiallyDifferent) 1.43 + { 1.44 + SkRect bounds; 1.45 + fAnim.getInvalBounds(&bounds); 1.46 + this->inval(&bounds); 1.47 + } 1.48 +} 1.49 + 1.50 +/*virtual*/ bool SkProgressBarView::onEvent(const SkEvent& evt) 1.51 +{ 1.52 + if (evt.isType(SK_EventType_Inval)) 1.53 + { 1.54 + this->inval(NULL); 1.55 + return true; 1.56 + } 1.57 + if (evt.isType("recommendDim")) 1.58 + { 1.59 + SkScalar height; 1.60 + 1.61 + if (evt.findScalar("y", &height)) 1.62 + this->setHeight(height); 1.63 + return true; 1.64 + } 1.65 + return this->INHERITED::onEvent(evt); 1.66 +} 1.67 + 1.68 +/*virtual*/ void SkProgressBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node) 1.69 +{ 1.70 + this->INHERITED::onInflate(dom, node); 1.71 + int32_t temp; 1.72 + if (dom.findS32(node, "max", &temp)) 1.73 + this->setMax(temp); 1.74 + if (dom.findS32(node, "progress", &temp)) 1.75 + this->setProgress(temp); 1.76 +} 1.77 + 1.78 +/*virtual*/ void SkProgressBarView::onSizeChange() 1.79 +{ 1.80 + this->INHERITED::onSizeChange(); 1.81 + SkEvent evt("user"); 1.82 + evt.setString("id", "setDim"); 1.83 + evt.setScalar("dimX", this->width()); 1.84 + evt.setScalar("dimY", this->height()); 1.85 + fAnim.doUserEvent(evt); 1.86 +} 1.87 + 1.88 +void SkProgressBarView::reset() 1.89 +{ 1.90 + fProgress = 0; 1.91 + SkEvent e("user"); 1.92 + e.setString("id", "reset"); 1.93 + fAnim.doUserEvent(e); 1.94 +} 1.95 + 1.96 +void SkProgressBarView::setMax(int max) 1.97 +{ 1.98 + fMax = max; 1.99 + SkEvent e("user"); 1.100 + e.setString("id", "setMax"); 1.101 + e.setS32("newMax", max); 1.102 + fAnim.doUserEvent(e); 1.103 +} 1.104 + 1.105 +void SkProgressBarView::setProgress(int progress) 1.106 +{ 1.107 + fProgress = progress; 1.108 + SkEvent e("user"); 1.109 + e.setString("id", "setProgress"); 1.110 + e.setS32("newProgress", progress); 1.111 + fAnim.doUserEvent(e); 1.112 +}