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