imguiManager
remove fullscreen + add speed slider
This commit is contained in:
parent
a6ea730dc3
commit
fffaa8b048
@ -126,7 +126,6 @@ void SystemClass::Run()
|
|||||||
bool SystemClass::Frame()
|
bool SystemClass::Frame()
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
float value = 0.0f;
|
|
||||||
|
|
||||||
|
|
||||||
// Check if the user pressed escape and wants to exit the application.
|
// Check if the user pressed escape and wants to exit the application.
|
||||||
@ -148,13 +147,9 @@ bool SystemClass::Frame()
|
|||||||
//ImGui Widget
|
//ImGui Widget
|
||||||
ImGui::Begin("Khaotic Engine", NULL);
|
ImGui::Begin("Khaotic Engine", NULL);
|
||||||
|
|
||||||
bool fullscreen = m_Application->GetFullscreen();
|
float speed = m_Application->GetSpeed();
|
||||||
m_imguiManager->WidgetFullscreenBox(&fullscreen);
|
m_imguiManager->WidgetSpeedSlider(&speed);
|
||||||
if (fullscreen != m_Application->GetFullscreen())
|
m_Application->SetSpeed(speed);
|
||||||
{
|
|
||||||
m_Application->SetFullscreen(fullscreen);
|
|
||||||
m_Application->GetDirect3D()->SetFullscreen(fullscreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
@ -238,7 +233,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
|||||||
screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
|
||||||
// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
|
// 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.
|
// If full screen set the screen to maximum size of the users desktop and 32bit.
|
||||||
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
|
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
|
||||||
@ -287,7 +282,7 @@ void SystemClass::ShutdownWindows()
|
|||||||
ShowCursor(true);
|
ShowCursor(true);
|
||||||
|
|
||||||
// Fix the display settings if leaving full screen mode.
|
// Fix the display settings if leaving full screen mode.
|
||||||
if (m_Application->GetFullscreen())
|
if (FULL_SCREEN)
|
||||||
{
|
{
|
||||||
ChangeDisplaySettings(NULL, 0);
|
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);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
return false;
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
|
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
|
||||||
@ -131,9 +131,8 @@ bool ApplicationClass::Frame()
|
|||||||
static float rotation = 0.0f;
|
static float rotation = 0.0f;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Update the rotation variable each frame.
|
// Update the rotation variable each frame.
|
||||||
rotation -= 0.0174532925f * 0.1f;
|
rotation -= 0.0174532925f * speed;
|
||||||
if (rotation < 0.0f)
|
if (rotation < 0.0f)
|
||||||
{
|
{
|
||||||
rotation += 360.0f;
|
rotation += 360.0f;
|
||||||
@ -190,16 +189,6 @@ D3DClass* ApplicationClass::GetDirect3D()
|
|||||||
return m_Direct3D;
|
return m_Direct3D;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationClass::SetFullscreen(bool fullscreen)
|
|
||||||
{
|
|
||||||
m_fullscreen = fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ApplicationClass::GetFullscreen() const
|
|
||||||
{
|
|
||||||
return m_fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ApplicationClass::GetScreenWidth() const
|
int ApplicationClass::GetScreenWidth() const
|
||||||
{
|
{
|
||||||
return GetSystemMetrics(SM_CXSCREEN);
|
return GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
/////////////
|
/////////////
|
||||||
// GLOBALS //
|
// GLOBALS //
|
||||||
/////////////
|
/////////////
|
||||||
|
const bool FULL_SCREEN = false;
|
||||||
const bool VSYNC_ENABLED = true;
|
const bool VSYNC_ENABLED = true;
|
||||||
const float SCREEN_DEPTH = 1000.0f;
|
const float SCREEN_DEPTH = 1000.0f;
|
||||||
const float SCREEN_NEAR = 0.3f;
|
const float SCREEN_NEAR = 0.3f;
|
||||||
@ -33,11 +34,13 @@ public:
|
|||||||
bool Initialize(int, int, HWND);
|
bool Initialize(int, int, HWND);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
bool Frame();
|
bool Frame();
|
||||||
void SetFullscreen(bool fullscreen);
|
|
||||||
bool GetFullscreen() const;
|
|
||||||
int GetScreenWidth() const;
|
int GetScreenWidth() const;
|
||||||
int GetScreenHeight() const;
|
int GetScreenHeight() const;
|
||||||
|
|
||||||
|
float GetSpeed() const { return speed; };
|
||||||
|
void SetSpeed(float speed) { this->speed = speed; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Render(float);
|
bool Render(float);
|
||||||
|
|
||||||
@ -46,9 +49,9 @@ private:
|
|||||||
CameraClass* m_Camera;
|
CameraClass* m_Camera;
|
||||||
ModelClass* m_Model;
|
ModelClass* m_Model;
|
||||||
IDXGISwapChain* m_swapChain;
|
IDXGISwapChain* m_swapChain;
|
||||||
bool m_fullscreen = false;
|
|
||||||
LightShaderClass* m_LightShader;
|
LightShaderClass* m_LightShader;
|
||||||
LightClass* m_Light;
|
LightClass* m_Light;
|
||||||
|
float speed = 0.1f;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -590,52 +590,6 @@ bool D3DClass::RecreateResources()
|
|||||||
return true;
|
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()
|
IDXGISwapChain* D3DClass::GetSwapChain()
|
||||||
{
|
{
|
||||||
return m_swapChain;
|
return m_swapChain;
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
void ResetViewport();
|
void ResetViewport();
|
||||||
|
|
||||||
void ReleaseResources();
|
void ReleaseResources();
|
||||||
bool SetFullscreen(bool fullscreen);
|
|
||||||
bool RecreateResources();
|
bool RecreateResources();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -3,6 +3,7 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=59,59
|
Pos=10,10
|
||||||
Size=694,353
|
Size=694,354
|
||||||
|
Collapsed=1
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void imguiManager::NewFrame()
|
|||||||
ImGui::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);
|
||||||
}
|
}
|
@ -17,7 +17,9 @@ public:
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Render();
|
void Render();
|
||||||
void NewFrame();
|
void NewFrame();
|
||||||
void WidgetFullscreenBox(bool* fullscreen);
|
|
||||||
|
// Widgets
|
||||||
|
void WidgetSpeedSlider(float* speed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImGuiIO* io;
|
ImGuiIO* io;
|
||||||
|
@ -16,7 +16,6 @@ public:
|
|||||||
bool Initialize();
|
bool Initialize();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Run();
|
void Run();
|
||||||
void SetScreen(bool fullscreen);
|
|
||||||
|
|
||||||
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user