1 #include "touchscreen.h"
8 Touchscreen::Touchscreen(Graphics::Window &w):
13 window.set_touch_input(true);
14 window.signal_input_event.connect(sigc::mem_fun(this, &Touchscreen::input_event));
17 Touchscreen::~Touchscreen()
19 window.set_touch_input(false);
22 string Touchscreen::get_button_name(unsigned btn) const
25 return "Primary touch";
27 return Device::get_button_name(btn);
30 string Touchscreen::get_axis_name(unsigned axis) const
33 return "Primary touch X";
35 return "Primary touch Y";
37 return Device::get_axis_name(axis);
40 unsigned Touchscreen::map_point_id(unsigned id)
42 unsigned unused = active_points.size();
43 for(unsigned i=0; i<active_points.size(); ++i)
45 if(active_points[i]==id)
47 else if(active_points[i]==UNUSED && i<unused)
51 if(unused<active_points.size())
52 active_points[unused] = id;
54 active_points.push_back(id);
59 void Touchscreen::touch_down(unsigned id)
61 unsigned i = map_point_id(id);
62 set_button_state(i, true, true);
65 void Touchscreen::touch_move(unsigned id, float x, float y)
67 unsigned i = map_point_id(id);
68 set_axis_value(i*2, x, true);
69 set_axis_value(i*2+1, y, true);
72 void Touchscreen::touch_up(unsigned id)
74 unsigned i = map_point_id(id);
75 set_button_state(i, false, true);
76 active_points[i] = UNUSED;