]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keys.cpp
Add constants for mouse axes and buttons
[libs/gui.git] / source / input / keys.cpp
index 4a6df371776a843ab159c9dc4493e92ee9c586f8..6be00ba591cbb0618733e0ba1533f867c16fe146 100644 (file)
@@ -333,5 +333,54 @@ void operator<<(LexicalConverter &conv, Key key)
        }
 }
 
+void operator>>(const LexicalConverter &conv, MouseAxis &axis)
+{
+       if(conv.get()=="X")
+               axis = MOUSE_X_AXIS;
+       else if(conv.get()=="Y")
+               axis = MOUSE_Y_AXIS;
+       else
+               throw lexical_error(format("conversion of '%s' to MouseAxis", conv.get()));
+}
+
+void operator<<(LexicalConverter &conv, MouseAxis axis)
+{
+       switch(axis)
+       {
+       case MOUSE_X_AXIS: conv.result("X"); break;
+       case MOUSE_Y_AXIS: conv.result("Y"); break;
+       default: conv.result(format("MouseAxis(%#x)", static_cast<int>(axis)));
+       }
+}
+
+void operator>>(const LexicalConverter &conv, MouseButton &btn)
+{
+       if(conv.get()=="LEFT")
+               btn = MOUSE_LEFT;
+       else if(conv.get()=="MIDDLE")
+               btn = MOUSE_MIDDLE;
+       else if(conv.get()=="RIGHT")
+               btn = MOUSE_RIGHT;
+       else if(conv.get()=="WHEEL_UP")
+               btn = MOUSE_WHEEL_UP;
+       else if(conv.get()=="WHEEL_DOWN")
+               btn = MOUSE_WHEEL_DOWN;
+       else
+               throw lexical_error(format("conversion of '%s' to MouseButton", conv.get()));
+}
+
+void operator<<(LexicalConverter &conv, MouseButton btn)
+{
+       switch(btn)
+       {
+       case MOUSE_LEFT: conv.result("LEFT"); break;
+       case MOUSE_MIDDLE: conv.result("MIDDLE"); break;
+       case MOUSE_RIGHT: conv.result("RIGHT"); break;
+       case MOUSE_WHEEL_UP: conv.result("WHEEL_UP"); break;
+       case MOUSE_WHEEL_DOWN: conv.result("WHEEL_DOWN"); break;
+       default: conv.result(format("MouseButton(%#x)", static_cast<int>(btn)));
+       }
+}
+
 } // namespace Input
 } // namespace Msp