Create MENU_ANIMATION_CTL_TICKER

This commit is contained in:
twinaphex 2016-02-25 15:19:33 +01:00
parent 5dbca80ed8
commit b5f4332e74
6 changed files with 125 additions and 82 deletions

View File

@ -503,6 +503,7 @@ static void mui_render_label_value(mui_handle_t *mui,
uint64_t index, uint32_t color, bool selected, const char *label,
const char *value, float *pure_white)
{
menu_animation_ctx_ticker_t ticker;
char label_str[PATH_MAX_LENGTH];
char value_str[PATH_MAX_LENGTH];
int value_len = strlen(value);
@ -519,8 +520,19 @@ static void mui_render_label_value(mui_handle_t *mui,
ticker_limit = (usable_width / mui->glyph_width) - (value_len + 2);
menu_animation_ticker_str(label_str, ticker_limit, index, label, selected);
menu_animation_ticker_str(value_str, value_len, index, value, selected);
ticker.s = label_str;
ticker.len = ticker_limit;
ticker.idx = index;
ticker.str = label;
ticker.selected = selected;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
ticker.s = value_str;
ticker.len = value_len;
ticker.str = value;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
mui_blit_line(mui->margin, y + mui->line_height / 2,
width, height, label_str, color, TEXT_ALIGN_LEFT);
@ -784,6 +796,7 @@ static void mui_frame(void *data)
0, 0, 0, 0.2,
0, 0, 0, 0.2,
};
menu_animation_ctx_ticker_t ticker;
unsigned width, height, ticker_limit, i;
char msg[256];
char title[256];
@ -931,8 +944,14 @@ static void mui_frame(void *data)
}
ticker_limit = (width - mui->margin*2) / mui->glyph_width;
menu_animation_ticker_str(title_buf, ticker_limit,
*frame_count / 100, title, true);
ticker.s = title_buf;
ticker.len = ticker_limit;
ticker.idx = *frame_count / 100;
ticker.str = title;
ticker.selected = true;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
/* Title */
if (mui_get_core_title(title_msg, sizeof(title_msg)) == 0)
@ -947,8 +966,13 @@ static void mui_frame(void *data)
value_len = strlen(title_buf);
ticker_limit = (usable_width / mui->glyph_width) - (value_len + 2);
menu_animation_ticker_str(title_buf_msg_tmp,
ticker_limit, *frame_count / 20, title_buf_msg, true);
ticker.s = title_buf_msg_tmp;
ticker.len = ticker_limit;
ticker.idx = *frame_count / 20;
ticker.str = title_buf_msg;
ticker.selected = true;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
strlcpy(title_buf, title_buf_msg_tmp, sizeof(title_buf));
}

View File

@ -413,6 +413,7 @@ static void rgui_blit_cursor(void)
static void rgui_render(void *data)
{
menu_animation_ctx_ticker_t ticker;
unsigned x, y;
bool display_kb, msg_force;
uint16_t hover_color, normal_color;
@ -534,8 +535,13 @@ static void rgui_render(void *data)
menu_entries_get_title(title, sizeof(title));
menu_animation_ticker_str(title_buf, RGUI_TERM_WIDTH(fb_width) - 10,
*frame_count / RGUI_TERM_START_X(fb_width), title, true);
ticker.s = title_buf;
ticker.len = RGUI_TERM_WIDTH(fb_width) - 10;
ticker.idx = *frame_count / RGUI_TERM_START_X(fb_width);
ticker.str = title;
ticker.selected = true;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
hover_color = HOVER_COLOR(settings);
normal_color = NORMAL_COLOR(settings);
@ -585,6 +591,7 @@ static void rgui_render(void *data)
for (; i < end; i++, y += FONT_HEIGHT_STRIDE)
{
menu_animation_ctx_ticker_t ticker;
size_t selection;
char entry_path[PATH_MAX_LENGTH];
char entry_value[PATH_MAX_LENGTH];
@ -609,14 +616,19 @@ static void rgui_render(void *data)
menu_entry_get_value(i, entry_value, sizeof(entry_value));
menu_entry_get_path(i, entry_path, sizeof(entry_path));
menu_animation_ticker_str(entry_title_buf,
RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2),
*frame_count / RGUI_TERM_START_X(fb_width),
entry_path,
entry_selected);
menu_animation_ticker_str(type_str_buf, entry_spacing,
*frame_count / RGUI_TERM_START_X(fb_width),
entry_value, entry_selected);
ticker.s = entry_title_buf;
ticker.len = RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2);
ticker.idx = *frame_count / RGUI_TERM_START_X(fb_width);
ticker.str = entry_path;
ticker.selected = entry_selected;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
ticker.s = type_str_buf;
ticker.len = entry_spacing;
ticker.str = entry_value;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
snprintf(message, sizeof(message), "%c %-*.*s %-*s",
entry_selected ? '>' : ' ',

View File

@ -1372,11 +1372,12 @@ static void xmb_draw_items(xmb_handle_t *xmb,
size_t current, size_t cat_selection_ptr, float *color,
unsigned width, unsigned height)
{
uint64_t *frame_count;
menu_animation_ctx_ticker_t ticker;
size_t i;
unsigned ticker_limit;
math_matrix_4x4 mymat;
menu_display_ctx_rotate_draw_t rotate_draw;
uint64_t *frame_count = NULL;
xmb_node_t *core_node = NULL;
size_t end = 0;
settings_t *settings = config_get_ptr();
@ -1554,9 +1555,13 @@ static void xmb_draw_items(xmb_handle_t *xmb,
ticker_limit = 70;
}
menu_animation_ticker_str(name, ticker_limit,
*frame_count / 20, entry.path,
(i == current));
ticker.s = name;
ticker.len = ticker_limit;
ticker.idx = *frame_count / 20;
ticker.str = entry.path;
ticker.selected = (i == current);
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
xmb_draw_text(xmb, name,
node->x + xmb->margins.screen.left +
@ -1565,10 +1570,13 @@ static void xmb_draw_items(xmb_handle_t *xmb,
1, node->label_alpha, TEXT_ALIGN_LEFT,
width, height);
menu_animation_ticker_str(value, 35,
*frame_count / 20, entry.value,
(i == current));
ticker.s = value;
ticker.len = 35;
ticker.idx = *frame_count / 20;
ticker.str = entry.value;
ticker.selected = (i == current);
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
if (do_draw_text)
xmb_draw_text(xmb, value,

View File

@ -489,9 +489,10 @@ static bool zarch_zui_button(zui_t *zui, int x1, int y1, const char *label)
static bool zarch_zui_list_item(zui_t *zui, zui_tabbed_t *tab, int x1, int y1,
const char *label, unsigned item_id, const char *entry)
{
uint64_t *frame_count;
menu_animation_ctx_ticker_t ticker;
char title_buf[PATH_MAX_LENGTH];
unsigned ticker_size;
uint64_t *frame_count = NULL;
bool set_active_id = false;
unsigned id = zarch_zui_hash(zui, label);
int x2 = x1 + zui->width - 290 - 40;
@ -534,11 +535,13 @@ static bool zarch_zui_list_item(zui_t *zui, zui_tabbed_t *tab, int x1, int y1,
ticker_size = x2 / 14;
menu_animation_ticker_str(title_buf,
ticker_size,
*frame_count / 50,
label,
(bg == ZUI_BG_HILITE || bg == ZUI_BG_PAD_HILITE));
ticker.s = title_buf;
ticker.len = ticker_size;
ticker.idx = *frame_count / 50;
ticker.str = label;
ticker.selected = (bg == ZUI_BG_HILITE || bg == ZUI_BG_PAD_HILITE);
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2);
zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 12, y1 + 35, title_buf);

View File

@ -522,44 +522,6 @@ bool menu_animation_push(float duration, float target_value, float* subject,
return true;
}
/**
* menu_animation_ticker_str:
* @s : buffer to write new message line to.
* @len : length of buffer @input.
* @idx : Index. Will be used for ticker logic.
* @str : Input string.
* @selected : Is the item currently selected in the menu?
*
* Take the contents of @str and apply a ticker effect to it,
* and write the results in @s.
**/
void menu_animation_ticker_str(char *s, size_t len, uint64_t idx,
const char *str, bool selected)
{
menu_animation_t *anim = menu_animation_get_ptr();
size_t str_len = utf8len(str);
size_t offset = 0;
if ((size_t)str_len <= len)
{
utf8cpy(s, PATH_MAX_LENGTH, str, len);
return;
}
if (!selected)
{
utf8cpy(s, PATH_MAX_LENGTH, str, len-3);
strlcat(s, "...", PATH_MAX_LENGTH);
return;
}
menu_animation_ticker_generic(idx, len, &offset, &str_len);
utf8cpy(s, PATH_MAX_LENGTH, utf8skip(str, offset), str_len);
anim->is_active = true;
}
bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data)
{
menu_animation_t *anim = menu_animation_get_ptr();
@ -699,6 +661,44 @@ bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data)
}
}
break;
case MENU_ANIMATION_CTL_TICKER:
{
menu_animation_ctx_ticker_t *ticker = (menu_animation_ctx_ticker_t*)
data;
size_t str_len = utf8len(ticker->str);
size_t offset = 0;
if ((size_t)str_len <= ticker->len)
{
utf8cpy(ticker->s,
PATH_MAX_LENGTH,
ticker->str,
ticker->len);
return true;
}
if (!ticker->selected)
{
utf8cpy(ticker->s, PATH_MAX_LENGTH, ticker->str, ticker->len - 3);
strlcat(ticker->s, "...", PATH_MAX_LENGTH);
return true;
}
menu_animation_ticker_generic(
ticker->idx,
ticker->len,
&offset,
&str_len);
utf8cpy(
ticker->s,
PATH_MAX_LENGTH,
utf8skip(ticker->str, offset),
str_len);
anim->is_active = true;
}
break;
case MENU_ANIMATION_CTL_NONE:
default:
break;

View File

@ -43,7 +43,8 @@ enum menu_animation_ctl_state
MENU_ANIMATION_CTL_UPDATE_TIME,
MENU_ANIMATION_CTL_UPDATE,
MENU_ANIMATION_CTL_KILL_BY_TAG,
MENU_ANIMATION_CTL_KILL_BY_SUBJECT
MENU_ANIMATION_CTL_KILL_BY_SUBJECT,
MENU_ANIMATION_CTL_TICKER
};
enum menu_animation_easing_type
@ -103,24 +104,19 @@ typedef struct menu_animation_ctx_subject
const void *data;
} menu_animation_ctx_subject_t;
typedef struct menu_animation_ctx_ticker
{
char *s;
size_t len;
uint64_t idx;
const char *str;
bool selected;
} menu_animation_ctx_ticker_t;
/* Use -1 for untagged */
bool menu_animation_push(float duration, float target_value, float* subject,
enum menu_animation_easing_type easing_enum, int tag, tween_cb cb);
/**
* menu_animation_ticker_str:
* @s : buffer to write new message line to.
* @len : length of buffer @input.
* @idx : Index. Will be used for ticker logic.
* @str : Input string.
* @selected : Is the item currently selected in the menu?
*
* Take the contents of @str and apply a ticker effect to it,
* and write the results in @s.
**/
void menu_animation_ticker_str(char *s, size_t len, uint64_t tick,
const char *str, bool selected);
bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data);
#ifdef __cplusplus