From: Mikko Rasa Date: Sun, 28 Feb 2010 11:28:36 +0000 (+0000) Subject: Add EventSource abstraction layer below Window X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5add89fdd5e5e542ae0e93de2fe9d9b2532c1e07;p=libs%2Fgui.git Add EventSource abstraction layer below Window --- diff --git a/source/gbase/eventsource.h b/source/gbase/eventsource.h new file mode 100644 index 0000000..8133bbe --- /dev/null +++ b/source/gbase/eventsource.h @@ -0,0 +1,36 @@ +/* $Id$ + +This file is part of libmspgbase +Copyright © 2010 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef MSP_GBASE_EVENTSOURCE_H_ +#define MSP_GBASE_EVENTSOURCE_H_ + +namespace Msp { +namespace Graphics { + +class EventSource +{ +public: + sigc::signal signal_key_press; + sigc::signal signal_key_release; + sigc::signal signal_button_press; + sigc::signal signal_button_release; + sigc::signal signal_pointer_motion; + sigc::signal signal_resize; + +protected: + EventSource() { } +public: + virtual ~EventSource() { } + + virtual unsigned get_width() const = 0; + virtual unsigned get_height() const = 0; +}; + +} // namespace Graphics +} // namespace Msp + +#endif diff --git a/source/gbase/window.cpp b/source/gbase/window.cpp index 0891360..ad130d9 100644 --- a/source/gbase/window.cpp +++ b/source/gbase/window.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgbase -Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/gbase/window.h b/source/gbase/window.h index 38ffb6d..c008fe8 100644 --- a/source/gbase/window.h +++ b/source/gbase/window.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgbase -Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -10,6 +10,7 @@ Distributed under the LGPL #include #include +#include "eventsource.h" namespace Msp { namespace Graphics { @@ -26,18 +27,12 @@ struct WindowOptions WindowOptions(); }; -class Window +class Window: public EventSource { public: struct Private; struct Event; - sigc::signal signal_button_press; - sigc::signal signal_button_release; - sigc::signal signal_pointer_motion; - sigc::signal signal_key_press; - sigc::signal signal_key_release; - sigc::signal signal_resize; sigc::signal signal_close; protected: @@ -65,8 +60,8 @@ public: Display &get_display() const { return display; } const WindowOptions &get_options() const { return options; } - unsigned get_width() const { return options.width; } - unsigned get_height() const { return options.height; } + virtual unsigned get_width() const { return options.width; } + virtual unsigned get_height() const { return options.height; } const Private &get_private() const { return *priv; } void show(); diff --git a/source/input/keyboard.cpp b/source/input/keyboard.cpp index cef812c..963a062 100644 --- a/source/input/keyboard.cpp +++ b/source/input/keyboard.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgbase -Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,15 +20,15 @@ Distributed under the LGPL namespace Msp { namespace Input { -Keyboard::Keyboard(Graphics::Window &w): - window(w) +Keyboard::Keyboard(Graphics::EventSource &s): + source(s) { name="Keyboard"; buttons.resize(N_KEYS_, false); - window.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press)); - window.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release)); + source.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press)); + source.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release)); } std::string Keyboard::get_button_name(unsigned btn) const diff --git a/source/input/keyboard.h b/source/input/keyboard.h index 1b70fec..944cf4d 100644 --- a/source/input/keyboard.h +++ b/source/input/keyboard.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgbase -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -21,10 +21,10 @@ are translated to platform-independent values. See keys.h for a list. class Keyboard: public Device { private: - Graphics::Window &window; + Graphics::EventSource &source; public: - Keyboard(Graphics::Window &); + Keyboard(Graphics::EventSource &); virtual std::string get_button_name(unsigned) const; private: diff --git a/source/input/keys.cpp b/source/input/keys.cpp index 4446a7f..15f729a 100644 --- a/source/input/keys.cpp +++ b/source/input/keys.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgbase -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -9,6 +9,7 @@ Distributed under the LGPL #ifdef WIN32 #include #else +#include #include #endif #include @@ -103,6 +104,15 @@ unsigned keymap[Msp::Input::N_KEYS_]= #endif }; +unsigned modmap[Msp::Input::N_MODS_]= +{ +#ifndef WIN32 + ShiftMask, ControlMask, Mod1Mask, Mod4Mask +#else + 1, 2, 4, 8 +#endif +}; + } namespace Msp { @@ -131,10 +141,19 @@ unsigned key_from_sys(unsigned code) unsigned key_to_sys(unsigned key) { - if(key>N_KEYS_) + if(key>=N_KEYS_) throw InvalidParameterValue("Key out of range"); return keymap[key]; } +unsigned mod_from_sys(unsigned mod) +{ + unsigned result; + for(unsigned i=0; i