-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
127 lines (107 loc) · 3.63 KB
/
Copy pathButton.cpp
File metadata and controls
127 lines (107 loc) · 3.63 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//Button.cpp
#include "Button.h"
#include <iostream>
using namespace sdlUtility;
namespace sdlGUI {
Button::Button() {
Next = Previous = NULL;
Type = Buttons::Standard;
Checked = false; ShareInput = true;
DisplayList = NULL;
DisplayMessage = NULL;
}
List *Button::GetDisplayList() {
if (Type == Buttons::DropDown) return DisplayList; else return NULL;
}
Message *Button::GetDisplayMessage() {
if (Type == Buttons::DropDown) return DisplayMessage; else return NULL;
}
int Button::GetType() {
return Type;
}
bool Button::IsChecked() {
if (Type == Buttons::Checkbox) return Checked; else return false;
}
void Button::OnLeftButtonDown() {
if (!Disabled) {
if (Type == Buttons::Standard) {
Renderable.SetTile(3);
ChildrenOffset = Vector2(1, 1);
} else if (Type == Buttons::DropDown) {
Renderable.SetTile(3);
}
}
}
void Button::OnLeftButtonUp() {
if (!Disabled) {
if (Type == Buttons::Standard) {
if (Hovered) Renderable.SetTile(2); else Renderable.SetTile(1);
ChildrenOffset = Vector2(0, 0);
} else if (Type == Buttons::DropDown) {
if (Hovered) Renderable.SetTile(2); else Renderable.SetTile(1);
if (DisplayList) DisplayList->Toggle();
} else if (Type == Buttons::Checkbox) {
ToggleCheck();
}
}
}
void Button::OnMouseIn() {
if (!Disabled) {
if (Type == Buttons::Standard) {
Renderable.SetTile(2);
} else if (Type == Buttons::DropDown) {
Renderable.SetTile(2);
} else if (Type == Buttons::Checkbox) {
if (Checked) Renderable.SetTile(4); else Renderable.SetTile(2);
}
if (IsHovered()) Renderable.SetColor(sdlObjects::Color::Hovered);
}
}
void Button::OnMouseOut() {
if (!Disabled) {
if (Type == Buttons::Standard) {
Renderable.SetTile(1);
ChildrenOffset = Vector2(0, 0);
} else if (Type == Buttons::DropDown) {
Renderable.SetTile(1);
} else if (Type == Buttons::Checkbox) {
if (Checked) Renderable.SetTile(3); else Renderable.SetTile(1);
}
if (!IsHovered()) Renderable.SetColor(sdlObjects::Color::Idle);
}
}
void Button::SetChecked(bool State) {
if (Type == Buttons::Checkbox) {
if (State) {
if (!Checked) Renderable.SetTile(Renderable.GetTile()+2);
} else {
if (Checked) Renderable.SetTile(Renderable.GetTile()-2);
}
Checked = State;
}
}
void Button::SetDisplayList(List *DisplayList) {
if (Type == Buttons::DropDown) this->DisplayList = DisplayList;
}
void Button::SetDisplayMessage(Message *DisplayMessage) {
if (Type == Buttons::DropDown) this->DisplayMessage = DisplayMessage;
}
void Button::SetType(int Type) {
this->Type = Type;
if (Type == Buttons::Checkbox) {
CopyInput = true;
} else CopyInput = false;
}
void Button::ToggleCheck() {
if (Type == Buttons::Checkbox) {
if (Checked) SetChecked(false); else SetChecked(true);
}
}
Button::~Button() {
Next = Previous = NULL;
Type = Buttons::Standard;
Checked = ShareInput = false;
DisplayList = NULL;
DisplayMessage = NULL;
}
}