#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
#include <control.h>
Controlset *cs;
int ctldeletequits = 1;
char *colornames[3] =
{
"white",
"black",
"red"
};
char *label = "slider";
void
resizecontrolset(Controlset*)
{
Rectangle r;
if(getwindow(display, Refnone) < 0)
sysfatal("resize failed: %r");
r = insetrect(screen->r, 5);
chanprint(cs->ctl, "slider rect %R \nslider show", r);
}
void
threadmain(int argc, char *argv[])
{
Control *slider;
Channel *c;
char *s, *args[3];
int i, max;
max = 100;
ARGBEGIN{
case 'c':
for(i=0; i<3; i++){
colornames[i] = ARGF();
if(colornames[i] == nil)
goto Usage;
}
break;
case 'l':
label = ARGF();
if(label == nil)
goto Usage;
break;
case 'm':
s = ARGF();
if(s == nil)
goto Usage;
max = atoi(s);
if(max <= 0)
goto Usage;
break;
default:
Usage:
fprint(2, "usage: slider [-c bgcol bdcol indicol] [-l label] [-m max]\n");
exits("usage");
}ARGEND
if(initdraw(0, 0, label) < 0)
sysfatal("can't open display");
initcontrols();
cs = newcontrolset(screen, nil, nil, nil);
slider = createslider(cs, "slider");
chanprint(cs->ctl, "slider border 1");
chanprint(cs->ctl, "slider image %s", colornames[0]);
chanprint(cs->ctl, "slider bordercolor %s", colornames[1]);
chanprint(cs->ctl, "slider indicatorcolor %s", colornames[2]);
chanprint(cs->ctl, "slider max %d", max);
chanprint(cs->ctl, "slider clamp low 1");
chanprint(cs->ctl, "slider orient horizontal");
c = chancreate(sizeof(char*), 0);
controlwire(slider, "event", c);
activate(slider);
resizecontrolset(cs);
for(;;){
s = recvp(c);
i = tokenize(s, args, nelem(args));
if(i==3 && strcmp(args[1], "value")==0)
print("%s\n", args[2]);
free(s);
}
}
|