From: Mikko Rasa Date: Tue, 30 Aug 2011 18:07:30 +0000 (+0300) Subject: Add an event handling example X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e8ebbdbe8dbaec58f9e661efa3124118705fcd13;p=libs%2Fgui.git Add an event handling example --- diff --git a/.gitignore b/.gitignore index d614451..724594c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.options.* /.profile /debug +/ev /libmspgui.a /libmspgui.so /mspgui.pc diff --git a/Build b/Build index 76b5622..0f29bb2 100644 --- a/Build +++ b/Build @@ -69,6 +69,15 @@ package "mspgui" install true; }; + program "ev" + { + source "examples/ev.cpp"; + build_info + { + library "mspgui"; + }; + }; + tarball "@src" { source "License.txt"; diff --git a/examples/ev.cpp b/examples/ev.cpp new file mode 100644 index 0000000..9ded9c7 --- /dev/null +++ b/examples/ev.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include + +using namespace Msp; + +class Ev: public RegisteredApplication +{ +private: + Graphics::SimpleWindow window; + Input::Keyboard keyboard; + Input::Mouse mouse; + +public: + Ev(int, char **); + +private: + virtual void tick(); + + void key_press(unsigned); + void key_release(unsigned); + void button_press(unsigned); + void button_release(unsigned); + void axis_motion(unsigned, float, float); +}; + +Ev::Ev(int, char **): + window(200, 200), + keyboard(window), + mouse(window) +{ + 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)); + window.show(); +} + +void Ev::tick() +{ + window.tick(); +} + +void Ev::key_press(unsigned key) +{ + IO::print("key_press: %s\n", keyboard.get_button_name(key)); +} + +void Ev::key_release(unsigned key) +{ + IO::print("key_release: %s\n", keyboard.get_button_name(key)); +} + +void Ev::button_press(unsigned btn) +{ + IO::print("button_press: %s\n", mouse.get_button_name(btn)); +} + +void Ev::button_release(unsigned btn) +{ + IO::print("button_release: %s\n", mouse.get_button_name(btn)); +} + +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); +}