*
*/
-/*
+/*
* exported functions:
*
* int widget_junk(void)
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;
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;
}
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;
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
*
*/
-/*
+/*
* exported functions:
*
* WIDGET_CLASS Widget_Bar
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,
*
* 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
*
*/
-/*
+/*
* exported functions:
*
* WIDGET_CLASS Widget_Text
- * a simple text widget which
+ * a simple text widget which
* must be supported by all displays
*
*/
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);