-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.h
126 lines (113 loc) · 3.13 KB
/
gui.h
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
class Widget;
typedef void (*button_event_handler)(Widget *w, int button, int x, int y);
typedef void (*mouse_move_handler)(Widget *w, int x, int y);
typedef void (*paint_handler)(Widget *w);
class Widget {
public:
int x_, y_, w_, h_;
virtual void button_down(int button, int x, int y) {}
virtual void button_up(int button, int x, int y) {}
//virtual void mouse_leave() {}
//virtual void mouse_enter() {}
virtual void mouse_move(int x, int y) {}
virtual void paint() {}
void set_size(int w, int h);
Widget(): x_(0), y_(0), w_(0), h_(0) {}
virtual ~Widget() {}
};
class Container: public Widget {
public:
int n_child_;
Widget **children_;
int cap_;
void add_child(Widget *child, int x, int y);
Container(int cap);
void paint() override;
void button_down(int button, int x, int y) override;
};
class Panel: public Container {
public:
enum Bevel {
BEVEL_NONE,
BEVEL_INNER,
BEVEL_OUTER,
} bevel_;
Panel(int cap, Bevel bevel);
void paint() override;
};
class ImageWidget: public Widget {
public:
SDL_Texture *tex_;
ImageWidget(SDL_Texture *tex);
void paint() override;
};
class Canvas: public Widget {
public:
button_event_handler button_down_;
button_event_handler button_up_;
mouse_move_handler mouse_move_;
paint_handler paint_;
void paint() override;
void button_down(int button, int x, int y) override;
void button_up(int button, int x, int y) override;
void mouse_move(int x, int y) override;
};
class TextArea {
SDL_Texture *tex_;
int tex_w_, tex_h_;
public:
SDL_Color color_;
int style_;
void set_text(const char *);
void paint(int x, int y, int w, int h);
TextArea();
void set_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
};
class TextWidget: public Widget {
TextArea text_area_;
public:
void paint() override;
void set_text(const char *);
void set_text_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
};
class Edit: public Widget {
TextArea text_area_;
std::string text_;
public:
void paint() override;
};
class Button: public Widget {
bool depressed_;
bool left_button_down_;
public:
button_event_handler click_;
TextArea caption_;
Button(button_event_handler cb);
void paint() override;
void button_down(int button, int x, int y) override;
void button_up(int button, int x, int y) override;
//void mouse_leave() override;
//void mouse_enter() override;
void mouse_move(int x, int y) override;
void set_text(const char *);
};
class Palette: public Widget {
public:
int n_col_;
int n_row_;
int n_sprite_;
SDL_Texture **sprites_;
int selection1_, selection2_;
void paint() override;
void button_down(int button, int x, int y) override;
Palette(int n_col, int n_sprite, SDL_Texture **sprites);
};
extern Container *root;
extern SDL_Renderer *renderer;
void init_gui(int root_cap);
void handle_button_down(SDL_MouseButtonEvent *e);
void handle_button_up(SDL_MouseButtonEvent *e);
void handle_mouse_motion(SDL_MouseMotionEvent *e);
void draw_gui(void);
void capture_mouse(Widget *w);
void release_mouse();