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