3 This file is part of libmspgltk
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/input/keys.h>
9 #include <msp/time/units.h>
10 #include <msp/time/utils.h>
18 Root::Root(const Resources &r, Graphics::Window &w):
25 set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
29 window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
30 window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
31 window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
32 window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press_event));
33 window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event));
38 if(tooltip_timeout && Time::now()>tooltip_timeout)
41 if(Widget *wdg=get_descendant_at(pointer_x, pointer_y))
43 tip=wdg->get_tooltip();
48 tip=signal_tooltip.emit(pointer_x, pointer_y);
56 lbl_tooltip=new Label(res);
58 lbl_tooltip->set_style("tooltip");
61 lbl_tooltip->set_text(tip);
62 lbl_tooltip->autosize();
63 const Geometry &tip_geom=lbl_tooltip->get_geometry();
64 unsigned x=pointer_x+10;
65 unsigned y=pointer_y-10-lbl_tooltip->get_geometry().h;
66 if(x+tip_geom.w>geom.w)
68 if(pointer_x>static_cast<int>(tip_geom.w+2))
69 x=pointer_x-2-tip_geom.w;
73 lbl_tooltip->set_position(x, y);
75 lbl_tooltip->set_visible(true);
78 tooltip_timeout=Time::TimeStamp();
82 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
86 translate_coords(x, y);
87 button_press(x, y, btn);
91 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
95 translate_coords(x, y);
96 button_release(x, y, btn);
100 void Root::pointer_motion_event(int x, int y)
104 translate_coords(x, y);
105 pointer_motion(x, y);
111 tooltip_timeout=Time::now()+700*Time::msec;
113 else if(get_descendant_at(x, y)!=tooltip_target)
116 lbl_tooltip->set_visible(false);
122 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
125 key_press(Input::key_from_sys(key), mod, ch);
128 void Root::key_release_event(unsigned key, unsigned mod)
131 key_release(Input::key_from_sys(key), mod);
134 void Root::translate_coords(int &x, int &y)
136 x=x*geom.w/window.get_width();
137 y=geom.h-1-y*geom.h/window.get_height();