|
@@ -21,6 +21,9 @@
|
|
|
# error "SDL2 SDK not found in hl/include/sdl/"
|
|
|
#endif
|
|
|
|
|
|
+#define TWIN _ABSTRACT(sdl_window)
|
|
|
+#define TGL _ABSTRACT(sdl_gl)
|
|
|
+
|
|
|
typedef struct {
|
|
|
int x;
|
|
|
int y;
|
|
@@ -362,6 +365,23 @@ HL_PRIM int HL_NAME(get_screen_height)() {
|
|
|
return e.h;
|
|
|
}
|
|
|
|
|
|
+HL_PRIM int HL_NAME(get_screen_width_of_window)(SDL_Window* win) {
|
|
|
+ SDL_DisplayMode e;
|
|
|
+ SDL_GetCurrentDisplayMode(win != NULL ? SDL_GetWindowDisplayIndex(win) : 0, &e);
|
|
|
+ return e.w;
|
|
|
+}
|
|
|
+
|
|
|
+HL_PRIM int HL_NAME(get_screen_height_of_window)(SDL_Window* win) {
|
|
|
+ SDL_DisplayMode e;
|
|
|
+ SDL_GetCurrentDisplayMode(win != NULL ? SDL_GetWindowDisplayIndex(win) : 0, &e);
|
|
|
+ return e.h;
|
|
|
+}
|
|
|
+
|
|
|
+HL_PRIM int HL_NAME(get_framerate)(SDL_Window* win) {
|
|
|
+ SDL_DisplayMode e;
|
|
|
+ SDL_GetCurrentDisplayMode(win != NULL ? SDL_GetWindowDisplayIndex(win) : 0, &e);
|
|
|
+ return e.refresh_rate;
|
|
|
+}
|
|
|
|
|
|
HL_PRIM void HL_NAME(message_box)(vbyte *title, vbyte *text, bool error) {
|
|
|
hl_blocking(true);
|
|
@@ -412,6 +432,9 @@ DEFINE_PRIM(_VOID, quit, _NO_ARG);
|
|
|
DEFINE_PRIM(_VOID, delay, _I32);
|
|
|
DEFINE_PRIM(_I32, get_screen_width, _NO_ARG);
|
|
|
DEFINE_PRIM(_I32, get_screen_height, _NO_ARG);
|
|
|
+DEFINE_PRIM(_I32, get_screen_width_of_window, TWIN);
|
|
|
+DEFINE_PRIM(_I32, get_screen_height_of_window, TWIN);
|
|
|
+DEFINE_PRIM(_I32, get_framerate, TWIN);
|
|
|
DEFINE_PRIM(_VOID, message_box, _BYTES _BYTES _BOOL);
|
|
|
DEFINE_PRIM(_VOID, set_vsync, _BOOL);
|
|
|
DEFINE_PRIM(_BOOL, detect_win32, _NO_ARG);
|
|
@@ -423,23 +446,22 @@ DEFINE_PRIM(_BOOL, hint_value, _BYTES _BYTES);
|
|
|
// Window
|
|
|
|
|
|
HL_PRIM SDL_Window *HL_NAME(win_create_ex)(int x, int y, int width, int height, int sdlFlags) {
|
|
|
- SDL_Window *w;
|
|
|
// force window to match device resolution on mobile
|
|
|
#ifdef HL_MOBILE
|
|
|
SDL_DisplayMode displayMode;
|
|
|
SDL_GetDesktopDisplayMode(0, &displayMode);
|
|
|
- w = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | sdlFlags);
|
|
|
+ SDL_Window* win = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | sdlFlags);
|
|
|
#else
|
|
|
- w = SDL_CreateWindow("", x, y, width, height, SDL_WINDOW_OPENGL | sdlFlags);
|
|
|
+ SDL_Window* win = SDL_CreateWindow("", x, y, width, height, SDL_WINDOW_OPENGL | sdlFlags);
|
|
|
#endif
|
|
|
# ifdef HL_WIN
|
|
|
// force window to show even if the debugger force process windows to be hidden
|
|
|
- if( (SDL_GetWindowFlags(w) & SDL_WINDOW_INPUT_FOCUS) == 0 ) {
|
|
|
- SDL_HideWindow(w);
|
|
|
- SDL_ShowWindow(w);
|
|
|
+ if( (SDL_GetWindowFlags(win) & SDL_WINDOW_INPUT_FOCUS) == 0 ) {
|
|
|
+ SDL_HideWindow(win);
|
|
|
+ SDL_ShowWindow(win);
|
|
|
}
|
|
|
# endif
|
|
|
- return w;
|
|
|
+ return win;
|
|
|
}
|
|
|
|
|
|
HL_PRIM SDL_Window *HL_NAME(win_create)(int width, int height) {
|
|
@@ -472,7 +494,7 @@ HL_PRIM bool HL_NAME(win_set_fullscreen)(SDL_Window *win, int mode) {
|
|
|
case 0: // WINDOWED
|
|
|
return SDL_SetWindowFullscreen(win, 0) == 0;
|
|
|
case 1: // FULLSCREEN
|
|
|
- return SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0;
|
|
|
+ return SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN) == 0;
|
|
|
case 2: // BORDERLESS
|
|
|
# ifdef _WIN32
|
|
|
{
|
|
@@ -496,12 +518,27 @@ HL_PRIM bool HL_NAME(win_set_fullscreen)(SDL_Window *win, int mode) {
|
|
|
# else
|
|
|
return SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0;
|
|
|
# endif
|
|
|
- case 3:
|
|
|
- return SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN) == 0;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+HL_PRIM bool HL_NAME(win_set_display_mode)(SDL_Window *win, int width, int height, int framerate) {
|
|
|
+ SDL_DisplayMode mode;
|
|
|
+ int display_idx = SDL_GetWindowDisplayIndex(win);
|
|
|
+ for (int i = 0; i < SDL_GetNumDisplayModes(display_idx); i++) {
|
|
|
+ if (SDL_GetDisplayMode(display_idx, i, &mode) == 0) {
|
|
|
+ if (mode.w == width && mode.h == height && mode.refresh_rate == framerate) {
|
|
|
+ return SDL_SetWindowDisplayMode(win, &mode) >= 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+HL_PRIM int HL_NAME(win_display_handle)(SDL_Window *win) {
|
|
|
+ return SDL_GetWindowDisplayIndex(win);
|
|
|
+}
|
|
|
+
|
|
|
HL_PRIM void HL_NAME(win_set_title)(SDL_Window *win, vbyte *title) {
|
|
|
SDL_SetWindowTitle(win, (char*)title);
|
|
|
}
|
|
@@ -592,12 +629,12 @@ HL_PRIM void HL_NAME(win_destroy)(SDL_Window *win, SDL_GLContext gl) {
|
|
|
SDL_GL_DeleteContext(gl);
|
|
|
}
|
|
|
|
|
|
-#define TWIN _ABSTRACT(sdl_window)
|
|
|
-#define TGL _ABSTRACT(sdl_gl)
|
|
|
DEFINE_PRIM(TWIN, win_create_ex, _I32 _I32 _I32 _I32 _I32);
|
|
|
DEFINE_PRIM(TWIN, win_create, _I32 _I32);
|
|
|
DEFINE_PRIM(TGL, win_get_glcontext, TWIN);
|
|
|
DEFINE_PRIM(_BOOL, win_set_fullscreen, TWIN _I32);
|
|
|
+DEFINE_PRIM(_BOOL, win_set_display_mode, TWIN _I32 _I32 _I32);
|
|
|
+DEFINE_PRIM(_I32, win_display_handle, TWIN);
|
|
|
DEFINE_PRIM(_VOID, win_resize, TWIN _I32);
|
|
|
DEFINE_PRIM(_VOID, win_set_title, TWIN _BYTES);
|
|
|
DEFINE_PRIM(_VOID, win_set_position, TWIN _I32 _I32);
|
|
@@ -774,6 +811,58 @@ HL_PRIM char* HL_NAME(get_clipboard_text)() {
|
|
|
return bytes;
|
|
|
}
|
|
|
|
|
|
+HL_PRIM varray* HL_NAME(get_displays)() {
|
|
|
+ int n = SDL_GetNumVideoDisplays();
|
|
|
+ varray* arr = hl_alloc_array(&hlt_dynobj, n);
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
+ vdynamic *obj = (vdynamic*) hl_alloc_dynobj();
|
|
|
+ SDL_Rect rect;
|
|
|
+ SDL_GetDisplayBounds(i, &rect);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("right"), &hlt_i32, rect.x+rect.w);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("bottom"), &hlt_i32, rect.y+rect.h);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("left"), &hlt_i32, rect.x);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("top"), &hlt_i32, rect.y);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("handle"), &hlt_i32, i);
|
|
|
+ const char *name = SDL_GetDisplayName(i);
|
|
|
+ hl_dyn_setp(obj, hl_hash_utf8("name"), &hlt_bytes, hl_copy_bytes(name, (int) strlen(name)+1));
|
|
|
+ hl_aptr(arr, vdynamic*)[i] = obj;
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+}
|
|
|
+
|
|
|
+HL_PRIM varray* HL_NAME(get_display_modes)(int display_id) {
|
|
|
+ int n = SDL_GetNumDisplayModes(display_id);
|
|
|
+ varray* arr = hl_alloc_array(&hlt_dynobj, n);
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
+ SDL_DisplayMode mode;
|
|
|
+ SDL_GetDisplayMode(display_id, i, &mode);
|
|
|
+ vdynamic *obj = (vdynamic*)hl_alloc_dynobj();
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("width"), &hlt_i32, mode.w);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("height"), &hlt_i32, mode.h);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("framerate"), &hlt_i32, mode.refresh_rate);
|
|
|
+ hl_aptr(arr, vdynamic*)[i] = obj;
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+}
|
|
|
+
|
|
|
+HL_PRIM vdynobj* HL_NAME(get_current_display_mode)(int display_id, bool registry) {
|
|
|
+ SDL_DisplayMode mode;
|
|
|
+ int r;
|
|
|
+ if(registry)
|
|
|
+ r = SDL_GetDesktopDisplayMode(display_id, &mode);
|
|
|
+ else
|
|
|
+ r = SDL_GetCurrentDisplayMode(display_id, &mode);
|
|
|
+ if (r < 0) {
|
|
|
+ printf("can't find mode for %d : %d\n", display_id, r);
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ vdynamic* obj = (vdynamic*)hl_alloc_dynobj();
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("width"), &hlt_i32, mode.w);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("height"), &hlt_i32, mode.h);
|
|
|
+ hl_dyn_seti(obj, hl_hash_utf8("framerate"), &hlt_i32, mode.refresh_rate);
|
|
|
+ return (vdynobj*) obj;
|
|
|
+}
|
|
|
+
|
|
|
#define MAX_DEVICES 16
|
|
|
HL_PRIM varray *HL_NAME(get_devices)() {
|
|
|
varray *a = hl_alloc_array(&hlt_bytes, MAX_DEVICES);
|
|
@@ -798,4 +887,7 @@ DEFINE_PRIM(_VOID, free_cursor, _CURSOR);
|
|
|
DEFINE_PRIM(_VOID, set_cursor, _CURSOR);
|
|
|
DEFINE_PRIM(_BOOL, set_clipboard_text, _BYTES);
|
|
|
DEFINE_PRIM(_BYTES, get_clipboard_text, _NO_ARG);
|
|
|
+DEFINE_PRIM(_ARR, get_displays, _NO_ARG);
|
|
|
+DEFINE_PRIM(_ARR, get_display_modes, _I32);
|
|
|
+DEFINE_PRIM(_DYN, get_current_display_mode, _I32 _BOOL);
|
|
|
DEFINE_PRIM(_ARR, get_devices, _NO_ARG);
|