diff options
Diffstat (limited to 'apps/gui/list.c')
-rw-r--r-- | apps/gui/list.c | 122 |
1 files changed, 80 insertions, 42 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index 8a5c2060ba..94150176dc 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -70,6 +70,7 @@ void gui_list_init(struct gui_list * gui_list, | |||
70 | gui_list->selected_size=selected_size; | 70 | gui_list->selected_size=selected_size; |
71 | gui_list->title = NULL; | 71 | gui_list->title = NULL; |
72 | gui_list->title_width = 0; | 72 | gui_list->title_width = 0; |
73 | gui_list->title_icon = NOICON; | ||
73 | } | 74 | } |
74 | 75 | ||
75 | void gui_list_set_display(struct gui_list * gui_list, struct screen * display) | 76 | void gui_list_set_display(struct gui_list * gui_list, struct screen * display) |
@@ -144,6 +145,39 @@ void gui_list_put_selection_in_screen(struct gui_list * gui_list, | |||
144 | gui_list->start_item = 0; | 145 | gui_list->start_item = 0; |
145 | } | 146 | } |
146 | 147 | ||
148 | #ifdef HAVE_LCD_BITMAP | ||
149 | int gui_list_get_item_offset(struct gui_list * gui_list, int item_width, | ||
150 | int text_pos) | ||
151 | { | ||
152 | struct screen * display=gui_list->display; | ||
153 | int item_offset; | ||
154 | |||
155 | if (offset_out_of_view) | ||
156 | { | ||
157 | item_offset = gui_list->offset_position; | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | /* if text is smaller then view */ | ||
162 | if (item_width <= display->width - text_pos) | ||
163 | { | ||
164 | item_offset = 0; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | /* if text got out of view */ | ||
169 | if (gui_list->offset_position > | ||
170 | item_width - (display->width - text_pos)) | ||
171 | item_offset = item_width - (display->width - text_pos); | ||
172 | else | ||
173 | item_offset = gui_list->offset_position; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | return item_offset; | ||
178 | } | ||
179 | #endif | ||
180 | |||
147 | void gui_list_draw(struct gui_list * gui_list) | 181 | void gui_list_draw(struct gui_list * gui_list) |
148 | { | 182 | { |
149 | struct screen * display=gui_list->display; | 183 | struct screen * display=gui_list->display; |
@@ -154,30 +188,62 @@ void gui_list_draw(struct gui_list * gui_list) | |||
154 | bool draw_cursor; | 188 | bool draw_cursor; |
155 | int i; | 189 | int i; |
156 | int lines; | 190 | int lines; |
191 | #ifdef HAVE_LCD_BITMAP | ||
192 | int item_offset; | ||
193 | #endif | ||
194 | |||
195 | gui_textarea_clear(display); | ||
157 | 196 | ||
158 | /* Adjust the position of icon, cursor, text */ | 197 | /* position and draw the list title & icon */ |
159 | if (gui_list->title) | 198 | if (gui_list->title) |
160 | { | 199 | { |
161 | i = 1; | 200 | i = 1; |
162 | lines = display->nb_lines - 1; | 201 | lines = display->nb_lines - 1; |
202 | |||
203 | if (gui_list->title_icon != NOICON && draw_icons) | ||
204 | { | ||
205 | screen_put_iconxy(display, 0, 0, gui_list->title_icon); | ||
206 | #ifdef HAVE_LCD_BITMAP | ||
207 | text_pos = 8; /* pixels */ | ||
208 | #else | ||
209 | text_pos = 1; /* chars */ | ||
210 | #endif | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | text_pos = 0; | ||
215 | } | ||
216 | |||
217 | #ifdef HAVE_LCD_BITMAP | ||
218 | screen_set_xmargin(display, text_pos); /* margin for title */ | ||
219 | item_offset = gui_list_get_item_offset(gui_list, gui_list->title_width, | ||
220 | text_pos); | ||
221 | if (item_offset > gui_list->title_width - (display->width - text_pos)) | ||
222 | display->puts_offset(0, 0, gui_list->title, item_offset); | ||
223 | else | ||
224 | display->puts_scroll_offset(0, 0, gui_list->title, item_offset); | ||
225 | #else | ||
226 | display->puts_scroll(text_pos, 0, gui_list->title); | ||
227 | #endif | ||
163 | } | 228 | } |
164 | else | 229 | else |
165 | { | 230 | { |
166 | i = 0; | 231 | i = 0; |
167 | lines = display->nb_lines; | 232 | lines = display->nb_lines; |
168 | } | 233 | } |
234 | |||
235 | /* Adjust the position of icon, cursor, text for the list */ | ||
169 | #ifdef HAVE_LCD_BITMAP | 236 | #ifdef HAVE_LCD_BITMAP |
170 | display->setfont(FONT_UI); | 237 | display->setfont(FONT_UI); |
171 | gui_textarea_update_nblines(display); | 238 | gui_textarea_update_nblines(display); |
172 | bool draw_scrollbar; | 239 | bool draw_scrollbar; |
173 | 240 | ||
174 | |||
175 | draw_scrollbar = (global_settings.scrollbar && | 241 | draw_scrollbar = (global_settings.scrollbar && |
176 | lines < gui_list->nb_items); | 242 | lines < gui_list->nb_items); |
177 | 243 | ||
178 | draw_cursor = !global_settings.invert_cursor; | 244 | draw_cursor = !global_settings.invert_cursor; |
179 | text_pos = 0; /* here it's in pixels */ | 245 | text_pos = 0; /* here it's in pixels */ |
180 | if(draw_scrollbar) | 246 | if(draw_scrollbar || gui_list->title) /* indent if there's a title */ |
181 | { | 247 | { |
182 | cursor_pos++; | 248 | cursor_pos++; |
183 | icon_pos++; | 249 | icon_pos++; |
@@ -198,12 +264,10 @@ void gui_list_draw(struct gui_list * gui_list) | |||
198 | text_pos = 1; | 264 | text_pos = 1; |
199 | #endif | 265 | #endif |
200 | 266 | ||
201 | gui_textarea_clear(display); | ||
202 | #ifdef HAVE_LCD_BITMAP | 267 | #ifdef HAVE_LCD_BITMAP |
203 | screen_set_xmargin(display, text_pos); | 268 | screen_set_xmargin(display, text_pos); /* margin for list */ |
204 | #endif | 269 | #endif |
205 | 270 | ||
206 | |||
207 | while (i < display->nb_lines) | 271 | while (i < display->nb_lines) |
208 | { | 272 | { |
209 | char entry_buffer[MAX_PATH]; | 273 | char entry_buffer[MAX_PATH]; |
@@ -219,26 +283,13 @@ void gui_list_draw(struct gui_list * gui_list) | |||
219 | entry_buffer); | 283 | entry_buffer); |
220 | #ifdef HAVE_LCD_BITMAP | 284 | #ifdef HAVE_LCD_BITMAP |
221 | /* position the string at the correct offset place */ | 285 | /* position the string at the correct offset place */ |
222 | int item_offset; | ||
223 | int item_width,h; | 286 | int item_width,h; |
224 | display->getstringsize(entry_name, &item_width, &h); | 287 | display->getstringsize(entry_name, &item_width, &h); |
225 | 288 | item_offset = gui_list_get_item_offset(gui_list, item_width, text_pos); | |
226 | if (offset_out_of_view) | ||
227 | item_offset = gui_list->offset_position; | ||
228 | else | ||
229 | /* if text is smaller then view */ | ||
230 | if (item_width <= display->width - text_pos) | ||
231 | item_offset = 0; | ||
232 | else | ||
233 | /* if text got out of view */ | ||
234 | if (gui_list->offset_position > | ||
235 | item_width - (display->width - text_pos)) | ||
236 | item_offset = item_width - (display->width - text_pos); | ||
237 | else | ||
238 | item_offset = gui_list->offset_position; | ||
239 | |||
240 | #endif | 289 | #endif |
241 | if(current_item >= gui_list->selected_item && current_item < gui_list->selected_item+gui_list->selected_size) | 290 | |
291 | if(current_item >= gui_list->selected_item && | ||
292 | current_item < gui_list->selected_item + gui_list->selected_size) | ||
242 | {/* The selected item must be displayed scrolling */ | 293 | {/* The selected item must be displayed scrolling */ |
243 | #ifdef HAVE_LCD_BITMAP | 294 | #ifdef HAVE_LCD_BITMAP |
244 | if (global_settings.invert_cursor)/* Display inverted-line-style*/ | 295 | if (global_settings.invert_cursor)/* Display inverted-line-style*/ |
@@ -308,21 +359,7 @@ void gui_list_draw(struct gui_list * gui_list) | |||
308 | gui_list->start_item + display->nb_lines, VERTICAL); | 359 | gui_list->start_item + display->nb_lines, VERTICAL); |
309 | } | 360 | } |
310 | #endif | 361 | #endif |
311 | if (gui_list->title) | 362 | |
312 | { | ||
313 | /* Scroll if the title is too large, otherwise center */ | ||
314 | if (gui_list->title_width > gui_list->display->width) { | ||
315 | display->puts_scroll(0, 0, gui_list->title); | ||
316 | } else { | ||
317 | #ifdef HAVE_LCD_BITMAP | ||
318 | display->putsxy((display->width - gui_list->title_width) / 2, | ||
319 | gui_textarea_get_ystart(display), gui_list->title); | ||
320 | #else | ||
321 | display->puts((display->width - gui_list->title_width) / 2, 0, | ||
322 | gui_list->title); | ||
323 | #endif | ||
324 | } | ||
325 | } | ||
326 | gui_textarea_update(display); | 363 | gui_textarea_update(display); |
327 | } | 364 | } |
328 | 365 | ||
@@ -522,9 +559,10 @@ void gui_list_screen_scroll_out_of_view(bool enable) | |||
522 | } | 559 | } |
523 | #endif /* HAVE_LCD_BITMAP */ | 560 | #endif /* HAVE_LCD_BITMAP */ |
524 | 561 | ||
525 | void gui_list_set_title(struct gui_list * gui_list, char * title) | 562 | void gui_list_set_title(struct gui_list * gui_list, char * title, ICON icon) |
526 | { | 563 | { |
527 | gui_list->title = title; | 564 | gui_list->title = title; |
565 | gui_list->title_icon = icon; | ||
528 | if (title) { | 566 | if (title) { |
529 | #ifdef HAVE_LCD_BITMAP | 567 | #ifdef HAVE_LCD_BITMAP |
530 | gui_list->display->getstringsize(title, &gui_list->title_width, NULL); | 568 | gui_list->display->getstringsize(title, &gui_list->title_width, NULL); |
@@ -652,11 +690,11 @@ void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll) | |||
652 | gui_list_limit_scroll(&(lists->gui_list[i]), scroll); | 690 | gui_list_limit_scroll(&(lists->gui_list[i]), scroll); |
653 | } | 691 | } |
654 | 692 | ||
655 | void gui_synclist_set_title(struct gui_synclist * lists, char* title) | 693 | void gui_synclist_set_title(struct gui_synclist * lists, char * title, ICON icon) |
656 | { | 694 | { |
657 | int i; | 695 | int i; |
658 | FOR_NB_SCREENS(i) | 696 | FOR_NB_SCREENS(i) |
659 | gui_list_set_title(&(lists->gui_list[i]), title); | 697 | gui_list_set_title(&(lists->gui_list[i]), title, icon); |
660 | } | 698 | } |
661 | 699 | ||
662 | void gui_synclist_flash(struct gui_synclist * lists) | 700 | void gui_synclist_flash(struct gui_synclist * lists) |