Skip to content

Commit

Permalink
increase terminal size if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jan 24, 2025
1 parent 8e59559 commit b4570ed
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,54 @@ void config_game_gfx_update(void)
break;
}

//
// Failed to find a good size.
//
if (tries < 0) {
TERM_WIDTH = TERM_WIDTH_MIN;
TERM_HEIGHT = TERM_HEIGHT_MIN;
font_width = game_window_pix_width_get(game) / TERM_WIDTH;
font_height = game_window_pix_height_get(game) / TERM_HEIGHT;
CON("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) best effort", TERM_WIDTH, TERM_HEIGHT,
LOG("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) best effort", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
}

//
// Try again, just in case we had to resort to a best effort font size and can get a few more columns
// and rows out of the terminal.
//
tries = 100;
while (tries-- > 0) {
if (TERM_WIDTH >= TERM_WIDTH_MAX) {
LOG("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) > max width", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
TERM_WIDTH = TERM_WIDTH_MAX;
continue;
}

if (TERM_HEIGHT >= TERM_HEIGHT_MAX) {
LOG("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) > max height", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
TERM_HEIGHT = TERM_HEIGHT_MAX;
continue;
}

if (font_width * TERM_WIDTH < game_window_pix_width_get(game) - font_width - 1) {
LOG("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) can grow horiz", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
TERM_WIDTH++;
continue;
}

if (font_height * TERM_HEIGHT < game_window_pix_height_get(game) - font_height - 1) {
LOG("SDL: Terminal (try %ux%u min %ux%u max %ux%u font %ux%u) can grow vert", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
TERM_HEIGHT++;
continue;
}
break;
}

LOG("SDL: Terminal");
LOG("SDL: - term size : %dx%d", TERM_WIDTH, TERM_HEIGHT);
LOG("SDL: - ascii gl size : %ux%u", font_width, font_height);
Expand Down
33 changes: 33 additions & 0 deletions src/wid_cfg_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ void wid_cfg_gfx_select(class Game *g)
}
y_at++;

/////////////////////////////////////////////////////////////////////////
// ascii font
/////////////////////////////////////////////////////////////////////////
{
TRACE_AND_INDENT();
auto p = wid_cfg_gfx_window->wid_text_area->wid_text_area;
auto w = wid_new_square_button(p, "Font size");

point tl(1, y_at);
point br(width / 2, y_at);
wid_set_shape_none(w);
wid_set_pos(w, tl, br);
wid_set_text_lhs(w, true);
wid_set_text(w, "Font size");
}
{
TRACE_AND_INDENT();
auto p = wid_cfg_gfx_window->wid_text_area->wid_text_area;
auto w = wid_new_square_button(p, "Font size value");

point tl(width / 2 + 4, y_at);
point br(width / 2 + 12, y_at);
wid_set_shape_none(w);
wid_set_pos(w, tl, br);

auto fw = game_ascii_pix_width_get(game);
auto fh = game_ascii_pix_height_get(game);
auto res = std::to_string(fw) + "x" + std::to_string(fh);
wid_set_text(w, res);
wid_set_text_lhs(w, true);
}
y_at++;

/////////////////////////////////////////////////////////////////////////
// Fullscreen
/////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit b4570ed

Please sign in to comment.