diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-01-22 04:24:26 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-01-22 04:24:26 +0000 |
commit | d3a03b679f196be076043d475b9512338fd6c8bb (patch) | |
tree | c4c57a157a46d09a7037c39e290182a8c43deb71 /apps/gui | |
parent | bfe740712a3513dbb4143336cbc5e9aaab09d732 (diff) | |
download | rockbox-d3a03b679f196be076043d475b9512338fd6c8bb.tar.gz rockbox-d3a03b679f196be076043d475b9512338fd6c8bb.zip |
Horizontal screen scrolling part 3 (by Shachar Liberman)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8414 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/list.c | 172 | ||||
-rw-r--r-- | apps/gui/list.h | 45 |
2 files changed, 109 insertions, 108 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index 2ae5f995f4..ce2a3354e4 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -37,8 +37,13 @@ | |||
37 | #define SCROLL_LIMIT 2 | 37 | #define SCROLL_LIMIT 2 |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | static int offset_step = 15; | 40 | #ifdef HAVE_LCD_BITMAP |
41 | static bool offset_outof_view = false; | 41 | static int offset_step = 16; /* pixels per screen scroll step */ |
42 | /* should lines scroll out of the screen */ | ||
43 | static bool offset_out_of_view = false; | ||
44 | #endif | ||
45 | |||
46 | |||
42 | 47 | ||
43 | void gui_list_init(struct gui_list * gui_list, | 48 | void gui_list_init(struct gui_list * gui_list, |
44 | list_get_name callback_get_item_name, | 49 | list_get_name callback_get_item_name, |
@@ -54,7 +59,9 @@ void gui_list_init(struct gui_list * gui_list, | |||
54 | gui_list->limit_scroll = false; | 59 | gui_list->limit_scroll = false; |
55 | gui_list->data=data; | 60 | gui_list->data=data; |
56 | gui_list->cursor_flash_state=false; | 61 | gui_list->cursor_flash_state=false; |
57 | gui_list->offsetval = 0; | 62 | #ifdef HAVE_LCD_BITMAP |
63 | gui_list->offset_position = 0; | ||
64 | #endif | ||
58 | } | 65 | } |
59 | 66 | ||
60 | void gui_list_set_display(struct gui_list * gui_list, struct screen * display) | 67 | void gui_list_set_display(struct gui_list * gui_list, struct screen * display) |
@@ -181,47 +188,43 @@ void gui_list_draw(struct gui_list * gui_list) | |||
181 | entry_name = gui_list->callback_get_item_name(current_item, | 188 | entry_name = gui_list->callback_get_item_name(current_item, |
182 | gui_list->data, | 189 | gui_list->data, |
183 | entry_buffer); | 190 | entry_buffer); |
184 | |||
185 | #ifdef HAVE_LCD_BITMAP | 191 | #ifdef HAVE_LCD_BITMAP |
186 | /* position the string at the right offset place */ | 192 | /* position the string at the correct offset place */ |
187 | int item_offset; | 193 | int item_offset; |
188 | int str_width,h; | 194 | int item_width,h; |
189 | display->getstringsize(entry_name, &str_width, &h); | 195 | display->getstringsize(entry_name, &item_width, &h); |
190 | 196 | ||
191 | if (offset_outof_view) | 197 | if (offset_out_of_view) |
192 | item_offset = gui_list->offsetval; | 198 | item_offset = gui_list->offset_position; |
193 | else | ||
194 | /* if text is smaller then view */ | ||
195 | if (str_width <= display->width - text_pos) | ||
196 | item_offset = 0; | ||
197 | else | 199 | else |
198 | /* if text got out of view */ | 200 | /* if text is smaller then view */ |
199 | if (gui_list->offsetval > str_width - (display->width - text_pos)) | 201 | if (item_width <= display->width - text_pos) |
200 | item_offset = str_width - (display->width - text_pos); | 202 | item_offset = 0; |
201 | else | 203 | else |
202 | item_offset = gui_list->offsetval; | 204 | /* if text got out of view */ |
203 | 205 | if (gui_list->offset_position > | |
204 | #endif | 206 | item_width - (display->width - text_pos)) |
207 | item_offset = item_width - (display->width - text_pos); | ||
208 | else | ||
209 | item_offset = gui_list->offset_position; | ||
205 | 210 | ||
211 | #endif | ||
206 | if(current_item == gui_list->selected_item) { | 212 | if(current_item == gui_list->selected_item) { |
207 | /* The selected item must be displayed scrolling */ | 213 | /* The selected item must be displayed scrolling */ |
208 | #ifdef HAVE_LCD_BITMAP | 214 | #ifdef HAVE_LCD_BITMAP |
209 | if (global_settings.invert_cursor) /* Display inverted-line-style*/ | 215 | if (global_settings.invert_cursor)/* Display inverted-line-style*/ |
210 | |||
211 | /* if text got out of view */ | 216 | /* if text got out of view */ |
212 | if (item_offset > str_width - (display->width - text_pos)) | 217 | if (item_offset > item_width - (display->width - text_pos)) |
213 | /* don't scroll */ | 218 | /* don't scroll */ |
214 | display->puts_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); | 219 | display->puts_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); |
215 | else | 220 | else |
216 | display->puts_scroll_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); | 221 | display->puts_scroll_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); |
217 | |||
218 | else /* if (global_settings.invert_cursor) */ | ||
219 | |||
220 | if (item_offset > str_width - (display->width - text_pos)) | ||
221 | display->puts_offset(0, i, entry_name,item_offset); | ||
222 | else | ||
223 | display->puts_scroll_offset(0, i, entry_name,item_offset); | ||
224 | 222 | ||
223 | else /* if (!global_settings.invert_cursor) */ | ||
224 | if (item_offset > item_width - (display->width - text_pos)) | ||
225 | display->puts_offset(0, i, entry_name,item_offset); | ||
226 | else | ||
227 | display->puts_scroll_offset(0, i, entry_name,item_offset); | ||
225 | #else | 228 | #else |
226 | display->puts_scroll(text_pos, i, entry_name); | 229 | display->puts_scroll(text_pos, i, entry_name); |
227 | #endif | 230 | #endif |
@@ -264,40 +267,6 @@ void gui_list_draw(struct gui_list * gui_list) | |||
264 | gui_textarea_update(display); | 267 | gui_textarea_update(display); |
265 | } | 268 | } |
266 | 269 | ||
267 | #ifdef HAVE_LCD_BITMAP | ||
268 | void gui_list_screen_scroll_step(int ofs) | ||
269 | { | ||
270 | offset_step = ofs; | ||
271 | } | ||
272 | |||
273 | void gui_list_screen_scroll_out_of_view(bool enable) | ||
274 | { | ||
275 | if (enable) | ||
276 | offset_outof_view = true; | ||
277 | else | ||
278 | offset_outof_view = false; | ||
279 | } | ||
280 | |||
281 | void gui_list_offset_right(struct gui_list * gui_list) | ||
282 | { | ||
283 | /* there should be a callback to find out what's the longest item on the list, | ||
284 | * and then, by finding out the width with get_stringsize, we would stop the | ||
285 | * list from scrolling at that point */ | ||
286 | |||
287 | gui_list->offsetval+=offset_step; | ||
288 | if (gui_list->offsetval > 1000) | ||
289 | gui_list->offsetval = 1000; | ||
290 | } | ||
291 | |||
292 | void gui_list_offset_left(struct gui_list * gui_list) | ||
293 | { | ||
294 | gui_list->offsetval-=offset_step; | ||
295 | if (gui_list->offsetval < 0) | ||
296 | gui_list->offsetval = 0; | ||
297 | |||
298 | } | ||
299 | #endif /* HAVE_LCD_BITMAP */ | ||
300 | |||
301 | void gui_list_select_item(struct gui_list * gui_list, int item_number) | 270 | void gui_list_select_item(struct gui_list * gui_list, int item_number) |
302 | { | 271 | { |
303 | if( item_number > gui_list->nb_items-1 || item_number < 0 ) | 272 | if( item_number > gui_list->nb_items-1 || item_number < 0 ) |
@@ -428,6 +397,37 @@ void gui_list_del_item(struct gui_list * gui_list) | |||
428 | } | 397 | } |
429 | } | 398 | } |
430 | 399 | ||
400 | #ifdef HAVE_LCD_BITMAP | ||
401 | void gui_list_scroll_right(struct gui_list * gui_list) | ||
402 | { | ||
403 | /* FIXME: This is a fake right boundry limiter. there should be some | ||
404 | * callback function to find the longest item on the list in pixels, | ||
405 | * to stop the list from scrolling past that point */ | ||
406 | gui_list->offset_position+=offset_step; | ||
407 | if (gui_list->offset_position > 1000) | ||
408 | gui_list->offset_position = 1000; | ||
409 | } | ||
410 | |||
411 | void gui_list_scroll_left(struct gui_list * gui_list) | ||
412 | { | ||
413 | gui_list->offset_position-=offset_step; | ||
414 | if (gui_list->offset_position < 0) | ||
415 | gui_list->offset_position = 0; | ||
416 | } | ||
417 | void gui_list_screen_scroll_step(int ofs) | ||
418 | { | ||
419 | offset_step = ofs; | ||
420 | } | ||
421 | |||
422 | void gui_list_screen_scroll_out_of_view(bool enable) | ||
423 | { | ||
424 | if (enable) | ||
425 | offset_out_of_view = true; | ||
426 | else | ||
427 | offset_out_of_view = false; | ||
428 | } | ||
429 | #endif /* HAVE_LCD_BITMAP */ | ||
430 | |||
431 | /* | 431 | /* |
432 | * Synchronized lists stuffs | 432 | * Synchronized lists stuffs |
433 | */ | 433 | */ |
@@ -453,7 +453,9 @@ void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items) | |||
453 | FOR_NB_SCREENS(i) | 453 | FOR_NB_SCREENS(i) |
454 | { | 454 | { |
455 | gui_list_set_nb_items(&(lists->gui_list[i]), nb_items); | 455 | gui_list_set_nb_items(&(lists->gui_list[i]), nb_items); |
456 | lists->gui_list[i].offsetval = 0; | 456 | #ifdef HAVE_LCD_BITMAP |
457 | lists->gui_list[i].offset_position = 0; | ||
458 | #endif | ||
457 | } | 459 | } |
458 | } | 460 | } |
459 | void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback) | 461 | void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback) |
@@ -502,22 +504,6 @@ void gui_synclist_select_next_page(struct gui_synclist * lists, | |||
502 | screens[screen].nb_lines); | 504 | screens[screen].nb_lines); |
503 | } | 505 | } |
504 | 506 | ||
505 | #ifdef HAVE_LCD_BITMAP | ||
506 | void gui_synclist_offset_right(struct gui_synclist * lists) | ||
507 | { | ||
508 | int i; | ||
509 | FOR_NB_SCREENS(i) | ||
510 | gui_list_offset_right(&(lists->gui_list[i])); | ||
511 | } | ||
512 | |||
513 | void gui_synclist_offset_left(struct gui_synclist * lists) | ||
514 | { | ||
515 | int i; | ||
516 | FOR_NB_SCREENS(i) | ||
517 | gui_list_offset_left(&(lists->gui_list[i])); | ||
518 | } | ||
519 | #endif /* HAVE_LCD_BITMAP */ | ||
520 | |||
521 | void gui_synclist_select_previous_page(struct gui_synclist * lists, | 507 | void gui_synclist_select_previous_page(struct gui_synclist * lists, |
522 | enum screen_type screen) | 508 | enum screen_type screen) |
523 | { | 509 | { |
@@ -555,6 +541,22 @@ void gui_synclist_flash(struct gui_synclist * lists) | |||
555 | gui_list_flash(&(lists->gui_list[i])); | 541 | gui_list_flash(&(lists->gui_list[i])); |
556 | } | 542 | } |
557 | 543 | ||
544 | #ifdef HAVE_LCD_BITMAP | ||
545 | void gui_synclist_scroll_right(struct gui_synclist * lists) | ||
546 | { | ||
547 | int i; | ||
548 | FOR_NB_SCREENS(i) | ||
549 | gui_list_scroll_right(&(lists->gui_list[i])); | ||
550 | } | ||
551 | |||
552 | void gui_synclist_scroll_left(struct gui_synclist * lists) | ||
553 | { | ||
554 | int i; | ||
555 | FOR_NB_SCREENS(i) | ||
556 | gui_list_scroll_left(&(lists->gui_list[i])); | ||
557 | } | ||
558 | #endif /* HAVE_LCD_BITMAP */ | ||
559 | |||
558 | unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | 560 | unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) |
559 | { | 561 | { |
560 | gui_synclist_limit_scroll(lists, true); | 562 | gui_synclist_limit_scroll(lists, true); |
@@ -588,7 +590,7 @@ unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
588 | gui_synclist_select_next(lists); | 590 | gui_synclist_select_next(lists); |
589 | gui_synclist_draw(lists); | 591 | gui_synclist_draw(lists); |
590 | return LIST_NEXT; | 592 | return LIST_NEXT; |
591 | 593 | ||
592 | #ifdef LIST_PGRIGHT | 594 | #ifdef LIST_PGRIGHT |
593 | case LIST_PGRIGHT: | 595 | case LIST_PGRIGHT: |
594 | case LIST_PGRIGHT | BUTTON_REPEAT: | 596 | case LIST_PGRIGHT | BUTTON_REPEAT: |
@@ -596,7 +598,7 @@ unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
596 | case LIST_RC_PGRIGHT: | 598 | case LIST_RC_PGRIGHT: |
597 | case LIST_RC_PGRIGHT | BUTTON_REPEAT: | 599 | case LIST_RC_PGRIGHT | BUTTON_REPEAT: |
598 | #endif | 600 | #endif |
599 | gui_synclist_offset_right(lists); | 601 | gui_synclist_scroll_right(lists); |
600 | gui_synclist_draw(lists); | 602 | gui_synclist_draw(lists); |
601 | return true; | 603 | return true; |
602 | #endif | 604 | #endif |
@@ -608,7 +610,7 @@ unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
608 | case LIST_RC_PGLEFT: | 610 | case LIST_RC_PGLEFT: |
609 | case LIST_RC_PGLEFT | BUTTON_REPEAT: | 611 | case LIST_RC_PGLEFT | BUTTON_REPEAT: |
610 | #endif | 612 | #endif |
611 | gui_synclist_offset_left(lists); | 613 | gui_synclist_scroll_left(lists); |
612 | gui_synclist_draw(lists); | 614 | gui_synclist_draw(lists); |
613 | return true; | 615 | return true; |
614 | #endif | 616 | #endif |
diff --git a/apps/gui/list.h b/apps/gui/list.h index e177f5ef75..8643c4d047 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h | |||
@@ -126,19 +126,20 @@ typedef void list_get_icon(int selected_item, | |||
126 | * a buffer when it's not necessary) | 126 | * a buffer when it's not necessary) |
127 | * Returns a pointer to a string that contains the text to display | 127 | * Returns a pointer to a string that contains the text to display |
128 | */ | 128 | */ |
129 | |||
130 | typedef char * list_get_name(int selected_item, | 129 | typedef char * list_get_name(int selected_item, |
131 | void * data, | 130 | void * data, |
132 | char *buffer); | 131 | char *buffer); |
133 | 132 | ||
134 | struct gui_list | 133 | struct gui_list |
135 | { | 134 | { |
136 | int offsetval; /* value of screen offset */ | ||
137 | int nb_items; | 135 | int nb_items; |
138 | int selected_item; | 136 | int selected_item; |
139 | bool cursor_flash_state; | 137 | bool cursor_flash_state; |
140 | int start_item; /* the item that is displayed at the top of the screen */ | 138 | int start_item; /* the item that is displayed at the top of the screen */ |
141 | 139 | ||
140 | #ifdef HAVE_LCD_BITMAP | ||
141 | int offset_position; /* the list's screen scroll placement in pixels */ | ||
142 | #endif | ||
142 | list_get_icon *callback_get_item_icon; | 143 | list_get_icon *callback_get_item_icon; |
143 | list_get_name *callback_get_item_name; | 144 | list_get_name *callback_get_item_name; |
144 | 145 | ||
@@ -234,13 +235,6 @@ extern void gui_list_draw(struct gui_list * gui_list); | |||
234 | * (Item 0 gets selected if the end of the list is reached) | 235 | * (Item 0 gets selected if the end of the list is reached) |
235 | * - gui_list : the list structure | 236 | * - gui_list : the list structure |
236 | */ | 237 | */ |
237 | |||
238 | extern void gui_list_screen_scroll_step(int ofs); | ||
239 | /* parse global setting to static int */ | ||
240 | |||
241 | extern void gui_list_screen_scroll_out_of_view(bool enable); | ||
242 | /* parse global setting to static bool */ | ||
243 | |||
244 | extern void gui_list_select_next(struct gui_list * gui_list); | 238 | extern void gui_list_select_next(struct gui_list * gui_list); |
245 | 239 | ||
246 | /* | 240 | /* |
@@ -250,27 +244,32 @@ extern void gui_list_select_next(struct gui_list * gui_list); | |||
250 | */ | 244 | */ |
251 | extern void gui_list_select_previous(struct gui_list * gui_list); | 245 | extern void gui_list_select_previous(struct gui_list * gui_list); |
252 | 246 | ||
253 | /* | 247 | #ifdef HAVE_LCD_BITMAP |
254 | * Go to next page if any, else selects the last item in the list | ||
255 | * - gui_list : the list structure | ||
256 | * - nb_lines : the number of lines to try to move the cursor | ||
257 | */ | ||
258 | |||
259 | extern void gui_list_offset_right(struct gui_list * gui_list); | ||
260 | |||
261 | /* | 248 | /* |
262 | * Makes all the item in the list scroll by one step to the right. | 249 | * Makes all the item in the list scroll by one step to the right. |
263 | * Should stop increasing the value when reaching the widest item value | 250 | * Should stop increasing the value when reaching the widest item value |
264 | * in the list. | 251 | * in the list. |
265 | */ | 252 | */ |
266 | 253 | void gui_list_scroll_right(struct gui_list * gui_list); | |
267 | extern void gui_list_offset_left(struct gui_list * gui_list); | ||
268 | 254 | ||
269 | /* | 255 | /* |
270 | * Makes all the item in the list scroll by one step to the left. | 256 | * Makes all the item in the list scroll by one step to the left. |
271 | * stops at starting position. | 257 | * stops at starting position. |
272 | */ | 258 | */ |
273 | 259 | void gui_list_scroll_left(struct gui_list * gui_list); | |
260 | |||
261 | /* parse global setting to static int */ | ||
262 | extern void gui_list_screen_scroll_step(int ofs); | ||
263 | |||
264 | /* parse global setting to static bool */ | ||
265 | extern void gui_list_screen_scroll_out_of_view(bool enable); | ||
266 | #endif /* HAVE_LCD_BITMAP */ | ||
267 | |||
268 | /* | ||
269 | * Go to next page if any, else selects the last item in the list | ||
270 | * - gui_list : the list structure | ||
271 | * - nb_lines : the number of lines to try to move the cursor | ||
272 | */ | ||
274 | extern void gui_list_select_next_page(struct gui_list * gui_list, | 273 | extern void gui_list_select_next_page(struct gui_list * gui_list, |
275 | int nb_lines); | 274 | int nb_lines); |
276 | 275 | ||
@@ -347,8 +346,6 @@ extern void gui_synclist_select_item(struct gui_synclist * lists, | |||
347 | int item_number); | 346 | int item_number); |
348 | extern void gui_synclist_select_next(struct gui_synclist * lists); | 347 | extern void gui_synclist_select_next(struct gui_synclist * lists); |
349 | extern void gui_synclist_select_previous(struct gui_synclist * lists); | 348 | extern void gui_synclist_select_previous(struct gui_synclist * lists); |
350 | extern void gui_synclist_offset_right(struct gui_synclist * lists); | ||
351 | extern void gui_synclist_offset_left(struct gui_synclist * lists); | ||
352 | extern void gui_synclist_select_next_page(struct gui_synclist * lists, | 349 | extern void gui_synclist_select_next_page(struct gui_synclist * lists, |
353 | enum screen_type screen); | 350 | enum screen_type screen); |
354 | extern void gui_synclist_select_previous_page(struct gui_synclist * lists, | 351 | extern void gui_synclist_select_previous_page(struct gui_synclist * lists, |
@@ -357,6 +354,8 @@ extern void gui_synclist_add_item(struct gui_synclist * lists); | |||
357 | extern void gui_synclist_del_item(struct gui_synclist * lists); | 354 | extern void gui_synclist_del_item(struct gui_synclist * lists); |
358 | extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll); | 355 | extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll); |
359 | extern void gui_synclist_flash(struct gui_synclist * lists); | 356 | extern void gui_synclist_flash(struct gui_synclist * lists); |
357 | void gui_synclist_scroll_right(struct gui_synclist * lists); | ||
358 | void gui_synclist_scroll_left(struct gui_synclist * lists); | ||
360 | 359 | ||
361 | /* | 360 | /* |
362 | * Do the action implied by the given button, | 361 | * Do the action implied by the given button, |