2008-03-05 09:58:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Jonathan Gordon
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-03-05 09:58:30 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This file contains the code to draw the list widget on BITMAP LCDs. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
2009-08-19 21:48:17 +00:00
|
|
|
#include "file.h"
|
2008-03-05 09:58:30 +00:00
|
|
|
|
|
|
|
#include "action.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "scrollbar.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "viewport.h"
|
2010-02-26 03:45:41 +00:00
|
|
|
#include "statusbar-skinned.h"
|
2010-09-23 00:02:32 +00:00
|
|
|
#include "debug.h"
|
2008-03-05 09:58:30 +00:00
|
|
|
|
|
|
|
#define ICON_PADDING 1
|
2009-10-05 20:22:02 +00:00
|
|
|
|
2008-12-31 05:59:26 +00:00
|
|
|
/* these are static to make scrolling work */
|
|
|
|
static struct viewport list_text[NB_SCREENS], title_text[NB_SCREENS];
|
2008-03-05 09:58:30 +00:00
|
|
|
|
2010-09-23 00:37:33 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2010-10-06 12:46:42 +00:00
|
|
|
/* difference in pixels between draws, above it means enough to start scrolling */
|
|
|
|
#define SCROLL_BEGIN_THRESHOLD 3
|
|
|
|
|
2010-09-23 00:37:33 +00:00
|
|
|
static enum {
|
2010-10-31 11:11:46 +00:00
|
|
|
SCROLL_NONE, /* no scrolling */
|
|
|
|
SCROLL_BAR, /* scroll by using the scrollbar */
|
|
|
|
SCROLL_SWIPE, /* scroll by wiping over the screen */
|
|
|
|
SCROLL_KINETIC, /* state after releasing swipe */
|
2010-09-23 00:37:33 +00:00
|
|
|
} scroll_mode;
|
2010-10-06 12:46:42 +00:00
|
|
|
|
|
|
|
static int y_offset;
|
2010-09-23 00:37:33 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
int gui_list_get_item_offset(struct gui_synclist * gui_list, int item_width,
|
|
|
|
int text_pos, struct screen * display,
|
|
|
|
struct viewport *vp);
|
2008-12-31 05:59:26 +00:00
|
|
|
bool list_display_title(struct gui_synclist *list, enum screen_type screen);
|
2008-03-05 09:58:30 +00:00
|
|
|
|
2010-02-11 10:41:06 +00:00
|
|
|
void gui_synclist_scroll_stop(struct gui_synclist *lists)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].scroll_stop(&list_text[i]);
|
|
|
|
screens[i].scroll_stop(&title_text[i]);
|
|
|
|
screens[i].scroll_stop(lists->parent[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
/* Draw the list...
|
|
|
|
internal screen layout:
|
|
|
|
-----------------
|
|
|
|
|TI| title | TI is title icon
|
|
|
|
-----------------
|
|
|
|
| | | |
|
|
|
|
|S|I| | S - scrollbar
|
|
|
|
| | | items | I - icons
|
|
|
|
| | | |
|
|
|
|
------------------
|
2009-10-05 11:43:38 +00:00
|
|
|
|
|
|
|
Note: This image is flipped horizontally when the language is a
|
|
|
|
right-to-left one (Hebrew, Arabic)
|
2008-03-05 09:58:30 +00:00
|
|
|
*/
|
2008-12-31 05:59:26 +00:00
|
|
|
static bool draw_title(struct screen *display, struct gui_synclist *list)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2008-12-31 05:59:26 +00:00
|
|
|
const int screen = display->screen_type;
|
2009-03-08 12:42:33 +00:00
|
|
|
int style = STYLE_DEFAULT;
|
2009-10-05 19:59:16 +00:00
|
|
|
struct viewport *title_text_vp = &title_text[screen];
|
|
|
|
|
2010-02-26 03:45:41 +00:00
|
|
|
if (sb_set_title_text(list->title, list->title_icon, screen))
|
|
|
|
return false; /* the sbs is handling the title */
|
2009-10-05 19:59:16 +00:00
|
|
|
display->scroll_stop(title_text_vp);
|
2008-12-31 05:59:26 +00:00
|
|
|
if (!list_display_title(list, screen))
|
2008-03-05 09:58:30 +00:00
|
|
|
return false;
|
2009-10-05 19:59:16 +00:00
|
|
|
*title_text_vp = *(list->parent[screen]);
|
|
|
|
title_text_vp->height = font_get(title_text_vp->font)->height;
|
2009-01-28 18:06:58 +00:00
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
if (list->title_icon != Icon_NOICON && global_settings.show_icons)
|
|
|
|
{
|
2009-10-05 19:59:16 +00:00
|
|
|
struct viewport title_icon = *title_text_vp;
|
|
|
|
|
|
|
|
title_icon.width = get_icon_width(screen) + ICON_PADDING * 2;
|
2009-10-06 08:07:30 +00:00
|
|
|
if (VP_IS_RTL(&title_icon))
|
2009-10-05 11:43:38 +00:00
|
|
|
{
|
2009-10-06 13:32:37 +00:00
|
|
|
title_icon.x += title_text_vp->width - title_icon.width;
|
2009-10-05 11:43:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-05 19:59:16 +00:00
|
|
|
title_text_vp->x += title_icon.width;
|
2009-10-05 11:43:38 +00:00
|
|
|
}
|
2009-10-05 19:59:16 +00:00
|
|
|
title_text_vp->width -= title_icon.width;
|
2008-12-31 05:59:26 +00:00
|
|
|
|
|
|
|
display->set_viewport(&title_icon);
|
2008-03-05 09:58:30 +00:00
|
|
|
screen_put_icon(display, 0, 0, list->title_icon);
|
|
|
|
}
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (list->title_color >= 0)
|
|
|
|
{
|
2009-03-08 12:42:33 +00:00
|
|
|
style |= (STYLE_COLORED|list->title_color);
|
2008-12-31 05:59:26 +00:00
|
|
|
}
|
2008-03-05 09:58:30 +00:00
|
|
|
#endif
|
2009-10-05 19:59:16 +00:00
|
|
|
display->set_viewport(title_text_vp);
|
2009-03-08 12:42:33 +00:00
|
|
|
display->puts_scroll_style(0, 0, list->title, style);
|
2008-03-05 09:58:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-08-22 21:46:02 +00:00
|
|
|
|
2008-12-31 05:59:26 +00:00
|
|
|
void list_draw(struct screen *display, struct gui_synclist *list)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2008-12-31 05:59:26 +00:00
|
|
|
struct viewport list_icons;
|
2009-10-05 19:59:16 +00:00
|
|
|
int start, end, line_height, style, i;
|
2008-12-31 05:59:26 +00:00
|
|
|
const int screen = display->screen_type;
|
2009-10-05 19:59:16 +00:00
|
|
|
const int list_start_item = list->start_item[screen];
|
2008-12-31 05:59:26 +00:00
|
|
|
const int icon_width = get_icon_width(screen) + ICON_PADDING;
|
2010-01-03 13:14:50 +00:00
|
|
|
const bool scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT);
|
2008-12-31 05:59:26 +00:00
|
|
|
const bool show_cursor = !global_settings.cursor_style &&
|
2008-03-05 09:58:30 +00:00
|
|
|
list->show_selection_marker;
|
2008-12-31 05:59:26 +00:00
|
|
|
struct viewport *parent = (list->parent[screen]);
|
2008-03-05 09:58:30 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
unsigned char cur_line = 0;
|
|
|
|
#endif
|
2009-10-05 21:13:55 +00:00
|
|
|
int item_offset;
|
2008-03-05 09:58:30 +00:00
|
|
|
bool show_title;
|
2009-10-05 19:59:16 +00:00
|
|
|
struct viewport *list_text_vp = &list_text[screen];
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
line_height = font_get(parent->font)->height;
|
|
|
|
display->set_viewport(parent);
|
|
|
|
display->clear_viewport();
|
2009-10-05 19:59:16 +00:00
|
|
|
display->scroll_stop(list_text_vp);
|
|
|
|
*list_text_vp = *parent;
|
2008-12-31 05:59:26 +00:00
|
|
|
if ((show_title = draw_title(display, list)))
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->y += line_height;
|
|
|
|
list_text_vp->height -= line_height;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2008-12-31 05:59:26 +00:00
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
const int nb_lines = viewport_get_nb_lines(list_text_vp);
|
2010-10-06 12:46:42 +00:00
|
|
|
|
2009-10-05 19:59:16 +00:00
|
|
|
start = list_start_item;
|
2010-10-31 11:11:46 +00:00
|
|
|
end = start + nb_lines;
|
2009-10-05 18:11:41 +00:00
|
|
|
|
2010-10-06 12:46:42 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2010-10-31 11:11:46 +00:00
|
|
|
if (list->selected_item == 0 || (list->nb_items < nb_lines))
|
2010-10-06 12:46:42 +00:00
|
|
|
y_offset = 0; /* reset in case it's a new list */
|
|
|
|
|
|
|
|
int draw_offset = y_offset;
|
|
|
|
/* draw some extra items to not have empty lines at the top and bottom */
|
|
|
|
if (y_offset > 0)
|
|
|
|
{
|
|
|
|
/* make it negative for more consistent apparence when switching
|
|
|
|
* directions */
|
|
|
|
draw_offset -= line_height;
|
|
|
|
if (start > 0)
|
|
|
|
start--;
|
|
|
|
}
|
|
|
|
else if (y_offset < 0)
|
|
|
|
end++;
|
|
|
|
#else
|
|
|
|
#define draw_offset 0
|
|
|
|
#endif
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
/* draw the scrollbar if its needed */
|
2010-10-31 11:11:46 +00:00
|
|
|
if (global_settings.scrollbar && nb_lines < list->nb_items)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2010-10-09 11:22:52 +00:00
|
|
|
struct viewport vp = *list_text_vp;
|
2008-03-05 09:58:30 +00:00
|
|
|
vp.width = SCROLLBAR_WIDTH;
|
2010-10-31 11:11:46 +00:00
|
|
|
vp.height = line_height * nb_lines;
|
2008-03-05 09:58:30 +00:00
|
|
|
vp.x = parent->x;
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->width -= SCROLLBAR_WIDTH;
|
2009-10-05 13:20:08 +00:00
|
|
|
if (scrollbar_in_left)
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->x += SCROLLBAR_WIDTH;
|
2009-10-05 13:00:28 +00:00
|
|
|
else
|
2009-10-05 19:59:16 +00:00
|
|
|
vp.x += list_text_vp->width;
|
2008-03-05 09:58:30 +00:00
|
|
|
display->set_viewport(&vp);
|
2010-01-07 12:51:57 +00:00
|
|
|
gui_scrollbar_draw(display,
|
|
|
|
(scrollbar_in_left? 0: 1), 0, SCROLLBAR_WIDTH-1, vp.height,
|
2010-10-31 11:11:46 +00:00
|
|
|
list->nb_items, list_start_item, list_start_item + nb_lines,
|
2009-10-05 19:59:16 +00:00
|
|
|
VERTICAL);
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
else if (show_title)
|
|
|
|
{
|
2009-10-05 13:20:08 +00:00
|
|
|
/* shift everything a bit in relation to the title... */
|
2009-10-06 08:07:30 +00:00
|
|
|
if (!VP_IS_RTL(list_text_vp) && scrollbar_in_left)
|
2009-08-17 23:36:49 +00:00
|
|
|
{
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->width -= SCROLLBAR_WIDTH;
|
|
|
|
list_text_vp->x += SCROLLBAR_WIDTH;
|
2009-08-17 23:36:49 +00:00
|
|
|
}
|
2009-10-06 08:07:30 +00:00
|
|
|
else if (VP_IS_RTL(list_text_vp) && !scrollbar_in_left)
|
2009-10-05 23:41:59 +00:00
|
|
|
{
|
|
|
|
list_text_vp->width -= SCROLLBAR_WIDTH;
|
|
|
|
}
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2009-10-05 19:59:16 +00:00
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
/* setup icon placement */
|
2009-10-05 19:59:16 +00:00
|
|
|
list_icons = *list_text_vp;
|
2009-12-16 08:36:46 +00:00
|
|
|
int icon_count = (list->callback_get_item_icon != NULL) ? 1 : 0;
|
2008-03-05 09:58:30 +00:00
|
|
|
if (show_cursor)
|
|
|
|
icon_count++;
|
|
|
|
if (icon_count)
|
|
|
|
{
|
2008-12-31 05:59:26 +00:00
|
|
|
list_icons.width = icon_width * icon_count;
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->width -= list_icons.width + ICON_PADDING;
|
2009-10-06 08:07:30 +00:00
|
|
|
if (VP_IS_RTL(&list_icons))
|
2009-10-05 23:41:59 +00:00
|
|
|
list_icons.x += list_text_vp->width + ICON_PADDING;
|
2009-10-05 11:43:38 +00:00
|
|
|
else
|
2009-10-05 19:59:16 +00:00
|
|
|
list_text_vp->x += list_icons.width + ICON_PADDING;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2009-10-05 19:59:16 +00:00
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
for (i=start; i<end && i<list->nb_items; i++)
|
|
|
|
{
|
|
|
|
/* do the text */
|
2009-08-20 16:47:44 +00:00
|
|
|
unsigned const char *s;
|
2008-03-05 09:58:30 +00:00
|
|
|
char entry_buffer[MAX_PATH];
|
|
|
|
unsigned char *entry_name;
|
|
|
|
int text_pos = 0;
|
2010-10-06 12:46:42 +00:00
|
|
|
int line = i - start;
|
2008-04-09 15:25:17 +00:00
|
|
|
s = list->callback_get_item_name(i, list->data, entry_buffer,
|
|
|
|
sizeof(entry_buffer));
|
2008-03-05 09:58:30 +00:00
|
|
|
entry_name = P2STR(s);
|
2009-10-05 19:59:16 +00:00
|
|
|
display->set_viewport(list_text_vp);
|
2009-03-08 12:42:33 +00:00
|
|
|
style = STYLE_DEFAULT;
|
2008-03-05 09:58:30 +00:00
|
|
|
/* position the string at the correct offset place */
|
|
|
|
int item_width,h;
|
|
|
|
display->getstringsize(entry_name, &item_width, &h);
|
2009-10-05 19:59:16 +00:00
|
|
|
item_offset = gui_list_get_item_offset(list, item_width, text_pos,
|
|
|
|
display, list_text_vp);
|
2008-03-05 09:58:30 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
/* if the list has a color callback */
|
|
|
|
if (list->callback_get_item_color)
|
|
|
|
{
|
|
|
|
int color = list->callback_get_item_color(i, list->data);
|
|
|
|
/* if color selected */
|
|
|
|
if (color >= 0)
|
|
|
|
{
|
2009-03-08 12:42:33 +00:00
|
|
|
style |= STYLE_COLORED|color;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-23 00:02:32 +00:00
|
|
|
/* draw the selected line */
|
2010-09-23 00:37:33 +00:00
|
|
|
if(
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
/* don't draw it during scrolling */
|
|
|
|
scroll_mode == SCROLL_NONE &&
|
|
|
|
#endif
|
|
|
|
i >= list->selected_item
|
2010-09-23 00:02:32 +00:00
|
|
|
&& i < list->selected_item + list->selected_size
|
|
|
|
&& list->show_selection_marker)
|
2008-03-05 09:58:30 +00:00
|
|
|
{/* The selected item must be displayed scrolling */
|
2008-04-03 04:41:42 +00:00
|
|
|
if (global_settings.cursor_style == 1
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2009-10-05 19:59:16 +00:00
|
|
|
/* the global_settings.cursor_style check is here to make
|
2008-12-31 05:59:26 +00:00
|
|
|
* sure if they want the cursor instead of bar it will work
|
|
|
|
*/
|
2008-04-03 04:41:42 +00:00
|
|
|
|| (display->depth < 16 && global_settings.cursor_style)
|
|
|
|
#endif
|
|
|
|
)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
|
|
|
/* Display inverted-line-style */
|
2009-03-08 12:42:33 +00:00
|
|
|
style = STYLE_INVERT;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
else if (global_settings.cursor_style == 2)
|
|
|
|
{
|
|
|
|
/* Display colour line selector */
|
2009-03-08 12:42:33 +00:00
|
|
|
style = STYLE_COLORBAR;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
else if (global_settings.cursor_style == 3)
|
|
|
|
{
|
|
|
|
/* Display gradient line selector */
|
2009-03-08 12:42:33 +00:00
|
|
|
style = STYLE_GRADIENT;
|
2008-03-05 09:58:30 +00:00
|
|
|
|
|
|
|
/* Make the lcd driver know how many lines the gradient should
|
|
|
|
cover and current line number */
|
|
|
|
/* number of selected lines */
|
2009-03-08 12:42:33 +00:00
|
|
|
style |= NUMLN_PACK(list->selected_size);
|
2008-03-05 09:58:30 +00:00
|
|
|
/* current line number, zero based */
|
2009-03-08 12:42:33 +00:00
|
|
|
style |= CURLN_PACK(cur_line);
|
2008-03-05 09:58:30 +00:00
|
|
|
cur_line++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* if the text is smaller than the viewport size */
|
2009-10-05 19:59:16 +00:00
|
|
|
if (item_offset> item_width - (list_text_vp->width - text_pos))
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
|
|
|
/* don't scroll */
|
2010-10-06 12:46:42 +00:00
|
|
|
display->puts_style_xyoffset(0, line, entry_name,
|
|
|
|
style, item_offset, draw_offset);
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-06 12:46:42 +00:00
|
|
|
display->puts_scroll_style_xyoffset(0, line, entry_name,
|
|
|
|
style, item_offset, draw_offset);
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-07-05 12:31:04 +00:00
|
|
|
{
|
|
|
|
if (list->scroll_all)
|
2010-10-06 12:46:42 +00:00
|
|
|
display->puts_scroll_style_xyoffset(0, line, entry_name,
|
|
|
|
style, item_offset, draw_offset);
|
2008-07-05 12:31:04 +00:00
|
|
|
else
|
2010-10-06 12:46:42 +00:00
|
|
|
display->puts_style_xyoffset(0, line, entry_name,
|
|
|
|
style, item_offset, draw_offset);
|
2008-07-05 12:31:04 +00:00
|
|
|
}
|
2008-03-05 09:58:30 +00:00
|
|
|
/* do the icon */
|
2009-10-05 23:08:52 +00:00
|
|
|
display->set_viewport(&list_icons);
|
2010-10-26 12:19:39 +00:00
|
|
|
if (list->callback_get_item_icon != NULL)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
|
|
|
screen_put_icon_with_offset(display, show_cursor?1:0,
|
2010-10-06 12:46:42 +00:00
|
|
|
(line),show_cursor?ICON_PADDING:0,draw_offset,
|
2008-12-31 05:59:26 +00:00
|
|
|
list->callback_get_item_icon(i, list->data));
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2009-10-05 23:08:52 +00:00
|
|
|
if (show_cursor && i >= list->selected_item &&
|
2008-03-05 09:58:30 +00:00
|
|
|
i < list->selected_item + list->selected_size)
|
|
|
|
{
|
2010-10-06 12:46:42 +00:00
|
|
|
screen_put_icon_with_offset(display, 0, line, 0, draw_offset, Icon_Cursor);
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
display->set_viewport(parent);
|
|
|
|
display->update_viewport();
|
2009-01-07 07:52:32 +00:00
|
|
|
display->set_viewport(NULL);
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#if defined(HAVE_TOUCHSCREEN)
|
2009-08-22 23:35:27 +00:00
|
|
|
/* This needs to be fixed if we ever get more than 1 touchscreen on a target. */
|
2010-09-23 00:02:32 +00:00
|
|
|
|
|
|
|
static bool released = false;
|
|
|
|
|
|
|
|
/* Used for kinetic scrolling as we need to know the last position to
|
|
|
|
* recognize the scroll direction.
|
|
|
|
* This gets reset to 0 at the end of scrolling
|
|
|
|
*/
|
|
|
|
static int last_position=0;
|
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
static int scrollbar_scroll(struct gui_synclist * gui_list,
|
2009-08-17 23:36:49 +00:00
|
|
|
int y)
|
|
|
|
{
|
2009-10-05 19:59:16 +00:00
|
|
|
const int screen = screens[SCREEN_MAIN].screen_type;
|
|
|
|
const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
|
|
|
|
|
2009-08-17 23:36:49 +00:00
|
|
|
if (nb_lines < gui_list->nb_items)
|
|
|
|
{
|
2010-10-06 12:46:42 +00:00
|
|
|
/* scrollbar scrolling is still line based */
|
|
|
|
y_offset = 0;
|
2009-08-17 23:36:49 +00:00
|
|
|
int scrollbar_size = nb_lines*
|
|
|
|
font_get(gui_list->parent[screen]->font)->height;
|
|
|
|
int actual_y = y - list_text[screen].y;
|
|
|
|
|
|
|
|
int new_selection = (actual_y * gui_list->nb_items)
|
|
|
|
/ scrollbar_size;
|
|
|
|
|
|
|
|
int start_item = new_selection - nb_lines/2;
|
|
|
|
if(start_item < 0)
|
|
|
|
start_item = 0;
|
|
|
|
else if(start_item > gui_list->nb_items - nb_lines)
|
|
|
|
start_item = gui_list->nb_items - nb_lines;
|
|
|
|
|
|
|
|
gui_list->start_item[screen] = start_item;
|
|
|
|
|
|
|
|
return ACTION_REDRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
/* kinetic scrolling, based on
|
|
|
|
*
|
|
|
|
* v = a*t + v0 and ds = v*dt
|
|
|
|
*
|
|
|
|
* In each (fixed interval) timeout, the list is advanced by ds, then
|
|
|
|
* the v is reduced by a.
|
|
|
|
* This way we get a linear and smooth deceleration of the scrolling
|
|
|
|
*
|
|
|
|
* As v is the difference of distance per time unit, v is passed (as
|
|
|
|
* pixels moved since the last call) to the scrolling function which takes
|
|
|
|
* care of the pixel accurate drawing
|
|
|
|
*
|
|
|
|
* v0 is dertermined by averaging the last 4 movements of the list
|
|
|
|
* (the pixel and time difference is used to compute each v)
|
|
|
|
*
|
|
|
|
* influenced by http://stechz.com/tag/kinetic/
|
|
|
|
* We take the easy and smooth first approach (until section "Drawbacks"),
|
|
|
|
* since its drawbacks don't apply for us since our timers seem to be
|
|
|
|
* relatively accurate
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define SIGN(a) ((a) < 0 ? -1 : 1)
|
|
|
|
/* these could possibly be configurable */
|
|
|
|
/* the lower the smoother */
|
|
|
|
#define RELOAD_INTERVAL (HZ/25)
|
|
|
|
/* the higher the earler the list stops */
|
|
|
|
#define DECELERATION (1000*RELOAD_INTERVAL/HZ)
|
|
|
|
|
|
|
|
/* this array holds data to compute the initial velocity v0 */
|
|
|
|
static struct kinetic_info {
|
|
|
|
int difference;
|
|
|
|
long ticks;
|
|
|
|
} kinetic_data[4];
|
|
|
|
static size_t cur_idx;
|
|
|
|
|
|
|
|
static struct cb_data {
|
|
|
|
struct gui_synclist *list; /* current list */
|
|
|
|
int velocity; /* in pixel/s */
|
|
|
|
} cb_data;
|
|
|
|
|
|
|
|
/* data member points to the above struct */
|
|
|
|
static struct timeout kinetic_tmo;
|
|
|
|
|
|
|
|
static bool is_kinetic_over(void)
|
|
|
|
{
|
|
|
|
return !cb_data.velocity && (scroll_mode == SCROLL_KINETIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* collect data about how fast the list is moved in order to compute
|
|
|
|
* the initial velocity from it later */
|
|
|
|
static void kinetic_stats_collect(const int difference)
|
|
|
|
{
|
|
|
|
static long last_tick;
|
|
|
|
/* collect velocity statistics */
|
|
|
|
kinetic_data[cur_idx].difference = difference;
|
|
|
|
kinetic_data[cur_idx].ticks = current_tick - last_tick;
|
|
|
|
|
|
|
|
last_tick = current_tick;
|
|
|
|
cur_idx += 1;
|
|
|
|
if (cur_idx >= ARRAYLEN(kinetic_data))
|
|
|
|
cur_idx = 0; /* rewind the index */
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:02:32 +00:00
|
|
|
/*
|
2010-10-31 11:11:46 +00:00
|
|
|
* resets the statistic */
|
|
|
|
static void kinetic_stats_reset(void)
|
|
|
|
{
|
|
|
|
memset(kinetic_data, 0, sizeof(kinetic_data));
|
|
|
|
cur_idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cancels all currently active kinetic scrolling */
|
|
|
|
static void kinetic_force_stop(void)
|
|
|
|
{
|
|
|
|
timeout_cancel(&kinetic_tmo);
|
|
|
|
kinetic_stats_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* helper for gui/list.c to cancel scrolling if a normal button event comes
|
|
|
|
* through dpad or keyboard or whatever */
|
|
|
|
void _gui_synclist_stop_kinetic_scrolling(void)
|
|
|
|
{
|
|
|
|
y_offset = 0;
|
|
|
|
if (scroll_mode == SCROLL_KINETIC)
|
|
|
|
kinetic_force_stop();
|
|
|
|
scroll_mode = SCROLL_NONE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* returns false if scrolling should be stopped entirely
|
|
|
|
*
|
|
|
|
* otherwise it returns true even if it didn't actually scroll,
|
|
|
|
* but scrolling mode shouldn't be changed
|
2010-09-23 00:02:32 +00:00
|
|
|
**/
|
2010-11-10 15:25:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int scroll_begin_threshold;
|
|
|
|
static int threshold_accumulation;
|
2010-10-31 11:11:46 +00:00
|
|
|
static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int difference)
|
2010-09-23 00:02:32 +00:00
|
|
|
{
|
2010-10-06 12:46:42 +00:00
|
|
|
/* fixme */
|
|
|
|
const enum screen_type screen = screens[SCREEN_MAIN].screen_type;
|
2010-09-23 00:02:32 +00:00
|
|
|
const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
|
2010-10-06 12:46:42 +00:00
|
|
|
|
2010-11-10 15:25:15 +00:00
|
|
|
if (UNLIKELY(scroll_begin_threshold == 0))
|
|
|
|
scroll_begin_threshold = touchscreen_get_scroll_threshold();
|
|
|
|
|
2010-10-06 12:46:42 +00:00
|
|
|
/* make selecting items easier */
|
2010-11-10 15:25:15 +00:00
|
|
|
threshold_accumulation += abs(difference);
|
|
|
|
if (threshold_accumulation < scroll_begin_threshold && scroll_mode == SCROLL_NONE)
|
2010-10-31 11:11:46 +00:00
|
|
|
return false;
|
2010-10-06 12:46:42 +00:00
|
|
|
|
2010-11-10 15:25:15 +00:00
|
|
|
threshold_accumulation = 0;
|
|
|
|
|
2010-10-06 12:46:42 +00:00
|
|
|
/* does the list even scroll? if no, return but still show
|
|
|
|
* the caller that we would scroll */
|
|
|
|
if (nb_lines >= gui_list->nb_items)
|
2010-10-31 11:11:46 +00:00
|
|
|
return true;
|
2010-10-06 12:46:42 +00:00
|
|
|
|
|
|
|
const int old_start = gui_list->start_item[screen];
|
|
|
|
int new_start_item = -1;
|
|
|
|
int line_diff = 0;
|
|
|
|
|
|
|
|
/* don't scroll at the edges of the list */
|
|
|
|
if ((old_start == 0 && difference > 0)
|
|
|
|
|| (old_start == (gui_list->nb_items - nb_lines) && difference < 0))
|
|
|
|
{
|
|
|
|
y_offset = 0;
|
2010-10-31 11:11:46 +00:00
|
|
|
gui_list->start_item[screen] = old_start;
|
|
|
|
return scroll_mode != SCROLL_KINETIC; /* stop kinetic at the edges */
|
2010-10-06 12:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add up y_offset over time and translate to lines
|
|
|
|
* if scrolled enough */
|
|
|
|
y_offset += difference;
|
|
|
|
if (abs(y_offset) > line_height)
|
|
|
|
{
|
|
|
|
line_diff = y_offset/line_height;
|
|
|
|
y_offset -= line_diff * line_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(line_diff != 0)
|
2010-09-23 00:02:32 +00:00
|
|
|
{
|
2010-10-31 11:11:46 +00:00
|
|
|
int selection_offset = gui_list->selected_item - old_start;
|
2010-10-06 12:46:42 +00:00
|
|
|
new_start_item = old_start - line_diff;
|
2010-09-26 07:32:16 +00:00
|
|
|
/* check if new_start_item is bigger than list item count */
|
2010-09-23 00:02:32 +00:00
|
|
|
if(new_start_item > gui_list->nb_items - nb_lines)
|
|
|
|
new_start_item = gui_list->nb_items - nb_lines;
|
2010-09-26 07:32:16 +00:00
|
|
|
/* set new_start_item to 0 if it's negative */
|
2010-09-23 00:02:32 +00:00
|
|
|
if(new_start_item < 0)
|
|
|
|
new_start_item = 0;
|
2010-10-31 11:11:46 +00:00
|
|
|
|
2010-09-23 00:02:32 +00:00
|
|
|
gui_list->start_item[screen] = new_start_item;
|
2010-10-31 11:11:46 +00:00
|
|
|
/* keep selected item in sync */
|
|
|
|
gui_list->selected_item = new_start_item + selection_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kinetic_callback(struct timeout *tmo)
|
|
|
|
{
|
|
|
|
/* cancel if screen was pressed */
|
|
|
|
if (scroll_mode != SCROLL_KINETIC)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
struct cb_data *data = (struct cb_data*)tmo->data;
|
|
|
|
int line_height = font_get(data->list->parent[0]->font)->height;
|
|
|
|
/* ds = v*dt */
|
|
|
|
int pixel_diff = data->velocity * RELOAD_INTERVAL / HZ;
|
|
|
|
/* remember signedness to detect stopping */
|
|
|
|
int old_sign = SIGN(data->velocity);
|
|
|
|
/* advance the list */
|
|
|
|
if (!swipe_scroll(data->list, line_height, pixel_diff))
|
|
|
|
{
|
|
|
|
/* nothing to scroll? */
|
|
|
|
data->velocity = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* decelerate by a fixed amount
|
|
|
|
* decrementing v0 over time by the deceleration is
|
|
|
|
* equivalent to computing v = a*t + v0 */
|
|
|
|
data->velocity -= SIGN(data->velocity)*DECELERATION;
|
|
|
|
if (SIGN(data->velocity) != old_sign)
|
|
|
|
data->velocity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_post(&button_queue, BUTTON_TOUCHSCREEN, 0);
|
|
|
|
/* stop if the velocity hit or crossed zero */
|
|
|
|
if (!data->velocity)
|
|
|
|
{
|
|
|
|
kinetic_stats_reset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* let get_action() timeout, which loads to a
|
|
|
|
* gui_synclist_draw() call from the main thread */
|
|
|
|
return RELOAD_INTERVAL; /* cancel or reload */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* computes the initial velocity v0 and sets up the timer */
|
|
|
|
static bool kinetic_setup_scroll(struct gui_synclist *list)
|
|
|
|
{
|
|
|
|
/* compute initial velocity */
|
|
|
|
int i, _i, v0, len = ARRAYLEN(kinetic_data);
|
|
|
|
for(i = 0, _i = 0, v0 = 0; i < len; i++)
|
|
|
|
{ /* in pixel/s */
|
|
|
|
if (kinetic_data[i].ticks > 0)
|
|
|
|
{
|
|
|
|
v0 += kinetic_data[i].difference*HZ/kinetic_data[i].ticks;
|
|
|
|
_i++;
|
|
|
|
}
|
2010-09-23 00:02:32 +00:00
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
if (_i > 0)
|
|
|
|
v0 /= _i;
|
|
|
|
else
|
|
|
|
v0 = 0;
|
2010-10-06 12:46:42 +00:00
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
if (v0 != 0)
|
|
|
|
{
|
|
|
|
cb_data.list = list;
|
|
|
|
cb_data.velocity = v0;
|
|
|
|
timeout_register(&kinetic_tmo, kinetic_callback, RELOAD_INTERVAL, (intptr_t)&cb_data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-09-23 00:02:32 +00:00
|
|
|
}
|
|
|
|
|
2008-12-31 05:59:26 +00:00
|
|
|
unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
|
2008-03-05 10:38:10 +00:00
|
|
|
{
|
2008-06-02 16:08:01 +00:00
|
|
|
short x, y;
|
2010-10-06 12:46:42 +00:00
|
|
|
const enum screen_type screen = SCREEN_MAIN;
|
|
|
|
struct viewport *info_vp = sb_skin_get_info_vp(screen);
|
|
|
|
const int button = action_get_touchscreen_press_in_vp(&x, &y, info_vp);
|
2009-10-05 19:59:16 +00:00
|
|
|
const int list_start_item = gui_list->start_item[screen];
|
2010-10-09 11:22:52 +00:00
|
|
|
const int line_height = font_get(gui_list->parent[screen]->font)->height;
|
2009-10-05 19:59:16 +00:00
|
|
|
const struct viewport *list_text_vp = &list_text[screen];
|
2010-09-23 00:02:32 +00:00
|
|
|
const bool old_released = released;
|
2010-10-09 11:22:52 +00:00
|
|
|
const bool show_title = list_display_title(gui_list, screen);
|
|
|
|
const bool show_cursor = !global_settings.cursor_style &&
|
|
|
|
gui_list->show_selection_marker;
|
2010-10-31 11:11:46 +00:00
|
|
|
const bool on_title_clicked = show_title && y < line_height && (button&BUTTON_REL);
|
|
|
|
const bool cancelled_kinetic = (scroll_mode == SCROLL_KINETIC
|
|
|
|
&& button != ACTION_NONE && button != ACTION_UNKNOWN
|
|
|
|
&& !is_kinetic_over());
|
2010-10-09 11:22:52 +00:00
|
|
|
int icon_width = 0;
|
2010-09-23 00:02:32 +00:00
|
|
|
int line, list_width = list_text_vp->width;
|
2010-11-05 19:23:34 +00:00
|
|
|
static bool wait_for_release = false;
|
2010-09-23 00:02:32 +00:00
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
released = (button&BUTTON_REL) != 0;
|
2011-01-29 16:33:25 +00:00
|
|
|
|
|
|
|
if (released && wait_for_release)
|
|
|
|
{ /* was waiting on a release, reset everything so the next call
|
|
|
|
* can start from new */
|
2010-11-05 19:23:34 +00:00
|
|
|
wait_for_release = false;
|
2011-01-29 16:33:25 +00:00
|
|
|
last_position = 0;
|
|
|
|
if (scroll_mode == SCROLL_KINETIC)
|
|
|
|
kinetic_force_stop();
|
|
|
|
scroll_mode = SCROLL_NONE;
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
|
2010-10-06 12:46:42 +00:00
|
|
|
if (button == ACTION_NONE || button == ACTION_UNKNOWN)
|
2010-10-31 11:11:46 +00:00
|
|
|
{
|
|
|
|
/* this happens when we hit edges of the list while kinetic scrolling,
|
|
|
|
* but not when manually cancelling */
|
|
|
|
if (scroll_mode == SCROLL_KINETIC)
|
|
|
|
return ACTION_REDRAW;
|
2010-10-06 12:46:42 +00:00
|
|
|
return ACTION_NONE;
|
2010-10-31 11:11:46 +00:00
|
|
|
}
|
2010-09-26 07:32:16 +00:00
|
|
|
|
2010-10-09 11:22:52 +00:00
|
|
|
/* x and y are relative to info_vp */
|
2010-10-26 12:19:39 +00:00
|
|
|
if (gui_list->callback_get_item_icon != NULL)
|
2010-10-09 11:22:52 +00:00
|
|
|
icon_width += get_icon_width(screen);
|
|
|
|
if (show_cursor)
|
|
|
|
icon_width += get_icon_width(screen);
|
2010-06-24 14:32:25 +00:00
|
|
|
|
2010-10-09 11:22:52 +00:00
|
|
|
if (on_title_clicked)
|
2008-03-05 10:38:10 +00:00
|
|
|
{
|
2010-10-31 11:11:46 +00:00
|
|
|
if (scroll_mode == SCROLL_NONE || is_kinetic_over())
|
|
|
|
{
|
|
|
|
if (x < icon_width)
|
|
|
|
{
|
|
|
|
/* Top left corner is GO_TO_ROOT */
|
|
|
|
if (button == BUTTON_REL)
|
|
|
|
return ACTION_STD_MENU;
|
|
|
|
else if (button == (BUTTON_REPEAT|BUTTON_REL))
|
|
|
|
return ACTION_STD_CONTEXT;
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
else /* click on title text is cancel */
|
|
|
|
if (button == BUTTON_REL)
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
}
|
|
|
|
/* do this after the above so the scrolling stops without
|
|
|
|
* going back in the list with the same touch */
|
|
|
|
if (scroll_mode == SCROLL_KINETIC)
|
2008-03-05 10:38:10 +00:00
|
|
|
{
|
2010-10-31 11:11:46 +00:00
|
|
|
kinetic_force_stop();
|
|
|
|
scroll_mode = SCROLL_NONE;
|
2008-03-05 10:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
else /* list area clicked (or not released) */
|
2008-03-05 10:38:10 +00:00
|
|
|
{
|
2010-10-09 11:22:52 +00:00
|
|
|
const int actual_y = y - (show_title ? line_height : 0);
|
|
|
|
bool on_scrollbar_clicked;
|
|
|
|
switch (global_settings.scrollbar)
|
|
|
|
{
|
|
|
|
case SCROLLBAR_LEFT:
|
|
|
|
on_scrollbar_clicked = x <= SCROLLBAR_WIDTH; break;
|
|
|
|
case SCROLLBAR_RIGHT:
|
|
|
|
on_scrollbar_clicked = x > (icon_width + list_width); break;
|
|
|
|
default:
|
|
|
|
on_scrollbar_clicked = false; break;
|
|
|
|
}
|
2010-09-23 00:02:32 +00:00
|
|
|
/* conditions for scrollbar scrolling:
|
2010-10-09 11:22:52 +00:00
|
|
|
* * pen is on the scrollbar
|
2010-09-23 00:02:32 +00:00
|
|
|
* AND scrollbar is on the right (left case is handled above)
|
|
|
|
* OR * pen is in the somewhere else but we did scrollbar scrolling before
|
|
|
|
*
|
|
|
|
* scrollbar scrolling must end if the pen is released
|
|
|
|
* scrollbar scrolling must not happen if we're currently scrolling
|
|
|
|
* via swiping the screen
|
|
|
|
**/
|
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
if (!released && scroll_mode != SCROLL_SWIPE &&
|
2010-10-09 11:22:52 +00:00
|
|
|
(on_scrollbar_clicked || scroll_mode == SCROLL_BAR))
|
2010-09-23 00:02:32 +00:00
|
|
|
{
|
2010-10-31 11:11:46 +00:00
|
|
|
if (scroll_mode == SCROLL_KINETIC)
|
|
|
|
kinetic_force_stop();
|
2010-10-09 11:22:52 +00:00
|
|
|
scroll_mode = SCROLL_BAR;
|
2010-10-31 11:11:46 +00:00
|
|
|
return scrollbar_scroll(gui_list, y);
|
2010-09-23 00:02:32 +00:00
|
|
|
}
|
2009-08-17 23:36:49 +00:00
|
|
|
|
2008-06-02 16:08:01 +00:00
|
|
|
/* |--------------------------------------------------------|
|
|
|
|
* | Description of the touchscreen list interface: |
|
|
|
|
* |--------------------------------------------------------|
|
|
|
|
* | Pressing an item will select it and "enter" it. |
|
|
|
|
* | |
|
|
|
|
* | Pressing and holding your pen down will scroll through |
|
2008-06-02 18:59:32 +00:00
|
|
|
* | the list of items. |
|
2008-06-02 16:08:01 +00:00
|
|
|
* | |
|
|
|
|
* | Pressing and holding your pen down on a single item |
|
|
|
|
* | will bring up the context menu of it. |
|
|
|
|
* |--------------------------------------------------------|
|
|
|
|
*/
|
2010-10-09 11:22:52 +00:00
|
|
|
if (actual_y > 0 || button & BUTTON_REPEAT)
|
2008-03-05 10:38:10 +00:00
|
|
|
{
|
2010-10-06 12:46:42 +00:00
|
|
|
/* selection needs to be corrected if an items are only
|
2010-10-09 11:22:52 +00:00
|
|
|
* partially visible */
|
2010-10-06 12:46:42 +00:00
|
|
|
line = (actual_y - y_offset) / line_height;
|
2010-10-31 11:11:46 +00:00
|
|
|
|
|
|
|
if (cancelled_kinetic)
|
|
|
|
{
|
|
|
|
kinetic_force_stop();
|
|
|
|
scroll_mode = SCROLL_SWIPE;
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:16:22 +00:00
|
|
|
/* Pressed below the list*/
|
2009-10-05 19:59:16 +00:00
|
|
|
if (list_start_item + line >= gui_list->nb_items)
|
2010-10-06 12:46:42 +00:00
|
|
|
{
|
|
|
|
/* don't collect last_position outside of the list area
|
|
|
|
* it'd break selecting after such a situation */
|
|
|
|
last_position = 0;
|
2008-05-30 22:55:24 +00:00
|
|
|
return ACTION_NONE;
|
2010-10-06 12:46:42 +00:00
|
|
|
}
|
2010-09-23 00:02:32 +00:00
|
|
|
|
2010-11-05 19:23:34 +00:00
|
|
|
if (button & BUTTON_REPEAT && scroll_mode == SCROLL_NONE
|
|
|
|
&& !wait_for_release)
|
|
|
|
{
|
|
|
|
/* held a single line for a while, bring up the context menu */
|
|
|
|
gui_synclist_select_item(gui_list, list_start_item + line);
|
|
|
|
/* don't sent context repeatedly */
|
|
|
|
wait_for_release = true;
|
|
|
|
return ACTION_STD_CONTEXT;
|
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
if (released && !cancelled_kinetic)
|
2008-05-30 22:55:24 +00:00
|
|
|
{
|
2010-09-23 00:02:32 +00:00
|
|
|
/* Pen was released anywhere on the screen */
|
|
|
|
last_position = 0;
|
|
|
|
if (scroll_mode == SCROLL_NONE)
|
2008-05-30 22:55:24 +00:00
|
|
|
{
|
2010-11-05 19:23:34 +00:00
|
|
|
/* select current line */
|
2010-09-23 00:02:32 +00:00
|
|
|
gui_synclist_select_item(gui_list, list_start_item + line);
|
|
|
|
return ACTION_STD_OK;
|
2008-05-30 22:55:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-23 00:02:32 +00:00
|
|
|
/* we were scrolling
|
|
|
|
* -> reset scrolling but do nothing else */
|
2010-10-31 11:11:46 +00:00
|
|
|
if (scroll_mode == SCROLL_SWIPE)
|
|
|
|
{
|
|
|
|
if (kinetic_setup_scroll(gui_list))
|
|
|
|
scroll_mode = SCROLL_KINETIC;
|
|
|
|
}
|
|
|
|
if (scroll_mode != SCROLL_KINETIC)
|
|
|
|
scroll_mode = SCROLL_NONE;
|
2008-06-02 18:59:32 +00:00
|
|
|
return ACTION_NONE;
|
2008-05-30 22:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 10:38:10 +00:00
|
|
|
else
|
2010-09-23 00:02:32 +00:00
|
|
|
{ /* pen is on the screen */
|
2010-10-31 11:11:46 +00:00
|
|
|
bool redraw = false, result = false;
|
2010-09-23 00:02:32 +00:00
|
|
|
/* beginning of list interaction denoted by release in
|
|
|
|
* the previous call */
|
2010-10-31 11:11:46 +00:00
|
|
|
if (old_released || is_kinetic_over())
|
2010-09-23 00:02:32 +00:00
|
|
|
{
|
|
|
|
scroll_mode = SCROLL_NONE;
|
|
|
|
redraw = true;
|
|
|
|
}
|
2010-09-26 07:32:16 +00:00
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
/* select current item; gui_synclist_select_item()
|
|
|
|
* is not called because it has side effects that
|
|
|
|
* disturb kinetic scrolling */
|
|
|
|
gui_list->selected_item = list_start_item+line;
|
|
|
|
gui_synclist_speak_item(gui_list);
|
2010-09-23 00:02:32 +00:00
|
|
|
if (last_position == 0)
|
2010-10-06 12:46:42 +00:00
|
|
|
last_position = actual_y;
|
2010-09-23 00:02:32 +00:00
|
|
|
else
|
2010-10-31 11:11:46 +00:00
|
|
|
{
|
|
|
|
/* record speed data in case we do kinetic scrolling */
|
|
|
|
int diff = actual_y - last_position;
|
|
|
|
kinetic_stats_collect(diff);
|
|
|
|
result = swipe_scroll(gui_list, line_height, diff);
|
|
|
|
}
|
2010-09-23 00:02:32 +00:00
|
|
|
|
|
|
|
/* Start scrolling once the pen is moved without
|
|
|
|
* releasing it inbetween */
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
redraw = true;
|
|
|
|
scroll_mode = SCROLL_SWIPE;
|
|
|
|
}
|
2010-10-06 12:46:42 +00:00
|
|
|
last_position = actual_y;
|
2010-09-23 00:02:32 +00:00
|
|
|
|
|
|
|
return redraw ? ACTION_REDRAW:ACTION_NONE;
|
|
|
|
}
|
2008-03-05 10:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
return ACTION_REDRAW;
|
2008-03-05 10:38:10 +00:00
|
|
|
}
|
|
|
|
#endif
|