I don't think I'll bother any more with this, so I'll just make it start
[ld42_outofspace] / src / goatkit / widget.h
1 /*
2 GoatKit - a themable/animated widget toolkit for games
3 Copyright (C) 2014-2018 John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef GOATKIT_WIDGET_H_
19 #define GOATKIT_WIDGET_H_
20
21 #include "vec.h"
22 #include "event.h"
23
24 namespace goatkit {
25
26 struct BBox {
27         Vec2 bmin, bmax;
28 };
29
30 class Screen;
31 class Widget;
32 struct WidgetImpl;
33
34 typedef void (*EventCallback)(Widget*, const Event &ev, void *cls);
35
36 class Widget {
37 protected:
38         WidgetImpl *widget;
39
40         virtual void set_screen(Screen *scr);
41         Screen *get_screen() const;
42
43 public:
44         Widget();
45         virtual ~Widget();
46
47         virtual const char *get_type_name() const;
48
49         virtual void set_name(const char *name);
50         virtual const char *get_name() const;
51
52         virtual void set_text(const char *text);
53         virtual const char *get_text() const;
54
55         virtual void show();
56         virtual void hide();
57         virtual float get_visibility() const;
58         virtual bool is_visible() const;
59         virtual void set_visibility_transition(long msec);
60         virtual long get_visibility_transition() const;
61
62         virtual void activate();
63         virtual void deactivate();
64         virtual float get_active() const;
65         virtual bool is_active() const;
66         virtual void set_active_transition(long msec);
67         virtual long get_active_transition() const;
68
69         virtual void press();
70         virtual void release();
71         virtual float get_pressed() const;
72         virtual bool is_pressed() const;
73         virtual void set_press_transition(long msec);
74         virtual long get_press_transition() const;
75
76         virtual void mousein();
77         virtual void mouseout();
78         virtual float get_under_mouse() const;
79         virtual bool is_under_mouse() const;
80         virtual void set_hover_transition(long msec);
81         virtual long get_hover_transition() const;
82
83         // input focus, managed by the screen
84         virtual bool can_focus() const;
85         virtual void focusin();
86         virtual void focusout();
87         virtual float get_focus() const;
88         virtual bool is_focused() const;
89         virtual void set_focus_transition(long msec);
90         virtual long get_focus_transition() const;
91
92         virtual void set_position(float x, float y);
93         virtual void set_position(const Vec2 &pos);
94         virtual const Vec2 &get_position() const;
95
96         virtual void set_size(float x, float y);
97         virtual void set_size(const Vec2 &size);
98         virtual const Vec2 get_size() const;
99
100         virtual const BBox &get_box() const;
101
102         virtual bool hit_test(const Vec2 &pt) const;
103
104         virtual void draw() const;
105
106         // low level events
107         virtual void on_mouse_button(const ButtonEvent &ev);
108         virtual void on_mouse_motion(const MotionEvent &ev);
109         virtual void on_mouse_focus(const FocusEvent &ev);
110         virtual void on_key(const KeyEvent &ev);
111
112         // high level events
113         virtual void on_click();
114         virtual void on_double_click();
115         virtual void on_change();
116         //virtual void on_drag_move(int bn, const Vec2 &pt);
117         //virtual void on_drag_release(int bn, const Vec2 &pt);
118
119         // event dispatcher
120         virtual void handle_event(const Event &ev);
121
122         // external callback setting
123         virtual void set_callback(EventType evtype, EventCallback func, void *cls = 0);
124
125         friend class Screen;
126 };
127
128 }
129
130 #endif  // GOATKIT_WIDGET_H_