]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keys.cpp
Include the matching header first in .cpp files
[libs/gui.git] / source / input / keys.cpp
index 4a6df371776a843ab159c9dc4493e92ee9c586f8..9b3349ac443346ca6e6e5e5867a9c9434e74cc54 100644 (file)
@@ -1,7 +1,7 @@
+#include "keys.h"
 #include <map>
 #include <stdexcept>
 #include <msp/strings/format.h>
-#include "keys.h"
 
 using namespace std;
 
@@ -24,7 +24,7 @@ unsigned key_from_sys(unsigned code)
                init_done = true;
        }
 
-       map<unsigned, unsigned>::const_iterator i = reverse_map.find(code);
+       auto i = reverse_map.find(code);
        if(i!=reverse_map.end())
                return i->second;
 
@@ -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