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