window position on startup

This commit is contained in:
2026-03-09 15:26:11 +01:00
parent 48b42e943e
commit 7876b380da
2 changed files with 17 additions and 4 deletions

View File

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