]> git.tdb.fi Git - libs/gui.git/commitdiff
Add an event handling example
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2011 18:07:30 +0000 (21:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2011 18:07:30 +0000 (21:07 +0300)
.gitignore
Build
examples/ev.cpp [new file with mode: 0644]

index d614451095709b27eef1adc555f2c37fb38e8ff0..724594c93c726b5649100a1aa6c914fef3535618 100644 (file)
@@ -2,6 +2,7 @@
 /.options.*
 /.profile
 /debug
+/ev
 /libmspgui.a
 /libmspgui.so
 /mspgui.pc
diff --git a/Build b/Build
index 76b5622f9a41aac9f4dafccb6e3e9b1ff9fdcc05..0f29bb238b49fc49a13b2f595b335fcb9d0fac00 100644 (file)
--- 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 (file)
index 0000000..9ded9c7
--- /dev/null
@@ -0,0 +1,71 @@
+#include <msp/core/application.h>
+#include <msp/graphics/simplewindow.h>
+#include <msp/input/keyboard.h>
+#include <msp/input/mouse.h>
+#include <msp/io/print.h>
+
+using namespace Msp;
+
+class Ev: public RegisteredApplication<Ev>
+{
+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);
+}