]> git.tdb.fi Git - libs/gltk.git/blob - source/root.cpp
Add Toggle widget
[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_event));
25         window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event));
26 }
27
28 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
29 {
30         if(visible)
31         {
32                 translate_coords(x, y);
33                 button_press(x, y, btn);
34         }
35 }
36
37 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
38 {
39         if(visible)
40         {
41                 translate_coords(x, y);
42                 button_release(x, y, btn);
43         }
44 }
45
46 void Root::pointer_motion_event(int x, int y)
47 {
48         if(visible)
49         {
50                 translate_coords(x, y);
51                 pointer_motion(x, y);
52         }
53 }
54
55 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
56 {
57         if(visible)
58                 key_press(key, mod, ch);
59 }
60
61 void Root::key_release_event(unsigned key, unsigned mod)
62 {
63         if(visible)
64                 key_release(key, mod);
65 }
66
67 void Root::translate_coords(int &x, int &y)
68 {
69         x=x*geom.w/window.get_width();
70         y=geom.h-1-y*geom.h/window.get_height();
71 }
72
73 } // namespace GLtk
74 } // namespace Msp