]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
a59c939b5b1415d1e918c7fe7c7a023652303ee6
[libs/gltk.git] / source / root.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "root.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 Root::Root(Resources &r, Window &w):
14         Panel(r),
15         window(w)
16 {
17         set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
18
19         update_style();
20
21         window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
22         window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
23         window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
24 }
25
26 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
27 {
28         translate_coords(x, y);
29         button_press(x, y, btn);
30 }
31
32 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
33 {
34         translate_coords(x, y);
35         button_release(x, y, btn);
36 }
37
38 void Root::pointer_motion_event(int x, int y)
39 {
40         translate_coords(x, y);
41         pointer_motion(x, y);
42 }
43
44 void Root::translate_coords(int &x, int &y)
45 {
46         x=x*geom.w/window.get_width();
47         y=geom.h-1-y*geom.h/window.get_height();
48 }
49
50 } // namespace GLtk
51 } // namespace Msp