Skip to content

Commit

Permalink
tr2/text: add user scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 30, 2024
1 parent 2c344d8 commit 39ee43b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
- added an optional fix for Lara drifting into walls when collecting underwater items (#2096)
- added an option to control how music is played while underwater (#1937)
- added an optional demo number argument to the `/demo` command
- added an option to set the bar scaling (no UI for it yet) (#2149)
- added an option to set the bar scaling (no UI for it yet) (#1636)
- added an option to set the text scaling (no UI for it yet) (#1636)
- changed demo to be interrupted only by esc or action keys
- fixed health bar and air bar scaling (#2149)
- fixed text being stretched on non-4:3 aspect ratios (#2012)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void Config_Sanitize(void)
CLAMP(g_Config.rendering.linear_adjustment, 0, 256);

CLAMP(g_Config.ui.bar_scale, 0.5, 2.0);
CLAMP(g_Config.ui.text_scale, 0.5, 2.0);
}

void Config_ApplyChanges(void)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct {
} visuals;

struct {
double text_scale;
double bar_scale;
} ui;

Expand Down
1 change: 1 addition & 0 deletions src/tr2/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CFG_INT32(g_Config, gameplay.turbo_speed, 0)
CFG_BOOL(g_Config, visuals.enable_3d_pickups, true)
CFG_BOOL(g_Config, visuals.enable_fade_effects, true)
CFG_BOOL(g_Config, visuals.fix_item_rots, true)
CFG_DOUBLE(g_Config, ui.text_scale, 1.0)
CFG_DOUBLE(g_Config, ui.bar_scale, 1.0)
CFG_ENUM(g_Config, rendering.screenshot_format, SCREENSHOT_FORMAT_JPEG, SCREENSHOT_FORMAT)
CFG_ENUM(g_Config, rendering.render_mode, RM_HARDWARE, RENDER_MODE)
Expand Down
3 changes: 2 additions & 1 deletion src/tr2/game/scaler.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ int32_t Scaler_Calc(const int32_t unit, const SCALER_TARGET target)
case SCALER_TARGET_BAR:
scale = g_Config.ui.bar_scale;
break;
default:
case SCALER_TARGET_TEXT:
scale = g_Config.ui.text_scale;
break;
}

Expand Down
12 changes: 12 additions & 0 deletions src/tr2/game/ui/widgets/stats_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct {
int32_t visible_row_offset;
int32_t row_count;
M_ROW *rows;
int32_t listener;
} UI_STATS_DIALOG;

static M_ROW *M_AddRow(
Expand All @@ -56,6 +57,7 @@ static void M_AddFinalStatsRows(UI_STATS_DIALOG *self);
static void M_AddAssaultCourseStatsRows(UI_STATS_DIALOG *self);
static void M_UpdateTimerRow(UI_STATS_DIALOG *self);
static void M_DoLayout(UI_STATS_DIALOG *self);
static void M_HandleCanvasResize(const EVENT *event, void *data);

static int32_t M_GetWidth(const UI_STATS_DIALOG *self);
static int32_t M_GetHeight(const UI_STATS_DIALOG *self);
Expand Down Expand Up @@ -258,6 +260,12 @@ static void M_DoLayout(UI_STATS_DIALOG *const self)
(UI_GetCanvasHeight() - M_GetHeight(self)) - 50);
}

static void M_HandleCanvasResize(const EVENT *event, void *data)
{
UI_STATS_DIALOG *const self = (UI_STATS_DIALOG *)data;
M_DoLayout(self);
}

static int32_t M_GetWidth(const UI_STATS_DIALOG *const self)
{
return self->window->get_width(self->window);
Expand Down Expand Up @@ -320,6 +328,7 @@ static void M_Free(UI_STATS_DIALOG *const self)
}
self->outer_stack->free(self->outer_stack);
self->window->free(self->window);
UI_Events_Unsubscribe(self->listener);
Memory_Free(self);
}

Expand All @@ -343,6 +352,9 @@ UI_WIDGET *UI_StatsDialog_Create(const UI_STATS_DIALOG_MODE mode)

self->window = UI_Window_Create(self->outer_stack, 8, 8, 8, 8);

self->listener =
UI_Events_Subscribe("canvas_resize", NULL, M_HandleCanvasResize, self);

switch (mode) {
case UI_STATS_DIALOG_MODE_LEVEL:
UI_Window_SetTitle(self->window, g_GF_LevelNames[g_CurrentLevel]);
Expand Down

0 comments on commit 39ee43b

Please sign in to comment.