summaryrefslogtreecommitdiff
path: root/Data/Libraries
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-20 20:29:08 +0800
committerchai <chaifix@163.com>2021-11-20 20:29:08 +0800
commit0944b2f95b9971d62f35b9dcc38d28a27e278249 (patch)
tree3cd71eff172b394655bf69bf23ec3eb6eb471256 /Data/Libraries
parentbb452bba78dc1870d6316b383180472fe3a8a06a (diff)
* mv gui to editor
Diffstat (limited to 'Data/Libraries')
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/GUIState.lua23
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/IMGUI.lua113
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/init.lua4
-rw-r--r--Data/Libraries/GameLab/Editor/Window/GUIWindow.lua11
-rw-r--r--Data/Libraries/GameLab/Editor/Window/SplitWindow.lua3
5 files changed, 150 insertions, 4 deletions
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")