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();

View File

@@ -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;

View File

@@ -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);
} */
}
}

View File

@@ -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}")