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)
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 */
/* should lines scroll out of the screen */
static bool offset_out_of_view = false;
#endif
-static int force_list_reinit = false;
static void gui_list_select_at_offset(struct gui_synclist * gui_list,
int offset);
void list_draw(struct screen *display, struct gui_synclist *list);
#ifdef HAVE_LCD_BITMAP
-static struct viewport parent[NB_SCREENS];
-void list_init_viewports(struct gui_synclist *list)
+static void list_init_viewports(struct gui_synclist *list)
{
+ struct viewport* vp;
int i;
- struct viewport *vp;
- FOR_NB_SCREENS(i)
+ bool parent_used = (*list->parent != NULL);
+ if (!parent_used)
{
- vp = &parent[i];
- if (!list || list->parent[i] == vp)
- viewport_set_defaults(vp, i);
+ vp = viewport_get_current_vp();
+ FOR_NB_SCREENS(i)
+ list->parent[i] = &vp[i];
}
#ifdef HAVE_BUTTONBAR
- if (list && (list->parent[0] == &parent[0]) && global_settings.buttonbar)
+ if (list && !parent_used[SCREEN_MAIN] && global_settings.buttonbar)
list->parent[0]->height -= BUTTONBAR_HEIGHT;
#endif
- force_list_reinit = false;
+}
+#else
+#define list_init_viewports(a)
+#endif
+
+#ifdef HAVE_LCD_BITMAP
+bool list_display_title(struct gui_synclist *list, enum screen_type screen)
+{
+ return list->title != NULL &&
+ viewport_get_nb_lines(list->parent[screen])>2;
}
#else
static struct viewport parent[NB_SCREENS] =
@@ -90,20 +98,6 @@ static struct viewport parent[NB_SCREENS] =
.height = LCD_HEIGHT
},
};
-void list_init_viewports(struct gui_synclist *list)
-{
- (void)list;
- force_list_reinit = false;
-}
-#endif
-
-#ifdef HAVE_LCD_BITMAP
-bool list_display_title(struct gui_synclist *list, enum screen_type screen)
-{
- return list->title != NULL &&
- viewport_get_nb_lines(list->parent[screen])>2;
-}
-#else
#define list_display_title(l, i) false
#endif
@@ -141,9 +135,12 @@ void gui_synclist_init(struct gui_synclist * gui_list,
if (list_parent)
gui_list->parent[i] = &list_parent[i];
else
- {
- gui_list->parent[i] = &parent[i];
- }
+ gui_list->parent[i] =
+#ifdef HAVE_LCD_BITMAP
+ NULL;
+#else
+ &parent[i];
+#endif
}
list_init_viewports(gui_list);
gui_list->limit_scroll = false;
@@ -162,7 +159,6 @@ void gui_synclist_init(struct gui_synclist * gui_list,
gui_list->title_color = -1;
gui_list->callback_get_item_color = NULL;
#endif
- force_list_reinit = true;
}
/* this toggles the selection bar or cursor */
@@ -218,7 +214,7 @@ void gui_synclist_draw(struct gui_synclist *gui_list)
#ifdef HAVE_BUTTONBAR
static bool last_buttonbar = false;
#endif
- if (force_list_reinit ||
+ if (
#ifdef HAVE_BUTTONBAR
last_buttonbar != screens[SCREEN_MAIN].has_buttonbar ||
#endif
@@ -436,7 +432,6 @@ void gui_synclist_set_title(struct gui_synclist * gui_list,
} else {
gui_list->title_width = 0;
}
- force_list_reinit = true;
}
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);
extern void gui_list_screen_scroll_out_of_view(bool enable);
#endif /* HAVE_LCD_BITMAP */
-void list_init_viewports(struct gui_synclist * lists);
-
extern void gui_synclist_init(
struct gui_synclist * lists,
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)
memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
{
struct viewport vp;
- viewport_set_defaults(&vp, display->screen_type);
+ viewport_set_fullscreen(&vp, display->screen_type);
vp.height = STATUSBAR_HEIGHT;
vp.x = STATUSBAR_X_POS;
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 @@
static int statusbar_enabled = 0;
+#ifdef HAVE_LCD_BITMAP
+
+static struct {
+ struct viewport* vp;
+ int active;
+} ui_vp_info;
+
+static struct viewport custom_vp[NB_SCREENS];
+
+/* callbacks for GUI_EVENT_* events */
+static void viewportmanager_ui_vp_changed(void *param);
+static void statusbar_toggled(void* param);
+static int viewport_init_ui_vp(void);
+#endif
+static void viewportmanager_redraw(void* data);
+
int viewport_get_nb_lines(struct viewport *vp)
{
#ifdef HAVE_LCD_BITMAP
@@ -78,9 +94,9 @@ static bool showing_bars(enum screen_type screen)
#endif
}
return false;
-}
+}
-void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
+void viewport_set_fullscreen(struct viewport *vp, enum screen_type screen)
{
vp->x = 0;
vp->width = screens[screen].lcdwidth;
@@ -120,6 +136,30 @@ void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
#endif
}
+void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
+{
+#ifdef HAVE_LCD_BITMAP
+ if (ui_vp_info.active)
+ *vp = custom_vp[screen];
+ else
+#endif
+ viewport_set_fullscreen(vp, screen);
+}
+
+void viewportmanager_init(void)
+{
+ viewportmanager_set_statusbar(VP_SB_ALLSCREENS);
+#ifdef HAVE_LCD_BITMAP
+ add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggled);
+ ui_vp_info.active = viewport_init_ui_vp();
+ ui_vp_info.vp = custom_vp;
+#endif
+}
+
+int viewportmanager_get_statusbar(void)
+{
+ return statusbar_enabled;
+}
int viewportmanager_set_statusbar(int enabled)
{
@@ -133,37 +173,101 @@ int viewportmanager_set_statusbar(int enabled)
if (showing_bars(i))
gui_statusbar_draw(&statusbars.statusbars[i], true);
}
- add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_draw_statusbars);
+ add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
}
else
{
- remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_draw_statusbars);
+ remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw);
}
return old;
}
-void viewportmanager_draw_statusbars(void* data)
+static void viewportmanager_redraw(void* data)
{
int i;
FOR_NB_SCREENS(i)
{
if (showing_bars(i))
- gui_statusbar_draw(&statusbars.statusbars[i], (bool)data);
+ gui_statusbar_draw(&statusbars.statusbars[i], NULL != data);
}
}
+#ifdef HAVE_LCD_BITMAP
-void viewportmanager_statusbar_changed(void* data)
+static void statusbar_toggled(void* param)
{
- (void)data;
- statusbar_enabled = 0;
- if (global_settings.statusbar != STATUSBAR_OFF)
- statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN);
+ (void)param;
+ /* update vp manager for the new setting and reposition vps
+ * if necessary */
+ viewportmanager_theme_changed(THEME_STATUSBAR);
+}
+
+void viewportmanager_theme_changed(int which)
+{
+ if (which & THEME_UI_VIEWPORT)
+ {
+ /* reset the ui viewport */
+ if ((ui_vp_info.active = viewport_init_ui_vp()))
+ add_event(GUI_EVENT_REFRESH, false, viewportmanager_ui_vp_changed);
+ else
+ remove_event(GUI_EVENT_REFRESH, viewportmanager_ui_vp_changed);
+ /* and point to it */
+ ui_vp_info.vp = custom_vp;
+ }
+ if (which & THEME_STATUSBAR)
+ {
+ statusbar_enabled = 0;
+ if (global_settings.statusbar != STATUSBAR_OFF)
+ statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN);
#ifdef HAVE_REMOTE_LCD
- if (global_settings.remote_statusbar != STATUSBAR_OFF)
- statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE);
+ if (global_settings.remote_statusbar != STATUSBAR_OFF)
+ statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE);
#endif
+ if (statusbar_enabled)
+ add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
+ else
+ remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw);
+
+ /* reposition viewport to fit statusbar, only if not using the ui vp */
+ if (!ui_vp_info.active)
+ {
+ int i;
+ FOR_NB_SCREENS(i)
+ viewport_set_fullscreen(&custom_vp[i], i);
+ }
+ }
+}
+
+static void viewportmanager_ui_vp_changed(void *param)
+{
+ /* if the user changed the theme, we need to initiate a full redraw */
+ int i;
+ /* cast param to a function */
+ void (*draw_func)(void) = ((void(*)(void))param);
+ /* start with clearing the screen */
+ FOR_NB_SCREENS(i)
+ screens[i].clear_display();
+ /* redraw the statusbar if it was enabled */
viewportmanager_set_statusbar(statusbar_enabled);
+ /* call the passed function which will redraw the content of
+ * the current screen */
+ if (param != NULL)
+ draw_func();
+ FOR_NB_SCREENS(i)
+ screens[i].update();
+}
+
+void viewport_set_current_vp(struct viewport* vp)
+{
+ if (vp != NULL)
+ ui_vp_info.vp = vp;
+ else
+ ui_vp_info.vp = custom_vp;
+}
+
+struct viewport* viewport_get_current_vp(void)
+{
+ return ui_vp_info.vp;
}
#ifdef HAVE_LCD_COLOR
@@ -172,7 +276,6 @@ void viewportmanager_statusbar_changed(void* data)
#define ARG_STRING(_depth) "dddddgg"
#endif
-#ifdef HAVE_LCD_BITMAP
const char* viewport_parse_viewport(struct viewport *vp,
enum screen_type screen,
const char *bufptr,
@@ -213,9 +316,9 @@ const char* viewport_parse_viewport(struct viewport *vp,
return NULL;
}
else
-#undef ARG_STRING
#endif
{}
+#undef ARG_STRING
/* X and Y *must* be set */
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,
return ptr;
}
+/*
+ * (re)parse the UI vp from the settings
+ * - Returns
+ * 0 if no UI vp is used
+ * >0 if it's used at least partly (on multiscreen targets)
+ * NB_SCREENS if all screens have a UI vp
+ */
+static int viewport_init_ui_vp(void)
+{
+ int screen, ret = NB_SCREENS;
+ FOR_NB_SCREENS(screen)
+ {
+#ifdef HAVE_REMOTE_LCD
+ if ((screen == SCREEN_REMOTE))
+ {
+ if(!(viewport_parse_viewport(&custom_vp[screen], screen,
+ global_settings.remote_ui_vp_config, ',')))
+ {
+ viewport_set_fullscreen(&custom_vp[screen], screen);
+ ret--;
+ }
+ }
+ else
+#endif
+ {
+ if (!(viewport_parse_viewport(&custom_vp[screen], screen,
+ global_settings.ui_vp_config, ',')))
+ {
+ viewport_set_fullscreen(&custom_vp[screen], screen);
+ ret--;
+ }
+ }
+ }
+ return ret;
+}
+
#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);
void viewport_set_defaults(struct viewport *vp, enum screen_type screen);
-/* Parse a viewport definition (vp_def), which looks like:
- *
- * Screens with depth > 1:
- * X|Y|width|height|font|foregorund color|background color
- * Screens with depth = 1:
- * X|Y|width|height|font
- *
- * | is a separator and can be specified via the parameter
- *
- * Returns the pointer to the char after the last character parsed
- * if everything went OK or NULL if an error happened (some values
- * not specified in the definition)
- */
-#ifdef HAVE_LCD_BITMAP
-const char* viewport_parse_viewport(struct viewport *vp,
- enum screen_type screen,
- const char *vp_def,
- const char separator);
-#endif
-
/* Used to specify which screens the statusbar (SB) should be displayed on.
*
* 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,
* Returns the status before the call. This value can be used to restore the
* SB "displaying rules".
*/
+
+
+#define THEME_STATUSBAR (BIT_N(0))
+#define THEME_UI_VIEWPORT (BIT_N(1))
+#define THEME_ALL (~(0u))
+
#define VP_SB_HIDE_ALL 0
#define VP_SB_ONSCREEN(screen) BIT_N(screen)
#define VP_SB_IGNORE_SETTING(screen) BIT_N(4+screen)
#define VP_SB_ALLSCREENS (VP_SB_ONSCREEN(0)|VP_SB_ONSCREEN(1))
+
+/*
+ * Initialize the viewportmanager, which in turns initializes the UI vp and
+ * statusbar stuff
+ */
+void viewportmanager_init(void);
+int viewportmanager_get_statusbar(void);
int viewportmanager_set_statusbar(int enabled);
-/* callbacks for GUI_EVENT_* events */
-void viewportmanager_draw_statusbars(void*data);
-void viewportmanager_statusbar_changed(void* data);
+/* call this when a theme changed */
+void viewportmanager_theme_changed(int);
+
+/*
+ * Initializes the given viewport with maximum dimensions minus status- and
+ * buttonbar
+ */
+void viewport_set_fullscreen(struct viewport *vp, enum screen_type screen);
+#ifdef HAVE_LCD_BITMAP
+
+/*
+ * Parse a viewport definition (vp_def), which looks like:
+ *
+ * Screens with depth > 1:
+ * X|Y|width|height|font|foregorund color|background color
+ * Screens with depth = 1:
+ * X|Y|width|height|font
+ *
+ * | is a separator and can be specified via the parameter
+ *
+ * Returns the pointer to the char after the last character parsed
+ * if everything went OK or NULL if an error happened (some values
+ * not specified in the definition)
+ */
+const char* viewport_parse_viewport(struct viewport *vp,
+ enum screen_type screen,
+ const char *vp_def,
+ const char separator);
+
+/*
+ * Returns a pointer to the current viewport
+ * - That could be the UI vp, or a viewport passed to do_menu() or the like
+ */
+struct viewport* viewport_get_current_vp(void);
+
+/*
+ * Set the UI vp pointer to a different one - NULL to reset to the UI vp
+ *
+ * This is needed since the UI viewport needs is kept in RAM.
+ */
+void viewport_set_current_vp(struct viewport* vp);
+
+#else /* HAVE_LCD_CHARCELL */
+#define viewport_set_current_vp(a)
+#define viewport_get_current_vp() NULL
+#endif
#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)
/* Play safe and unregister the hook */
lcd_activation_set_hook(NULL);
#endif
+ send_event(GUI_EVENT_REFRESH, NULL);
}
void gwps_draw_statusbars(void)