Plan 9 from Bell Labs’s /usr/web/sources/extra/art/draw.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * code to render drawings on the screen
 */
#include "art.h"

Image *color;
Image  *black, *background, *red, *msgboxcolor;
Image *anchormark, *sel, *bg;

void drawprim(Item *ip, Item *op){
	if(!(ip->flags&INVIS)) (*ip->fn->artdraw)(ip, screen, color);
}

void itemdraw(Item *ip, Dpoint offs, Image *color){
	marks();
	walk(ip, offs, drawprim);
	marks();
}
/*
 * Draw (or undraw) little dinks at argument points
 * These are always done in xor mode, and must be erased and redrawn
 * around any non xor-mode drawing.
 */
Image *sqmark=0;
void marks(void){
	Point p0, p1, p2;
	int i;

	if(sqmark==0){
		sqmark = allocimage(display, Rect(0,0,3,3), chan, 1, DBlue);
	}
	if(narg>1){
		p0=D2P(dadd(arg[0], scoffs));
		p1=D2P(dadd(arg[1], scoffs));
		if(!eqpt(p0, p1)) {		/* if p0 != p1 */
			draw(screen, Rect(p1.x-1, p1.y-1, p1.x+2, p1.y+2), sqmark, 0, ZP);
			flushimage(display, 1);
		}
		if(narg>2 && !eqpt(p0, p2=D2P(dadd(arg[2], scoffs))) && !eqpt(p1, p2)){
				/* if arguments > 2, and p0!=p1!=p2, draw red X  */
			line(screen, subpt(p2, Pt(2, 2)), addpt(p2, Pt(3, 3)), 0, 0, 0, red, ZP);
			line(screen, subpt(p2, Pt(2, -2)), p2, Endsquare, Endsquare, 0, red, ZP);
			line(screen, subpt(p2, Pt(-2, 2)), p2, Endsquare, Endsquare, 0, red, ZP);
		}
	}
	p0=D2P(dadd(anchor, scoffs));
	draw(screen, Rect(p0.x-8, p0.y-7, p0.x+8, p0.y+7), anchormark, 0, ZP);
}
/*
 * Redraw absolutely everything
 *  sel == whole window area for this art program
 */
void redraw(void){
	rectf(sel, screen->r, background);
	rectf(sel, echobox, black);
	rectf(sel, msgbox, black);
	rectf(sel, dwgbox, background);
	if(bg)						/* there is a background image */
/*		draw(sel, bg->r, bg, 0, ZP);	*/
		draw(sel, dwgbox, bg, 0, ZP);
	rectf(sel, echobox, msgboxcolor);
	rectf(sel, msgbox, msgboxcolor);
	draw(screen, sel->r, sel, 0, screen->r.min);
	drawmenubar();
	echo(cmd);
	lastmsg();
	if(scsp!=scstack)
		itemdraw(scstack[0].scene, scstack[0].scoffs, color);
	else
		itemdraw(scene, scoffs, color);
	itemdraw(active, Dpt(0., 0.), color);
	drawcurpt();
	marks();
	drawsel();
	drawgrid();
}

void setbg(char *file){
	int fd;

	fd = open(file, OREAD);
	bg = readimage(display, fd, 0);
	close(fd);
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.