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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#pragma once
#include "Appearance.h"
#include "Point.h"
#include "Window.h"
#include "Platform.h"
namespace ui
{
class ContextMenu;
class Window;
class Panel;
/* class Component
*
* An interactive UI component that can be added to a state or an XComponent*.
* *See sys::XComponent
*/
class Component
{
private:
Window* parentstate_;
Panel* _parent;
protected:
bool drawn;
ui::Point textPosition;
ui::Point textSize;
ui::Point iconPosition;
ui::ContextMenu * menu;
public:
Component(Window* parent_state);
Component(Point position, Point size);
Component();
virtual ~Component();
void* UserData;
inline Window* const GetParentWindow() const { return parentstate_; }
bool IsFocused() const;
void Invalidate() { drawn = false; }
Point Position;
Point Size;
bool Locked;
bool Visible;
ui::Appearance Appearance;
//virtual void SetAppearance(ui::Appearance);
//ui::Appearance GetAppearance();
virtual void TextPosition(std::string);
void Refresh();
Point GetScreenPos();
/* See the parent of this component.
* If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild)
*/
void SetParentWindow(Window* window);
void SetParent(Panel* new_parent);
//Get the parent component.
inline Panel* const GetParent() const { return _parent; }
virtual void OnContextMenuAction(int item);
//UI functions:
/*
void Tick(float dt);
void Draw(const Point& screenPos);
void OnMouseHover(int localx, int localy);
void OnMouseMoved(int localx, int localy, int dx, int dy);
void OnMouseMovedInside(int localx, int localy, int dx, int dy);
void OnMouseEnter(int localx, int localy);
void OnMouseLeave(int localx, int localy);
void OnMouseDown(int x, int y, unsigned int button);
void OnMouseUp(int x, int y, unsigned int button);
void OnMouseClick(int localx, int localy, unsigned int button);
void OnMouseUnclick(int localx, int localy, unsigned int button);
void OnMouseWheel(int localx, int localy, int d);
void OnMouseWheelInside(int localx, int localy, int d);
void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
*/
///
// Called: Every tick.
// Params:
// dt: The change in time.
///
virtual void Tick(float dt);
///
// Called: When ready to draw.
// Params:
// None
///
virtual void Draw(const Point& screenPos);
///
// Called: When the mouse is currently hovering over the item. (Called every tick)
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
///
virtual void OnMouseHover(int localx, int localy);
///
// Called: When the mouse moves.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
///
// Called: When the mouse moves.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy);
///
// Called: When the mouse moves on top of the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
virtual void OnMouseEnter(int localx, int localy);
///
// Called: When the mouse leaves the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
///
virtual void OnMouseLeave(int localx, int localy);
///
// Called: When a mouse button is pressed.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being held down.
///
virtual void OnMouseDown(int x, int y, unsigned button);
///
// Called: When a mouse button is released.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being released.
///
virtual void OnMouseUp(int x, int y, unsigned button);
///
// Called: When a mouse button is pressed on top of the item.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being held down.
///
virtual void OnMouseClick(int localx, int localy, unsigned button);
///
// Called: When a mouse button is released on top of the item.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being released.
///
virtual void OnMouseUnclick(int localx, int localy, unsigned button);
///
// Called: When the mouse wheel moves/changes.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
///
virtual void OnMouseWheel(int localx, int localy, int d);
///
// Called: When the mouse wheel moves/changes on top of the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
///
virtual void OnMouseWheelInside(int localx, int localy, int d);
///
// Called: When a key is pressed.
// Params:
// key: The value of the key that is being pressed.
// shift: Shift key is down.
// ctrl: Control key is down.
// alt: Alternate key is down.
///
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
///
// Called: When a key is released.
// Params:
// key: The value of the key that is being released.
// shift: Shift key is released.
// ctrl: Control key is released.
// alt: Alternate key is released.
///
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
};
}
|