From 0944b2f95b9971d62f35b9dcc38d28a27e278249 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 20 Nov 2021 20:29:08 +0800 Subject: * mv gui to editor --- .../Libraries/GameLab/Engine/GUI/GUIState.lua | 23 ----- .../BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua | 114 --------------------- Data/BuiltIn/Libraries/GameLab/Engine/GUI/init.lua | 3 - Data/Libraries/GameLab/Editor/GUI/GUIState.lua | 23 +++++ Data/Libraries/GameLab/Editor/GUI/IMGUI.lua | 113 ++++++++++++++++++++ Data/Libraries/GameLab/Editor/GUI/init.lua | 4 +- Data/Libraries/GameLab/Editor/Window/GUIWindow.lua | 11 +- .../GameLab/Editor/Window/SplitWindow.lua | 3 +- Data/boot.lua | 3 +- Runtime/Scripting/GL/GL.bind.cpp | 6 +- Runtime/Scripting/RuntimeScriptGlobals.cpp | 8 +- 11 files changed, 159 insertions(+), 152 deletions(-) delete mode 100644 Data/BuiltIn/Libraries/GameLab/Engine/GUI/GUIState.lua delete mode 100644 Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua create mode 100644 Data/Libraries/GameLab/Editor/GUI/GUIState.lua create mode 100644 Data/Libraries/GameLab/Editor/GUI/IMGUI.lua diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/GUIState.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/GUIState.lua deleted file mode 100644 index bb4884e..0000000 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/GUIState.lua +++ /dev/null @@ -1,23 +0,0 @@ -local GUIState = GameLab.GlobalStaticClass("GameLab.Engine.GUI.GUIState") - -local hotControl = 0 -local currentId = 0 -- 当前可分配的controlID - -GUIState.get_hotControl = function() - return hotControl -end - -GUIState.set_hotControl = function(value) - hotControl = value -end - -GUIState.GetControlID = function() - currentId = currentId + 1 - return currentId -end - -GUIState.ResetControlID = function() - currentId = 0 -end - -return GUIState \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua deleted file mode 100644 index 3c99622..0000000 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua +++ /dev/null @@ -1,114 +0,0 @@ -local GUI = GameLab.Package("GameLab.Engine.GUI") - -local find = GameLab.Find - -local EditorGUI = GameLab.Editor.GUI - -local Debug = GameLab.Debug -local GUIState = GUI.GUIState -local Event = GameLab.Events.Event -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 -local Vector2 = GameLab.Engine.Math.Vector2 -local Vector4 = GameLab.Engine.Math.Vector4 -local Color = Rendering.Color -local builtin_res = require "GameLab.BuiltInResources" - -local editor_res -if GAMELAB_EDITOR then - editor_res = find "Scripts/EditorResources" -elseif GAMELAB_RUNNER then -end - -GUI.BeginOnGUI = function() - GUIState.ResetControlID() -end - -GUI.EndOnGUI = function() - GUIState.ResetControlID() -end - -GUI.BeginFrame = function() - GUIState.ResetControlID() -end - -GUI.EndFrame = function() - GUIState.ResetControlID() -end - ------------------------------------------------------------------------------------------------- --- Controls ------------------------------------------------------------------------------------------------- - -GUI.Button = function(rect, content ) - -end - -GUI.Toggle = function() - -end - -GUI.Label = function() - -end - -GUI.Box = function(rect, color) - if Event.current.type == EEventType.Repaint then - Rendering.UseShader(editor_res.shaders["EditorShape"]) - Rendering.SetVector2("gamelab_ui_position", rect.position) - Rendering.SetColor("gamelab_color", color) - GUI.DrawQuad(Vector2(0,0), rect.size) - end -end - -GUI.BoxFrame = function(rect, color) - if Event.current.type == EEventType.Repaint then - GUI.Line(Vector2(rect.x, rect.y), Vector2(rect.x + rect.w, rect.y), color) - GUI.Line(Vector2(rect.x + rect.w, rect.y), Vector2(rect.x + rect.w, rect.y + rect.h), color) - GUI.Line(Vector2(rect.x + rect.w, rect.y + rect.h), Vector2(rect.x, rect.y + rect.h), color) - GUI.Line(Vector2(rect.x, rect.y + rect.h), Vector2(rect.x, rect.y), color) - end -end - -GUI.HorizontalSlider = function() - -end - -GUI.VerticalSlider = function() - -end - -GUI.TextField = function() - -end - -GUI.TextArea = function() - -end - -GUI.Toolbar = function() - -end - -GUI.VerticalScrollbar = function() - -end - -GUI.HorizontalScrollbar = function() - -end - -GUI.Line = function(from, to, color) - if Event.current.type ~= EEventType.Repaint then - return - end - Rendering.UseShader(editor_res.shaders["EditorShape"]) - Rendering.SetVector2("gamelab_ui_position", {0, 0}) - Rendering.SetColor("gamelab_color", color) - GUI.DrawLine(from, to) -end - -return GUI \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/init.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/init.lua index 3012551..2eb8ac2 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/init.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/init.lua @@ -1,7 +1,4 @@ local GUI = GameLab.Package("GameLab.Engine.GUI") local import = GameLab.Import(...) -import "GUIState" -import "imgui" - return GUI \ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/GUIState.lua b/Data/Libraries/GameLab/Editor/GUI/GUIState.lua new file mode 100644 index 0000000..b45dc6b --- /dev/null +++ b/Data/Libraries/GameLab/Editor/GUI/GUIState.lua @@ -0,0 +1,23 @@ +local GUIState = GameLab.GlobalStaticClass("GameLab.Editor.GUI.GUIState") + +local hotControl = 0 +local currentId = 0 -- 当前可分配的controlID + +GUIState.get_hotControl = function() + return hotControl +end + +GUIState.set_hotControl = function(value) + hotControl = value +end + +GUIState.GetControlID = function() + currentId = currentId + 1 + return currentId +end + +GUIState.ResetControlID = function() + currentId = 0 +end + +return GUIState \ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/IMGUI.lua b/Data/Libraries/GameLab/Editor/GUI/IMGUI.lua new file mode 100644 index 0000000..2f47c80 --- /dev/null +++ b/Data/Libraries/GameLab/Editor/GUI/IMGUI.lua @@ -0,0 +1,113 @@ +local EditorGUI = GameLab.Package("GameLab.Editor.GUI") + +local find = GameLab.Find + +local Debug = GameLab.Debug +local GUIState = EditorGUI.GUIState +local Event = GameLab.Events.Event +local GL = GameLab.Engine.GL +local GUI = GameLab.Engine.GUI +local Matrix44 = find "GameLab.Engine.Math.Matrix44" +local Rendering = GameLab.Engine.Rendering +local EEventType = GameLab.Events.EEventType +local Resource = GameLab.Engine.Resource +local Vector2 = GameLab.Engine.Math.Vector2 +local Vector4 = GameLab.Engine.Math.Vector4 +local Color = Rendering.Color +local builtin_res = require "GameLab.BuiltInResources" + +local editor_res +if GAMELAB_EDITOR then + editor_res = find "Scripts/EditorResources" +elseif GAMELAB_RUNNER then +end + +EditorGUI.BeginOnGUI = function() + GUIState.ResetControlID() +end + +EditorGUI.EndOnGUI = function() + GUIState.ResetControlID() +end + +EditorGUI.BeginFrame = function() + GUIState.ResetControlID() +end + +EditorGUI.EndFrame = function() + GUIState.ResetControlID() +end + +------------------------------------------------------------------------------------------------ +-- Controls +------------------------------------------------------------------------------------------------ + +EditorGUI.Button = function(rect, content ) + +end + +EditorGUI.Toggle = function() + +end + +EditorGUI.Label = function() + +end + +EditorGUI.Box = function(rect, color) + if Event.current.type == EEventType.Repaint then + Rendering.UseShader(editor_res.shaders["EditorShape"]) + Rendering.SetVector2("gamelab_ui_position", rect.position) + Rendering.SetColor("gamelab_color", color) + GUI.DrawQuad(Vector2(0,0), rect.size) + end +end + +EditorGUI.BoxFrame = function(rect, color) + if Event.current.type == EEventType.Repaint then + EditorGUI.Line(Vector2(rect.x, rect.y), Vector2(rect.x + rect.w, rect.y), color) + EditorGUI.Line(Vector2(rect.x + rect.w, rect.y), Vector2(rect.x + rect.w, rect.y + rect.h), color) + EditorGUI.Line(Vector2(rect.x + rect.w, rect.y + rect.h), Vector2(rect.x, rect.y + rect.h), color) + EditorGUI.Line(Vector2(rect.x, rect.y + rect.h), Vector2(rect.x, rect.y), color) + end +end + +EditorGUI.HorizontalSlider = function() + +end + +EditorGUI.VerticalSlider = function() + +end + +EditorGUI.TextField = function() + +end + +EditorGUI.TextArea = function() + +end + +EditorGUI.Toolbar = function() + +end + +EditorGUI.VerticalScrollbar = function() + +end + +EditorGUI.HorizontalScrollbar = function() + +end + +EditorGUI.Line = function(from, to, color) + if Event.current.type ~= EEventType.Repaint then + return + end + Rendering.UseShader(editor_res.shaders["EditorShape"]) + Rendering.SetVector2("gamelab_ui_position", {0, 0}) + Rendering.SetColor("gamelab_color", color) + GUI.DrawLine(from, to) +end + +return GUI \ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/init.lua b/Data/Libraries/GameLab/Editor/GUI/init.lua index 0f01d9f..4c715b5 100644 --- a/Data/Libraries/GameLab/Editor/GUI/init.lua +++ b/Data/Libraries/GameLab/Editor/GUI/init.lua @@ -1,5 +1,7 @@ local GUI = GameLab.Package("GameLab.Editor.GUI") +local import = GameLab.Import(...) - +import "GUIState" +import "imgui" return GUI \ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua index 9290b1e..ceb026e 100644 --- a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua @@ -7,7 +7,7 @@ local Math = require "GameLab.Engine.Math" local Rendering = require "GameLab.Engine.Rendering" local Utils = require "GameLab.Utils" local Events = require "GameLab.Events" -local GUI = require "GameLab.Engine.GUI" +local GUI = require "GameLab.Editor.GUI" local Rect = Math.Rect local Event = Events.Event @@ -29,6 +29,7 @@ local col = { local kSideBorders = 2 -- GUIView的右边距 local kTabHeight = 17 -- 标题栏高度 local kBottomBorders = 2 -- 底部边距 +local kEditorSpace = 2 local GUIWindow = GameLab.GlobalClass("GameLab.Editor.Window.GUIWindow", function(self) self.m_Native = NativeGUIWindow.New(self) -- native guiwindow @@ -121,12 +122,18 @@ GUIWindow.OnGUI = function(self) ortho:SetOrtho(0, windowSize.x, windowSize.y, 0, 0.1, 10) Rendering.SetMatrix44("gamelab_mat_mvp", ortho) - -- + -- 框架 local guiSize = Vector2(windowSize.x - kSideBorders*2, windowSize.y - kSideBorders*2) local bgRect = Rect(kSideBorders, kSideBorders, guiSize.x, guiSize.y) GUI.Box(bgRect, Color(0.22, 0.22, 0.22, 1)) GUI.BoxFrame(bgRect, Color(0.13, 0.13, 0.13, 1)) + -- 编辑器 + local editorPos = Vector2(kSideBorders + kEditorSpace, kSideBorders + kEditorSpace + kTabHeight) + local editorRect = Rect(editorPos.x, editorPos.y, windowSize.x - editorPos.x * 2, windowSize.y - editorPos.y) + GL.Viewport(editorRect.x, windowSize.y - editorRect.height - editorPos.y, editorRect.width, editorRect.height) + GUI.Line(Vector2(0,0), Vector2(100, 100), Color(1,0,0,1)) + end GUIWindow.GetContainerWindow = function(self) diff --git a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua index cd8d3a3..a06fee8 100644 --- a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua @@ -8,9 +8,10 @@ local ECursor = GameLab.Editor.Window.ECursor local Window = GameLab.Editor.Window local Vector2 = GameLab.Engine.Math.Vector2 local Utils = GameLab.Utils +local EditorGUI = GameLab.Editor.GUI local Rect = Math.Rect -local GUIState = GUI.GUIState +local GUIState = EditorGUI.GUIState local Splitter = GameLab.Class("GameLab.Editor.Window.Internal.Splitter") diff --git a/Data/boot.lua b/Data/boot.lua index 6807de6..d1261c3 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -39,10 +39,11 @@ require "GameLab.Engine.Rendering" require "GameLab.Engine.Resource" require "GameLab.Engine.GL" require "GameLab.Editor" +require "GameLab.Editor.GUI" 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/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp index caf3877..5260378 100644 --- a/Runtime/Scripting/GL/GL.bind.cpp +++ b/Runtime/Scripting/GL/GL.bind.cpp @@ -180,12 +180,12 @@ int Viewport(lua_State* L) { LUA_BIND_STATE(L); - float left = state.GetValue(1, 0); - float right = state.GetValue(2, 0); + float x = state.GetValue(1, 0); + float y = state.GetValue(2, 0); float width = state.GetValue(3, 0); float height = state.GetValue(4, 0); - glViewport(left, right, width, height); + glViewport(x, y, width, height); return 0; } diff --git a/Runtime/Scripting/RuntimeScriptGlobals.cpp b/Runtime/Scripting/RuntimeScriptGlobals.cpp index bb3139c..76de265 100644 --- a/Runtime/Scripting/RuntimeScriptGlobals.cpp +++ b/Runtime/Scripting/RuntimeScriptGlobals.cpp @@ -7,9 +7,9 @@ namespace Scripting { globals.setCurrentEvent = "GameLab.Events.Event.SetCurrentEvent"; - globals.guiBeginFrame = "GameLab.Engine.GUI.BeginFrame"; - globals.guiEndFrame = "GameLab.Engine.GUI.EndFrame"; - globals.guiBeginOnGUI = "GameLab.Engine.GUI.BeginOnGUI"; - globals.guiEndOnGUI = "GameLab.Engine.GUI.EndOnGUI"; + globals.guiBeginFrame = "GameLab.Editor.GUI.BeginFrame"; + globals.guiEndFrame = "GameLab.Editor.GUI.EndFrame"; + globals.guiBeginOnGUI = "GameLab.Editor.GUI.BeginOnGUI"; + globals.guiEndOnGUI = "GameLab.Editor.GUI.EndOnGUI"; } } \ No newline at end of file -- cgit v1.1-26-g67d0