summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/bitmap/list.c129
1 files changed, 65 insertions, 64 deletions
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c
index 79df35b363..5c582ae55e 100644
--- a/apps/gui/bitmap/list.c
+++ b/apps/gui/bitmap/list.c
@@ -70,28 +70,30 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
70{ 70{
71 const int screen = display->screen_type; 71 const int screen = display->screen_type;
72 int style = STYLE_DEFAULT; 72 int style = STYLE_DEFAULT;
73 display->scroll_stop(&title_text[screen]); 73 struct viewport *title_text_vp = &title_text[screen];
74
75 display->scroll_stop(title_text_vp);
74 if (!list_display_title(list, screen)) 76 if (!list_display_title(list, screen))
75 return false; 77 return false;
76 title_text[screen] = *(list->parent[screen]); 78 *title_text_vp = *(list->parent[screen]);
77 title_text[screen].height = font_get(title_text[screen].font)->height; 79 title_text_vp->height = font_get(title_text_vp->font)->height;
78 80
79 if (list->title_icon != Icon_NOICON && global_settings.show_icons) 81 if (list->title_icon != Icon_NOICON && global_settings.show_icons)
80 { 82 {
81 struct viewport title_icon = title_text[screen]; 83 struct viewport title_icon = *title_text_vp;
82 title_icon.width = get_icon_width(screen) 84
83 + ICON_PADDING*2; 85 title_icon.width = get_icon_width(screen) + ICON_PADDING * 2;
84 if (lang_is_rtl()) 86 if (lang_is_rtl())
85 { 87 {
86 title_icon.x = title_text[screen].width - ICON_PADDING - 88 title_icon.x = title_text_vp->width - ICON_PADDING -
87 get_icon_width(screen); 89 get_icon_width(screen);
88 } 90 }
89 else 91 else
90 { 92 {
91 title_icon.x = ICON_PADDING; 93 title_icon.x = ICON_PADDING;
92 title_text[screen].x += title_icon.width; 94 title_text_vp->x += title_icon.width;
93 } 95 }
94 title_text[screen].width -= title_icon.width; 96 title_text_vp->width -= title_icon.width;
95 97
96 display->set_viewport(&title_icon); 98 display->set_viewport(&title_icon);
97 screen_put_icon(display, 0, 0, list->title_icon); 99 screen_put_icon(display, 0, 0, list->title_icon);
@@ -102,7 +104,7 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
102 style |= (STYLE_COLORED|list->title_color); 104 style |= (STYLE_COLORED|list->title_color);
103 } 105 }
104#endif 106#endif
105 display->set_viewport(&title_text[screen]); 107 display->set_viewport(title_text_vp);
106 display->puts_scroll_style(0, 0, list->title, style); 108 display->puts_scroll_style(0, 0, list->title, style);
107 return true; 109 return true;
108} 110}
@@ -110,9 +112,11 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
110void list_draw(struct screen *display, struct gui_synclist *list) 112void list_draw(struct screen *display, struct gui_synclist *list)
111{ 113{
112 struct viewport list_icons; 114 struct viewport list_icons;
113 int start, end, line_height, style, i, scrollbar_in_left; 115 int start, end, line_height, style, i;
114 const int screen = display->screen_type; 116 const int screen = display->screen_type;
117 const int list_start_item = list->start_item[screen];
115 const int icon_width = get_icon_width(screen) + ICON_PADDING; 118 const int icon_width = get_icon_width(screen) + ICON_PADDING;
119 const int scrollbar_in_left = global_settings.scrollbar == SCROLLBAR_LEFT;
116 const bool show_cursor = !global_settings.cursor_style && 120 const bool show_cursor = !global_settings.cursor_style &&
117 list->show_selection_marker; 121 list->show_selection_marker;
118 struct viewport *parent = (list->parent[screen]); 122 struct viewport *parent = (list->parent[screen]);
@@ -121,71 +125,67 @@ void list_draw(struct screen *display, struct gui_synclist *list)
121#endif 125#endif
122 int item_offset, is_rtl = lang_is_rtl(); 126 int item_offset, is_rtl = lang_is_rtl();
123 bool show_title; 127 bool show_title;
128 struct viewport *list_text_vp = &list_text[screen];
129
124 line_height = font_get(parent->font)->height; 130 line_height = font_get(parent->font)->height;
125 display->set_viewport(parent); 131 display->set_viewport(parent);
126 display->clear_viewport(); 132 display->clear_viewport();
127 display->scroll_stop(&list_text[screen]); 133 display->scroll_stop(list_text_vp);
128 list_text[screen] = *parent; 134 *list_text_vp = *parent;
129 if ((show_title = draw_title(display, list))) 135 if ((show_title = draw_title(display, list)))
130 { 136 {
131 list_text[screen].y += line_height; 137 list_text_vp->y += line_height;
132 list_text[screen].height -= line_height; 138 list_text_vp->height -= line_height;
133 } 139 }
134 140
135 start = list->start_item[screen]; 141 start = list_start_item;
136 end = start + viewport_get_nb_lines(&list_text[screen]); 142 end = start + viewport_get_nb_lines(list_text_vp);
137
138 scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT);
139 143
140 /* draw the scrollbar if its needed */ 144 /* draw the scrollbar if its needed */
141 if (global_settings.scrollbar && 145 if (global_settings.scrollbar &&
142 viewport_get_nb_lines(&list_text[screen]) < list->nb_items) 146 viewport_get_nb_lines(list_text_vp) < list->nb_items)
143 { 147 {
144 struct viewport vp; 148 struct viewport vp;
145 vp = list_text[screen]; 149 vp = *list_text_vp;
146 vp.width = SCROLLBAR_WIDTH; 150 vp.width = SCROLLBAR_WIDTH;
147 vp.height = line_height * 151 vp.height = line_height * viewport_get_nb_lines(list_text_vp);
148 viewport_get_nb_lines(&list_text[screen]);
149 vp.x = parent->x; 152 vp.x = parent->x;
150 list_text[screen].width -= SCROLLBAR_WIDTH; 153 list_text_vp->width -= SCROLLBAR_WIDTH;
151 if (scrollbar_in_left) 154 if (scrollbar_in_left)
152 list_text[screen].x += SCROLLBAR_WIDTH; 155 list_text_vp->x += SCROLLBAR_WIDTH;
153 else 156 else
154 vp.x += list_text[screen].width; 157 vp.x += list_text_vp->width;
155 display->set_viewport(&vp); 158 display->set_viewport(&vp);
156 gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH-1, 159 gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH-1, vp.height,
157 vp.height, list->nb_items, 160 list->nb_items, list_start_item, list_start_item + end-start,
158 list->start_item[screen], 161 VERTICAL);
159 list->start_item[screen] + end-start,
160 VERTICAL);
161 } 162 }
162 else if (show_title) 163 else if (show_title)
163 { 164 {
164 /* shift everything a bit in relation to the title... */ 165 /* shift everything a bit in relation to the title... */
165 if (scrollbar_in_left) 166 if (scrollbar_in_left)
166 { 167 {
167 list_text[screen].width -= SCROLLBAR_WIDTH; 168 list_text_vp->width -= SCROLLBAR_WIDTH;
168 list_text[screen].x += SCROLLBAR_WIDTH; 169 list_text_vp->x += SCROLLBAR_WIDTH;
169 } 170 }
170 } 171 }
171 172
172 /* setup icon placement */ 173 /* setup icon placement */
173 list_icons = list_text[screen]; 174 list_icons = *list_text_vp;
174 int icon_count = global_settings.show_icons && 175 int icon_count = global_settings.show_icons &&
175 (list->callback_get_item_icon != NULL) ? 1 : 0; 176 (list->callback_get_item_icon != NULL) ? 1 : 0;
176 if (show_cursor) 177 if (show_cursor)
177 icon_count++; 178 icon_count++;
178 if (icon_count) 179 if (icon_count)
179 { 180 {
180 list_icons.width = icon_width * icon_count; 181 list_icons.width = icon_width * icon_count;
181 list_text[screen].width -= 182 list_text_vp->width -= list_icons.width + ICON_PADDING;
182 list_icons.width + ICON_PADDING;
183 if (is_rtl) 183 if (is_rtl)
184 list_icons.x += list_text[screen].width; 184 list_icons.x += list_text_vp->width;
185 else 185 else
186 list_text[screen].x += list_icons.width + ICON_PADDING; 186 list_text_vp->x += list_icons.width + ICON_PADDING;
187 } 187 }
188 188
189 for (i=start; i<end && i<list->nb_items; i++) 189 for (i=start; i<end && i<list->nb_items; i++)
190 { 190 {
191 /* do the text */ 191 /* do the text */
@@ -196,14 +196,13 @@ void list_draw(struct screen *display, struct gui_synclist *list)
196 s = list->callback_get_item_name(i, list->data, entry_buffer, 196 s = list->callback_get_item_name(i, list->data, entry_buffer,
197 sizeof(entry_buffer)); 197 sizeof(entry_buffer));
198 entry_name = P2STR(s); 198 entry_name = P2STR(s);
199 display->set_viewport(&list_text[screen]); 199 display->set_viewport(list_text_vp);
200 style = STYLE_DEFAULT; 200 style = STYLE_DEFAULT;
201 /* position the string at the correct offset place */ 201 /* position the string at the correct offset place */
202 int item_width,h; 202 int item_width,h;
203 display->getstringsize(entry_name, &item_width, &h); 203 display->getstringsize(entry_name, &item_width, &h);
204 item_offset = gui_list_get_item_offset(list, item_width, 204 item_offset = gui_list_get_item_offset(list, item_width, text_pos,
205 text_pos, display, 205 display, list_text_vp);
206 &list_text[screen]);
207 206
208#ifdef HAVE_LCD_COLOR 207#ifdef HAVE_LCD_COLOR
209 /* if the list has a color callback */ 208 /* if the list has a color callback */
@@ -222,7 +221,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
222 {/* The selected item must be displayed scrolling */ 221 {/* The selected item must be displayed scrolling */
223 if (global_settings.cursor_style == 1 222 if (global_settings.cursor_style == 1
224#ifdef HAVE_REMOTE_LCD 223#ifdef HAVE_REMOTE_LCD
225 /* the global_settings.cursor_style check is here to make 224 /* the global_settings.cursor_style check is here to make
226 * sure if they want the cursor instead of bar it will work 225 * sure if they want the cursor instead of bar it will work
227 */ 226 */
228 || (display->depth < 16 && global_settings.cursor_style) 227 || (display->depth < 16 && global_settings.cursor_style)
@@ -253,8 +252,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
253 } 252 }
254#endif 253#endif
255 /* if the text is smaller than the viewport size */ 254 /* if the text is smaller than the viewport size */
256 if (item_offset> item_width 255 if (item_offset> item_width - (list_text_vp->width - text_pos))
257 - (list_text[screen].width - text_pos))
258 { 256 {
259 /* don't scroll */ 257 /* don't scroll */
260 display->puts_style_offset(0, i-start, entry_name, 258 display->puts_style_offset(0, i-start, entry_name,
@@ -307,8 +305,9 @@ static bool scrolling=false;
307static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list, 305static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list,
308 int y) 306 int y)
309{ 307{
310 int screen = screens[SCREEN_MAIN].screen_type; 308 const int screen = screens[SCREEN_MAIN].screen_type;
311 int nb_lines = viewport_get_nb_lines(&list_text[screen]); 309 const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
310
312 if (nb_lines < gui_list->nb_items) 311 if (nb_lines < gui_list->nb_items)
313 { 312 {
314 scrolling = true; 313 scrolling = true;
@@ -338,13 +337,16 @@ static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list,
338unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list) 337unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
339{ 338{
340 short x, y; 339 short x, y;
341 int button = action_get_touchscreen_press(&x, &y); 340 const int button = action_get_touchscreen_press(&x, &y);
342 int line; 341 int line;
343 struct screen *display = &screens[SCREEN_MAIN]; 342 const struct screen *display = &screens[SCREEN_MAIN];
344 int screen = display->screen_type; 343 const int screen = display->screen_type;
344 const int list_start_item = gui_list->start_item[screen];
345 const struct viewport *list_text_vp = &list_text[screen];
346
345 if (button == BUTTON_NONE) 347 if (button == BUTTON_NONE)
346 return ACTION_NONE; 348 return ACTION_NONE;
347 if (x<list_text[screen].x) 349 if (x < list_text_vp->x)
348 { 350 {
349 /* Top left corner is GO_TO_ROOT */ 351 /* Top left corner is GO_TO_ROOT */
350 if (y<list_text[SCREEN_MAIN].y) 352 if (y<list_text[SCREEN_MAIN].y)
@@ -362,7 +364,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
362 } 364 }
363 else 365 else
364 { 366 {
365 if(x>list_text[screen].x+list_text[screen].width && 367 if (x > list_text_vp->x + list_text_vp->width &&
366 global_settings.scrollbar == SCROLLBAR_RIGHT) 368 global_settings.scrollbar == SCROLLBAR_RIGHT)
367 return gui_synclist_touchscreen_scrollbar(gui_list, y); 369 return gui_synclist_touchscreen_scrollbar(gui_list, y);
368 370
@@ -378,30 +380,29 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
378 * | will bring up the context menu of it. | 380 * | will bring up the context menu of it. |
379 * |--------------------------------------------------------| 381 * |--------------------------------------------------------|
380 */ 382 */
381 if (y > list_text[screen].y || button & BUTTON_REPEAT) 383 if (y > list_text_vp->y || button & BUTTON_REPEAT)
382 { 384 {
383 int line_height, actual_y; 385 int line_height, actual_y;
384 386
385 actual_y = y - list_text[screen].y; 387 actual_y = y - list_text_vp->y;
386 line_height = font_get(gui_list->parent[screen]->font)->height; 388 line_height = font_get(gui_list->parent[screen]->font)->height;
387 line = actual_y / line_height; 389 line = actual_y / line_height;
388 390
389 /* Pressed below the list*/ 391 /* Pressed below the list*/
390 if (gui_list->start_item[screen]+line >= gui_list->nb_items) 392 if (list_start_item + line >= gui_list->nb_items)
391 return ACTION_NONE; 393 return ACTION_NONE;
392 394
393 /* Pressed a border */ 395 /* Pressed a border */
394 if(UNLIKELY(actual_y % line_height == 0)) 396 if(UNLIKELY(actual_y % line_height == 0))
395 return ACTION_NONE; 397 return ACTION_NONE;
396 398
397 if (line != (gui_list->selected_item - gui_list->start_item[screen]) 399 if (line != (gui_list->selected_item - list_start_item)
398 && button ^ BUTTON_REL) 400 && button ^ BUTTON_REL)
399 { 401 {
400 if(button & BUTTON_REPEAT) 402 if(button & BUTTON_REPEAT)
401 scrolling = true; 403 scrolling = true;
402 404
403 gui_synclist_select_item(gui_list, gui_list->start_item[screen] 405 gui_synclist_select_item(gui_list, list_start_item + line);
404 + line);
405 406
406 return ACTION_REDRAW; 407 return ACTION_REDRAW;
407 } 408 }
@@ -412,7 +413,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
412 dead zones) 413 dead zones)
413 */ 414 */
414 if(global_settings.scrollbar == SCROLLBAR_RIGHT && 415 if(global_settings.scrollbar == SCROLLBAR_RIGHT &&
415 x > list_text[screen].x + list_text[screen].width - 416 x > list_text_vp->x + list_text_vp->width -
416 get_icon_width(SCREEN_MAIN)) 417 get_icon_width(SCREEN_MAIN))
417 return ACTION_NONE; 418 return ACTION_NONE;
418 419
@@ -437,7 +438,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
437 } 438 }
438 } 439 }
439 else if(button == BUTTON_REL && 440 else if(button == BUTTON_REL &&
440 line == gui_list->selected_item - gui_list->start_item[screen]) 441 line == gui_list->selected_item - list_start_item)
441 { 442 {
442 /* Pen was released on either the same line as the previously 443 /* Pen was released on either the same line as the previously
443 * selected one or an other one 444 * selected one or an other one
@@ -449,7 +450,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
449 return ACTION_NONE; 450 return ACTION_NONE;
450 } 451 }
451 /* Everything above the items is cancel */ 452 /* Everything above the items is cancel */
452 else if (y < list_text[screen].y && button == BUTTON_REL) 453 else if (y < list_text_vp->.y && button == BUTTON_REL)
453 return ACTION_STD_CANCEL; 454 return ACTION_STD_CANCEL;
454 } 455 }
455 return ACTION_NONE; 456 return ACTION_NONE;