summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2009-10-11 12:21:27 +0000
committerThomas Martitz <kugel@rockbox.org>2009-10-11 12:21:27 +0000
commita79dc877615c2af571bf0416dd2867c000701e7e (patch)
tree20be2176756c12d56d4e1947a05c2331fe1666ca /apps
parente171294c1d50dc4e4ba30339940a854c2b82d1ea (diff)
downloadrockbox-a79dc877615c2af571bf0416dd2867c000701e7e.tar.gz
rockbox-a79dc877615c2af571bf0416dd2867c000701e7e.tar.bz2
rockbox-a79dc877615c2af571bf0416dd2867c000701e7e.zip
Add a center flag, next to the rtl flag, for viewports. That results in any text being drawn centered. It overrides the RTL flag if set.
Simplify splashes and time menu by using it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23105 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/splash.c20
-rw-r--r--apps/gui/viewport.c13
-rw-r--r--apps/menus/time_menu.c33
3 files changed, 21 insertions, 45 deletions
diff --git a/apps/gui/splash.c b/apps/gui/splash.c
index 10a6885f92..aaa259c09d 100644
--- a/apps/gui/splash.c
+++ b/apps/gui/splash.c
@@ -48,7 +48,6 @@
static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
{
char splash_buf[MAXBUFFER];
- short widths[MAXLINES];
char *lines[MAXLINES];
char *next;
@@ -95,7 +94,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
if (x + (next - lastbreak) * space_w + w
> screen->lcdwidth - RECT_SPACING*2)
{ /* too wide, wrap */
- widths[line] = x;
#ifdef HAVE_LCD_BITMAP
if (x > maxw)
maxw = x;
@@ -118,7 +116,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
next = strtok_r(NULL, " ", &store);
if (!next)
{ /* no more words */
- widths[line] = x;
#ifdef HAVE_LCD_BITMAP
if (x > maxw)
maxw = x;
@@ -149,7 +146,8 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
vp.width = screen->lcdwidth;
if (vp.height > screen->lcdheight)
vp.height = screen->lcdheight;
-
+
+ vp.flags |= VP_FLAG_CENTER_ALIGN;
#if LCD_DEPTH > 1
if (screen->depth > 1)
{
@@ -179,7 +177,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
y = RECT_SPACING;
#else /* HAVE_LCD_CHARCELLS */
y = 0; /* vertical centering on 2 lines would be silly */
- x = 0;
screen->clear_display();
#endif
@@ -187,19 +184,10 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
for (i = 0; i <= line; i++, y+=h)
{
#ifdef HAVE_LCD_BITMAP
-#define W (vp.width - RECT_SPACING*2)
-#else
-#define W (screens->lcdwidth)
-#endif
- x = (W - widths[i])/2;
- if (x < 0)
- x = 0;
-#ifdef HAVE_LCD_BITMAP
- screen->putsxy(x+RECT_SPACING, y, lines[i]);
+ screen->putsxy(0, y, lines[i]);
#else
- screen->puts(x, y, lines[i]);
+ screen->puts(0, y, lines[i]);
#endif
-#undef W
}
screen->update_viewport();
end:
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c
index 6f9abb74a0..d5f45b3382 100644
--- a/apps/gui/viewport.c
+++ b/apps/gui/viewport.c
@@ -62,7 +62,7 @@
static int statusbar_enabled = 0;
#ifdef HAVE_LCD_BITMAP
-static void viewport_rtl_handler(struct viewport *vp);
+static void set_default_align_flags(struct viewport *vp);
static struct {
struct viewport* vp;
@@ -109,7 +109,7 @@ void viewport_set_fullscreen(struct viewport *vp,
vp->width = screens[screen].lcdwidth;
#ifdef HAVE_LCD_BITMAP
- viewport_rtl_handler(vp);
+ set_default_align_flags(vp);
vp->drawmode = DRMODE_SOLID;
vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */
@@ -245,7 +245,7 @@ void viewportmanager_theme_changed(const int which)
else if (which & THEME_LANGUAGE)
{ /* THEME_UI_VIEWPORT handles rtl already */
FOR_NB_SCREENS(i)
- viewport_rtl_handler(&custom_vp[i]);
+ set_default_align_flags(&custom_vp[i]);
}
if (which & THEME_STATUSBAR)
{
@@ -364,14 +364,13 @@ bool viewport_point_within_vp(const struct viewport *vp,
#ifdef HAVE_LCD_BITMAP
-static void viewport_rtl_handler(struct viewport *vp)
+static void set_default_align_flags(struct viewport *vp)
{
+ vp->flags &= ~VP_FLAG_ALIGNMENT_MASK;
#ifndef __PCTOOL__
if (UNLIKELY(lang_is_rtl()))
vp->flags |= VP_FLAG_IS_RTL;
- else
#endif
- vp->flags &= ~VP_FLAG_IS_RTL;
}
const char* viewport_parse_viewport(struct viewport *vp,
@@ -456,7 +455,7 @@ const char* viewport_parse_viewport(struct viewport *vp,
/* Set the defaults for fields not user-specified */
vp->drawmode = DRMODE_SOLID;
- viewport_rtl_handler(vp);
+ set_default_align_flags(vp);
return ptr;
}
diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c
index cb0e4aac5b..bc08374ba0 100644
--- a/apps/menus/time_menu.c
+++ b/apps/menus/time_menu.c
@@ -46,11 +46,9 @@
static int timedate_set(void)
{
- struct tm tm;
- int result;
-
/* Make a local copy of the time struct */
- memcpy(&tm, get_time(), sizeof(struct tm));
+ struct tm tm = *get_time();
+ int result;
/* do some range checks */
/* This prevents problems with time/date setting after a power loss */
@@ -160,21 +158,6 @@ static void talk_timedate(void)
}
}
-static void vp_puts_center(struct viewport *vp, struct screen *display,
- int line, const char *str)
-{
- int w, offset;
-
- display->getstringsize(str, &w, NULL);
- if (w > vp->width)
- display->puts_scroll(0, line, str);
- else
- {
- offset = (vp->width - w)/2;
- display->putsxy(offset, line * font_get(vp->font)->height, str);
- }
-}
-
static void draw_timedate(struct viewport *vp, struct screen *display)
{
struct tm *tm = get_time();
@@ -210,13 +193,14 @@ static void draw_timedate(struct viewport *vp, struct screen *display)
d = str(LANG_UNKNOWN);
}
- vp_puts_center(vp, display, line, t);
- line++;
- vp_puts_center(vp, display, line, d);
+ display->puts_scroll(0, line++, time);
+ display->puts_scroll(0, line, date);
display->update_viewport();
+ display->set_viewport(NULL);
}
+
static struct viewport clock[NB_SCREENS], menu[NB_SCREENS];
static bool menu_was_pressed;
static int time_menu_callback(int action,
@@ -281,7 +265,11 @@ int time_screen(void* ignored)
}
#endif
nb_lines = viewport_get_nb_lines(&clock[i]);
+
menu[i] = clock[i];
+ /* force time to be drawn centered */
+ clock[i].flags |= VP_FLAG_CENTER_ALIGN;
+
font_h = font_get(clock[i].font)->height;
if (nb_lines > 3)
{
@@ -302,6 +290,7 @@ int time_screen(void* ignored)
menu[i].height -= clock[i].height;
draw_timedate(&clock[i], &screens[i]);
}
+
ret = do_menu(&time_menu, NULL, menu, false);
/* see comments above in the button callback */
if (!menu_was_pressed && ret == GO_TO_PREVIOUS)