altos/draw: Make test drawing app emulate TeleLCO
authorKeith Packard <keithp@keithp.com>
Sun, 26 Feb 2023 06:39:07 +0000 (22:39 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 26 Feb 2023 06:47:51 +0000 (22:47 -0800)
Draw some numbers for box and pad. Also allow display of a couple of
polygons.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/draw/draw-test.c
src/draw/frame.c

index 9487aa31bdf3005b1308406ef7859213e629a0c0..2f8ca636462a32d79957f7573d183deb03fb74b1 100644 (file)
@@ -22,6 +22,7 @@
 #define DEFAULT_WIDTH  WIDTH
 #define DEFAULT_HEIGHT HEIGHT
 
+#define PASS_KEYS
 #include "frame.c"
 #include "ao_draw.h"
 
@@ -47,17 +48,54 @@ static struct ao_bitmap fb = {
 #define PAD_LABEL_X    95
 #define SEP_X          (PAD_X - 8)
 
+static int     box_number = 1;
+static int     pad_number = 1;
+static bool    do_polys = false;
+
+static const struct ao_coord trek[] = {
+       { .x = 90, .y = 0 },
+       { .x = 60, .y = 40 },
+       { .x = 90, .y = 20 },
+       { .x = 120, .y = 40 },
+};
+
+#define NCOORD_TREK (sizeof(trek)/sizeof(trek[0]))
+
+static const struct ao_coord donut[] = {
+       { .x = 30, .y = 0 },
+       { .x = 0, .y = 30 },
+       { .x = 30, .y = 60 },
+       { .x = 60, .y = 30 },
+       { .x = 30, .y = 0 },
+       { .x = 30, .y = 10 },
+       { .x = 50, .y = 30 },
+       { .x = 30, .y = 50 },
+       { .x = 10, .y = 30 },
+       { .x = 30, .y = 10 },
+};
+
+#define NCOORD_DONUT (sizeof(donut)/sizeof(donut[0]))
+
 void HandleExpose(Display *dpy, Window win, GC gc)
 {
        ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
 
-       ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, "32", 0x00000000, AO_COPY);
-       ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "box", 0x00000000, AO_COPY);
+       if (do_polys) {
+               ao_poly(&fb, trek, NCOORD_TREK, 0x00000000, AO_COPY);
+               ao_poly(&fb, donut, NCOORD_DONUT, 0x00000000, AO_COPY);
+       } else {
+               char    str[64];
 
-       ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, "2", 0x00000000, AO_COPY);
-       ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "pad", 0x00000000, AO_COPY);
+               sprintf(str, "%02d", box_number);
+               ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, str, 0x00000000, AO_COPY);
+               ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "box", 0x00000000, AO_COPY);
 
-       ao_line(&fb, SEP_X, 0, SEP_X, HEIGHT, 0x00000000, AO_COPY);
+               sprintf(str, "%d", pad_number);
+               ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, str, 0x00000000, AO_COPY);
+               ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "pad", 0x00000000, AO_COPY);
+
+               ao_line(&fb, SEP_X, 0, SEP_X, HEIGHT, 0x00000000, AO_COPY);
+       }
 
        XImage *image = XCreateImage(dpy, visual, 1, XYBitmap, 0, (char *) bits, WIDTH, HEIGHT, 32, STRIDE*4);
        XSetForeground(dpy, gc, WhitePixel(dpy, screen));
@@ -65,3 +103,47 @@ void HandleExpose(Display *dpy, Window win, GC gc)
        XPutImage(dpy, win, gc, image, 0, 0, 0, 0, WIDTH, HEIGHT);
        free(image);
 }
+
+void
+HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev)
+{
+       char    string[10];
+       if (XLookupString ((XKeyEvent *) ev, string, sizeof (string), 0, 0) >= 1) {
+               printf("key %s\n", string);
+               switch (string[0]) {
+               case 'q':
+                       exit (0);
+               case 'p':
+                       pad_number++;
+                       if (pad_number > 8)
+                               pad_number = 1;
+                       break;
+               case 'P':
+                       pad_number--;
+                       if (pad_number < 1)
+                               pad_number = 8;
+                       break;
+               case 'b':
+                       box_number++;
+                       if (box_number > 99)
+                               box_number = 1;
+                       break;
+               case 'B':
+                       box_number--;
+                       if (box_number < 1)
+                               box_number = 99;
+                       break;
+               case 's':
+                       do_polys = !do_polys;
+                       break;
+               case 'c':
+                       break;
+               }
+               HandleExpose(dpy, win, gc);
+       }
+}
+
+void
+HandleKeyRelease(Display *dpy, Window win, GC gc, XEvent *ev)
+{
+}
index bcb26145265224cb14c2a4c39d2bbc63effcfe54..c9e37d63c3c21c67663c980b57ca91b9ab41318f 100644 (file)
@@ -371,6 +371,12 @@ int            screen;
 void
 HandleExpose(Display *dpy, Window win, GC gc);
 
+void
+HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev);
+
+void
+HandleKeyRelease(Display *dpy, Window win, GC gc, XEvent *ev);
+
 int
 main (argc, argv)
     int            argc;