altos/draw: Add line test app
authorKeith Packard <keithp@keithp.com>
Mon, 27 Feb 2023 02:50:31 +0000 (18:50 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 27 Feb 2023 02:50:31 +0000 (18:50 -0800)
There were bugs, now there's a app to check them.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/draw/.gitignore
src/draw/Makefile
src/draw/line-test.c [new file with mode: 0644]

index 8e744beafae284f091549f97dc2d80ac0c8c75ce..992c31719b980dff689f579628bd078e970a2bdb 100644 (file)
@@ -5,3 +5,4 @@ NotoMono*.c
 ao_font.h
 ao_logo.h
 lco-test
+line-test
index 47336fbef3ca19168b45e90c650cb7570c21e895..f5969f26bde0e83b23819d0369e4c9195ecc56e3 100644 (file)
@@ -79,7 +79,7 @@ FONT_SRCS=$(BDFS:.bdf=.c)
 .bdf.c:
        nickle font-convert -o $@ $<
 
-all: ao_font.h ao_logo.h lco-test
+all: ao_font.h ao_logo.h lco-test line-test
 
 $(FONT_SRCS): font-convert
 
@@ -103,9 +103,12 @@ LIB_SRCS=\
 LCO_TEST_SRCS=$(LIB_SRCS) lco-test.c
 LCO_TEST_OBJS=$(LCO_TEST_SRCS:.c=.o)
 
-TEST_LIBS=-lXrender -lX11 -lm -Wl,--gc-sections
+LINE_TEST_SRCS=$(LIB_SRCS) line-test.c
+LINE_TEST_OBJS=$(LINE_TEST_SRCS:.c=.o)
 
-CFLAGS=-O0 -g $(WARN_FLAGS)
+TEST_LIBS=-lXrender -lXext -lX11 -lm -Wl,--gc-sections
+
+CFLAGS=-O0 -g $(WARN_FLAGS) -DVALIDATE
 
 HEADERS=\
        ao_draw.h \
@@ -116,7 +119,16 @@ HEADERS=\
 lco-test: $(LCO_TEST_OBJS)
        cc $(CFLAGS) -o $@ $(LCO_TEST_OBJS) $(TEST_LIBS)
 
+lco-test.o: test-frame.c frame.c
+
 $(LCO_TEST_OBJS): $(HEADERS)
 
+line-test: $(LINE_TEST_OBJS)
+       cc $(CFLAGS) -o $@ $(LINE_TEST_OBJS) $(TEST_LIBS)
+
+line-test.o: test-frame.c frame.c
+
+$(LINE_TEST_OBJS): $(HEADERS)
+
 clean:
        rm -f $(LCO_TEST_OBJS) ao_font.h ao_logo.h $(FONT_SRCS)
diff --git a/src/draw/line-test.c b/src/draw/line-test.c
new file mode 100644 (file)
index 0000000..df77bae
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2023 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#define TRACK_POINTER
+
+#include "test-frame.c"
+
+static int16_t x1 = 32, my_y1 = 10, x2 = 32, my_y2 = 100;
+
+void HandleExpose(Display *dpy, Window win, GC gc)
+{
+       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
+
+       ao_line(&fb, x1, my_y1, x2, my_y2, 0x00000000, AO_COPY);
+
+       DoDisplay(dpy, win, gc);
+       DisplayPositions(dpy, win, gc, current_positions);
+}
+
+void
+Draw(Display *dpy, Window win, GC gc, PositionRec positions[5])
+{
+       x1 = (int16_t) positions[0].cur_x / IMAGE_SCALE;
+       my_y1 = (int16_t) positions[0].cur_y / IMAGE_SCALE;
+       x2 = (int16_t) positions[2].cur_x / IMAGE_SCALE;
+       my_y2 = (int16_t) positions[2].cur_y / IMAGE_SCALE;
+       HandleExpose(dpy, win, gc);
+}
+
+void
+Undraw(Display *dpy, Window win, GC gc, PositionRec positions[5])
+{
+       (void) dpy;
+       (void) win;
+       (void) gc;
+       (void) positions;
+}