X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fdevice.cpp;h=22429a0371bfcb9062e7c96d478e4a7c1d3a579f;hb=3bb7bd5d99a71420b1dfa8d433f4f274bbe280fa;hp=228313616c62a92b0bb75d0c370f224944c4b883;hpb=da43cbcdf8fd6cbfe3c24c48247854832f8b3930;p=libs%2Fgui.git diff --git a/source/input/device.cpp b/source/input/device.cpp index 2283136..22429a0 100644 --- a/source/input/device.cpp +++ b/source/input/device.cpp @@ -1,15 +1,28 @@ -#include #include "device.h" +#include + +using namespace std; namespace Msp { namespace Input { -Device::Device() +Device::Device(DeviceType t): + type(t) { } Device::~Device() { } +Device *Device::find_subdevice(const string &n) +{ + return (n==name ? this : nullptr); +} + +Device *Device::find_subdevice(DeviceType t, unsigned i) +{ + return (t==type && i==0 ? this : nullptr); +} + bool Device::get_button_state(unsigned btn) const { if(btn>=buttons.size()) @@ -26,12 +39,12 @@ float Device::get_axis_value(unsigned axis) const return axes[axis]; } -std::string Device::get_button_name(unsigned btn) const +string Device::get_button_name(unsigned btn) const { return format("Button %d", btn); } -std::string Device::get_axis_name(unsigned axis) const +string Device::get_axis_name(unsigned axis) const { return format("Axis %d", axis); } @@ -41,7 +54,7 @@ void Device::set_button_state(unsigned btn, bool state, bool event) if(btn>=buttons.size()) buttons.resize(btn+1, false); - if(state!=buttons[btn]) + if(state!=static_cast(buttons[btn])) { buttons[btn] = state; @@ -70,5 +83,35 @@ void Device::set_axis_value(unsigned axis, float value, bool event) } } + +void operator>>(const LexicalConverter &conv, DeviceType &type) +{ + if(conv.get()=="UNSPECIFIED") + type = UNSPECIFIED; + else if(conv.get()=="KEYBOARD") + type = KEYBOARD; + else if(conv.get()=="MOUSE") + type = MOUSE; + else if(conv.get()=="TOUCH_SURFACE") + type = TOUCH_SURFACE; + else if(conv.get()=="GAME_CONTROLLER") + type = GAME_CONTROLLER; + else + throw lexical_error(format("conversion of '%s' to DeviceType", conv.get())); +} + +void operator<<(LexicalConverter &conv, DeviceType type) +{ + switch(type) + { + case UNSPECIFIED: conv.result("UNSPECIFIED"); break; + case KEYBOARD: conv.result("KEYBOARD"); break; + case MOUSE: conv.result("MOUSE"); break; + case TOUCH_SURFACE: conv.result("TOUCH_SURFACE"); break; + case GAME_CONTROLLER: conv.result("GAME_CONTROLLER"); break; + default: conv.result(format("DeviceType(%#x)", static_cast(type))); + } +} + } // namespace Input } // namespace Msp