Files
coven/windowing/window.jai
2025-03-22 01:04:15 +01:00

74 lines
1.8 KiB
Plaintext

Window :: struct {
width: u32;
height: u32;
}
WINDOW_SIZE :: 42000;
SDL_Window_Type :: struct {
using #as window : Window;
sdl_window: *SDL_Window;
}
// SDL
#import "SDL";
#load "../imgui/imgui_sdl.jai";
create_window :: (title: string, width: u32, height: u32, fullscreen: bool) -> *Window {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
// Get the display resolution
display_mode : SDL_DisplayMode;
if (SDL_GetDesktopDisplayMode(0, *display_mode) != 0) {
log_error("Could not get display mode! SDL_Error: %\n", SDL_GetError());
return null;
}
screen_width : s32 = xx width;
screen_height : s32 = xx height;
flags := SDL_WINDOW_SHOWN;
if fullscreen {
screen_width = display_mode.w;
screen_height = display_mode.h;
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if width == WINDOW_SIZE {
screen_width = display_mode.w;
}
if height == WINDOW_SIZE {
screen_height = display_mode.h;
}
sdl_window := SDL_CreateWindow(to_c_string(title,, temp), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, flags);
if sdl_window == null {
// In the case that the window could not be made...
log_error("Could not create window: %\n", to_string(SDL_GetError()));
return null;
}
window := New(SDL_Window_Type);
window.width = xx screen_width;
window.height = xx screen_height;
window.sdl_window = sdl_window;
return window;
}
get_hwnd :: (window: *Window) -> HWND {
sdl := cast(*SDL_Window_Type)window;
wm_info : SDL_SysWMinfo;
SDL_GetWindowWMInfo(sdl.sdl_window, *wm_info);
return wm_info.info.win.window;
}
set_show_cursor :: (show: bool) {
SDL_ShowCursor(xx show);
SDL_SetRelativeMouseMode(ifx show then SDL_FALSE else SDL_TRUE);
}