From e8ebbdbe8dbaec58f9e661efa3124118705fcd13 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 30 Aug 2011 21:07:30 +0300 Subject: [PATCH] Add an event handling example --- .gitignore | 1 + Build | 9 +++++++ examples/ev.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 examples/ev.cpp 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); +} -- 2.45.2