1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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. */
36 #include "screen_access.h"
38 #include "scrollbar.h"
44 #define ICON_PADDING 1
46 /* these are static to make scrolling work */
47 static struct viewport list_text
[NB_SCREENS
], title_text
[NB_SCREENS
];
49 int gui_list_get_item_offset(struct gui_synclist
* gui_list
, int item_width
,
50 int text_pos
, struct screen
* display
,
52 bool list_display_title(struct gui_synclist
*list
, enum screen_type screen
);
55 internal screen layout:
57 |TI| title | TI is title icon
61 | | | items | I - icons
65 Note: This image is flipped horizontally when the language is a
66 right-to-left one (Hebrew, Arabic)
68 static bool draw_title(struct screen
*display
, struct gui_synclist
*list
)
70 const int screen
= display
->screen_type
;
71 int style
= STYLE_DEFAULT
;
72 struct viewport
*title_text_vp
= &title_text
[screen
];
74 display
->scroll_stop(title_text_vp
);
75 if (!list_display_title(list
, screen
))
77 *title_text_vp
= *(list
->parent
[screen
]);
78 title_text_vp
->height
= font_get(title_text_vp
->font
)->height
;
80 if (list
->title_icon
!= Icon_NOICON
&& global_settings
.show_icons
)
82 struct viewport title_icon
= *title_text_vp
;
84 title_icon
.width
= get_icon_width(screen
) + ICON_PADDING
* 2;
85 if (VP_IS_RTL(&title_icon
))
87 title_icon
.x
+= title_text_vp
->width
- title_icon
.width
;
91 title_text_vp
->x
+= title_icon
.width
;
93 title_text_vp
->width
-= title_icon
.width
;
95 display
->set_viewport(&title_icon
);
96 screen_put_icon(display
, 0, 0, list
->title_icon
);
99 if (list
->title_color
>= 0)
101 style
|= (STYLE_COLORED
|list
->title_color
);
104 display
->set_viewport(title_text_vp
);
105 display
->puts_scroll_style(0, 0, list
->title
, style
);
109 void list_draw(struct screen
*display
, struct gui_synclist
*list
)
111 struct viewport list_icons
;
112 int start
, end
, line_height
, style
, i
;
113 const int screen
= display
->screen_type
;
114 const int list_start_item
= list
->start_item
[screen
];
115 const int icon_width
= get_icon_width(screen
) + ICON_PADDING
;
116 const int scrollbar_in_left
= global_settings
.scrollbar
== SCROLLBAR_LEFT
;
117 const bool show_cursor
= !global_settings
.cursor_style
&&
118 list
->show_selection_marker
;
119 struct viewport
*parent
= (list
->parent
[screen
]);
120 #ifdef HAVE_LCD_COLOR
121 unsigned char cur_line
= 0;
125 struct viewport
*list_text_vp
= &list_text
[screen
];
127 line_height
= font_get(parent
->font
)->height
;
128 display
->set_viewport(parent
);
129 display
->clear_viewport();
130 display
->scroll_stop(list_text_vp
);
131 *list_text_vp
= *parent
;
132 if ((show_title
= draw_title(display
, list
)))
134 list_text_vp
->y
+= line_height
;
135 list_text_vp
->height
-= line_height
;
138 start
= list_start_item
;
139 end
= start
+ viewport_get_nb_lines(list_text_vp
);
141 /* draw the scrollbar if its needed */
142 if (global_settings
.scrollbar
&&
143 viewport_get_nb_lines(list_text_vp
) < list
->nb_items
)
147 vp
.width
= SCROLLBAR_WIDTH
;
148 vp
.height
= line_height
* viewport_get_nb_lines(list_text_vp
);
150 list_text_vp
->width
-= SCROLLBAR_WIDTH
;
151 if (scrollbar_in_left
)
152 list_text_vp
->x
+= SCROLLBAR_WIDTH
;
154 vp
.x
+= list_text_vp
->width
;
155 display
->set_viewport(&vp
);
156 gui_scrollbar_draw(display
, VP_IS_RTL(&vp
) ? 1 : 0, 0, SCROLLBAR_WIDTH
-1, vp
.height
,
157 list
->nb_items
, list_start_item
, list_start_item
+ end
-start
,
162 /* shift everything a bit in relation to the title... */
163 if (!VP_IS_RTL(list_text_vp
) && scrollbar_in_left
)
165 list_text_vp
->width
-= SCROLLBAR_WIDTH
;
166 list_text_vp
->x
+= SCROLLBAR_WIDTH
;
168 else if (VP_IS_RTL(list_text_vp
) && !scrollbar_in_left
)
170 list_text_vp
->width
-= SCROLLBAR_WIDTH
;
174 /* setup icon placement */
175 list_icons
= *list_text_vp
;
176 int icon_count
= (list
->callback_get_item_icon
!= NULL
) ? 1 : 0;
181 list_icons
.width
= icon_width
* icon_count
;
182 list_text_vp
->width
-= list_icons
.width
+ ICON_PADDING
;
183 if (VP_IS_RTL(&list_icons
))
184 list_icons
.x
+= list_text_vp
->width
+ ICON_PADDING
;
186 list_text_vp
->x
+= list_icons
.width
+ ICON_PADDING
;
189 for (i
=start
; i
<end
&& i
<list
->nb_items
; i
++)
192 unsigned const char *s
;
193 char entry_buffer
[MAX_PATH
];
194 unsigned char *entry_name
;
196 s
= list
->callback_get_item_name(i
, list
->data
, entry_buffer
,
197 sizeof(entry_buffer
));
198 entry_name
= P2STR(s
);
199 display
->set_viewport(list_text_vp
);
200 style
= STYLE_DEFAULT
;
201 /* position the string at the correct offset place */
203 display
->getstringsize(entry_name
, &item_width
, &h
);
204 item_offset
= gui_list_get_item_offset(list
, item_width
, text_pos
,
205 display
, list_text_vp
);
207 #ifdef HAVE_LCD_COLOR
208 /* if the list has a color callback */
209 if (list
->callback_get_item_color
)
211 int color
= list
->callback_get_item_color(i
, list
->data
);
212 /* if color selected */
215 style
|= STYLE_COLORED
|color
;
219 if(i
>= list
->selected_item
&& i
< list
->selected_item
220 + list
->selected_size
&& list
->show_selection_marker
)
221 {/* The selected item must be displayed scrolling */
222 if (global_settings
.cursor_style
== 1
223 #ifdef HAVE_REMOTE_LCD
224 /* the global_settings.cursor_style check is here to make
225 * sure if they want the cursor instead of bar it will work
227 || (display
->depth
< 16 && global_settings
.cursor_style
)
231 /* Display inverted-line-style */
232 style
= STYLE_INVERT
;
234 #ifdef HAVE_LCD_COLOR
235 else if (global_settings
.cursor_style
== 2)
237 /* Display colour line selector */
238 style
= STYLE_COLORBAR
;
240 else if (global_settings
.cursor_style
== 3)
242 /* Display gradient line selector */
243 style
= STYLE_GRADIENT
;
245 /* Make the lcd driver know how many lines the gradient should
246 cover and current line number */
247 /* number of selected lines */
248 style
|= NUMLN_PACK(list
->selected_size
);
249 /* current line number, zero based */
250 style
|= CURLN_PACK(cur_line
);
254 /* if the text is smaller than the viewport size */
255 if (item_offset
> item_width
- (list_text_vp
->width
- text_pos
))
258 display
->puts_style_offset(0, i
-start
, entry_name
,
263 display
->puts_scroll_style_offset(0, i
-start
, entry_name
,
269 if (list
->scroll_all
)
270 display
->puts_scroll_style_offset(0, i
-start
, entry_name
,
273 display
->puts_style_offset(0, i
-start
, entry_name
,
277 display
->set_viewport(&list_icons
);
278 if (list
->callback_get_item_icon
&& global_settings
.show_icons
)
280 screen_put_icon_with_offset(display
, show_cursor
?1:0,
281 (i
-start
),show_cursor
?ICON_PADDING
:0,0,
282 list
->callback_get_item_icon(i
, list
->data
));
284 if (show_cursor
&& i
>= list
->selected_item
&&
285 i
< list
->selected_item
+ list
->selected_size
)
287 screen_put_icon(display
, 0, i
-start
, Icon_Cursor
);
290 display
->set_viewport(parent
);
291 display
->update_viewport();
292 display
->set_viewport(NULL
);
295 #if defined(HAVE_TOUCHSCREEN)
296 /* This needs to be fixed if we ever get more than 1 touchscreen on a target. */
297 static bool scrolling
=false;
299 static int gui_synclist_touchscreen_scrollbar(struct gui_synclist
* gui_list
,
302 const int screen
= screens
[SCREEN_MAIN
].screen_type
;
303 const int nb_lines
= viewport_get_nb_lines(&list_text
[screen
]);
305 if (nb_lines
< gui_list
->nb_items
)
309 int scrollbar_size
= nb_lines
*
310 font_get(gui_list
->parent
[screen
]->font
)->height
;
311 int actual_y
= y
- list_text
[screen
].y
;
313 int new_selection
= (actual_y
* gui_list
->nb_items
)
316 int start_item
= new_selection
- nb_lines
/2;
319 else if(start_item
> gui_list
->nb_items
- nb_lines
)
320 start_item
= gui_list
->nb_items
- nb_lines
;
322 gui_list
->start_item
[screen
] = start_item
;
323 gui_synclist_select_item(gui_list
, new_selection
);
325 return ACTION_REDRAW
;
331 unsigned gui_synclist_do_touchscreen(struct gui_synclist
* gui_list
)
334 const int button
= action_get_touchscreen_press(&x
, &y
);
336 const struct screen
*display
= &screens
[SCREEN_MAIN
];
337 const int screen
= display
->screen_type
;
338 const int list_start_item
= gui_list
->start_item
[screen
];
339 const struct viewport
*list_text_vp
= &list_text
[screen
];
341 if (button
== BUTTON_NONE
)
343 if (x
> list_text_vp
->x
+ list_text_vp
->width
)
345 /* wider than the list's viewport, ignore it */
348 else if (x
< list_text_vp
->x
)
350 /* Top left corner is GO_TO_ROOT */
351 if (y
<list_text
[SCREEN_MAIN
].y
)
353 if (button
== BUTTON_REL
)
354 return ACTION_STD_MENU
;
355 else if (button
== (BUTTON_REPEAT
|BUTTON_REL
))
356 return ACTION_STD_CONTEXT
;
361 else if(global_settings
.scrollbar
== SCROLLBAR_LEFT
)
362 return gui_synclist_touchscreen_scrollbar(gui_list
, y
);
366 if (x
> list_text_vp
->x
+ list_text_vp
->width
&&
367 global_settings
.scrollbar
== SCROLLBAR_RIGHT
)
368 return gui_synclist_touchscreen_scrollbar(gui_list
, y
);
370 /* |--------------------------------------------------------|
371 * | Description of the touchscreen list interface: |
372 * |--------------------------------------------------------|
373 * | Pressing an item will select it and "enter" it. |
375 * | Pressing and holding your pen down will scroll through |
376 * | the list of items. |
378 * | Pressing and holding your pen down on a single item |
379 * | will bring up the context menu of it. |
380 * |--------------------------------------------------------|
382 if (y
> list_text_vp
->y
|| button
& BUTTON_REPEAT
)
384 int line_height
, actual_y
;
386 actual_y
= y
- list_text_vp
->y
;
387 line_height
= font_get(gui_list
->parent
[screen
]->font
)->height
;
388 line
= actual_y
/ line_height
;
390 /* Pressed below the list*/
391 if (list_start_item
+ line
>= gui_list
->nb_items
)
394 /* Pressed a border */
395 if(UNLIKELY(actual_y
% line_height
== 0))
398 if (line
!= (gui_list
->selected_item
- list_start_item
)
399 && button
^ BUTTON_REL
)
401 if(button
& BUTTON_REPEAT
)
404 gui_synclist_select_item(gui_list
, list_start_item
+ line
);
406 return ACTION_REDRAW
;
409 /* This has the same effect as the icons do when the scrollbar
410 is on the left (ie eliminate the chances an user enters/starts
411 an item when he wanted to use the scrollbar, due to touchscreen
414 if(global_settings
.scrollbar
== SCROLLBAR_RIGHT
&&
415 x
> list_text_vp
->x
+ list_text_vp
->width
-
416 get_icon_width(SCREEN_MAIN
))
419 if (button
== (BUTTON_REPEAT
|BUTTON_REL
))
423 /* Pen was hold on the same line as the
424 * previously selected one
425 * => simulate long button press
427 return ACTION_STD_CONTEXT
;
431 /* Pen was moved across several lines and then released on
439 else if(button
== BUTTON_REL
&&
440 line
== gui_list
->selected_item
- list_start_item
)
442 /* Pen was released on either the same line as the previously
443 * selected one or an other one
444 * => simulate short press
446 return ACTION_STD_OK
;
451 /* Everything above the items is cancel */
452 else if (y
< list_text_vp
->y
&& button
== BUTTON_REL
)
453 return ACTION_STD_CANCEL
;