This commit is contained in:
twinaphex 2020-10-14 04:05:32 +02:00
parent 7c48e77bcd
commit b6039b1638

View File

@ -309,9 +309,6 @@ static void gfx_animation_ticker_loop(uint64_t idx,
/* Output offsets/widths are unsigned size_t, but it's /* Output offsets/widths are unsigned size_t, but it's
* easier to perform the required calculations with ints, * easier to perform the required calculations with ints,
* so create some temporary variables... */ * so create some temporary variables... */
int offset;
int width;
/* Looping text is composed of up to three strings, /* Looping text is composed of up to three strings,
* where string 1 and 2 are different regions of the * where string 1 and 2 are different regions of the
* source text and string 2 is a spacer: * source text and string 2 is a spacer:
@ -325,8 +322,8 @@ static void gfx_animation_ticker_loop(uint64_t idx,
*/ */
/* String 1 */ /* String 1 */
offset = (phase < (int)str_width) ? phase : 0; int offset = (phase < (int)str_width) ? phase : 0;
width = (int)(str_width - phase); int width = (int)(str_width - phase);
width = (width < 0) ? 0 : width; width = (width < 0) ? 0 : width;
width = (width > (int)max_width) ? (int)max_width : width; width = (width > (int)max_width) ? (int)max_width : width;
@ -358,23 +355,19 @@ static unsigned get_ticker_smooth_generic_scroll_offset(
uint64_t idx, unsigned str_width, unsigned field_width) uint64_t idx, unsigned str_width, unsigned field_width)
{ {
unsigned scroll_width = str_width - field_width; unsigned scroll_width = str_width - field_width;
unsigned scroll_offset = 0;
unsigned pause_duration = 32; unsigned pause_duration = 32;
unsigned ticker_period = 2 * (scroll_width + pause_duration); unsigned ticker_period = 2 * (scroll_width + pause_duration);
unsigned phase = idx % ticker_period; unsigned phase = idx % ticker_period;
/* Determine scroll offset */ /* Determine scroll offset */
if (phase < pause_duration) if (phase < pause_duration)
scroll_offset = 0; return 0;
else if (phase < ticker_period >> 1) else if (phase < ticker_period >> 1)
scroll_offset = phase - pause_duration; return (phase - pause_duration);
else if (phase < (ticker_period >> 1) + pause_duration) else if (phase < (ticker_period >> 1) + pause_duration)
scroll_offset = (ticker_period - (2 * pause_duration)) >> 1; return ((ticker_period - (2 * pause_duration)) >> 1);
else
scroll_offset = ticker_period - phase;
return scroll_offset; return (ticker_period - phase);
} }
/* 'Fixed width' font version of ticker_smooth_scan_characters() */ /* 'Fixed width' font version of ticker_smooth_scan_characters() */
@ -531,10 +524,10 @@ static void ticker_smooth_scan_characters(
unsigned *char_offset, unsigned *num_chars_to_copy, unsigned *x_offset, unsigned *char_offset, unsigned *num_chars_to_copy, unsigned *x_offset,
unsigned *str_width, unsigned *display_width) unsigned *str_width, unsigned *display_width)
{ {
unsigned i;
unsigned text_width = 0; unsigned text_width = 0;
unsigned scroll_pos = scroll_offset; unsigned scroll_pos = scroll_offset;
bool deferred_str_width = true; bool deferred_str_width = true;
unsigned i;
/* Initialise output variables to 'sane' values */ /* Initialise output variables to 'sane' values */
*char_offset = 0; *char_offset = 0;
@ -740,7 +733,9 @@ static void gfx_animation_ticker_smooth_loop(uint64_t idx,
} }
} }
static size_t get_line_display_ticks(size_t line_len) static void gfx_animation_line_ticker_generic(uint64_t idx,
size_t line_len, size_t max_lines, size_t num_lines,
size_t *line_offset)
{ {
/* Mean human reading speed for all western languages, /* Mean human reading speed for all western languages,
* characters per minute */ * characters per minute */
@ -749,14 +744,7 @@ static size_t get_line_display_ticks(size_t line_len)
float line_duration = (line_len * 60.0f * 1000.0f * 1000.0f) / cpm; float line_duration = (line_len * 60.0f * 1000.0f * 1000.0f) / cpm;
/* Ticker updates (nominally) once every TICKER_SPEED us /* Ticker updates (nominally) once every TICKER_SPEED us
* > Return base number of ticks for which line should be shown */ * > Return base number of ticks for which line should be shown */
return (size_t)(line_duration / (float)TICKER_SPEED); size_t line_ticks = (size_t)(line_duration / (float)TICKER_SPEED);
}
static void gfx_animation_line_ticker_generic(uint64_t idx,
size_t line_len, size_t max_lines, size_t num_lines,
size_t *line_offset)
{
size_t line_ticks = get_line_display_ticks(line_len);
/* Note: This function is only called if num_lines > max_lines */ /* Note: This function is only called if num_lines > max_lines */
size_t excess_lines = num_lines - max_lines; size_t excess_lines = num_lines - max_lines;
/* Ticker will pause for one line duration when the first /* Ticker will pause for one line duration when the first
@ -782,56 +770,56 @@ static void gfx_animation_line_ticker_generic(uint64_t idx,
*line_offset = (excess_lines * 2) - phase; *line_offset = (excess_lines * 2) - phase;
} }
static void gfx_animation_line_ticker_loop(uint64_t idx, static size_t gfx_animation_line_ticker_loop(uint64_t idx,
size_t line_len, size_t num_lines, size_t line_len, size_t num_lines,
size_t *line_offset) size_t *line_offset)
{
size_t line_ticks = get_line_display_ticks(line_len);
size_t ticker_period = num_lines + 1;
size_t phase = (idx / line_ticks) % ticker_period;
/* In this case, line_offset is simply equal to the phase */
*line_offset = phase;
}
static size_t get_line_smooth_scroll_ticks(size_t line_len)
{ {
/* Mean human reading speed for all western languages, /* Mean human reading speed for all western languages,
* characters per minute */ * characters per minute */
float cpm = 1000.0f; float cpm = 1000.0f;
/* Base time for which a line should be shown, in ms */ /* Base time for which a line should be shown, in us */
float line_duration = (line_len * 60.0f * 1000.0f) / cpm; float line_duration = (line_len * 60.0f * 1000.0f * 1000.0f) / cpm;
/* Ticker updates (nominally) once every TICKER_PIXEL_PERIOD ms /* Ticker updates (nominally) once every TICKER_SPEED us
* > Return base number of ticks for which text should scroll * > Return base number of ticks for which line should be shown */
* from one line to the next */ size_t line_ticks = (size_t)(line_duration / (float)TICKER_SPEED);
return (size_t)(line_duration / TICKER_PIXEL_PERIOD); size_t ticker_period = num_lines + 1;
size_t phase = (idx / line_ticks) % ticker_period;
return phase;
} }
static void set_line_smooth_fade_parameters( static void set_line_smooth_fade_parameters(
bool scroll_up, size_t scroll_ticks, size_t line_phase, size_t line_height, bool scroll_up,
size_t num_lines, size_t num_display_lines, size_t line_offset, float y_offset, size_t scroll_ticks, size_t line_phase, size_t line_height,
size_t *top_fade_line_offset, float *top_fade_y_offset, float *top_fade_alpha, size_t num_lines, size_t num_display_lines, size_t line_offset,
size_t *bottom_fade_line_offset, float *bottom_fade_y_offset, float *bottom_fade_alpha) float y_offset,
size_t *top_fade_line_offset,
float *top_fade_y_offset, float *top_fade_alpha,
size_t *bottom_fade_line_offset,
float *bottom_fade_y_offset, float *bottom_fade_alpha)
{ {
float fade_out_alpha = 0.0f;
float fade_in_alpha = 0.0f;
/* When a line fades out, alpha transitions from /* When a line fades out, alpha transitions from
* 1 to 0 over the course of one half of the * 1 to 0 over the course of one half of the
* scrolling line height. When a line fades in, * scrolling line height. When a line fades in,
* it's the other way around */ * it's the other way around */
fade_out_alpha = ((float)scroll_ticks - ((float)line_phase * 2.0f)) / (float)scroll_ticks; float fade_out_alpha = ((float)scroll_ticks - ((float)line_phase * 2.0f)) / (float)scroll_ticks;
fade_in_alpha = -1.0f * fade_out_alpha; float fade_in_alpha = -1.0f * fade_out_alpha;
fade_out_alpha = (fade_out_alpha < 0.0f) ? 0.0f : fade_out_alpha; fade_out_alpha = (fade_out_alpha < 0.0f) ? 0.0f : fade_out_alpha;
fade_in_alpha = (fade_in_alpha < 0.0f) ? 0.0f : fade_in_alpha; fade_in_alpha = (fade_in_alpha < 0.0f) ? 0.0f : fade_in_alpha;
*top_fade_line_offset = (line_offset > 0) ? line_offset - 1 : num_lines; *top_fade_line_offset = (line_offset > 0) ? line_offset - 1 : num_lines;
*top_fade_y_offset = y_offset - (float)line_height; *top_fade_y_offset = y_offset - (float)line_height;
*top_fade_alpha = scroll_up ? fade_out_alpha : fade_in_alpha; if (scroll_up)
{
*top_fade_alpha = fade_out_alpha;
*bottom_fade_alpha = fade_in_alpha;
}
else
{
*top_fade_alpha = fade_in_alpha;
*bottom_fade_alpha = fade_out_alpha;
}
*bottom_fade_line_offset = line_offset + num_display_lines; *bottom_fade_line_offset = line_offset + num_display_lines;
*bottom_fade_y_offset = y_offset + (float)(line_height * num_display_lines); *bottom_fade_y_offset = y_offset + (float)(line_height * num_display_lines);
*bottom_fade_alpha = scroll_up ? fade_in_alpha : fade_out_alpha;
} }
static void set_line_smooth_fade_parameters_default( static void set_line_smooth_fade_parameters_default(
@ -855,7 +843,15 @@ static void gfx_animation_line_ticker_smooth_generic(uint64_t idx,
size_t *top_fade_line_offset, float *top_fade_y_offset, float *top_fade_alpha, size_t *top_fade_line_offset, float *top_fade_y_offset, float *top_fade_alpha,
size_t *bottom_fade_line_offset, float *bottom_fade_y_offset, float *bottom_fade_alpha) size_t *bottom_fade_line_offset, float *bottom_fade_y_offset, float *bottom_fade_alpha)
{ {
size_t scroll_ticks = get_line_smooth_scroll_ticks(line_len); /* Mean human reading speed for all western languages,
* characters per minute */
float cpm = 1000.0f;
/* Base time for which a line should be shown, in ms */
float line_duration = (line_len * 60.0f * 1000.0f) / cpm;
/* Ticker updates (nominally) once every TICKER_PIXEL_PERIOD ms
* > Return base number of ticks for which text should scroll
* from one line to the next */
size_t scroll_ticks = (size_t)(line_duration / TICKER_PIXEL_PERIOD);
/* Note: This function is only called if num_lines > max_display_lines */ /* Note: This function is only called if num_lines > max_display_lines */
size_t excess_lines = num_lines - max_display_lines; size_t excess_lines = num_lines - max_display_lines;
/* Ticker will pause for one line duration when the first /* Ticker will pause for one line duration when the first
@ -941,7 +937,15 @@ static void gfx_animation_line_ticker_smooth_loop(uint64_t idx,
size_t *top_fade_line_offset, float *top_fade_y_offset, float *top_fade_alpha, size_t *top_fade_line_offset, float *top_fade_y_offset, float *top_fade_alpha,
size_t *bottom_fade_line_offset, float *bottom_fade_y_offset, float *bottom_fade_alpha) size_t *bottom_fade_line_offset, float *bottom_fade_y_offset, float *bottom_fade_alpha)
{ {
size_t scroll_ticks = get_line_smooth_scroll_ticks(line_len); /* Mean human reading speed for all western languages,
* characters per minute */
float cpm = 1000.0f;
/* Base time for which a line should be shown, in ms */
float line_duration = (line_len * 60.0f * 1000.0f) / cpm;
/* Ticker updates (nominally) once every TICKER_PIXEL_PERIOD ms
* > Return base number of ticks for which text should scroll
* from one line to the next */
size_t scroll_ticks = (size_t)(line_duration / TICKER_PIXEL_PERIOD);
size_t ticker_period = (num_lines + 1) * scroll_ticks; size_t ticker_period = (num_lines + 1) * scroll_ticks;
size_t phase = idx % ticker_period; size_t phase = idx % ticker_period;
size_t line_phase = phase % scroll_ticks; size_t line_phase = phase % scroll_ticks;
@ -1905,7 +1909,8 @@ bool gfx_animation_line_ticker(gfx_animation_ctx_line_ticker_t *line_ticker)
switch (line_ticker->type_enum) switch (line_ticker->type_enum)
{ {
case TICKER_TYPE_LOOP: case TICKER_TYPE_LOOP:
gfx_animation_line_ticker_loop( /* In this case, line_offset is simply equal to the phase */
line_offset = gfx_animation_line_ticker_loop(
line_ticker->idx, line_ticker->idx,
line_ticker->line_len, line_ticker->line_len,
lines.size, lines.size,