summaryrefslogtreecommitdiff
path: root/Runtime
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-15 01:19:35 +0800
committerchai <chaifix@163.com>2021-11-15 01:19:35 +0800
commit452eceb3ba4bdbbc77786dc7f7235c03f1c62302 (patch)
treeb4f86a4ed4d0121e5ad1c9cb3a9cfa774800f9dc /Runtime
parent73dc62da054cbc18afc694f803ebff7fe24f4eca (diff)
*class
Diffstat (limited to 'Runtime')
-rw-r--r--Runtime/Events/InputEvent.cpp32
-rw-r--r--Runtime/Events/InputEvent.h5
2 files changed, 36 insertions, 1 deletions
diff --git a/Runtime/Events/InputEvent.cpp b/Runtime/Events/InputEvent.cpp
index e741511..bfa7a1e 100644
--- a/Runtime/Events/InputEvent.cpp
+++ b/Runtime/Events/InputEvent.cpp
@@ -320,4 +320,36 @@ void InputEvent::RestoreFromTable(LuaBind::State& state, int idx)
}
state.SetTop(top);
+}
+
+void InputEvent::Init()
+{
+ mousePosition = Vector2f(0.0F, 0.0F);
+ mouseDelta = Vector2f(0.0F, 0.0F);
+ type = InputEvent_Ignore;
+ keycode = 0;
+ character = 0;
+ button = 0;
+ clickCount = 0;
+ pressure = 0;
+ modifiers = 0;
+ commandString = NULL;
+}
+
+InputEvent InputEvent::RepaintEvent(HWND window)
+{
+ InputEvent evt;
+ evt.Init();
+ evt.type = InputEvent_Repaint;
+
+ Vector2f p = GetInputMousePosition(window);
+ evt.mousePosition = p;
+ evt.button = 0;
+ bool swapped = GetSystemMetrics(SM_SWAPBUTTON);
+ if (GetAsyncKeyState(swapped ? VK_LBUTTON : VK_RBUTTON))
+ evt.button = Mouse_RightButton;
+ if (GetAsyncKeyState(swapped ? VK_RBUTTON : VK_LBUTTON))
+ evt.button = Mouse_LeftButton;
+
+ return evt;
} \ No newline at end of file
diff --git a/Runtime/Events/InputEvent.h b/Runtime/Events/InputEvent.h
index d19fbea..5502aea 100644
--- a/Runtime/Events/InputEvent.h
+++ b/Runtime/Events/InputEvent.h
@@ -46,7 +46,7 @@ enum EMouseButton {
Mouse_MiddleButton = 3
};
-// 输入事件
+// 输入事件,是脚本层面接收和处理的事件
struct InputEvent : public LuaBind::INativeTable
{
EInputEventType type;
@@ -66,8 +66,11 @@ struct InputEvent : public LuaBind::INativeTable
bool use;
+ static InputEvent RepaintEvent(HWND window);
+
InputEvent();
InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window);
+ void Init();
void CastToTable(LuaBind::State& state) const override;
void RestoreFromTable(LuaBind::State& state, int index) override;