示例#1
0
文件: entry.c 项目: BGCX261/znos-git
static void
tkentrytext(Image *i, Rectangle s, Tk *tk, TkEnv *env)
{
	TkEntry *tke = TKobj(TkEntry, tk);
	Point dp;
	int s0, s1, xs0, xs1, j;
	Rectangle r;
	Rune showr, *text;

	dp = Pt(s.min.x - (tke->x0 - tke->xv0), s.min.y);
	if (tke->show) {
		chartorune(&showr, tke->show);
		text = mallocz(sizeof(Rune) * (tke->textlen+1), 0);
		if (text == nil)
			return;
		for (j = 0; j < tke->textlen; j++)
			text[j] = showr;
	} else
		text = tke->text;

	runestringn(i, dp, tkgc(env, TkCforegnd), dp, env->font,
				text+tke->v0, tke->v1-tke->v0);

	if (tke->sel0 < tke->v1 && tke->sel1 > tke->v0) {
		if (tke->sel0 < tke->v0) {
			s0 = tke->v0;
			xs0 = tke->xv0 - tke->x0;
		} else {
			s0 = tke->sel0;
			xs0 = tke->xsel0 - tke->x0;
		}

		if (tke->sel1 > tke->v1) {
			s1 = tke->v1;
			xs1 = s.max.x;
		} else {
			s1 = tke->sel1;
			xs1 = tke->xsel1 - tke->x0;
		}

		r = rectaddpt(Rect(xs0, 0, xs1, env->font->height), s.min);
		tktextsdraw(i, r, env, 1);
		runestringn(i, r.min, tkgc(env, TkCselectfgnd), r.min, env->font,
				text+s0, s1-s0);
	}

	if((tke->flag&Ecursoron) && tke->icursor >= tke->v0 && tke->icursor <= tke->v1) {
		r = Rect(
			tke->xicursor - tke->x0, 0, 
			tke->xicursor - tke->x0 + Inswidth, env->font->height
		);
		draw(i, rectaddpt(r, s.min), tkgc(env, TkCforegnd), nil, ZP);
	}
	if (tke->show)
		free(text);
}
示例#2
0
文件: ctext.c 项目: 8l/inferno
void
tkcvstextdraw(Image *img, TkCitem *i, TkEnv *pe)
{
	TkEnv *e;
	TkCtext *t;
	Point o, dp;
	Rectangle r;
	char *p, *next;
	Image *pen;
	int len, lw, end, start;

	t = TKobj(TkCtext, i);

	e = i->env;
	pen = t->pen;
	if(pen == nil) {
		if (e->set & (1<<TkCfill))
			pen = tkgc(e, TkCfill);
		else
			pen = img->display->black;
	}


	o = addpt(t->anchorp, i->p.drawpt[0]);
	p = t->text;
	while(p && *p) {
		next = tkcvstextgetl(t, e->font, p, &len);
		dp = o;
		if(t->justify != Tkleft) {
			lw = stringnwidth(e->font, p, len);
			if(t->justify == Tkcenter)
				dp.x += (t->pixwidth - lw)/2;
			else
			if(t->justify == Tkright)
				dp.x += t->pixwidth - lw;
		}
		lw = p - t->text;
		if(t->self != -1 && lw+len > t->self) {
			if(t->sell >= t->self) {
				start = t->self - lw;
				end = t->sell - lw;
			}
			else {
				start = t->sell - lw;
				end = t->self - lw;
			}
			if(start < 0)
				r.min.x = o.x;
			else
				r.min.x = dp.x + stringnwidth(e->font, p, start);
			r.min.y = dp.y;
			if(end > len)
				r.max.x = o.x + t->pixwidth;
			else
				r.max.x = dp.x + stringnwidth(e->font, p, end);
			r.max.y = dp.y + e->font->height;
			tktextsdraw(img, r, pe, t->sbw);
			r.max.y = dp.y;
			if(start > 0)
				stringn(img, dp, pen, dp, e->font, p, start);
			if(end > start)
				stringn(img, r.min, tkgc(pe, TkCselectfgnd), r.min, e->font, p+start, end-start);
			if(len > end)
				stringn(img, r.max, pen, r.max, e->font, p+end, len-end);
		}
		else
			stringn(img, dp, pen, dp, e->font, p, len);
		if(t->focus) {
			lw = p - t->text;
			if(t->icursor >= lw && t->icursor <= lw+len) {
				lw = t->icursor - lw;
				if(lw > 0)
					lw = stringnwidth(e->font, p, lw);
				r.min.x = dp.x + lw;
				r.min.y = dp.y - 1;
				r.max.x = r.min.x + 2;
				r.max.y = r.min.y + e->font->height + 1;
				draw(img, r, pen, nil, ZP);
			}
		}
		o.y += e->font->height;
		p = next;
	}
}