commit 8c7d6c1077f97dd4ae11a551ccf3a68fa86e21f6
parent c5dbd602a0e8b531a5760038c271098feffdcf47
Author: lumidify <nobody@lumidify.org>
Date:   Thu, 16 Jun 2022 20:04:35 +0200
Remove obsolete draw.{c,h}
Diffstat:
| D | src/draw.c |  |  | 388 | ------------------------------------------------------------------------------- | 
| D | src/draw.h |  |  | 36 | ------------------------------------ | 
2 files changed, 0 insertions(+), 424 deletions(-)
diff --git a/src/draw.c b/src/draw.c
@@ -1,388 +0,0 @@
-/*
- * Copyright (c) 2020 lumidify <nobody@lumidify.org>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdint.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-#include "memory.h"
-#include "color.h"
-#include "rect.h"
-#include "widget.h"
-#include "ltk.h"
-#include "util.h"
-#include "draw.h"
-
-static void ltk_draw_draw(ltk_widget *self, ltk_rect clip_rect);
-static ltk_draw *ltk_draw_create(ltk_window *window,
-    const char *id, int w, int h, const char *color);
-static void ltk_draw_resize(ltk_widget *self);
-static void ltk_draw_destroy(ltk_widget *self, int shallow);
-static void ltk_draw_clear(ltk_window *window, ltk_draw *draw);
-static void ltk_draw_set_color(ltk_window *window, ltk_draw *draw, const char *color);
-static void ltk_draw_line(ltk_window *window, ltk_draw *draw, int x1, int y1, int x2, int y2);
-static void ltk_draw_rect(ltk_window *window, ltk_draw *draw, int x, int y, int w, int h, int fill);
-
-static struct ltk_widget_vtable vtable = {
-	.draw = <k_draw_draw,
-	.resize = <k_draw_resize,
-	.destroy = <k_draw_destroy,
-	.type = LTK_DRAW,
-	.needs_redraw = 1,
-	/* FIXME: use the widget pixmap here and store the drawn stuff
-	   logically as paths, not just on the pixmap */
-	.needs_pixmap = 0
-};
-
-static int ltk_draw_cmd_clear(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-static int ltk_draw_cmd_set_color(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-static int ltk_draw_cmd_line(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-static int ltk_draw_cmd_rect(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-static int ltk_draw_cmd_create(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-
-static void
-ltk_draw_draw(ltk_widget *self, ltk_rect clip_rect) {
-	(void)clip_rect; /* FIXME: actually use this */
-	ltk_draw *draw = (ltk_draw *)self;
-	ltk_window *window = draw->widget.window;
-	ltk_rect rect = draw->widget.rect;
-	XCopyArea(window->dpy, draw->pix, window->drawable, window->gc, 0, 0, rect.w, rect.h, rect.x, rect.y);
-}
-
-
-static ltk_draw *
-ltk_draw_create(ltk_window *window, const char *id, int w, int h, const char *color) {
-	ltk_draw *draw = ltk_malloc(sizeof(ltk_draw));
-
-	ltk_fill_widget_defaults(&draw->widget, id, window, &vtable, w, h);
-	draw->widget.rect.w = w;
-	draw->widget.rect.h = h;
-	draw->pix = XCreatePixmap(window->dpy, window->drawable, w, h, window->depth);
-	if (!ltk_create_xcolor(window, color, &draw->bg)) {
-		ltk_free(draw);
-		ltk_fatal_errno("Unable to allocate XColor.\n");
-	}
-	draw->fg = draw->bg;
-	XSetForeground(window->dpy, window->gc, draw->bg.pixel);
-	XFillRectangle(window->dpy, draw->pix, window->gc, 0, 0, w, h);
-
-	return draw;
-}
-
-static void
-ltk_draw_resize(ltk_widget *self) {
-	ltk_draw *draw = (ltk_draw *)self;
-	Window win;
-	int x, y;
-	unsigned int w, h, bw, d;
-	unsigned int new_w, new_h;
-	ltk_window *window = draw->widget.window;
-	ltk_rect rect = draw->widget.rect;
-	XGetGeometry(window->dpy, draw->pix, &win, &x, &y, &w, &h, &bw, &d);
-
-	/* FIXME: get rid of casts */
-	new_w = (int)w < rect.w ? rect.w : (int)w;
-	new_h = (int)h < rect.h ? rect.h : (int)h;
-	if (new_w < w && new_h < h)
-		return;
-	Pixmap tmp = XCreatePixmap(window->dpy, window->drawable,
-	    new_w, new_h, window->depth);
-	XSetForeground(window->dpy, window->gc, draw->bg.pixel);
-	XFillRectangle(window->dpy, tmp, window->gc, 0, 0, new_w, new_h);
-	XCopyArea(window->dpy, draw->pix, tmp, window->gc,
-	    0, 0, w, h, 0, 0);
-	XFreePixmap(window->dpy, draw->pix);
-	draw->pix = tmp;
-}
-
-static void
-ltk_draw_destroy(ltk_widget *self, int shallow) {
-	(void)shallow;
-	ltk_draw *draw = (ltk_draw *)self;
-	if (!draw) {
-		ltk_warn("Tried to destroy NULL draw.\n");
-		return;
-	}
-	ltk_remove_widget(draw->widget.id);
-	ltk_free(draw->widget.id);
-	XFreePixmap(draw->widget.window->dpy, draw->pix);
-	ltk_free(draw);
-}
-
-static void
-ltk_draw_clear(ltk_window *window, ltk_draw *draw) {
-	Window win;
-	int x, y;
-	unsigned int w, h, bw, d;
-	XGetGeometry(window->dpy, draw->pix, &win, &x, &y, &w, &h, &bw, &d);
-	XSetForeground(window->dpy, window->gc, draw->bg.pixel);
-	XFillRectangle(window->dpy, window->drawable, window->gc, 0, 0, w, h);
-	ltk_draw_draw((ltk_widget *)draw, draw->widget.rect);
-}
-
-/* FIXME: Error return */
-static void
-ltk_draw_set_color(ltk_window *window, ltk_draw *draw, const char *color) {
-	XColor tmp;
-	if (ltk_create_xcolor(window, color, &tmp)) {
-		draw->fg = tmp;
-	}
-}
-
-static void
-ltk_draw_line(ltk_window *window, ltk_draw *draw, int x1, int y1, int x2, int y2) {
-	ltk_rect rect = draw->widget.rect;
-	XSetForeground(window->dpy, window->gc, draw->fg.pixel);
-	XSetLineAttributes(window->dpy, window->gc, 2, LineSolid, CapButt, JoinMiter);
-	XDrawLine(window->dpy, draw->pix, window->gc, x1, y1, x2, y2);
-	x1 += rect.x;
-	y1 += rect.y;
-	x2 += rect.x;
-	y2 += rect.y;
-	if (x1 > rect.x + rect.w) x1 = rect.x + rect.w;
-	if (y1 > rect.y + rect.h) y1 = rect.y + rect.h;
-	if (x2 > rect.x + rect.w) x2 = rect.x + rect.w;
-	if (y2 > rect.y + rect.h) y2 = rect.y + rect.h;
-	XDrawLine(window->dpy, window->drawable, window->gc, x1, y1, x2, y2);
-}
-
-static void
-ltk_draw_rect(ltk_window *window, ltk_draw *draw, int x, int y, int w, int h, int fill) {
-	int x_win, y_win, w_win, h_win;
-	ltk_rect rect = draw->widget.rect;
-	XSetForeground(window->dpy, window->gc, draw->fg.pixel);
-	x_win = x + rect.x;
-	y_win = y + rect.y;
-	w_win = x + w > rect.w ? rect.w - x : w;
-	h_win = y + h > rect.h ? rect.h - y : h;
-	if (fill) {
-		XFillRectangle(window->dpy, draw->pix, window->gc, x, y, w, h);
-		XFillRectangle(window->dpy, window->drawable, window->gc, x_win, y_win, w_win, h_win);
-	} else {
-		XSetLineAttributes(window->dpy, window->gc, 2, LineSolid, CapButt, JoinMiter);
-		XDrawRectangle(window->dpy, draw->pix, window->gc, x, y, w, h);
-		XDrawRectangle(window->dpy, window->drawable, window->gc, x_win, y_win, w_win, h_win);
-	}
-}
-
-static int
-ltk_draw_cmd_clear(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	ltk_draw *draw;
-	if (num_tokens != 3) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	draw = (ltk_draw *)ltk_get_widget(tokens[1], LTK_DRAW, errstr);
-	if (!draw) return 1;
-	ltk_draw_clear(window, draw);
-
-	return 0;
-}
-
-static int
-ltk_draw_cmd_set_color(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	ltk_draw *draw;
-	if (num_tokens != 4) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	draw = (ltk_draw *)ltk_get_widget(tokens[1], LTK_DRAW, errstr);
-	if (!draw) return 1;
-	ltk_draw_set_color(window, draw, tokens[3]);
-
-	return 0;
-}
-
-static int
-ltk_draw_cmd_line(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	ltk_draw *draw;
-	int x1, y1, x2, y2;
-	const char *errstr_num;
-	if (num_tokens != 7) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	draw = (ltk_draw *)ltk_get_widget(tokens[1], LTK_DRAW, errstr);
-	if (!draw) return 1;
-	x1 = ltk_strtonum(tokens[3], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid x1.\n";
-		return 1;
-	}
-	y1 = ltk_strtonum(tokens[4], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid y1.\n";
-		return 1;
-	}
-	x2 = ltk_strtonum(tokens[5], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid x2.\n";
-		return 1;
-	}
-	y2 = ltk_strtonum(tokens[6], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid y2.\n";
-		return 1;
-	}
-	ltk_draw_line(window, draw, x1, y1, x2, y2);
-
-	return 0;
-}
-
-static int
-ltk_draw_cmd_rect(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	ltk_draw *draw;
-	const char *errstr_num;
-	int x, y, w, h, fill;
-	if (num_tokens != 8) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	draw = (ltk_draw *)ltk_get_widget(tokens[1], LTK_DRAW, errstr);
-	if (!draw) return 1;
-	x = ltk_strtonum(tokens[3], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid x.\n";
-		return 1;
-	}
-	y = ltk_strtonum(tokens[4], 0, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid y.\n";
-		return 1;
-	}
-	w = ltk_strtonum(tokens[5], 1, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid width.\n";
-		return 1;
-	}
-	h = ltk_strtonum(tokens[6], 1, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid height.\n";
-		return 1;
-	}
-	fill = ltk_strtonum(tokens[7], 0, 1, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid fill bool.\n";
-		return 1;
-	}
-	ltk_draw_rect(window, draw, x, y, w, h, fill);
-
-	return 0;
-}
-
-/* draw <draw id> create <width> <height> <color> */
-static int
-ltk_draw_cmd_create(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	ltk_draw *draw;
-	int w, h;
-	const char *errstr_num;
-	if (num_tokens != 6) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	if (!ltk_widget_id_free(tokens[1])) {
-		*errstr = "Widget ID already taken.\n";
-		return 1;
-	}
-	w = ltk_strtonum(tokens[3], 1, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid width.\n";
-		return 1;
-	}
-	h = ltk_strtonum(tokens[4], 1, 100000, &errstr_num);
-	if (errstr_num) {
-		*errstr = "Invalid height.\n";
-		return 1;
-	}
-	draw = ltk_draw_create(window, tokens[1], w, h, tokens[5]);
-	ltk_set_widget((ltk_widget *)draw, tokens[1]);
-
-	return 0;
-}
-
-/* draw <draw id> <command> ... */
-int
-ltk_draw_cmd(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr) {
-	if (num_tokens < 3) {
-		*errstr = "Invalid number of arguments.\n";
-		return 1;
-	}
-	if (strcmp(tokens[2], "create") == 0) {
-		return ltk_draw_cmd_create(window, tokens, num_tokens, errstr);
-	} else if (strcmp(tokens[2], "clear") == 0) {
-		return ltk_draw_cmd_clear(window, tokens, num_tokens, errstr);
-	} else if (strcmp(tokens[2], "set-color") == 0) {
-		return ltk_draw_cmd_set_color(window, tokens, num_tokens, errstr);
-	} else if (strcmp(tokens[2], "line") == 0) {
-		return ltk_draw_cmd_line(window, tokens, num_tokens, errstr);
-	} else if (strcmp(tokens[2], "rect") == 0) {
-		return ltk_draw_cmd_rect(window, tokens, num_tokens, errstr);
-	} else {
-		*errstr = "Invalid command.\n";
-		return 1;
-	}
-
-	return 0;
-}
diff --git a/src/draw.h b/src/draw.h
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2020 lumidify <nobody@lumidify.org>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _LTK_DRAW_H_
-#define _LTK_DRAW_H_
-
-/* Requires the following includes: <X11/Xlib.h>, "rect.h", "widget.h", "ltk.h" */
-
-typedef struct {
-	ltk_widget widget;
-	Pixmap pix;
-	int depth;
-	XColor fg;
-	XColor bg;
-} ltk_draw;
-
-int ltk_draw_cmd(
-    ltk_window *window,
-    char **tokens,
-    size_t num_tokens,
-    char **errstr);
-
-#endif /* _LTK_DRAW_H_ */