Touchscreen/lists: Hopefully fix glitchy behavior that happened after opening the...
[maemo-rb.git] / apps / gui / bitmap / list.c
blob3da0d0bb7f5bbdb6a3412d4ffef73f16b46b600f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* This file contains the code to draw the list widget on BITMAP LCDs. */
24 #include "config.h"
25 #include "lcd.h"
26 #include "font.h"
27 #include "button.h"
28 #include "string.h"
29 #include "settings.h"
30 #include "kernel.h"
31 #include "system.h"
32 #include "file.h"
34 #include "action.h"
35 #include "screen_access.h"
36 #include "list.h"
37 #include "scrollbar.h"
38 #include "lang.h"
39 #include "sound.h"
40 #include "misc.h"
41 #include "viewport.h"
42 #include "statusbar-skinned.h"
43 #include "debug.h"
45 #define ICON_PADDING 1
47 /* these are static to make scrolling work */
48 static struct viewport list_text[NB_SCREENS], title_text[NB_SCREENS];
50 #ifdef HAVE_TOUCHSCREEN
51 /* difference in pixels between draws, above it means enough to start scrolling */
52 #define SCROLL_BEGIN_THRESHOLD 3
54 static enum {
55 SCROLL_NONE, /* no scrolling */
56 SCROLL_BAR, /* scroll by using the scrollbar */
57 SCROLL_SWIPE, /* scroll by wiping over the screen */
58 SCROLL_KINETIC, /* state after releasing swipe */
59 } scroll_mode;
61 static int y_offset;
62 #endif
64 int gui_list_get_item_offset(struct gui_synclist * gui_list, int item_width,
65 int text_pos, struct screen * display,
66 struct viewport *vp);
67 bool list_display_title(struct gui_synclist *list, enum screen_type screen);
69 void gui_synclist_scroll_stop(struct gui_synclist *lists)
71 int i;
72 FOR_NB_SCREENS(i)
74 screens[i].scroll_stop(&list_text[i]);
75 screens[i].scroll_stop(&title_text[i]);
76 screens[i].scroll_stop(lists->parent[i]);
80 /* Draw the list...
81 internal screen layout:
82 -----------------
83 |TI| title | TI is title icon
84 -----------------
85 | | | |
86 |S|I| | S - scrollbar
87 | | | items | I - icons
88 | | | |
89 ------------------
91 Note: This image is flipped horizontally when the language is a
92 right-to-left one (Hebrew, Arabic)
94 static bool draw_title(struct screen *display, struct gui_synclist *list)
96 const int screen = display->screen_type;
97 int style = STYLE_DEFAULT;
98 struct viewport *title_text_vp = &title_text[screen];
100 if (sb_set_title_text(list->title, list->title_icon, screen))
101 return false; /* the sbs is handling the title */
102 display->scroll_stop(title_text_vp);
103 if (!list_display_title(list, screen))
104 return false;
105 *title_text_vp = *(list->parent[screen]);
106 title_text_vp->height = font_get(title_text_vp->font)->height;
108 if (list->title_icon != Icon_NOICON && global_settings.show_icons)
110 struct viewport title_icon = *title_text_vp;
112 title_icon.width = get_icon_width(screen) + ICON_PADDING * 2;
113 if (VP_IS_RTL(&title_icon))
115 title_icon.x += title_text_vp->width - title_icon.width;
117 else
119 title_text_vp->x += title_icon.width;
121 title_text_vp->width -= title_icon.width;
123 display->set_viewport(&title_icon);
124 screen_put_icon(display, 0, 0, list->title_icon);
126 #ifdef HAVE_LCD_COLOR
127 if (list->title_color >= 0)
129 style |= (STYLE_COLORED|list->title_color);
131 #endif
132 display->set_viewport(title_text_vp);
133 display->puts_scroll_style(0, 0, list->title, style);
134 return true;
137 void list_draw(struct screen *display, struct gui_synclist *list)
139 struct viewport list_icons;
140 int start, end, line_height, style, i;
141 const int screen = display->screen_type;
142 const int list_start_item = list->start_item[screen];
143 const int icon_width = get_icon_width(screen) + ICON_PADDING;
144 const bool scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT);
145 const bool show_cursor = !global_settings.cursor_style &&
146 list->show_selection_marker;
147 struct viewport *parent = (list->parent[screen]);
148 #ifdef HAVE_LCD_COLOR
149 unsigned char cur_line = 0;
150 #endif
151 int item_offset;
152 bool show_title;
153 struct viewport *list_text_vp = &list_text[screen];
155 line_height = font_get(parent->font)->height;
156 display->set_viewport(parent);
157 display->clear_viewport();
158 display->scroll_stop(list_text_vp);
159 *list_text_vp = *parent;
160 if ((show_title = draw_title(display, list)))
162 list_text_vp->y += line_height;
163 list_text_vp->height -= line_height;
166 const int nb_lines = viewport_get_nb_lines(list_text_vp);
168 start = list_start_item;
169 end = start + nb_lines;
171 #ifdef HAVE_TOUCHSCREEN
172 if (list->selected_item == 0 || (list->nb_items < nb_lines))
173 y_offset = 0; /* reset in case it's a new list */
175 int draw_offset = y_offset;
176 /* draw some extra items to not have empty lines at the top and bottom */
177 if (y_offset > 0)
179 /* make it negative for more consistent apparence when switching
180 * directions */
181 draw_offset -= line_height;
182 if (start > 0)
183 start--;
185 else if (y_offset < 0)
186 end++;
187 #else
188 #define draw_offset 0
189 #endif
191 /* draw the scrollbar if its needed */
192 if (global_settings.scrollbar && nb_lines < list->nb_items)
194 struct viewport vp = *list_text_vp;
195 vp.width = SCROLLBAR_WIDTH;
196 vp.height = line_height * nb_lines;
197 vp.x = parent->x;
198 list_text_vp->width -= SCROLLBAR_WIDTH;
199 if (scrollbar_in_left)
200 list_text_vp->x += SCROLLBAR_WIDTH;
201 else
202 vp.x += list_text_vp->width;
203 display->set_viewport(&vp);
204 gui_scrollbar_draw(display,
205 (scrollbar_in_left? 0: 1), 0, SCROLLBAR_WIDTH-1, vp.height,
206 list->nb_items, list_start_item, list_start_item + nb_lines,
207 VERTICAL);
209 else if (show_title)
211 /* shift everything a bit in relation to the title... */
212 if (!VP_IS_RTL(list_text_vp) && scrollbar_in_left)
214 list_text_vp->width -= SCROLLBAR_WIDTH;
215 list_text_vp->x += SCROLLBAR_WIDTH;
217 else if (VP_IS_RTL(list_text_vp) && !scrollbar_in_left)
219 list_text_vp->width -= SCROLLBAR_WIDTH;
223 /* setup icon placement */
224 list_icons = *list_text_vp;
225 int icon_count = (list->callback_get_item_icon != NULL) ? 1 : 0;
226 if (show_cursor)
227 icon_count++;
228 if (icon_count)
230 list_icons.width = icon_width * icon_count;
231 list_text_vp->width -= list_icons.width + ICON_PADDING;
232 if (VP_IS_RTL(&list_icons))
233 list_icons.x += list_text_vp->width + ICON_PADDING;
234 else
235 list_text_vp->x += list_icons.width + ICON_PADDING;
238 for (i=start; i<end && i<list->nb_items; i++)
240 /* do the text */
241 unsigned const char *s;
242 char entry_buffer[MAX_PATH];
243 unsigned char *entry_name;
244 int text_pos = 0;
245 int line = i - start;
246 s = list->callback_get_item_name(i, list->data, entry_buffer,
247 sizeof(entry_buffer));
248 entry_name = P2STR(s);
249 display->set_viewport(list_text_vp);
250 style = STYLE_DEFAULT;
251 /* position the string at the correct offset place */
252 int item_width,h;
253 display->getstringsize(entry_name, &item_width, &h);
254 item_offset = gui_list_get_item_offset(list, item_width, text_pos,
255 display, list_text_vp);
257 #ifdef HAVE_LCD_COLOR
258 /* if the list has a color callback */
259 if (list->callback_get_item_color)
261 int color = list->callback_get_item_color(i, list->data);
262 /* if color selected */
263 if (color >= 0)
265 style |= STYLE_COLORED|color;
268 #endif
269 /* draw the selected line */
271 #ifdef HAVE_TOUCHSCREEN
272 /* don't draw it during scrolling */
273 scroll_mode == SCROLL_NONE &&
274 #endif
275 i >= list->selected_item
276 && i < list->selected_item + list->selected_size
277 && list->show_selection_marker)
278 {/* The selected item must be displayed scrolling */
279 if (global_settings.cursor_style == 1
280 #ifdef HAVE_REMOTE_LCD
281 /* the global_settings.cursor_style check is here to make
282 * sure if they want the cursor instead of bar it will work
284 || (display->depth < 16 && global_settings.cursor_style)
285 #endif
288 /* Display inverted-line-style */
289 style = STYLE_INVERT;
291 #ifdef HAVE_LCD_COLOR
292 else if (global_settings.cursor_style == 2)
294 /* Display colour line selector */
295 style = STYLE_COLORBAR;
297 else if (global_settings.cursor_style == 3)
299 /* Display gradient line selector */
300 style = STYLE_GRADIENT;
302 /* Make the lcd driver know how many lines the gradient should
303 cover and current line number */
304 /* number of selected lines */
305 style |= NUMLN_PACK(list->selected_size);
306 /* current line number, zero based */
307 style |= CURLN_PACK(cur_line);
308 cur_line++;
310 #endif
311 /* if the text is smaller than the viewport size */
312 if (item_offset> item_width - (list_text_vp->width - text_pos))
314 /* don't scroll */
315 display->puts_style_xyoffset(0, line, entry_name,
316 style, item_offset, draw_offset);
318 else
320 display->puts_scroll_style_xyoffset(0, line, entry_name,
321 style, item_offset, draw_offset);
324 else
326 if (list->scroll_all)
327 display->puts_scroll_style_xyoffset(0, line, entry_name,
328 style, item_offset, draw_offset);
329 else
330 display->puts_style_xyoffset(0, line, entry_name,
331 style, item_offset, draw_offset);
333 /* do the icon */
334 display->set_viewport(&list_icons);
335 if (list->callback_get_item_icon != NULL)
337 screen_put_icon_with_offset(display, show_cursor?1:0,
338 (line),show_cursor?ICON_PADDING:0,draw_offset,
339 list->callback_get_item_icon(i, list->data));
341 if (show_cursor && i >= list->selected_item &&
342 i < list->selected_item + list->selected_size)
344 screen_put_icon_with_offset(display, 0, line, 0, draw_offset, Icon_Cursor);
347 display->set_viewport(parent);
348 display->update_viewport();
349 display->set_viewport(NULL);
352 #if defined(HAVE_TOUCHSCREEN)
353 /* This needs to be fixed if we ever get more than 1 touchscreen on a target. */
355 static bool released = false;
357 /* Used for kinetic scrolling as we need to know the last position to
358 * recognize the scroll direction.
359 * This gets reset to 0 at the end of scrolling
361 static int last_position=0;
363 static int scrollbar_scroll(struct gui_synclist * gui_list,
364 int y)
366 const int screen = screens[SCREEN_MAIN].screen_type;
367 const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
369 if (nb_lines < gui_list->nb_items)
371 /* scrollbar scrolling is still line based */
372 y_offset = 0;
373 int scrollbar_size = nb_lines*
374 font_get(gui_list->parent[screen]->font)->height;
375 int actual_y = y - list_text[screen].y;
377 int new_selection = (actual_y * gui_list->nb_items)
378 / scrollbar_size;
380 int start_item = new_selection - nb_lines/2;
381 if(start_item < 0)
382 start_item = 0;
383 else if(start_item > gui_list->nb_items - nb_lines)
384 start_item = gui_list->nb_items - nb_lines;
386 gui_list->start_item[screen] = start_item;
388 return ACTION_REDRAW;
391 return ACTION_NONE;
394 /* kinetic scrolling, based on
396 * v = a*t + v0 and ds = v*dt
398 * In each (fixed interval) timeout, the list is advanced by ds, then
399 * the v is reduced by a.
400 * This way we get a linear and smooth deceleration of the scrolling
402 * As v is the difference of distance per time unit, v is passed (as
403 * pixels moved since the last call) to the scrolling function which takes
404 * care of the pixel accurate drawing
406 * v0 is dertermined by averaging the last 4 movements of the list
407 * (the pixel and time difference is used to compute each v)
409 * influenced by http://stechz.com/tag/kinetic/
410 * We take the easy and smooth first approach (until section "Drawbacks"),
411 * since its drawbacks don't apply for us since our timers seem to be
412 * relatively accurate
416 #define SIGN(a) ((a) < 0 ? -1 : 1)
417 /* these could possibly be configurable */
418 /* the lower the smoother */
419 #define RELOAD_INTERVAL (HZ/25)
420 /* the higher the earler the list stops */
421 #define DECELERATION (1000*RELOAD_INTERVAL/HZ)
423 /* this array holds data to compute the initial velocity v0 */
424 static struct kinetic_info {
425 int difference;
426 long ticks;
427 } kinetic_data[4];
428 static size_t cur_idx;
430 static struct cb_data {
431 struct gui_synclist *list; /* current list */
432 int velocity; /* in pixel/s */
433 } cb_data;
435 /* data member points to the above struct */
436 static struct timeout kinetic_tmo;
438 static bool is_kinetic_over(void)
440 return !cb_data.velocity && (scroll_mode == SCROLL_KINETIC);
444 * collect data about how fast the list is moved in order to compute
445 * the initial velocity from it later */
446 static void kinetic_stats_collect(const int difference)
448 static long last_tick;
449 /* collect velocity statistics */
450 kinetic_data[cur_idx].difference = difference;
451 kinetic_data[cur_idx].ticks = current_tick - last_tick;
453 last_tick = current_tick;
454 cur_idx += 1;
455 if (cur_idx >= ARRAYLEN(kinetic_data))
456 cur_idx = 0; /* rewind the index */
460 * resets the statistic */
461 static void kinetic_stats_reset(void)
463 memset(kinetic_data, 0, sizeof(kinetic_data));
464 cur_idx = 0;
467 /* cancels all currently active kinetic scrolling */
468 static void kinetic_force_stop(void)
470 timeout_cancel(&kinetic_tmo);
471 kinetic_stats_reset();
474 /* helper for gui/list.c to cancel scrolling if a normal button event comes
475 * through dpad or keyboard or whatever */
476 void _gui_synclist_stop_kinetic_scrolling(void)
478 y_offset = 0;
479 if (scroll_mode == SCROLL_KINETIC)
480 kinetic_force_stop();
481 scroll_mode = SCROLL_NONE;
484 * returns false if scrolling should be stopped entirely
486 * otherwise it returns true even if it didn't actually scroll,
487 * but scrolling mode shouldn't be changed
491 static int scroll_begin_threshold;
492 static int threshold_accumulation;
493 static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int difference)
495 /* fixme */
496 const enum screen_type screen = screens[SCREEN_MAIN].screen_type;
497 const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
499 if (UNLIKELY(scroll_begin_threshold == 0))
500 scroll_begin_threshold = touchscreen_get_scroll_threshold();
502 /* make selecting items easier */
503 threshold_accumulation += abs(difference);
504 if (threshold_accumulation < scroll_begin_threshold && scroll_mode == SCROLL_NONE)
505 return false;
507 threshold_accumulation = 0;
509 /* does the list even scroll? if no, return but still show
510 * the caller that we would scroll */
511 if (nb_lines >= gui_list->nb_items)
512 return true;
514 const int old_start = gui_list->start_item[screen];
515 int new_start_item = -1;
516 int line_diff = 0;
518 /* don't scroll at the edges of the list */
519 if ((old_start == 0 && difference > 0)
520 || (old_start == (gui_list->nb_items - nb_lines) && difference < 0))
522 y_offset = 0;
523 gui_list->start_item[screen] = old_start;
524 return scroll_mode != SCROLL_KINETIC; /* stop kinetic at the edges */
527 /* add up y_offset over time and translate to lines
528 * if scrolled enough */
529 y_offset += difference;
530 if (abs(y_offset) > line_height)
532 line_diff = y_offset/line_height;
533 y_offset -= line_diff * line_height;
536 if(line_diff != 0)
538 int selection_offset = gui_list->selected_item - old_start;
539 new_start_item = old_start - line_diff;
540 /* check if new_start_item is bigger than list item count */
541 if(new_start_item > gui_list->nb_items - nb_lines)
542 new_start_item = gui_list->nb_items - nb_lines;
543 /* set new_start_item to 0 if it's negative */
544 if(new_start_item < 0)
545 new_start_item = 0;
547 gui_list->start_item[screen] = new_start_item;
548 /* keep selected item in sync */
549 gui_list->selected_item = new_start_item + selection_offset;
552 return true;
555 static int kinetic_callback(struct timeout *tmo)
557 /* cancel if screen was pressed */
558 if (scroll_mode != SCROLL_KINETIC)
559 return 0;
561 struct cb_data *data = (struct cb_data*)tmo->data;
562 int line_height = font_get(data->list->parent[0]->font)->height;
563 /* ds = v*dt */
564 int pixel_diff = data->velocity * RELOAD_INTERVAL / HZ;
565 /* remember signedness to detect stopping */
566 int old_sign = SIGN(data->velocity);
567 /* advance the list */
568 if (!swipe_scroll(data->list, line_height, pixel_diff))
570 /* nothing to scroll? */
571 data->velocity = 0;
573 else
575 /* decelerate by a fixed amount
576 * decrementing v0 over time by the deceleration is
577 * equivalent to computing v = a*t + v0 */
578 data->velocity -= SIGN(data->velocity)*DECELERATION;
579 if (SIGN(data->velocity) != old_sign)
580 data->velocity = 0;
583 queue_post(&button_queue, BUTTON_TOUCHSCREEN, 0);
584 /* stop if the velocity hit or crossed zero */
585 if (!data->velocity)
587 kinetic_stats_reset();
588 return 0;
590 /* let get_action() timeout, which loads to a
591 * gui_synclist_draw() call from the main thread */
592 return RELOAD_INTERVAL; /* cancel or reload */
596 * computes the initial velocity v0 and sets up the timer */
597 static bool kinetic_setup_scroll(struct gui_synclist *list)
599 /* compute initial velocity */
600 int i, _i, v0, len = ARRAYLEN(kinetic_data);
601 for(i = 0, _i = 0, v0 = 0; i < len; i++)
602 { /* in pixel/s */
603 if (kinetic_data[i].ticks > 0)
605 v0 += kinetic_data[i].difference*HZ/kinetic_data[i].ticks;
606 _i++;
609 if (_i > 0)
610 v0 /= _i;
611 else
612 v0 = 0;
614 if (v0 != 0)
616 cb_data.list = list;
617 cb_data.velocity = v0;
618 timeout_register(&kinetic_tmo, kinetic_callback, RELOAD_INTERVAL, (intptr_t)&cb_data);
619 return true;
621 return false;
624 unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
626 short x, y;
627 const enum screen_type screen = SCREEN_MAIN;
628 struct viewport *info_vp = sb_skin_get_info_vp(screen);
629 const int button = action_get_touchscreen_press_in_vp(&x, &y, info_vp);
630 const int list_start_item = gui_list->start_item[screen];
631 const int line_height = font_get(gui_list->parent[screen]->font)->height;
632 const struct viewport *list_text_vp = &list_text[screen];
633 const bool old_released = released;
634 const bool show_title = list_display_title(gui_list, screen);
635 const bool show_cursor = !global_settings.cursor_style &&
636 gui_list->show_selection_marker;
637 const bool on_title_clicked = show_title && y < line_height && (button&BUTTON_REL);
638 const bool cancelled_kinetic = (scroll_mode == SCROLL_KINETIC
639 && button != ACTION_NONE && button != ACTION_UNKNOWN
640 && !is_kinetic_over());
641 int icon_width = 0;
642 int line, list_width = list_text_vp->width;
643 static bool wait_for_release = false;
645 released = (button&BUTTON_REL) != 0;
647 if (released && wait_for_release)
648 { /* was waiting on a release, reset everything so the next call
649 * can start from new */
650 wait_for_release = false;
651 last_position = 0;
652 if (scroll_mode == SCROLL_KINETIC)
653 kinetic_force_stop();
654 scroll_mode = SCROLL_NONE;
655 return ACTION_NONE;
658 if (button == ACTION_NONE || button == ACTION_UNKNOWN)
660 /* this happens when we hit edges of the list while kinetic scrolling,
661 * but not when manually cancelling */
662 if (scroll_mode == SCROLL_KINETIC)
663 return ACTION_REDRAW;
664 return ACTION_NONE;
667 /* x and y are relative to info_vp */
668 if (gui_list->callback_get_item_icon != NULL)
669 icon_width += get_icon_width(screen);
670 if (show_cursor)
671 icon_width += get_icon_width(screen);
673 if (on_title_clicked)
675 if (scroll_mode == SCROLL_NONE || is_kinetic_over())
677 if (x < icon_width)
679 /* Top left corner is GO_TO_ROOT */
680 if (button == BUTTON_REL)
681 return ACTION_STD_MENU;
682 else if (button == (BUTTON_REPEAT|BUTTON_REL))
683 return ACTION_STD_CONTEXT;
684 return ACTION_NONE;
686 else /* click on title text is cancel */
687 if (button == BUTTON_REL)
688 return ACTION_STD_CANCEL;
690 /* do this after the above so the scrolling stops without
691 * going back in the list with the same touch */
692 if (scroll_mode == SCROLL_KINETIC)
694 kinetic_force_stop();
695 scroll_mode = SCROLL_NONE;
698 else /* list area clicked (or not released) */
700 const int actual_y = y - (show_title ? line_height : 0);
701 bool on_scrollbar_clicked;
702 switch (global_settings.scrollbar)
704 case SCROLLBAR_LEFT:
705 on_scrollbar_clicked = x <= SCROLLBAR_WIDTH; break;
706 case SCROLLBAR_RIGHT:
707 on_scrollbar_clicked = x > (icon_width + list_width); break;
708 default:
709 on_scrollbar_clicked = false; break;
711 /* conditions for scrollbar scrolling:
712 * * pen is on the scrollbar
713 * AND scrollbar is on the right (left case is handled above)
714 * OR * pen is in the somewhere else but we did scrollbar scrolling before
716 * scrollbar scrolling must end if the pen is released
717 * scrollbar scrolling must not happen if we're currently scrolling
718 * via swiping the screen
721 if (!released && scroll_mode != SCROLL_SWIPE &&
722 (on_scrollbar_clicked || scroll_mode == SCROLL_BAR))
724 if (scroll_mode == SCROLL_KINETIC)
725 kinetic_force_stop();
726 scroll_mode = SCROLL_BAR;
727 return scrollbar_scroll(gui_list, y);
730 /* |--------------------------------------------------------|
731 * | Description of the touchscreen list interface: |
732 * |--------------------------------------------------------|
733 * | Pressing an item will select it and "enter" it. |
734 * | |
735 * | Pressing and holding your pen down will scroll through |
736 * | the list of items. |
737 * | |
738 * | Pressing and holding your pen down on a single item |
739 * | will bring up the context menu of it. |
740 * |--------------------------------------------------------|
742 if (actual_y > 0 || button & BUTTON_REPEAT)
744 /* selection needs to be corrected if an items are only
745 * partially visible */
746 line = (actual_y - y_offset) / line_height;
748 if (cancelled_kinetic)
750 kinetic_force_stop();
751 scroll_mode = SCROLL_SWIPE;
754 /* Pressed below the list*/
755 if (list_start_item + line >= gui_list->nb_items)
757 /* don't collect last_position outside of the list area
758 * it'd break selecting after such a situation */
759 last_position = 0;
760 return ACTION_NONE;
763 if (button & BUTTON_REPEAT && scroll_mode == SCROLL_NONE
764 && !wait_for_release)
766 /* held a single line for a while, bring up the context menu */
767 gui_synclist_select_item(gui_list, list_start_item + line);
768 /* don't sent context repeatedly */
769 wait_for_release = true;
770 return ACTION_STD_CONTEXT;
772 if (released && !cancelled_kinetic)
774 /* Pen was released anywhere on the screen */
775 last_position = 0;
776 if (scroll_mode == SCROLL_NONE)
778 /* select current line */
779 gui_synclist_select_item(gui_list, list_start_item + line);
780 return ACTION_STD_OK;
782 else
784 /* we were scrolling
785 * -> reset scrolling but do nothing else */
786 if (scroll_mode == SCROLL_SWIPE)
788 if (kinetic_setup_scroll(gui_list))
789 scroll_mode = SCROLL_KINETIC;
791 if (scroll_mode != SCROLL_KINETIC)
792 scroll_mode = SCROLL_NONE;
793 return ACTION_NONE;
796 else
797 { /* pen is on the screen */
798 bool redraw = false, result = false;
799 /* beginning of list interaction denoted by release in
800 * the previous call */
801 if (old_released || is_kinetic_over())
803 scroll_mode = SCROLL_NONE;
804 redraw = true;
807 /* select current item; gui_synclist_select_item()
808 * is not called because it has side effects that
809 * disturb kinetic scrolling */
810 gui_list->selected_item = list_start_item+line;
811 gui_synclist_speak_item(gui_list);
812 if (last_position == 0)
813 last_position = actual_y;
814 else
816 /* record speed data in case we do kinetic scrolling */
817 int diff = actual_y - last_position;
818 kinetic_stats_collect(diff);
819 result = swipe_scroll(gui_list, line_height, diff);
822 /* Start scrolling once the pen is moved without
823 * releasing it inbetween */
824 if (result)
826 redraw = true;
827 scroll_mode = SCROLL_SWIPE;
829 last_position = actual_y;
831 return redraw ? ACTION_REDRAW:ACTION_NONE;
835 return ACTION_REDRAW;
837 #endif