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