From 33422af5b63a50e337da8817ad02639a33f6ea5e Mon Sep 17 00:00:00 2001 From: volker Date: Mon, 23 Mar 2009 17:22:24 +0000 Subject: test intersection of (displayable) widgets git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@996 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- widget.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'widget.c') diff --git a/widget.c b/widget.c index bc3fe31..165fbc2 100644 --- a/widget.c +++ b/widget.c @@ -22,7 +22,7 @@ * */ -/* +/* * exported functions: * * int widget_junk(void) @@ -128,6 +128,32 @@ int widget_color(const char *section, const char *name, const char *key, RGBA * return 1; } +int intersect(WIDGET * w1, WIDGET * w2) +{ + int x1w1, y1w1, x2w1, y2w1; /* 1st rectangle */ + int x1w2, y1w2, x2w2, y2w2; /* 2nd rectangle */ + + if (w1->x2 == NOCOORD || w1->y2 == NOCOORD || w2->x2 == NOCOORD || w2->y2 == NOCOORD) { + /* w1 or w2 is no display widget: no intersection */ + return 0; + } + x1w1 = MIN(w1->col, w1->x2); + x2w1 = MAX(w1->col, w1->x2); + y1w1 = MIN(w1->row, w1->y2); + y2w1 = MAX(w1->row, w1->y2); + x1w2 = MIN(w2->col, w2->x2); + x2w2 = MAX(w2->col, w2->x2); + y1w2 = MIN(w2->row, w2->y2); + y2w2 = MAX(w2->row, w2->y2); + + if (x1w2 < x2w1 && x2w2 > x1w1 && y1w2 < y2w1 && y2w2 > y1w1) { + /* true: Intersection */ + return 1; + } else { + return 0; + } +} + int widget_add(const char *name, const int type, const int layer, const int row, const int col) { int i; @@ -240,15 +266,26 @@ int widget_add(const char *name, const int type, const int layer, const int row, Widget->row = row; Widget->col = col; - info(" widget '%s': Class '%s', Parent '%s', Layer %d, %s %d, %s %d", - name, (NULL == Class) ? "" : Class->name, - (NULL == Parent) ? "" : Parent->name, - layer, (WIDGET_TYPE_XY == Class->type) ? "Y" : "Row", row, (WIDGET_TYPE_XY == Class->type) ? "X" : "Col", col); - if (Class->init != NULL) { Class->init(Widget); } + info(" widget '%s': Class '%s', Parent '%s', Layer %d, %s %d, %s %d (to %d,%d)", + name, (NULL == Class) ? "" : Class->name, + (NULL == Parent) ? "" : Parent->name, + layer, (WIDGET_TYPE_XY == Class->type) ? "Y" : "Row", row, (WIDGET_TYPE_XY == Class->type) ? "X" : "Col", col, + Widget->y2, Widget->x2); + + /* sanity check: look for overlapping widgets */ + for (i = 0; i < nWidgets - 1; i++) { + if (Widgets[i].layer == layer) { + if (intersect(&(Widgets[i]), Widget)) { + info("WARNING widget %s(%i,%i) intersects with %s(%i,%i) on layer %d", + Widgets[i].name, Widgets[i].row, Widgets[i].col, name, row, col, layer); + } + } + } + return 0; } -- cgit v1.2.3