]> git.tdb.fi Git - libs/gltk.git/blob - source/root.h
Rudimentary touchscreen support
[libs/gltk.git] / source / root.h
1 #ifndef MSP_GLTK_ROOT_H_
2 #define MSP_GLTK_ROOT_H_
3
4 #include <sigc++/trackable.h>
5 #include <msp/gl/camera.h>
6 #include <msp/gl/program.h>
7 #include <msp/graphics/window.h>
8 #include <msp/input/keyboard.h>
9 #include <msp/input/mouse.h>
10 #include <msp/input/touchscreen.h>
11 #include <msp/time/timestamp.h>
12 #include "panel.h"
13
14 namespace Msp {
15 namespace GLtk {
16
17 class Label;
18
19 /**
20 A Root is a special type of Panel that covers the entire viewport and receives
21 input from keyboard and mouse.
22 */
23 class Root: public Panel, public sigc::trackable
24 {
25 public:
26         sigc::signal<std::string, int, int> signal_tooltip;
27
28 private:
29         const Resources &resources;
30         Input::Keyboard *keyboard;
31         Input::Mouse *mouse;
32         Input::Touchscreen *touchscreen;
33         bool own_input;
34         Label *lbl_tooltip;
35         int pointer_x;
36         int pointer_y;
37         Time::TimeStamp tooltip_timeout;
38         Widget *tooltip_target;
39         Msp::GL::Camera camera;
40         Msp::GL::Program *shprog;
41
42 public:
43         /** Creates a Root widget for a window.  The geometry is set to match the
44         window's size, and input devices are created automatically. */
45         Root(const Resources &, Graphics::Window &);
46
47         /** Creates a Root widget with custom input devices.  If window is not null,
48         it is used to set the widget's initial geometry. */
49         Root(const Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *, Input::Touchscreen * = 0);
50 private:
51         void init(Graphics::Window *);
52 public:
53         virtual ~Root();
54
55         virtual const char *get_class() const { return "root"; }
56
57         const Resources &get_resources() const { return resources; }
58         virtual unsigned get_width() const { return geom.w; }
59         virtual unsigned get_height() const { return geom.h; }
60
61         void tick();
62         void render() const;
63
64 private:
65         bool button_press_event(unsigned);
66         bool button_release_event(unsigned);
67         bool axis_motion_event(unsigned, float, float);
68         bool key_press_event(unsigned);
69         bool key_release_event(unsigned);
70         bool character_event(StringCodec::unichar);
71         bool touch_press_event(unsigned);
72         bool touch_release_event(unsigned);
73         bool touch_motion_event(unsigned, float, float);
74
75         void get_pointer(int &, int &);
76         void get_touch(unsigned, int &, int &);
77         void update_camera();
78
79         virtual void on_geometry_change();
80         virtual void on_child_added(Widget &);
81 };
82
83 } // namespace GLtk
84 } // namespace Msp
85
86 #endif