blob: 009bed6dbf4c44d31579c48e87bc86560afcfac1 (
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
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
|
/*
ui/ui.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_UI_H__
#define __INCLUDED_UI_H__
#include "ui/console.h"
#include "ui/font.h"
#include "ui/palette.h"
#include "ui/tooltip.h"
#include "ui/widget.h"
#include "ui/window.h"
namespace ui
{
class UI : public Window
{
public:
/// constructor
UI();
/// destructor
~UI();
/// list widgets
void list() const;
/// list visible widgets
void list_visible() const;
/// the console
inline Console *console() {
return ui_console;
}
/// return the widget with global mouse focus
inline Widget *mouse_focus() const {
return ui_mouse_focus;
}
/// return the widget with global input focus
inline Widget *input_focus() const {
return ui_input_focus;
}
/// receive global mouse movement
void input_mouse(const float x, const float y);
/// receive global mouse button events
bool input_mouse_button(const bool pressed, unsigned int button);
/// receive global mouse wheel events
bool input_mouse_wheel(const math::Vector2f & direction);
/// receive global keyboard events
bool input_key(const bool pressed, const int key, const unsigned int modifier);
/// run a user interface frame
void frame();
/// load settings from ui.ini
void load_settings();
/* -- font & icon sizes------------------------------------- */
/// default tiny font
inline const Font *font_tiny() const {
return ui_font_tiny;
}
/// default small font
inline const Font *font_small() const {
return ui_font_small;
}
/// default large font
inline const Font *font_large() const {
return ui_font_large;
}
/* -- mouse pointer ---------------------------------------- */
/// current position of the mouse cursor in global window coordinates
inline const math::Vector2f & global_mouse_coords()
{
return mouse_cursor;
}
/// set mouse pointer bitmap
void set_pointer(const char *pointerbitmap = 0, const Palette::Color color = Palette::Highlight, const bool animated = false);
static bool ui_debug;
/**
* global size of a ui element, used by resize() functions
* */
static math::Vector2f elementsize;
/**
* global padding between ui elements, used by resize() functions
* */
static float padding;
/**
* global margin for frames and widgets, used by resize() functions
* see @Widget::resize();
* */
static float margin;
static float pointer_size;
static float icon_small;
protected:
/* -- event handlers --------------------------------------- */
/// handle keypress events
virtual bool on_keypress(const int key, const unsigned int modifier);
/// handle key release events
virtual bool on_keyrelease(const int key, const unsigned int modifier);
private:
void draw_pointer();
Palette *ui_palette;
Font *ui_font_tiny;
Font *ui_font_small;
Font *ui_font_large;
Widget *ui_mouse_focus;
Widget *ui_input_focus;
Console *ui_console;
/// TODO move to separate object to handle mouse cursor drawing
math::Vector2f mouse_cursor;
std::string mouse_pointer_bitmap;
Palette::Color mouse_pointer_color;
bool mouse_pointer_animated;
bool mouse_buttonleft_pressed;
unsigned long ui_tooltip_timestamp;
};
/// initialize the user interface
void init();
/// shutdown the user interface
void shutdown();
/// the global root window
UI *root();
/// the console
inline Console *console()
{
return root()->console();
}
/// debug mode
inline bool debug()
{
return UI::ui_debug;
}
}
#endif // __INCLUDED_UI_H__
|