diff --git a/libraries/tinyblocks-sdl2/src/tb_sdl2.c b/libraries/tinyblocks-sdl2/src/tb_sdl2.c index 50ec5e3..068f3d5 100644 --- a/libraries/tinyblocks-sdl2/src/tb_sdl2.c +++ b/libraries/tinyblocks-sdl2/src/tb_sdl2.c @@ -711,8 +711,22 @@ static void be_shutdown(void) { s_be_inited = false; } +/* Encolhe a janela para caber na tela (deixa espaco para a barra de titulo e + as bordas), senao numa tela pequena (ex.: 1024x768) a janela de 1280x800 + sai com a barra de titulo fora do visivel e nao da para clicar nos botoes. */ +static void clamp_to_display(int* w, int* h) { + SDL_DisplayMode dm; + if (SDL_GetDesktopDisplayMode(0, &dm) != 0 || dm.w <= 0 || dm.h <= 0) return; + int maxw = dm.w - 16, maxh = dm.h - 64; + if (*w > maxw) *w = maxw; + if (*h > maxh) *h = maxh; + if (*w < 320) *w = 320; + if (*h < 240) *h = 240; +} + static void* be_window_open(const char* title, int w, int h) { if (!be_init()) return NULL; + clamp_to_display(&w, &h); SdlWin* sw = (SdlWin*)calloc(1, sizeof(SdlWin)); if (!sw) return NULL; sw->win = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, @@ -1140,6 +1154,7 @@ static void eval_sdl2_app(TinyBlocks_Block* self, TinyBlocks* rt) { ? vtitle.as.text : "TinyBlocks"; int win_w = (int)(vw.kind == TB_VALUE_INTEGER ? vw.as.integer : 1280); int win_h = (int)(vh.kind == TB_VALUE_INTEGER ? vh.as.integer : 720); + clamp_to_display(&win_w, &win_h); TinyBlocks_Block* scene = (vscene.kind == TB_VALUE_BLOCK) ? vscene.as.block : NULL; TinyBlocks_Block* ev_blk = (vevents.kind == TB_VALUE_BLOCK) ? vevents.as.block : NULL;