Initial commit
This commit is contained in:
61
windowing/window.jai
Normal file
61
windowing/window.jai
Normal file
@@ -0,0 +1,61 @@
|
||||
Window :: struct {
|
||||
width: u32;
|
||||
height: u32;
|
||||
}
|
||||
|
||||
SDL_Window_Type :: struct {
|
||||
using #as window : Window;
|
||||
|
||||
sdl_window: *SDL_Window;
|
||||
}
|
||||
|
||||
// SDL
|
||||
#import "SDL";
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user