-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.cpp
More file actions
87 lines (74 loc) · 1.29 KB
/
Copy pathbutton.cpp
File metadata and controls
87 lines (74 loc) · 1.29 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "stdafx.h"
#include "button.h"
#include "printText.h"
Button::Button(string pic, int layer) :Sprite(pic, layer)
{
}
Button::Button(GLuint _Texture, int layer) : Sprite(_Texture, layer)
{
}
Button::~Button()
{
}
void Button::setType(buttonType type)
{
_buttonInfo.type = type;
}
buttonType Button::getType()
{
return _buttonInfo.type;
}
void Button::setRadius(float r)
{
_buttonInfo.radius = r;
}
float Button::getRadius()
{
return _buttonInfo.radius;
}
void Button::setRectSize(Size size)
{
_buttonInfo.size = size;
}
Size Button::getRectSize()
{
return _buttonInfo.size;
}
void Button::raiseEvent(EventMsg msg)
{
Director::getTheInstance()->raiseEvent(msg);
}
bool Button::mouseEventCallBack(mouseEvent _event)
{
Point pt = _event.point;
EventMsg msg;
msg.name = callbackName;
pt = convertToLocalSpace(pt);
if (_event.type == DOWN)
{
switch (_buttonInfo.type)
{
case RECTANGLE:
if (pt.x > -_size.width / 2 && pt.x<_size.width / 2 && pt.y>-_size.height / 2 && pt.y < _size.height / 2)
{
raiseEvent(msg);
return true;
}
else
return false;
break;
case CIRCLE:
if (sqrt(pt.x*pt.x + pt.y*pt.y) <= _buttonInfo.radius)
{
raiseEvent(msg);
return true;
}
else
return false;
break;
default:
return false;
break;
}
}
}