diff options
author | chai <chaifix@163.com> | 2021-11-19 15:33:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-19 15:33:48 +0800 |
commit | 1cd31d14c95f9d52e30fbc611df5da4b46f048d9 (patch) | |
tree | 86dbda850f9b8ed26b152c6521adc0a777d6563a | |
parent | 2ab7fad7b308debba0aacbf76831569f360d19a0 (diff) |
*misc
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua | 39 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua | 8 | ||||
-rw-r--r-- | Data/Libraries/GameLab/Editor/Window/GUIWindow.lua | 37 | ||||
-rw-r--r-- | Data/Libraries/GameLab/Editor/Window/SplitWindow.lua | 6 | ||||
-rw-r--r-- | Data/Resources/Shaders/Editor-Text.glsl | 5 | ||||
-rw-r--r-- | Data/Scripts/EditorApplication.lua | 4 | ||||
-rw-r--r-- | Data/boot.lua | 2 | ||||
-rw-r--r-- | Editor/GUI/GUIWindow.cpp | 42 | ||||
-rw-r--r-- | Editor/GUI/GUIWindow.h | 1 | ||||
-rw-r--r-- | Editor/Scripting/GUI/EditorGUI.bind.cpp | 2 | ||||
-rw-r--r-- | Editor/Scripting/Window/ContainerWindow.bind.cpp | 2 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj | 1 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj.filters | 3 | ||||
-rw-r--r-- | Runtime/GUI/UIQuad.cpp | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.h | 6 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindLClass.h | 12 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 4 | ||||
-rw-r--r-- | Runtime/Math/ITransData.h | 7 | ||||
-rw-r--r-- | Runtime/Math/Vector2.h | 12 |
19 files changed, 142 insertions, 53 deletions
diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua index c2677bc..a16c2ed 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua @@ -12,6 +12,8 @@ local shaders = Res.shaders local GL = GameLab.Engine.GL
local Matrix44 = find "GameLab.Engine.Math.Matrix44"
local Rendering = GameLab.Engine.Rendering
+local EEventType = GameLab.Events.EEventType
+local Resource = GameLab.Engine.Resource
GUI.BeginOnGUI = function()
GUIState.ResetControlID()
@@ -45,18 +47,33 @@ GUI.Label = function() end
local shader
+local tex
+
GUI.Box = function(position, color, size)
- --Rendering.UseShader(Res.shaders["EditorShape"])
- local ortho = Matrix44()
- ortho:SetOrtho(0, size.x, size.y, 0, 0.1, 10)
- if shader == nil then
- shader = Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.glsl")
- end
-
- Rendering.UseShader(shader)
- Rendering.SetMatrix44("gamelab_mat_mvp", ortho)
- Rendering.SetVector2("gamelab_ui_position", {0, 0})
- EditorGUI.Text(_G["default_font"], "你好世界!\nMaterials\nHello,World!\nProject Window Properties", 12)
+ if Event.current.type == EEventType.Repaint then
+ -- GL.ClearColor({0.13, 0.13, 0.13, 1})
+ -- GL.Clear(GL.EBufferType.ColorBuffer)
+ --Rendering.UseShader(Res.shaders["EditorShape"])
+ local ortho = Matrix44()
+ ortho:SetOrtho(0, size.x, size.y, 0, 0.1, 10)
+ if shader == nil then
+ shader = Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.glsl")
+ --shader = Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-UI.glsl")
+ end
+ if tex == nil then
+ tex = Resource.LoadTexture("./Resources/Images/tile.png")
+ --tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall_small.jpg")
+ end
+
+ Rendering.UseShader(shader)
+ Rendering.SetMatrix44("gamelab_mat_mvp", ortho)
+ Rendering.SetVector2("gamelab_ui_position", {0, 0})
+ --Rendering.SetTexture("gamelab_main_tex", tex)
+ --Rendering.DrawUIQuad({0, 0, 200, 200})
+ --Rendering.DrawUI9Slicing(1, {25, 25}, {25, 25}, {80, 80}, {400, 30} )
+ EditorGUI.Text(_G["default_font"], "你好世界!\nMaterials\nHello,World!\nProject Window Properties", 12)
+ --EditorGUI.Text(_G["default_font"], "hello", 12)
+ end
end
GUI.HorizontalSlider = function()
diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua b/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua index afadee8..2a1733a 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua @@ -10,10 +10,10 @@ end Rect.Set = function(self, rect)
if rect.Is and rect:Is(Rect) then
- self.x = rect.x or rect.x
- self.y = rect.y or rect.y
- self.width = rect.z or rect.width
- self.height = rect.w or rect.height
+ self.x = rect.x
+ self.y = rect.y
+ self.width = rect.width
+ self.height = rect.height
else
self.x = rect.x or rect[1]
self.y = rect.y or rect[2]
diff --git a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua index e2ceee5..c430cfd 100644 --- a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua @@ -9,10 +9,11 @@ local Utils = require "GameLab.Utils" local Events = require "GameLab.Events"
local GUI = require "GameLab.Engine.GUI"
-local Rect = Math.Rect
-local Event = Events.Event
-local Vector2 = Math.Vector2
-local Color = Rendering.Color
+local Rect = Math.Rect
+local Event = Events.Event
+local EEventType = Events.EEventType
+local Vector2 = Math.Vector2
+local Color = Rendering.Color
local clone = Utils.Clone
@@ -99,20 +100,22 @@ end -- 最主要的回调函数,同时处理窗口管理、事件、布局、渲染
GUIWindow.OnGUI = function(self)
Debug.Log("OnGUI")
- self:ClearBackground()
local event = Event.current
- local sp = self.splitWindow
- if sp ~= nil and event ~= nil then
- local e = clone(event)
- e.mousePosition:Add(self.position.xy) -- 坐标转换到全局containerWindow的坐标
- sp:DoSplit(e)
+ if event.type ~= EEventType.Repaint then
+ local sp = self.splitWindow
+ if sp ~= nil and event ~= nil then
+ local e = clone(event)
+ e.mousePosition:Add(self.position.xy) -- 坐标转换到全局containerWindow的坐标
+ sp:DoSplit(e)
+ end
end
+ self:ClearBackground()
GUI.Box(Rect(), Color(), self.position.size)
-end
+end
GUIWindow.GetContainerWindow = function(self)
return self.m_ContainerWindow
@@ -120,11 +123,17 @@ end GUIWindow.OnFocus = function(self)
Debug.Log("GUIWindow.OnFocus")
-end
+end
GUIWindow.ClearBackground = function(self)
- GL.ClearColor(self.m_ClearColor)
- GL.Clear(GL.EBufferType.ColorBuffer)
+ if Event.current.type == EEventType.Repaint then
+ GL.ClearColor(self.m_ClearColor)
+ GL.Clear(GL.EBufferType.ColorBuffer)
+ end
end
+GUIWindow.DoRepaint = function(self)
+ self.m_Native:DoPaint()
+end
+
return GUIWindow
\ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua index fea443d..cd8d3a3 100644 --- a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua @@ -179,4 +179,10 @@ SplitWindow.AddSubWindow = function(self, subWindow) subWindow.m_Parent = self end +SplitWindow.DoRepaint = function(self) + for _, wnd in ipairs(self.m_SubWindows) do + wnd:DoRepaint() + end +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 d1003c3..3c1ad4f 100644 --- a/Data/Resources/Shaders/Editor-Text.glsl +++ b/Data/Resources/Shaders/Editor-Text.glsl @@ -5,7 +5,7 @@ Cull Off Blend SrcAlpha OneMinusSrcAlpha DepthTest Off CMD_END - + uniform mat4 gamelab_mat_mvp; uniform sampler2D gamelab_main_tex; uniform vec2 gamelab_ui_position; @@ -36,11 +36,8 @@ out vec4 FragColor; void main() { - //vec2 uv = vec2(uv.x, 1 - uv.y); vec4 sampled = vec4(0.8,0.8,0.8,texture(gamelab_main_tex, uv).r); sampled *= color; - // if(sampled.a == 0) - // sampled = vec4(1,0,0,1); FragColor = sampled; } FSH_END diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index 92df9ad..1a31cdd 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -45,8 +45,8 @@ local v = GameLab.Engine.Math.Vector4(1,2,3,4) local c = Engine.Rendering.Color(1,1,1,1) -GL.ClearColor({1,1,1,1}) -GL.Clear(GL.EBufferType.ColorBuffer) +-- GL.ClearColor({1,1,1,1}) +-- GL.Clear(GL.EBufferType.ColorBuffer) local files = { "README.txt", diff --git a/Data/boot.lua b/Data/boot.lua index ff8e93f..94dabd1 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -37,7 +37,7 @@ require "GameLab.Editor" require "GameLab.Editor.Window"
-- debugging
---require("LuaPanda").start("127.0.0.1",8818)
+require("LuaPanda").start("127.0.0.1",8818)
-- launch editor
dofile("./Scripts/EditorApplication.lua")
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index fe19a95..b680e28 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -23,6 +23,15 @@ void GUIWindowProxy::OnGUI(LuaBind::State& state) invoker.Invoke(0); } +void GUIWindowProxy::DoInputEvent(LuaBind::State& state) +{ + MemberInvoker invoker = MemberInvoker(state, owner); + invoker.member = script; + invoker.method = "OnGUI"; + invoker.AddMember(script); + invoker.Invoke(0); +} + void GUIWindowProxy::OnFocus(LuaBind::State& state) { LuaBind::MemberInvoker invoker = MemberInvoker(state, owner); @@ -81,6 +90,7 @@ static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam) //s_ReentrancyCheck = false; return true; } +static PAINTSTRUCT ps; LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -102,12 +112,11 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_PAINT: { - static PAINTSTRUCT ps; - log_info_tag("WndProc", "WM_PAINT %d", _event_count); self->SetAsRenderContext(); self->OnPaint(); + //glFlush(); BeginPaint(self->m_Handle, &ps); EndPaint(self->m_Handle, &ps); @@ -221,7 +230,7 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara // self->RequestRepaint(); // } - self->DoPaint(); + //self->DoPaint(); // // Update the scene so that scripts marked with [ExecuteInEditMode] are able to react to screen size changes // GetApplication().SetSceneRepaintDirty(); @@ -321,9 +330,7 @@ void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam) SCRIPT_GLOBAL.guiBeginOnGUI.Invoke(state); - SetAsRenderContext(); - - m_Script.DoGUI(state); + m_Script.DoInputEvent(state); SCRIPT_GLOBAL.guiEndOnGUI.Invoke(state); } @@ -402,8 +409,17 @@ void GUIWindow::OnLostFocus() void GUIWindow::OnPaint() { + InputEvent e = InputEvent::RepaintEvent(m_Handle); LuaBind::State state = GetVM()->GetCurThread(); - m_Script.OnGUI(state); + + SCRIPT_GLOBAL.setCurrentEvent.AddTable(state, e); + SCRIPT_GLOBAL.setCurrentEvent.Invoke(state); + + SCRIPT_GLOBAL.guiBeginOnGUI.Invoke(state); + + m_Script.DoGUI(state); + + SCRIPT_GLOBAL.guiEndOnGUI.Invoke(state); } void GUIWindow::SetPosition(Rect position) @@ -429,12 +445,12 @@ void GUIWindow::SetAsRenderContext() void GUIWindow::Focus() { log_info("Focus GUIWindow "); - //if (m_Handle) - //{ - // if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) - // ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); - // SetFocus(m_Handle); - //} + if (m_Handle) + { + //if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) + // ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); + SetFocus(m_Handle); + } } void GUIWindow::SetContainerWindow(ContainerWindow* wnd) diff --git a/Editor/GUI/GUIWindow.h b/Editor/GUI/GUIWindow.h index ed79f26..858004c 100644 --- a/Editor/GUI/GUIWindow.h +++ b/Editor/GUI/GUIWindow.h @@ -25,6 +25,7 @@ public: GUIWindowProxy() {} GUIWindowProxy(GUIWindow *owner, LuaBind::MemberRef script); + void DoInputEvent(LuaBind::State& state); void DoGUI(LuaBind::State& state); void DoClean(LuaBind::State& state); diff --git a/Editor/Scripting/GUI/EditorGUI.bind.cpp b/Editor/Scripting/GUI/EditorGUI.bind.cpp index b51e019..e0b94e0 100644 --- a/Editor/Scripting/GUI/EditorGUI.bind.cpp +++ b/Editor/Scripting/GUI/EditorGUI.bind.cpp @@ -80,6 +80,8 @@ static int Text(lua_State* L) const UITextMesh* tm = g_TextMeshGenerator.GetTextMesh(str, font, pixelSize, lineHeight, color, (ETextAnchor)anchor, (ETextAlignment)alignment, wordwrap, preferred); tm->Draw(); + WipeGLError(); + return 0; } diff --git a/Editor/Scripting/Window/ContainerWindow.bind.cpp b/Editor/Scripting/Window/ContainerWindow.bind.cpp index f459c85..f3a8cc7 100644 --- a/Editor/Scripting/Window/ContainerWindow.bind.cpp +++ b/Editor/Scripting/Window/ContainerWindow.bind.cpp @@ -62,7 +62,7 @@ LUA_BIND_IMPL_METHOD(ContainerWindow, _GetSize) { LUA_BIND_PREPARE(L, ContainerWindow); - state.PushLuaObject(self->GetSize()); + state.PushLuaObject<Vector2f>(self->GetSize()); return 1; } diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index c76c890..eaf43c7 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -334,6 +334,7 @@ <ClInclude Include="..\..\..\Runtime\Lua\LuaObjectProxy.h" />
<ClInclude Include="..\..\..\Runtime\Math\AABB.h" />
<ClInclude Include="..\..\..\Runtime\Math\FloatConversion.h" />
+ <ClInclude Include="..\..\..\Runtime\Math\ITransData.h" />
<ClInclude Include="..\..\..\Runtime\Math\Math.h" />
<ClInclude Include="..\..\..\Runtime\Math\MathHelper.h" />
<ClInclude Include="..\..\..\Runtime\Math\Matrix44.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 2324494..c775d60 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -771,6 +771,9 @@ <ClInclude Include="..\..\..\Runtime\GUI\UISquare.h">
<Filter>Runtime\GUI</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Math\ITransData.h">
+ <Filter>Runtime\Math</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/GUI/UIQuad.cpp b/Runtime/GUI/UIQuad.cpp index e28a772..c57685c 100644 --- a/Runtime/GUI/UIQuad.cpp +++ b/Runtime/GUI/UIQuad.cpp @@ -30,6 +30,8 @@ void UIQuad::Draw() m_Left, m_Top, // top-left }; + int n = sizeof(Vector2); + float uv[] = { 0, 0, 1, 0, diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h index 5f24b15..cbfb2f9 100644 --- a/Runtime/Lua/LuaBind/LuaBindInvoker.h +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h @@ -59,6 +59,12 @@ namespace LuaBind udata.PushUserdata(state); ++argc; } + template<class T> + void AddLuaObject(T& obj) { + //LuaObjectTransfer::CastToLuaObject<T>(state, obj); + obj.CastToLuaObject(state); + ++argc; + } void Invoke(int nReturns = 0); diff --git a/Runtime/Lua/LuaBind/LuaBindLClass.h b/Runtime/Lua/LuaBind/LuaBindLClass.h index 296d6a1..538941e 100644 --- a/Runtime/Lua/LuaBind/LuaBindLClass.h +++ b/Runtime/Lua/LuaBind/LuaBindLClass.h @@ -14,4 +14,16 @@ namespace LuaBind };
+ class LuaObjectTransfer
+ {
+ public:
+ // ػЩ
+ template <class T>
+ static void CastToLuaObject(State&, T& in);
+
+ template <class T>
+ static void RestoreFromLuaObject(State& state, int index, T& out);
+
+ };
+
}
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index e8ac42d..680f6e2 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -104,6 +104,10 @@ namespace LuaBind bool HasField(int idx, int name, int type); bool HasKeys(int idx); + template <class T> + void PushLuaObject(const T& obj) { + obj.CastToLuaObject(*this); + } void PushLuaObject(const ILuaClass& lc); void PushTable(const INativeTable& tb); void PushNil(); diff --git a/Runtime/Math/ITransData.h b/Runtime/Math/ITransData.h new file mode 100644 index 0000000..bda81e5 --- /dev/null +++ b/Runtime/Math/ITransData.h @@ -0,0 +1,7 @@ +//#pragma once
+//
+//class ITransData
+//{
+//public:
+// virtual int GetDataSize() = 0;
+//};
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h index f83a521..5dd8fe6 100644 --- a/Runtime/Math/Vector2.h +++ b/Runtime/Math/Vector2.h @@ -2,11 +2,12 @@ #include "MathHelper.h" #include "Runtime/Utilities/Assert.h" #include "Runtime/Lua/LuaHelper.h" +#include "ITransData.h" namespace Internal { template<typename T> - struct Vector2T : public LuaBind::ILuaClass + struct Vector2T { Vector2T(T x = 0, T y = 0) { @@ -50,7 +51,7 @@ namespace Internal return res; } - void CastToLuaObject(LuaBind::State& state) const override + void CastToLuaObject(LuaBind::State& state) const { int top = state.GetTop(); if (LuaHelper::GetLuaClass(state, "GameLab.Engine.Math.Vector2")) @@ -68,7 +69,7 @@ namespace Internal } } - void RestoreFromLuaObject(LuaBind::State& state, int index) override + void RestoreFromLuaObject(LuaBind::State& state, int index) { if (lua_isnil(state, index)) return; @@ -84,6 +85,11 @@ namespace Internal y = state.GetField<float>(index, 1, 0); } } + + static int GetDataSize() + { + return 2 * sizeof(T); + } T x, y; |