15int Window::Height = 0;
20 : WindowName(name),event()
28 SDL_DestroyWindow(SDLWindow);
32 SLEAK_LOG(
"The window has been destroyed");
45 GraphicsAPI = SDL_WINDOW_OPENGL;
47 GraphicsAPI = SDL_WINDOW_VULKAN;
49 if (!SDL_Init(SDL_INIT_VIDEO)) {
50 SLEAK_FATAL(
"Failed to initialize SDL: %{0}" , SDL_GetError());
54 SDLWindow = SDL_CreateWindow(WindowName.c_str(), Width, Height, GraphicsAPI | SDL_WINDOW_RESIZABLE);
57 SLEAK_FATAL(
"Failed to create window! {0} ", SDL_GetError());
61 if (SDL_Surface* icon = SDL_LoadBMP(
"assets/branding/icon.bmp")) {
62 SDL_SetWindowIcon(SDLWindow, icon);
63 SDL_DestroySurface(icon);
66 if(!SDL_ShowWindow(SDLWindow)) {
67 SLEAK_FATAL(
"Failed to show window! {0} ", SDL_GetError());
74 SLEAK_INFO(
"Window has been initialized and created without any errors!");
76 SLEAK_INFO(
"Current used operating system: {0}" , OS);
78 SLEAK_INFO(
"Current used window system: {0}" , WINDOW_SYSTEM);
80 SLEAK_FATAL(
"No window system has been detected! are you sure you use a computer?" , WINDOW_SYSTEM);
87 while (SDL_PollEvent(&event)) {
90 ImGui_ImplSDL3_ProcessEvent(&event);
94 case SDL_EVENT_WINDOW_RESIZED:
96 uint16_t
width =
event.window.data1;
97 uint16_t
height =
event.window.data2;
99 Window::Width =
width;
106 case SDL_EVENT_WINDOW_ENTER_FULLSCREEN:
111 case SDL_EVENT_WINDOW_LEAVE_FULLSCREEN:
124 case SDL_EVENT_KEY_DOWN:
127 bool isRepeat =
event.key.repeat;
133 case SDL_EVENT_KEY_UP:
141 case SDL_EVENT_MOUSE_BUTTON_DOWN:
144 int x =
event.button.x;
145 int y =
event.button.y;
151 case SDL_EVENT_MOUSE_BUTTON_UP:
154 int x =
event.button.x;
155 int y =
event.button.y;
161 case SDL_EVENT_MOUSE_MOTION:
163 int x =
event.motion.x;
164 int y =
event.motion.y;
165 int dx =
event.motion.xrel;
166 int dy =
event.motion.yrel;
172 case SDL_EVENT_MOUSE_WHEEL:
174 int xOffset =
event.wheel.x;
175 int yOffset =
event.wheel.y;
186 if(!SDL_SetWindowFullscreen(SDLWindow,isFullscreen))
188 SLEAK_INFO(
"Successfully changed window state: %s", isFullscreen ?
"Fullscreen is enabled" :
"Fullscreen is disabled");
189 bIsFullScreen = isFullscreen;
192 SLEAK_ERROR(
"Failed to set full screen state! {}",SDL_GetError());
197 SDL_SetWindowRelativeMouseMode(SDLWindow, enabled);
Sleak::Input::MOUSE_CODE MouseCode
Sleak::Input::KEY_CODE KeyCode
static void UnregisterAllEvents()
Drops every handler for every event type.
static RendererType GetRendererType()
void SetRelativeMouseMode(bool enabled)
void SetFullScreen(bool bEnable)
bool InitializeWindow()
Creates the SDL window and picks the graphics API flag for the active renderer.
void Update()
Pumps the SDL event queue, dispatching engine events (resize, input, close, ...).
void Close()
Marks the window for close; actual teardown happens in the destructor.
Root namespace for everything the engine exposes.
void DispatchEvent(Args &&... args)
Constructs a T from args and dispatches it through EventDispatcher.