tr2/text: fix aspect ratio

Resolves #2012.
This commit is contained in:
Marcin Kurczewski 2024-12-30 00:22:04 +01:00
parent c64944cf96
commit 2c344d8639
9 changed files with 39 additions and 27 deletions

View file

@ -12,6 +12,7 @@
- added an option to set the bar scaling (no UI for it yet) (#2149)
- 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)
- fixed Lara prioritising throwing a spent flare while mid-air, so to avoid missing ledge grabs (#1989)
- fixed Lara at times not being able to jump immediately after going from her walking to running animation (#1587)
- fixed bubbles spawning from flares if Lara is in shallow water (#1590)

View file

@ -97,6 +97,7 @@ static void M_HandleCanvasResize(const EVENT *event, void *data)
{
UI_CONSOLE *const self = (UI_CONSOLE *)data;
UI_Stack_SetSize(self->container, M_GetWidth(self), M_GetHeight(self));
M_SetPosition(self, WINDOW_MARGIN, WINDOW_MARGIN);
}
static void M_HandleKeyDown(const EVENT *const event, void *const user_data)
@ -161,6 +162,7 @@ static void M_Draw(UI_CONSOLE *const self)
if (self->vtable.is_hidden) {
return;
}
if (self->container->draw != NULL) {
self->container->draw(self->container);
}
@ -209,8 +211,6 @@ UI_WIDGET *UI_Console_Create(void)
self->prompt = UI_Prompt_Create(UI_LABEL_AUTO_SIZE, UI_LABEL_AUTO_SIZE);
UI_Stack_AddChild(self->container, self->prompt);
M_SetPosition(self, WINDOW_MARGIN, WINDOW_MARGIN);
int32_t i = 0;
self->listeners[i++] = UI_Events_Subscribe(
"confirm", self->prompt, M_HandlePromptConfirm, self);

View file

@ -25,6 +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:
break;
}
return M_DoCalc(unit, 640, 480, scale);

View file

@ -4,6 +4,7 @@
typedef enum {
SCALER_TARGET_BAR,
SCALER_TARGET_TEXT,
} SCALER_TARGET;
int32_t Scaler_Calc(int32_t unit, SCALER_TARGET target);

View file

@ -105,6 +105,7 @@ static void M_SyncToWindow(void)
static void M_RefreshRendererViewport(void)
{
Viewport_Reset();
UI_Events_Fire(&(EVENT) { .name = "canvas_resize" });
}
static void M_SyncFromWindow(void)

View file

@ -2,10 +2,18 @@
#include "decomp/decomp.h"
#include "game/output.h"
#include "game/scaler.h"
#include "global/vars.h"
#include <libtrx/utils.h>
static int32_t M_Scale(const int32_t value);
static int32_t M_Scale(const int32_t value)
{
return Scaler_Calc(value, SCALER_TARGET_TEXT);
}
void Text_DrawBorder(
const int32_t x, const int32_t y, const int32_t z, const int32_t width,
const int32_t height)
@ -47,8 +55,8 @@ void Text_DrawText(TEXTSTRING *const text)
int32_t box_w = 0;
int32_t box_h = 0;
const int32_t scale_h = Text_GetScaleH(text->scale.h);
const int32_t scale_v = Text_GetScaleV(text->scale.v);
const int32_t scale_h = M_Scale(text->scale.h);
const int32_t scale_v = M_Scale(text->scale.v);
if (text->flags.flash) {
text->flash.count -= g_Camera.num_frames;
@ -59,13 +67,11 @@ void Text_DrawText(TEXTSTRING *const text)
}
}
int32_t x =
(text->pos.x * Text_GetScaleH(TEXT_BASE_SCALE)) / TEXT_BASE_SCALE;
int32_t y =
(text->pos.y * Text_GetScaleV(TEXT_BASE_SCALE)) / TEXT_BASE_SCALE;
int32_t x = (text->pos.x * M_Scale(TEXT_BASE_SCALE)) / TEXT_BASE_SCALE;
int32_t y = (text->pos.y * M_Scale(TEXT_BASE_SCALE)) / TEXT_BASE_SCALE;
int32_t z = text->pos.z;
int32_t text_width =
Text_GetWidth(text) * Text_GetScaleH(TEXT_BASE_SCALE) / TEXT_BASE_SCALE;
Text_GetWidth(text) * M_Scale(TEXT_BASE_SCALE) / TEXT_BASE_SCALE;
if (text->flags.centre_h) {
x += (g_PhdWinWidth - text_width) / 2;
@ -80,11 +86,11 @@ void Text_DrawText(TEXTSTRING *const text)
}
int32_t box_x = x
+ (text->background.offset.x * Text_GetScaleH(TEXT_BASE_SCALE))
+ (text->background.offset.x * M_Scale(TEXT_BASE_SCALE))
/ TEXT_BASE_SCALE
- ((2 * scale_h) / TEXT_BASE_SCALE);
int32_t box_y = y
+ (text->background.offset.y * Text_GetScaleV(TEXT_BASE_SCALE))
+ (text->background.offset.y * M_Scale(TEXT_BASE_SCALE))
/ TEXT_BASE_SCALE
- ((4 * scale_v) / TEXT_BASE_SCALE)
- ((11 * scale_v) / TEXT_BASE_SCALE);
@ -93,7 +99,7 @@ void Text_DrawText(TEXTSTRING *const text)
const GLYPH_INFO **glyph_ptr = text->glyphs;
while (*glyph_ptr != NULL) {
if (text->flags.multiline && (*glyph_ptr)->role == GLYPH_NEWLINE) {
y += TEXT_HEIGHT * Text_GetScaleV(text->scale.v) / TEXT_BASE_SCALE;
y += TEXT_HEIGHT * M_Scale(text->scale.v) / TEXT_BASE_SCALE;
x = start_x;
glyph_ptr++;
continue;
@ -155,16 +161,6 @@ void Text_DrawText(TEXTSTRING *const text)
}
}
int32_t Text_GetScaleH(const uint32_t value)
{
return value * g_PhdWinWidth / 640;
}
int32_t Text_GetScaleV(const uint32_t value)
{
return value * g_PhdWinHeight / 480;
}
int32_t Text_GetMaxLineLength(void)
{
return 640 / (TEXT_HEIGHT * 0.75);

View file

@ -9,6 +9,3 @@
void Text_DrawBorder(
int32_t x, int32_t y, int32_t z, int32_t width, int32_t height);
void Text_DrawText(TEXTSTRING *text);
int32_t Text_GetScaleH(uint32_t value);
int32_t Text_GetScaleV(uint32_t value);

View file

@ -1,4 +1,6 @@
#include "config.h"
#include "game/scaler.h"
#include "global/vars.h"
#include <libtrx/game/ui/common.h>
@ -6,12 +8,12 @@
int32_t UI_GetCanvasWidth(void)
{
return 640;
return Scaler_CalcInverse(g_PhdWinWidth, SCALER_TARGET_TEXT);
}
int32_t UI_GetCanvasHeight(void)
{
return 480;
return Scaler_CalcInverse(g_PhdWinHeight, SCALER_TARGET_TEXT);
}
UI_INPUT UI_TranslateInput(uint32_t system_keycode)

View file

@ -15,9 +15,11 @@ typedef struct {
UI_WIDGET *window;
UI_WIDGET *backend_selector;
UI_WIDGET *layout_editor;
int32_t listener;
} UI_CONTROLS_DIALOG;
static void M_DoLayout(UI_CONTROLS_DIALOG *self);
static void M_HandleCanvasResize(const EVENT *event, void *data);
static int32_t M_GetWidth(const UI_CONTROLS_DIALOG *self);
static int32_t M_GetHeight(const UI_CONTROLS_DIALOG *self);
static void M_SetPosition(UI_CONTROLS_DIALOG *self, int32_t x, int32_t y);
@ -32,6 +34,12 @@ static void M_DoLayout(UI_CONTROLS_DIALOG *const self)
(UI_GetCanvasHeight() - M_GetHeight(self)) * 2 / 3);
}
static void M_HandleCanvasResize(const EVENT *event, void *data)
{
UI_CONTROLS_DIALOG *const self = (UI_CONTROLS_DIALOG *)data;
M_DoLayout(self);
}
static int32_t M_GetWidth(const UI_CONTROLS_DIALOG *const self)
{
return self->window->get_width(self->window);
@ -81,6 +89,7 @@ static void M_Free(UI_CONTROLS_DIALOG *const self)
self->layout_editor->free(self->layout_editor);
self->backend_selector->free(self->backend_selector);
self->window->free(self->window);
UI_Events_Unsubscribe(self->listener);
Memory_Free(self);
}
@ -105,6 +114,9 @@ UI_WIDGET *UI_ControlsDialog_Create(UI_CONTROLS_CONTROLLER *const controller)
UI_Window_SetTitle(self->window, GS(CONTROL_CUSTOMIZE));
self->listener =
UI_Events_Subscribe("canvas_resize", NULL, M_HandleCanvasResize, self);
M_DoLayout(self);
return (UI_WIDGET *)self;
}