Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Jonathan Gordon |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | /* This file contains the code to draw the list widget on BITMAP LCDs. */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "lcd.h" |
| 26 | #include "font.h" |
| 27 | #include "button.h" |
| 28 | #include "sprintf.h" |
| 29 | #include "string.h" |
| 30 | #include "settings.h" |
| 31 | #include "kernel.h" |
| 32 | #include "system.h" |
Nils Wallménius | 4f87976 | 2009-08-19 21:48:17 +0000 | [diff] [blame] | 33 | #include "file.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 34 | |
| 35 | #include "action.h" |
| 36 | #include "screen_access.h" |
| 37 | #include "list.h" |
| 38 | #include "scrollbar.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 39 | #include "lang.h" |
| 40 | #include "sound.h" |
| 41 | #include "misc.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 42 | #include "viewport.h" |
| 43 | |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 44 | #define ICON_PADDING 1 |
| 45 | |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 46 | /* these are static to make scrolling work */ |
| 47 | static struct viewport list_text[NB_SCREENS], title_text[NB_SCREENS]; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 48 | |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 49 | int gui_list_get_item_offset(struct gui_synclist * gui_list, int item_width, |
| 50 | int text_pos, struct screen * display, |
| 51 | struct viewport *vp); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 52 | bool list_display_title(struct gui_synclist *list, enum screen_type screen); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 53 | |
| 54 | /* Draw the list... |
| 55 | internal screen layout: |
| 56 | ----------------- |
| 57 | |TI| title | TI is title icon |
| 58 | ----------------- |
| 59 | | | | | |
| 60 | |S|I| | S - scrollbar |
| 61 | | | | items | I - icons |
| 62 | | | | | |
| 63 | ------------------ |
| 64 | */ |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 65 | static bool draw_title(struct screen *display, struct gui_synclist *list) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 66 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 67 | const int screen = display->screen_type; |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 68 | int style = STYLE_DEFAULT; |
Thomas Martitz | 3c47d94 | 2009-09-04 16:34:55 +0000 | [diff] [blame] | 69 | display->scroll_stop(&title_text[screen]); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 70 | if (!list_display_title(list, screen)) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 71 | return false; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 72 | title_text[screen] = *(list->parent[screen]); |
Thomas Martitz | 0dd6641 | 2009-01-28 18:06:58 +0000 | [diff] [blame] | 73 | title_text[screen].height = font_get(title_text[screen].font)->height; |
| 74 | |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 75 | if (list->title_icon != Icon_NOICON && global_settings.show_icons) |
| 76 | { |
Thomas Martitz | 0dd6641 | 2009-01-28 18:06:58 +0000 | [diff] [blame] | 77 | struct viewport title_icon = title_text[screen]; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 78 | title_icon.width = get_icon_width(screen) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 79 | + ICON_PADDING*2; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 80 | title_icon.x += ICON_PADDING; |
| 81 | |
Thomas Martitz | 0dd6641 | 2009-01-28 18:06:58 +0000 | [diff] [blame] | 82 | title_text[screen].width -= title_icon.width; |
| 83 | title_text[screen].x += title_icon.width; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 84 | |
| 85 | display->set_viewport(&title_icon); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 86 | screen_put_icon(display, 0, 0, list->title_icon); |
| 87 | } |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 88 | #ifdef HAVE_LCD_COLOR |
| 89 | if (list->title_color >= 0) |
| 90 | { |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 91 | style |= (STYLE_COLORED|list->title_color); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 92 | } |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 93 | #endif |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 94 | display->set_viewport(&title_text[screen]); |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 95 | display->puts_scroll_style(0, 0, list->title, style); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 96 | return true; |
| 97 | } |
Maurus Cuelenaere | 07b2708 | 2009-08-22 21:46:02 +0000 | [diff] [blame] | 98 | |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 99 | void list_draw(struct screen *display, struct gui_synclist *list) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 100 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 101 | struct viewport list_icons; |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 102 | int start, end, line_height, style, i; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 103 | const int screen = display->screen_type; |
| 104 | const int icon_width = get_icon_width(screen) + ICON_PADDING; |
| 105 | const bool show_cursor = !global_settings.cursor_style && |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 106 | list->show_selection_marker; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 107 | struct viewport *parent = (list->parent[screen]); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 108 | #ifdef HAVE_LCD_COLOR |
| 109 | unsigned char cur_line = 0; |
| 110 | #endif |
| 111 | int item_offset; |
| 112 | bool show_title; |
| 113 | line_height = font_get(parent->font)->height; |
| 114 | display->set_viewport(parent); |
| 115 | display->clear_viewport(); |
Thomas Martitz | 3c47d94 | 2009-09-04 16:34:55 +0000 | [diff] [blame] | 116 | display->scroll_stop(&list_text[screen]); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 117 | list_text[screen] = *parent; |
| 118 | if ((show_title = draw_title(display, list))) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 119 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 120 | list_text[screen].y += line_height; |
| 121 | list_text[screen].height -= line_height; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 122 | } |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 123 | |
| 124 | start = list->start_item[screen]; |
| 125 | end = start + viewport_get_nb_lines(&list_text[screen]); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 126 | |
| 127 | /* draw the scrollbar if its needed */ |
| 128 | if (global_settings.scrollbar && |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 129 | viewport_get_nb_lines(&list_text[screen]) < list->nb_items) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 130 | { |
| 131 | struct viewport vp; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 132 | vp = list_text[screen]; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 133 | vp.width = SCROLLBAR_WIDTH; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 134 | list_text[screen].width -= SCROLLBAR_WIDTH; |
Alexander Levin | 07d0bfd | 2009-08-19 12:36:40 +0000 | [diff] [blame] | 135 | if(global_settings.scrollbar == SCROLLBAR_LEFT) |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 136 | list_text[screen].x += SCROLLBAR_WIDTH; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 137 | vp.height = line_height * |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 138 | viewport_get_nb_lines(&list_text[screen]); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 139 | vp.x = parent->x; |
Alexander Levin | 23e534d | 2009-08-19 12:38:16 +0000 | [diff] [blame] | 140 | if(global_settings.scrollbar == SCROLLBAR_RIGHT) |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 141 | vp.x += list_text[screen].width; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 142 | display->set_viewport(&vp); |
| 143 | gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH-1, |
| 144 | vp.height, list->nb_items, |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 145 | list->start_item[screen], |
| 146 | list->start_item[screen] + end-start, |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 147 | VERTICAL); |
| 148 | } |
| 149 | else if (show_title) |
| 150 | { |
| 151 | /* shift everything right a bit... */ |
Alexander Levin | 07d0bfd | 2009-08-19 12:36:40 +0000 | [diff] [blame] | 152 | if(global_settings.scrollbar == SCROLLBAR_LEFT) |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 153 | { |
| 154 | list_text[screen].width -= SCROLLBAR_WIDTH; |
| 155 | list_text[screen].x += SCROLLBAR_WIDTH; |
| 156 | } |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* setup icon placement */ |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 160 | list_icons = list_text[screen]; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 161 | int icon_count = global_settings.show_icons && |
| 162 | (list->callback_get_item_icon != NULL) ? 1 : 0; |
| 163 | if (show_cursor) |
| 164 | icon_count++; |
| 165 | if (icon_count) |
| 166 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 167 | list_icons.width = icon_width * icon_count; |
| 168 | list_text[screen].width -= |
| 169 | list_icons.width + ICON_PADDING; |
| 170 | list_text[screen].x += |
| 171 | list_icons.width + ICON_PADDING; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | for (i=start; i<end && i<list->nb_items; i++) |
| 175 | { |
| 176 | /* do the text */ |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 177 | unsigned const char *s; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 178 | char entry_buffer[MAX_PATH]; |
| 179 | unsigned char *entry_name; |
| 180 | int text_pos = 0; |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 181 | s = list->callback_get_item_name(i, list->data, entry_buffer, |
| 182 | sizeof(entry_buffer)); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 183 | entry_name = P2STR(s); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 184 | display->set_viewport(&list_text[screen]); |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 185 | style = STYLE_DEFAULT; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 186 | /* position the string at the correct offset place */ |
| 187 | int item_width,h; |
| 188 | display->getstringsize(entry_name, &item_width, &h); |
| 189 | item_offset = gui_list_get_item_offset(list, item_width, |
| 190 | text_pos, display, |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 191 | &list_text[screen]); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 192 | |
| 193 | #ifdef HAVE_LCD_COLOR |
| 194 | /* if the list has a color callback */ |
| 195 | if (list->callback_get_item_color) |
| 196 | { |
| 197 | int color = list->callback_get_item_color(i, list->data); |
| 198 | /* if color selected */ |
| 199 | if (color >= 0) |
| 200 | { |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 201 | style |= STYLE_COLORED|color; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | #endif |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 205 | if(i >= list->selected_item && i < list->selected_item |
| 206 | + list->selected_size && list->show_selection_marker) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 207 | {/* The selected item must be displayed scrolling */ |
Jonathan Gordon | 34196ed | 2008-04-03 04:41:42 +0000 | [diff] [blame] | 208 | if (global_settings.cursor_style == 1 |
| 209 | #ifdef HAVE_REMOTE_LCD |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 210 | /* the global_settings.cursor_style check is here to make |
| 211 | * sure if they want the cursor instead of bar it will work |
| 212 | */ |
Jonathan Gordon | 34196ed | 2008-04-03 04:41:42 +0000 | [diff] [blame] | 213 | || (display->depth < 16 && global_settings.cursor_style) |
| 214 | #endif |
| 215 | ) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 216 | { |
| 217 | /* Display inverted-line-style */ |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 218 | style = STYLE_INVERT; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 219 | } |
| 220 | #ifdef HAVE_LCD_COLOR |
| 221 | else if (global_settings.cursor_style == 2) |
| 222 | { |
| 223 | /* Display colour line selector */ |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 224 | style = STYLE_COLORBAR; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 225 | } |
| 226 | else if (global_settings.cursor_style == 3) |
| 227 | { |
| 228 | /* Display gradient line selector */ |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 229 | style = STYLE_GRADIENT; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 230 | |
| 231 | /* Make the lcd driver know how many lines the gradient should |
| 232 | cover and current line number */ |
| 233 | /* number of selected lines */ |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 234 | style |= NUMLN_PACK(list->selected_size); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 235 | /* current line number, zero based */ |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 236 | style |= CURLN_PACK(cur_line); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 237 | cur_line++; |
| 238 | } |
| 239 | #endif |
| 240 | /* if the text is smaller than the viewport size */ |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 241 | if (item_offset> item_width |
| 242 | - (list_text[screen].width - text_pos)) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 243 | { |
| 244 | /* don't scroll */ |
| 245 | display->puts_style_offset(0, i-start, entry_name, |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 246 | style, item_offset); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 247 | } |
| 248 | else |
| 249 | { |
| 250 | display->puts_scroll_style_offset(0, i-start, entry_name, |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 251 | style, item_offset); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | else |
Jonathan Gordon | 311d048 | 2008-07-05 12:31:04 +0000 | [diff] [blame] | 255 | { |
| 256 | if (list->scroll_all) |
| 257 | display->puts_scroll_style_offset(0, i-start, entry_name, |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 258 | style, item_offset); |
Jonathan Gordon | 311d048 | 2008-07-05 12:31:04 +0000 | [diff] [blame] | 259 | else |
| 260 | display->puts_style_offset(0, i-start, entry_name, |
Jens Arnold | 3f69bb2 | 2009-03-08 12:42:33 +0000 | [diff] [blame] | 261 | style, item_offset); |
Jonathan Gordon | 311d048 | 2008-07-05 12:31:04 +0000 | [diff] [blame] | 262 | } |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 263 | /* do the icon */ |
| 264 | if (list->callback_get_item_icon && global_settings.show_icons) |
| 265 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 266 | display->set_viewport(&list_icons); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 267 | screen_put_icon_with_offset(display, show_cursor?1:0, |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 268 | (i-start),show_cursor?ICON_PADDING:0,0, |
| 269 | list->callback_get_item_icon(i, list->data)); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 270 | if (show_cursor && i >= list->selected_item && |
| 271 | i < list->selected_item + list->selected_size) |
| 272 | { |
| 273 | screen_put_icon(display, 0, i-start, Icon_Cursor); |
| 274 | } |
| 275 | } |
| 276 | else if (show_cursor && i >= list->selected_item && |
| 277 | i < list->selected_item + list->selected_size) |
| 278 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 279 | display->set_viewport(&list_icons); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 280 | screen_put_icon(display, 0, (i-start), Icon_Cursor); |
| 281 | } |
| 282 | } |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 283 | display->set_viewport(parent); |
| 284 | display->update_viewport(); |
Jonathan Gordon | f9329e4 | 2009-01-07 07:52:32 +0000 | [diff] [blame] | 285 | display->set_viewport(NULL); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Maurus Cuelenaere | 1392dc2 | 2008-08-23 09:46:38 +0000 | [diff] [blame] | 288 | #if defined(HAVE_TOUCHSCREEN) |
Maurus Cuelenaere | 94419e9 | 2009-08-22 23:35:27 +0000 | [diff] [blame] | 289 | /* This needs to be fixed if we ever get more than 1 touchscreen on a target. */ |
Maurus Cuelenaere | 75cac2c | 2008-06-02 18:59:32 +0000 | [diff] [blame] | 290 | static bool scrolling=false; |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 291 | |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 292 | static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list, |
| 293 | int y) |
| 294 | { |
| 295 | int screen = screens[SCREEN_MAIN].screen_type; |
| 296 | int nb_lines = viewport_get_nb_lines(&list_text[screen]); |
| 297 | if (nb_lines < gui_list->nb_items) |
| 298 | { |
Maurus Cuelenaere | 07b2708 | 2009-08-22 21:46:02 +0000 | [diff] [blame] | 299 | scrolling = true; |
| 300 | |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 301 | int scrollbar_size = nb_lines* |
| 302 | font_get(gui_list->parent[screen]->font)->height; |
| 303 | int actual_y = y - list_text[screen].y; |
| 304 | |
| 305 | int new_selection = (actual_y * gui_list->nb_items) |
| 306 | / scrollbar_size; |
| 307 | |
| 308 | int start_item = new_selection - nb_lines/2; |
| 309 | if(start_item < 0) |
| 310 | start_item = 0; |
| 311 | else if(start_item > gui_list->nb_items - nb_lines) |
| 312 | start_item = gui_list->nb_items - nb_lines; |
| 313 | |
| 314 | gui_list->start_item[screen] = start_item; |
| 315 | gui_synclist_select_item(gui_list, new_selection); |
| 316 | |
| 317 | return ACTION_REDRAW; |
| 318 | } |
| 319 | |
| 320 | return ACTION_NONE; |
| 321 | } |
| 322 | |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 323 | unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 324 | { |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 325 | short x, y; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 326 | int button = action_get_touchscreen_press(&x, &y); |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 327 | int line; |
| 328 | struct screen *display = &screens[SCREEN_MAIN]; |
Jonathan Gordon | 79b3e87 | 2008-12-31 06:11:23 +0000 | [diff] [blame] | 329 | int screen = display->screen_type; |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 330 | if (button == BUTTON_NONE) |
| 331 | return ACTION_NONE; |
Jonathan Gordon | 79b3e87 | 2008-12-31 06:11:23 +0000 | [diff] [blame] | 332 | if (x<list_text[screen].x) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 333 | { |
Maurus Cuelenaere | 39be5ff | 2009-02-12 15:58:55 +0000 | [diff] [blame] | 334 | /* Top left corner is GO_TO_ROOT */ |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 335 | if (y<list_text[SCREEN_MAIN].y) |
| 336 | { |
| 337 | if (button == BUTTON_REL) |
| 338 | return ACTION_STD_MENU; |
Maurus Cuelenaere | 5dca53e | 2008-06-01 13:56:34 +0000 | [diff] [blame] | 339 | else if (button == (BUTTON_REPEAT|BUTTON_REL)) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 340 | return ACTION_STD_CONTEXT; |
| 341 | else |
| 342 | return ACTION_NONE; |
| 343 | } |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 344 | /* Scroll bar */ |
Alexander Levin | 07d0bfd | 2009-08-19 12:36:40 +0000 | [diff] [blame] | 345 | else if(global_settings.scrollbar == SCROLLBAR_LEFT) |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 346 | return gui_synclist_touchscreen_scrollbar(gui_list, y); |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 347 | } |
| 348 | else |
| 349 | { |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 350 | if(x>list_text[screen].x+list_text[screen].width && |
Alexander Levin | 07d0bfd | 2009-08-19 12:36:40 +0000 | [diff] [blame] | 351 | global_settings.scrollbar == SCROLLBAR_RIGHT) |
Maurus Cuelenaere | daaecb9 | 2009-08-17 23:36:49 +0000 | [diff] [blame] | 352 | return gui_synclist_touchscreen_scrollbar(gui_list, y); |
| 353 | |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 354 | /* |--------------------------------------------------------| |
| 355 | * | Description of the touchscreen list interface: | |
| 356 | * |--------------------------------------------------------| |
| 357 | * | Pressing an item will select it and "enter" it. | |
| 358 | * | | |
| 359 | * | Pressing and holding your pen down will scroll through | |
Maurus Cuelenaere | 75cac2c | 2008-06-02 18:59:32 +0000 | [diff] [blame] | 360 | * | the list of items. | |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 361 | * | | |
| 362 | * | Pressing and holding your pen down on a single item | |
| 363 | * | will bring up the context menu of it. | |
| 364 | * |--------------------------------------------------------| |
| 365 | */ |
Maurus Cuelenaere | 39be5ff | 2009-02-12 15:58:55 +0000 | [diff] [blame] | 366 | if (y > list_text[screen].y || button & BUTTON_REPEAT) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 367 | { |
Maurus Cuelenaere | 4bbdc5c | 2008-06-06 18:44:59 +0000 | [diff] [blame] | 368 | int line_height, actual_y; |
Maurus Cuelenaere | e1753de | 2008-06-06 18:29:46 +0000 | [diff] [blame] | 369 | |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 370 | actual_y = y - list_text[screen].y; |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 371 | line_height = font_get(gui_list->parent[screen]->font)->height; |
Maurus Cuelenaere | e1753de | 2008-06-06 18:29:46 +0000 | [diff] [blame] | 372 | line = actual_y / line_height; |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 373 | |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 374 | /* Pressed below the list*/ |
| 375 | if (gui_list->start_item[screen]+line >= gui_list->nb_items) |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 376 | return ACTION_NONE; |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 377 | |
| 378 | /* Pressed a border */ |
| 379 | if(UNLIKELY(actual_y % line_height == 0)) |
Maurus Cuelenaere | 3d240f1 | 2008-06-28 20:11:51 +0000 | [diff] [blame] | 380 | return ACTION_NONE; |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 381 | |
| 382 | if (line != (gui_list->selected_item - gui_list->start_item[screen]) |
| 383 | && button ^ BUTTON_REL) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 384 | { |
Maurus Cuelenaere | 75cac2c | 2008-06-02 18:59:32 +0000 | [diff] [blame] | 385 | if(button & BUTTON_REPEAT) |
| 386 | scrolling = true; |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 387 | |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 388 | gui_synclist_select_item(gui_list, gui_list->start_item[screen] |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 389 | + line); |
| 390 | |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 391 | return ACTION_REDRAW; |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 392 | } |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 393 | |
Maurus Cuelenaere | 4ce82b9 | 2009-08-22 22:48:03 +0000 | [diff] [blame] | 394 | /* This has the same effect as the icons do when the scrollbar |
| 395 | is on the left (ie eliminate the chances an user enters/starts |
| 396 | an item when he wanted to use the scrollbar, due to touchscreen |
| 397 | dead zones) |
| 398 | */ |
| 399 | if(global_settings.scrollbar == SCROLLBAR_RIGHT && |
| 400 | x > list_text[screen].x + list_text[screen].width - |
Maurus Cuelenaere | 94419e9 | 2009-08-22 23:35:27 +0000 | [diff] [blame] | 401 | get_icon_width(SCREEN_MAIN)) |
Maurus Cuelenaere | 4ce82b9 | 2009-08-22 22:48:03 +0000 | [diff] [blame] | 402 | return ACTION_NONE; |
| 403 | |
Maurus Cuelenaere | 5dca53e | 2008-06-01 13:56:34 +0000 | [diff] [blame] | 404 | if (button == (BUTTON_REPEAT|BUTTON_REL)) |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 405 | { |
Maurus Cuelenaere | 75cac2c | 2008-06-02 18:59:32 +0000 | [diff] [blame] | 406 | if(!scrolling) |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 407 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 408 | /* Pen was hold on the same line as the |
| 409 | * previously selected one |
| 410 | * => simulate long button press |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 411 | */ |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 412 | return ACTION_STD_CONTEXT; |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 413 | } |
| 414 | else |
| 415 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 416 | /* Pen was moved across several lines and then released on |
| 417 | * this one |
| 418 | * => do nothing |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 419 | */ |
Maurus Cuelenaere | 75cac2c | 2008-06-02 18:59:32 +0000 | [diff] [blame] | 420 | scrolling = false; |
| 421 | return ACTION_NONE; |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 424 | else if(button == BUTTON_REL && |
| 425 | line == gui_list->selected_item - gui_list->start_item[screen]) |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 426 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 427 | /* Pen was released on either the same line as the previously |
| 428 | * selected one or an other one |
Maurus Cuelenaere | cad30d3 | 2008-06-02 16:08:01 +0000 | [diff] [blame] | 429 | * => simulate short press |
| 430 | */ |
| 431 | return ACTION_STD_OK; |
| 432 | } |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 433 | else |
Maurus Cuelenaere | 944219b | 2008-05-30 22:55:24 +0000 | [diff] [blame] | 434 | return ACTION_NONE; |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 435 | } |
Maurus Cuelenaere | 21ca866 | 2009-02-19 16:16:22 +0000 | [diff] [blame] | 436 | /* Everything above the items is cancel */ |
| 437 | else if (y < list_text[screen].y && button == BUTTON_REL) |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 438 | return ACTION_STD_CANCEL; |
Jonathan Gordon | f444f1e | 2008-03-05 10:38:10 +0000 | [diff] [blame] | 439 | } |
| 440 | return ACTION_NONE; |
| 441 | } |
| 442 | #endif |