summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua4
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua12
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua22
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua2
-rw-r--r--Data/Resources/Shaders/Editor-Text.glsl1
-rw-r--r--Data/Scripts/EditorApplication.lua7
-rw-r--r--Data/Scripts/EditorGUI/EditorWindowManager.lua8
-rw-r--r--Documents/窗口.xlsxbin1347749 -> 1445520 bytes
-rw-r--r--Editor/GUI/GUIWindow.cpp10
-rw-r--r--Editor/GUI/GUIWindow.h3
-rw-r--r--Editor/GUI/WindowUtil.cpp29
-rw-r--r--Editor/GUI/WindowUtil.h (renamed from Editor/GUI/WindowBase.h)6
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj7
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj.filters9
-rw-r--r--Runtime/Events/InputEvent.cpp262
-rw-r--r--Runtime/Events/InputEvent.h23
-rw-r--r--Runtime/Lua/LuaBind/LuaBind.h1
-rw-r--r--Runtime/Lua/LuaBind/LuaBindInvoker.cpp8
-rw-r--r--Runtime/Lua/LuaBind/LuaBindInvoker.h3
-rw-r--r--Runtime/Lua/LuaBind/LuaBindLClass.h16
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.cpp7
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.h4
-rw-r--r--Runtime/Lua/LuaBind/LuaBindTable.h2
-rw-r--r--Runtime/Lua/LuaHelper.cpp29
-rw-r--r--Runtime/Lua/LuaHelper.h7
-rw-r--r--Runtime/Math/Vector2.h27
-rw-r--r--Runtime/Scripting/Resource/Resource.bind.cpp1
27 files changed, 466 insertions, 44 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua b/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua
index 4a160fa..bc3b451 100644
--- a/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua
+++ b/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua
@@ -1,8 +1,8 @@
local Enum = GameLab.Enum or require("GameLab.Enum")
-- 声明类的同时添加到G表
-local GlobalEnum = function(enumName)
- local enum = Enum(enumName)
+local GlobalEnum = function(enumName, tb)
+ local enum = Enum(tb)
local shortName = string.match(enumName, "%.*(%w+)$")
local t = _G
diff --git a/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua b/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua
index af525f0..b270110 100644
--- a/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua
+++ b/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua
@@ -1,20 +1,20 @@
-local InternalContainWidow = GameLab.Editor.GUI.Internal.ContainerWindow
+local NativeContainWidow = GameLab.Editor.GUI.Internal.ContainerWindow
local ContainerWindow = GameLab.GlobalClass("GameLab.Editor.GUI.ContainerWindow")
ContainerWindow.Ctor = function(self, position, showMode, min, max)
- self.m_Internal = InternalContainWidow.New(position, showMode, min, max)
+ self.m_Native = NativeContainWidow.New(position, showMode, min, max)
end
ContainerWindow.SetTitle = function(self)
- self.m_Internal:SetTitle(self)
+ self.m_Native:SetTitle(self)
end
ContainerWindow.SetIcon = function(self)
- self.m_Internal:SetIcon(self)
+ self.m_Native:SetIcon(self)
end
-ContainerWindow.GetInternal = function(self)
- return self.m_Internal
+ContainerWindow.GetNative = function(self)
+ return self.m_Native
end
return ContainerWindow \ No newline at end of file
diff --git a/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua b/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua
index e283c07..f136d56 100644
--- a/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua
+++ b/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua
@@ -1,6 +1,8 @@
-local InternalGUIWindow = GameLab.Editor.GUI.Internal.GUIWindow
+local NativeGUIWindow = GameLab.Editor.GUI.Internal.GUIWindow
local GUIWindow = GameLab.GlobalClass("GameLab.Editor.GUI.GUIWindow")
+local inspect = require("inspect")
+
local Debug = GameLab.Debug
local GL = GameLab.Engine.GL
local Math = GameLab.Engine.Math
@@ -9,25 +11,25 @@ local Rendering = GameLab.Engine.Rendering
local Rect = Math.Rect
GUIWindow.Ctor = function(self)
- self.m_Internal = InternalGUIWindow.New(self)
+ self.m_Native = NativeGUIWindow.New(self)
self.m_ContainerWindow = nil
- self.m_SplitWindow = nil
+ self.m_SplitWindow = nil -- parent window
self.m_Position = Rect.New(0,0,0,0) -- 在父窗口中的位置和大小
self.m_EditorWindows = {} -- 编辑器脚本
end
GUIWindow.SetContainerWindow = function(self, containerWindow)
self.m_ContainerWindow = containerWindow
- self.m_Internal:SetContainerWindow(containerWindow:GetInternal())
+ self.m_Native:SetContainerWindow(containerWindow:GetNative())
end
GUIWindow.SetPosition = function(self, pos)
self.m_Position:Set(pos)
- self.m_Internal:SetPosition(pos)
+ self.m_Native:SetPosition(pos)
end
-GUIWindow.GetInternal = function(self)
- return self.m_Internal
+GUIWindow.GetNative = function(self)
+ return self.m_Native
end
GUIWindow.OnGUI = function(self)
@@ -35,9 +37,13 @@ GUIWindow.OnGUI = function(self)
end
+GUIWindow.OnEvent = function(self, evt)
+
+end
+
GUIWindow.GetContainerWindow = function(self)
return self.m_ContainerWindow
-end
+end
GUIWindow.OnFocus = function(self)
Debug.Log("GUIWindow.OnFocus")
diff --git a/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua b/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua
index 0d6417e..d594bee 100644
--- a/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua
+++ b/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua
@@ -11,4 +11,6 @@ SplitWindow.Ctor = function(self)
self.m_GUIWindows = {}
end
+
+
return SplitWindow \ No newline at end of file
diff --git a/Data/Resources/Shaders/Editor-Text.glsl b/Data/Resources/Shaders/Editor-Text.glsl
index b228198..d1003c3 100644
--- a/Data/Resources/Shaders/Editor-Text.glsl
+++ b/Data/Resources/Shaders/Editor-Text.glsl
@@ -44,4 +44,3 @@ void main()
FragColor = sampled;
}
FSH_END
- \ No newline at end of file
diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua
index 4c91f72..9e2b632 100644
--- a/Data/Scripts/EditorApplication.lua
+++ b/Data/Scripts/EditorApplication.lua
@@ -21,18 +21,15 @@ local mainWindow = GUI.ContainerWindow.New({400, 400, 800, 500}, GUI.EShowMode.M
mainWindow:SetTitle("GameLab")
mainWindow:SetIcon("./Data/Icon/GameLab.ico")
-app:SetMainWindow(mainWindow:GetInternal())
+app:SetMainWindow(mainWindow:GetNative())
local guiWindow = GUI.GUIWindow.New()
guiWindow:SetContainerWindow(mainWindow)
guiWindow:SetPosition({0,0, 400, 400})
-
local guiWindow2 = GUI.GUIWindow.New()
guiWindow2:SetContainerWindow(mainWindow)
-guiWindow2:SetPosition({500,0, 400, 400})
-
-collectgarbage()
+guiWindow2:SetPosition({400,0, 400, 400})
local wnd = AssetBrowser.New()
diff --git a/Data/Scripts/EditorGUI/EditorWindowManager.lua b/Data/Scripts/EditorGUI/EditorWindowManager.lua
index e3595ae..693cb9e 100644
--- a/Data/Scripts/EditorGUI/EditorWindowManager.lua
+++ b/Data/Scripts/EditorGUI/EditorWindowManager.lua
@@ -1,5 +1,11 @@
+local ContainerWindow = require("GameLab.Editor.GUI.ContainerWindow")
+local GUIWindow = require("GameLab.Editor.GUI.GUIWindow")
+local SplitWindow = require("GameLab.Editor.GUI.SplitWindow")
+
local EditorWindowManager = {}
-EditorWindowManager.name = "asd"
+EditorWindowManager.splitWindows = {}
+
+
return EditorWindowManager \ No newline at end of file
diff --git a/Documents/窗口.xlsx b/Documents/窗口.xlsx
index e93e2c6..17bf94c 100644
--- a/Documents/窗口.xlsx
+++ b/Documents/窗口.xlsx
Binary files differ
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
index 1a9ea00..c79cb52 100644
--- a/Editor/GUI/GUIWindow.cpp
+++ b/Editor/GUI/GUIWindow.cpp
@@ -4,6 +4,7 @@
#include "Editor/Graphics/Graphics.h"
#include "Editor/Win/Win.h"
#include "Runtime/Math/Math.h"
+#include "Runtime/Events/InputEvent.h"
using namespace LuaBind;
@@ -260,7 +261,16 @@ GUIWindow::GUIWindow(LuaBind::VM* vm, std::string name)
void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam)
{
+ InputEvent ie(message, wParam, lParam, m_Handle);
+ LuaBind::State state = GetVM()->GetCurThread();
+
+ LuaBind::MemberInvoker invoker = LuaBind::MemberInvoker(state, this);
+ invoker.member = m_Script;
+ invoker.method = "OnEvent";
+ invoker.AddMember(m_Script);
+ invoker.AddTable(ie);
+ invoker.Invoke(0);
}
bool GUIWindow::SetRenderContext()
diff --git a/Editor/GUI/GUIWindow.h b/Editor/GUI/GUIWindow.h
index aa81b38..06d8a17 100644
--- a/Editor/GUI/GUIWindow.h
+++ b/Editor/GUI/GUIWindow.h
@@ -12,8 +12,7 @@
#include "Editor/Utils/HelperFuncs.h"
#include "Runtime/Math/Math.h"
#include "Runtime/Utilities/Exception.h"
-
-#include "WindowBase.h"
+#include "WindowUtil.h"
// GUIڣ¼ӦơֵĵԪ
class GUIWindow
diff --git a/Editor/GUI/WindowUtil.cpp b/Editor/GUI/WindowUtil.cpp
index 34a7b30..2c73573 100644
--- a/Editor/GUI/WindowUtil.cpp
+++ b/Editor/GUI/WindowUtil.cpp
@@ -1,3 +1,4 @@
+#include "Runtime/Utilities/StaticInitiator.h"
#include "EditorWindows.h"
#include "WinUtils.h"
@@ -9,6 +10,16 @@ static ATOM ContainerWindowClassAtom;
static ATOM PopupWindowClassAtom;
static ATOM GUIViewClassAtom;
+static int s_EditorMouseOffsetX;
+static int s_EditorMouseOffsetY;
+static HWND s_EditorInputWindow;
+
+InitializeStaticVariables([]() {
+ s_EditorMouseOffsetX = 0;
+ s_EditorMouseOffsetY = 0;
+ s_EditorInputWindow = NULL;
+});
+
void WindowUtil::RegisterClasses()
{
log_info("WindowUtil::Init()");
@@ -16,4 +27,22 @@ void WindowUtil::RegisterClasses()
ContainerWindowClassAtom = winutils::RegisterWindowClass(kContainerWindowClassName, ContainerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW);
PopupWindowClassAtom = winutils::RegisterWindowClass(kPopupWindowClassName, ContainerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);//CS_HREDRAWȣˮƽ仯ʱػ桢CS_VREDRAW߶ȣֱ仯ʱػ
GUIViewClassAtom = winutils::RegisterWindowClass(kGUIWindowClassName, GUIWindow::GUIViewWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);
+}
+
+void WindowUtil::SetEditorMouseOffset(int x, int y, HWND window)
+{
+ s_EditorMouseOffsetX = x;
+ s_EditorMouseOffsetY = y;
+ s_EditorInputWindow = window;
+}
+
+void WindowUtil::GetEditorMouseOffset(int *x, int *y, HWND *window)
+{
+ *x = s_EditorMouseOffsetX;
+ *y = s_EditorMouseOffsetY;
+
+ if (NULL != window)
+ {
+ *window = s_EditorInputWindow;
+ }
} \ No newline at end of file
diff --git a/Editor/GUI/WindowBase.h b/Editor/GUI/WindowUtil.h
index cf3cae6..dcc4eca 100644
--- a/Editor/GUI/WindowBase.h
+++ b/Editor/GUI/WindowUtil.h
@@ -29,6 +29,9 @@ public:
static const wchar_t* kContainerWindowClassName;
static const wchar_t* kPopupWindowClassName;
static const wchar_t* kGUIWindowClassName;
+
+ static void SetEditorMouseOffset(int x, int y, HWND window);
+ static void GetEditorMouseOffset(int *x, int *y, HWND *window);
};
class WindowManager : Singleton<WindowManager>
@@ -41,3 +44,6 @@ private:
static std::vector<GUIWindow*> s_GUIWindows;
};
+
+
+
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj
index 3ebe2b5..0d9bd11 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj
@@ -87,7 +87,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
- <PreprocessorDefinitions>GAMELAB_WIN;_CRT_SECURE_NO_WARNINGS;GAMELAB_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>GAMELAB_WIN;GAMELAB_EDITOR;_CRT_SECURE_NO_WARNINGS;GAMELAB_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)..\..\;$(SolutionDir)..\..\ThirdParty\;%(AdditionalIncludeDirectories);$(SolutionDir)..\..\ThirdParty\freetype\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
@@ -135,7 +135,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)..\..\;%(AdditionalIncludeDirectories);$(SolutionDir)..\..\ThirdParty\freetype\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>GAMELAB_WIN;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>GAMELAB_WIN;GAMELAB_EDITOR;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -256,7 +256,7 @@
<ClInclude Include="..\..\..\Editor\GUI\GUIWindow.h" />
<ClInclude Include="..\..\..\Editor\GUI\MenuManager.h" />
<ClInclude Include="..\..\..\Editor\GUI\Rect.h" />
- <ClInclude Include="..\..\..\Editor\GUI\WindowBase.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\WindowUtil.h" />
<ClInclude Include="..\..\..\Editor\GUI\WinUtils.h" />
<ClInclude Include="..\..\..\Editor\Resource\ResourceManager.h" />
<ClInclude Include="..\..\..\Editor\Scripting\EditorScripting.h" />
@@ -311,6 +311,7 @@
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInternal.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.h" />
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindLClass.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindMemberRef.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRef.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRefTable.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
index f868707..2b04b8f 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
@@ -741,12 +741,15 @@
<ClInclude Include="..\..\..\Editor\GUI\GUIWindow.h">
<Filter>Editor\GUI</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Editor\GUI\WindowBase.h">
- <Filter>Editor\GUI</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\Runtime\Events\KeyCode.h">
<Filter>Runtime\Events</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Editor\GUI\WindowUtil.h">
+ <Filter>Editor\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindLClass.h">
+ <Filter>Runtime\Lua\LuaBind</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/Events/InputEvent.cpp b/Runtime/Events/InputEvent.cpp
index e062bc2..c5994ef 100644
--- a/Runtime/Events/InputEvent.cpp
+++ b/Runtime/Events/InputEvent.cpp
@@ -1,11 +1,246 @@
#include "InputEvent.h"
+#ifdef GAMELAB_EDITOR
+#include "Editor/GUI/WindowUtil.h"
+#endif
-InputEvent::InputEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+static Vector2f GetInputMousePosition(HWND window)
{
+#if GAMELAB_EDITOR
+ POINT mousePos;
+ ::GetCursorPos(&mousePos);
+ ::ScreenToClient(window, &mousePos);
+ int offsetX = 0, offsetY = 0;
+ HWND offsetWindow;
+ WindowUtil::GetEditorMouseOffset(&offsetX, &offsetY, &offsetWindow);
+ if (offsetWindow == window)
+ {
+ mousePos.x += offsetX;
+ mousePos.y += offsetY;
+ }
+ return Vector2f(mousePos.x, mousePos.y);
+#else
+ //return GetInputManager().GetMousePosition();
+
+#endif
}
-void InputEvent::CastToTable(LuaBind::State& state)
+InputEvent::InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window)
+{
+ static Vector2f s_LastMousePos(0.0f, 0.0f);
+
+ isMouse = false, isKey = false;
+
+ 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)
+ {
+ type = InputEvent_MouseDrag;
+ button |= Mouse_LeftButton;
+ }
+ if (wParam & MK_RBUTTON)
+ {
+ type = InputEvent_MouseDrag;
+ button |= Mouse_RightButton;
+ }
+ if (wParam & MK_MBUTTON)
+ {
+ type = InputEvent_MouseDrag;
+ button |= Mouse_MiddleButton;
+ }
+ 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:
+ type = InputEvent_Ignore;
+ break;
+ }
+
+ // Handle modifiers
+ modifiers = 0;
+ if (type != InputEvent_Ignore)
+ {
+ if (GetKeyState(VK_SHIFT) < 0)
+ modifiers |= Modifier_Shift;
+ if (GetKeyState(VK_CONTROL) < 0)
+ modifiers |= Modifier_Control;
+ if (GetKeyState(VK_MENU) < 0)
+ modifiers |= Modifier_Alt;
+ if (GetKeyState(VK_LWIN) < 0 || GetKeyState(VK_RWIN) < 0)
+ modifiers |= Modifier_Command;
+ if (GetKeyState(VK_CAPITAL) < 0)
+ modifiers |= Modifier_CapsLock;
+ }
+
+ if (isMouse)
+ {
+ Vector2f p = GetInputMousePosition(window);
+ mousePosition = p;
+
+ pressure = 1.0f; // TODO ?
+
+ // mouse wheel events already captured scroll distance in delta
+ if (type == InputEvent_ScrollWheel && message == WM_MOUSEWHEEL)
+ {
+ // nothing
+ }
+ else
+ {
+ mouseDelta = mousePosition - s_LastMousePos;
+
+ //if (type == InputEvent_MouseDrag && s_wantsMouseJumping)
+ // DoMouseJumpingTroughScreenEdges(window, mousePosition, s_LastMousePos);
+ //else
+ s_LastMousePos = mousePosition;
+
+ // We get quite a lot of move/drag events that have delta of zero. Filter those
+ // out.
+ if ((type == InputEvent_MouseMove || type == InputEvent_MouseDrag) && mouseDelta.x == 0.0f && mouseDelta.y == 0.0f)
+ type = InputEvent_Ignore;
+
+ }
+ }
+ else
+ {
+ Vector2f p = GetInputMousePosition(window);
+
+ button = 0;
+ pressure = 0.0f;
+ mouseDelta = Vector2f(0.0f, 0.0f);
+ clickCount = 0;
+ mousePosition = p;
+ }
+
+ // handle keyboard
+ character = keycode = 0;
+
+ if (isKey)
+ {
+ //if (message == WM_CHAR)
+ //{
+ // character = wParam;
+ // if (character == 127 || character < ' ' && character != 13 && character != 10 && character != 9) // ignore control characters other than Enter or Tab
+ // type = InputEvent_Ignore;
+ //}
+ //else
+ //{
+ // if (wParam == VK_CONTROL)
+ // {
+ // wParam = (lParam & (1 << 24)) ? VK_RCONTROL : VK_LCONTROL;
+ // }
+ // if (wParam == VK_MENU)
+ // {
+ // wParam = (lParam & (1 << 24)) ? VK_RMENU : VK_LMENU;
+ // }
+ // keycode = InputKeycodeFromVKEY(wParam);
+ // if (keycode == SDLK_UNKNOWN)
+ // type = InputEvent::kIgnore;
+ // if (((wParam >= VK_F1) || (wParam >= VK_PRIOR && wParam <= VK_HELP)) && (wParam < VK_OEM_1 || wParam > VK_OEM_8))
+ // modifiers |= InputEvent::kFunctionKey;
+ //}
+
+ //// The unity convention is that function keys are anything that requires special handling
+ //// when dealing with a text entry field. Hence, backspace is
+ //if (keycode == SDLK_BACKSPACE)
+ // modifiers |= InputEvent::kFunctionKey;
+
+ //// "Return" gives an ASCII-13 (Carriage return). For sanity, we turn that into ASCII-10(linefeed, \n)
+ //if (character == 13)
+ // character = 10;
+ }
+}
+
+void InputEvent::CastToTable(LuaBind::State& state) const
{
lua_newtable(state);
int table = state.GetTop();
@@ -15,5 +250,28 @@ void InputEvent::CastToTable(LuaBind::State& state)
lua_setfield(state, table, "type");
// "mousePosition"
+ state.PushLuaObject(mousePosition);
+ lua_setfield(state, table, "mousePosition");
+
+ if (isMouse)
+ {
+ // "mouseDelta"
+ state.PushLuaObject(mouseDelta);
+ lua_setfield(state, table, "mouseDelta");
+
+ // "button"
+ lua_pushnumber(state, button);
+ lua_setfield(state, table, "button");
+
+ // "clickCount"
+ lua_pushnumber(state, clickCount);
+ lua_setfield(state, table, "clickCount");
+ }
+
+ if (isKey)
+ {
+
+ }
+ state.SetTop(table);
} \ No newline at end of file
diff --git a/Runtime/Events/InputEvent.h b/Runtime/Events/InputEvent.h
index 6069c85..164bfff 100644
--- a/Runtime/Events/InputEvent.h
+++ b/Runtime/Events/InputEvent.h
@@ -30,6 +30,22 @@ enum EInputEventType
InputEvent_RotateGesture = 1002
};
+enum EModifiers {
+ Modifier_Shift = 1 << 0,
+ Modifier_Control = 1 << 1,
+ Modifier_Alt = 1 << 2,
+ Modifier_Command = 1 << 3,
+ Modifier_Numeric = 1 << 4,
+ Modifier_CapsLock = 1 << 5,
+ Modifier_FunctionKey = 1 << 6
+};
+
+enum EMouseButton {
+ Mouse_LeftButton = 0,
+ Mouse_RightButton = 1,
+ Mouse_MiddleButton = 2
+};
+
// ¼
struct InputEvent : public LuaBind::INativeTable
{
@@ -50,8 +66,11 @@ struct InputEvent : public LuaBind::INativeTable
bool use;
- InputEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+ InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window);
+
+ void CastToTable(LuaBind::State& state) const override;
- void CastToTable(LuaBind::State& state) override;
+private:
+ bool isMouse, isKey;
}; \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBind.h b/Runtime/Lua/LuaBind/LuaBind.h
index b6c5870..2a73c98 100644
--- a/Runtime/Lua/LuaBind/LuaBind.h
+++ b/Runtime/Lua/LuaBind/LuaBind.h
@@ -12,5 +12,6 @@
#include "LuaBindState.inc"
#include "LuaBindInvoker.h"
#include "LuaBindTable.h"
+#include "LuaBindLClass.h"
#endif \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
index debebf8..a95ef5c 100644
--- a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
@@ -76,12 +76,18 @@ namespace LuaBind
++argc;
}
- void MemberInvoker::AddTable(INativeTable& tb)
+ void MemberInvoker::AddTable(const INativeTable& tb)
{
tb.CastToTable(state);
++argc;
}
+ void MemberInvoker::AddLuaObject(const ILuaClass& obj)
+ {
+ obj.CastToLuaObject(state);
+ ++argc;
+ }
+
void MemberInvoker::AddMember(MemberRef member)
{
owner->PushMemberRef(state, member);
diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h
index 8ea57a2..edb0725 100644
--- a/Runtime/Lua/LuaBind/LuaBindInvoker.h
+++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h
@@ -56,7 +56,8 @@ namespace LuaBind
void AddNil();
void AddBool(bool b);
void AddString(const char* str);
- void AddTable(INativeTable& tb);
+ void AddTable(const INativeTable& tb);
+ void AddLuaObject(const ILuaClass& obj);
template<class T>
void AddUserdata(NativeClass<T>& udata) {
udata.PushUserdata(state);
diff --git a/Runtime/Lua/LuaBind/LuaBindLClass.h b/Runtime/Lua/LuaBind/LuaBindLClass.h
new file mode 100644
index 0000000..9f4c959
--- /dev/null
+++ b/Runtime/Lua/LuaBind/LuaBindLClass.h
@@ -0,0 +1,16 @@
+#pragma once
+
+namespace LuaBind
+{
+
+ class State;
+
+ // Ҫתlua classʵӿڣһluaĶ󣬷ջ
+ class ILuaClass
+ {
+ public:
+ virtual void CastToLuaObject(State&) const = 0 ;
+
+ };
+
+}
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp
index 676c19c..92e46cd 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindState.cpp
@@ -196,7 +196,12 @@ namespace LuaBind
}
}
- void State::PushTable(INativeTable& tb)
+ void State::PushLuaObject(const ILuaClass& lc)
+ {
+ lc.CastToLuaObject(*this);
+ }
+
+ void State::PushTable(const INativeTable& tb)
{
tb.CastToTable(*this);
}
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h
index 24bd092..aaad952 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.h
+++ b/Runtime/Lua/LuaBind/LuaBindState.h
@@ -7,6 +7,7 @@
#include "LuaBindRefTable.h"
#include "LuaBindGlobalState.h"
#include "LuaBindTable.h"
+#include "LuaBindLClass.h"
namespace LuaBind
{
@@ -101,7 +102,8 @@ namespace LuaBind
bool HasField(int idx, int name, int type);
bool HasKeys(int idx);
- void PushTable(INativeTable& tb);
+ void PushLuaObject(const ILuaClass& lc);
+ void PushTable(const INativeTable& tb);
void PushNil();
void Push(bool value);
void Push(cc8* value);
diff --git a/Runtime/Lua/LuaBind/LuaBindTable.h b/Runtime/Lua/LuaBind/LuaBindTable.h
index 3a6ec6c..a3822d3 100644
--- a/Runtime/Lua/LuaBind/LuaBindTable.h
+++ b/Runtime/Lua/LuaBind/LuaBindTable.h
@@ -9,7 +9,7 @@ namespace LuaBind
struct INativeTable
{
// ṹתΪtableջ
- virtual void CastToTable(State& state) = 0;
+ virtual void CastToTable(State& state) const = 0;
};
} \ No newline at end of file
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index f1dc349..71fe782 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -5,6 +5,7 @@
#include "Runtime/Graphics/Color.h"
using namespace LuaBind;
+using namespace std;
template <>
Rect State::GetValue < Rect >(int idx, const Rect value)
@@ -207,4 +208,32 @@ bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx)
bool LuaHelper::InstantiateClass(LuaBind::State& state, const char* classFullName)
{
return false;
+}
+
+bool LuaHelper::GetLuaClass(LuaBind::State& state, const char* fullName)
+{
+ if (fullName == NULL || strlen(fullName) == 0)
+ return false;
+ int top = state.GetTop();
+ lua_pushvalue(state, LUA_GLOBALSINDEX);
+ string name = fullName;
+ while (name.size() > 0)
+ {
+ int dot = name.find('.');
+ dot = dot != string::npos ? dot : name.size();
+ string pkg = name.substr(0, dot);
+ if (dot < name.size())
+ name = name.substr(dot + 1, name.size() - dot - 1);
+ else
+ name = "";
+ lua_getfield(state, -1, pkg.c_str());
+ if (lua_isnil(state, -1))
+ {
+ lua_settop(state, top);
+ return false;
+ }
+ }
+ lua_replace(state, top + 1);
+ lua_settop(state, top + 1);
+ return true;
} \ No newline at end of file
diff --git a/Runtime/Lua/LuaHelper.h b/Runtime/Lua/LuaHelper.h
index c3cd70e..79cab29 100644
--- a/Runtime/Lua/LuaHelper.h
+++ b/Runtime/Lua/LuaHelper.h
@@ -1,6 +1,4 @@
#pragma once
-#include "Runtime/Math/Rect.h"
-#include "Runtime/Math/Vector2.h"
#include "./LuaBind/LuaBind.h"
// lua 5.1 doc: https://www.lua.org/manual/5.1/
@@ -14,5 +12,8 @@ public:
static void OnRegisterNativeClass(LuaBind::State& state, int cls, std::string clsName, std::string pkgName);
// luaʵջʧܷfalseҲѹջ
static bool InstantiateClass(LuaBind::State& state, const char* classFullName);
-
+
+ // ҵtableջfalseʾûҵջֵ
+ static bool GetLuaClass(LuaBind::State& state, const char* fullName);
+
}; \ No newline at end of file
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
index 7c519b8..31098ab 100644
--- a/Runtime/Math/Vector2.h
+++ b/Runtime/Math/Vector2.h
@@ -1,11 +1,12 @@
#pragma once
#include "MathHelper.h"
#include "Runtime/Utilities/Assert.h"
+#include "Runtime/Lua/LuaHelper.h"
namespace Internal
{
template<typename T>
- struct Vector2T
+ struct Vector2T : public LuaBind::ILuaClass
{
Vector2T(T x = 0, T y = 0)
{
@@ -43,6 +44,30 @@ namespace Internal
return v.x != x || v.y != y;
}
+ Vector2T<T> operator - (const Vector2T& v) const
+ {
+ Vector2T<T> res = Vector2T<T>(x - v.x, y - v.y);
+ return res;
+ }
+
+ void CastToLuaObject(LuaBind::State& state) const override
+ {
+ int top = state.GetTop();
+ if (LuaHelper::GetLuaClass(state, "GameLab.Engine.Math.Vector2"))
+ {
+ lua_getfield(state, -1, "New");
+ lua_pushnumber(state, (float)x);
+ lua_pushnumber(state, (float)y);
+ state.Call(2, 1);
+ lua_replace(state, top + 1);
+ lua_settop(state, top + 1);
+ }
+ else
+ {
+ lua_pushnil(state);
+ }
+ }
+
T x, y;
static Vector2T<T> zero;
diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp
index a10ed69..2f63951 100644
--- a/Runtime/Scripting/Resource/Resource.bind.cpp
+++ b/Runtime/Scripting/Resource/Resource.bind.cpp
@@ -4,6 +4,7 @@
#include "Runtime/Graphics/ImageData.h"
#define STB_IMAGE_IMPLEMENTATION
#include "ThirdParty/stb/stb_image.h"
+#include "Runtime/Utilities/Assert.h"
using namespace LuaBind;