summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2009-08-16 22:20:11 +0000
committerThomas Martitz <kugel@rockbox.org>2009-08-16 22:20:11 +0000
commit4c48b59be8ba41b80350d5329d0f13240229da0a (patch)
treee8cb9547c4d8d5faff39de2aef5626a5cabc689d /apps/gui
parentc0897a8002d493244efd69fca5c433dbafe8d5be (diff)
downloadrockbox-4c48b59be8ba41b80350d5329d0f13240229da0a.tar.gz
rockbox-4c48b59be8ba41b80350d5329d0f13240229da0a.zip
User definable UI viewport, to be able to restrict the UI into a viewport for all bitmap displays.
Flyspray: FS#8799 This will allow for pretty themes, for example those with nice glass effects on their backdrops (some might argue they're wasting screen space but it's upto them), as well as allowing for future background WPS updates in the main UI. Plugins are not converted yet, they simply use the full screen. Ideally, any plugin that does *not* want the UI viewport, should take care of that itself (i.e. plugins should normally use the UI viewport). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22365 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/list.c55
-rw-r--r--apps/gui/list.h2
-rw-r--r--apps/gui/statusbar.c2
-rw-r--r--apps/gui/viewport.c169
-rw-r--r--apps/gui/viewport.h82
-rw-r--r--apps/gui/wps.c1
6 files changed, 240 insertions, 71 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 8a65d3f298..3627f12221 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -55,29 +55,37 @@ static int offset_step = 16; /* pixels per screen scroll step */
55/* should lines scroll out of the screen */ 55/* should lines scroll out of the screen */
56static bool offset_out_of_view = false; 56static bool offset_out_of_view = false;
57#endif 57#endif
58static int force_list_reinit = false;
59 58
60static void gui_list_select_at_offset(struct gui_synclist * gui_list, 59static void gui_list_select_at_offset(struct gui_synclist * gui_list,
61 int offset); 60 int offset);
62void list_draw(struct screen *display, struct gui_synclist *list); 61void list_draw(struct screen *display, struct gui_synclist *list);
63 62
64#ifdef HAVE_LCD_BITMAP 63#ifdef HAVE_LCD_BITMAP
65static struct viewport parent[NB_SCREENS]; 64static void list_init_viewports(struct gui_synclist *list)
66void list_init_viewports(struct gui_synclist *list)
67{ 65{
66 struct viewport* vp;
68 int i; 67 int i;
69 struct viewport *vp; 68 bool parent_used = (*list->parent != NULL);
70 FOR_NB_SCREENS(i) 69 if (!parent_used)
71 { 70 {
72 vp = &parent[i]; 71 vp = viewport_get_current_vp();
73 if (!list || list->parent[i] == vp) 72 FOR_NB_SCREENS(i)
74 viewport_set_defaults(vp, i); 73 list->parent[i] = &vp[i];
75 } 74 }
76#ifdef HAVE_BUTTONBAR 75#ifdef HAVE_BUTTONBAR
77 if (list && (list->parent[0] == &parent[0]) && global_settings.buttonbar) 76 if (list && !parent_used[SCREEN_MAIN] && global_settings.buttonbar)
78 list->parent[0]->height -= BUTTONBAR_HEIGHT; 77 list->parent[0]->height -= BUTTONBAR_HEIGHT;
79#endif 78#endif
80 force_list_reinit = false; 79}
80#else
81#define list_init_viewports(a)
82#endif
83
84#ifdef HAVE_LCD_BITMAP
85bool list_display_title(struct gui_synclist *list, enum screen_type screen)
86{
87 return list->title != NULL &&
88 viewport_get_nb_lines(list->parent[screen])>2;
81} 89}
82#else 90#else
83static struct viewport parent[NB_SCREENS] = 91static struct viewport parent[NB_SCREENS] =
@@ -90,20 +98,6 @@ static struct viewport parent[NB_SCREENS] =
90 .height = LCD_HEIGHT 98 .height = LCD_HEIGHT
91 }, 99 },
92}; 100};
93void list_init_viewports(struct gui_synclist *list)
94{
95 (void)list;
96 force_list_reinit = false;
97}
98#endif
99
100#ifdef HAVE_LCD_BITMAP
101bool list_display_title(struct gui_synclist *list, enum screen_type screen)
102{
103 return list->title != NULL &&
104 viewport_get_nb_lines(list->parent[screen])>2;
105}
106#else
107#define list_display_title(l, i) false 101#define list_display_title(l, i) false
108#endif 102#endif
109 103
@@ -141,9 +135,12 @@ void gui_synclist_init(struct gui_synclist * gui_list,
141 if (list_parent) 135 if (list_parent)
142 gui_list->parent[i] = &list_parent[i]; 136 gui_list->parent[i] = &list_parent[i];
143 else 137 else
144 { 138 gui_list->parent[i] =
145 gui_list->parent[i] = &parent[i]; 139#ifdef HAVE_LCD_BITMAP
146 } 140 NULL;
141#else
142 &parent[i];
143#endif
147 } 144 }
148 list_init_viewports(gui_list); 145 list_init_viewports(gui_list);
149 gui_list->limit_scroll = false; 146 gui_list->limit_scroll = false;
@@ -162,7 +159,6 @@ void gui_synclist_init(struct gui_synclist * gui_list,
162 gui_list->title_color = -1; 159 gui_list->title_color = -1;
163 gui_list->callback_get_item_color = NULL; 160 gui_list->callback_get_item_color = NULL;
164#endif 161#endif
165 force_list_reinit = true;
166} 162}
167 163
168/* this toggles the selection bar or cursor */ 164/* this toggles the selection bar or cursor */
@@ -218,7 +214,7 @@ void gui_synclist_draw(struct gui_synclist *gui_list)
218#ifdef HAVE_BUTTONBAR 214#ifdef HAVE_BUTTONBAR
219 static bool last_buttonbar = false; 215 static bool last_buttonbar = false;
220#endif 216#endif
221 if (force_list_reinit || 217 if (
222#ifdef HAVE_BUTTONBAR 218#ifdef HAVE_BUTTONBAR
223 last_buttonbar != screens[SCREEN_MAIN].has_buttonbar || 219 last_buttonbar != screens[SCREEN_MAIN].has_buttonbar ||
224#endif 220#endif
@@ -436,7 +432,6 @@ void gui_synclist_set_title(struct gui_synclist * gui_list,
436 } else { 432 } else {
437 gui_list->title_width = 0; 433 gui_list->title_width = 0;
438 } 434 }
439 force_list_reinit = true;
440} 435}
441 436
442 437
diff --git a/apps/gui/list.h b/apps/gui/list.h
index 50aaebe93a..23997e8a65 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -139,8 +139,6 @@ extern void gui_list_screen_scroll_step(int ofs);
139extern void gui_list_screen_scroll_out_of_view(bool enable); 139extern void gui_list_screen_scroll_out_of_view(bool enable);
140#endif /* HAVE_LCD_BITMAP */ 140#endif /* HAVE_LCD_BITMAP */
141 141
142void list_init_viewports(struct gui_synclist * lists);
143
144extern void gui_synclist_init( 142extern void gui_synclist_init(
145 struct gui_synclist * lists, 143 struct gui_synclist * lists,
146 list_get_name callback_get_item_name, 144 list_get_name callback_get_item_name,
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index 5e215090f5..024ade330f 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -263,7 +263,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
263 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info))) 263 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
264 { 264 {
265 struct viewport vp; 265 struct viewport vp;
266 viewport_set_defaults(&vp, display->screen_type); 266 viewport_set_fullscreen(&vp, display->screen_type);
267 vp.height = STATUSBAR_HEIGHT; 267 vp.height = STATUSBAR_HEIGHT;
268 vp.x = STATUSBAR_X_POS; 268 vp.x = STATUSBAR_X_POS;
269 if (statusbar_position(display->screen_type) != STATUSBAR_BOTTOM) 269 if (statusbar_position(display->screen_type) != STATUSBAR_BOTTOM)
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c
index ef527d90cc..bb4c291cc0 100644
--- a/apps/gui/viewport.c
+++ b/apps/gui/viewport.c
@@ -56,6 +56,22 @@
56 56
57static int statusbar_enabled = 0; 57static int statusbar_enabled = 0;
58 58
59#ifdef HAVE_LCD_BITMAP
60
61static struct {
62 struct viewport* vp;
63 int active;
64} ui_vp_info;
65
66static struct viewport custom_vp[NB_SCREENS];
67
68/* callbacks for GUI_EVENT_* events */
69static void viewportmanager_ui_vp_changed(void *param);
70static void statusbar_toggled(void* param);
71static int viewport_init_ui_vp(void);
72#endif
73static void viewportmanager_redraw(void* data);
74
59int viewport_get_nb_lines(struct viewport *vp) 75int viewport_get_nb_lines(struct viewport *vp)
60{ 76{
61#ifdef HAVE_LCD_BITMAP 77#ifdef HAVE_LCD_BITMAP
@@ -78,9 +94,9 @@ static bool showing_bars(enum screen_type screen)
78#endif 94#endif
79 } 95 }
80 return false; 96 return false;
81} 97}
82 98
83void viewport_set_defaults(struct viewport *vp, enum screen_type screen) 99void viewport_set_fullscreen(struct viewport *vp, enum screen_type screen)
84{ 100{
85 vp->x = 0; 101 vp->x = 0;
86 vp->width = screens[screen].lcdwidth; 102 vp->width = screens[screen].lcdwidth;
@@ -120,6 +136,30 @@ void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
120#endif 136#endif
121} 137}
122 138
139void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
140{
141#ifdef HAVE_LCD_BITMAP
142 if (ui_vp_info.active)
143 *vp = custom_vp[screen];
144 else
145#endif
146 viewport_set_fullscreen(vp, screen);
147}
148
149void viewportmanager_init(void)
150{
151 viewportmanager_set_statusbar(VP_SB_ALLSCREENS);
152#ifdef HAVE_LCD_BITMAP
153 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggled);
154 ui_vp_info.active = viewport_init_ui_vp();
155 ui_vp_info.vp = custom_vp;
156#endif
157}
158
159int viewportmanager_get_statusbar(void)
160{
161 return statusbar_enabled;
162}
123 163
124int viewportmanager_set_statusbar(int enabled) 164int viewportmanager_set_statusbar(int enabled)
125{ 165{
@@ -133,37 +173,101 @@ int viewportmanager_set_statusbar(int enabled)
133 if (showing_bars(i)) 173 if (showing_bars(i))
134 gui_statusbar_draw(&statusbars.statusbars[i], true); 174 gui_statusbar_draw(&statusbars.statusbars[i], true);
135 } 175 }
136 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_draw_statusbars); 176 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
137 } 177 }
138 else 178 else
139 { 179 {
140 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_draw_statusbars); 180 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw);
141 } 181 }
142 return old; 182 return old;
143} 183}
144 184
145void viewportmanager_draw_statusbars(void* data) 185static void viewportmanager_redraw(void* data)
146{ 186{
147 int i; 187 int i;
148 188
149 FOR_NB_SCREENS(i) 189 FOR_NB_SCREENS(i)
150 { 190 {
151 if (showing_bars(i)) 191 if (showing_bars(i))
152 gui_statusbar_draw(&statusbars.statusbars[i], (bool)data); 192 gui_statusbar_draw(&statusbars.statusbars[i], NULL != data);
153 } 193 }
154} 194}
195#ifdef HAVE_LCD_BITMAP
155 196
156void viewportmanager_statusbar_changed(void* data) 197static void statusbar_toggled(void* param)
157{ 198{
158 (void)data; 199 (void)param;
159 statusbar_enabled = 0; 200 /* update vp manager for the new setting and reposition vps
160 if (global_settings.statusbar != STATUSBAR_OFF) 201 * if necessary */
161 statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN); 202 viewportmanager_theme_changed(THEME_STATUSBAR);
203}
204
205void viewportmanager_theme_changed(int which)
206{
207 if (which & THEME_UI_VIEWPORT)
208 {
209 /* reset the ui viewport */
210 if ((ui_vp_info.active = viewport_init_ui_vp()))
211 add_event(GUI_EVENT_REFRESH, false, viewportmanager_ui_vp_changed);
212 else
213 remove_event(GUI_EVENT_REFRESH, viewportmanager_ui_vp_changed);
214 /* and point to it */
215 ui_vp_info.vp = custom_vp;
216 }
217 if (which & THEME_STATUSBAR)
218 {
219 statusbar_enabled = 0;
220 if (global_settings.statusbar != STATUSBAR_OFF)
221 statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN);
162#ifdef HAVE_REMOTE_LCD 222#ifdef HAVE_REMOTE_LCD
163 if (global_settings.remote_statusbar != STATUSBAR_OFF) 223 if (global_settings.remote_statusbar != STATUSBAR_OFF)
164 statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE); 224 statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE);
165#endif 225#endif
226 if (statusbar_enabled)
227 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
228 else
229 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw);
230
231 /* reposition viewport to fit statusbar, only if not using the ui vp */
232 if (!ui_vp_info.active)
233 {
234 int i;
235 FOR_NB_SCREENS(i)
236 viewport_set_fullscreen(&custom_vp[i], i);
237 }
238 }
239}
240
241static void viewportmanager_ui_vp_changed(void *param)
242{
243 /* if the user changed the theme, we need to initiate a full redraw */
244 int i;
245 /* cast param to a function */
246 void (*draw_func)(void) = ((void(*)(void))param);
247 /* start with clearing the screen */
248 FOR_NB_SCREENS(i)
249 screens[i].clear_display();
250 /* redraw the statusbar if it was enabled */
166 viewportmanager_set_statusbar(statusbar_enabled); 251 viewportmanager_set_statusbar(statusbar_enabled);
252 /* call the passed function which will redraw the content of
253 * the current screen */
254 if (param != NULL)
255 draw_func();
256 FOR_NB_SCREENS(i)
257 screens[i].update();
258}
259
260void viewport_set_current_vp(struct viewport* vp)
261{
262 if (vp != NULL)
263 ui_vp_info.vp = vp;
264 else
265 ui_vp_info.vp = custom_vp;
266}
267
268struct viewport* viewport_get_current_vp(void)
269{
270 return ui_vp_info.vp;
167} 271}
168 272
169#ifdef HAVE_LCD_COLOR 273#ifdef HAVE_LCD_COLOR
@@ -172,7 +276,6 @@ void viewportmanager_statusbar_changed(void* data)
172#define ARG_STRING(_depth) "dddddgg" 276#define ARG_STRING(_depth) "dddddgg"
173#endif 277#endif
174 278
175#ifdef HAVE_LCD_BITMAP
176const char* viewport_parse_viewport(struct viewport *vp, 279const char* viewport_parse_viewport(struct viewport *vp,
177 enum screen_type screen, 280 enum screen_type screen,
178 const char *bufptr, 281 const char *bufptr,
@@ -213,9 +316,9 @@ const char* viewport_parse_viewport(struct viewport *vp,
213 return NULL; 316 return NULL;
214 } 317 }
215 else 318 else
216#undef ARG_STRING
217#endif 319#endif
218 {} 320 {}
321#undef ARG_STRING
219 322
220 /* X and Y *must* be set */ 323 /* X and Y *must* be set */
221 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) 324 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
@@ -259,4 +362,40 @@ const char* viewport_parse_viewport(struct viewport *vp,
259 return ptr; 362 return ptr;
260} 363}
261 364
365/*
366 * (re)parse the UI vp from the settings
367 * - Returns
368 * 0 if no UI vp is used
369 * >0 if it's used at least partly (on multiscreen targets)
370 * NB_SCREENS if all screens have a UI vp
371 */
372static int viewport_init_ui_vp(void)
373{
374 int screen, ret = NB_SCREENS;
375 FOR_NB_SCREENS(screen)
376 {
377#ifdef HAVE_REMOTE_LCD
378 if ((screen == SCREEN_REMOTE))
379 {
380 if(!(viewport_parse_viewport(&custom_vp[screen], screen,
381 global_settings.remote_ui_vp_config, ',')))
382 {
383 viewport_set_fullscreen(&custom_vp[screen], screen);
384 ret--;
385 }
386 }
387 else
388#endif
389 {
390 if (!(viewport_parse_viewport(&custom_vp[screen], screen,
391 global_settings.ui_vp_config, ',')))
392 {
393 viewport_set_fullscreen(&custom_vp[screen], screen);
394 ret--;
395 }
396 }
397 }
398 return ret;
399}
400
262#endif /* HAVE_LCD_BITMAP */ 401#endif /* HAVE_LCD_BITMAP */
diff --git a/apps/gui/viewport.h b/apps/gui/viewport.h
index 6c3fb92998..2ed138b365 100644
--- a/apps/gui/viewport.h
+++ b/apps/gui/viewport.h
@@ -34,26 +34,6 @@ int viewport_get_nb_lines(struct viewport *vp);
34 34
35void viewport_set_defaults(struct viewport *vp, enum screen_type screen); 35void viewport_set_defaults(struct viewport *vp, enum screen_type screen);
36 36
37/* Parse a viewport definition (vp_def), which looks like:
38 *
39 * Screens with depth > 1:
40 * X|Y|width|height|font|foregorund color|background color
41 * Screens with depth = 1:
42 * X|Y|width|height|font
43 *
44 * | is a separator and can be specified via the parameter
45 *
46 * Returns the pointer to the char after the last character parsed
47 * if everything went OK or NULL if an error happened (some values
48 * not specified in the definition)
49 */
50#ifdef HAVE_LCD_BITMAP
51const char* viewport_parse_viewport(struct viewport *vp,
52 enum screen_type screen,
53 const char *vp_def,
54 const char separator);
55#endif
56
57/* Used to specify which screens the statusbar (SB) should be displayed on. 37/* Used to specify which screens the statusbar (SB) should be displayed on.
58 * 38 *
59 * The parameter is a bit OR'ed combination of the following (screen is 39 * The parameter is a bit OR'ed combination of the following (screen is
@@ -74,14 +54,70 @@ const char* viewport_parse_viewport(struct viewport *vp,
74 * Returns the status before the call. This value can be used to restore the 54 * Returns the status before the call. This value can be used to restore the
75 * SB "displaying rules". 55 * SB "displaying rules".
76 */ 56 */
57
58
59#define THEME_STATUSBAR (BIT_N(0))
60#define THEME_UI_VIEWPORT (BIT_N(1))
61#define THEME_ALL (~(0u))
62
77#define VP_SB_HIDE_ALL 0 63#define VP_SB_HIDE_ALL 0
78#define VP_SB_ONSCREEN(screen) BIT_N(screen) 64#define VP_SB_ONSCREEN(screen) BIT_N(screen)
79#define VP_SB_IGNORE_SETTING(screen) BIT_N(4+screen) 65#define VP_SB_IGNORE_SETTING(screen) BIT_N(4+screen)
80#define VP_SB_ALLSCREENS (VP_SB_ONSCREEN(0)|VP_SB_ONSCREEN(1)) 66#define VP_SB_ALLSCREENS (VP_SB_ONSCREEN(0)|VP_SB_ONSCREEN(1))
67
68/*
69 * Initialize the viewportmanager, which in turns initializes the UI vp and
70 * statusbar stuff
71 */
72void viewportmanager_init(void);
73int viewportmanager_get_statusbar(void);
81int viewportmanager_set_statusbar(int enabled); 74int viewportmanager_set_statusbar(int enabled);
82 75
83/* callbacks for GUI_EVENT_* events */ 76/* call this when a theme changed */
84void viewportmanager_draw_statusbars(void*data); 77void viewportmanager_theme_changed(int);
85void viewportmanager_statusbar_changed(void* data); 78
79/*
80 * Initializes the given viewport with maximum dimensions minus status- and
81 * buttonbar
82 */
83void viewport_set_fullscreen(struct viewport *vp, enum screen_type screen);
86 84
85#ifdef HAVE_LCD_BITMAP
86
87/*
88 * Parse a viewport definition (vp_def), which looks like:
89 *
90 * Screens with depth > 1:
91 * X|Y|width|height|font|foregorund color|background color
92 * Screens with depth = 1:
93 * X|Y|width|height|font
94 *
95 * | is a separator and can be specified via the parameter
96 *
97 * Returns the pointer to the char after the last character parsed
98 * if everything went OK or NULL if an error happened (some values
99 * not specified in the definition)
100 */
101const char* viewport_parse_viewport(struct viewport *vp,
102 enum screen_type screen,
103 const char *vp_def,
104 const char separator);
105
106/*
107 * Returns a pointer to the current viewport
108 * - That could be the UI vp, or a viewport passed to do_menu() or the like
109 */
110struct viewport* viewport_get_current_vp(void);
111
112/*
113 * Set the UI vp pointer to a different one - NULL to reset to the UI vp
114 *
115 * This is needed since the UI viewport needs is kept in RAM.
116 */
117void viewport_set_current_vp(struct viewport* vp);
118
119#else /* HAVE_LCD_CHARCELL */
120#define viewport_set_current_vp(a)
121#define viewport_get_current_vp() NULL
122#endif
87#endif /* __VIEWPORT_H__ */ 123#endif /* __VIEWPORT_H__ */
diff --git a/apps/gui/wps.c b/apps/gui/wps.c
index b57f06d2b5..055f8d01e6 100644
--- a/apps/gui/wps.c
+++ b/apps/gui/wps.c
@@ -565,6 +565,7 @@ static void gwps_leave_wps(void)
565 /* Play safe and unregister the hook */ 565 /* Play safe and unregister the hook */
566 lcd_activation_set_hook(NULL); 566 lcd_activation_set_hook(NULL);
567#endif 567#endif
568 send_event(GUI_EVENT_REFRESH, NULL);
568} 569}
569 570
570void gwps_draw_statusbars(void) 571void gwps_draw_statusbars(void)