Improved Editor

- Added window docking
- Added MenuBar
- Added scene viewport
- Added closing and reopening for editor windows
This commit is contained in:
Simon Lübeß
2021-09-17 13:05:15 +02:00
parent 45d298b755
commit 0b1ec9a837
5 changed files with 260 additions and 18 deletions
@@ -7,16 +7,18 @@ namespace GlitchyEditor.EditWindows
{
class ComponentEditWindow
{
public const String s_WindowTitle = "Components";
private Editor _editor;
private bool _show = true;
private bool _open = true;
public Editor Editor => _editor;
public bool Show
public bool Open
{
get => _show;
set => _show = value;
get => _open;
set => _open = value;
}
public this(Editor editor)
@@ -26,10 +28,10 @@ namespace GlitchyEditor.EditWindows
public void Show()
{
if(!_show)
if(!_open)
return;
if(!ImGui.Begin("Components"))
if(!ImGui.Begin(s_WindowTitle, &_open, .None))
{
ImGui.End();
return;
@@ -12,19 +12,21 @@ namespace GlitchyEditor.EditWindows
/// A window for viewing and editing the scene hierarchy
class EntityHierarchyWindow
{
public const String s_WindowTitle = "Entity Hierarchy";
private Editor _editor;
/// Buffer for the entity search string.
private char8[64] _entitySearchChars;
private bool _show = true;
private bool _open = true;
public Editor Editor => _editor;
public bool Show
public bool Open
{
get => _show;
set => _show = value;
get => _open;
set => _open = value;
}
public this(Editor editor)
@@ -34,10 +36,10 @@ namespace GlitchyEditor.EditWindows
public void Show()
{
if(!_show)
if(!_open)
return;
if(!ImGui.Begin("Entity Hierarchy", null, .MenuBar))
if(!ImGui.Begin(s_WindowTitle, &_open, .MenuBar))
{
ImGui.End();
return;
@@ -0,0 +1,99 @@
using System;
using ImGui;
using GlitchyEngine.Renderer;
using GlitchyEngine.Math;
using GlitchyEngine;
namespace GlitchyEditor.EditWindows
{
class SceneViewportWindow
{
public const String s_WindowTitle = "Scene";
private bool _open = true;
private Texture2D _texture ~ _?.ReleaseRef();
private bool _hasFocus;
public Event<EventHandler<Vector2>> ViewportSizeChangedEvent ~ _.Dispose();
public bool Open
{
get => _open;
set => _open = value;
}
public bool HasFocus
{
get => _hasFocus;
}
public Texture2D Texture
{
get => _texture;
set
{
if(_texture == value)
return;
_texture?.ReleaseRef();
_texture = value;
_texture?.AddRef();
}
}
public this()
{
}
private ImGui.Vec2 oldViewportSize;
Texture2D _lastTexture;
public void Show()
{
// Hold a reference to the texture until the next frame.
// This is a workaround for the issue that changing the window size will release the texture
_lastTexture?.ReleaseRef();
_lastTexture = _texture;
_lastTexture.AddRef();
if(!_open)
return;
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1));
defer ImGui.PopStyleVar();
if(!ImGui.Begin(s_WindowTitle, &_open, .NoScrollbar))
{
ImGui.End();
return;
}
if(ImGui.IsWindowHovered() && Input.IsMouseButtonPressing(.RightButton))
{
var currentWindow = ImGui.GetCurrentWindow();
ImGui.FocusWindow(currentWindow);
}
_hasFocus = ImGui.IsWindowFocused();
var viewportSize = ImGui.GetContentRegionAvail();
if(_lastTexture != null)
{
ImGui.Image(_lastTexture, viewportSize);
}
ImGui.End();
if(oldViewportSize != viewportSize)
{
ViewportSizeChangedEvent.Invoke(this, *(Vector2*)&viewportSize);
oldViewportSize = viewportSize;
}
}
}
}