From 57e6de978b382a7be29f34f3f5708fadfd56ca84 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 23 Apr 2021 07:09:50 -0700 Subject: [PATCH] Fix error with missing ren_resize call --- src/api/system.c | 10 ++++++---- src/renderer.c | 8 ++++---- src/renderer.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index be5fdea5..826ad5c1 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -109,11 +109,12 @@ top: case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_RESIZED) { - int w = e.window.data1, h = e.window.data2; - ren_resize(w, h); + ren_resize(); lua_pushstring(L, "resized"); - lua_pushnumber(L, w); - lua_pushnumber(L, h); + /* The size below can be wrong on Retina display by a multiplicative factor + but the size reported below is not currently used. */ + lua_pushnumber(L, e.window.data1); + lua_pushnumber(L, e.window.data2); return 3; } else if (e.window.event == SDL_WINDOWEVENT_EXPOSED) { rencache_invalidate(); @@ -318,6 +319,7 @@ static int f_set_window_size(lua_State *L) { double y = luaL_checknumber(L, 4); SDL_SetWindowSize(window, w, h); SDL_SetWindowPosition(window, x, y); + ren_resize(); return 0; } diff --git a/src/renderer.c b/src/renderer.c index 145e3f47..b48bf3d2 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -138,7 +138,7 @@ void ren_init(SDL_Window *win) { } -void ren_resize(int w, int h) { +void ren_resize() { int new_w, new_h; SDL_GL_GetDrawableSize(window, &new_w, &new_h); /* Note that (w, h) may differ from (new_w, new_h) on retina displays. */ @@ -175,7 +175,7 @@ void ren_set_clip_rect(RenRect rect) { void ren_get_size(int *x, int *y) { - SDL_Surface *surf = get_window_surface(window); + SDL_Surface *surf = get_window_surface(); *x = surf->w; *y = surf->h; } @@ -334,7 +334,7 @@ void ren_draw_rect(RenRect rect, RenColor color) { x2 = x2 > clip.right ? clip.right : x2; y2 = y2 > clip.bottom ? clip.bottom : y2; - SDL_Surface *surf = get_window_surface(window); + SDL_Surface *surf = get_window_surface(); RenColor *d = (RenColor*) surf->pixels; d += x1 + y1 * surf->w; int dr = surf->w - (x2 - x1); @@ -364,7 +364,7 @@ void ren_draw_text_subpixel(RenFont *font, const char *text, int x_subpixel, int { const char *p = text; unsigned codepoint; - SDL_Surface *surf = get_window_surface(window); + SDL_Surface *surf = get_window_surface(); const FR_Color color_fr = { .r = color.r, .g = color.g, .b = color.b }; while (*p) { FR_Color color_rep; diff --git a/src/renderer.h b/src/renderer.h index 1ab82206..f11d8e64 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -36,7 +36,7 @@ typedef struct CPReplaceTable CPReplaceTable; void ren_init(SDL_Window *win); -void ren_resize(int w, int h); +void ren_resize(); void ren_update_rects(RenRect *rects, int count); void ren_set_clip_rect(RenRect rect); void ren_get_size(int *x, int *y);