X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fdevice.cpp;h=452af22543e4f57db85a9a5271dad5c2648c96a1;hb=51d4984883ae44002fd33665b6ce3c3249210a90;hp=194e999e935c25c8a38a1e41cf53a9b680a42d48;hpb=e00c4dcafe0cce456719cc340b3fc2ae8fa403c8;p=libs%2Fgui.git diff --git a/source/input/device.cpp b/source/input/device.cpp index 194e999..452af22 100644 --- a/source/input/device.cpp +++ b/source/input/device.cpp @@ -4,9 +4,16 @@ namespace Msp { namespace Input { +Device::Device(DeviceType t): + type(t) +{ } + +Device::~Device() +{ } + bool Device::get_button_state(unsigned btn) const { - if(btn>buttons.size()) + if(btn>=buttons.size()) return false; return buttons[btn]; @@ -14,7 +21,7 @@ bool Device::get_button_state(unsigned btn) const float Device::get_axis_value(unsigned axis) const { - if(axis>axes.size()) + if(axis>=axes.size()) return 0; return axes[axis]; @@ -64,5 +71,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