]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
32cd87940fe22e71abcef2769f2c3b6516181005
[libs/gltk.git] / source / root.cpp
1 #include "root.h"
2
3 namespace Msp {
4 namespace GLtk {
5
6 Root::Root(Resources &r, Window &w):
7         Panel(r),
8         window(w)
9 {
10         set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
11
12         update_style();
13
14         window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
15         window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
16         window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
17 }
18
19 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
20 {
21         translate_coords(x, y);
22         button_press(x, y, btn);
23 }
24
25 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
26 {
27         translate_coords(x, y);
28         button_release(x, y, btn);
29 }
30
31 void Root::pointer_motion_event(int x, int y)
32 {
33         translate_coords(x, y);
34         pointer_motion(x, y);
35 }
36
37 void Root::translate_coords(int &x, int &y)
38 {
39         x=x*geom.w/window.get_width();
40         y=geom.h-1-y*geom.h/window.get_height();
41 }
42
43 } // namespace GLtk
44 } // namespace Msp