From bb50090c6cd069832ba06772e3387639fe4dca6e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Sep 2016 20:32:45 +0300 Subject: [PATCH] Add touchscreen and gestures to the event test program --- examples/ev.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/examples/ev.cpp b/examples/ev.cpp index cc15e71..1c4e59c 100644 --- a/examples/ev.cpp +++ b/examples/ev.cpp @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include #include #include #include @@ -16,9 +18,12 @@ private: Graphics::SimpleWindow window; Input::Keyboard keyboard; Input::Mouse mouse; + Input::Touchscreen *touch; + Input::GestureDetector *gesture; public: Ev(int, char **); + ~Ev(); private: virtual void tick(); @@ -31,12 +36,20 @@ private: void button_press(unsigned); void button_release(unsigned); void axis_motion(unsigned, float, float); + void touch_press(unsigned); + void touch_release(unsigned); + void touch_motion(unsigned, float, float); + void gesture_started(unsigned); + void gesture_ended(unsigned); + void gesture_axis(unsigned, float, float); }; Ev::Ev(int, char **): window(200, 200), keyboard(window), - mouse(window) + mouse(window), + touch(0), + gesture(0) { window.get_display().signal_got_focus.connect(sigc::mem_fun(this, &Ev::got_focus)); window.get_display().signal_lost_focus.connect(sigc::mem_fun(this, &Ev::lost_focus)); @@ -47,10 +60,27 @@ Ev::Ev(int, char **): mouse.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::button_press), false)); mouse.signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::button_release), false)); mouse.signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::axis_motion), false)); + if(Input::Touchscreen::is_available()) + { + touch = new Input::Touchscreen(window); + gesture = new Input::GestureDetector(*touch); + touch->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::touch_press), false)); + touch->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::touch_release), false)); + touch->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::touch_motion), false)); + gesture->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::gesture_started), false)); + gesture->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::gesture_ended), false)); + gesture->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::gesture_axis), false)); + } window.set_title("Event tester"); window.show(); } +Ev::~Ev() +{ + delete gesture; + delete touch; +} + void Ev::tick() { window.tick(); @@ -96,3 +126,33 @@ void Ev::axis_motion(unsigned axis, float value, float rel) { IO::print("axis_motion: %s %.3f %+.3f\n", mouse.get_axis_name(axis), value, rel); } + +void Ev::touch_press(unsigned btn) +{ + IO::print("touch_press: %s\n", touch->get_button_name(btn)); +} + +void Ev::touch_release(unsigned btn) +{ + IO::print("touch_release: %s\n", touch->get_button_name(btn)); +} + +void Ev::touch_motion(unsigned axis, float value, float rel) +{ + IO::print("touch_motion: %s %.3f %+.3f\n", touch->get_axis_name(axis), value, rel); +} + +void Ev::gesture_started(unsigned type) +{ + IO::print("gesture_started: %s\n", gesture->get_button_name(type)); +} + +void Ev::gesture_ended(unsigned type) +{ + IO::print("gesture_ended: %s\n", gesture->get_button_name(type)); +} + +void Ev::gesture_axis(unsigned axis, float value, float rel) +{ + IO::print("gesture_axis: %s %.3f %.3f\n", gesture->get_axis_name(axis), value, rel); +} -- 2.45.2