Add RGUI scroll acceleration.

This commit is contained in:
Themaister 2013-10-03 20:44:33 +02:00
parent 1c9bbb9333
commit b72996da86
3 changed files with 13 additions and 8 deletions

View File

@ -621,6 +621,7 @@ bool menu_iterate(void)
{
first_held = false;
rgui->trigger_state = input_state;
rgui->scroll_accel = min(rgui->scroll_accel + 1, 64);
}
initial_held = false;
@ -629,6 +630,7 @@ bool menu_iterate(void)
{
first_held = false;
initial_held = true;
rgui->scroll_accel = 0;
}
rgui->delay_count++;

View File

@ -290,6 +290,7 @@ typedef struct
// Rebuilt when parsing directory.
size_t scroll_indices[2 * (26 + 2) + 1];
unsigned scroll_indices_size;
unsigned scroll_accel;
char base_path[PATH_MAX];
char default_glslp[PATH_MAX];

View File

@ -1111,32 +1111,34 @@ static int rgui_iterate(void *data, unsigned action)
if (rgui->need_refresh && action != RGUI_ACTION_MESSAGE)
action = RGUI_ACTION_NOOP;
unsigned scroll_speed = (max(rgui->scroll_accel, 4) - 4) / 4 + 1;
switch (action)
{
case RGUI_ACTION_UP:
if (rgui->selection_ptr > 0)
rgui->selection_ptr--;
if (rgui->selection_ptr >= scroll_speed)
rgui->selection_ptr -= scroll_speed;
else
rgui->selection_ptr = rgui->selection_buf->size - 1;
break;
case RGUI_ACTION_DOWN:
if (rgui->selection_ptr + 1 < rgui->selection_buf->size)
rgui->selection_ptr++;
if (rgui->selection_ptr + scroll_speed < rgui->selection_buf->size)
rgui->selection_ptr += scroll_speed;
else
rgui->selection_ptr = 0;
break;
case RGUI_ACTION_LEFT:
if (rgui->selection_ptr > 8)
rgui->selection_ptr -= 8;
if (rgui->selection_ptr > 8 * scroll_speed)
rgui->selection_ptr -= 8 * scroll_speed;
else
rgui->selection_ptr = 0;
break;
case RGUI_ACTION_RIGHT:
if (rgui->selection_ptr + 8 < rgui->selection_buf->size)
rgui->selection_ptr += 8;
if (rgui->selection_ptr + 8 * scroll_speed < rgui->selection_buf->size)
rgui->selection_ptr += 8 * scroll_speed;
else
rgui->selection_ptr = rgui->selection_buf->size - 1;
break;