From fac5176c3ad0a56db226f700126cd8a265950de2 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:40:19 -0800 Subject: [PATCH 01/10] Move stats panel --- Hazelnut/imgui.ini | 2 +- Hazelnut/src/EditorLayer.cpp | 35 ++++++++++++++++++++--------------- Hazelnut/src/EditorLayer.h | 1 + 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Hazelnut/imgui.ini b/Hazelnut/imgui.ini index f6210ad04..52c3a4637 100644 --- a/Hazelnut/imgui.ini +++ b/Hazelnut/imgui.ini @@ -58,7 +58,7 @@ Collapsed=0 DockId=0x0000000B,0 [Docking][Data] -DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=294,341 Size=1600,876 Split=X Selected=0x995B0CF8 +DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=386,376 Size=1600,876 Split=X Selected=0x995B0CF8 DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=1228,876 Split=X DockNode ID=0x00000001 Parent=0x00000008 SizeRef=370,696 Split=Y Selected=0xC89E3217 DockNode ID=0x00000005 Parent=0x00000001 SizeRef=370,435 Selected=0x9A68760C diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index 454a5d4c6..c5aa9f561 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -246,21 +246,7 @@ namespace Hazel { m_SceneHierarchyPanel.OnImGuiRender(); m_ContentBrowserPanel.OnImGuiRender(); - ImGui::Begin("Stats"); - - std::string name = "None"; - if (m_HoveredEntity) - name = m_HoveredEntity.GetComponent().Tag; - ImGui::Text("Hovered Entity: %s", name.c_str()); - - auto stats = Renderer2D::GetStats(); - ImGui::Text("Renderer2D Stats:"); - ImGui::Text("Draw Calls: %d", stats.DrawCalls); - ImGui::Text("Quads: %d", stats.QuadCount); - ImGui::Text("Vertices: %d", stats.GetTotalVertexCount()); - ImGui::Text("Indices: %d", stats.GetTotalIndexCount()); - - ImGui::End(); + UI_Stats(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); ImGui::Begin("Viewport"); @@ -349,6 +335,25 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_Stats() + { + ImGui::Begin("Stats"); + + std::string name = "None"; + if (m_HoveredEntity) + name = m_HoveredEntity.GetComponent().Tag; + ImGui::Text("Hovered Entity: %s", name.c_str()); + + auto stats = Renderer2D::GetStats(); + ImGui::Text("Renderer2D Stats:"); + ImGui::Text("Draw Calls: %d", stats.DrawCalls); + ImGui::Text("Quads: %d", stats.QuadCount); + ImGui::Text("Vertices: %d", stats.GetTotalVertexCount()); + ImGui::Text("Indices: %d", stats.GetTotalIndexCount()); + + ImGui::End(); + } + void EditorLayer::UI_Toolbar() { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 2)); diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index 35bdd9cb8..02bf5ddeb 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -33,6 +33,7 @@ namespace Hazel { void OnSceneStop(); // UI Panels + void UI_Stats(); void UI_Toolbar(); private: Hazel::OrthographicCameraController m_CameraController; From b48a928dff4337748f06f00c9caf026b32cfce05 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:41:52 -0800 Subject: [PATCH 02/10] Move menu bar --- Hazelnut/src/EditorLayer.cpp | 49 ++++++++++++++++++++---------------- Hazelnut/src/EditorLayer.h | 1 + 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index c5aa9f561..4a582d18b 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -220,28 +220,7 @@ namespace Hazel { style.WindowMinSize.x = minWinSizeX; - if (ImGui::BeginMenuBar()) - { - if (ImGui::BeginMenu("File")) - { - // Disabling fullscreen would allow the window to be moved to the front of other windows, - // which we can't undo at the moment without finer window depth/z control. - //ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1 - if (ImGui::MenuItem("New", "Ctrl+N")) - NewScene(); - - if (ImGui::MenuItem("Open...", "Ctrl+O")) - OpenScene(); - - if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S")) - SaveSceneAs(); - - if (ImGui::MenuItem("Exit")) Application::Get().Close(); - ImGui::EndMenu(); - } - - ImGui::EndMenuBar(); - } + UI_MenuBar(); m_SceneHierarchyPanel.OnImGuiRender(); m_ContentBrowserPanel.OnImGuiRender(); @@ -335,6 +314,32 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_MenuBar() + { + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("File")) + { + // Disabling fullscreen would allow the window to be moved to the front of other windows, + // which we can't undo at the moment without finer window depth/z control. + //ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1 + if (ImGui::MenuItem("New", "Ctrl+N")) + NewScene(); + + if (ImGui::MenuItem("Open...", "Ctrl+O")) + OpenScene(); + + if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S")) + SaveSceneAs(); + + if (ImGui::MenuItem("Exit")) Application::Get().Close(); + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); + } + } + void EditorLayer::UI_Stats() { ImGui::Begin("Stats"); diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index 02bf5ddeb..5b35d0b80 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -33,6 +33,7 @@ namespace Hazel { void OnSceneStop(); // UI Panels + void UI_MenuBar(); void UI_Stats(); void UI_Toolbar(); private: From 0a3d45bb63c59c86881b899dfb10c2be03385662 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:44:37 -0800 Subject: [PATCH 03/10] Move gizmos --- Hazelnut/src/EditorLayer.cpp | 103 ++++++++++++++++++----------------- Hazelnut/src/EditorLayer.h | 1 + 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index 4a582d18b..979fdbc9b 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -255,56 +255,7 @@ namespace Hazel { ImGui::EndDragDropTarget(); } - // Gizmos - Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity(); - if (selectedEntity && m_GizmoType != -1) - { - ImGuizmo::SetOrthographic(false); - ImGuizmo::SetDrawlist(); - - ImGuizmo::SetRect(m_ViewportBounds[0].x, m_ViewportBounds[0].y, m_ViewportBounds[1].x - m_ViewportBounds[0].x, m_ViewportBounds[1].y - m_ViewportBounds[0].y); - - // Camera - - // Runtime camera from entity - // auto cameraEntity = m_ActiveScene->GetPrimaryCameraEntity(); - // const auto& camera = cameraEntity.GetComponent().Camera; - // const glm::mat4& cameraProjection = camera.GetProjection(); - // glm::mat4 cameraView = glm::inverse(cameraEntity.GetComponent().GetTransform()); - - // Editor camera - const glm::mat4& cameraProjection = m_EditorCamera.GetProjection(); - glm::mat4 cameraView = m_EditorCamera.GetViewMatrix(); - - // Entity transform - auto& tc = selectedEntity.GetComponent(); - glm::mat4 transform = tc.GetTransform(); - - // Snapping - bool snap = Input::IsKeyPressed(Key::LeftControl); - float snapValue = 0.5f; // Snap to 0.5m for translation/scale - // Snap to 45 degrees for rotation - if (m_GizmoType == ImGuizmo::OPERATION::ROTATE) - snapValue = 45.0f; - - float snapValues[3] = { snapValue, snapValue, snapValue }; - - ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection), - (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(transform), - nullptr, snap ? snapValues : nullptr); - - if (ImGuizmo::IsUsing()) - { - glm::vec3 translation, rotation, scale; - Math::DecomposeTransform(transform, translation, rotation, scale); - - glm::vec3 deltaRotation = rotation - tc.Rotation; - tc.Translation = translation; - tc.Rotation += deltaRotation; - tc.Scale = scale; - } - } - + UI_Gizmos(); ImGui::End(); ImGui::PopStyleVar(); @@ -387,6 +338,58 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_Gizmos() + { + Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity(); + if (selectedEntity && m_GizmoType != -1) + { + ImGuizmo::SetOrthographic(false); + ImGuizmo::SetDrawlist(); + + ImGuizmo::SetRect(m_ViewportBounds[0].x, m_ViewportBounds[0].y, m_ViewportBounds[1].x - m_ViewportBounds[0].x, m_ViewportBounds[1].y - m_ViewportBounds[0].y); + + // Camera + + // Runtime camera from entity + // auto cameraEntity = m_ActiveScene->GetPrimaryCameraEntity(); + // const auto& camera = cameraEntity.GetComponent().Camera; + // const glm::mat4& cameraProjection = camera.GetProjection(); + // glm::mat4 cameraView = glm::inverse(cameraEntity.GetComponent().GetTransform()); + + // Editor camera + const glm::mat4& cameraProjection = m_EditorCamera.GetProjection(); + glm::mat4 cameraView = m_EditorCamera.GetViewMatrix(); + + // Entity transform + auto& tc = selectedEntity.GetComponent(); + glm::mat4 transform = tc.GetTransform(); + + // Snapping + bool snap = Input::IsKeyPressed(Key::LeftControl); + float snapValue = 0.5f; // Snap to 0.5m for translation/scale + // Snap to 45 degrees for rotation + if (m_GizmoType == ImGuizmo::OPERATION::ROTATE) + snapValue = 45.0f; + + float snapValues[3] = { snapValue, snapValue, snapValue }; + + ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection), + (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(transform), + nullptr, snap ? snapValues : nullptr); + + if (ImGuizmo::IsUsing()) + { + glm::vec3 translation, rotation, scale; + Math::DecomposeTransform(transform, translation, rotation, scale); + + glm::vec3 deltaRotation = rotation - tc.Rotation; + tc.Translation = translation; + tc.Rotation += deltaRotation; + tc.Scale = scale; + } + } + } + void EditorLayer::OnEvent(Event& e) { m_CameraController.OnEvent(e); diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index 5b35d0b80..2118ff757 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -36,6 +36,7 @@ namespace Hazel { void UI_MenuBar(); void UI_Stats(); void UI_Toolbar(); + void UI_Gizmos(); private: Hazel::OrthographicCameraController m_CameraController; From 9f0aa8d71b8947f089f1e6d2df902ee7e8f3d939 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:46:32 -0800 Subject: [PATCH 04/10] Move viewport --- Hazelnut/imgui.ini | 2 +- Hazelnut/src/EditorLayer.cpp | 71 +++++++++++++++++++----------------- Hazelnut/src/EditorLayer.h | 1 + 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Hazelnut/imgui.ini b/Hazelnut/imgui.ini index 52c3a4637..7f276f2f8 100644 --- a/Hazelnut/imgui.ini +++ b/Hazelnut/imgui.ini @@ -58,7 +58,7 @@ Collapsed=0 DockId=0x0000000B,0 [Docking][Data] -DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=386,376 Size=1600,876 Split=X Selected=0x995B0CF8 +DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=719,348 Size=1600,876 Split=X Selected=0x995B0CF8 DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=1228,876 Split=X DockNode ID=0x00000001 Parent=0x00000008 SizeRef=370,696 Split=Y Selected=0xC89E3217 DockNode ID=0x00000005 Parent=0x00000001 SizeRef=370,435 Selected=0x9A68760C diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index 979fdbc9b..06574d77f 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -226,39 +226,8 @@ namespace Hazel { m_ContentBrowserPanel.OnImGuiRender(); UI_Stats(); - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); - ImGui::Begin("Viewport"); - auto viewportMinRegion = ImGui::GetWindowContentRegionMin(); - auto viewportMaxRegion = ImGui::GetWindowContentRegionMax(); - auto viewportOffset = ImGui::GetWindowPos(); - m_ViewportBounds[0] = { viewportMinRegion.x + viewportOffset.x, viewportMinRegion.y + viewportOffset.y }; - m_ViewportBounds[1] = { viewportMaxRegion.x + viewportOffset.x, viewportMaxRegion.y + viewportOffset.y }; - - m_ViewportFocused = ImGui::IsWindowFocused(); - m_ViewportHovered = ImGui::IsWindowHovered(); - Application::Get().GetImGuiLayer()->BlockEvents(!m_ViewportFocused && !m_ViewportHovered); - - ImVec2 viewportPanelSize = ImGui::GetContentRegionAvail(); - m_ViewportSize = { viewportPanelSize.x, viewportPanelSize.y }; - - uint64_t textureID = m_Framebuffer->GetColorAttachmentRendererID(); - ImGui::Image(reinterpret_cast(textureID), ImVec2{ m_ViewportSize.x, m_ViewportSize.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 }); - - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_ITEM")) - { - const wchar_t* path = (const wchar_t*)payload->Data; - OpenScene(std::filesystem::path(g_AssetPath) / path); - } - ImGui::EndDragDropTarget(); - } - - UI_Gizmos(); - - ImGui::End(); - ImGui::PopStyleVar(); + + UI_Viewport(); UI_Toolbar(); @@ -338,6 +307,42 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_Viewport() + { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); + ImGui::Begin("Viewport"); + auto viewportMinRegion = ImGui::GetWindowContentRegionMin(); + auto viewportMaxRegion = ImGui::GetWindowContentRegionMax(); + auto viewportOffset = ImGui::GetWindowPos(); + m_ViewportBounds[0] = { viewportMinRegion.x + viewportOffset.x, viewportMinRegion.y + viewportOffset.y }; + m_ViewportBounds[1] = { viewportMaxRegion.x + viewportOffset.x, viewportMaxRegion.y + viewportOffset.y }; + + m_ViewportFocused = ImGui::IsWindowFocused(); + m_ViewportHovered = ImGui::IsWindowHovered(); + Application::Get().GetImGuiLayer()->BlockEvents(!m_ViewportFocused && !m_ViewportHovered); + + ImVec2 viewportPanelSize = ImGui::GetContentRegionAvail(); + m_ViewportSize = { viewportPanelSize.x, viewportPanelSize.y }; + + uint64_t textureID = m_Framebuffer->GetColorAttachmentRendererID(); + ImGui::Image(reinterpret_cast(textureID), ImVec2{ m_ViewportSize.x, m_ViewportSize.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 }); + + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_ITEM")) + { + const wchar_t* path = (const wchar_t*)payload->Data; + OpenScene(std::filesystem::path(g_AssetPath) / path); + } + ImGui::EndDragDropTarget(); + } + + UI_Gizmos(); + + ImGui::End(); + ImGui::PopStyleVar(); + } + void EditorLayer::UI_Gizmos() { Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity(); diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index 2118ff757..8cb812790 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -36,6 +36,7 @@ namespace Hazel { void UI_MenuBar(); void UI_Stats(); void UI_Toolbar(); + void UI_Viewport(); void UI_Gizmos(); private: Hazel::OrthographicCameraController m_CameraController; From cbe55705e3647a539f5bfb97ba75d764973ce558 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:48:12 -0800 Subject: [PATCH 05/10] Move child panels --- Hazelnut/src/EditorLayer.cpp | 9 +++++++-- Hazelnut/src/EditorLayer.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index 06574d77f..45cf226d0 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -222,8 +222,7 @@ namespace Hazel { UI_MenuBar(); - m_SceneHierarchyPanel.OnImGuiRender(); - m_ContentBrowserPanel.OnImGuiRender(); + UI_ChildPanels(); UI_Stats(); @@ -234,6 +233,12 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_ChildPanels() + { + m_SceneHierarchyPanel.OnImGuiRender(); + m_ContentBrowserPanel.OnImGuiRender(); + } + void EditorLayer::UI_MenuBar() { if (ImGui::BeginMenuBar()) diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index 8cb812790..ba73e3460 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -33,6 +33,7 @@ namespace Hazel { void OnSceneStop(); // UI Panels + void UI_ChildPanels(); void UI_MenuBar(); void UI_Stats(); void UI_Toolbar(); From eb0af5b2afa3646e781b2c69533faac1b4dd9972 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:52:45 -0800 Subject: [PATCH 06/10] Revert imgui ini --- Hazelnut/imgui.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hazelnut/imgui.ini b/Hazelnut/imgui.ini index 7f276f2f8..f6210ad04 100644 --- a/Hazelnut/imgui.ini +++ b/Hazelnut/imgui.ini @@ -58,7 +58,7 @@ Collapsed=0 DockId=0x0000000B,0 [Docking][Data] -DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=719,348 Size=1600,876 Split=X Selected=0x995B0CF8 +DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=294,341 Size=1600,876 Split=X Selected=0x995B0CF8 DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=1228,876 Split=X DockNode ID=0x00000001 Parent=0x00000008 SizeRef=370,696 Split=Y Selected=0xC89E3217 DockNode ID=0x00000005 Parent=0x00000001 SizeRef=370,435 Selected=0x9A68760C From e1b41374c64185bef072f67240e5a91b96d323d2 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:53:41 -0800 Subject: [PATCH 07/10] Reorder methods --- Hazelnut/src/EditorLayer.cpp | 64 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index 45cf226d0..e793ff4fb 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -220,15 +220,11 @@ namespace Hazel { style.WindowMinSize.x = minWinSizeX; + UI_Viewport(); UI_MenuBar(); - + UI_Toolbar(); UI_ChildPanels(); - UI_Stats(); - - UI_Viewport(); - - UI_Toolbar(); ImGui::End(); } @@ -284,34 +280,6 @@ namespace Hazel { ImGui::End(); } - void EditorLayer::UI_Toolbar() - { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 2)); - ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - auto& colors = ImGui::GetStyle().Colors; - const auto& buttonHovered = colors[ImGuiCol_ButtonHovered]; - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(buttonHovered.x, buttonHovered.y, buttonHovered.z, 0.5f)); - const auto& buttonActive = colors[ImGuiCol_ButtonActive]; - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(buttonActive.x, buttonActive.y, buttonActive.z, 0.5f)); - - ImGui::Begin("##toolbar", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); - - float size = ImGui::GetWindowHeight() - 4.0f; - Ref icon = m_SceneState == SceneState::Edit ? m_IconPlay : m_IconStop; - ImGui::SetCursorPosX((ImGui::GetWindowContentRegionMax().x * 0.5f) - (size * 0.5f)); - if (ImGui::ImageButton((ImTextureID)icon->GetRendererID(), ImVec2(size, size), ImVec2(0, 0), ImVec2(1, 1), 0)) - { - if (m_SceneState == SceneState::Edit) - OnScenePlay(); - else if (m_SceneState == SceneState::Play) - OnSceneStop(); - } - ImGui::PopStyleVar(2); - ImGui::PopStyleColor(3); - ImGui::End(); - } - void EditorLayer::UI_Viewport() { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); @@ -400,6 +368,34 @@ namespace Hazel { } } + void EditorLayer::UI_Toolbar() + { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 2)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0)); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + auto& colors = ImGui::GetStyle().Colors; + const auto& buttonHovered = colors[ImGuiCol_ButtonHovered]; + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(buttonHovered.x, buttonHovered.y, buttonHovered.z, 0.5f)); + const auto& buttonActive = colors[ImGuiCol_ButtonActive]; + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(buttonActive.x, buttonActive.y, buttonActive.z, 0.5f)); + + ImGui::Begin("##toolbar", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); + + float size = ImGui::GetWindowHeight() - 4.0f; + Ref icon = m_SceneState == SceneState::Edit ? m_IconPlay : m_IconStop; + ImGui::SetCursorPosX((ImGui::GetWindowContentRegionMax().x * 0.5f) - (size * 0.5f)); + if (ImGui::ImageButton((ImTextureID)icon->GetRendererID(), ImVec2(size, size), ImVec2(0, 0), ImVec2(1, 1), 0)) + { + if (m_SceneState == SceneState::Edit) + OnScenePlay(); + else if (m_SceneState == SceneState::Play) + OnSceneStop(); + } + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(3); + ImGui::End(); + } + void EditorLayer::OnEvent(Event& e) { m_CameraController.OnEvent(e); From e2f5ece4cf7c78e176d7dc52a37f57f01a9fc576 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Mon, 27 Dec 2021 12:54:31 -0800 Subject: [PATCH 08/10] Update EditorLayer.cpp --- Hazelnut/src/EditorLayer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index e793ff4fb..e4cb6d414 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -229,12 +229,6 @@ namespace Hazel { ImGui::End(); } - void EditorLayer::UI_ChildPanels() - { - m_SceneHierarchyPanel.OnImGuiRender(); - m_ContentBrowserPanel.OnImGuiRender(); - } - void EditorLayer::UI_MenuBar() { if (ImGui::BeginMenuBar()) @@ -261,6 +255,12 @@ namespace Hazel { } } + void EditorLayer::UI_ChildPanels() + { + m_SceneHierarchyPanel.OnImGuiRender(); + m_ContentBrowserPanel.OnImGuiRender(); + } + void EditorLayer::UI_Stats() { ImGui::Begin("Stats"); From 829c1ac6c8f25cfde06b12f0c2899fe022321b88 Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Sat, 30 Jul 2022 15:34:01 -0700 Subject: [PATCH 09/10] Update EditorLayer.cpp --- Hazelnut/src/EditorLayer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Hazelnut/src/EditorLayer.cpp b/Hazelnut/src/EditorLayer.cpp index b21b8f8ac..87fad49a6 100644 --- a/Hazelnut/src/EditorLayer.cpp +++ b/Hazelnut/src/EditorLayer.cpp @@ -241,6 +241,13 @@ namespace Hazel { ImGui::End(); } + void EditorLayer::UI_Settings() + { + ImGui::Begin("Settings"); + ImGui::Checkbox("Show physics colliders", &m_ShowPhysicsColliders); + ImGui::End(); + } + void EditorLayer::UI_Viewport() { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); @@ -376,13 +383,6 @@ namespace Hazel { ImGui::End(); } - void EditorLayer::UI_Settings() - { - ImGui::Begin("Settings"); - ImGui::Checkbox("Show physics colliders", &m_ShowPhysicsColliders); - ImGui::End(); - } - void EditorLayer::OnEvent(Event& e) { m_CameraController.OnEvent(e); From 9e7f1d28be2778f30076c3bd2aae5c5244de652a Mon Sep 17 00:00:00 2001 From: Ben Cooper Date: Sat, 30 Jul 2022 15:35:15 -0700 Subject: [PATCH 10/10] Update EditorLayer.h --- Hazelnut/src/EditorLayer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Hazelnut/src/EditorLayer.h b/Hazelnut/src/EditorLayer.h index f5c5bfe80..3954bb047 100644 --- a/Hazelnut/src/EditorLayer.h +++ b/Hazelnut/src/EditorLayer.h @@ -45,6 +45,7 @@ namespace Hazel { void UI_MenuBar(); void UI_Stats(); void UI_Toolbar(); + void UI_Settings(); void UI_Viewport(); void UI_Gizmos(); private: