]> git.ipfire.org Git - thirdparty/newt.git/blob - scale.c
revert for now
[thirdparty/newt.git] / scale.c
1 #include <slang.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "newt.h"
6 #include "newt_pr.h"
7
8 struct scale {
9 long long fullValue;
10 int charsSet;
11 };
12
13 static void scaleDraw(newtComponent co);
14
15 static struct componentOps scaleOps = {
16 scaleDraw,
17 newtDefaultEventHandler,
18 NULL,
19 newtDefaultPlaceHandler,
20 newtDefaultMappedHandler,
21 } ;
22
23 newtComponent newtScale(int left, int top, int width, long long fullValue) {
24 newtComponent co;
25 struct scale * sc;
26
27 co = malloc(sizeof(*co));
28 sc = malloc(sizeof(struct scale));
29 co->data = sc;
30
31 co->ops = &scaleOps;
32
33 co->height = 1;
34 co->width = width;
35 co->top = top;
36 co->left = left;
37 co->takesFocus = 0;
38
39 sc->fullValue = fullValue;
40 sc->charsSet = 0;
41
42 return co;
43 }
44
45 void newtScaleSet(newtComponent co, unsigned long long amount) {
46 struct scale * sc = co->data;
47 int newCharsSet;
48
49 newCharsSet = (amount * co->width) / sc->fullValue;
50
51 if (newCharsSet != sc->charsSet) {
52 sc->charsSet = newCharsSet;
53 scaleDraw(co);
54 }
55 }
56
57 static void scaleDraw(newtComponent co) {
58 struct scale * sc = co->data;
59 int i;
60
61 if (co->top == -1) return;
62
63 newtGotorc(co->top, co->left);
64
65 SLsmg_set_color(NEWT_COLORSET_FULLSCALE);
66 for (i = 0; i < sc->charsSet; i++)
67 SLsmg_write_string(" ");
68
69 SLsmg_set_color(NEWT_COLORSET_EMPTYSCALE);
70 for (i = 0; i < (co->width - sc->charsSet); i++)
71 SLsmg_write_string(" ");
72 }