1
/* $Id: widget_bar.c 1106 2010-02-07 14:03:46Z mzuther $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/widget_bar.c $
6
* Copyright (C) 2003, 2004 Michael Reinelt <michael@reinelt.co.at>
7
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
* WIDGET_CLASS Widget_Bar
44
#include "timer_group.h"
46
#include "widget_bar.h"
53
void widget_bar_update(void *Self)
55
WIDGET *W = (WIDGET *) Self;
56
WIDGET_BAR *Bar = W->data;
61
/* evaluate properties */
62
property_eval(&Bar->expression1);
63
val1 = P2N(&Bar->expression1);
65
if (property_valid(&Bar->expression2)) {
66
property_eval(&Bar->expression2);
67
val2 = P2N(&Bar->expression2);
72
/* minimum: if expression is empty, do auto-scaling */
73
if (property_valid(&Bar->expr_min)) {
74
property_eval(&Bar->expr_min);
75
min = P2N(&Bar->expr_min);
86
/* maximum: if expression is empty, do auto-scaling */
87
if (property_valid(&Bar->expr_max)) {
88
property_eval(&Bar->expr_max);
89
max = P2N(&Bar->expr_max);
101
if (Bar->min != min || Bar->max != max) {
102
debug("Bar '%s': new scale %G - %G", W->name, min, max);
105
/* calculate bar values */
109
Bar->val1 = (val1 - min) / (max - min);
110
Bar->val2 = (val2 - min) / (max - min);
116
/* finally, draw it! */
123
int widget_bar_init(WIDGET * Self)
129
/* prepare config section */
130
/* strlen("Widget:")=7 */
131
section = malloc(strlen(Self->name) + 8);
132
strcpy(section, "Widget:");
133
strcat(section, Self->name);
135
Bar = malloc(sizeof(WIDGET_BAR));
136
memset(Bar, 0, sizeof(WIDGET_BAR));
138
/* load properties */
139
property_load(section, "expression", NULL, &Bar->expression1);
140
property_load(section, "expression2", NULL, &Bar->expression2);
141
property_load(section, "min", NULL, &Bar->expr_min);
142
property_load(section, "max", NULL, &Bar->expr_max);
145
if (!property_valid(&Bar->expression1)) {
146
error("Warning: widget %s has no expression", section);
149
/* bar length, default 1 */
150
cfg_number(section, "length", 1, 0, -1, &(Bar->length));
152
/* direction: East (default), West, North, South */
153
c = cfg_get(section, "direction", "E");
154
switch (toupper(*c)) {
156
Bar->direction = DIR_EAST;
157
Self->x2 = Self->col + Bar->length - 1;
158
Self->y2 = Self->row;
161
Bar->direction = DIR_WEST;
162
Self->x2 = Self->col + Bar->length - 1;
163
Self->y2 = Self->row;
166
Bar->direction = DIR_NORTH;
167
Self->x2 = Self->col;
168
Self->y2 = Self->row + Bar->length - 1;
171
Bar->direction = DIR_SOUTH;
172
Self->x2 = Self->col;
173
Self->y2 = Self->row + Bar->length - 1;
176
error("widget %s has unknown direction '%s'; known directions: 'E', 'W', 'N', 'S'; using 'E(ast)'", Self->name,
178
Bar->direction = DIR_EAST;
182
/* style: none (default), hollow */
183
c = cfg_get(section, "style", "0");
184
switch (toupper(*c)) {
186
Bar->style = STYLE_HOLLOW;
192
error("widget %s has unknown style '%s'; known styles: '0' or 'H'; using '0'", Self->name, c);
197
/* update interval (msec), default 1 sec */
198
cfg_number(section, "update", 1000, 10, -1, &(Bar->update));
200
/* get widget special colors */
201
Bar->color_valid[0] = widget_color(section, Self->name, "barcolor0", &Bar->color[0]);
202
Bar->color_valid[1] = widget_color(section, Self->name, "barcolor1", &Bar->color[1]);
207
timer_add_widget(widget_bar_update, Self, Bar->update, 0);
213
int widget_bar_quit(WIDGET * Self)
217
WIDGET_BAR *Bar = Self->data;
218
property_free(&Bar->expression1);
219
property_free(&Bar->expression2);
220
property_free(&Bar->expr_min);
221
property_free(&Bar->expr_max);
234
WIDGET_CLASS Widget_Bar = {
236
.type = WIDGET_TYPE_RC,
237
.init = widget_bar_init,
239
.quit = widget_bar_quit,