levelbar.c
Go to the documentation of this file.00001
00012 #include "levelbar.h"
00013
00014
00021 void lbar_init(struct LevelBar *lb, struct Bitmap *bmp, int type, int min, int max, int pos,
00022 coord_t x1, coord_t y1, coord_t x2, coord_t y2)
00023 {
00024 lb->bitmap = bmp;
00025 lb->type = type;
00026 lb->min = min;
00027 lb->max = max;
00028 lb->pos = pos;
00029 lb->x1 = x1;
00030 lb->y1 = y1;
00031 lb->x2 = x2;
00032 lb->y2 = y2;
00033 }
00034
00035
00039 void lbar_setLevel(struct LevelBar *lb, int level)
00040 {
00041 if (level < lb->min)
00042 level = lb->min;
00043 if (level > lb->max)
00044 level = lb->max;
00045
00046 lb->pos = level;
00047 }
00048
00049
00053 int lbar_getLevel(struct LevelBar *lb)
00054 {
00055 return lb->pos;
00056 }
00057
00058
00063 void lbar_changeLevel(struct LevelBar *lb, int delta)
00064 {
00065 lbar_setLevel(lb, lb->pos + delta);
00066 }
00067
00068
00072 void lbar_setMax(struct LevelBar *lb, int max)
00073 {
00074 lb->max = max;
00075 }
00076
00077
00081 void lbar_draw(struct LevelBar *lb)
00082 {
00083 #define BORDERW 1
00084 #define BORDERH 1
00085
00086
00087 int totlen = (lb->type & LBAR_HORIZONTAL) ? lb->x2 - lb->x1 - BORDERW*4 : lb->y2 - lb->y1 - BORDERH*4;
00088 int range = lb->max - lb->min;
00089 int barlen = ((long)(lb->pos - lb->min) * (long)totlen + range - 1) / range;
00090
00091
00092 gfx_rectDraw(lb->bitmap, lb->x1, lb->y1, lb->x2, lb->y2);
00093
00094
00095 gfx_rectClear(lb->bitmap, lb->x1 + BORDERW, lb->y1 + BORDERH, lb->x2 - BORDERW, lb->y2 - BORDERH);
00096
00097
00098 if (lb->type & LBAR_HORIZONTAL)
00099 gfx_rectFill(lb->bitmap,
00100 lb->x1 + BORDERW*2, lb->y1 + BORDERH*2,
00101 lb->x1 + BORDERW*2 + barlen, lb->y2 - BORDERH*2);
00102 else
00103 gfx_rectFill(lb->bitmap,
00104 lb->x1 + BORDERW*2, lb->y2 - BORDERH*2 - barlen,
00105 lb->x2 - BORDERW*2, lb->y2 - BORDERH*2);
00106 }