summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/splash.c20
-rw-r--r--apps/gui/viewport.c13
-rw-r--r--apps/menus/time_menu.c33
-rw-r--r--firmware/drivers/lcd-bitmap-common.c9
-rw-r--r--firmware/export/lcd.h8
5 files changed, 34 insertions, 49 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 @@
48static void splash_internal(struct screen * screen, const char *fmt, va_list ap) 48static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
49{ 49{
50 char splash_buf[MAXBUFFER]; 50 char splash_buf[MAXBUFFER];
51 short widths[MAXLINES];
52 char *lines[MAXLINES]; 51 char *lines[MAXLINES];
53 52
54 char *next; 53 char *next;
@@ -95,7 +94,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
95 if (x + (next - lastbreak) * space_w + w 94 if (x + (next - lastbreak) * space_w + w
96 > screen->lcdwidth - RECT_SPACING*2) 95 > screen->lcdwidth - RECT_SPACING*2)
97 { /* too wide, wrap */ 96 { /* too wide, wrap */
98 widths[line] = x;
99#ifdef HAVE_LCD_BITMAP 97#ifdef HAVE_LCD_BITMAP
100 if (x > maxw) 98 if (x > maxw)
101 maxw = x; 99 maxw = x;
@@ -118,7 +116,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
118 next = strtok_r(NULL, " ", &store); 116 next = strtok_r(NULL, " ", &store);
119 if (!next) 117 if (!next)
120 { /* no more words */ 118 { /* no more words */
121 widths[line] = x;
122#ifdef HAVE_LCD_BITMAP 119#ifdef HAVE_LCD_BITMAP
123 if (x > maxw) 120 if (x > maxw)
124 maxw = x; 121 maxw = x;
@@ -149,7 +146,8 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
149 vp.width = screen->lcdwidth; 146 vp.width = screen->lcdwidth;
150 if (vp.height > screen->lcdheight) 147 if (vp.height > screen->lcdheight)
151 vp.height = screen->lcdheight; 148 vp.height = screen->lcdheight;
152 149
150 vp.flags |= VP_FLAG_CENTER_ALIGN;
153#if LCD_DEPTH > 1 151#if LCD_DEPTH > 1
154 if (screen->depth > 1) 152 if (screen->depth > 1)
155 { 153 {
@@ -179,7 +177,6 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
179 y = RECT_SPACING; 177 y = RECT_SPACING;
180#else /* HAVE_LCD_CHARCELLS */ 178#else /* HAVE_LCD_CHARCELLS */
181 y = 0; /* vertical centering on 2 lines would be silly */ 179 y = 0; /* vertical centering on 2 lines would be silly */
182 x = 0;
183 screen->clear_display(); 180 screen->clear_display();
184#endif 181#endif
185 182
@@ -187,19 +184,10 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap)
187 for (i = 0; i <= line; i++, y+=h) 184 for (i = 0; i <= line; i++, y+=h)
188 { 185 {
189#ifdef HAVE_LCD_BITMAP 186#ifdef HAVE_LCD_BITMAP
190#define W (vp.width - RECT_SPACING*2) 187 screen->putsxy(0, y, lines[i]);
191#else
192#define W (screens->lcdwidth)
193#endif
194 x = (W - widths[i])/2;
195 if (x < 0)
196 x = 0;
197#ifdef HAVE_LCD_BITMAP
198 screen->putsxy(x+RECT_SPACING, y, lines[i]);
199#else 188#else
200 screen->puts(x, y, lines[i]); 189 screen->puts(0, y, lines[i]);
201#endif 190#endif
202#undef W
203 } 191 }
204 screen->update_viewport(); 192 screen->update_viewport();
205end: 193end:
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 @@
62static int statusbar_enabled = 0; 62static int statusbar_enabled = 0;
63 63
64#ifdef HAVE_LCD_BITMAP 64#ifdef HAVE_LCD_BITMAP
65static void viewport_rtl_handler(struct viewport *vp); 65static void set_default_align_flags(struct viewport *vp);
66 66
67static struct { 67static struct {
68 struct viewport* vp; 68 struct viewport* vp;
@@ -109,7 +109,7 @@ void viewport_set_fullscreen(struct viewport *vp,
109 vp->width = screens[screen].lcdwidth; 109 vp->width = screens[screen].lcdwidth;
110 110
111#ifdef HAVE_LCD_BITMAP 111#ifdef HAVE_LCD_BITMAP
112 viewport_rtl_handler(vp); 112 set_default_align_flags(vp);
113 vp->drawmode = DRMODE_SOLID; 113 vp->drawmode = DRMODE_SOLID;
114 vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */ 114 vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */
115 115
@@ -245,7 +245,7 @@ void viewportmanager_theme_changed(const int which)
245 else if (which & THEME_LANGUAGE) 245 else if (which & THEME_LANGUAGE)
246 { /* THEME_UI_VIEWPORT handles rtl already */ 246 { /* THEME_UI_VIEWPORT handles rtl already */
247 FOR_NB_SCREENS(i) 247 FOR_NB_SCREENS(i)
248 viewport_rtl_handler(&custom_vp[i]); 248 set_default_align_flags(&custom_vp[i]);
249 } 249 }
250 if (which & THEME_STATUSBAR) 250 if (which & THEME_STATUSBAR)
251 { 251 {
@@ -364,14 +364,13 @@ bool viewport_point_within_vp(const struct viewport *vp,
364 364
365#ifdef HAVE_LCD_BITMAP 365#ifdef HAVE_LCD_BITMAP
366 366
367static void viewport_rtl_handler(struct viewport *vp) 367static void set_default_align_flags(struct viewport *vp)
368{ 368{
369 vp->flags &= ~VP_FLAG_ALIGNMENT_MASK;
369#ifndef __PCTOOL__ 370#ifndef __PCTOOL__
370 if (UNLIKELY(lang_is_rtl())) 371 if (UNLIKELY(lang_is_rtl()))
371 vp->flags |= VP_FLAG_IS_RTL; 372 vp->flags |= VP_FLAG_IS_RTL;
372 else
373#endif 373#endif
374 vp->flags &= ~VP_FLAG_IS_RTL;
375} 374}
376 375
377const char* viewport_parse_viewport(struct viewport *vp, 376const char* viewport_parse_viewport(struct viewport *vp,
@@ -456,7 +455,7 @@ const char* viewport_parse_viewport(struct viewport *vp,
456 455
457 /* Set the defaults for fields not user-specified */ 456 /* Set the defaults for fields not user-specified */
458 vp->drawmode = DRMODE_SOLID; 457 vp->drawmode = DRMODE_SOLID;
459 viewport_rtl_handler(vp); 458 set_default_align_flags(vp);
460 459
461 return ptr; 460 return ptr;
462} 461}
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 @@
46 46
47static int timedate_set(void) 47static int timedate_set(void)
48{ 48{
49 struct tm tm;
50 int result;
51
52 /* Make a local copy of the time struct */ 49 /* Make a local copy of the time struct */
53 memcpy(&tm, get_time(), sizeof(struct tm)); 50 struct tm tm = *get_time();
51 int result;
54 52
55 /* do some range checks */ 53 /* do some range checks */
56 /* This prevents problems with time/date setting after a power loss */ 54 /* This prevents problems with time/date setting after a power loss */
@@ -160,21 +158,6 @@ static void talk_timedate(void)
160 } 158 }
161} 159}
162 160
163static void vp_puts_center(struct viewport *vp, struct screen *display,
164 int line, const char *str)
165{
166 int w, offset;
167
168 display->getstringsize(str, &w, NULL);
169 if (w > vp->width)
170 display->puts_scroll(0, line, str);
171 else
172 {
173 offset = (vp->width - w)/2;
174 display->putsxy(offset, line * font_get(vp->font)->height, str);
175 }
176}
177
178static void draw_timedate(struct viewport *vp, struct screen *display) 161static void draw_timedate(struct viewport *vp, struct screen *display)
179{ 162{
180 struct tm *tm = get_time(); 163 struct tm *tm = get_time();
@@ -210,13 +193,14 @@ static void draw_timedate(struct viewport *vp, struct screen *display)
210 d = str(LANG_UNKNOWN); 193 d = str(LANG_UNKNOWN);
211 } 194 }
212 195
213 vp_puts_center(vp, display, line, t); 196 display->puts_scroll(0, line++, time);
214 line++; 197 display->puts_scroll(0, line, date);
215 vp_puts_center(vp, display, line, d);
216 198
217 display->update_viewport(); 199 display->update_viewport();
200 display->set_viewport(NULL);
218} 201}
219 202
203
220static struct viewport clock[NB_SCREENS], menu[NB_SCREENS]; 204static struct viewport clock[NB_SCREENS], menu[NB_SCREENS];
221static bool menu_was_pressed; 205static bool menu_was_pressed;
222static int time_menu_callback(int action, 206static int time_menu_callback(int action,
@@ -281,7 +265,11 @@ int time_screen(void* ignored)
281 } 265 }
282#endif 266#endif
283 nb_lines = viewport_get_nb_lines(&clock[i]); 267 nb_lines = viewport_get_nb_lines(&clock[i]);
268
284 menu[i] = clock[i]; 269 menu[i] = clock[i];
270 /* force time to be drawn centered */
271 clock[i].flags |= VP_FLAG_CENTER_ALIGN;
272
285 font_h = font_get(clock[i].font)->height; 273 font_h = font_get(clock[i].font)->height;
286 if (nb_lines > 3) 274 if (nb_lines > 3)
287 { 275 {
@@ -302,6 +290,7 @@ int time_screen(void* ignored)
302 menu[i].height -= clock[i].height; 290 menu[i].height -= clock[i].height;
303 draw_timedate(&clock[i], &screens[i]); 291 draw_timedate(&clock[i], &screens[i]);
304 } 292 }
293
305 ret = do_menu(&time_menu, NULL, menu, false); 294 ret = do_menu(&time_menu, NULL, menu, false);
306 /* see comments above in the button callback */ 295 /* see comments above in the button callback */
307 if (!menu_was_pressed && ret == GO_TO_PREVIOUS) 296 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 38fa55b02d..5bf4706c59 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)
82 unsigned short ch; 82 unsigned short ch;
83 unsigned short *ucs; 83 unsigned short *ucs;
84 struct font* pf = font_get(current_vp->font); 84 struct font* pf = font_get(current_vp->font);
85 int vp_flags = current_vp->flags;
85 86
86 ucs = bidi_l2v(str, 1); 87 ucs = bidi_l2v(str, 1);
87 88
88 if (VP_IS_RTL(current_vp)) 89 if ((vp_flags & VP_FLAG_ALIGNMENT_MASK) != 0)
89 { 90 {
90 int w; 91 int w;
91 92
92 LCDFN(getstringsize)(str, &w, NULL); 93 LCDFN(getstringsize)(str, &w, NULL);
93 x = current_vp->width - w - x; 94 /* center takes precedence */
95 if (vp_flags & VP_FLAG_CENTER_ALIGN)
96 x = ((current_vp->width - w)/ 2) + x;
97 else
98 x = current_vp->width - w - x;
94 } 99 }
95 100
96 while ((ch = *ucs++) != 0 && x < current_vp->width) 101 while ((ch = *ucs++) != 0 && x < current_vp->width)
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 2c66b5f8b3..463714ff03 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -26,9 +26,13 @@
26#include "cpu.h" 26#include "cpu.h"
27#include "config.h" 27#include "config.h"
28 28
29#define VP_FLAG_IS_RTL 0x01 29#define VP_FLAG_IS_RTL 0x01
30#define VP_FLAG_CENTER_ALIGN 0x02
30 31
31#define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_IS_RTL) != 0) 32#define VP_FLAG_ALIGNMENT_MASK \
33 (VP_FLAG_IS_RTL|VP_FLAG_CENTER_ALIGN)
34
35#define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_ALIGNMENT_MASK) == VP_FLAG_IS_RTL)
32 36
33struct viewport { 37struct viewport {
34 int x; 38 int x;