diff options
Diffstat (limited to 'Runtime/Events/InputEvent.cpp')
-rw-r--r-- | Runtime/Events/InputEvent.cpp | 88 |
1 files changed, 65 insertions, 23 deletions
diff --git a/Runtime/Events/InputEvent.cpp b/Runtime/Events/InputEvent.cpp index 07d8778..e741511 100644 --- a/Runtime/Events/InputEvent.cpp +++ b/Runtime/Events/InputEvent.cpp @@ -3,6 +3,34 @@ #include "Editor/GUI/WindowUtil.h" #endif +namespace Events +{
+ bool IsMouseEvent(EInputEventType type) + { + switch (type) + { + case InputEvent_MouseDown: + case InputEvent_MouseUp: + case InputEvent_MouseMove: + case InputEvent_MouseDrag: + case InputEvent_ScrollWheel: + return true; + } + return false; + } + + bool IsKeyEvent(EInputEventType type) + { + switch (type) + { + case InputEvent_KeyDown: + case InputEvent_KeyUp: + return true; + } + return false; + } +} + static Vector2f GetInputMousePosition(HWND window) { #if GAMELAB_EDITOR @@ -25,70 +53,64 @@ static Vector2f GetInputMousePosition(HWND window) #endif } +InputEvent::InputEvent() +{ +} + InputEvent::InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window) { static Vector2f s_LastMousePos(0.0f, 0.0f); - isMouse = false, isKey = false; + clickCount = 0; switch (message) { case WM_LBUTTONDOWN: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_LeftButton; clickCount = 1; break; case WM_RBUTTONDOWN: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_RightButton; clickCount = 1; break; case WM_MBUTTONDOWN: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_MiddleButton; clickCount = 1; break; case WM_LBUTTONUP: type = InputEvent_MouseUp; - isMouse = true; button = Mouse_LeftButton; clickCount = 1; break; case WM_RBUTTONUP: type = InputEvent_MouseUp; - isMouse = true; button = Mouse_RightButton; clickCount = 1; break; case WM_MBUTTONUP: type = InputEvent_MouseUp; - isMouse = true; button = Mouse_MiddleButton; clickCount = 1; break; case WM_LBUTTONDBLCLK: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_LeftButton; clickCount = 2; break; case WM_RBUTTONDBLCLK: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_RightButton; clickCount = 2; break; case WM_MBUTTONDBLCLK: type = InputEvent_MouseDown; - isMouse = true; button = Mouse_MiddleButton; clickCount = 2; break; case WM_MOUSEMOVE: type = InputEvent_MouseMove; - isMouse = true; button = 0; if (wParam & MK_LBUTTON) { @@ -108,37 +130,30 @@ InputEvent::InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window) break; case WM_KEYUP: type = InputEvent_KeyUp; - isKey = true; break; case WM_KEYDOWN: type = InputEvent_KeyDown; - isKey = true; break; case WM_SYSKEYUP: type = InputEvent_KeyUp; - isKey = true; break; case WM_SYSKEYDOWN: type = InputEvent_KeyDown; - isKey = true; break; case WM_CHAR: if (!(lParam & (1 << 31))) // key is pressed { type = InputEvent_KeyDown; - isKey = true; } break; case WM_MOUSEWHEEL: mouseDelta.y = -GET_WHEEL_DELTA_WPARAM(wParam) / float(WHEEL_DELTA) * 3.0f; type = InputEvent_ScrollWheel; - isMouse = true; button = 0; break; case WM_MOUSEHWHEEL: mouseDelta.x = GET_WHEEL_DELTA_WPARAM(wParam) / float(WHEEL_DELTA) * 3.0f; type = InputEvent_ScrollWheel; - isMouse = true; button = 0; break; default: @@ -162,7 +177,7 @@ InputEvent::InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window) modifiers |= Modifier_CapsLock; } - if (isMouse) + if (Events::IsMouseEvent(type)) { Vector2f p = GetInputMousePosition(window); mousePosition = p; @@ -204,7 +219,7 @@ InputEvent::InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window) // handle keyboard character = keycode = 0; - if (isKey) + if (Events::IsKeyEvent(type)) { //if (message == WM_CHAR) //{ @@ -249,7 +264,7 @@ void InputEvent::CastToTable(LuaBind::State& state) const lua_pushnumber(state, type); lua_setfield(state, table, "type"); - // "used" + // "use" lua_pushboolean(state, use); lua_setfield(state, table, "use"); @@ -257,7 +272,7 @@ void InputEvent::CastToTable(LuaBind::State& state) const state.PushLuaObject(mousePosition); lua_setfield(state, table, "mousePosition"); - if (isMouse) + if (Events::IsMouseEvent(type)) { // "mouseDelta" state.PushLuaObject(mouseDelta); @@ -272,10 +287,37 @@ void InputEvent::CastToTable(LuaBind::State& state) const lua_setfield(state, table, "clickCount"); } - if (isKey) + if (Events::IsKeyEvent(type)) { } state.SetTop(table); +} + +void InputEvent::RestoreFromTable(LuaBind::State& state, int idx) +{ + int top = state.GetTop(); + int index = state.AbsIndex(idx); + type = (EInputEventType) state.GetField<int>(index, "type", InputEvent_Ignore); + use = state.GetField<bool>(index, "use", false); + + lua_getfield(state, index, "mousePosition"); + mousePosition.RestoreFromLuaObject(state, -1); + + if (Events::IsMouseEvent(type)) + { + lua_getfield(state, index, "mouseDelta"); + mouseDelta.RestoreFromLuaObject(state, -1); + + button = state.GetField<int>(index, "button", 0); + clickCount = state.GetField<int>(index, "clickCount", 0); + } + + if (Events::IsKeyEvent(type)) + { + + } + + state.SetTop(top); }
\ No newline at end of file |