aboutsummaryrefslogtreecommitdiffstats
path: root/minui
diff options
context:
space:
mode:
authorTom Marshall <tdm@cyngn.com>2014-03-27 09:18:00 -0700
committerTom Marshall <tdm@cyngn.com>2015-11-25 15:35:22 -0800
commit8e614b89838dda1adff952c0bfbb02721bb5db2b (patch)
tree1424980ad0021219328b3779eee9bae9380d9bc6 /minui
parenta48fd33655b2d95c250f033eaf88999cfb66e8ea (diff)
downloadbootable_recovery-8e614b89838dda1adff952c0bfbb02721bb5db2b.zip
bootable_recovery-8e614b89838dda1adff952c0bfbb02721bb5db2b.tar.gz
bootable_recovery-8e614b89838dda1adff952c0bfbb02721bb5db2b.tar.bz2
sr: Touch UI
Change-Id: I4ee87f3474aec0496c47bb561ddecc74e151cbbf
Diffstat (limited to 'minui')
-rw-r--r--minui/graphics.cpp43
-rw-r--r--minui/minui.h1
2 files changed, 41 insertions, 3 deletions
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 43c28ce..1f25531 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -41,6 +41,20 @@ struct GRFont {
int cheight;
};
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+#endif
+
+typedef struct {
+ char name[80];
+ GRFont* font;
+} font_item;
+
+static font_item gr_fonts[] = {
+ { "menu", NULL },
+ { "log", NULL },
+};
+
static GRFont* gr_font = NULL;
static minui_backend* gr_backend = NULL;
@@ -261,6 +275,17 @@ void gr_fill(int x1, int y1, int x2, int y2)
}
}
+void gr_set_font(const char* name)
+{
+ unsigned int idx;
+ for (idx = 0; idx < ARRAY_SIZE(gr_fonts); ++idx) {
+ if (strcmp(name, gr_fonts[idx].name) == 0) {
+ gr_font = gr_fonts[idx].font;
+ break;
+ }
+ }
+}
+
void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
if (source == NULL) return;
@@ -299,11 +324,14 @@ unsigned int gr_get_height(GRSurface* surface) {
return surface->height;
}
-static void gr_init_font(void)
+static void gr_init_one_font(int idx)
{
- gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
+ char name[80];
+ GRFont* gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
+ snprintf(name, sizeof(name), "font_%s", gr_fonts[idx].name);
+ gr_fonts[idx].font = gr_font;
- int res = res_create_alpha_surface("font", &(gr_font->texture));
+ int res = res_create_alpha_surface(name, &(gr_font->texture));
if (res == 0) {
// The font image should be a 96x2 array of character images. The
// columns are the printable ASCII characters 0x20 - 0x7f. The
@@ -335,6 +363,15 @@ static void gr_init_font(void)
}
}
+static void gr_init_font()
+{
+ unsigned int idx;
+ for (idx = 0; idx < ARRAY_SIZE(gr_fonts); ++idx) {
+ gr_init_one_font(idx);
+ }
+ gr_font = gr_fonts[0].font;
+}
+
#if 0
// Exercises many of the gr_*() functions; useful for testing.
static void gr_test() {
diff --git a/minui/minui.h b/minui/minui.h
index 7dec2d7..063fc86 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -45,6 +45,7 @@ void gr_fb_blank(bool blank);
void gr_clear(); // clear entire surface to current color
void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
void gr_fill(int x1, int y1, int x2, int y2);
+void gr_set_font(const char* name);
void gr_text(int x, int y, const char *s, bool bold);
void gr_texticon(int x, int y, GRSurface* icon);
int gr_measure(const char *s);