From fffaa8b0488300908f4351ee112e3a828edb70eb Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Fri, 22 Mar 2024 17:42:01 +0100 Subject: [PATCH] imguiManager remove fullscreen + add speed slider --- enginecustom/Systemclass.cpp | 36 ++++-------------------- enginecustom/applicationclass.cpp | 15 ++-------- enginecustom/applicationclass.h | 9 ++++-- enginecustom/d3dclass.cpp | 46 ------------------------------- enginecustom/d3dclass.h | 1 - enginecustom/imgui.ini | 5 ++-- enginecustom/imguiManager.cpp | 4 +-- enginecustom/imguiManager.h | 4 ++- enginecustom/systemclass.h | 1 - 9 files changed, 21 insertions(+), 100 deletions(-) diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 5011268..75939c4 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -126,7 +126,6 @@ void SystemClass::Run() bool SystemClass::Frame() { bool result; - float value = 0.0f; // Check if the user pressed escape and wants to exit the application. @@ -148,13 +147,9 @@ bool SystemClass::Frame() //ImGui Widget ImGui::Begin("Khaotic Engine", NULL); - bool fullscreen = m_Application->GetFullscreen(); - m_imguiManager->WidgetFullscreenBox(&fullscreen); - if (fullscreen != m_Application->GetFullscreen()) - { - m_Application->SetFullscreen(fullscreen); - m_Application->GetDirect3D()->SetFullscreen(fullscreen); - } + float speed = m_Application->GetSpeed(); + m_imguiManager->WidgetSpeedSlider(&speed); + m_Application->SetSpeed(speed); ImGui::End(); @@ -238,7 +233,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) screenHeight = GetSystemMetrics(SM_CYSCREEN); // Setup the screen settings depending on whether it is running in full screen or in windowed mode. - if (m_Application->GetFullscreen()) + if (FULL_SCREEN) { // If full screen set the screen to maximum size of the users desktop and 32bit. memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); @@ -287,7 +282,7 @@ void SystemClass::ShutdownWindows() ShowCursor(true); // Fix the display settings if leaving full screen mode. - if (m_Application->GetFullscreen()) + if (FULL_SCREEN) { ChangeDisplaySettings(NULL, 0); } @@ -335,25 +330,4 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam) return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam); } } -} - -void SystemClass::SetScreen(bool fullscreen) -{ - if (fullscreen) - { - DEVMODE dmScreenSettings; - memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); - dmScreenSettings.dmSize = sizeof(dmScreenSettings); - dmScreenSettings.dmPelsWidth = (unsigned long)GetSystemMetrics(SM_CXSCREEN); // donne la largeur de l'écran en pixel - dmScreenSettings.dmPelsHeight = (unsigned long)GetSystemMetrics(SM_CYSCREEN); // donne la hauteur de l'écran en pixel - dmScreenSettings.dmBitsPerPel = 32; - dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - - - ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); - } - else - { - ChangeDisplaySettings(NULL, 0); - } } \ No newline at end of file diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 40c7ed8..e940250 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -33,7 +33,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) return false; } - result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, m_fullscreen, SCREEN_DEPTH, SCREEN_NEAR); + result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR); if (!result) { MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK); @@ -131,9 +131,8 @@ bool ApplicationClass::Frame() static float rotation = 0.0f; bool result; - // Update the rotation variable each frame. - rotation -= 0.0174532925f * 0.1f; + rotation -= 0.0174532925f * speed; if (rotation < 0.0f) { rotation += 360.0f; @@ -190,16 +189,6 @@ D3DClass* ApplicationClass::GetDirect3D() return m_Direct3D; } -void ApplicationClass::SetFullscreen(bool fullscreen) -{ - m_fullscreen = fullscreen; -} - -bool ApplicationClass::GetFullscreen() const -{ - return m_fullscreen; -} - int ApplicationClass::GetScreenWidth() const { return GetSystemMetrics(SM_CXSCREEN); diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index cbf87ac..84a476b 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -14,6 +14,7 @@ ///////////// // GLOBALS // ///////////// +const bool FULL_SCREEN = false; const bool VSYNC_ENABLED = true; const float SCREEN_DEPTH = 1000.0f; const float SCREEN_NEAR = 0.3f; @@ -33,11 +34,13 @@ public: bool Initialize(int, int, HWND); void Shutdown(); bool Frame(); - void SetFullscreen(bool fullscreen); - bool GetFullscreen() const; + int GetScreenWidth() const; int GetScreenHeight() const; + float GetSpeed() const { return speed; }; + void SetSpeed(float speed) { this->speed = speed; }; + private: bool Render(float); @@ -46,9 +49,9 @@ private: CameraClass* m_Camera; ModelClass* m_Model; IDXGISwapChain* m_swapChain; - bool m_fullscreen = false; LightShaderClass* m_LightShader; LightClass* m_Light; + float speed = 0.1f; }; #endif diff --git a/enginecustom/d3dclass.cpp b/enginecustom/d3dclass.cpp index 69f861f..84b40ae 100644 --- a/enginecustom/d3dclass.cpp +++ b/enginecustom/d3dclass.cpp @@ -590,52 +590,6 @@ bool D3DClass::RecreateResources() return true; } - -bool D3DClass::SetFullscreen(bool fullscreen) -{ - HRESULT result; - - ReleaseResources(); - - // Definie les options de plein ecran - DXGI_MODE_DESC newScreenSize; - ZeroMemory(&newScreenSize, sizeof(newScreenSize)); - newScreenSize.Width = 1920; - newScreenSize.Height = 1080; - newScreenSize.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - - // Redimensionne la cible - result = m_swapChain->ResizeTarget(&newScreenSize); - if (FAILED(result)) - { - return false; - } - - // Change le mode d'affichage - result = m_swapChain->SetFullscreenState(fullscreen, NULL); - if (FAILED(result)) - { - return false; - } - - // Recréez les ressources - if (!RecreateResources()) - { - return false; - } - - // Informez ImGui du changement de taille de la fenêtre - ImGui::GetIO().DisplaySize = ImVec2((float)newScreenSize.Width, (float)newScreenSize.Height); - - // Libérez les anciens objets de rendu ImGui - ImGui_ImplDX11_InvalidateDeviceObjects(); - - // Recréez les objets de rendu ImGui - ImGui_ImplDX11_CreateDeviceObjects(); - - return true; -} - IDXGISwapChain* D3DClass::GetSwapChain() { return m_swapChain; diff --git a/enginecustom/d3dclass.h b/enginecustom/d3dclass.h index 240cdc7..09a8044 100644 --- a/enginecustom/d3dclass.h +++ b/enginecustom/d3dclass.h @@ -53,7 +53,6 @@ public: void ResetViewport(); void ReleaseResources(); - bool SetFullscreen(bool fullscreen); bool RecreateResources(); private: diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 5325a49..15328a5 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,6 +3,7 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=59,59 -Size=694,353 +Pos=10,10 +Size=694,354 +Collapsed=1 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 95890cc..6cd662f 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -42,7 +42,7 @@ void imguiManager::NewFrame() ImGui::NewFrame(); } -void imguiManager::WidgetFullscreenBox(bool* fullscreen) +void imguiManager::WidgetSpeedSlider(float* speed) { - ImGui::Checkbox("Fullscreen", fullscreen); + ImGui::SliderFloat("Speed", speed, 0.0f, 100.0f); } \ No newline at end of file diff --git a/enginecustom/imguiManager.h b/enginecustom/imguiManager.h index 91362ed..b3ec5d1 100644 --- a/enginecustom/imguiManager.h +++ b/enginecustom/imguiManager.h @@ -17,7 +17,9 @@ public: void Shutdown(); void Render(); void NewFrame(); - void WidgetFullscreenBox(bool* fullscreen); + + // Widgets + void WidgetSpeedSlider(float* speed); private: ImGuiIO* io; diff --git a/enginecustom/systemclass.h b/enginecustom/systemclass.h index 04e9e85..ef53ecb 100644 --- a/enginecustom/systemclass.h +++ b/enginecustom/systemclass.h @@ -16,7 +16,6 @@ public: bool Initialize(); void Shutdown(); void Run(); - void SetScreen(bool fullscreen); LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);