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 &window):
14 keyboard(new Input::Keyboard(window)),
15 mouse(new Input::Mouse(window)),
18 set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
23 Root::Root(const Resources &r, Input::Keyboard *k, Input::Mouse *m):
39 mouse->signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
40 mouse->signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
41 mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event));
42 keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event));
43 keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
44 keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event));
58 if(tooltip_timeout && Time::now()>tooltip_timeout)
61 if(Widget *wdg = get_descendant_at(pointer_x, pointer_y))
63 tip = wdg->get_tooltip();
68 tip = signal_tooltip.emit(pointer_x, pointer_y);
69 tooltip_target = this;
76 lbl_tooltip = new Label;
78 lbl_tooltip->set_style("tooltip");
81 lbl_tooltip->set_text(tip);
82 lbl_tooltip->autosize();
83 const Geometry &tip_geom = lbl_tooltip->get_geometry();
84 unsigned x = pointer_x+10;
85 unsigned y = pointer_y-10-lbl_tooltip->get_geometry().h;
86 if(x+tip_geom.w>geom.w)
88 if(pointer_x>static_cast<int>(tip_geom.w+2))
89 x = pointer_x-2-tip_geom.w;
91 x = geom.w-tip_geom.w;
93 lbl_tooltip->set_position(x, y);
95 lbl_tooltip->set_visible(true);
98 tooltip_timeout = Time::TimeStamp();
102 void Root::render() const
104 GL::MatrixStack::projection() = GL::Matrix::ortho_bottomleft(geom.w, geom.h);
105 GL::MatrixStack::modelview() = GL::Matrix();
106 GL::Bind bind_blend(GL::Blend::alpha());
108 GL::Renderer renderer(0);
109 Widget::render(renderer);
112 void Root::button_press_event(unsigned btn)
118 button_press(x, y, btn);
122 void Root::button_release_event(unsigned btn)
128 button_release(x, y, btn);
132 void Root::axis_motion_event(unsigned, float, float)
138 pointer_motion(x, y);
144 tooltip_timeout = Time::now()+700*Time::msec;
146 else if(get_descendant_at(x, y)!=tooltip_target)
149 lbl_tooltip->set_visible(false);
155 void Root::key_press_event(unsigned key)
162 void Root::key_release_event(unsigned key)
168 void Root::character_event(StringCodec::unichar ch)
174 void Root::get_pointer(int &x, int &y)
176 x = (mouse->get_axis_value(0)*0.5+0.5)*geom.w;
177 y = (mouse->get_axis_value(1)*0.5+0.5)*geom.h;