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