From a36a3ffb476313c6a09e4ad14d9b42c10295a4f3 Mon Sep 17 00:00:00 2001 From: Mitch Andrews Date: Fri, 1 Mar 2024 07:24:10 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Making=20a=20Tool=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/Tool/Source/Tool.cpp | 188 ++++++++++++++++++++++++++++++++ Modules/Tool/Source/Tool.h | 36 ++++++ Tools/HUB/MitchHub.sharpmake.cs | 3 + Tools/HUB/Source/MitchHub.cpp | 179 ++++++------------------------ Tools/HUB/Source/MitchHub.h | 38 +++---- Tools/HUB/Source/main.cpp | 76 +------------ 6 files changed, 282 insertions(+), 238 deletions(-) create mode 100644 Modules/Tool/Source/Tool.cpp create mode 100644 Modules/Tool/Source/Tool.h diff --git a/Modules/Tool/Source/Tool.cpp b/Modules/Tool/Source/Tool.cpp new file mode 100644 index 00000000..08c99636 --- /dev/null +++ b/Modules/Tool/Source/Tool.cpp @@ -0,0 +1,188 @@ +#include "Tool.h" + +#include + +#include "SDL_video.h" + +#include "Renderer.h" +#include "Math/Vector2.h" +#include "Window/SDLWindow.h" +#include "imgui.h" +#include "UI/Colors.h" +#include "Window/PlatformWindowHooks.h" +#include + +extern bool ImGui_ImplSDL2_InitForMetal( SDL_Window* window ); +extern bool ImGui_ImplSDL2_InitForD3D( SDL_Window* window ); + +Tool::Tool( ToolCreationFlags& inToolCreationFlags ) + : m_toolCreationFlags( inToolCreationFlags ) +{ +} + +void Tool::Start() +{ + if( m_renderer ) + { + return; + } + + m_renderer = new BGFXRenderer(); + + std::function ResizeFunc = [this]( const Vector2& NewSize ) + { + if( m_renderer ) + { + m_renderer->WindowResized( NewSize ); + } + }; + + m_window = new SDLWindow( "ME HUB", ResizeFunc, 500, 300, Vector2( 1280, 720 ) ); + m_window->SetBorderless( m_toolCreationFlags.isBorderless ); + ResizeFunc( Vector2( 1280, 720 ) ); + RendererCreationSettings set; + set.WindowPtr = m_window->GetWindowPtr(); + set.InitAssets = false; + m_renderer->Create( set ); + +#if USING( ME_PLATFORM_WIN64 ) + ImGui_ImplSDL2_InitForD3D( static_cast( m_window )->WindowHandle ); +#endif +#if USING( ME_PLATFORM_MACOS ) + ImGui_ImplSDL2_InitForMetal( static_cast( m_window )->WindowHandle ); +#endif + + + ImGuiIO& io = ImGui::GetIO(); (void)io; + Path EngineConfigFilePath = Path( ".tmp/hub-imgui.cfg" ); + io.IniFilename = EngineConfigFilePath.FullPath.c_str(); + + io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_RendererHasViewports; + + { + ImVec4* colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Text] = COLOR_TEXT; + colors[ImGuiCol_TextDisabled] = ImVec4( 0.50f, 0.50f, 0.50f, 1.00f ); + colors[ImGuiCol_WindowBg] = COLOR_FOREGROUND; + colors[ImGuiCol_ChildBg] = ImVec4( 1.00f, 1.00f, 1.00f, 0.00f ); + colors[ImGuiCol_PopupBg] = ImVec4( 0.08f, 0.08f, 0.08f, 0.94f ); + colors[ImGuiCol_Border] = ImVec4( 0.43f, 0.43f, 0.50f, 0.50f ); + colors[ImGuiCol_BorderShadow] = ImVec4( 0.00f, 0.00f, 0.00f, 0.00f ); + colors[ImGuiCol_FrameBg] = COLOR_DROPDOWN; + colors[ImGuiCol_FrameBgHovered] = ImVec4( 0.40f, 0.40f, 0.40f, 0.40f ); + colors[ImGuiCol_FrameBgActive] = ImVec4( 0.18f, 0.18f, 0.18f, 0.67f ); + colors[ImGuiCol_TitleBg] = COLOR_BACKGROUND_BORDER; + colors[ImGuiCol_TitleBgActive] = COLOR_BACKGROUND_BORDER; + colors[ImGuiCol_TitleBgCollapsed] = ImVec4( 0.00f, 0.00f, 0.00f, 0.51f ); + colors[ImGuiCol_MenuBarBg] = COLOR_FOREGROUND; + colors[ImGuiCol_ScrollbarBg] = COLOR_FOREGROUND; + colors[ImGuiCol_ScrollbarGrab] = COLOR_WHITE_25; + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4( 0.41f, 0.41f, 0.41f, 1.00f ); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4( 0.51f, 0.51f, 0.51f, 1.00f ); + colors[ImGuiCol_CheckMark] = ImVec4( 0.94f, 0.94f, 0.94f, 1.00f ); + colors[ImGuiCol_SliderGrab] = ImVec4( 0.51f, 0.51f, 0.51f, 1.00f ); + colors[ImGuiCol_SliderGrabActive] = ImVec4( 0.86f, 0.86f, 0.86f, 1.00f ); + colors[ImGuiCol_Button] = { 0.220f, 0.220f, 0.220f, 0.25f }; + colors[ImGuiCol_ButtonHovered] = COLOR_PRIMARY_HOVER; + colors[ImGuiCol_ButtonActive] = COLOR_PRIMARY_PRESS; + colors[ImGuiCol_Header] = COLOR_WHITE_25; + colors[ImGuiCol_HeaderHovered] = COLOR_PRIMARY_HOVER; + colors[ImGuiCol_HeaderActive] = COLOR_PRIMARY_PRESS; + colors[ImGuiCol_Separator] = COLOR_BACKGROUND_BORDER; + colors[ImGuiCol_SeparatorHovered] = COLOR_PRIMARY_HOVER; + colors[ImGuiCol_SeparatorActive] = COLOR_PRIMARY_PRESS; + colors[ImGuiCol_ResizeGrip] = ImVec4( 0.91f, 0.91f, 0.91f, 0.25f ); + colors[ImGuiCol_ResizeGripHovered] = ImVec4( 0.81f, 0.81f, 0.81f, 0.67f ); + colors[ImGuiCol_ResizeGripActive] = ImVec4( 0.46f, 0.46f, 0.46f, 0.95f ); + colors[ImGuiCol_PlotLines] = ImVec4( 0.61f, 0.61f, 0.61f, 1.00f ); + colors[ImGuiCol_PlotLinesHovered] = ImVec4( 1.00f, 0.43f, 0.35f, 1.00f ); + colors[ImGuiCol_PlotHistogram] = ImVec4( 0.73f, 0.60f, 0.15f, 1.00f ); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4( 1.00f, 0.60f, 0.00f, 1.00f ); + colors[ImGuiCol_TextSelectedBg] = ImVec4( 0.87f, 0.87f, 0.87f, 0.35f ); + //colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); + colors[ImGuiCol_DragDropTarget] = ImVec4( 1.00f, 1.00f, 0.00f, 0.90f ); + colors[ImGuiCol_NavHighlight] = ImVec4( 0.60f, 0.60f, 0.60f, 1.00f ); + colors[ImGuiCol_NavWindowingHighlight] = ImVec4( 1.00f, 1.00f, 1.00f, 0.70f ); + colors[ImGuiCol_Tab] = COLOR_FOREGROUND; + colors[ImGuiCol_TabHovered] = COLOR_PRIMARY_HOVER; + colors[ImGuiCol_TabActive] = COLOR_PRIMARY; + colors[ImGuiCol_TabUnfocused] = COLOR_TITLE; + colors[ImGuiCol_TabUnfocusedActive] = COLOR_FOREGROUND; + colors[ImGuiCol_TableHeaderBg] = COLOR_HEADER; + colors[ImGuiCol_TableRowBg] = COLOR_TITLE; + colors[ImGuiCol_TableRowBgAlt] = COLOR_RECESSED; + } + + // Hooking into ImGui + { + ImGui::InitHooks( m_window, m_renderer->GetImGuiRenderer() ); + } + + /*{ + ProjectEntry p; + p.BackgroundImage = ResourceCache::GetInstance().Get(Path("fl.png")); + p.TitleImage = logo; + p.Name = "Fruit Loops"; + Cache.Projects.push_back(p); + } + + { + ProjectEntry p; + p.BackgroundImage = ResourceCache::GetInstance().Get(Path("run.png")); + p.TitleImage = logo; + p.Name = "Fruit Loops: Secret Department"; + Cache.Projects.push_back(p); + }*/ + + // Setup the borderless window + { + auto cb = [this]( const Vector2& pos ) -> std::optional + { + if( pos > TitleBarDragPosition && pos < TitleBarDragPosition + TitleBarDragSize ) + { + return SDL_HitTestResult::SDL_HITTEST_DRAGGABLE; + } + + return std::nullopt; + }; + m_window->SetBorderless( m_toolCreationFlags.isBorderless ); + m_window->SetCustomDragCallback( cb ); + } + + OnStart(); + + Run(); +} + +void Tool::Run() +{ + while( !m_window->ShouldClose() ) + { + m_window->ParseMessageQueue(); + + m_input.Update(); + ImGuiIO& io = ImGui::GetIO(); + + Vector2 mousePos = m_input.GetMousePosition(); + if( io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable ) + { + // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor) + mousePos = m_input.GetGlobalMousePosition(); + } + + m_renderer->BeginFrame( mousePos, ( m_input.IsMouseButtonDown( MouseButton::Left ) ? 0x01 : 0 ) + | ( m_input.IsMouseButtonDown( MouseButton::Right ) ? 0x02 : 0 ) + | ( m_input.IsMouseButtonDown( MouseButton::Middle ) ? 0x04 : 0 ) + , (int32_t)m_input.GetMouseScrollOffset().y + , m_window->GetSize() + , -1 + , 255 ); + + OnUpdate(); + + Moonlight::CameraData cam; + m_renderer->Render( cam ); + m_input.PostUpdate(); + } +} + diff --git a/Modules/Tool/Source/Tool.h b/Modules/Tool/Source/Tool.h new file mode 100644 index 00000000..63bf1a93 --- /dev/null +++ b/Modules/Tool/Source/Tool.h @@ -0,0 +1,36 @@ +#pragma once +#include "Engine/Input.h" +#include "Math/Vector2.h" + +class SDLWindow; +class BGFXRenderer; + +struct ToolCreationFlags +{ + bool isBorderless = false; +}; + + +class Tool +{ +public: + Tool() = delete; + Tool( ToolCreationFlags& inToolCreationFlags ); + + void Start(); + + virtual void OnStart() = 0; + + virtual void OnUpdate() = 0; + +private: + void Run(); + +protected: + ToolCreationFlags m_toolCreationFlags; + Input m_input; + SDLWindow* m_window = nullptr; + BGFXRenderer* m_renderer = nullptr; + Vector2 TitleBarDragPosition = { 0.f, 0.f }; + Vector2 TitleBarDragSize = { 0.f, 0.f }; +}; \ No newline at end of file diff --git a/Tools/HUB/MitchHub.sharpmake.cs b/Tools/HUB/MitchHub.sharpmake.cs index cca8653e..627f253c 100644 --- a/Tools/HUB/MitchHub.sharpmake.cs +++ b/Tools/HUB/MitchHub.sharpmake.cs @@ -8,6 +8,8 @@ public MitchHubProject() { Name = "HUB"; SourceRootPath = @"Source"; + SourceFiles.Add(Globals.RootDir + "/Engine/Modules/Tool/Source/Tool.h"); + SourceFiles.Add(Globals.RootDir + "/Engine/Modules/Tool/Source/Tool.cpp"); } public override void ConfigureAll(Project.Configuration conf, CommonTarget target) @@ -17,6 +19,7 @@ public override void ConfigureAll(Project.Configuration conf, CommonTarget targe conf.SolutionFolder = "Tools"; conf.IncludePaths.Add("[project.SourceRootPath]"); + conf.IncludePaths.Add(Globals.RootDir + "/Engine/Modules/Tool/Source/"); conf.TargetPath = Globals.RootDir + "/.build/[target.Name]/"; conf.VcxprojUserFile.LocalDebuggerWorkingDirectory = "[project.SharpmakeCsPath]"; diff --git a/Tools/HUB/Source/MitchHub.cpp b/Tools/HUB/Source/MitchHub.cpp index 40abaa0b..74b6a823 100644 --- a/Tools/HUB/Source/MitchHub.cpp +++ b/Tools/HUB/Source/MitchHub.cpp @@ -1,150 +1,47 @@ #include "MitchHub.h" #include -#include #include #include #include #include "Utils/ImGuiUtils.h" #include -#include - -#include #include #include -#include -#include #include "Utils/PlatformUtils.h" #include "Dementia.h" #include "Utils/HUBUtils.h" #include "Config.h" +#include "Window/SDLWindow.h" + -MitchHub::MitchHub( Input* input, SDLWindow* window, ImGuiRenderer* renderer ) - : m_input( input ) - , m_window( window ) - , m_renderer( renderer ) +MitchHub::MitchHub( ToolCreationFlags& inToolCreationFlags ) + : Tool( inToolCreationFlags ) { - //ImGui Init - { - ImGuiIO& io = ImGui::GetIO(); (void)io; - Path EngineConfigFilePath = Path( ".tmp/hub-imgui.cfg" ); - io.IniFilename = EngineConfigFilePath.FullPath.c_str(); - //io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - - io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_RendererHasViewports; - - logo = ResourceCache::GetInstance().Get( Path( "Assets/LOGO.png" ) ); - closeIcon = ResourceCache::GetInstance().Get( Path( "Assets/Close.png" ) ); - minimizeIcon = ResourceCache::GetInstance().Get( Path( "Assets/Minimize.png" ) ); - vsIcon = ResourceCache::GetInstance().Get( Path( "Assets/VS.png" ) ); - genIcon = ResourceCache::GetInstance().Get( Path( "Assets/GEN.png" ) ); - - // TODO: Fix the HUB packaging - ME_ASSERT_MSG( genIcon || vsIcon || minimizeIcon || closeIcon || logo, "TODO: Missing asset for the HUB, probaly a packaging error" ); - - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - - ImVec4* colors = ImGui::GetStyle().Colors; - colors[ImGuiCol_Text] = COLOR_TEXT; - colors[ImGuiCol_TextDisabled] = ImVec4( 0.50f, 0.50f, 0.50f, 1.00f ); - colors[ImGuiCol_WindowBg] = COLOR_FOREGROUND; - colors[ImGuiCol_ChildBg] = ImVec4( 1.00f, 1.00f, 1.00f, 0.00f ); - colors[ImGuiCol_PopupBg] = ImVec4( 0.08f, 0.08f, 0.08f, 0.94f ); - colors[ImGuiCol_Border] = ImVec4( 0.43f, 0.43f, 0.50f, 0.50f ); - colors[ImGuiCol_BorderShadow] = ImVec4( 0.00f, 0.00f, 0.00f, 0.00f ); - colors[ImGuiCol_FrameBg] = COLOR_DROPDOWN; - colors[ImGuiCol_FrameBgHovered] = ImVec4( 0.40f, 0.40f, 0.40f, 0.40f ); - colors[ImGuiCol_FrameBgActive] = ImVec4( 0.18f, 0.18f, 0.18f, 0.67f ); - colors[ImGuiCol_TitleBg] = COLOR_BACKGROUND_BORDER; - colors[ImGuiCol_TitleBgActive] = COLOR_BACKGROUND_BORDER; - colors[ImGuiCol_TitleBgCollapsed] = ImVec4( 0.00f, 0.00f, 0.00f, 0.51f ); - colors[ImGuiCol_MenuBarBg] = COLOR_FOREGROUND; - colors[ImGuiCol_ScrollbarBg] = COLOR_FOREGROUND; - colors[ImGuiCol_ScrollbarGrab] = COLOR_WHITE_25; - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4( 0.41f, 0.41f, 0.41f, 1.00f ); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4( 0.51f, 0.51f, 0.51f, 1.00f ); - colors[ImGuiCol_CheckMark] = ImVec4( 0.94f, 0.94f, 0.94f, 1.00f ); - colors[ImGuiCol_SliderGrab] = ImVec4( 0.51f, 0.51f, 0.51f, 1.00f ); - colors[ImGuiCol_SliderGrabActive] = ImVec4( 0.86f, 0.86f, 0.86f, 1.00f ); - colors[ImGuiCol_Button] = { 0.220f, 0.220f, 0.220f, 0.25f }; - colors[ImGuiCol_ButtonHovered] = COLOR_PRIMARY_HOVER; - colors[ImGuiCol_ButtonActive] = COLOR_PRIMARY_PRESS; - colors[ImGuiCol_Header] = COLOR_WHITE_25; - colors[ImGuiCol_HeaderHovered] = COLOR_PRIMARY_HOVER; - colors[ImGuiCol_HeaderActive] = COLOR_PRIMARY_PRESS; - colors[ImGuiCol_Separator] = COLOR_BACKGROUND_BORDER; - colors[ImGuiCol_SeparatorHovered] = COLOR_PRIMARY_HOVER; - colors[ImGuiCol_SeparatorActive] = COLOR_PRIMARY_PRESS; - colors[ImGuiCol_ResizeGrip] = ImVec4( 0.91f, 0.91f, 0.91f, 0.25f ); - colors[ImGuiCol_ResizeGripHovered] = ImVec4( 0.81f, 0.81f, 0.81f, 0.67f ); - colors[ImGuiCol_ResizeGripActive] = ImVec4( 0.46f, 0.46f, 0.46f, 0.95f ); - colors[ImGuiCol_PlotLines] = ImVec4( 0.61f, 0.61f, 0.61f, 1.00f ); - colors[ImGuiCol_PlotLinesHovered] = ImVec4( 1.00f, 0.43f, 0.35f, 1.00f ); - colors[ImGuiCol_PlotHistogram] = ImVec4( 0.73f, 0.60f, 0.15f, 1.00f ); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4( 1.00f, 0.60f, 0.00f, 1.00f ); - colors[ImGuiCol_TextSelectedBg] = ImVec4( 0.87f, 0.87f, 0.87f, 0.35f ); - //colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4( 1.00f, 1.00f, 0.00f, 0.90f ); - colors[ImGuiCol_NavHighlight] = ImVec4( 0.60f, 0.60f, 0.60f, 1.00f ); - colors[ImGuiCol_NavWindowingHighlight] = ImVec4( 1.00f, 1.00f, 1.00f, 0.70f ); - colors[ImGuiCol_Tab] = COLOR_FOREGROUND; - colors[ImGuiCol_TabHovered] = COLOR_PRIMARY_HOVER; - colors[ImGuiCol_TabActive] = COLOR_PRIMARY; - colors[ImGuiCol_TabUnfocused] = COLOR_TITLE; - colors[ImGuiCol_TabUnfocusedActive] = COLOR_FOREGROUND; - colors[ImGuiCol_TableHeaderBg] = COLOR_HEADER; - colors[ImGuiCol_TableRowBg] = COLOR_TITLE; - colors[ImGuiCol_TableRowBgAlt] = COLOR_RECESSED; - } +} - // Loading the project cache - { - Cache.Load(); - } - // Hooking into ImGui - { - ImGui::InitHooks( m_window, m_renderer ); - } +void MitchHub::OnStart() +{ + // Load Icons + logo = ResourceCache::GetInstance().Get( Path( "Assets/LOGO.png" ) ); + closeIcon = ResourceCache::GetInstance().Get( Path( "Assets/Close.png" ) ); + minimizeIcon = ResourceCache::GetInstance().Get( Path( "Assets/Minimize.png" ) ); + vsIcon = ResourceCache::GetInstance().Get( Path( "Assets/VS.png" ) ); + genIcon = ResourceCache::GetInstance().Get( Path( "Assets/GEN.png" ) ); - /*{ - ProjectEntry p; - p.BackgroundImage = ResourceCache::GetInstance().Get(Path("fl.png")); - p.TitleImage = logo; - p.Name = "Fruit Loops"; - Cache.Projects.push_back(p); - } + // TODO: Fix the HUB packaging + ME_ASSERT_MSG( genIcon || vsIcon || minimizeIcon || closeIcon || logo, "TODO: Missing asset for the HUB, probaly a packaging error" ); - { - ProjectEntry p; - p.BackgroundImage = ResourceCache::GetInstance().Get(Path("run.png")); - p.TitleImage = logo; - p.Name = "Fruit Loops: Secret Department"; - Cache.Projects.push_back(p); - }*/ - - // Setup the borderless window - { - auto cb = [this]( const Vector2& pos ) -> std::optional - { - if ( pos > TitleBarDragPosition && pos < TitleBarDragPosition + TitleBarDragSize ) - { - return SDL_HitTestResult::SDL_HITTEST_DRAGGABLE; - } - - return std::nullopt; - }; - m_window->SetBorderless( true ); - m_window->SetCustomDragCallback( cb ); - } + // Loading the project cache + Cache.Load(); } -void MitchHub::Draw() +void MitchHub::OnUpdate() { #if USING( ME_PLATFORM_WIN64 ) - if ( m_input->WasKeyPressed( KeyCode::A ) ) + if( m_input.WasKeyPressed( KeyCode::A ) ) { HUB::ShowOpenFilePrompt( m_window->GetWindowPtr() ); } @@ -173,28 +70,28 @@ void MitchHub::Draw() ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, { 0.f, 15.f } ); ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, { 0.f, 10.f } ); - for ( int i = 0; i < Cache.Projects.size(); ++i ) + for( int i = 0; i < Cache.Projects.size(); ++i ) { ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_FramePadding | ( SelectedProjectIndex == i ? ImGuiTreeNodeFlags_Selected : 0 ); node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet std::string name = Cache.Projects[i].Name; - if ( name.empty() ) + if( name.empty() ) { name = Cache.Projects[i].ProjectPath.FullPath.substr( Cache.Projects[i].ProjectPath.FullPath.rfind( '/' ) + 1, Cache.Projects[i].ProjectPath.FullPath.size() ); } - if ( ImGui::TreeNodeEx( (void*)(intptr_t)i, node_flags, name.c_str() ) ) + if( ImGui::TreeNodeEx( (void*)(intptr_t)i, node_flags, name.c_str() ) ) { - if ( ImGui::IsItemClicked() ) + if( ImGui::IsItemClicked() ) { SelectedProjectIndex = i; } } } - if ( ImGui::Button( "Add Project", { -1.f, 0.f } ) ) + if( ImGui::Button( "Add Project", { -1.f, 0.f } ) ) { #if USING( ME_PLATFORM_WIN64 ) Path path = HUB::ShowOpenFilePrompt( m_window->GetWindowPtr() ); - if ( path.Exists ) + if( path.Exists ) { ProjectEntry p; p.ProjectPath = path; @@ -223,15 +120,15 @@ void MitchHub::Draw() IsMetaPanelOpen = !Cache.Projects.empty(); - if ( IsMetaPanelOpen ) + if( IsMetaPanelOpen ) { ImGui::SameLine(); ImGui::Button( "##vsplitter", ImVec2( 4.0f, h ) ); - if ( ImGui::IsItemHovered() ) + if( ImGui::IsItemHovered() ) { ImGui::SetMouseCursor( ImGuiMouseCursor_ResizeEW ); } - if ( ImGui::IsItemActive() ) + if( ImGui::IsItemActive() ) wOffset += ImGui::GetIO().MouseDelta.x; ImGui::SameLine(); @@ -242,7 +139,7 @@ void MitchHub::Draw() float panelWidth = ImGui::GetContentRegionAvail().x; float xPos = 0.f; float yPos = 0.f; - if ( bgTexture ) + if( bgTexture ) { bool contentAreaTaller = ImGui::GetContentRegionAvail().y > panelWidth; float height = bgTexture->mHeight; @@ -253,12 +150,12 @@ void MitchHub::Draw() width *= bestRatio; height *= bestRatio; - if ( panelWidth < width ) + if( panelWidth < width ) { xPos = -( ( width - panelWidth ) / 2.f ); } - if ( ImGui::GetContentRegionAvail().y < height ) + if( ImGui::GetContentRegionAvail().y < height ) { yPos = -( ( height - ImGui::GetContentRegionAvail().y ) / 2.f ); } @@ -269,7 +166,7 @@ void MitchHub::Draw() } auto titleTexture = Cache.GetActiveTitleTexture( SelectedProjectIndex ); - if ( titleTexture ) + if( titleTexture ) { Vector2 size = Mathf::KeepAspect( { titleTexture->mWidth, titleTexture->mHeight }, { 400, 200 } ); @@ -279,7 +176,7 @@ void MitchHub::Draw() ImGui::SetCursorPos( { ImGui::GetWindowWidth() - SystemButtonSize, 0.f } ); ImGui::PushStyleColor( ImGuiCol_Button, { 0.f, 0.f, 0.f, 0.f } ); - if ( ImGui::ImageButton( closeIcon->TexHandle, { SystemButtonSize, SystemButtonSize } ) ) + if( ImGui::ImageButton( closeIcon->TexHandle, { SystemButtonSize, SystemButtonSize } ) ) { m_window->Exit(); } @@ -308,7 +205,7 @@ void MitchHub::Draw() // 55AAFF 81 170 255 ImGui::PushStyleColor( ImGuiCol_Button, { 81.f / 255.f, 170.f / 255.f, 255.f / 255.f, 1.f } ); ImGui::SetCursorPos( { ImGui::GetWindowWidth() - 475.f, ImGui::GetWindowHeight() - 75.f } ); - if ( genIcon && ImGui::ImageButton( genIcon->TexHandle, { 168.f, 36.f } ) ) + if( genIcon && ImGui::ImageButton( genIcon->TexHandle, { 168.f, 36.f } ) ) { PlatformUtils::SystemCall( Path( Cache.Projects[SelectedProjectIndex].ProjectPath.FullPath + std::string( "/Project/GenerateSolution.bat" ) ) ); @@ -331,10 +228,4 @@ void MitchHub::Draw() static bool showDemo = true; ImGui::ShowDemoWindow( &showDemo ); -} - -ImGuiRenderer* MitchHub::GetRenderer() const -{ - return m_renderer; -} - +} \ No newline at end of file diff --git a/Tools/HUB/Source/MitchHub.h b/Tools/HUB/Source/MitchHub.h index bd99c2a4..023fafcb 100644 --- a/Tools/HUB/Source/MitchHub.h +++ b/Tools/HUB/Source/MitchHub.h @@ -1,36 +1,30 @@ #pragma once #include -#include #include "ProjectCache.h" -#include +#include "Tool.h" -class Input; -class SDLWindow; -class ImGuiRenderer; -namespace Moonlight { class Texture; } +namespace Moonlight { + class Texture; +} class MitchHub + : public Tool { public: - MitchHub(Input* input, SDLWindow* window, ImGuiRenderer* renderer); + MitchHub( ToolCreationFlags& inToolCreationFlags ); - void Draw(); - - ImGuiRenderer* GetRenderer() const; + void OnUpdate() final; + + void OnStart() override; private: - Input* m_input = nullptr; - SDLWindow* m_window = nullptr; - ImGuiRenderer* m_renderer = nullptr; - SharedPtr logo; - SharedPtr closeIcon; - SharedPtr minimizeIcon; + SharedPtr logo; + SharedPtr closeIcon; + SharedPtr minimizeIcon; SharedPtr vsIcon; SharedPtr genIcon; - - std::size_t SelectedProjectIndex = 0; - ProjectCache Cache; - Vector2 TitleBarDragPosition = { 0.f, 0.f }; - Vector2 TitleBarDragSize = { 0.f, 0.f }; - const float SystemButtonSize = 30.f; + + std::size_t SelectedProjectIndex = 0; + ProjectCache Cache; + const float SystemButtonSize = 30.f; }; diff --git a/Tools/HUB/Source/main.cpp b/Tools/HUB/Source/main.cpp index 67990a77..57695a1d 100644 --- a/Tools/HUB/Source/main.cpp +++ b/Tools/HUB/Source/main.cpp @@ -1,80 +1,12 @@ #define SDL_MAIN_HANDLED -#include "Window/SDLWindow.h" -#include "Renderer.h" -#include -#include #include "MitchHub.h" -#include -#include -#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE (SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)) -#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5) -#define SDL_HAS_WINDOW_ALPHA SDL_VERSION_ATLEAST(2,0,5) -#define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5) -#define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5) -#define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4) -#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6) - -extern bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); -extern bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); int main(int argc, char** argv) { - BGFXRenderer* Renderer = new BGFXRenderer(); - - std::function ResizeFunc = [Renderer](const Vector2& NewSize) - { - if (Renderer) - { - Renderer->WindowResized(NewSize); - } - }; - - SDLWindow* win = new SDLWindow("ME HUB", ResizeFunc, 500, 300, Vector2(1280, 720)); - win->SetBorderless(true); - ResizeFunc(Vector2(1280, 720)); - RendererCreationSettings set; - set.WindowPtr = win->GetWindowPtr(); - set.InitAssets = false; - Renderer->Create(set); - -#if USING( ME_PLATFORM_WIN64 ) - ImGui_ImplSDL2_InitForD3D(static_cast(win)->WindowHandle); -#endif -#if USING( ME_PLATFORM_MACOS ) - ImGui_ImplSDL2_InitForMetal(static_cast(win)->WindowHandle); -#endif - - Input input; - MitchHub hub(&input, win, Renderer->GetImGuiRenderer()); - - while (!win->ShouldClose()) - { - win->ParseMessageQueue(); - - input.Update(); - ImGuiIO& io = ImGui::GetIO(); - - Vector2 mousePos = input.GetMousePosition(); - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor) - mousePos = input.GetGlobalMousePosition(); - } - - Renderer->BeginFrame(mousePos, (input.IsMouseButtonDown(MouseButton::Left) ? 0x01 : 0) - | (input.IsMouseButtonDown(MouseButton::Right) ? 0x02 : 0) - | (input.IsMouseButtonDown(MouseButton::Middle) ? 0x04 : 0) - , (int32_t)input.GetMouseScrollOffset().y - , win->GetSize() - , -1 - , 255); - - hub.Draw(); - - Moonlight::CameraData cam; - Renderer->Render(cam); - input.PostUpdate(); - } + ToolCreationFlags flags; + flags.isBorderless = true; + MitchHub tool( flags ); + tool.Start(); return 0; }