3 * Copyright 2004, 2006 Develer S.r.l. (http://www.develer.com/)
6 * \brief Graphics user interface element to display a level bar.
8 * \author Stefano Fedrigo <aleph@develer.com>
15 * Initialize the LevelBar widget with the bitmap associated,
16 * the value range and the coordinates in the bitmap.
17 * \note The levelbar should be at least 5 pixels wide and high
18 * for correct borders drawing. No check is done on this.
20 void lbar_init(struct LevelBar *lb, struct Bitmap *bmp, int type, int min, int max, int pos,
21 coord_t x1, coord_t y1, coord_t x2, coord_t y2)
38 void lbar_setLevel(struct LevelBar *lb, int level)
52 int lbar_getLevel(struct LevelBar *lb)
59 * Change level with respect to previous value
60 * (delta can be negative).
62 void lbar_changeLevel(struct LevelBar *lb, int delta)
64 lbar_setLevel(lb, lb->pos + delta);
69 * Change the top limit.
71 void lbar_setMax(struct LevelBar *lb, int max)
78 * Render the LevelBar on the bitmap.
80 void lbar_draw(struct LevelBar *lb)
85 /* Compute filled bar length in pixels */
86 int totlen = (lb->type & LBAR_HORIZONTAL) ? lb->x2 - lb->x1 - BORDERW*4 : lb->y2 - lb->y1 - BORDERH*4;
87 int range = lb->max - lb->min;
88 int barlen = ((long)(lb->pos - lb->min) * (long)totlen + range - 1) / range;
91 gfx_rectDraw(lb->bitmap, lb->x1, lb->y1, lb->x2, lb->y2);
94 gfx_rectClear(lb->bitmap, lb->x1 + BORDERW, lb->y1 + BORDERH, lb->x2 - BORDERW, lb->y2 - BORDERH);
97 if (lb->type & LBAR_HORIZONTAL)
98 gfx_rectFill(lb->bitmap,
99 lb->x1 + BORDERW*2, lb->y1 + BORDERH*2,
100 lb->x1 + BORDERW*2 + barlen, lb->y2 - BORDERH*2);
102 gfx_rectFill(lb->bitmap,
103 lb->x1 + BORDERW*2, lb->y2 - BORDERH*2 - barlen,
104 lb->x2 - BORDERW*2, lb->y2 - BORDERH*2);