(drivers_font) switch_font - cleanups

This commit is contained in:
twinaphex 2020-03-07 05:25:28 +01:00
parent 3e891c6237
commit f3c6799b4e
1 changed files with 50 additions and 47 deletions

View File

@ -57,7 +57,8 @@ static void *switch_font_init_font(void *data, const char *font_path,
font->atlas = font->font_driver->get_atlas(font->font_data); font->atlas = font->font_driver->get_atlas(font->font_data);
RARCH_LOG("Switch font driver initialized with backend %s\n", font->font_driver->ident); RARCH_LOG("Switch font driver initialized with backend %s\n",
font->font_driver->ident);
return font; return font;
} }
@ -78,10 +79,9 @@ static void switch_font_free_font(void *data, bool is_threaded)
static int switch_font_get_message_width(void *data, const char *msg, static int switch_font_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale) unsigned msg_len, float scale)
{ {
switch_font_t *font = (switch_font_t *)data;
unsigned i; unsigned i;
int delta_x = 0; int delta_x = 0;
switch_font_t *font = (switch_font_t *)data;
if (!font) if (!font)
return 0; return 0;
@ -89,8 +89,8 @@ static int switch_font_get_message_width(void *data, const char *msg,
for (i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
{ {
const char *msg_tmp = &msg[i]; const char *msg_tmp = &msg[i];
unsigned code = utf8_walk(&msg_tmp); unsigned code = utf8_walk(&msg_tmp);
unsigned skip = msg_tmp - &msg[i]; unsigned skip = msg_tmp - &msg[i];
if (skip > 1) if (skip > 1)
i += skip - 1; i += skip - 1;
@ -111,24 +111,19 @@ static int switch_font_get_message_width(void *data, const char *msg,
} }
static void switch_font_render_line( static void switch_font_render_line(
video_frame_info_t *video_info, switch_video_t *sw,
switch_font_t *font, const char *msg, unsigned msg_len, switch_font_t *font, const char *msg, unsigned msg_len,
float scale, const unsigned int color, float pos_x, float scale, const unsigned int color, float pos_x,
float pos_y, unsigned text_align) float pos_y, unsigned text_align)
{ {
unsigned fb_width, fb_height;
int delta_x = 0; int delta_x = 0;
int delta_y = 0; int delta_y = 0;
switch_video_t* sw = (switch_video_t*)video_info->userdata; unsigned fb_width = sw->vp.full_width;
unsigned fb_height = sw->vp.full_height;
if (!sw)
return;
fb_width = sw->vp.full_width;
fb_height = sw->vp.full_height;
if (sw->out_buffer) if (sw->out_buffer)
{ {
unsigned i;
int x = roundf(pos_x * fb_width); int x = roundf(pos_x * fb_width);
int y = roundf((1.0f - pos_y) * fb_height); int y = roundf((1.0f - pos_y) * fb_height);
@ -142,7 +137,7 @@ static void switch_font_render_line(
break; break;
} }
for (int i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
{ {
int off_x, off_y, tex_x, tex_y, width, height, y; int off_x, off_y, tex_x, tex_y, width, height, y;
const char *msg_tmp = &msg[i]; const char *msg_tmp = &msg[i];
@ -192,13 +187,13 @@ static void switch_font_render_line(
} }
static void switch_font_render_message( static void switch_font_render_message(
video_frame_info_t *video_info, switch_video_t *sw,
switch_font_t *font, const char *msg, float scale, switch_font_t *font, const char *msg, float scale,
const unsigned int color, float pos_x, float pos_y, const unsigned int color, float pos_x, float pos_y,
unsigned text_align) unsigned text_align)
{ {
int lines = 0;
float line_height; float line_height;
int lines = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
@ -209,8 +204,9 @@ static void switch_font_render_message(
int msgLen = strlen(msg); int msgLen = strlen(msg);
if (msgLen <= AVG_GLPYH_LIMIT) if (msgLen <= AVG_GLPYH_LIMIT)
{ {
switch_font_render_line(video_info, font, msg, strlen(msg), if (sw)
scale, color, pos_x, pos_y, text_align); switch_font_render_line(sw, font, msg, strlen(msg),
scale, color, pos_x, pos_y, text_align);
} }
return; return;
} }
@ -226,9 +222,10 @@ static void switch_font_render_message(
unsigned msg_len = delim - msg; unsigned msg_len = delim - msg;
if (msg_len <= AVG_GLPYH_LIMIT) if (msg_len <= AVG_GLPYH_LIMIT)
{ {
switch_font_render_line(video_info, font, msg, msg_len, if (sw)
scale, color, pos_x, pos_y - (float)lines * line_height, switch_font_render_line(sw, font, msg, msg_len,
text_align); scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
} }
msg += msg_len + 1; msg += msg_len + 1;
lines++; lines++;
@ -238,9 +235,10 @@ static void switch_font_render_message(
unsigned msg_len = strlen(msg); unsigned msg_len = strlen(msg);
if (msg_len <= AVG_GLPYH_LIMIT) if (msg_len <= AVG_GLPYH_LIMIT)
{ {
switch_font_render_line(video_info, font, msg, msg_len, if (sw)
scale, color, pos_x, pos_y - (float)lines * line_height, switch_font_render_line(sw, font, msg, msg_len,
text_align); scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
} }
break; break;
} }
@ -255,7 +253,12 @@ static void switch_font_render_msg(
float x, y, scale; float x, y, scale;
enum text_alignment text_align; enum text_alignment text_align;
unsigned color, r, g, b, alpha; unsigned color, r, g, b, alpha;
switch_font_t *font = (switch_font_t *)data; switch_font_t *font = (switch_font_t *)data;
switch_video_t *sw = (switch_video_t*)video_info->userdata;
settings_t *settings = config_get_ptr();
float video_msg_color_r = settings->floats.video_msg_color_r;
float video_msg_color_g = settings->floats.video_msg_color_g;
float video_msg_color_b = settings->floats.video_msg_color_b;
if (!font || !msg || (msg && !*msg)) if (!font || !msg || (msg && !*msg))
return; return;
@ -281,15 +284,15 @@ static void switch_font_render_msg(
scale = 1.0f; scale = 1.0f;
text_align = TEXT_ALIGN_LEFT; text_align = TEXT_ALIGN_LEFT;
r = (video_info->font_msg_color_r * 255); r = (video_msg_color_r * 255);
g = (video_info->font_msg_color_g * 255); g = (video_msg_color_g * 255);
b = (video_info->font_msg_color_b * 255); b = (video_msg_color_b * 255);
alpha = 255; alpha = 255;
color = COLOR_ABGR(r, g, b, alpha); color = COLOR_ABGR(r, g, b, alpha);
} }
switch_font_render_message(video_info, font, msg, scale, switch_font_render_message(sw, font, msg, scale,
color, x, y, text_align); color, x, y, text_align);
} }
@ -317,14 +320,14 @@ static int switch_font_get_line_height(void *data)
} }
font_renderer_t switch_font = font_renderer_t switch_font =
{ {
switch_font_init_font, switch_font_init_font,
switch_font_free_font, switch_font_free_font,
switch_font_render_msg, switch_font_render_msg,
"switchfont", "switchfont",
switch_font_get_glyph, switch_font_get_glyph,
NULL, /* bind_block */ NULL, /* bind_block */
NULL, /* flush_block */ NULL, /* flush_block */
switch_font_get_message_width, switch_font_get_message_width,
switch_font_get_line_height switch_font_get_line_height
}; };