+#include "touchscreen.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Input {
+
+Touchscreen::Touchscreen(Graphics::Window &w):
+ window(w)
+{
+ name = "Touchscreen";
+
+ window.set_touch_input(true);
+ window.signal_input_event.connect(sigc::mem_fun(this, &Touchscreen::input_event));
+}
+
+Touchscreen::~Touchscreen()
+{
+ window.set_touch_input(false);
+}
+
+string Touchscreen::get_button_name(unsigned btn) const
+{
+ if(btn==0)
+ return "Primary touch";
+ else
+ return Device::get_button_name(btn);
+}
+
+string Touchscreen::get_axis_name(unsigned axis) const
+{
+ if(axis==0)
+ return "Primary touch X";
+ else if(axis==1)
+ return "Primary touch Y";
+ else
+ return Device::get_axis_name(axis);
+}
+
+unsigned Touchscreen::map_point_id(unsigned id)
+{
+ unsigned unused = active_points.size();
+ for(unsigned i=0; i<active_points.size(); ++i)
+ {
+ if(active_points[i]==id)
+ return i;
+ else if(active_points[i]==UNUSED && i<unused)
+ unused = i;
+ }
+
+ if(unused<active_points.size())
+ active_points[unused] = id;
+ else
+ active_points.push_back(id);
+
+ return unused;
+}
+
+void Touchscreen::touch_down(unsigned id)
+{
+ unsigned i = map_point_id(id);
+ set_button_state(i, true, true);
+}
+
+void Touchscreen::touch_move(unsigned id, float x, float y)
+{
+ unsigned i = map_point_id(id);
+ set_axis_value(i*2, x, true);
+ set_axis_value(i*2+1, y, true);
+}
+
+void Touchscreen::touch_up(unsigned id)
+{
+ unsigned i = map_point_id(id);
+ set_button_state(i, true, false);
+ active_points[i] = UNUSED;
+}
+
+} // namespace Input
+} // namespace Msp