1 #include <msp/gl/blend.h>
2 #include <msp/input/keys.h>
3 #include <msp/time/units.h>
4 #include <msp/time/utils.h>
12 Root::Root(const Resources &r, Graphics::Window &w):
20 set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
24 mouse.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
25 mouse.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
26 mouse.signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event));
27 keyboard.signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event));
28 keyboard.signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
29 keyboard.signal_character.connect(sigc::mem_fun(this, &Root::character_event));
34 if(tooltip_timeout && Time::now()>tooltip_timeout)
37 if(Widget *wdg = get_descendant_at(pointer_x, pointer_y))
39 tip = wdg->get_tooltip();
44 tip = signal_tooltip.emit(pointer_x, pointer_y);
45 tooltip_target = this;
52 lbl_tooltip = new Label;
54 lbl_tooltip->set_style("tooltip");
57 lbl_tooltip->set_text(tip);
58 lbl_tooltip->autosize();
59 const Geometry &tip_geom = lbl_tooltip->get_geometry();
60 unsigned x = pointer_x+10;
61 unsigned y = pointer_y-10-lbl_tooltip->get_geometry().h;
62 if(x+tip_geom.w>geom.w)
64 if(pointer_x>static_cast<int>(tip_geom.w+2))
65 x = pointer_x-2-tip_geom.w;
67 x = geom.w-tip_geom.w;
69 lbl_tooltip->set_position(x, y);
71 lbl_tooltip->set_visible(true);
74 tooltip_timeout = Time::TimeStamp();
78 void Root::render() const
80 GL::MatrixStack::projection() = GL::Matrix::ortho_bottomleft(geom.w, geom.h);
81 GL::MatrixStack::modelview() = GL::Matrix();
82 GL::Bind bind_blend(GL::Blend::alpha());
84 GL::Renderer renderer(0);
85 Widget::render(renderer);
88 void Root::button_press_event(unsigned btn)
94 button_press(x, y, btn);
98 void Root::button_release_event(unsigned btn)
104 button_release(x, y, btn);
108 void Root::axis_motion_event(unsigned, float, float)
114 pointer_motion(x, y);
120 tooltip_timeout = Time::now()+700*Time::msec;
122 else if(get_descendant_at(x, y)!=tooltip_target)
125 lbl_tooltip->set_visible(false);
131 void Root::key_press_event(unsigned key)
138 void Root::key_release_event(unsigned key)
144 void Root::character_event(StringCodec::unichar ch)
150 void Root::get_pointer(int &x, int &y)
152 x = (mouse.get_axis_value(0)*0.5+0.5)*geom.w;
153 y = (mouse.get_axis_value(1)*0.5+0.5)*geom.h;