1 #include "touchscreen.h"
8 Touchscreen::Touchscreen(Graphics::Window &w):
13 throw device_not_available("Touchscreen");
17 window.set_touch_input(true);
18 window.signal_input_event.connect(sigc::mem_fun(this, &Touchscreen::input_event));
21 Touchscreen::~Touchscreen()
23 window.set_touch_input(false);
26 string Touchscreen::get_button_name(unsigned btn) const
29 return "Primary touch";
31 return Device::get_button_name(btn);
34 string Touchscreen::get_axis_name(unsigned axis) const
37 return "Primary touch X";
39 return "Primary touch Y";
41 return Device::get_axis_name(axis);
44 unsigned Touchscreen::map_point_id(unsigned id)
46 unsigned unused = active_points.size();
47 for(unsigned i=0; i<active_points.size(); ++i)
49 if(active_points[i]==id)
51 else if(active_points[i]==UNUSED && i<unused)
55 if(unused<active_points.size())
56 active_points[unused] = id;
58 active_points.push_back(id);
63 void Touchscreen::touch_down(unsigned id)
65 unsigned i = map_point_id(id);
66 set_button_state(i, true, true);
69 void Touchscreen::touch_move(unsigned id, float x, float y)
71 unsigned i = map_point_id(id);
72 set_axis_value(i*2, x, true);
73 set_axis_value(i*2+1, y, true);
76 void Touchscreen::touch_up(unsigned id)
78 unsigned i = map_point_id(id);
79 set_button_state(i, false, true);
80 active_points[i] = UNUSED;