#include <msp/graphics/window_private.h>
+#include "keys.h"
#include "mouse.h"
namespace Msp {
{
float x = AMotionEvent_getX(event.aevent, pointer_zero);
float y = AMotionEvent_getY(event.aevent, pointer_zero);
- set_axis_value(0, x*2/window.get_width()-1, true);
- set_axis_value(1, 1-y*2/window.get_height(), true);
+ set_axis_value(MOUSE_X_AXIS, x*2/window.get_width()-1, true);
+ set_axis_value(MOUSE_Y_AXIS, 1-y*2/window.get_height(), true);
}
switch(action)
case AMOTION_EVENT_ACTION_POINTER_DOWN:
case AMOTION_EVENT_ACTION_POINTER_UP:
if(action_pointer==0)
- set_button_state(1, action==AMOTION_EVENT_ACTION_DOWN, true);
+ set_button_state(MOUSE_LEFT, action==AMOTION_EVENT_ACTION_DOWN, true);
break;
default:;
}
add("button", &Loader::button);
add("device", &Binding::device);
add("key", &Loader::key);
+ add("mouse_axis", &Loader::mouse_axis);
+ add("mouse_button", &Loader::mouse_button);
}
void Bindings::Binding::Loader::axis(unsigned a, AxisSide s)
void axis(unsigned, AxisSide);
void button(unsigned);
void key(Key k) { button(k); }
+ void mouse_axis(MouseAxis a, AxisSide s) { axis(a, s); }
+ void mouse_button(MouseButton b) { button(b); }
};
std::string control;
#include <msp/graphics/window_private.h>
+#include "keys.h"
#include "mouse.h"
namespace Msp {
set_button_state(event.cevent.button.button, event.cevent.button.state, true);
break;
case MOUSE_MOVED:
- set_axis_value(0, event.cevent.motion.x*2.0/window.get_width()-1.0, true);
- set_axis_value(1, event.cevent.motion.y*2.0/window.get_height()-1.0, true);
+ set_axis_value(MOUSE_X_AXIS, event.cevent.motion.x*2.0/window.get_width()-1.0, true);
+ set_axis_value(MOUSE_Y_AXIS, event.cevent.motion.y*2.0/window.get_height()-1.0, true);
break;
default:;
}
}
}
+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
N_KEYS_ = 0x100
};
+enum MouseAxis
+{
+ MOUSE_X_AXIS = 0,
+ MOUSE_Y_AXIS,
+};
+
+enum MouseButton
+{
+ MOUSE_LEFT = 1,
+ MOUSE_MIDDLE,
+ MOUSE_RIGHT,
+ MOUSE_WHEEL_UP,
+ MOUSE_WHEEL_DOWN
+};
+
void operator>>(const LexicalConverter &, Key &);
void operator<<(LexicalConverter &, Key);
+void operator>>(const LexicalConverter &, MouseAxis &);
+void operator<<(LexicalConverter &, MouseAxis);
+void operator>>(const LexicalConverter &, MouseButton &);
+void operator<<(LexicalConverter &, MouseButton);
} // namespace Input
} // namespace Msp
#include <msp/graphics/window.h>
+#include "keys.h"
#include "mouse.h"
namespace Msp {
{
switch(btn)
{
- case 1:
+ case MOUSE_LEFT:
return "Left";
- case 2:
+ case MOUSE_MIDDLE:
return "Middle";
- case 3:
+ case MOUSE_RIGHT:
return "Right";
- case 4:
+ case MOUSE_WHEEL_UP:
return "Wheel Up";
- case 5:
+ case MOUSE_WHEEL_DOWN:
return "Wheel Down";
default:
return Device::get_button_name(btn);
{
switch(axis)
{
- case 0:
+ case MOUSE_X_AXIS:
return "X axis";
- case 1:
+ case MOUSE_Y_AXIS:
return "Y axis";
default:
return Device::get_axis_name(axis);
#include <windowsx.h>
#include <msp/graphics/window_private.h>
+#include "keys.h"
#include "mouse.h"
namespace Msp {
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
- set_button_state(1, event.msg==WM_LBUTTONDOWN, true);
+ set_button_state(MOUSE_LEFT, event.msg==WM_LBUTTONDOWN, true);
break;
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
- set_button_state(2, event.msg==WM_MBUTTONDOWN, true);
+ set_button_state(MOUSE_MIDDLE, event.msg==WM_MBUTTONDOWN, true);
break;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
- set_button_state(3, event.msg==WM_RBUTTONDOWN, true);
+ set_button_state(MOUSE_RIGHT, event.msg==WM_RBUTTONDOWN, true);
break;
case WM_MOUSEWHEEL:
{
- unsigned btn = (HIWORD(event.wparam)&0x8000) ? 5 : 4;
+ unsigned btn = (HIWORD(event.wparam)&0x8000) ? MOUSE_WHEEL_DOWN : MOUSE_WHEEL_UP;
set_button_state(btn, true, true);
set_button_state(btn, false, true);
}
break;
case WM_MOUSEMOVE:
- set_axis_value(0, GET_X_LPARAM(event.lparam)*2.0/window.get_width()-1.0, true);
- set_axis_value(1, 1.0-GET_Y_LPARAM(event.lparam)*2.0/window.get_height(), true);
+ set_axis_value(MOUSE_X_AXIS, GET_X_LPARAM(event.lparam)*2.0/window.get_width()-1.0, true);
+ set_axis_value(MOUSE_Y_AXIS, 1.0-GET_Y_LPARAM(event.lparam)*2.0/window.get_height(), true);
break;
}
}
#include <msp/graphics/window_private.h>
+#include "keys.h"
#include "mouse.h"
namespace Msp {
set_button_state(event.xevent.xbutton.button, event.xevent.type==ButtonPress, true);
break;
case MotionNotify:
- set_axis_value(0, event.xevent.xmotion.x*2.0/window.get_width()-1.0, true);
- set_axis_value(1, 1.0-event.xevent.xmotion.y*2.0/window.get_height(), true);
+ set_axis_value(MOUSE_X_AXIS, event.xevent.xmotion.x*2.0/window.get_width()-1.0, true);
+ set_axis_value(MOUSE_Y_AXIS, 1.0-event.xevent.xmotion.y*2.0/window.get_height(), true);
break;
}
}