]> git.tdb.fi Git - libs/gui.git/commitdiff
Output character events in the event example
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2011 18:27:46 +0000 (21:27 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2011 18:27:46 +0000 (21:27 +0300)
examples/ev.cpp

index 9ded9c7bb47e07867d59f00ee12143594450b81a..5a338e7355b9dedb1565812cbb92e1ae007f2d98 100644 (file)
@@ -3,6 +3,8 @@
 #include <msp/input/keyboard.h>
 #include <msp/input/mouse.h>
 #include <msp/io/print.h>
+#include <msp/stringcodec/codec.h>
+#include <msp/stringcodec/utf8.h>
 
 using namespace Msp;
 
@@ -21,6 +23,7 @@ private:
 
        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);
@@ -34,6 +37,7 @@ Ev::Ev(int, char **):
        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));
+       keyboard.signal_character.connect(sigc::mem_fun(this, &Ev::character));
        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));
@@ -55,6 +59,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::Utf8>(StringCodec::ustring(1, ch)));
+}
+
 void Ev::button_press(unsigned btn)
 {
        IO::print("button_press: %s\n", mouse.get_button_name(btn));