window position on startup
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user