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)
40 if(Widget *wdg=get_descendant_at(pointer_x, pointer_y))
42 const std::string &tip=wdg->get_tooltip();
47 lbl_tooltip=new Label(res);
49 lbl_tooltip->set_style("tooltip");
52 lbl_tooltip->set_text(tip);
53 lbl_tooltip->autosize();
54 const Geometry &tip_geom=lbl_tooltip->get_geometry();
55 unsigned x=pointer_x+10;
56 unsigned y=pointer_y-10-lbl_tooltip->get_geometry().h;
57 if(x+tip_geom.w>geom.w)
59 if(pointer_x>static_cast<int>(tip_geom.w+2))
60 x=pointer_x-2-tip_geom.w;
64 lbl_tooltip->set_position(x, y);
66 lbl_tooltip->set_visible(true);
67 tooltip_timeout=Time::TimeStamp();
74 void Root::button_press_event(int x, int y, unsigned btn, unsigned)
78 translate_coords(x, y);
79 button_press(x, y, btn);
83 void Root::button_release_event(int x, int y, unsigned btn, unsigned)
87 translate_coords(x, y);
88 button_release(x, y, btn);
92 void Root::pointer_motion_event(int x, int y)
96 translate_coords(x, y);
105 tooltip_timeout=Time::now()+700*Time::msec;
108 tooltip_timeout=Time::TimeStamp();
110 else if(get_descendant_at(x, y)!=tooltip_target)
112 lbl_tooltip->set_visible(false);
118 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
121 key_press(Input::key_from_sys(key), mod, ch);
124 void Root::key_release_event(unsigned key, unsigned mod)
127 key_release(Input::key_from_sys(key), mod);
130 void Root::translate_coords(int &x, int &y)
132 x=x*geom.w/window.get_width();
133 y=geom.h-1-y*geom.h/window.get_height();