From e1ef5b3dd79f0c5954804dbaf3a1dfd7555c2014 Mon Sep 17 00:00:00 2001 From: kugel Date: Sun, 11 Oct 2009 12:21:27 +0000 Subject: [PATCH] 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 --- apps/gui/splash.c | 20 ++++---------------- apps/gui/viewport.c | 13 ++++++------- apps/menus/time_menu.c | 33 +++++++++++---------------------- firmware/drivers/lcd-bitmap-common.c | 9 +++++++-- firmware/export/lcd.h | 8 ++++++-- 5 files changed, 34 insertions(+), 49 deletions(-) diff --git a/apps/gui/splash.c b/apps/gui/splash.c index 10a6885f9..aaa259c09 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 6f9abb74a..d5f45b338 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 cb0e4aac5..bc08374ba 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) diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 38fa55b02..5bf4706c5 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c @@ -82,15 +82,20 @@ static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str) unsigned short ch; unsigned short *ucs; struct font* pf = font_get(current_vp->font); + int vp_flags = current_vp->flags; ucs = bidi_l2v(str, 1); - if (VP_IS_RTL(current_vp)) + if ((vp_flags & VP_FLAG_ALIGNMENT_MASK) != 0) { int w; LCDFN(getstringsize)(str, &w, NULL); - x = current_vp->width - w - x; + /* center takes precedence */ + if (vp_flags & VP_FLAG_CENTER_ALIGN) + x = ((current_vp->width - w)/ 2) + x; + else + x = current_vp->width - w - x; } while ((ch = *ucs++) != 0 && x < current_vp->width) diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 2c66b5f8b..463714ff0 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h @@ -26,9 +26,13 @@ #include "cpu.h" #include "config.h" -#define VP_FLAG_IS_RTL 0x01 +#define VP_FLAG_IS_RTL 0x01 +#define VP_FLAG_CENTER_ALIGN 0x02 -#define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_IS_RTL) != 0) +#define VP_FLAG_ALIGNMENT_MASK \ + (VP_FLAG_IS_RTL|VP_FLAG_CENTER_ALIGN) + +#define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_ALIGNMENT_MASK) == VP_FLAG_IS_RTL) struct viewport { int x; -- 2.11.4.GIT