window can now be resized
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
WindowData Application::m_WindowData;
|
WindowData Application::m_WindowData;
|
||||||
bool Application::m_isRunning = false;
|
bool Application::m_isRunning = false;
|
||||||
|
|
||||||
Application::Application(){}
|
Application::Application()
|
||||||
|
: m_Renderer(nullptr){}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
@@ -42,7 +43,7 @@ bool Application::Init()
|
|||||||
|
|
||||||
|
|
||||||
//TODO: add the resizable flag and update the window size with the event system
|
//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);
|
m_Window = SDL_CreateWindow(GetWindowData().title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, GetWindowData().width, GetWindowData().height, windowFlags);
|
||||||
|
|
||||||
if (!m_Window)
|
if (!m_Window)
|
||||||
@@ -100,16 +101,35 @@ bool Application::Init()
|
|||||||
|
|
||||||
void Application::Run()
|
void Application::Run()
|
||||||
{
|
{
|
||||||
|
|
||||||
bool demoWindowShow = true;
|
bool demoWindowShow = true;
|
||||||
bool showOtherWindow = false;
|
bool showOtherWindow = false;
|
||||||
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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_ImplSDLRenderer2_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
struct WindowData{
|
struct WindowData {
|
||||||
int width = 800;
|
int width = 1280;
|
||||||
int height = 600;
|
int height = 720;
|
||||||
const char* title = "Sakura Visual Novel Engine";
|
const char* title = "Sakura Visual Novel Engine";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,20 +13,22 @@ class Application
|
|||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
~Application();
|
~Application();
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void Run();
|
void Run();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
static inline WindowData& GetWindowData(){ return m_WindowData; }
|
static inline WindowData& GetWindowData() { return m_WindowData; }
|
||||||
//static inline SDL_Window* GetWindow() { return m_Window; }
|
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 bool& GetRunningState() { return m_isRunning; }
|
||||||
static void SetRunningState(bool isRunning) { m_isRunning = isRunning; }
|
static void SetRunningState(bool isRunning) { m_isRunning = isRunning; }
|
||||||
private:
|
private:
|
||||||
SDL_Window* m_Window;
|
SDL_Window* m_Window;
|
||||||
SDL_Renderer* m_Renderer;
|
|
||||||
SDL_Surface* m_Surface;
|
SDL_Surface* m_Surface;
|
||||||
|
SDL_Renderer* m_Renderer;
|
||||||
|
|
||||||
static WindowData m_WindowData;
|
static WindowData m_WindowData;
|
||||||
|
|
||||||
|
|||||||
@@ -5,19 +5,5 @@
|
|||||||
|
|
||||||
void SakuraVNE::ProcessEvents()
|
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);
|
|
||||||
} */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ project "SakuraVNE" --project under solution
|
|||||||
language "C++"
|
language "C++"
|
||||||
cppdialect "C++20"
|
cppdialect "C++20"
|
||||||
|
|
||||||
|
ignoredefaultlibraries { "MSVCRT" }
|
||||||
|
|
||||||
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
|
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
|
||||||
objdir ("bin-int/" ..outputdir .. "/%{prj.name}")
|
objdir ("bin-int/" ..outputdir .. "/%{prj.name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user