-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbar.cpp
More file actions
69 lines (59 loc) · 1.23 KB
/
Copy pathbar.cpp
File metadata and controls
69 lines (59 loc) · 1.23 KB
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
#include "stdafx.h"
#include "bar.h"
#include "director.h"
Bar::Bar(Scene* theScene, string background, string foreground, string CallbackName, int layer) \
:_theScene(theScene), Callback(CallbackName), value(1.0f), _layer(layer)
{
_background = new Sprite(background, _layer-1);
_foreground = new Sprite(foreground, _layer);
_background->setAnchorPoint(0, 0.5);
_foreground->setAnchorPoint(0, 0.5);
backgroundID = _theScene->addchild(_background);
foregroundID = _theScene->addchild(_foreground);
Director::getTheInstance()->registerEvent(this, &Bar::onValueChange);
updateByValue(1.0f);
}
Bar::~Bar()
{
}
void Bar::setSize(Size size)
{
_size = size;
}
void Bar::setSize(float width, float height)
{
_size.width = width;
_size.height = height;
}
Size Bar::getSize()
{
return _size;
}
void Bar::setPos(Point pos)
{
_pos = pos;
}
void Bar::setPos(float x, float y)
{
_pos.x = x;
_pos.y = y;
}
Point Bar::getPos()
{
return _pos;
}
void Bar::onValueChange(EventMsg msg)
{
if (msg.name == Callback)
{
updateByValue(msg.param);
}
}
void Bar::updateByValue(float _value)
{
value = _value;
_background->setsize(_size);
_background->setpos(_pos);
_foreground->setsize(_size.width*value, _size.height);
_foreground->setpos(_pos);
}