// IAEngine: 2D Game Engine by IA // Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include #include #include #include #include #include #include #include #include #include namespace ia::iae { STATIC CONSTEXPR PCCHAR VIEW_NAME_ASSET_BROWSER = "AssetBrowser"; STATIC CONSTEXPR PCCHAR VIEW_NAME_ASSET = "Asset"; STATIC CONSTEXPR PCCHAR VIEW_NAME_CONSOLE = "Console"; STATIC CONSTEXPR PCCHAR VIEW_NAME_NODES = "Nodes"; STATIC CONSTEXPR PCCHAR VIEW_NAME_PACKAGE = "Package"; STATIC CONSTEXPR PCCHAR VIEW_NAME_PROPERTIES = "Properties"; STATIC CONSTEXPR PCCHAR VIEW_NAME_SCENE = "SCENE"; EXTERN IVec2 g_windowExtent; IView *UI::s_focusedView{}; TabContainer g_tabContainerB; TabContainer g_tabContainerTL; TabContainer g_tabContainerTM; TabContainer g_tabContainerTR; VOID UI::FocusAssetView() { g_tabContainerTR.ChangeActiveTab(VIEW_NAME_ASSET); } class View_Asset *UI::GetAssetView() { return (View_Asset*)g_tabContainerTR.GetTab(VIEW_NAME_ASSET); } VOID UI::Initialize() { g_tabContainerB.Initialize(); g_tabContainerTL.Initialize(); g_tabContainerTM.Initialize(); g_tabContainerTR.Initialize(); g_tabContainerB.AddTab(VIEW_NAME_ASSET_BROWSER); g_tabContainerB.AddTab(VIEW_NAME_CONSOLE); g_tabContainerTL.AddTab(VIEW_NAME_NODES); g_tabContainerTL.AddTab(VIEW_NAME_PACKAGE); g_tabContainerTM.AddTab(VIEW_NAME_SCENE); g_tabContainerTR.AddTab(VIEW_NAME_PROPERTIES); g_tabContainerTR.AddTab(VIEW_NAME_ASSET); } VOID UI::Terminate() { g_tabContainerB.Terminate(); g_tabContainerTL.Terminate(); g_tabContainerTM.Terminate(); g_tabContainerTR.Terminate(); } VOID UI::Update() { g_tabContainerB.Update(); g_tabContainerTL.Update(); g_tabContainerTM.Update(); g_tabContainerTR.Update(); } VOID UI::ProcessEvent(IN SDL_Event *event) { g_tabContainerB.ProcessEvent(event); g_tabContainerTL.ProcessEvent(event); g_tabContainerTM.ProcessEvent(event); g_tabContainerTR.ProcessEvent(event); } VOID UI::Draw() { DrawMenuBar(); g_tabContainerB.Draw({0.0f, LAYOUT_TOP_MIDDLE_VIEW_EXTENT.y * g_windowExtent.y + MENUBAR_HEIGHT}, {g_windowExtent.x * LAYOUT_BOTTOM_VIEW_EXTENT.x, g_windowExtent.y * LAYOUT_BOTTOM_VIEW_EXTENT.y - MENUBAR_HEIGHT}); g_tabContainerTL.Draw({0.0f, MENUBAR_HEIGHT}, {g_windowExtent.x * LAYOUT_TOP_LEFT_VIEW_EXTENT.x, g_windowExtent.y * LAYOUT_TOP_LEFT_VIEW_EXTENT.y}); g_tabContainerTM.Draw( {g_windowExtent.x * LAYOUT_TOP_LEFT_VIEW_EXTENT.x, MENUBAR_HEIGHT}, {g_windowExtent.x * LAYOUT_TOP_MIDDLE_VIEW_EXTENT.x, g_windowExtent.y * LAYOUT_TOP_MIDDLE_VIEW_EXTENT.y}); g_tabContainerTR.Draw( {g_windowExtent.x * (1.0f - LAYOUT_TOP_RIGHT_VIEW_EXTENT.x), MENUBAR_HEIGHT}, {g_windowExtent.x * LAYOUT_TOP_RIGHT_VIEW_EXTENT.x, g_windowExtent.y * LAYOUT_TOP_RIGHT_VIEW_EXTENT.y}); } VOID UI::DrawMenuBar() { if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("New Scene", nullptr, nullptr)) { } UI::PadY(); if (ImGui::MenuItem("Open Scene", nullptr, nullptr)) { } UI::PadY(); ImGui::Separator(); UI::PadY(); if (ImGui::MenuItem("Exit", nullptr, nullptr)) SDL_Quit(); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); } } VOID UI::PadX(IN FLOAT32 v) { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + v); } VOID UI::PadY(IN FLOAT32 v) { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + v); } VOID UI::AlignCursorLeft(IN CONST ImRect &rect) { ImGui::SetCursorPosX(rect.GetTL().x); } VOID UI::AlignCursorRight(IN CONST ImRect &rect, IN FLOAT32 width) { ImGui::SetCursorPosX(rect.GetWidth() - width); } VOID UI::AlignCursorTop(IN CONST ImRect &rect) { ImGui::SetCursorPosY(rect.AsVec4().y); } VOID UI::AlignCursorBottom(IN CONST ImRect &rect, IN FLOAT32 height) { ImGui::SetCursorPosY(rect.GetHeight() - height); } VOID UI::AlignCursorHCenter(IN CONST ImRect &rect, IN FLOAT32 width) { ImGui::SetCursorPosX((rect.GetWidth() - width) / 2.0f); } VOID UI::AlignCursorVCenter(IN CONST ImRect &rect, IN FLOAT32 height) { ImGui::SetCursorPosY((rect.GetHeight() - height) / 2.0f); } } // namespace ia::iae