Beispiel #1
0
static void draw_radio(control c, rect r)
{
	int w;
	rect box, textrect;
	char *name;
	int style = (AlignLeft | AlignTop);
	font f;
	rgb old = currentcolour();

	/* Calculate rectangles. */
	f = gettextfont(c);
	setfont(f);
	w = strwidth(f,"W");
	if (w > r.width)  w = r.width;
	if (w > r.height) w = r.height;
	box = rect(r.x,r.y+1,w,w);
	if (w < getheight(f) - getdescent(f))
		box.y += getheight(f) - getdescent(f) - w;
	textrect = rect(r.x+w+w/2,r.y,r.width-(w+w/2),r.height);

	/* Clear the check area. */
	setlinewidth(1);
	setcolour(White);
	fillellipse(insetr(box,1));

	/* Draw the check area */
	if (isenabled(c))
		setcolour(Black);
	else
		setcolour(Grey);
	drawellipse(box);

	/* Provide 'pressed button' effect by black border. */
	if (ishighlighted(c)) {
		setlinewidth(2);
		drawellipse(box);
		setlinewidth(1);
	}

	/* Put o in circle if checked. */
	if (ischecked(c))
		fillellipse(insetr(box,3));

	name = getname(c);
	if (isenabled(c)) {
		/* if (hasfocus(c)) {
			style |= Underline;
			setlinewidth(2);
		} */
		setcolour(getforeground(c));
	}
	drawtext(textrect, style, name);

	setcolour(old);
}
Beispiel #2
0
static const char *draw_text_left(char *line, rect r, int line_height,
				  int underline, const char *s)
{
    char *k;
    point p;
    int width, height;
    font f;

    f = current->fnt;

    for(p=pt(r.x,r.y); (p.y<=r.y+r.height) && (s); p.y+=line_height)
    {
	s = get_next_line(line, r.width, s);

	for (k=line; *k!='\0'; k++)
	    continue;
	for (--k; (k>=line) && isspace(*k); k--)
	    *k = '\0';

	drawstr(p, line);

	if (underline) {
	    width = strwidth(f, line);
	    height = p.y+getheight(f)-getdescent(f)+2;
	    drawline(pt(p.x+1, height), pt(p.x+width-1, height));
	}
    }

    return s;
}
Beispiel #3
0
static const char *draw_text_justified(char *line, rect r, int line_height,
				       int underline, const char *s)
{
    char *j, *k;
    int w, xw, nl, sc, sw, space_width;
    point p;
    int width, height;
    font f;

    space_width = strwidth(current->fnt, " ");
    f = current->fnt;

    for(p=pt(r.x,r.y); (p.y<=r.y+r.height) && (s); p.y+=line_height)
    {
	s = get_next_line(line, r.width, s);

	p.x = r.x;

	for(j=line; (*j!='\0') && isspace(*j); j++)
	    p.x += space_width;
	for (sc=0, k=j; *k!='\0'; k++)
	    if (isspace(*k))
		sc++;
	for (nl=0, --k; (k>=j) && isspace(*k); k--) {
	    if (*k == '\n')
		nl++;
	    *k = '\0';
	    sc--;
	}

	if ((sc==0) || nl || (! s)) {
	    drawstr(p, j);
	    width = strwidth(f, j);
	}
	else {
	    w = strwidth(f, j);
	    sw = space_width + (r.x+r.width-p.x-w)/sc;
	    xw = (r.x+r.width-p.x-w)%sc;

	    for(j=strtok(j," "); j; j=strtok(NULL," "))
	    {
		drawstr(p, j);
		p.x += sw + strwidth(f, j);
		if (xw) {
		    p.x++;
		    xw--;
		}
	    }
	    width = r.width;
	}
	if (underline) {
	    height = p.y+getheight(f)-getdescent(f)+2;
	    drawline(pt(p.x+1, height), pt(p.x+width-1, height));
	}
    }

    return s;
}