Skip to content

Commit f2bb729

Browse files
committed
SDL2: tidy up sdl2_render_msg
Small follow-up cleanup, no behavioural change. - Combine the empty-msg / missing-font-data / missing-font-tex guards into a single early return at the top. The previous arrangement ran SetTextureColorMod and the position math even when the loop body would never execute. - Drop the off_x / off_y / tex_x / tex_y temporaries - they were one-shot copies of gly-> fields used immediately afterwards. - SDL_RenderCopyEx with rotation=0, no center, SDL_FLIP_NONE is just SDL_RenderCopy. The legacy bitmap OSD font is never rotated or flipped (any rotation in the new backend is applied via per-vertex math in the gfx_display draw path) so the simpler call is correct. - Comment up top noting the function's role - it is a legitimate fallback path (HAVE_GFX_WIDGETS undefined, widgets disabled in settings, or pre-widget-init OSD frames) so future readers don't mistake it for dead code now that set_osd_msg dispatches real text through the sdl2_raster_font render_msg.
1 parent ff50b65 commit f2bb729

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

gfx/drivers/sdl2_gfx.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,36 @@ static void sdl2_init_font(sdl2_video_t *vid, const char *font_path,
142142

143143
static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
144144
{
145-
int delta_x = 0;
146-
int delta_y = 0;
147-
unsigned width = vid->vp.width;
148-
unsigned height = vid->vp.height;
149-
settings_t *settings = config_get_ptr();
150-
float msg_pos_x = settings->floats.video_msg_pos_x;
151-
float msg_pos_y = settings->floats.video_msg_pos_y;
152-
int x = msg_pos_x * width;
153-
int y = (1.0f - msg_pos_y) * height;
154-
155-
if (!vid->font_data)
145+
int delta_x, delta_y, x, y;
146+
unsigned width, height;
147+
settings_t *settings;
148+
float msg_pos_x, msg_pos_y;
149+
150+
/* Legacy bitmap OSD font path. Used as a fallback for the
151+
* yellow-text OSD output when widgets are disabled, and as the
152+
* set_osd_msg fallback when the supplied font_data isn't a
153+
* sdl2_raster_font. Anything else (menu / widget text, OSD
154+
* with widgets enabled) goes through the proper render_msg
155+
* dispatch in sdl2_poke_set_osd_msg. */
156+
if (!msg || !*msg || !vid->font_data || !vid->font.tex)
156157
return;
157158

159+
delta_x = 0;
160+
delta_y = 0;
161+
width = vid->vp.width;
162+
height = vid->vp.height;
163+
settings = config_get_ptr();
164+
msg_pos_x = settings->floats.video_msg_pos_x;
165+
msg_pos_y = settings->floats.video_msg_pos_y;
166+
x = (int)(msg_pos_x * width);
167+
y = (int)((1.0f - msg_pos_y) * height);
168+
158169
SDL_SetTextureColorMod(vid->font.tex,
159170
vid->font_r, vid->font_g, vid->font_b);
160171

161172
for (; *msg; msg++)
162173
{
163174
SDL_Rect src_rect, dst_rect;
164-
int off_x, off_y, tex_x, tex_y;
165175
const struct font_glyph *gly =
166176
vid->font_driver->get_glyph(vid->font_data, (uint8_t)*msg);
167177

@@ -171,23 +181,17 @@ static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
171181
if (!gly)
172182
continue;
173183

174-
off_x = gly->draw_offset_x;
175-
off_y = gly->draw_offset_y;
176-
tex_x = gly->atlas_offset_x;
177-
tex_y = gly->atlas_offset_y;
178-
179-
src_rect.x = tex_x;
180-
src_rect.y = tex_y;
184+
src_rect.x = gly->atlas_offset_x;
185+
src_rect.y = gly->atlas_offset_y;
181186
src_rect.w = (int)gly->width;
182187
src_rect.h = (int)gly->height;
183188

184-
dst_rect.x = x + delta_x + off_x;
185-
dst_rect.y = y + delta_y + off_y;
189+
dst_rect.x = x + delta_x + gly->draw_offset_x;
190+
dst_rect.y = y + delta_y + gly->draw_offset_y;
186191
dst_rect.w = (int)gly->width;
187192
dst_rect.h = (int)gly->height;
188193

189-
SDL_RenderCopyEx(vid->renderer, vid->font.tex,
190-
&src_rect, &dst_rect, 0, NULL, SDL_FLIP_NONE);
194+
SDL_RenderCopy(vid->renderer, vid->font.tex, &src_rect, &dst_rect);
191195

192196
delta_x += gly->advance_x;
193197
delta_y -= gly->advance_y;

0 commit comments

Comments
 (0)