]>
git.ipfire.org Git - thirdparty/newt.git/blob - scale.c
11 unsigned int percentage
;
14 static void scaleDraw(newtComponent co
);
16 static struct componentOps scaleOps
= {
18 newtDefaultEventHandler
,
20 newtDefaultPlaceHandler
,
21 newtDefaultMappedHandler
,
24 newtComponent
newtScale(int left
, int top
, int width
, long long fullValue
) {
28 co
= malloc(sizeof(*co
));
29 sc
= malloc(sizeof(struct scale
));
40 sc
->fullValue
= fullValue
;
47 void newtScaleSet(newtComponent co
, unsigned long long amount
) {
48 struct scale
* sc
= co
->data
;
51 sc
->charsSet
= (amount
* co
->width
) / sc
->fullValue
;
52 newPercentage
= (amount
* 100) / sc
->fullValue
;
54 if (newPercentage
> 100)
57 if (newPercentage
!= sc
->percentage
) {
58 sc
->percentage
= newPercentage
;
63 static void scaleDraw(newtComponent co
) {
64 struct scale
* sc
= co
->data
;
66 int xlabel
= (co
->width
-4) /2;
69 if (co
->top
== -1) return;
71 newtGotorc(co
->top
, co
->left
);
73 sprintf(percent
, "%3d%%", sc
->percentage
);
75 SLsmg_set_color(NEWT_COLORSET_FULLSCALE
);
77 for (i
= 0; i
< co
->width
; i
++) {
78 if (i
== sc
->charsSet
)
79 SLsmg_set_color(NEWT_COLORSET_EMPTYSCALE
);
80 if (i
>= xlabel
&& i
< xlabel
+4)
81 SLsmg_write_char(percent
[i
-xlabel
]);
83 SLsmg_write_char(' ');