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