Exemplo n.º 1
0
void
nextglenda(void)
{
	int min =1000, next, dir, nextdir = 0, count = 0;
	Point p = findglenda();

	calc();
	calc();
	calc();

	grid[p.x][p.y] = 1000;
	
	for(dir = NE; dir <= NW; dir++) {
		next = checknext(dir, p.x, p.y);
		if(next < min) {
			min = next;
			nextdir = dir;
			++count;
		} else if(next == min) {
			nextdir = (nrand(++count) == 0)?dir:nextdir;
		}
	}
	if(min < 100)
		domove(nextdir, p.x, p.y);
	else
		finished = Won;

	if(eqpt(findglenda(), Pt(-1, -1)))
		finished = Lost;
}
Exemplo n.º 2
0
static int
mga4xxscroll(VGAscr *scr, Rectangle dr, Rectangle sr)
{
	uchar * mga;
	int pitch;
 	int width, height;
	ulong start, end, sgn;
	Point sp, dp;
 
	if(scr->mmio == 0)
		return 0;
	mga = (uchar*)scr->mmio;

	assert(Dx(sr) == Dx(dr) && Dy(sr) == Dy(dr));

	sp = sr.min;
	dp = dr.min;
	if(eqpt(sp, dp))
		return 1;

	pitch = Dx(scr->gscreen->r);
	width = Dx(sr);
	height = Dy(sr);
	sgn = 0;

	if(dp.y > sp.y && dp.y < sp.y + height){
		sp.y += height - 1;
		dp.y += height - 1;
		sgn |= SGN_UP;
	}

	width--;
	start = end = sp.x + (sp.y * pitch);

	if(dp.x > sp.x && dp.x < sp.x + width){
		start += width;
		sgn |= SGN_LEFT;
	}
	else
		end += width;

	mga_fifo(mga, 8);
	mgawrite32(mga, DWGCTL, 0);
	mgawrite32(mga, SGN, sgn);
	mgawrite32(mga, AR5, sgn & SGN_UP ? -pitch : pitch);
	mgawrite32(mga, AR0, end);
	mgawrite32(mga, AR3, start);
	mgawrite32(mga, FXBNDRY, ((dp.x + width) << 16) | dp.x);
	mgawrite32(mga, YDSTLEN, (dp.y << 16) | height);
	mgawrite32(mga, DWGCTL + GO, DWG_BITBLT | DWG_SHIFTZERO | DWG_BFCOL | DWG_REPLACE);

	while(mgaread32(mga, STATUS) & 0x00010000)
		;

	return 1;
}
Exemplo n.º 3
0
void
swcursorclock(void)
{
	int x;
	if(!swenabled)
		return;
	if(swvisible && eqpt(swpt, swvispt) && swvers==swvisvers)
		return;

	x = splhi();
	if(swenabled)
	if(!swvisible || !eqpt(swpt, swvispt) || swvers!=swvisvers)
	if(canqlock(&drawlock)){
		swcursorhide();
		swcursordraw();
		qunlock(&drawlock);
	}
	splx(x);
}
Exemplo n.º 4
0
Arquivo: windw.c Projeto: 8l/inferno
void
tkmovewin(Tk *tk, Point p)
{
	TkWin *tkw;
	if((tk->flag & Tkwindow) == 0)
		return;
	tkw = TKobj(TkWin, tk);
	if(! eqpt(p, tkw->req)){
		tkw->req = p;
		tkw->changed = 1;
	}
}
Exemplo n.º 5
0
Arquivo: windw.c Projeto: 8l/inferno
char*
tkseecmd(TkTop *t, char *arg, char **ret)
{
	TkOptab tko[2];
	TkSee opts;
	TkName *names;
	Tk *tk;
	char *e;
	Rectangle vr;
	Point vp;

	opts.r[0] = bbnil.min.x;
	opts.r[1] = bbnil.min.y;
	opts.r[2] = bbnil.max.x;
	opts.r[3] = bbnil.max.y;
	opts.p[0] = bbnil.max.x;
	opts.p[1] = bbnil.max.y;
	opts.query = 0;

	tko[0].ptr = &opts;
	tko[0].optab = seeopts;
	tko[1].ptr = nil;
	names = nil;
	e = tkparse(t, arg, tko, &names);
	if (e != nil)
		return e;
	if (names == nil)
		return TkBadwp;
	tk = tklook(t, names->name, 0);
	tkfreename(names);
	if (tk == nil)
		return TkBadwp;
	if (opts.query) {
		if (!tkvisiblerect(tk, &vr))
			return nil;
		/* XXX should this be converted into screen coords? */
		return tkvalue(ret, "%d %d %d %d", vr.min.x, vr.min.y, vr.max.x, vr.max.y);
	}
	vr.min.x = opts.r[0];
	vr.min.y = opts.r[1];
	vr.max.x = opts.r[2];
	vr.max.y = opts.r[3];
	vp.x = opts.p[0];
	vp.y = opts.p[1];

	if (eqrect(vr, bbnil))
		vr = tkrect(tk, 1);
	if (eqpt(vp, bbnil.max))
		vp = vr.min;
	tksee(tk, vr, vp);
	return nil;
}
Exemplo n.º 6
0
void
drawtime(void)
{
	Rectangle r;

	r.min = addpt(screen->r.min, datep);
	if(eqpt(enddate, ZP)){
		enddate = r.min;
		enddate.x += stringwidth(datefont, "Wed May 30 22:54");	/* nice wide string */
		enddate.x += Facesep;	/* for safety */
	}
	r.max.x = enddate.x;
	r.max.y = enddate.y+datefont->height;
	draw(screen, r, bgrnd, nil, ZP);
	string(screen, r.min, display->black, ZP, datefont, date);
}
Exemplo n.º 7
0
Arquivo: gs.c Projeto: 99years/plan9
/*
 * set the dimensions of the bitmap we expect to get back from GS.
 */
void
setdim(GSInfo *gs, Rectangle bbox, int ppi, int landscape)
{
	Rectangle pbox;

	if(chatty)
		fprint(2, "setdim: bbox=%R\n", bbox);

	if(ppi)
		gs->ppi = ppi;

	gscmd(gs, "mark\n");
	if(ppi)
		gscmd(gs, "/HWResolution [%d %d]\n", ppi, ppi);

	if(!Dx(bbox))
		bbox = Rect(0, 0, 612, 792);	/* 8½×11 */

	switch(landscape){
	case 0:
		pbox = bbox;
		break;
	case 1:
		pbox = Rect(bbox.min.y, bbox.min.x, bbox.max.y, bbox.max.x);
		break;
	}
	gscmd(gs, "/PageSize [%d %d]\n", Dx(pbox), Dy(pbox));
	gscmd(gs, "/Margins [%d %d]\n", -pbox.min.x, -pbox.min.y);
	gscmd(gs, "currentdevice putdeviceprops pop\n");
	gscmd(gs, "/#copies 1 store\n");

	if(!eqpt(bbox.min, ZP))
		gscmd(gs, "%d %d translate\n", -bbox.min.x, -bbox.min.y);

	switch(landscape){
	case 0:
		break;
	case 1:
		gscmd(gs, "%d 0 translate\n", Dy(bbox));
		gscmd(gs, "90 rotate\n");
		break;
	}

	waitgs(gs);
}
Exemplo n.º 8
0
void
pageselect(Page *p)
{
	int b, x, y;


	selpage = p;
	/*
	 * To have double-clicking and chording, we double-click
	 * immediately if it might make sense.
	 */
	b = mouse->buttons;
	if(mouse->msec-clickmsec<500){
		pagedoubleclick(p);
		x = mouse->xy.x;
		y = mouse->xy.y;
		/* stay here until something interesting happens */
		do
			readmouse(mousectl);
		while(mouse->buttons==b && abs(mouse->xy.x-x)<3 && abs(mouse->xy.y-y)<3);
		mouse->xy.x = x;	/* in case we're calling pageselect1 */
		mouse->xy.y = y;
	}
	if(mousectl->buttons == b)
		pageselect1(p);

	if(eqpt(p->top, p->bot)){
		if(mouse->msec-clickmsec<500)
			pagedoubleclick(p);
		else
			clickmsec = mouse->msec;
	}
	while(mouse->buttons){
		mouse->msec = 0;
		b = mouse->buttons;
		if(b & 2)	/* snarf only */
			cut(nil, nil, TRUE, FALSE, nil, 0);
		while(mouse->buttons == b)
			readmouse(mousectl);
	}
}
Exemplo n.º 9
0
static void
_bezsplinepts(Plist *l, Point *pt, int npt)
{
	Point *p, *ep;
	Point a, b, c, d;
	int periodic;

	if(npt<3)
		return;
	ep = &pt[npt-3];
	periodic = eqpt(pt[0], ep[2]);
	if(periodic){
		a = divpt(addpt(ep[1], pt[0]), 2);
		b = divpt(addpt(ep[1], mulpt(pt[0], 5)), 6);
		c = divpt(addpt(mulpt(pt[0], 5), pt[1]), 6);
		d = divpt(addpt(pt[0], pt[1]), 2);
		bpts(l, a, b, c, d);
	}
	for(p=pt; p<=ep; p++){
		if(p==pt && !periodic){
			a = p[0];
			b = divpt(addpt(p[0], mulpt(p[1], 2)), 3);
		}
		else{
			a = divpt(addpt(p[0], p[1]), 2);
			b = divpt(addpt(p[0], mulpt(p[1], 5)), 6);
		}
		if(p==ep && !periodic){
			c = divpt(addpt(mulpt(p[1], 2), p[2]), 3);
			d = p[2];
		}
		else{
			c = divpt(addpt(mulpt(p[1], 5), p[2]), 6);
			d = divpt(addpt(p[1], p[2]), 2);
		}
		bpts(l, a, b, c, d);
	}
	appendpt(l, d);
}
Exemplo n.º 10
0
/*
 * Place i so i->r.min = log, i->layer->screenr.min == scr.
*/
int
memlorigin(Memimage *i, Point log, Point scr)
{
	Memlayer *l;
	Memscreen *s;
	Memimage *t, *shad, *nsave;
	Rectangle x, newr, oldr;
	Point delta;
	int overlap, eqlog, eqscr, wasclear;

	l = i->layer;
	s = l->screen;
	oldr = l->screenr;
	newr = Rect(scr.x, scr.y, scr.x+Dx(oldr), scr.y+Dy(oldr));
	eqscr = eqpt(scr, oldr.min);
	eqlog = eqpt(log, i->r.min);
	if(eqscr && eqlog)
		return 0;
	nsave = nil;
	if(eqlog==0 && l->save!=nil){
		nsave = allocmemimage(Rect(log.x, log.y, log.x+Dx(oldr), log.y+Dy(oldr)), i->chan);
		if(nsave == nil)
			return -1;
	}

	/*
	 * Bring it to front and move logical coordinate system.
	 */
	memltofront(i);
	wasclear = l->clear;
	if(nsave){
		if(!wasclear)
			memimagedraw(nsave, nsave->r, l->save, l->save->r.min, nil, Pt(0,0), S);
		freememimage(l->save);
		l->save = nsave;
	}
	delta = subpt(log, i->r.min);
	i->r = rectaddpt(i->r, delta);
	i->clipr = rectaddpt(i->clipr, delta);
	l->delta = subpt(l->screenr.min, i->r.min);
	if(eqscr)
		return 0;

	/*
	 * To clean up old position, make a shadow window there, don't paint it,
	 * push it behind this one, and (later) delete it.  Because the refresh function
	 * for this fake window is a no-op, this will cause no graphics action except
	 * to restore the background and expose the windows previously hidden.
	 */
	shad = memlalloc(s, oldr, memlnorefresh, nil, DNofill);
	if(shad == nil)
		return -1;
	s->frontmost = i;
	if(s->rearmost == i)
		s->rearmost = shad;
	else
		l->rear->layer->front = shad;
	shad->layer->front = i;
	shad->layer->rear = l->rear;
	l->rear = shad;
	l->front = nil;
	shad->layer->clear = 0;

	/*
	 * Shadow is now holding down the fort at the old position.
	 * Move the window and hide things obscured by new position.
	 */
	for(t=l->rear->layer->rear; t!=nil; t=t->layer->rear){
		x = newr;
		overlap = rectclip(&x, t->layer->screenr);
		if(overlap){
			memlhide(t, x);
			t->layer->clear = 0;
		}
	}
	l->screenr = newr;
	l->delta = subpt(scr, i->r.min);
	l->clear = rectinrect(newr, l->screen->image->clipr);

	/*
	 * Everything's covered.  Copy to new position and delete shadow window.
	 */
	if(wasclear)
		memdraw(s->image, newr, s->image, oldr.min, nil, Pt(0,0), S);
	else
		memlexpose(i, newr);
	memldelete(shad);

	return 1;
}
Exemplo n.º 11
0
static void
groupmouse(Control *c, Mouse *m)
{
	Group *g;
	int i, lastkid;

	g = (Group*)c;
	if (g->type == Ctlstack){
		i = g->selected;
		if (i >= 0 && g->kids[i]->mouse &&
                        ( ( ((m->buttons == 0) || (g->lastbut == 0)) &&
                           ptinrect(m->xy, g->kids[i]->rect) ) ||
                         ( ((m->buttons != 0) || (g->lastbut != 0)) &&
		         (g->lastkid == i) ) ) ) {
			if (debugm) fprint(2, "groupmouse %s mouse kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n",
						g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut,
						ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0);
			(g->kids[i]->mouse)(g->kids[i], m);
			g->lastkid = i;
			g->lastbut = m->buttons;
		} else {
			if (debugm) fprint(2, "groupmouse %s skip kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n",
						g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut,
						ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0);
		}
		return;
	}

	lastkid = -1;
	for(i=0; i<g->nkids; i++) {
		if(g->kids[i]->mouse &&
                      ( ( ((m->buttons == 0) || (g->lastbut == 0)) &&
                           ptinrect(m->xy, g->kids[i]->rect) ) ||
                        ( ((m->buttons != 0) || (g->lastbut != 0)) &&
		         (g->lastkid == i) ) ) ) {
			if (debugm) fprint(2, "groupmouse %s mouse kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n",
						g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut,
						ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0);
			(g->kids[i]->mouse)(g->kids[i], m);
			lastkid = i;
		} else {
			if (debugm) fprint(2, "groupmouse %s skip kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n",
						g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut,
						ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0);
		}
	}
	g->lastkid = lastkid;
	g->lastbut = m->buttons;

#ifdef notdef
	if(m->buttons == 0){
		/* buttons now up */
		g->lastbut = 0;
		return;
	}
	if(g->lastbut == 0 && m->buttons != 0){
		/* button went down, start tracking border */
		switch(g->stacking){
		default:
			return;
		case Vertical:
			p = Pt(m->xy.x, middle_of_border.y);
			p0 = Pt(g->r.min.x, m->xy.y);
			p1 = Pt(g->r.max.x, m->xy.y);
			break;
		case Horizontal:
			p = Pt(middle_of_border.x, m->xy.y);
			p0 = Pt(m->xy.x, g->r.min.y);
			p1 = Pt(m->xy.x, g->r.max.y);
			break;
		}
	//	setcursor();
		oi = nil;
	} else if (g->lastbut != 0 && s->m.buttons != 0){
		/* button is down, keep tracking border */
		if(!eqpt(s->m.xy, p)){
			p = onscreen(s->m.xy);
			r = canonrect(Rpt(p0, p));
			if(Dx(r)>5 && Dy(r)>5){
				i = allocwindow(wscreen, r, Refnone, 0xEEEEEEFF); /* grey */
				freeimage(oi);
				if(i == nil)
					goto Rescue;
				oi = i;
				border(i, r, Selborder, red, ZP);
				flushimage(display, 1);
			}
		}
	} else if (g->lastbut != 0 && s->m.buttons == 0){
		/* button went up, resize kiddies */
	}
	g->lastbut = s->m.buttons;
#endif
}