mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
Merge pull request #1557 from lakkatv/xmb
(Menu) Improved text alignment for gl menu drivers
This commit is contained in:
commit
30fce590df
@ -166,7 +166,7 @@ static void draw_vertices(gl_t *gl, const gl_coords_t *coords)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void render_message(gl_raster_t *font, const char *msg, GLfloat scale,
|
static void render_message(gl_raster_t *font, const char *msg, GLfloat scale,
|
||||||
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, bool align_right)
|
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, unsigned text_align)
|
||||||
{
|
{
|
||||||
int x, y, delta_x, delta_y;
|
int x, y, delta_x, delta_y;
|
||||||
float inv_tex_size_x, inv_tex_size_y, inv_win_width, inv_win_height;
|
float inv_tex_size_x, inv_tex_size_y, inv_win_width, inv_win_height;
|
||||||
@ -185,8 +185,15 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale,
|
|||||||
delta_x = 0;
|
delta_x = 0;
|
||||||
delta_y = 0;
|
delta_y = 0;
|
||||||
|
|
||||||
if (align_right)
|
switch (text_align)
|
||||||
x -= get_message_width(font, msg);
|
{
|
||||||
|
case TEXT_ALIGN_RIGHT:
|
||||||
|
x -= get_message_width(font, msg);
|
||||||
|
break;
|
||||||
|
case TEXT_ALIGN_CENTER:
|
||||||
|
x -= get_message_width(font, msg) / 2.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
inv_tex_size_x = 1.0f / font->tex_width;
|
inv_tex_size_x = 1.0f / font->tex_width;
|
||||||
inv_tex_size_y = 1.0f / font->tex_height;
|
inv_tex_size_y = 1.0f / font->tex_height;
|
||||||
@ -273,7 +280,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
|
|||||||
GLfloat color[4], color_dark[4];
|
GLfloat color[4], color_dark[4];
|
||||||
int drop_x, drop_y;
|
int drop_x, drop_y;
|
||||||
bool full_screen;
|
bool full_screen;
|
||||||
bool align_right;
|
enum text_alignment text_align;
|
||||||
gl_t *gl = NULL;
|
gl_t *gl = NULL;
|
||||||
gl_raster_t *font = (gl_raster_t*)data;
|
gl_raster_t *font = (gl_raster_t*)data;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
@ -290,7 +297,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
|
|||||||
y = params->y;
|
y = params->y;
|
||||||
scale = params->scale;
|
scale = params->scale;
|
||||||
full_screen = params->full_screen;
|
full_screen = params->full_screen;
|
||||||
align_right = params->align_right;
|
text_align = params->text_align;
|
||||||
drop_x = params->drop_x;
|
drop_x = params->drop_x;
|
||||||
drop_y = params->drop_y;
|
drop_y = params->drop_y;
|
||||||
drop_mod = params->drop_mod;
|
drop_mod = params->drop_mod;
|
||||||
@ -310,7 +317,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
|
|||||||
y = settings->video.msg_pos_y;
|
y = settings->video.msg_pos_y;
|
||||||
scale = 1.0f;
|
scale = 1.0f;
|
||||||
full_screen = false;
|
full_screen = false;
|
||||||
align_right = false;
|
text_align = TEXT_ALIGN_LEFT;
|
||||||
|
|
||||||
color[0] = settings->video.msg_color_r;
|
color[0] = settings->video.msg_color_r;
|
||||||
color[1] = settings->video.msg_color_g;
|
color[1] = settings->video.msg_color_g;
|
||||||
@ -336,10 +343,10 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
|
|||||||
|
|
||||||
render_message(font, msg, scale, color_dark,
|
render_message(font, msg, scale, color_dark,
|
||||||
x + scale * drop_x / gl->vp.width, y +
|
x + scale * drop_x / gl->vp.width, y +
|
||||||
scale * drop_y / gl->vp.height, align_right);
|
scale * drop_y / gl->vp.height, text_align);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_message(font, msg, scale, color, x, y, align_right);
|
render_message(font, msg, scale, color, x, y, text_align);
|
||||||
|
|
||||||
if (!font->block)
|
if (!font->block)
|
||||||
restore_viewport(gl);
|
restore_viewport(gl);
|
||||||
|
@ -57,6 +57,13 @@ typedef struct video_info
|
|||||||
bool rgb32;
|
bool rgb32;
|
||||||
} video_info_t;
|
} video_info_t;
|
||||||
|
|
||||||
|
enum text_alignment
|
||||||
|
{
|
||||||
|
TEXT_ALIGN_LEFT = 0,
|
||||||
|
TEXT_ALIGN_RIGHT,
|
||||||
|
TEXT_ALIGN_CENTER
|
||||||
|
};
|
||||||
|
|
||||||
struct font_params
|
struct font_params
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
@ -70,7 +77,7 @@ struct font_params
|
|||||||
/* ABGR. Use the macros. */
|
/* ABGR. Use the macros. */
|
||||||
uint32_t color;
|
uint32_t color;
|
||||||
bool full_screen;
|
bool full_screen;
|
||||||
bool align_right;
|
enum text_alignment text_align;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum texture_filter_type
|
enum texture_filter_type
|
||||||
|
@ -383,7 +383,7 @@ static void xmb_draw_icon_predone(gl_t *gl, xmb_handle_t *xmb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void xmb_draw_text(gl_t *gl, xmb_handle_t *xmb, const char *str, float x,
|
static void xmb_draw_text(gl_t *gl, xmb_handle_t *xmb, const char *str, float x,
|
||||||
float y, float scale_factor, float alpha, bool align_right)
|
float y, float scale_factor, float alpha, enum text_alignment text_align)
|
||||||
{
|
{
|
||||||
uint8_t a8 = 0;
|
uint8_t a8 = 0;
|
||||||
struct font_params params = {0};
|
struct font_params params = {0};
|
||||||
@ -408,7 +408,7 @@ static void xmb_draw_text(gl_t *gl, xmb_handle_t *xmb, const char *str, float x,
|
|||||||
params.scale = scale_factor;
|
params.scale = scale_factor;
|
||||||
params.color = FONT_COLOR_RGBA(255, 255, 255, a8);
|
params.color = FONT_COLOR_RGBA(255, 255, 255, a8);
|
||||||
params.full_screen = true;
|
params.full_screen = true;
|
||||||
params.align_right = align_right;
|
params.text_align = text_align;
|
||||||
|
|
||||||
video_driver_set_osd_msg(str, ¶ms, xmb->font.buf);
|
video_driver_set_osd_msg(str, ¶ms, xmb->font.buf);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user