summaryrefslogtreecommitdiff
path: root/bootloader/x1000/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/x1000/gui.c')
-rw-r--r--bootloader/x1000/gui.c69
1 files changed, 57 insertions, 12 deletions
diff --git a/bootloader/x1000/gui.c b/bootloader/x1000/gui.c
index a672c30380..513a3cb9cb 100644
--- a/bootloader/x1000/gui.c
+++ b/bootloader/x1000/gui.c
@@ -29,6 +29,8 @@
29#include "button.h" 29#include "button.h"
30#include "version.h" 30#include "version.h"
31#include <string.h> 31#include <string.h>
32#include <stdarg.h>
33#include <stdio.h>
32 34
33static bool lcd_inited = false; 35static bool lcd_inited = false;
34extern bool is_usb_connected; 36extern bool is_usb_connected;
@@ -53,27 +55,70 @@ void putcenter_y(int y, const char* msg)
53 lcd_putsxy(x, y, msg); 55 lcd_putsxy(x, y, msg);
54} 56}
55 57
56void putcenter_line(int line, const char* msg) 58static void get_splash_size(const char* str, int* width, int* height)
57{ 59{
58 int y = LCD_HEIGHT/2 + (line - 1)*SYSFONT_HEIGHT; 60 *width = 0;
59 putcenter_y(y, msg); 61 *height = 0;
62
63 while(str) {
64 const char* np = strchr(str, '\n');
65 int len;
66 if(np) {
67 len = np - str;
68 np++;
69 } else {
70 len = strlen(str);
71 }
72
73 *width = MAX(len, *width);
74 *height += 1;
75 str = np;
76 }
60} 77}
61 78
62void splash2(long delay, const char* msg, const char* msg2) 79void splashf(long delay, const char* msg, ...)
63{ 80{
81 static char buf[512];
82
83 va_list ap;
84 va_start(ap, msg);
85 int len = vsnprintf(buf, sizeof(buf), msg, ap);
86 va_end(ap);
87
88 if(len < 0)
89 return;
90
91 int xpos, ypos;
92 int width, height;
93 get_splash_size(buf, &width, &height);
94
95 width *= SYSFONT_WIDTH;
96 height *= SYSFONT_HEIGHT;
97 xpos = (LCD_WIDTH - width) / 2;
98 ypos = (LCD_HEIGHT - height) / 2;
99
100 const int padding = 10;
64 clearscreen(); 101 clearscreen();
65 putcenter_line(0, msg); 102 lcd_drawrect(xpos-padding, ypos-padding,
66 if(msg2) 103 width+2*padding, height+2*padding);
67 putcenter_line(1, msg2); 104
105 char* str = buf;
106 do {
107 char* np = strchr(str, '\n');
108 if(np) {
109 *np = '\0';
110 np++;
111 }
112
113 lcd_putsxyf(xpos, ypos, "%s", str);
114 ypos += SYSFONT_HEIGHT;
115 str = np;
116 } while(str);
117
68 lcd_update(); 118 lcd_update();
69 sleep(delay); 119 sleep(delay);
70} 120}
71 121
72void splash(long delay, const char* msg)
73{
74 splash2(delay, msg, NULL);
75}
76
77int get_button(int timeout) 122int get_button(int timeout)
78{ 123{
79 int btn = button_get_w_tmo(timeout); 124 int btn = button_get_w_tmo(timeout);