1 #include "touchscreen.h"
8 Touchscreen::Touchscreen(Graphics::Window &w):
12 throw device_not_available("Touchscreen");
16 window.set_touch_input(true);
17 window.signal_input_event.connect(sigc::mem_fun(this, &Touchscreen::input_event));
20 Touchscreen::~Touchscreen()
22 window.set_touch_input(false);
25 string Touchscreen::get_button_name(unsigned btn) const
28 return "Primary touch";
30 return Device::get_button_name(btn);
33 string Touchscreen::get_axis_name(unsigned axis) const
36 return "Primary touch X";
38 return "Primary touch Y";
40 return Device::get_axis_name(axis);
43 unsigned Touchscreen::map_point_id(unsigned id)
45 unsigned unused = active_points.size();
46 for(unsigned i=0; i<active_points.size(); ++i)
48 if(active_points[i]==id)
50 else if(active_points[i]==UNUSED && i<unused)
54 if(unused<active_points.size())
55 active_points[unused] = id;
57 active_points.push_back(id);
62 void Touchscreen::touch_down(unsigned id)
64 unsigned i = map_point_id(id);
65 set_button_state(i, true, true);
68 void Touchscreen::touch_move(unsigned id, float x, float y)
70 unsigned i = map_point_id(id);
71 set_axis_value(i*2, x, true);
72 set_axis_value(i*2+1, y, true);
75 void Touchscreen::touch_up(unsigned id)
77 unsigned i = map_point_id(id);
78 set_button_state(i, false, true);
79 active_points[i] = UNUSED;