From: Keith Packard Date: Sun, 26 Feb 2023 06:39:07 +0000 (-0800) Subject: altos/draw: Make test drawing app emulate TeleLCO X-Git-Tag: 1.9.16~1^2~44 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=033e32989aab05fe6174a3db4a5eca4df07d7ab8 altos/draw: Make test drawing app emulate TeleLCO Draw some numbers for box and pad. Also allow display of a couple of polygons. Signed-off-by: Keith Packard --- diff --git a/src/draw/draw-test.c b/src/draw/draw-test.c index 9487aa31..2f8ca636 100644 --- a/src/draw/draw-test.c +++ b/src/draw/draw-test.c @@ -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) +{ +} diff --git a/src/draw/frame.c b/src/draw/frame.c index bcb26145..c9e37d63 100644 --- a/src/draw/frame.c +++ b/src/draw/frame.c @@ -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;