altos: Add AO_STACK_CANARY to detect stack overflows sometimes
[fw/altos] / src / draw / lco-test.c
index 02d2b5decf0a4f926efad3ed0ccf5c9096da2f96..74671de57f8bfe0cc2364f04a813bef43c5554da 100644 (file)
 #define PASS_KEYS
 #include "test-frame.c"
 
-#define BIG_FONT FrutigerLT_Roman_64_font
-#define VOLT_FONT FrutigerLT_Roman_64_font
-#define SMALL_FONT NotoMono_12_font
-#define TINY_FONT NotoMono_10_font
+#define BIG_FONT BitstreamVeraSans_Roman_58_font
+#define VOLT_FONT BitstreamVeraSans_Roman_58_font
+#define SMALL_FONT BitstreamVeraSans_Roman_12_font
+#define TINY_FONT BitstreamVeraSans_Roman_12_font
 #define LOGO_FONT BenguiatGothicStd_Bold_26_font
 
 #define LABEL_Y                (int16_t) (SMALL_FONT.ascent)
-#define VALUE_Y                (int16_t) (LABEL_Y + BIG_FONT.ascent)
+#define VALUE_Y                (int16_t) (LABEL_Y + BIG_FONT.ascent + 3)
 #define BOX_X          2
 #define PAD_X          90
 #define BOX_LABEL_X    30
 #define RSSI_LABEL_X   15
 #define PAD_LABEL_X    95
 #define SEP_X          (PAD_X - 10)
+#define SCAN_X         (WIDTH - 100) / 2
+#define SCAN_Y         49
+#define SCAN_HEIGHT    4
+#define FOUND_Y                63
+#define FOUND_WIDTH    21
+#define MAX_VALID      (WIDTH / FOUND_WIDTH)
 
 static int     box_number = 1;
 static int     pad_number = 1;
@@ -80,13 +86,6 @@ static const struct ao_transform logo_transform = {
        .y_scale = 48, .y_off = 0,
 };
 
-#define SCAN_X         (WIDTH - 100) / 2
-#define SCAN_Y         51
-#define SCAN_HEIGHT    4
-#define FOUND_Y                64
-#define FOUND_WIDTH    14
-#define MAX_VALID      (WIDTH / FOUND_WIDTH)
-
 static const struct ao_transform bowtie_transform = {
        .x_scale = 1, .x_off = 50,
        .y_scale = 1, .y_off = 20,
@@ -136,14 +135,18 @@ prev_box(void)
        box_number = max_box;
 }
 
+static bool redraw_all = true;
+
 void HandleExpose(Display *dpy, Window win, GC gc)
 {
        char    str[64];
        int     i;
        int     v;
+       int     last_box;
        int16_t b;
 
-       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
+       if (redraw_all)
+               ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
 
        if (do_polys == 1)
                current_timeout = TIMEOUT;
@@ -151,13 +154,19 @@ void HandleExpose(Display *dpy, Window win, GC gc)
                current_timeout = 0;
        switch (do_polys) {
        case 1:
-               ao_logo(&fb, &logo_transform, &LOGO_FONT, 0x00000000, AO_COPY);
+               if (redraw_all)
+                       ao_logo(&fb, &logo_transform, &LOGO_FONT, 0x00000000, AO_COPY);
+               else
+                       ao_rect(&fb, 0, SCAN_Y, WIDTH, HEIGHT-SCAN_Y, 0xffffffff, AO_COPY);
                if (scan_number) {
                        ao_rect(&fb, SCAN_X, SCAN_Y, (int16_t) scan_number, SCAN_HEIGHT, 0x00000000, AO_COPY);
                        b = 0;
                        v = 0;
+                       last_box = 0;
                        for (i = scan_number; i > 1; i--) {
                                if (valid_box(i)) {
+                                       if (!last_box)
+                                               last_box = i;
                                        v++;
                                        if (v == MAX_VALID)
                                                break;
@@ -165,11 +174,12 @@ void HandleExpose(Display *dpy, Window win, GC gc)
                        }
                        for (; i <= scan_number; i++) {
                                if (valid_box(i)) {
-                                       sprintf(str, "%02d", i);
+                                       sprintf(str, "%02d%s", i, i == last_box ? "" : ",");
                                        ao_text(&fb, &TINY_FONT, 0 + FOUND_WIDTH * b, FOUND_Y, str, 0x00000000, AO_COPY);
                                        b++;
                                }
                        }
+                       redraw_all = false;
                }
                break;
        case 2:
@@ -222,6 +232,8 @@ void
 HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev)
 {
        char    string[10];
+
+       redraw_all = true;
        if (XLookupString ((XKeyEvent *) ev, string, sizeof (string), 0, 0) >= 1) {
                switch (string[0]) {
                case 'q':
@@ -291,6 +303,7 @@ HandleTimeout(Display *dpy, Window win, GC gc)
                if (scan_number < 99)
                        scan_number++;
                else {
+                       redraw_all = true;
                        box_number = boxes[0];
                        pad_number = 1;
                        do_polys = 0;