]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
Add Container class
[libs/gltk.git] / source / root.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007-2009  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         Widget(r),
16         Panel(r),
17         window(w)
18 {
19         set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
20
21         update_style();
22
23         window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
24         window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
25         window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
26         window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press_event));
27         window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event));
28 }
29
30 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
31 {
32         if(visible)
33         {
34                 translate_coords(x, y);
35                 button_press(x, y, btn);
36         }
37 }
38
39 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
40 {
41         if(visible)
42         {
43                 translate_coords(x, y);
44                 button_release(x, y, btn);
45         }
46 }
47
48 void Root::pointer_motion_event(int x, int y)
49 {
50         if(visible)
51         {
52                 translate_coords(x, y);
53                 pointer_motion(x, y);
54         }
55 }
56
57 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
58 {
59         if(visible)
60                 key_press(Input::key_from_sys(key), mod, ch);
61 }
62
63 void Root::key_release_event(unsigned key, unsigned mod)
64 {
65         if(visible)
66                 key_release(Input::key_from_sys(key), mod);
67 }
68
69 void Root::translate_coords(int &x, int &y)
70 {
71         x=x*geom.w/window.get_width();
72         y=geom.h-1-y*geom.h/window.get_height();
73 }
74
75 } // namespace GLtk
76 } // namespace Msp