X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=examples%2Fev.cpp;h=1c4e59c6b223a1ddca518cabe5b00cd02c0da218;hb=bb50090c6cd069832ba06772e3387639fe4dca6e;hp=9ded9c7bb47e07867d59f00ee12143594450b81a;hpb=e8ebbdbe8dbaec58f9e661efa3124118705fcd13;p=libs%2Fgui.git diff --git a/examples/ev.cpp b/examples/ev.cpp index 9ded9c7..1c4e59c 100644 --- a/examples/ev.cpp +++ b/examples/ev.cpp @@ -1,8 +1,14 @@ #include #include +#include #include #include +#include #include +#include +#include +#include +#include using namespace Msp; @@ -12,37 +18,83 @@ 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::mem_fun(this, &Ev::key_press)); - keyboard.signal_button_release.connect(sigc::mem_fun(this, &Ev::key_release)); - mouse.signal_button_press.connect(sigc::mem_fun(this, &Ev::button_press)); - mouse.signal_button_release.connect(sigc::mem_fun(this, &Ev::button_release)); - mouse.signal_axis_motion.connect(sigc::mem_fun(this, &Ev::axis_motion)); + 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)); + keyboard.signal_character.connect(sigc::bind_return(sigc::mem_fun(this, &Ev::character), false)); + 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) @@ -55,6 +107,11 @@ void Ev::key_release(unsigned key) IO::print("key_release: %s\n", keyboard.get_button_name(key)); } +void Ev::character(StringCodec::unichar ch) +{ + IO::print("character: %s\n", StringCodec::encode(StringCodec::ustring(1, ch))); +} + void Ev::button_press(unsigned btn) { IO::print("button_press: %s\n", mouse.get_button_name(btn)); @@ -69,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); +}