]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
bb3913c73fbf5db85fc85217a98dce872417666a
[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, Graphics::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         window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press));
25         window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release));
26 }
27
28 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
29 {
30         translate_coords(x, y);
31         button_press(x, y, btn);
32 }
33
34 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
35 {
36         translate_coords(x, y);
37         button_release(x, y, btn);
38 }
39
40 void Root::pointer_motion_event(int x, int y)
41 {
42         translate_coords(x, y);
43         pointer_motion(x, y);
44 }
45
46 void Root::translate_coords(int &x, int &y)
47 {
48         x=x*geom.w/window.get_width();
49         y=geom.h-1-y*geom.h/window.get_height();
50 }
51
52 } // namespace GLtk
53 } // namespace Msp