From 7876b380da618599511cd68ebaa15a75e63b4f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hatvani=20Tam=C3=A1s?= Date: Mon, 9 Mar 2026 15:26:11 +0100 Subject: [PATCH] window position on startup --- SakuraVNE/src/Application.cpp | 17 ++++++++++++++--- SakuraVNE/src/Application.h | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SakuraVNE/src/Application.cpp b/SakuraVNE/src/Application.cpp index a3674d1..23bdeca 100644 --- a/SakuraVNE/src/Application.cpp +++ b/SakuraVNE/src/Application.cpp @@ -1,7 +1,11 @@ #include "Application.h" #include "Event.h" #include "Log.h" +#include "SDL3/SDL.h" +#include "SDL3/SDL_error.h" #include "SDL3/SDL_events.h" +#include "SDL3/SDL_init.h" +#include "SDL3/SDL_video.h" #include "imgui.h" #include "imgui_impl_sdl3.h" #include "imgui_impl_sdlrenderer3.h" @@ -21,7 +25,7 @@ bool Application::Init() { LOG_INFO("window width: {0}, height: {1}", GetWindowData().width, GetWindowData().height); // Init sdl - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { LOG_ERROR("SDL could not be initialized! {0}", SDL_GetError()); Shutdown(); return false; @@ -32,8 +36,9 @@ bool Application::Init() { #endif // TODO: add the resizable flag and update the window size with the event system - SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE); - m_Window = SDL_CreateWindow(GetWindowData().title, GetWindowData().width, GetWindowData().height, windowFlags); + // SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE); + SDL_WindowFlags flags; + m_Window = SDL_CreateWindow(GetWindowData().title, GetWindowData().width, GetWindowData().height, flags); if (!m_Window) { LOG_ERROR("SDL window could not be created! {0}", SDL_GetError()); @@ -44,6 +49,12 @@ bool Application::Init() { LOG_INFO("SDl window created"); } + if (GetWindowData().pos_x != -1 && GetWindowData().pos_y != -1) { + if (!SDL_SetWindowPosition(m_Window, GetWindowData().pos_x, GetWindowData().pos_y)) { + LOG_ERROR("Failed to set SDL_Window position", SDL_GetError()); + } + } + m_Renderer = SDL_CreateRenderer(m_Window, nullptr); if (!m_Renderer) { LOG_ERROR("Renderer could not be created! {0}", SDL_GetError()); diff --git a/SakuraVNE/src/Application.h b/SakuraVNE/src/Application.h index 3d817aa..1a8e175 100644 --- a/SakuraVNE/src/Application.h +++ b/SakuraVNE/src/Application.h @@ -1,10 +1,12 @@ #pragma once -#include "../../libs/sdl3/include/SDL3/SDL.h" +#include "SDL3/SDL.h" struct WindowData { int width = 1280; int height = 720; + int pos_x = -1; + int pos_y = -1; const char *title = "Sakura Visual Novel Engine"; };