From da605a15bbdc3b0f15cf7c70256ce4c32da071c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 26 Feb 2023 18:50:31 -0800 Subject: [PATCH] altos/draw: Add line test app There were bugs, now there's a app to check them. Signed-off-by: Keith Packard --- src/draw/.gitignore | 1 + src/draw/Makefile | 18 ++++++++++++--- src/draw/line-test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/draw/line-test.c diff --git a/src/draw/.gitignore b/src/draw/.gitignore index 8e744bea..992c3171 100644 --- a/src/draw/.gitignore +++ b/src/draw/.gitignore @@ -5,3 +5,4 @@ NotoMono*.c ao_font.h ao_logo.h lco-test +line-test diff --git a/src/draw/Makefile b/src/draw/Makefile index 47336fbe..f5969f26 100644 --- a/src/draw/Makefile +++ b/src/draw/Makefile @@ -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 index 00000000..df77bae7 --- /dev/null +++ b/src/draw/line-test.c @@ -0,0 +1,52 @@ +/* + * Copyright © 2023 Keith Packard + * + * 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; +} -- 2.30.2