/* $Id$ * $URL$ * * bar widget handling * * Copyright (C) 2003, 2004 Michael Reinelt * Copyright (C) 2004 The LCD4Linux Team * * 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 * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * exported functions: * * WIDGET_CLASS Widget_Bar * the bar widget * */ #include "config.h" #include #include #include #include #include "debug.h" #include "cfg.h" #include "property.h" #include "timer.h" #include "widget.h" #include "widget_bar.h" #ifdef WITH_DMALLOC #include #endif void widget_bar_update(void *Self) { WIDGET *W = (WIDGET *) Self; WIDGET_BAR *Bar = W->data; double val1, val2; double min, max; /* evaluate properties */ property_eval(&Bar->expression1); val1 = P2N(&Bar->expression1); 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 (property_valid(&Bar->expr_min)) { property_eval(&Bar->expr_min); min = P2N(&Bar->expr_min); } else { min = Bar->min; if (val1 < min) min = val1; if (val2 < min) min = val2; } /* maximum: if expression is empty, do auto-scaling */ if (property_valid(&Bar->expr_max)) { property_eval(&Bar->expr_max); max = P2N(&Bar->expr_max); } else { max = Bar->max; if (val1 > max) max = val1; if (val2 > max) max = val2; } /* calculate bar values */ Bar->min = min; Bar->max = max; if (max > min) { Bar->val1 = (val1 - min) / (max - min); Bar->val2 = (val2 - min) / (max - min); } else { Bar->val1 = 0.0; Bar->val2 = 0.0; } /* finally, draw it! */ if (W->class->draw) W->class->draw(W); } int widget_bar_init(WIDGET * Self) { char *section; char *c; WIDGET_BAR *Bar; /* prepare config section */ /* strlen("Widget:")=7 */ section = malloc(strlen(Self->name) + 8); strcpy(section, "Widget:"); strcat(section, Self->name); Bar = malloc(sizeof(WIDGET_BAR)); memset(Bar, 0, sizeof(WIDGET_BAR)); /* 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 checks */ if (!property_valid(&Bar->expression1)) { error("Warning: widget %s has no expression", section); } /* bar length, default 1 */ cfg_number(section, "length", 1, 0, -1, &(Bar->length)); /* direction: East (default), West, North, South */ c = cfg_get(section, "direction", "E"); switch (toupper(*c)) { case 'E': Bar->direction = DIR_EAST; break; case 'W': Bar->direction = DIR_WEST; break; case 'N': Bar->direction = DIR_NORTH; break; case 'S': Bar->direction = DIR_SOUTH; break; default: error("widget %s has unknown direction '%s'; known directions: 'E', 'W', 'N', 'S'; using 'E(ast)'", Self->name, c); Bar->direction = DIR_EAST; } free(c); /* style: none (default), hollow */ c = cfg_get(section, "style", "0"); switch (toupper(*c)) { case 'H': Bar->style = STYLE_HOLLOW; if (!(Bar->direction & (DIR_EAST | DIR_WEST))) { error("widget %s with style \"hollow\" not implemented for other directions than E(ast) or W(est)", Self->name); Bar->style = 0; } break; case '0': Bar->style = 0; break; default: error("widget %s has unknown style '%s'; known styles: '0' or 'H'; using '0'", Self->name, c); Bar->style = 0; } free(c); /* update interval (msec), default 1 sec */ cfg_number(section, "update", 1000, 10, -1, &(Bar->update)); /* get widget special colors */ Bar->color_valid[0] = widget_color(section, Self->name, "barcolor0", &Bar->color[0]); Bar->color_valid[1] = widget_color(section, Self->name, "barcolor1", &Bar->color[1]); free(section); Self->data = Bar; timer_add(widget_bar_update, Self, Bar->update, 0); return 0; } int widget_bar_quit(WIDGET * Self) { if (Self) { if (Self->data) { WIDGET_BAR *Bar = Self->data; property_free(&Bar->expression1); property_free(&Bar->expression2); property_free(&Bar->expr_min); property_free(&Bar->expr_max); free(Self->data); } Self->data = NULL; } return 0; } WIDGET_CLASS Widget_Bar = { .name = "bar", .type = WIDGET_TYPE_RC, .init = widget_bar_init, .draw = NULL, .quit = widget_bar_quit, }; ='/lcd4linux.git/commit/python.m4?id=0849d874e73b9c456d633bf43f8c219a6be4ec0e&follow=1'>[lcd4linux @ 2005-05-02 10:29:20 by reinelt]reinelt9-30/+636 2005-05-02[lcd4linux @ 2005-05-02 05:15:46 by reinelt]reinelt4-9/+51 2005-04-30[lcd4linux @ 2005-04-30 06:02:09 by reinelt]reinelt3-15/+44 2005-04-24[lcd4linux @ 2005-04-24 05:27:09 by reinelt]reinelt2-7/+38 2005-04-24[lcd4linux @ 2005-04-24 04:41:28 by reinelt]reinelt1-0/+68 2005-04-24[lcd4linux @ 2005-04-24 04:33:46 by reinelt]reinelt9-10/+444 2005-04-20[lcd4linux @ 2005-04-20 05:49:21 by reinelt]reinelt1-44/+125 2005-04-09[lcd4linux @ 2005-04-09 07:36:42 by reinelt]reinelt2-17/+99 2005-04-05[lcd4linux @ 2005-04-05 06:57:39 by reinelt]reinelt3-34/+34 2005-04-05[lcd4linux @ 2005-04-05 05:12:48 by reinelt]reinelt4-407/+33 2005-04-05[lcd4linux @ 2005-04-05 04:46:06 by reinelt]reinelt1-1/+20 2005-04-04[lcd4linux @ 2005-04-04 20:11:14 by nicowallmeier]nicowallmeier1-2/+6 2005-04-03[lcd4linux @ 2005-04-03 07:07:43 by reinelt]reinelt8-9/+152 2005-04-02[lcd4linux @ 2005-04-02 05:28:58 by reinelt]reinelt3-19/+27 2005-04-01[lcd4linux @ 2005-04-01 05:16:04 by reinelt]reinelt5-584/+694 2005-03-30[lcd4linux @ 2005-03-30 04:57:50 by reinelt]reinelt3-23/+67 2005-03-28[lcd4linux @ 2005-03-28 22:29:23 by reinelt]reinelt1-250/+346 2005-03-28[lcd4linux @ 2005-03-28 19:39:14 by reinelt]reinelt9-256/+1147 2005-03-25[lcd4linux @ 2005-03-25 15:44:43 by reinelt]reinelt1-2/+5 2005-03-23[lcd4linux @ 2005-03-23 12:23:35 by reinelt]reinelt1-27/+32 2005-02-24[lcd4linux @ 2005-02-24 07:07:55 by reinelt]reinelt1-0/+53 2005-02-24[lcd4linux @ 2005-02-24 07:06:45 by reinelt]reinelt11-28/+347 2005-02-24[lcd4linux @ 2005-02-24 06:51:40 by reinelt]reinelt1-4/+5 2005-01-30[lcd4linux @ 2005-01-30 06:43:22 by reinelt]reinelt4-69/+95 2005-01-29[lcd4linux @ 2005-01-29 09:30:56 by reinelt]reinelt1-8/+11 2005-01-22[lcd4linux @ 2005-01-22 22:57:57 by reinelt]reinelt9-47/+382 2005-01-22[lcd4linux @ 2005-01-22 12:44:41 by reinelt]reinelt1-3/+6 2005-01-18[lcd4linux @ 2005-01-18 06:30:21 by reinelt]reinelt89-261/+603 2005-01-17[lcd4linux @ 2005-01-17 06:38:48 by reinelt]reinelt1-1/+6 2005-01-17[lcd4linux @ 2005-01-17 06:29:24 by reinelt]reinelt3-33/+85