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