diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index 5a7b2d4..3f47d27 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -5,32 +5,19 @@ using GlitchyEngine.Math; namespace GlitchyEditor.EditWindows { - class ComponentEditWindow + class ComponentEditWindow : EditorWindow { public const String s_WindowTitle = "Components"; - private Editor _editor; - - private bool _open = true; - public Editor Editor => _editor; - public bool Open - { - get => _open; - set => _open = value; - } - public this(Editor editor) { _editor = editor; } - public void Show() + protected override void InternalShow() { - if(!_open) - return; - if(!ImGui.Begin(s_WindowTitle, &_open, .None)) { ImGui.End(); diff --git a/GlitchyEditor/src/EditWindows/EditorWindow.bf b/GlitchyEditor/src/EditWindows/EditorWindow.bf new file mode 100644 index 0000000..35c724d --- /dev/null +++ b/GlitchyEditor/src/EditWindows/EditorWindow.bf @@ -0,0 +1,31 @@ +namespace GlitchyEditor.EditWindows +{ + abstract class EditorWindow + { + protected Editor _editor; + + protected bool _open = true; + protected bool _hasFocus; + + public bool Open + { + get => _open; + set => _open = value; + } + + public bool HasFocus + { + get => _hasFocus; + } + + public void Show() + { + if(!_open) + return; + + InternalShow(); + } + + protected abstract void InternalShow(); + } +} \ No newline at end of file diff --git a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf index b1e74ca..0ff530c 100644 --- a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf +++ b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf @@ -10,35 +10,22 @@ namespace GlitchyEditor.EditWindows using internal GlitchyEditor; /// A window for viewing and editing the scene hierarchy - class EntityHierarchyWindow + class EntityHierarchyWindow : EditorWindow { public const String s_WindowTitle = "Entity Hierarchy"; - private Editor _editor; - /// Buffer for the entity search string. private char8[64] _entitySearchChars; - private bool _open = true; - public Editor Editor => _editor; - public bool Open - { - get => _open; - set => _open = value; - } - public this(Editor editor) { _editor = editor; } - public void Show() + protected override void InternalShow() { - if(!_open) - return; - if(!ImGui.Begin(s_WindowTitle, &_open, .MenuBar)) { ImGui.End(); diff --git a/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf b/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf index 2aa092d..6e59a63 100644 --- a/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf +++ b/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf @@ -8,32 +8,16 @@ using ImGuizmo; namespace GlitchyEditor.EditWindows { - class SceneViewportWindow + class SceneViewportWindow : EditorWindow { - private Editor _editor; public Camera _camera; public const String s_WindowTitle = "Scene"; - private bool _open = true; - private RenderTarget2D _renderTarget ~ _?.ReleaseRef(); - private bool _hasFocus; - public Event> ViewportSizeChangedEvent ~ _.Dispose(); - public bool Open - { - get => _open; - set => _open = value; - } - - public bool HasFocus - { - get => _hasFocus; - } - public RenderTarget2D RenderTarget { get => _renderTarget; @@ -54,11 +38,8 @@ namespace GlitchyEditor.EditWindows private ImGui.Vec2 oldViewportSize; private bool viewPortChanged; - public void Show() + protected override void InternalShow() { - if(!_open) - return; - ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1)); defer ImGui.PopStyleVar(); @@ -83,8 +64,22 @@ namespace GlitchyEditor.EditWindows ImGui.Image(_renderTarget, viewportSize); } - ImGuizmo.SetDrawlist(); + DrawImGuizmo(viewportSize); + ImGui.End(); + + if(oldViewportSize != viewportSize) + { + ViewportSizeChangedEvent.Invoke(this, (Vector2)viewportSize); + viewPortChanged = true; + oldViewportSize = viewportSize; + } + } + + private void DrawImGuizmo(ImGui.Vec2 viewportSize) + { + ImGuizmo.SetDrawlist(); + var topLeft = ImGui.GetWindowPos(); var cntMin = ImGui.GetWindowContentRegionMin(); @@ -112,15 +107,6 @@ namespace GlitchyEditor.EditWindows transformCmp.LocalTransform = transform; } - - ImGui.End(); - - if(oldViewportSize != viewportSize) - { - ViewportSizeChangedEvent.Invoke(this, (Vector2)viewportSize); - viewPortChanged = true; - oldViewportSize = viewportSize; - } } } }