--- /dev/null
+/* $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<void, unsigned, unsigned, unsigned> signal_key_press;
+ sigc::signal<void, unsigned, unsigned> signal_key_release;
+ sigc::signal<void, int, int, unsigned, unsigned> signal_button_press;
+ sigc::signal<void, int, int, unsigned, unsigned> signal_button_release;
+ sigc::signal<void, int, int> signal_pointer_motion;
+ sigc::signal<void, unsigned, unsigned> signal_resize;
+
+protected:
+ EventSource() { }
+public:
+ virtual ~EventSource() { }
+
+ virtual unsigned get_width() const = 0;
+ virtual unsigned get_height() const = 0;
+};
+
+} // namespace Graphics
+} // namespace Msp
+
+#endif
/* $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
*/
/* $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
*/
#include <string>
#include <sigc++/signal.h>
+#include "eventsource.h"
namespace Msp {
namespace Graphics {
WindowOptions();
};
-class Window
+class Window: public EventSource
{
public:
struct Private;
struct Event;
- sigc::signal<void, int, int, unsigned, unsigned> signal_button_press;
- sigc::signal<void, int, int, unsigned, unsigned> signal_button_release;
- sigc::signal<void, int, int> signal_pointer_motion;
- sigc::signal<void, unsigned, unsigned, unsigned> signal_key_press;
- sigc::signal<void, unsigned, unsigned> signal_key_release;
- sigc::signal<void, unsigned, unsigned> signal_resize;
sigc::signal<void> signal_close;
protected:
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();
/* $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
*/
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
/* $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
*/
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:
/* $Id$
This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifdef WIN32
#include <windows.h>
#else
+#include <X11/X.h>
#include <X11/keysym.h>
#endif
#include <msp/core/except.h>
#endif
};
+unsigned modmap[Msp::Input::N_MODS_]=
+{
+#ifndef WIN32
+ ShiftMask, ControlMask, Mod1Mask, Mod4Mask
+#else
+ 1, 2, 4, 8
+#endif
+};
+
}
namespace Msp {
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<N_MODS_; ++i)
+ if(mod&modmap[i])
+ result|=1<<i;
+ return result;
+}
+
} // namespace Input
} // namespace Msp
/* $Id$
This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
N_KEYS_ = 0x100
};
+enum
+{
+ MOD_SHIFT = 1,
+ MOD_CONTROL = 2,
+ MOD_ALT = 4,
+ MOD_SUPER = 8,
+ N_MODS_ = 4
+};
+
extern unsigned key_from_sys(unsigned);
extern unsigned key_to_sys(unsigned);
+extern unsigned mod_from_sys(unsigned);
+
} // namespace Input
} // namespace Msp
/* $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
*/
namespace Msp {
namespace Input {
-Mouse::Mouse(Graphics::Window &w):
- window(w)
+Mouse::Mouse(Graphics::EventSource &s):
+ source(s)
{
name="Mouse";
buttons.resize(3);
axes.resize(2);
- window.signal_button_press.connect(sigc::mem_fun(this, &Mouse::button_press));
- window.signal_button_release.connect(sigc::mem_fun(this, &Mouse::button_release));
- window.signal_pointer_motion.connect(sigc::mem_fun(this, &Mouse::pointer_motion));
+ source.signal_button_press.connect(sigc::mem_fun(this, &Mouse::button_press));
+ source.signal_button_release.connect(sigc::mem_fun(this, &Mouse::button_release));
+ source.signal_pointer_motion.connect(sigc::mem_fun(this, &Mouse::pointer_motion));
}
std::string Mouse::get_button_name(unsigned btn) const
void Mouse::pointer_motion(int x, int y)
{
- set_axis_value(0, x*2.0f/window.get_width()-1.0f, true);
- set_axis_value(1, 1.0f-y*2.0f/window.get_height(), true);
+ set_axis_value(0, x*2.0f/source.get_width()-1.0f, true);
+ set_axis_value(1, 1.0f-y*2.0f/source.get_height(), true);
}
} // namespace Input
/* $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
*/
class Mouse: public Device
{
private:
- Graphics::Window &window;
+ Graphics::EventSource &source;
public:
- Mouse(Graphics::Window &);
+ Mouse(Graphics::EventSource &);
virtual std::string get_button_name(unsigned) const;
virtual std::string get_axis_name(unsigned) const;
private: