(XMB) Align datetime to the right

This commit is contained in:
Jean-André Santoni 2015-01-23 01:54:17 +01:00
parent be7554c603
commit f130a59ab2
4 changed files with 68 additions and 21 deletions

View File

@ -120,9 +120,40 @@ static void gl_raster_font_free_font(void *data)
free(font);
}
static int get_message_width(gl_raster_t *font, const char *msg)
{
int delta_x;
unsigned i, msg_len_full, msg_len;
msg_len_full = strlen(msg);
msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
delta_x = 0;
while (msg_len_full)
{
for (i = 0; i < msg_len; i++)
{
const struct font_glyph *glyph =
font->font_driver->get_glyph(font->font_data, (uint8_t)msg[i]);
if (!glyph)
glyph = font->font_driver->get_glyph(font->font_data, '?'); /* Do something smarter here ... */
if (!glyph)
continue;
delta_x += glyph->advance_x;
}
msg_len_full -= msg_len;
msg += msg_len;
msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
}
return delta_x;
}
static void render_message(gl_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y)
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, bool align_right)
{
int x, y, delta_x, delta_y;
float inv_tex_size_x, inv_tex_size_y, inv_win_width, inv_win_height;
@ -142,6 +173,9 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale,
delta_x = 0;
delta_y = 0;
if (align_right)
x -= get_message_width(font, msg);
inv_tex_size_x = 1.0f / font->tex_width;
inv_tex_size_y = 1.0f / font->tex_height;
inv_win_width = 1.0f / font->gl->vp.width;
@ -211,6 +245,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
GLfloat color[4], color_dark[4];
int drop_x, drop_y;
bool full_screen;
bool align_right;
gl_t *gl = NULL;
gl_raster_t *font = (gl_raster_t*)data;
@ -225,6 +260,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
y = params->y;
scale = params->scale;
full_screen = params->full_screen;
align_right = params->align_right;
drop_x = params->drop_x;
drop_y = params->drop_y;
drop_mod = params->drop_mod;
@ -244,6 +280,7 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
y = g_settings.video.msg_pos_y;
scale = 1.0f;
full_screen = false;
align_right = false;
color[0] = g_settings.video.msg_color_r;
color[1] = g_settings.video.msg_color_g;
@ -270,9 +307,9 @@ static void gl_raster_font_render_msg(void *data, const char *msg,
render_message(font, msg, scale, color_dark,
x + scale * drop_x / gl->vp.width, y +
scale * drop_y / gl->vp.height);
scale * drop_y / gl->vp.height, align_right);
}
render_message(font, msg, scale, color, x, y);
render_message(font, msg, scale, color, x, y, align_right);
glDisable(GL_BLEND);
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);

View File

@ -71,6 +71,7 @@ struct font_params
/* ABGR. Use the macros. */
uint32_t color;
bool full_screen;
bool align_right;
};

View File

@ -90,7 +90,7 @@ static char *str_replace (const char *string,
static void lakka_draw_text(lakka_handle_t *lakka,
const char *str, float x,
float y, float scale_factor, float alpha)
float y, float scale_factor, float alpha, bool align_right)
{
if (!lakka)
return;
@ -120,6 +120,7 @@ static void lakka_draw_text(lakka_handle_t *lakka,
params.scale = scale_factor;
params.color = FONT_COLOR_RGBA(255, 255, 255, a8);
params.full_screen = true;
params.align_right = align_right;
if (driver.video_data && driver.video_poke
&& driver.video_poke->set_osd_msg)
@ -300,7 +301,8 @@ static void lakka_draw_subitems(lakka_handle_t *lakka, int i, int j)
lakka->all_categories_x + lakka->label_margin_left,
lakka->margin_top + subitem->y + lakka->label_margin_top,
1,
subitem->alpha);
subitem->alpha,
0);
}
else if (k == 0 ||
lakka->menu_active_category == 0 ||
@ -321,7 +323,8 @@ static void lakka_draw_subitems(lakka_handle_t *lakka, int i, int j)
lakka->all_categories_x + lakka->label_margin_left,
lakka->margin_top + subitem->y + lakka->label_margin_top,
1,
subitem->alpha);
subitem->alpha,
0);
if (i && (k == 1 || k == 2))
{
@ -336,7 +339,8 @@ static void lakka_draw_subitems(lakka_handle_t *lakka, int i, int j)
lakka->all_categories_x + lakka->label_margin_left + lakka->setting_margin_left,
lakka->margin_top + subitem->y + lakka->label_margin_top,
1,
subitem->alpha);
subitem->alpha,
0);
}
}
@ -357,7 +361,8 @@ static void lakka_draw_subitems(lakka_handle_t *lakka, int i, int j)
+ lakka->setting_margin_left,
lakka->margin_top + subitem->y + lakka->label_margin_top,
1,
subitem->alpha);
subitem->alpha,
0);
if (!strcmp(val, "ON") && lakka->textures[TEXTURE_SWITCH_ON].id)
lakka_draw_icon(lakka, lakka->textures[TEXTURE_SWITCH_ON].id,
@ -424,7 +429,8 @@ static void lakka_draw_items(lakka_handle_t *lakka, int i)
lakka->all_categories_x + lakka->label_margin_left,
lakka->margin_top + item->y + lakka->label_margin_top,
1,
item->alpha);
item->alpha,
0);
}
/* performance improvement */
@ -608,15 +614,15 @@ static void lakka_frame(void)
if (lakka->depth == 0)
lakka_draw_text(lakka, active_category->name,
lakka->title_margin_left, lakka->title_margin_top, 1, 1.0);
lakka->title_margin_left, lakka->title_margin_top, 1, 1.0, 0);
else if (active_item)
lakka_draw_text(lakka, active_item->name,
lakka->title_margin_left, lakka->title_margin_top, 1, 1.0);
lakka->title_margin_left, lakka->title_margin_top, 1, 1.0, 0);
if (g_settings.menu.timedate_enable)
lakka_draw_text(lakka, timedate,
(lakka->title_margin_left * 25) - lakka->title_margin_left,
lakka->title_margin_top, 1, 1.0);
gl->win_width - lakka->title_margin_left,
lakka->title_margin_top, 1, 1.0, 1);
gl_set_viewport(gl, gl->win_width, gl->win_height, false, false);

View File

@ -235,7 +235,7 @@ static void xmb_draw_icon(GLuint texture, float x, float y,
}
static void xmb_draw_text(const char *str, float x,
float y, float scale_factor, float alpha)
float y, float scale_factor, float alpha, bool align_right)
{
gl_t *gl;
uint8_t a8 = 0;
@ -268,6 +268,7 @@ static void xmb_draw_text(const char *str, float x,
params.scale = scale_factor;
params.color = FONT_COLOR_RGBA(255, 255, 255, a8);
params.full_screen = true;
params.align_right = align_right;
if (driver.video_data && driver.video_poke
&& driver.video_poke->set_osd_msg)
@ -398,7 +399,7 @@ static void xmb_render_messagebox(const char *message)
const char *msg = list->elems[i].data;
if (msg)
xmb_draw_text(msg, x, y + i * xmb->font_size, 1, 1);
xmb_draw_text(msg, x, y + i * xmb->font_size, 1, 1, 0);
}
string_list_free(list);
@ -882,7 +883,8 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack,
node->x + xmb->margin_left + xmb->hspacing + xmb->label_margin_left,
xmb->margin_top + node->y + xmb->label_margin_top,
1,
node->label_alpha);
node->label_alpha,
0);
menu_ticker_line(value, 35, g_extern.frame_count / 20, val_buf,
(i == current));
@ -903,7 +905,8 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack,
xmb->label_margin_left + xmb->setting_margin_left,
xmb->margin_top + node->y + xmb->label_margin_top,
1,
node->label_alpha);
node->label_alpha,
0);
if (!strcmp(val_buf, "ON") && xmb->textures[XMB_TEXTURE_SWITCH_ON].id)
xmb_draw_icon(xmb->textures[XMB_TEXTURE_SWITCH_ON].id,
@ -952,14 +955,14 @@ static void xmb_frame(void)
core_name = "No Core";
xmb_draw_text(
xmb->title, xmb->title_margin_left, xmb->title_margin_top, 1, 1);
xmb->title, xmb->title_margin_left, xmb->title_margin_top, 1, 1, 0);
disp_timedate_set_label(timedate, sizeof(timedate), 0);
if (g_settings.menu.timedate_enable)
xmb_draw_text(
timedate, (xmb->title_margin_left * 25) - xmb->title_margin_left,
xmb->title_margin_top, 1, 1);
timedate, gl->win_width - xmb->title_margin_left,
xmb->title_margin_top, 1, 1, 1);
core_version = g_extern.menu.info.library_version;
@ -971,7 +974,7 @@ static void xmb_frame(void)
snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION,
core_name, core_version);
xmb_draw_text(title_msg, xmb->title_margin_left,
gl->win_height - xmb->title_margin_bottom, 1, 1);
gl->win_height - xmb->title_margin_bottom, 1, 1, 0);
xmb_draw_icon(xmb->textures[XMB_TEXTURE_ARROW].id,