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