]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2005-11-06 09:17:20 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sun, 6 Nov 2005 09:17:20 +0000 (09:17 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sun, 6 Nov 2005 09:17:20 +0000 (09:17 +0000)
re-use icons (thanks to Jesus de Santos Garcia)

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@596 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

widget.c
widget.h
widget_icon.c

index 09fc6371661c33abba1ee607c4ed898af5136b3e..a8303161b4628b783e57778def97bc7592c1f0d6 100644 (file)
--- a/widget.c
+++ b/widget.c
@@ -1,4 +1,4 @@
-/* $Id: widget.c,v 1.19 2005/05/08 04:32:45 reinelt Exp $
+/* $Id: widget.c,v 1.20 2005/11/06 09:17:20 reinelt Exp $
  *
  * generic widget handling
  *
@@ -21,6 +21,9 @@
  *
  *
  * $Log: widget.c,v $
+ * Revision 1.20  2005/11/06 09:17:20  reinelt
+ * re-use icons (thanks to Jesus de Santos Garcia)
+ *
  * Revision 1.19  2005/05/08 04:32:45  reinelt
  * CodingStyle added and applied
  *
@@ -165,6 +168,8 @@ void widget_unregister(void)
     int i;
     for (i = 0; i < nWidgets; i++) {
        Widgets[i].class->quit(&(Widgets[i]));
+       if (Widgets[i].name)
+           free (Widgets[i].name);
     }
     free(Widgets);
 
@@ -182,6 +187,7 @@ int widget_add(const char *name, const int row, const int col)
 
     WIDGET_CLASS *Class;
     WIDGET *Widget;
+    WIDGET *Parent;
 
     /* prepare config section */
     /* strlen("Widget:")=7 */
@@ -231,15 +237,25 @@ int widget_add(const char *name, const int row, const int col)
        return -1;
     }
 
+    /* look up parent widget (widget with the same name) */
+    Parent = NULL;
+    for (i = 0; i < nWidgets; i++) {
+       if (strcmp(name, Widgets[i].name) == 0) {
+           Parent = &(Widgets[i]);
+           break;
+       }
+    }
+
     Widget = &(Widgets[nWidgets]);
     nWidgets++;
 
-    Widget->name = (char *) name;
+    Widget->name = strdup(name);
     Widget->class = Class;
+    Widget->parent = Parent;
     Widget->row = row;
     Widget->col = col;
 
-    if (Class->init != 0) {
+    if (Class->init != NULL) {
        Class->init(Widget);
     }
 
index 0db6009f1507d0645e9dbfe5eff517a780b6013d..5805041b87ca5ed81c11cc9b75a7dd58183954fb 100644 (file)
--- a/widget.h
+++ b/widget.h
@@ -1,4 +1,4 @@
-/* $Id: widget.h,v 1.13 2005/05/08 04:32:45 reinelt Exp $
+/* $Id: widget.h,v 1.14 2005/11/06 09:17:20 reinelt Exp $
  *
  * generic widget handling
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: widget.h,v $
+ * Revision 1.14  2005/11/06 09:17:20  reinelt
+ * re-use icons (thanks to Jesus de Santos Garcia)
+ *
  * Revision 1.13  2005/05/08 04:32:45  reinelt
  * CodingStyle added and applied
  *
@@ -99,6 +102,7 @@ typedef struct WIDGET_CLASS {
 typedef struct WIDGET {
     char *name;
     WIDGET_CLASS *class;
+    struct WIDGET *parent;
     int row;
     int col;
     void *data;
index 0b7a3305fd3b7a7f42ec5b93e5c006baad2e2c0a..03416894b66e0051d2da196155f87b1e0a5fba5f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: widget_icon.c,v 1.17 2005/05/08 04:32:45 reinelt Exp $
+/* $Id: widget_icon.c,v 1.18 2005/11/06 09:17:20 reinelt Exp $
  *
  * icon widget handling
  *
@@ -21,6 +21,9 @@
  *
  *
  * $Log: widget_icon.c,v $
+ * Revision 1.18  2005/11/06 09:17:20  reinelt
+ * re-use icons (thanks to Jesus de Santos Garcia)
+ *
  * Revision 1.17  2005/05/08 04:32:45  reinelt
  * CodingStyle added and applied
  *
@@ -170,29 +173,33 @@ void widget_icon_update(void *Self)
     WIDGET_ICON *Icon = W->data;
     RESULT result = { 0, 0, 0, NULL };
 
-    /* evaluate expressions */
-    Icon->speed = 100;
-    if (Icon->speed_tree != NULL) {
-       Eval(Icon->speed_tree, &result);
-       Icon->speed = R2N(&result);
-       if (Icon->speed < 10)
-           Icon->speed = 10;
-       DelResult(&result);
-    }
+    /* process the parent only */
+    if (W->parent == NULL) {
+
+       /* evaluate expressions */
+       Icon->speed = 100;
+       if (Icon->speed_tree != NULL) {
+           Eval(Icon->speed_tree, &result);
+           Icon->speed = R2N(&result);
+           if (Icon->speed < 10)
+               Icon->speed = 10;
+           DelResult(&result);
+       }
 
-    Icon->visible = 1;
-    if (Icon->visible_tree != NULL) {
-       Eval(Icon->visible_tree, &result);
-       Icon->visible = R2N(&result);
-       if (Icon->visible < 1)
-           Icon->visible = 0;
-       DelResult(&result);
-    }
+       Icon->visible = 1;
+       if (Icon->visible_tree != NULL) {
+           Eval(Icon->visible_tree, &result);
+           Icon->visible = R2N(&result);
+           if (Icon->visible < 1)
+               Icon->visible = 0;
+           DelResult(&result);
+       }
 
-    /* rotate icon bitmap */
-    Icon->curmap++;
-    if (Icon->curmap >= Icon->maxmap)
-       Icon->curmap = 0;
+       /* rotate icon bitmap */
+       Icon->curmap++;
+       if (Icon->curmap >= Icon->maxmap)
+           Icon->curmap = 0;
+    }
 
     /* finally, draw it! */
     if (W->class->draw)
@@ -210,42 +217,52 @@ int widget_icon_init(WIDGET * Self)
     char *section;
     WIDGET_ICON *Icon;
 
-    /* prepare config section */
-    /* strlen("Widget:")=7 */
-    section = malloc(strlen(Self->name) + 8);
-    strcpy(section, "Widget:");
-    strcat(section, Self->name);
+    /* re-use the parent if one exists */
+    if (Self->parent == NULL) {
 
-    Icon = malloc(sizeof(WIDGET_ICON));
-    memset(Icon, 0, sizeof(WIDGET_ICON));
+       /* prepare config section */
+       /* strlen("Widget:")=7 */
+       section = malloc(strlen(Self->name) + 8);
+       strcpy(section, "Widget:");
+       strcat(section, Self->name);
 
-    /* get raw expressions (we evaluate them ourselves) */
-    Icon->speed_expr = cfg_get_raw(section, "speed", NULL);
-    Icon->visible_expr = cfg_get_raw(section, "visible", NULL);
+       Icon = malloc(sizeof(WIDGET_ICON));
+       memset(Icon, 0, sizeof(WIDGET_ICON));
 
-    /* compile'em */
-    Compile(Icon->speed_expr, &Icon->speed_tree);
-    Compile(Icon->visible_expr, &Icon->visible_tree);
+       /* get raw expressions (we evaluate them ourselves) */
+       Icon->speed_expr = cfg_get_raw(section, "speed", NULL);
+       Icon->visible_expr = cfg_get_raw(section, "visible", NULL);
 
-    /* sanity check */
-    if (Icon->speed_expr == NULL || *Icon->speed_expr == '\0') {
-       error("Icon %s has no speed, using '100'", Self->name);
-       Icon->speed_expr = "100";
-    }
+       /* compile'em */
+       Compile(Icon->speed_expr, &Icon->speed_tree);
+       Compile(Icon->visible_expr, &Icon->visible_tree);
+
+       /* sanity check */
+       if (Icon->speed_expr == NULL || *Icon->speed_expr == '\0') {
+           error("Icon %s has no speed, using '100'", Self->name);
+           Icon->speed_expr = "100";
+       }
 
-    /* read bitmap */
-    widget_icon_read_bitmap(section, Icon);
+       /* read bitmap */
+       widget_icon_read_bitmap(section, Icon);
 
-    free(section);
-    Self->data = Icon;
+       free(section);
+       Self->data = Icon;
 
-    /* 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().  */
-    /* We do the initial call here... */
-    Icon->prvmap = -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().  */
+       /* We do the initial call here... */
+       Icon->prvmap = -1;
 
-    /* reset ascii  */
-    Icon->ascii = -1;
+       /* reset ascii  */
+       Icon->ascii = -1;
+
+    } else {
+       
+       /* re-use the parent */
+       Self->data = Self->parent->data;
+       
+    }
 
     /* just do it! */
     widget_icon_update(Self);
@@ -257,14 +274,17 @@ int widget_icon_init(WIDGET * Self)
 int widget_icon_quit(WIDGET * Self)
 {
     if (Self) {
-       if (Self->data) {
-           WIDGET_ICON *Icon = Self->data;
-           DelTree(Icon->speed_tree);
-           DelTree(Icon->visible_tree);
-           if (Icon->bitmap)
-               free(Icon->bitmap);
-           free(Self->data);
-           Self->data = NULL;
+       /* do not deallocate child widget! */
+       if (Self->parent == NULL) {
+           if (Self->data) {
+               WIDGET_ICON *Icon = Self->data;
+               DelTree(Icon->speed_tree);
+               DelTree(Icon->visible_tree);
+               if (Icon->bitmap)
+                   free(Icon->bitmap);
+               free(Self->data);
+               Self->data = NULL;
+           }
        }
     }