~amavect/makeu

3be6d56622a6aa0b2eddc001a968a035e3ba02b5 — amavect 1 year, 9 months ago 4a0025a
Draw to back buffer instead of directly to screen.
5 files changed, 50 insertions(+), 34 deletions(-)

M components.h
M hsvmap.c
M makeu.c
M screenpick.c
M slider.c
M components.h => components.h +3 -0
@@ 2,6 2,9 @@ typedef struct Slider Slider;
typedef struct HSVmap HSVmap;
typedef struct Screenpick Screenpick;

/* screen back buffer */
extern Image *screenbuf;

struct Slider {
	double val; /* starting value */
	double min; /* minimum value */

M hsvmap.c => hsvmap.c +10 -10
@@ 113,28 113,28 @@ redraw(HSVmap *h)
	loadimage(h->pix, h->pix->r, c, sizeof(c));
	switch(h->maptype){
	case 0:
		draw(screen, h->r, h->huex, nil, ZP);
		draw(screen, h->r, h->saty, nil, ZP);
		draw(screenbuf, h->r, h->huex, nil, ZP);
		draw(screenbuf, h->r, h->saty, nil, ZP);
		rxy.y = hsvd.val;
		draw(h->pix, h->pix->r, h->valy, nil, ratioxytopoint(rxy, h->r));
		draw(screen, h->r, h->pix, nil, ZP);
		draw(screenbuf, h->r, h->pix, nil, ZP);
		break;
	case 1:
		rxy.x = hsvd.hue / 6.0;
		draw(h->pix, h->pix->r, h->huex, nil, ratioxytopoint(rxy, h->r));
		draw(screen, h->r, h->pix, nil, ZP);
		draw(screen, h->r, h->satx, nil, ZP);
		draw(screen, h->r, h->valy, nil, ZP);
		draw(screenbuf, h->r, h->pix, nil, ZP);
		draw(screenbuf, h->r, h->satx, nil, ZP);
		draw(screenbuf, h->r, h->valy, nil, ZP);
		break;
	case 2:
		draw(screen, h->r, h->huex, nil, ZP);
		draw(screenbuf, h->r, h->huex, nil, ZP);
		rxy.x = hsvd.sat;
		draw(h->pix, h->pix->r, h->satx, nil, ratioxytopoint(rxy, h->r));
		draw(screen, h->r, h->pix, nil, ZP);
		draw(screen, h->r, h->valy, nil, ZP);
		draw(screenbuf, h->r, h->pix, nil, ZP);
		draw(screenbuf, h->r, h->valy, nil, ZP);
		break;
	}
	draw(screen, h->r, h->circ, nil, mulpt(ratioxytopoint(h->pos, h->r),-1));
	draw(screenbuf, h->r, h->circ, nil, mulpt(ratioxytopoint(h->pos, h->r),-1));
}

/*

M makeu.c => makeu.c +24 -11
@@ 24,6 24,8 @@ void alphaevent(double);

int pflag = 0;

Image *screenbuf;

/* 
 * Alternative color models are needed because they do not map
 * injectively to each other.


@@ 273,7 275,15 @@ egetwindow(void)
{
	if(getwindow(display, Refnone) < 0)
		sysfatal("Cannot reconnect to display: %r");
	draw(screen, screen->r, display->black, nil, ZP);
	freeimage(screenbuf);
	screenbuf = allocimage(display, screen->r, screen->chan, 0, DBlack);
}

void
show(void)
{
	draw(screen, screen->r, screenbuf, nil, screen->r.min);
	flushimage(display, 1);
}

void


@@ 349,9 359,12 @@ threadmain(int argc, char **argv)
	va.val = hsvd.val;
	aa.val = alpha;
	
	screenbuf = allocimage(display, screen->r, screen->chan, 0, DBlack);
	if(screenbuf == nil)
		sysfatal("%r");
	root->init(root);
	root->resize(root, screen->r);
	flushimage(display, 1);
	root->resize(root, screenbuf->r);
	show();
	
	enum { MOUSE, RESIZE, KEYS, FS, NONE };
	Alt alts[] = {


@@ 373,11 386,11 @@ threadmain(int argc, char **argv)
		/* DEBUG frame counter */
		/*
		snprint(ftext, sizeof(ftext), "%uld", (ulong)frames);
		rekt = Rpt(screen->r.min, addpt(screen->r.min, stringsize(display->defaultfont, ftext)));
		draw(screen, rekt, display->white, nil, ZP);
		string(screen, screen->r.min, display->black, ZP, display->defaultfont, ftext);
		rekt = Rpt(screenbuf->r.min, addpt(screenbuf->r.min, stringsize(display->defaultfont, ftext)));
		draw(screenbuf, rekt, display->white, nil, ZP);
		string(screenbuf, screenbuf->r.min, display->black, ZP, display->defaultfont, ftext);
		frames++;
		flushimage(display, 1);
		show();
		*/
		
		switch(alt(alts)){


@@ 396,12 409,12 @@ threadmain(int argc, char **argv)
				break;
			}
			if(root->mouse(root, m) == 1)
				flushimage(display, 1);
				show();
			break;
		case RESIZE:
			egetwindow();
			root->resize(root, screen->r);
			flushimage(display, 1);
			root->resize(root, screenbuf->r);
			show();
			break;
		case KEYS:
			if(r == Kdel)


@@ 411,7 424,7 @@ threadmain(int argc, char **argv)
			if(incolor == color)
				break;
			allevent(incolor);
			flushimage(display, 1);
			show();
			break;
		case NONE:
			print("I'm a woodchuck, not a woodchucker! (thanks for playing)\n");

M screenpick.c => screenpick.c +7 -7
@@ 54,7 54,7 @@ redraw(Screenpick *sp)
	pfont.y -= 3*strsize.y/2;
	pfont2.y -= strsize.y/2;
	
	draw(screen, r, display->black, nil, ZP);
	draw(screenbuf, r, display->black, nil, ZP);
	for(i = 0; i < 2; i++){
		r2.min.x = dx*i/2 + r.min.x;
		r2.min.y = dy/2 + r.min.y;


@@ 63,12 63,12 @@ redraw(Screenpick *sp)
		r3.min = r2.max;
		r3.max.x = dx*(i+1)/2 + r.min.x;
		r3.max.y = r.max.y;
		draw(screen, r2, display->white, nil, ZP);
		draw(screen, r3, display->white, nil, ZP);
		draw(screenbuf, r2, display->white, nil, ZP);
		draw(screenbuf, r3, display->white, nil, ZP);
	}
	draw(screen, r, sp->pixel, nil, ZP);
	string(screen, pfont, display->black, ZP, display->defaultfont, hex);
	string(screen, pfont2, display->white, ZP, display->defaultfont, hex);
	draw(screenbuf, r, sp->pixel, nil, ZP);
	string(screenbuf, pfont, display->black, ZP, display->defaultfont, hex);
	string(screenbuf, pfont2, display->white, ZP, display->defaultfont, hex);
}

/*


@@ 195,7 195,7 @@ again:
		newpixr.min = addpt(newpixr.min, Pt(Dx(newpixr)/2,Dy(newpixr)/2));
		loadimage(screenline, screenline->r, sp->linebuf, sp->linesize);
		draw(pixel, pixel->r, screenline, nil, Pt(m.xy.x, 0));
		draw(screen, newpixr, pixel, nil, ZP);
		draw(screenbuf, newpixr, pixel, nil, ZP);
		if(m.buttons == 0){
			setcursor(sp->mctl, nil);
			sp->color = getpixelcolor(sp);

M slider.c => slider.c +6 -6
@@ 30,21 30,21 @@ redraw(Slider *sl)
	Point pfont;
	int off;
	r = sl->r;
	draw(screen, sl->r, sl->bg, nil, ZP);
	draw(screenbuf, sl->r, sl->bg, nil, ZP);
	if(sl->ishoriz){
		off = (int)(Dx(r) * sl->val / (sl->max - sl->min));
		draw(screen, r, sl->bka, nil, Pt(-off, 0));
		draw(screen, r, sl->wta, nil, Pt(-off, -Dy(r)));
		draw(screenbuf, r, sl->bka, nil, Pt(-off, 0));
		draw(screenbuf, r, sl->wta, nil, Pt(-off, -Dy(r)));
	}else{
		off = Dy(r) - (int)(Dy(r) * sl->val / (sl->max - sl->min));
		draw(screen, r, sl->bka, nil, Pt(0, -off));
		draw(screen, r, sl->wta, nil, Pt(-Dx(r), -off));
		draw(screenbuf, r, sl->bka, nil, Pt(0, -off));
		draw(screenbuf, r, sl->wta, nil, Pt(-Dx(r), -off));
	}
	snprint(txt, 64, sl->fmt, sl->val);
	pfont = stringsize(display->defaultfont, txt);
	pfont.x = (Dx(r) - pfont.x)/2 + r.min.x;
	pfont.y = (Dy(r) - pfont.y)/2 + r.min.y;
	string(screen, pfont, display->black, ZP, display->defaultfont, txt);
	string(screenbuf, pfont, display->black, ZP, display->defaultfont, txt);
}

/*