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. */
35 #include "screen_access.h"
37 #include "scrollbar.h"
38 #include "statusbar.h"
45 #define SCROLLBAR_WIDTH 6
46 #define ICON_PADDING 1
48 /* these are static to make scrolling work */
49 static struct viewport list_text
[NB_SCREENS
], title_text
[NB_SCREENS
];
51 int gui_list_get_item_offset(struct gui_synclist
* gui_list
, int item_width
,
52 int text_pos
, struct screen
* display
,
54 bool list_display_title(struct gui_synclist
*list
, enum screen_type screen
);
57 internal screen layout:
59 |TI| title | TI is title icon
63 | | | items | I - icons
67 static bool draw_title(struct screen
*display
, struct gui_synclist
*list
)
69 const int screen
= display
->screen_type
;
70 int style
= STYLE_DEFAULT
;
71 if (!list_display_title(list
, screen
))
73 title_text
[screen
] = *(list
->parent
[screen
]);
74 title_text
[screen
].height
= font_get(title_text
[screen
].font
)->height
;
76 if (list
->title_icon
!= Icon_NOICON
&& global_settings
.show_icons
)
78 struct viewport title_icon
= title_text
[screen
];
79 title_icon
.width
= get_icon_width(screen
)
81 title_icon
.x
+= ICON_PADDING
;
83 title_text
[screen
].width
-= title_icon
.width
;
84 title_text
[screen
].x
+= title_icon
.width
;
86 display
->set_viewport(&title_icon
);
87 screen_put_icon(display
, 0, 0, list
->title_icon
);
90 if (list
->title_color
>= 0)
92 style
|= (STYLE_COLORED
|list
->title_color
);
95 display
->set_viewport(&title_text
[screen
]);
96 display
->puts_scroll_style(0, 0, list
->title
, style
);
100 void list_draw(struct screen
*display
, struct gui_synclist
*list
)
102 struct viewport list_icons
;
103 int start
, end
, line_height
, style
, i
;
104 const int screen
= display
->screen_type
;
105 const int icon_width
= get_icon_width(screen
) + ICON_PADDING
;
106 const bool show_cursor
= !global_settings
.cursor_style
&&
107 list
->show_selection_marker
;
108 struct viewport
*parent
= (list
->parent
[screen
]);
109 #ifdef HAVE_LCD_COLOR
110 unsigned char cur_line
= 0;
114 line_height
= font_get(parent
->font
)->height
;
115 display
->set_viewport(parent
);
116 display
->clear_viewport();
117 display
->stop_scroll();
118 list_text
[screen
] = *parent
;
119 if ((show_title
= draw_title(display
, list
)))
121 list_text
[screen
].y
+= line_height
;
122 list_text
[screen
].height
-= line_height
;
125 start
= list
->start_item
[screen
];
126 end
= start
+ viewport_get_nb_lines(&list_text
[screen
]);
128 /* draw the scrollbar if its needed */
129 if (global_settings
.scrollbar
&&
130 viewport_get_nb_lines(&list_text
[screen
]) < list
->nb_items
)
133 vp
= list_text
[screen
];
134 vp
.width
= SCROLLBAR_WIDTH
;
135 list_text
[screen
].width
-= SCROLLBAR_WIDTH
;
136 list_text
[screen
].x
+= SCROLLBAR_WIDTH
;
137 vp
.height
= line_height
*
138 viewport_get_nb_lines(&list_text
[screen
]);
140 display
->set_viewport(&vp
);
141 gui_scrollbar_draw(display
, 0, 0, SCROLLBAR_WIDTH
-1,
142 vp
.height
, list
->nb_items
,
143 list
->start_item
[screen
],
144 list
->start_item
[screen
] + end
-start
,
149 /* shift everything right a bit... */
150 list_text
[screen
].width
-= SCROLLBAR_WIDTH
;
151 list_text
[screen
].x
+= SCROLLBAR_WIDTH
;
154 /* setup icon placement */
155 list_icons
= list_text
[screen
];
156 int icon_count
= global_settings
.show_icons
&&
157 (list
->callback_get_item_icon
!= NULL
) ? 1 : 0;
162 list_icons
.width
= icon_width
* icon_count
;
163 list_text
[screen
].width
-=
164 list_icons
.width
+ ICON_PADDING
;
165 list_text
[screen
].x
+=
166 list_icons
.width
+ ICON_PADDING
;
169 for (i
=start
; i
<end
&& i
<list
->nb_items
; i
++)
173 char entry_buffer
[MAX_PATH
];
174 unsigned char *entry_name
;
176 s
= list
->callback_get_item_name(i
, list
->data
, entry_buffer
,
177 sizeof(entry_buffer
));
178 entry_name
= P2STR(s
);
179 display
->set_viewport(&list_text
[screen
]);
180 style
= STYLE_DEFAULT
;
181 /* position the string at the correct offset place */
183 display
->getstringsize(entry_name
, &item_width
, &h
);
184 item_offset
= gui_list_get_item_offset(list
, item_width
,
188 #ifdef HAVE_LCD_COLOR
189 /* if the list has a color callback */
190 if (list
->callback_get_item_color
)
192 int color
= list
->callback_get_item_color(i
, list
->data
);
193 /* if color selected */
196 style
|= STYLE_COLORED
|color
;
200 if(i
>= list
->selected_item
&& i
< list
->selected_item
201 + list
->selected_size
&& list
->show_selection_marker
)
202 {/* The selected item must be displayed scrolling */
203 if (global_settings
.cursor_style
== 1
204 #ifdef HAVE_REMOTE_LCD
205 /* the global_settings.cursor_style check is here to make
206 * sure if they want the cursor instead of bar it will work
208 || (display
->depth
< 16 && global_settings
.cursor_style
)
212 /* Display inverted-line-style */
213 style
= STYLE_INVERT
;
215 #ifdef HAVE_LCD_COLOR
216 else if (global_settings
.cursor_style
== 2)
218 /* Display colour line selector */
219 style
= STYLE_COLORBAR
;
221 else if (global_settings
.cursor_style
== 3)
223 /* Display gradient line selector */
224 style
= STYLE_GRADIENT
;
226 /* Make the lcd driver know how many lines the gradient should
227 cover and current line number */
228 /* number of selected lines */
229 style
|= NUMLN_PACK(list
->selected_size
);
230 /* current line number, zero based */
231 style
|= CURLN_PACK(cur_line
);
235 /* if the text is smaller than the viewport size */
236 if (item_offset
> item_width
237 - (list_text
[screen
].width
- text_pos
))
240 display
->puts_style_offset(0, i
-start
, entry_name
,
245 display
->puts_scroll_style_offset(0, i
-start
, entry_name
,
251 if (list
->scroll_all
)
252 display
->puts_scroll_style_offset(0, i
-start
, entry_name
,
255 display
->puts_style_offset(0, i
-start
, entry_name
,
259 if (list
->callback_get_item_icon
&& global_settings
.show_icons
)
261 display
->set_viewport(&list_icons
);
262 screen_put_icon_with_offset(display
, show_cursor
?1:0,
263 (i
-start
),show_cursor
?ICON_PADDING
:0,0,
264 list
->callback_get_item_icon(i
, list
->data
));
265 if (show_cursor
&& i
>= list
->selected_item
&&
266 i
< list
->selected_item
+ list
->selected_size
)
268 screen_put_icon(display
, 0, i
-start
, Icon_Cursor
);
271 else if (show_cursor
&& i
>= list
->selected_item
&&
272 i
< list
->selected_item
+ list
->selected_size
)
274 display
->set_viewport(&list_icons
);
275 screen_put_icon(display
, 0, (i
-start
), Icon_Cursor
);
278 display
->set_viewport(parent
);
279 display
->update_viewport();
280 display
->set_viewport(NULL
);
283 #if defined(HAVE_TOUCHSCREEN)
284 /* This needs to be fixed if we ever get more than 1 touchscreen on a target.
285 * This also assumes the whole screen is used, which is a bad assumption but
286 * fine until customizable lists comes in...
288 static bool scrolling
=false;
290 unsigned gui_synclist_do_touchscreen(struct gui_synclist
* gui_list
)
293 int button
= action_get_touchscreen_press(&x
, &y
);
295 struct screen
*display
= &screens
[SCREEN_MAIN
];
296 int screen
= display
->screen_type
;
297 if (button
== BUTTON_NONE
)
299 if (x
<list_text
[screen
].x
)
301 /* Top left corner is GO_TO_ROOT */
302 if (y
<list_text
[SCREEN_MAIN
].y
)
304 if (button
== BUTTON_REL
)
305 return ACTION_STD_MENU
;
306 else if (button
== (BUTTON_REPEAT
|BUTTON_REL
))
307 return ACTION_STD_CONTEXT
;
314 int nb_lines
= viewport_get_nb_lines(&list_text
[screen
]);
315 if (nb_lines
< gui_list
->nb_items
)
317 int scrollbar_size
= nb_lines
*
318 font_get(gui_list
->parent
[screen
]->font
)->height
;
319 int actual_y
= y
- list_text
[screen
].y
;
321 int new_selection
= (actual_y
* gui_list
->nb_items
)
324 int start_item
= new_selection
- nb_lines
/2;
327 else if(start_item
> gui_list
->nb_items
- nb_lines
)
328 start_item
= gui_list
->nb_items
- nb_lines
;
330 gui_list
->start_item
[screen
] = start_item
;
331 gui_synclist_select_item(gui_list
, new_selection
);
333 return ACTION_REDRAW
;
339 /* |--------------------------------------------------------|
340 * | Description of the touchscreen list interface: |
341 * |--------------------------------------------------------|
342 * | Pressing an item will select it and "enter" it. |
344 * | Pressing and holding your pen down will scroll through |
345 * | the list of items. |
347 * | Pressing and holding your pen down on a single item |
348 * | will bring up the context menu of it. |
349 * |--------------------------------------------------------|
351 if (y
> list_text
[screen
].y
|| button
& BUTTON_REPEAT
)
353 int line_height
, actual_y
;
355 actual_y
= y
- list_text
[screen
].y
;
356 line_height
= font_get(gui_list
->parent
[screen
]->font
)->height
;
357 line
= actual_y
/ line_height
;
359 /* Pressed below the list*/
360 if (gui_list
->start_item
[screen
]+line
>= gui_list
->nb_items
)
363 /* Pressed a border */
364 if(UNLIKELY(actual_y
% line_height
== 0))
367 if (line
!= (gui_list
->selected_item
- gui_list
->start_item
[screen
])
368 && button
^ BUTTON_REL
)
370 if(button
& BUTTON_REPEAT
)
373 gui_synclist_select_item(gui_list
, gui_list
->start_item
[screen
]
376 return ACTION_REDRAW
;
379 if (button
== (BUTTON_REPEAT
|BUTTON_REL
))
383 /* Pen was hold on the same line as the
384 * previously selected one
385 * => simulate long button press
387 return ACTION_STD_CONTEXT
;
391 /* Pen was moved across several lines and then released on
399 else if(button
== BUTTON_REL
&&
400 line
== gui_list
->selected_item
- gui_list
->start_item
[screen
])
402 /* Pen was released on either the same line as the previously
403 * selected one or an other one
404 * => simulate short press
406 return ACTION_STD_OK
;
411 /* Everything above the items is cancel */
412 else if (y
< list_text
[screen
].y
&& button
== BUTTON_REL
)
413 return ACTION_STD_CANCEL
;