X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=examples%2Fev.cpp;h=1c4e59c6b223a1ddca518cabe5b00cd02c0da218;hb=bb50090c6cd069832ba06772e3387639fe4dca6e;hp=8029df2af8310a9c1e5a25a326b8d607bbfba085;hpb=130828739f6b0d3934bf1e29ed2d87d9acf22e89;p=libs%2Fgui.git diff --git a/examples/ev.cpp b/examples/ev.cpp index 8029df2..1c4e59c 100644 --- a/examples/ev.cpp +++ b/examples/ev.cpp @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include #include #include #include @@ -16,26 +18,41 @@ 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(); + void got_focus(); + void lost_focus(); void key_press(unsigned); void key_release(unsigned); void character(StringCodec::unichar); 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)); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Ev::exit), 0)); keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::key_press), false)); keyboard.signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::key_release), false)); @@ -43,16 +60,43 @@ 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(); Time::sleep(Time::msec); } +void Ev::got_focus() +{ + IO::print("got_focus\n"); +} + +void Ev::lost_focus() +{ + IO::print("lost_focus\n"); +} + void Ev::key_press(unsigned key) { IO::print("key_press: %s\n", keyboard.get_button_name(key)); @@ -82,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); +}