replace uses of SDL_Window with RenWindow (#1319)

Since Renwindow contains our instance of SDL_Window we can use this
to simplify future logic to create separate window instances
This commit is contained in:
Jan 2023-01-12 00:25:06 +01:00 committed by George Sokianos
parent 8bd6244add
commit 4d35dc4969
3 changed files with 28 additions and 32 deletions

View File

@ -6,7 +6,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "api.h" #include "api.h"
#include "rencache.h" #include "../rencache.h"
#include "../renwindow.h"
#ifdef _WIN32 #ifdef _WIN32
#include <direct.h> #include <direct.h>
#include <windows.h> #include <windows.h>
@ -40,8 +41,7 @@
#endif #endif
#endif #endif
extern SDL_Window *window; extern RenWindow window_renderer;
static const char* button_name(int button) { static const char* button_name(int button) {
switch (button) { switch (button) {
@ -80,7 +80,7 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p
const int controls_width = hit_info->controls_width; const int controls_width = hit_info->controls_width;
int w, h; int w, h;
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window_renderer.window, &w, &h);
if (pt->y < hit_info->title_height && if (pt->y < hit_info->title_height &&
#if RESIZE_FROM_TOP #if RESIZE_FROM_TOP
@ -337,7 +337,7 @@ top:
return 3; return 3;
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window_renderer.window, &w, &h);
lua_pushstring(L, "touchpressed"); lua_pushstring(L, "touchpressed");
lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w));
@ -346,7 +346,7 @@ top:
return 4; return 4;
case SDL_FINGERUP: case SDL_FINGERUP:
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window_renderer.window, &w, &h);
lua_pushstring(L, "touchreleased"); lua_pushstring(L, "touchreleased");
lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w));
@ -362,7 +362,7 @@ top:
e.tfinger.dx += event_plus.tfinger.dx; e.tfinger.dx += event_plus.tfinger.dx;
e.tfinger.dy += event_plus.tfinger.dy; e.tfinger.dy += event_plus.tfinger.dy;
} }
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window_renderer.window, &w, &h);
lua_pushstring(L, "touchmoved"); lua_pushstring(L, "touchmoved");
lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w));
@ -426,7 +426,7 @@ static int f_set_cursor(lua_State *L) {
static int f_set_window_title(lua_State *L) { static int f_set_window_title(lua_State *L) {
const char *title = luaL_checkstring(L, 1); const char *title = luaL_checkstring(L, 1);
SDL_SetWindowTitle(window, title); SDL_SetWindowTitle(window_renderer.window, title);
return 0; return 0;
} }
@ -436,43 +436,39 @@ enum { WIN_NORMAL, WIN_MINIMIZED, WIN_MAXIMIZED, WIN_FULLSCREEN };
static int f_set_window_mode(lua_State *L) { static int f_set_window_mode(lua_State *L) {
int n = luaL_checkoption(L, 1, "normal", window_opts); int n = luaL_checkoption(L, 1, "normal", window_opts);
SDL_SetWindowFullscreen(window, SDL_SetWindowFullscreen(window_renderer.window,
n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
if (n == WIN_NORMAL) if (n == WIN_NORMAL) { SDL_RestoreWindow(window_renderer.window); }
{ if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window_renderer.window); }
ren_resize_window(); if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window_renderer.window); }
SDL_RestoreWindow(window);
}
if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); }
if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window); }
return 0; return 0;
} }
static int f_set_window_bordered(lua_State *L) { static int f_set_window_bordered(lua_State *L) {
int bordered = lua_toboolean(L, 1); int bordered = lua_toboolean(L, 1);
SDL_SetWindowBordered(window, bordered); SDL_SetWindowBordered(window_renderer.window, bordered);
return 0; return 0;
} }
static int f_set_window_hit_test(lua_State *L) { static int f_set_window_hit_test(lua_State *L) {
if (lua_gettop(L) == 0) { if (lua_gettop(L) == 0) {
SDL_SetWindowHitTest(window, NULL, NULL); SDL_SetWindowHitTest(window_renderer.window, NULL, NULL);
return 0; return 0;
} }
window_hit_info->title_height = luaL_checknumber(L, 1); window_hit_info->title_height = luaL_checknumber(L, 1);
window_hit_info->controls_width = luaL_checknumber(L, 2); window_hit_info->controls_width = luaL_checknumber(L, 2);
window_hit_info->resize_border = luaL_checknumber(L, 3); window_hit_info->resize_border = luaL_checknumber(L, 3);
SDL_SetWindowHitTest(window, hit_test, window_hit_info); SDL_SetWindowHitTest(window_renderer.window, hit_test, window_hit_info);
return 0; return 0;
} }
static int f_get_window_size(lua_State *L) { static int f_get_window_size(lua_State *L) {
int x, y, w, h; int x, y, w, h;
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window_renderer.window, &w, &h);
SDL_GetWindowPosition(window, &x, &y); SDL_GetWindowPosition(window_renderer.window, &x, &y);
lua_pushinteger(L, w); lua_pushinteger(L, w);
lua_pushinteger(L, h); lua_pushinteger(L, h);
lua_pushinteger(L, x); lua_pushinteger(L, x);
@ -486,22 +482,22 @@ static int f_set_window_size(lua_State *L) {
double h = luaL_checknumber(L, 2); double h = luaL_checknumber(L, 2);
double x = luaL_checknumber(L, 3); double x = luaL_checknumber(L, 3);
double y = luaL_checknumber(L, 4); double y = luaL_checknumber(L, 4);
SDL_SetWindowSize(window, w, h); SDL_SetWindowSize(window_renderer.window, w, h);
SDL_SetWindowPosition(window, x, y); SDL_SetWindowPosition(window_renderer.window, x, y);
ren_resize_window(); ren_resize_window();
return 0; return 0;
} }
static int f_window_has_focus(lua_State *L) { static int f_window_has_focus(lua_State *L) {
unsigned flags = SDL_GetWindowFlags(window); unsigned flags = SDL_GetWindowFlags(window_renderer.window);
lua_pushboolean(L, flags & SDL_WINDOW_INPUT_FOCUS); lua_pushboolean(L, flags & SDL_WINDOW_INPUT_FOCUS);
return 1; return 1;
} }
static int f_get_window_mode(lua_State *L) { static int f_get_window_mode(lua_State *L) {
unsigned flags = SDL_GetWindowFlags(window); unsigned flags = SDL_GetWindowFlags(window_renderer.window);
if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) { if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
lua_pushstring(L, "fullscreen"); lua_pushstring(L, "fullscreen");
} else if (flags & SDL_WINDOW_MINIMIZED) { } else if (flags & SDL_WINDOW_MINIMIZED) {
@ -539,8 +535,8 @@ static int f_raise_window(lua_State *L) {
to allow the window to be focused. Also on wayland the raise window event to allow the window to be focused. Also on wayland the raise window event
may not always be obeyed. may not always be obeyed.
*/ */
SDL_SetWindowInputFocus(window); SDL_SetWindowInputFocus(window_renderer.window);
SDL_RaiseWindow(window); SDL_RaiseWindow(window_renderer.window);
return 0; return 0;
} }
@ -920,7 +916,7 @@ static int f_fuzzy_match(lua_State *L) {
static int f_set_window_opacity(lua_State *L) { static int f_set_window_opacity(lua_State *L) {
double n = luaL_checknumber(L, 1); double n = luaL_checknumber(L, 1);
int r = SDL_SetWindowOpacity(window, n); int r = SDL_SetWindowOpacity(window_renderer.window, n);
lua_pushboolean(L, r > -1); lua_pushboolean(L, r > -1);
return 1; return 1;
} }

View File

@ -32,7 +32,7 @@
#endif #endif
SDL_Window *window; static SDL_Window *window;
static double get_scale(void) { static double get_scale(void) {
#ifndef __APPLE__ #ifndef __APPLE__

View File

@ -20,7 +20,7 @@
#define MAX_LOADABLE_GLYPHSETS 1024 #define MAX_LOADABLE_GLYPHSETS 1024
#define SUBPIXEL_BITMAPS_CACHED 3 #define SUBPIXEL_BITMAPS_CACHED 3
static RenWindow window_renderer = {0}; RenWindow window_renderer = {0};
static FT_Library library; static FT_Library library;
// draw_rect_surface is used as a 1x1 surface to simplify ren_draw_rect with blending // draw_rect_surface is used as a 1x1 surface to simplify ren_draw_rect with blending