aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--widget.c49
-rw-r--r--widget.h9
-rw-r--r--widget_bar.c10
-rw-r--r--widget_gpo.c5
-rw-r--r--widget_icon.c4
-rw-r--r--widget_image.c4
-rw-r--r--widget_keypad.c4
-rw-r--r--widget_text.c8
-rw-r--r--widget_timer.c4
9 files changed, 82 insertions, 15 deletions
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) ? "<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;
}
diff --git a/widget.h b/widget.h
index 4f943b2..2fe7088 100644
--- a/widget.h
+++ b/widget.h
@@ -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
diff --git a/widget_bar.c b/widget_bar.c
index 7e453aa..7558550 100644
--- a/widget_bar.c
+++ b/widget_bar.c
@@ -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,
diff --git a/widget_gpo.c b/widget_gpo.c
index ebae5fa..1a0d52d 100644
--- a/widget_gpo.c
+++ b/widget_gpo.c
@@ -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);
diff --git a/widget_icon.c b/widget_icon.c
index 31299c9..83afbac 100644
--- a/widget_icon.c
+++ b/widget_icon.c
@@ -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(). */
diff --git a/widget_image.c b/widget_image.c
index 2a8f0ad..688f6c8 100644
--- a/widget_image.c
+++ b/widget_image.c
@@ -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 {
diff --git a/widget_keypad.c b/widget_keypad.c
index 8d571a4..cf38d34 100644
--- a/widget_keypad.c
+++ b/widget_keypad.c
@@ -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;
}
diff --git a/widget_text.c b/widget_text.c
index 948540b..1678812 100644
--- a/widget_text.c
+++ b/widget_text.c
@@ -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);
diff --git a/widget_timer.c b/widget_timer.c
index 948dee0..10ba86d 100644
--- a/widget_timer.c
+++ b/widget_timer.c
@@ -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);