test intersection of (displayable) widgets

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@996 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
volker
2009-03-23 17:22:24 +00:00
parent 14e0be7a79
commit 33422af5b6
9 changed files with 82 additions and 15 deletions
+43 -6
View File
@@ -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) ? "<none>" : Class->name,
(NULL == Parent) ? "<root>" : 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) ? "<none>" : Class->name,
(NULL == Parent) ? "<root>" : 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;
}
+9
View File
@@ -56,6 +56,8 @@ typedef struct WIDGET {
int row;
int col;
void *data;
int x2; /* x of opposite corner, -1 for no display widget */
int y2; /* y of opposite corner, -1 for no display widget */
} WIDGET;
@@ -68,8 +70,15 @@ typedef struct WIDGET {
int widget_register(WIDGET_CLASS * widget);
void widget_unregister(void);
int intersect(WIDGET * w1, WIDGET * w2);
int widget_add(const char *name, const int type, const int layer, const int row, const int col);
WIDGET *widget_find(int type, void *needle);
int widget_color(const char *section, const char *name, const char *key, RGBA * C);
#undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#undef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define NOCOORD (-1)
#endif
+9 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Bar
@@ -154,15 +154,23 @@ int widget_bar_init(WIDGET * Self)
switch (toupper(*c)) {
case 'E':
Bar->direction = DIR_EAST;
Self->x2 = Self->col + Bar->length - 1;
Self->y2 = Self->row;
break;
case 'W':
Bar->direction = DIR_WEST;
Self->x2 = Self->col + Bar->length - 1;
Self->y2 = Self->row;
break;
case 'N':
Bar->direction = DIR_NORTH;
Self->x2 = Self->col;
Self->y2 = Self->row + Bar->length - 1;
break;
case 'S':
Bar->direction = DIR_SOUTH;
Self->x2 = Self->col;
Self->y2 = Self->row + Bar->length - 1;
break;
default:
error("widget %s has unknown direction '%s'; known directions: 'E', 'W', 'N', 'S'; using 'E(ast)'", Self->name,
+4 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_GPO
@@ -96,6 +96,9 @@ int widget_gpo_init(WIDGET * Self)
free(section);
Self->data = GPO;
/* no display dimension */
Self->x2 = NOCOORD;
Self->y2 = NOCOORD;
/* fire it the first time */
widget_gpo_update(Self);
+3 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Icon
@@ -146,6 +146,8 @@ int widget_icon_init(WIDGET * Self)
free(section);
Self->data = Icon;
Self->x2 = Self->col + 1;
Self->y2 = Self->row + 1;
/* as the speed is evaluatod on every call, we use 'one-shot'-timers. */
/* The timer will be reactivated on every call to widget_icon_update(). */
+3 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Image
@@ -237,6 +237,8 @@ int widget_image_init(WIDGET * Self)
free(section);
Self->data = Image;
Self->x2 = Self->col + Image->width;
Self->y2 = Self->row + Image->height;
} else {
+3 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Keypad
@@ -103,6 +103,8 @@ int widget_keypad_init(WIDGET * Self)
free(section);
Self->data = keypad;
Self->x2 = NOCOORD;
Self->y2 = NOCOORD;
return 0;
}
+5 -3
View File
@@ -5,7 +5,7 @@
*
* Copyright (C) 2003, 2004 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
* Copyright (C) 2008 Michael Vogt <michu@neophob.com>
* Copyright (C) 2008 Michael Vogt <michu@neophob.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
@@ -23,11 +23,11 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Text
* a simple text widget which
* a simple text widget which
* must be supported by all displays
*
*/
@@ -352,6 +352,8 @@ int widget_text_init(WIDGET * Self)
free(section);
Self->data = Text;
Self->x2 = Self->col + Text->width;
Self->y2 = Self->row;
/* add update timer, use one-shot if 'update' is zero */
timer_add(widget_text_update, Self, Text->update, Text->update == 0);
+3 -1
View File
@@ -22,7 +22,7 @@
*
*/
/*
/*
* exported functions:
*
* WIDGET_CLASS Widget_Timer
@@ -98,6 +98,8 @@ int widget_timer_init(WIDGET * Self)
free(section);
Self->data = Timer;
Self->x2 = NOCOORD;
Self->y2 = NOCOORD;
/* just do it! */
widget_timer_update(Self);