diff --git a/SakuraVNE/src/Application.cpp b/SakuraVNE/src/Application.cpp index 9f4d848..01c2c92 100644 --- a/SakuraVNE/src/Application.cpp +++ b/SakuraVNE/src/Application.cpp @@ -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(); diff --git a/SakuraVNE/src/Application.h b/SakuraVNE/src/Application.h index a1ec3e4..1751e06 100644 --- a/SakuraVNE/src/Application.h +++ b/SakuraVNE/src/Application.h @@ -2,9 +2,9 @@ #include "SDL.h" -struct WindowData{ - int width = 800; - int height = 600; +struct WindowData { + int width = 1280; + int height = 720; const char* title = "Sakura Visual Novel Engine"; }; @@ -13,20 +13,22 @@ class Application public: Application(); ~Application(); - + bool Init(); void Run(); void Shutdown(); - static inline WindowData& GetWindowData(){ return m_WindowData; } - //static inline SDL_Window* GetWindow() { return m_Window; } + static inline WindowData& GetWindowData() { return m_WindowData; } + inline SDL_Window* GetSDLWindow() { return m_Window; } + inline SDL_Surface* GetSDLWindowSurface() { return m_Surface; } + inline void SetSDLWindowSurface(SDL_Surface* newSurface) { m_Surface = newSurface; } static bool& GetRunningState() { return m_isRunning; } - static void SetRunningState(bool isRunning) { m_isRunning = isRunning; } + static void SetRunningState(bool isRunning) { m_isRunning = isRunning; } private: SDL_Window* m_Window; - SDL_Renderer* m_Renderer; SDL_Surface* m_Surface; + SDL_Renderer* m_Renderer; static WindowData m_WindowData; diff --git a/SakuraVNE/src/Event.cpp b/SakuraVNE/src/Event.cpp index 3d95e72..476e39f 100644 --- a/SakuraVNE/src/Event.cpp +++ b/SakuraVNE/src/Event.cpp @@ -5,19 +5,5 @@ void SakuraVNE::ProcessEvents() { - SDL_Event event; - while (SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - Application::SetRunningState(false); - LOG_INFO("Running state: {0}", Application::GetRunningState()); - } - - /*if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(Application::GetWindow())) - { - Application::SetRunningState(false); - } */ - } } diff --git a/premake5.lua b/premake5.lua index 1ac36c4..9eb3fef 100644 --- a/premake5.lua +++ b/premake5.lua @@ -21,6 +21,8 @@ project "SakuraVNE" --project under solution language "C++" cppdialect "C++20" + ignoredefaultlibraries { "MSVCRT" } + targetdir ("bin/" .. outputdir .. "/%{prj.name}") objdir ("bin-int/" ..outputdir .. "/%{prj.name}")