From bbc8bf669119233f68e78dd5b8ef99883a25d235 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Mon, 18 Dec 2017 08:41:04 -0500 Subject: [PATCH] Resize maximums for SDL. To Do: The size returned for SDL2 is still too optimistic. --- sdl1/pdcscrn.c | 10 ++++++++++ sdl2/pdcscrn.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/sdl1/pdcscrn.c b/sdl1/pdcscrn.c index 8e9a0e60..ebacf2eb 100644 --- a/sdl1/pdcscrn.c +++ b/sdl1/pdcscrn.c @@ -31,6 +31,8 @@ Uint32 pdc_mapped[16]; int pdc_fheight, pdc_fwidth, pdc_flastc; bool pdc_own_screen; +static int max_height, max_width; + /* COLOR_PAIR to attribute encoding table. */ static struct {short f, b;} atrtab[PDC_COLOR_PAIRS]; @@ -212,6 +214,10 @@ int PDC_scr_open(int argc, char **argv) if (pdc_own_screen) { + const SDL_VideoInfo *info = SDL_GetVideoInfo(); + max_height = info->current_h; + max_width = info->current_w; + const char *env = getenv("PDC_LINES"); pdc_sheight = (env ? atoi(env) : 25) * pdc_fheight; @@ -281,7 +287,11 @@ int PDC_resize_screen(int nlines, int ncols) if (nlines && ncols) { + while (nlines * pdc_fheight > max_height) + nlines--; pdc_sheight = nlines * pdc_fheight; + while (ncols * pdc_fwidth > max_width) + ncols--; pdc_swidth = ncols * pdc_fwidth; } diff --git a/sdl2/pdcscrn.c b/sdl2/pdcscrn.c index de1f0a58..647eb028 100644 --- a/sdl2/pdcscrn.c +++ b/sdl2/pdcscrn.c @@ -293,12 +293,20 @@ int PDC_scr_open(int argc, char **argv) int PDC_resize_screen(int nlines, int ncols) { + SDL_Rect max; + if (!pdc_own_window) return ERR; + SDL_GetDisplayBounds(0, &max); + if (nlines && ncols) { + while (nlines * pdc_fheight > max.h) + nlines--; pdc_sheight = nlines * pdc_fheight; + while (ncols * pdc_fwidth > max.w) + ncols--; pdc_swidth = ncols * pdc_fwidth; }