version "0.0";
require "mspcore";
+ require "mspstrings";
require "sigc++-2.0";
// The OpenGL stuff is hackish, but only way to do it right now
if "arch!=win32"
*/
#include <msp/core/except.h>
+#include <msp/strings/lexicalcast.h>
#include "control.h"
#include "inputdevice.h"
index(i)
{ }
+std::string ControlSource::str() const
+{
+ if(type==BUTTON)
+ return dev->get_button_name(index);
+ else if(type==AXIS_POS || type==AXIS_NEG)
+ return dev->get_axis_name(index);
+ else if(type==NONE)
+ return "None";
+
+ return lexical_cast(index);
+}
+
Control::Control():
capture_dev(0)
ControlSource();
ControlSource(Device &, ControlSrcType, unsigned);
+ std::string str() const;
};
/**
#endif
public:
- GLContext(Window &wnd, const GLOptions &opts);
+ GLContext(Window &wnd, const GLOptions &opts=GLOptions());
~GLContext();
void swap_buffers();
Distributed under the LGPL
*/
+#include <msp/strings/formatter.h>
#include "inputdevice.h"
namespace Msp {
return axes[axis];
}
+std::string Device::get_button_name(unsigned btn) const
+{
+ return format("Button %d", btn);
+}
+
+std::string Device::get_axis_name(unsigned axis) const
+{
+ return format("Axis %d", axis);
+}
+
void Device::set_button_state(unsigned btn, bool state, bool event)
{
if(btn>=buttons.size())
#ifndef MSP_GBASE_INPUTDEVICE_H_
#define MSP_GBASE_INPUTDEVICE_H_
+#include <string>
#include <vector>
#include <sigc++/signal.h>
sigc::signal<void, unsigned, float, float> signal_axis_motion;
protected:
+ std::string name;
std::vector<char> buttons;
std::vector<float> axes;
float axis_threshold;
Device() { }
public:
virtual ~Device() { }
+ const std::string &get_name() const { return name; }
bool get_button_state(unsigned) const;
float get_axis_value(unsigned) const;
float get_axis_threshold() const { return axis_threshold; }
+
+ virtual std::string get_button_name(unsigned) const;
+ virtual std::string get_axis_name(unsigned) const;
protected:
void set_button_state(unsigned, bool, bool);
void set_axis_value(unsigned, float, bool);
*/
#include <sigc++/bind.h>
+#include <msp/core/except.h>
#include "inputhub.h"
namespace Msp {
namespace Input {
+Hub::Hub()
+{
+ name="Hub";
+}
+
unsigned Hub::attach(Device &dev)
{
unsigned index=devices.size();
return index;
}
+std::string Hub::get_button_name(unsigned btn) const
+{
+ unsigned dev_index=btn>>12;
+ if(dev_index>devices.size())
+ throw InvalidParameterValue("Button does not exist");
+
+ const Device &dev=*devices[dev_index];
+ return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
+}
+
void Hub::button_press(unsigned btn, unsigned index)
{
- set_button_state(index<<8 | btn&0xFF, true, true);
+ set_button_state(index<<12 | btn&0xFFF, true, true);
}
void Hub::button_release(unsigned btn, unsigned index)
{
- set_button_state(index<<8 | btn&0xFF, false, true);
+ set_button_state(index<<12 | btn&0xFFF, false, true);
}
void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
{
- set_axis_value(index<<8 | axis&0xFF, value, true);
+ set_axis_value(index<<12 | axis&0xFFF, value, true);
}
} // namespace Input
std::vector<Device *> devices;
public:
+ Hub();
+
/**
Attaches an input device to the hub.
@return Index of the device within the hub
*/
unsigned attach(Device &dev);
+
+ virtual std::string get_button_name(unsigned) const;
protected:
void button_press(unsigned, unsigned);
void button_release(unsigned, unsigned);
Distributed under the LGPL
*/
+#include <msp/strings/formatter.h>
+#include "display.h"
#include "keyboard.h"
namespace Msp {
namespace Input {
-Keyboard::Keyboard(Graphics::Window &window)
+Keyboard::Keyboard(Graphics::Window &w):
+ window(w)
{
+ name="Keyboard";
+
buttons.resize(256, 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));
}
+std::string Keyboard::get_button_name(unsigned btn) const
+{
+#ifndef WIN32
+ KeySym ksym=XKeycodeToKeysym(window.get_display().get_display(), btn, 0);
+ return XKeysymToString(ksym);
+#else
+ char buf[128];
+ if(!GetKeyNameText(btn<<16, buf, sizeof(buf)))
+ return format("Key %d", btn);
+ return buf;
+#endif
+}
+
void Keyboard::key_press(unsigned key, unsigned, unsigned)
{
set_button_state(key, true, true);
class Keyboard: public Device
{
+private:
+ Graphics::Window &window;
+
public:
Keyboard(Graphics::Window &);
-protected:
+
+ virtual std::string get_button_name(unsigned) const;
+private:
void key_press(unsigned, unsigned, unsigned);
void key_release(unsigned, unsigned);
};
Distributed under the LGPL
*/
+#include <msp/strings/formatter.h>
#include "mouse.h"
namespace Msp {
window(w),
axis_scale(0.01)
{
+ name="Mouse";
+
buttons.resize(3);
axes.resize(2);
window.signal_pointer_motion.connect(sigc::mem_fun(this, &Mouse::pointer_motion));
}
+std::string Mouse::get_button_name(unsigned btn) const
+{
+ switch(btn)
+ {
+ case 1:
+ return "Left";
+ case 2:
+ return "Middle";
+ case 3:
+ return "Right";
+ case 4:
+ return "Wheel Up";
+ case 5:
+ return "Wheel Down";
+ default:
+ return format("Button %d", btn);
+ }
+}
+
void Mouse::button_press(int, int, unsigned btn, unsigned)
{
set_button_state(btn, true, true);
public:
Mouse(Graphics::Window &);
+ virtual std::string get_button_name(unsigned) const;
private:
void button_press(int, int, unsigned, unsigned);
void button_release(int, int, unsigned, unsigned);
wndcl.cbWndExtra=sizeof(Window *);
wndcl.hInstance=reinterpret_cast<HINSTANCE>(Application::get_data());
wndcl.hIcon=0;
- wndcl.hCursor=0;
+ wndcl.hCursor=LoadCursor(0, IDC_ARROW);
wndcl.hbrBackground=0;
wndcl.lpszMenuName=0;
wndcl.lpszClassName="mspgbase";
switch(msg)
{
case WM_KEYDOWN:
- signal_key_press.emit(wp, 0, wp);
+ signal_key_press.emit((lp>>16)&0x1FF, 0, wp);
break;
case WM_KEYUP:
- signal_key_release.emit(wp, 0);
+ signal_key_release.emit((lp>>16)&0x1FF, 0);
break;
case WM_LBUTTONDOWN:
signal_button_press.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 1, 0);