blob: 97c6a018e735a769a68b569fa6ab5bfbc790f6d6 (
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
|
/*
ui/widget.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_WIDGET_H__
#define __INCLUDED_UI_WIDGET_H__
#include <string>
#include <list>
#include "math/vector2f.h"
#include "ui/palette.h"
namespace ui {
class Widget {
public:
/// create a new widget
Widget(Widget *parent=0);
/// destroy a widget
virtual ~Widget();
/* -- inspectors -------------------------------------------- */
inline bool visible() const { return widget_visible; }
inline math::Vector2f &location() { return widget_location; }
inline math::Vector2f &size() { return widget_size; }
inline float const left() const { return widget_location.x; }
inline float const top() const { return widget_location.y; }
inline float const width() const { return widget_size.x; }
inline float const height() const { return widget_size.y; }
inline Palette const *palette() const { return widget_palette; }
inline std::string const &label() const { return widget_label; }
inline bool border() const { return widget_border; }
inline bool background() { return widget_background; }
inline Widget *parent() { return widget_parent; }
/* -- mutators --------------------------------------------- */
/// show the widget
void show();
/// hide the widget
void hide();
/// set location of the top-left corner
void set_location(float const x, float const y);
/// set the widgets width and height
void set_size(float const w, float const h);
/// set the widgets width
void set_width(float const w);
/// set the widgets height
void set_height(float const h);
/// set the widgets palette
void set_palette(Palette *palette);
/// set the widgets label
void set_label(std::string const &label);
/// set the widgets label
void set_label(char const *label);
void set_border(bool border);
void set_background(bool background);
/// resize event
virtual void resize_event();
/// draw event
virtual void draw_event();
/// type definition for child widgets
typedef std::list<Widget *> Children;
/// child widgets
inline Children &children() { return widget_children; }
protected:
/// draw the widget
virtual void draw();
/// resize the widget
virtual void resize();
/// draw the widget background
virtual void draw_background();
/// draw the widget border
virtual void draw_border();
/// list widget content
size_t list(size_t indent);
/// map local widget coordinates to global coordinates
inline math::Vector2f to_global(math::Vector2f v) {
Widget *parent = widget_parent;
while (parent) {
v += parent->location();
parent = parent->widget_parent;
}
return v;
}
private:
Palette *widget_palette;
bool widget_visible;
bool widget_background;
bool widget_border;
math::Vector2f widget_location;
math::Vector2f widget_size;
std::string widget_label;
Children widget_children;
Widget *widget_parent;
Children::iterator find_child(Widget *child);
void add_child(Widget *child);
void remove_child(Widget *child);
};
}
#endif // __INCLUDED_UI_WIDGET_H__
|