From ceb6fc010ee9f4fadbcbf3e3cdc481ec505cdc32 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 20 Jan 2007 06:37:35 +0000 Subject: dynamic properties for bars; new 'property_valid()' helper git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@749 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- widget_bar.c | 69 ++++++++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 42 deletions(-) (limited to 'widget_bar.c') diff --git a/widget_bar.c b/widget_bar.c index e7e53b1..e0c8b1d 100644 --- a/widget_bar.c +++ b/widget_bar.c @@ -40,7 +40,7 @@ #include "debug.h" #include "cfg.h" -#include "evaluator.h" +#include "property.h" #include "timer.h" #include "widget.h" #include "widget_bar.h" @@ -59,26 +59,21 @@ void widget_bar_update(void *Self) double val1, val2; double min, max; - /* evaluate expressions */ - val1 = 0.0; - if (Bar->tree1 != NULL) { - Eval(Bar->tree1, &result); - val1 = R2N(&result); - DelResult(&result); - } + /* evaluate properties */ + property_eval(&Bar->expression1); + val1 = P2N(&Bar->expression1); - val2 = val1; - if (Bar->tree2 != NULL) { - Eval(Bar->tree2, &result); - val2 = R2N(&result); - DelResult(&result); + if (property_valid(&Bar->expression2)) { + property_eval(&Bar->expression2); + val2 = P2N(&Bar->expression2); + } else { + val2 = val1; } /* minimum: if expression is empty, do auto-scaling */ - if (Bar->tree_min != NULL) { - Eval(Bar->tree_min, &result); - min = R2N(&result); - DelResult(&result); + if (property_valid(&Bar->expr_min)) { + property_eval(&Bar->expr_min); + min = P2N(&Bar->expr_min); } else { min = Bar->min; if (val1 < min) @@ -88,10 +83,9 @@ void widget_bar_update(void *Self) } /* maximum: if expression is empty, do auto-scaling */ - if (Bar->tree_max != NULL) { - Eval(Bar->tree_max, &result); - max = R2N(&result); - DelResult(&result); + if (property_valid(&Bar->expr_max)) { + property_eval(&Bar->expr_max); + max = P2N(&Bar->expr_min); } else { max = Bar->max; if (val1 > max) @@ -133,26 +127,17 @@ int widget_bar_init(WIDGET * Self) Bar = malloc(sizeof(WIDGET_BAR)); memset(Bar, 0, sizeof(WIDGET_BAR)); - /* get raw expressions (we evaluate them ourselves) */ - Bar->expression1 = cfg_get_raw(section, "expression", NULL); - Bar->expression2 = cfg_get_raw(section, "expression2", NULL); + /* load properties */ + property_load(section, "expression", NULL, &Bar->expression1); + property_load(section, "expression2", NULL, &Bar->expression2); + property_load(section, "min", NULL, &Bar->expr_min); + property_load(section, "max", NULL, &Bar->expr_max); - /* sanity check */ - if (Bar->expression1 == NULL || *Bar->expression1 == '\0') { - error("widget %s has no expression, using '0.0'", Self->name); - Bar->expression1 = "0"; + /* sanity checks */ + if (!property_valid(&Bar->expression1)) { + error("Warning: widget %s has no expression", section); } - /* minimum and maximum value */ - Bar->expr_min = cfg_get_raw(section, "min", NULL); - Bar->expr_max = cfg_get_raw(section, "max", NULL); - - /* compile all expressions */ - Compile(Bar->expression1, &Bar->tree1); - Compile(Bar->expression2, &Bar->tree2); - Compile(Bar->expr_min, &Bar->tree_min); - Compile(Bar->expr_max, &Bar->tree_max); - /* bar length, default 1 */ cfg_number(section, "length", 1, 0, -1, &(Bar->length)); @@ -213,10 +198,10 @@ int widget_bar_quit(WIDGET * Self) if (Self) { if (Self->data) { WIDGET_BAR *Bar = Self->data; - DelTree(Bar->tree1); - DelTree(Bar->tree2); - DelTree(Bar->tree_min); - DelTree(Bar->tree_max); + property_free(&Bar->expression1); + property_free(&Bar->expression2); + property_free(&Bar->expr_min); + property_free(&Bar->expr_max); free(Self->data); } Self->data = NULL; -- cgit v1.2.3