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