From bb452bba78dc1870d6316b383180472fe3a8a06a Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 20 Nov 2021 17:32:55 +0800 Subject: *gui --- .../BuiltIn/Libraries/GameLab/BuiltInResources.lua | 3 - .../BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua | 75 +++++++++++----------- .../Libraries/GameLab/Engine/Rendering/init.lua | 1 + 3 files changed, 37 insertions(+), 42 deletions(-) (limited to 'Data/BuiltIn/Libraries') diff --git a/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua b/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua index 03da57e..26cbbb3 100644 --- a/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua +++ b/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua @@ -18,9 +18,6 @@ local res = {} local loadRes = function() res.shaders = { - ["EditorShape"] = SHADER "Editor-Shape.glsl", - ["EditorText"] = SHADER "Editor-Text.glsl", - ["EditorUI"] = SHADER "Editor-UI.glsl", } res.textures = { diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua index 084cc81..3c99622 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua @@ -2,26 +2,26 @@ local GUI = GameLab.Package("GameLab.Engine.GUI") local find = GameLab.Find -local Res = require "GameLab.BuiltInResources" local EditorGUI = GameLab.Editor.GUI -local Debug = GameLab.Debug -local GUIState = GUI.GUIState -local Event = GameLab.Events.Event -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 -local Vector2 = GameLab.Engine.Math.Vector2 -local Vector4 = GameLab.Engine.Math.Vector4 -local Color = Rendering.Color - -local EditorRes +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 - EditorRes = find "Scripts/EditorResources" -end + editor_res = find "Scripts/EditorResources" +elseif GAMELAB_RUNNER then +end GUI.BeginOnGUI = function() GUIState.ResetControlID() @@ -52,29 +52,27 @@ GUI.Toggle = function() end GUI.Label = function() - + end -GUI.Box = function(position, color, size) +GUI.Box = function(rect, color) 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) - - Rendering.UseShader(Res.shaders["EditorShape"]) - Rendering.SetMatrix44("gamelab_mat_mvp", ortho) - Rendering.SetVector2("gamelab_ui_position", {0, 0}) - Rendering.SetVector4("gamelab_color", Vector4(0.12, 0.12, 0.12, 1)) - --Rendering.SetTexture("gamelab_main_tex", tex) - --Rendering.DrawUIQuad({0, 0, 200, 200}) - --Rendering.DrawUI9Slicing(1, {25, 25}, {25, 25}, {80, 80}, {400, 30} ) - --GUI.DrawText(_G["default_font"], "你好世界!\nMaterials\nHello,World!\nProject Window Properties", 12) - GUI.Line(Vector2(0, 0), Vector2(100, 100)) + 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 @@ -103,15 +101,14 @@ GUI.HorizontalScrollbar = function() end -GUI.Line = function(from, to) +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 -GUI.BoxFrame = function(topleft, size) - -end - return GUI \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua index daa8bda..ed23b8c 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua @@ -17,6 +17,7 @@ m.SetVector2 = Shader.SetVector2 m.SetVector3 = Shader.SetVector3 m.SetVector4 = Shader.SetVector4 m.SetTexture = Shader.SetTexture +m.SetColor = Shader.SetColor m.UseShader = Shader.Use m.UnuseShader = Shader.Unuse -- cgit v1.1-26-g67d0