Ejemplo n.º 1
0
void drawinput(Input *i)
{
	char buf[512], *s;
	int x, y, curpos, textw, innerw;
	size_t n;
	unsigned long *col = hasfocus(i->win) ? dc.sel : dc.norm;

	XSetForeground(dpy, dc.gc, col[ColBG]);
	XFillRectangle(dpy, dc.drawable, dc.gc, 0, 0, i->w, 2 * i->h);

	/* draw label */
	n = strlen(i->label);
	x = i->xpadding;
	y = (i->h - dc.font.height) / 2 + dc.font.ascent;
	XSetForeground(dpy, dc.gc, col[ColFG]);
	drawtext(x, y, i->label, n);
	x += textnw(i->label, n);

	/* draw input */
	if (i->hidden) {
		n = numrunes(i->text, sizeof(i->text));
		memset(buf, '*', n);
		buf[n] = 0;
		curpos = textnw(buf, numrunes(i->text, i->cursor));
		s = buf;
	} else {
		n = strlen(i->text);
		curpos = textnw(i->text, i->cursor);
		s = i->text;
	}

	y += i->h;
	textw = textnw(s, strlen(s));
	innerw = i->w - i->xpadding - x;
	if (curpos < i->xshift)
		i->xshift = curpos;
	else if (curpos > i->xshift + innerw)
		i->xshift = curpos - innerw;
	if (i->xshift && textw < i->xshift + innerw)
		i->xshift = MAX(0, textw - innerw);

	drawtext(1 - i->xshift, y, s, n);
	if (col == dc.sel)
		XFillRectangle(dpy, dc.drawable, dc.gc, curpos - i->xshift,
				y - dc.font.ascent, 1, dc.font.height);

	XCopyArea(dpy, dc.drawable, i->win, dc.gc, 0, 0, x, i->h, 0, 0);
	XCopyArea(dpy, dc.drawable, i->win, dc.gc, 0, i->h, i->w - x, i->h, x, 0);
	XSync(dpy, False);
}
Ejemplo n.º 2
0
static void draw_button(control c, rect r)
{
	rect textrect;
	rgb up, down;
	font f;
	rgb old = currentcolour();

	clear(c);

	/* Draw the button name. */
	if (isenabled(c))
		setcolour(getforeground(c));
	else
		setcolour(Grey);
	f = gettextfont(c);
	setfont(f);
	textrect = r;
	if (ishighlighted(c))
		textrect.x += 1, textrect.y += 1;
	drawtext(textrect, Center|VCenter, getname(c));

	/* Draw button border. */
	setlinewidth(1);
	drawrect(r);
	r = insetr(r,1);

	/* Draw button shadow. */
	up = White, down = Grey;
	if (ishighlighted(c))
		up = Grey, down = LightGrey;
	else if (hasfocus(c)) {
		setcolour(Black);
		drawrect(r);
		r = insetr(r,1);
	}
	draw_shadow(r, up, down, SHADOW_WIDTH);

	setcolour(old);
}