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