]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
9d02c4a70f4a1698124263f55414969573489f54
[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 <msp/input/keys.h>
9 #include "root.h"
10
11 namespace Msp {
12 namespace GLtk {
13
14 Root::Root(const Resources &r, Graphics::Window &w):
15         Panel(r),
16         window(w)
17 {
18         set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
19
20         update_style();
21
22         window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
23         window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
24         window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
25         window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press_event));
26         window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event));
27 }
28
29 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
30 {
31         if(visible)
32         {
33                 translate_coords(x, y);
34                 button_press(x, y, btn);
35         }
36 }
37
38 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
39 {
40         if(visible)
41         {
42                 translate_coords(x, y);
43                 button_release(x, y, btn);
44         }
45 }
46
47 void Root::pointer_motion_event(int x, int y)
48 {
49         if(visible)
50         {
51                 translate_coords(x, y);
52                 pointer_motion(x, y);
53         }
54 }
55
56 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
57 {
58         if(visible)
59                 key_press(Input::key_from_sys(key), mod, ch);
60 }
61
62 void Root::key_release_event(unsigned key, unsigned mod)
63 {
64         if(visible)
65                 key_release(Input::key_from_sys(key), mod);
66 }
67
68 void Root::translate_coords(int &x, int &y)
69 {
70         x=x*geom.w/window.get_width();
71         y=geom.h-1-y*geom.h/window.get_height();
72 }
73
74 } // namespace GLtk
75 } // namespace Msp