window can now be resized

This commit is contained in:
2024-06-24 19:53:47 +02:00
parent 08ce815d05
commit f1576a2e69
4 changed files with 37 additions and 27 deletions

View File

@@ -12,7 +12,8 @@
WindowData Application::m_WindowData;
bool Application::m_isRunning = false;
Application::Application(){}
Application::Application()
: m_Renderer(nullptr){}
Application::~Application()
{
@@ -42,7 +43,7 @@ bool Application::Init()
//TODO: add the resizable flag and update the window size with the event system
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI /*| SDL_WINDOW_RESIZABLE*/);
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
m_Window = SDL_CreateWindow(GetWindowData().title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, GetWindowData().width, GetWindowData().height, windowFlags);
if (!m_Window)
@@ -100,16 +101,35 @@ bool Application::Init()
void Application::Run()
{
bool demoWindowShow = true;
bool showOtherWindow = false;
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ImGuiIO& io = ImGui::GetIO();
while (Application::GetRunningState())
while (GetRunningState())
{
SakuraVNE::ProcessEvents();
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
SetRunningState(false);
LOG_INFO("Running state: {0}", GetRunningState());
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(GetSDLWindow()))
{
SetRunningState(false);
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_GetWindowSize(GetSDLWindow(), &GetWindowData().width, &GetWindowData().height);
SetSDLWindowSurface(SDL_GetWindowSurface(GetSDLWindow()));
}
}
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();