aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/SkProgressBarView.cpp
blob: a9fd516458cf3792d967b83a67dc91d2fb1470cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "SkProgressBarView.h"
#include "SkAnimator.h"
#include "SkWidgetViews.h"
#include "SkTime.h"
#include "SkSystemEventTypes.h"

SkProgressBarView::SkProgressBarView()
{
	init_skin_anim(kProgress_SkinEnum, &fAnim);
	fAnim.setHostEventSink(this);
	fProgress = 0;
	fMax = 100;
	
}

void SkProgressBarView::changeProgress(int diff)
{
	int newProg = fProgress + diff;
	if (newProg > 0 && newProg < fMax)
		this->setProgress(newProg);
	//otherwise i'll just leave it as it is
	//this implies that if a new max and progress are set, max must be set first
}

/*virtual*/ void SkProgressBarView::onDraw(SkCanvas* canvas)
{
	SkPaint						paint;		
	SkAnimator::DifferenceType	diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
	
	if (diff == SkAnimator::kDifferent)
		this->inval(NULL);
	else if (diff == SkAnimator::kPartiallyDifferent)
	{
		SkRect	bounds;
		fAnim.getInvalBounds(&bounds);
		this->inval(&bounds);
	}
}
	
/*virtual*/ bool SkProgressBarView::onEvent(const SkEvent& evt)
{
	if (evt.isType(SK_EventType_Inval))
	{
		this->inval(NULL);
		return true;
	}
	if (evt.isType("recommendDim"))
	{
		SkScalar	height;
		
		if (evt.findScalar("y", &height))
			this->setHeight(height);
		return true;
	}
	return this->INHERITED::onEvent(evt);
}

/*virtual*/ void SkProgressBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);
	int32_t temp;
	if (dom.findS32(node, "max", &temp))
		this->setMax(temp);
	if (dom.findS32(node, "progress", &temp))
		this->setProgress(temp);
}

/*virtual*/ void SkProgressBarView::onSizeChange()
{
	this->INHERITED::onSizeChange();
	SkEvent evt("user");
	evt.setString("id", "setDim");
	evt.setScalar("dimX", this->width());
	evt.setScalar("dimY", this->height());
	fAnim.doUserEvent(evt);
}

void SkProgressBarView::reset()
{
	fProgress = 0;
	SkEvent e("user");
	e.setString("id", "reset");
	fAnim.doUserEvent(e);
}

void SkProgressBarView::setMax(int max)
{
	fMax = max;
	SkEvent e("user");
	e.setString("id", "setMax");
	e.setS32("newMax", max);
	fAnim.doUserEvent(e);
}

void SkProgressBarView::setProgress(int progress)
{
	fProgress = progress;
	SkEvent e("user");
	e.setString("id", "setProgress");
	e.setS32("newProgress", progress);
	fAnim.doUserEvent(e);
}