click_button(0),
pointer_focus(0),
pointer_grabbed(false),
- input_focus(0)
+ input_focus(0),
+ touch_focus(0)
{ }
Container::~Container()
void Container::button_press(int x, int y, unsigned btn)
{
- if(Widget *child = get_pointer_target(x, y))
+ if(Widget *child = get_pointer_target(x, y, false))
{
if(!click_focus)
{
void Container::button_release(int x, int y, unsigned btn)
{
- if(Widget *child = get_pointer_target(x, y))
+ if(Widget *child = get_pointer_target(x, y, false))
{
if(child==click_focus && btn==click_button)
{
void Container::pointer_motion(int x, int y)
{
- Widget *child = get_pointer_target(x, y);
+ Widget *child = get_pointer_target(x, y, false);
if(!pointer_grabbed)
set_pointer_focus((!click_focus || child->get_geometry().is_inside(x, y)) ? child : 0);
}
}
-Widget *Container::get_pointer_target(int x, int y) const
+Widget *Container::get_pointer_target(int x, int y, bool touch) const
{
if(pointer_grabbed)
return pointer_focus;
- else if(click_focus)
+ else if(!touch && click_focus)
return click_focus;
+ else if(touch && touch_focus)
+ return touch_focus;
else
{
Widget *child = get_child_at(x, y);
input_focus->character(ch);
}
+void Container::touch_press(int x, int y, unsigned finger)
+{
+ if(Widget *child = get_pointer_target(x, y, true))
+ {
+ // TODO track focus for each finger separately
+ if(!touch_focus)
+ touch_focus = child;
+
+ const Geometry &cgeom = child->get_geometry();
+ child->touch_press(x-cgeom.x, y-cgeom.y, finger);
+ }
+}
+
+void Container::touch_release(int x, int y, unsigned finger)
+{
+ if(Widget *child = get_pointer_target(x, y, true))
+ {
+ // TODO track focus for each finger separately
+ if(child==touch_focus)
+ touch_focus = 0;
+
+ const Geometry &cgeom = child->get_geometry();
+ child->touch_release(x-cgeom.x, y-cgeom.y, finger);
+ }
+}
+
+void Container::touch_motion(int x, int y, unsigned finger)
+{
+ if(Widget *child = get_pointer_target(x, y, true))
+ {
+ const Geometry &cgeom = child->get_geometry();
+ child->touch_motion(x-cgeom.x, y-cgeom.y, finger);
+ }
+}
+
void Container::focus_out()
{
set_input_focus(0);
Widget *pointer_focus;
bool pointer_grabbed;
Widget *input_focus;
+ Widget *touch_focus;
Container();
public:
virtual void button_release(int, int, unsigned);
virtual void pointer_motion(int, int);
private:
- Widget *get_pointer_target(int, int) const;
+ Widget *get_pointer_target(int, int, bool) const;
public:
virtual void pointer_leave();
virtual void key_press(unsigned, unsigned);
virtual void key_release(unsigned, unsigned);
+ virtual void touch_press(int, int, unsigned);
+ virtual void touch_release(int, int, unsigned);
+ virtual void touch_motion(int, int, unsigned);
virtual void character(wchar_t);
virtual void focus_out();
protected:
resources(r),
keyboard(new Input::Keyboard(window)),
mouse(new Input::Mouse(window)),
+ touchscreen(0),
own_input(true)
{
init(&window);
}
-Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m):
+Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t):
resources(r),
keyboard(k),
mouse(m),
+ touchscreen(t),
own_input(false)
{
init(window);
keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event));
}
+
+ if(touchscreen)
+ {
+ touchscreen->signal_button_press.connect(sigc::mem_fun(this, &Root::touch_press_event));
+ touchscreen->signal_button_release.connect(sigc::mem_fun(this, &Root::touch_release_event));
+ touchscreen->signal_axis_motion.connect(sigc::mem_fun(this, &Root::touch_motion_event));
+ }
}
Root::~Root()
return false;
}
+bool Root::touch_press_event(unsigned finger)
+{
+ if(visible)
+ {
+ Widget *old_focus = touch_focus;
+
+ int x, y;
+ get_touch(finger, x, y);
+ touch_press(x, y, finger);
+
+ if(touch_focus || old_focus)
+ return true;
+ }
+
+ return false;
+}
+
+bool Root::touch_release_event(unsigned finger)
+{
+ if(visible)
+ {
+ Widget *old_focus = touch_focus;
+
+ int x, y;
+ get_touch(finger, x, y);
+ touch_release(x, y, finger);
+
+ if(touch_focus || old_focus)
+ return true;
+ }
+
+ return false;
+}
+
+bool Root::touch_motion_event(unsigned axis, float, float)
+{
+ if(visible)
+ {
+ unsigned finger = axis/2;
+ int x, y;
+ get_touch(finger, x, y);
+ touch_motion(x, y, finger);
+
+ if(touch_focus)
+ return true;
+ }
+
+ return false;
+}
+
void Root::get_pointer(int &x, int &y)
{
x = (mouse->get_axis_value(0)*0.5+0.5)*geom.w;
y = (mouse->get_axis_value(1)*0.5+0.5)*geom.h;
}
+void Root::get_touch(unsigned finger, int &x, int &y)
+{
+ x = (touchscreen->get_axis_value(finger*2)*0.5+0.5)*geom.w;
+ y = (touchscreen->get_axis_value(finger*2+1)*0.5+0.5)*geom.h;
+}
+
void Root::update_camera()
{
camera.set_position(GL::Vector3(geom.w/2.0f, geom.h/2.0f, geom.h/2.0f));
#include <msp/graphics/window.h>
#include <msp/input/keyboard.h>
#include <msp/input/mouse.h>
+#include <msp/input/touchscreen.h>
#include <msp/time/timestamp.h>
#include "panel.h"
const Resources &resources;
Input::Keyboard *keyboard;
Input::Mouse *mouse;
+ Input::Touchscreen *touchscreen;
bool own_input;
Label *lbl_tooltip;
int pointer_x;
/** Creates a Root widget with custom input devices. If window is not null,
it is used to set the widget's initial geometry. */
- Root(const Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *);
+ Root(const Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *, Input::Touchscreen * = 0);
private:
void init(Graphics::Window *);
public:
bool key_press_event(unsigned);
bool key_release_event(unsigned);
bool character_event(StringCodec::unichar);
+ bool touch_press_event(unsigned);
+ bool touch_release_event(unsigned);
+ bool touch_motion_event(unsigned, float, float);
void get_pointer(int &, int &);
+ void get_touch(unsigned, int &, int &);
void update_camera();
virtual void on_geometry_change();
clear_state(HOVER);
}
+void Widget::touch_press(int x, int y, unsigned finger)
+{
+ if(finger==0)
+ button_press(x, y, 1);
+}
+
+void Widget::touch_release(int x, int y, unsigned finger)
+{
+ if(finger==0)
+ button_release(x, y, 1);
+}
+
+void Widget::touch_motion(int x, int y, unsigned finger)
+{
+ if(finger==0)
+ pointer_motion(x, y);
+}
+
void Widget::focus_in()
{
set_state(FOCUS);
virtual void key_press(unsigned, unsigned) { }
virtual void key_release(unsigned, unsigned) { }
virtual void character(wchar_t) { }
+ virtual void touch_press(int, int, unsigned);
+ virtual void touch_release(int, int, unsigned);
+ virtual void touch_motion(int, int, unsigned);
virtual void focus_in();
virtual void focus_out();
protected: