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

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


/*
 * initialization of globals and command loop
 */
#include "art.h"

#define	SPACE	1		/* width of interior vertical margins */
Item *scene, *active;
Alpt *alpt;

short tcur[16]={
	 0x0100, 0x0100, 0x0380, 0x0380,
	 0x07C0, 0x07C0, 0x0FE0, 0x0EE0,
	 0x1C70, 0x1830, 0x3018, 0x2008,
	 0x0000, 0x0000, 0x0000, 0x0000,
};
short anc[16]={
	0x3838, 0x7C7C, 0xF01E, 0xF83E,
	0xDC76, 0x4EE4, 0x07C0, 0x0280,
	0x07C0, 0x4EE4, 0xDC76, 0xF83E,
	0xF01E, 0x7C7C, 0x3838, 0x0000,
};

/* colors for art */
Image *black;
Image *red;
Image *blue;
Image *paleyellow;
Image *darkgreen;
Image *palegreen;
Image *darkblue;
Image *darkgrey;
Image *medgreen;
/* Image *transparent;	*/

Image *cur;				/* caret bitmap */
Image *anchormark;		/* anchor bitmap */
Image *sel;				/* selected window i.e. where art runs */
Image *bg;				/* background pic image */

Image *color;				/* changable color */
Image *menucolor;			/* color of menu bar */
Image *msgboxcolor;
Image *gridcolor;
Image *background;			/* background color of canvas */

Rectangle echobox;
Rectangle msgbox;
Rectangle dwgbox;

void eresized(int new){
	Rectangle rest;

	if(new && getwindow(display, Refmesg) < 0)
		fprint(2,"can't reattach to window");
	rest=drawmenubar();
	fontp=curface->font;
	/* does this look like we need an array, or what? */
	msgbox.max=subpt(rest.max, Pt(0, SPACE));
	msgbox.min=Pt(rest.min.x, msgbox.max.y-SPACE-fontp->height);
	echobox.max=Pt(rest.max.x, msgbox.min.y-SPACE);
	echobox.min=Pt(rest.min.x, echobox.max.y-SPACE-fontp->height);
	dwgbox.max=Pt(rest.max.x, echobox.min.y-SPACE);
	dwgbox.min=subpt(rest.min, Pt(SPACE, SPACE));

	if(dwgbox.max.y<=dwgbox.min.y){
		fprint(2, "%s: please make the window higher and restart: there's no space to draw in.\n",
			cmdname);
		exits("need higher window");
	}
	dwgdrect=drcanon(Drpt(P2D(dwgbox.min), P2D(dwgbox.max)));
	if(sel!=0) freeimage(sel);
	sel = allocimage(display, screen->r, chan, 1, DBlack);
	if(sel==0){
		fprint(2, "%s: out of image space\n", cmdname);
		exits("no space");
	}
	redraw();
}

void main(int argc, char *argv[]){
	Point p;
	char *fontname, *bgname;

	cmdname=argv[0];
	initdraw(0, 0, cmdname);
	einit(Emouse|Ekeyboard);
	ainit();
	setface("pelm,unicode,9");	/* do this anyway, in case the following fails */

	ARGBEGIN{
	case 'f':
		fontname=ARGF();
		if(fontname==0) goto Usage;
		setface(ARGF());
		break;
	case 'b':
		bgname=ARGF();
		if(bgname==0) goto Usage;
		setbg(bgname);
		break;
	default:
	Usage:
		fprint(2, "Usage: %s [-f font] [-b background]\n", cmdname);
		exits("bad font");
	}ARGEND

	chan = display->windows->chan;		/* set the color model */

	black = allocimage(display, Rect(0,0,1,1), chan, 1, DBlack);
	red = allocimage(display, Rect(0,0,1,1), chan, 1, DRed);
	blue = allocimage(display, Rect(0,0,1,1), chan, 1, DBlue);
	paleyellow=allocimage(display, Rect(0, 0, 1, 1), chan, 1, DPaleyellow);
	darkgreen=allocimage(display, Rect(0, 0, 1, 1), chan, 1, DDarkgreen);
	palegreen=allocimage(display, Rect(0, 0, 1, 1), chan, 1, DPalegreen);
	medgreen=allocimage(display, Rect(0, 0, 1, 1), chan, 1, DMedgreen);
	darkblue = allocimage(display, Rect(0,0,1,1), chan, 1, DDarkblue);
	darkgrey = allocimage(display, Rect(0,0,1,1), chan, 1, DGreygreen);
/*
	transparent = allocimage(display, Rect(0,0,1,1), chan, 1, DTransparent);
*/
	color = black;
	background = paleyellow;
	menucolor = palegreen;
	msgboxcolor=darkgreen;
	gridcolor=darkblue;

	cur = allocimage(display, Rect(0, 0, 16, 16), chan, 1, DTransparent);
	anchormark = allocimage(display, Rect(0,0,16,16), chan, 1, DTransparent);

	for(p.y=0;p.y!=16;p.y++) for(p.x=0;p.x!=16;p.x++){
		if(tcur[p.y]&(1<<p.x))
			line(cur, p, p, 0, 0, 0, blue, ZP);
		else
			line(cur, p, p, 0, 0, 0, background, ZP);
		if(anc[p.y]&(1<<p.x))
			line(anchormark, p, p, 0, 0, 0, medgreen, ZP);
		else
			line(anchormark, p, p, 0, 0, 0, background, ZP);
	}

	gravity=.13;
	scene=addhead();
	active=addhead();
	scoffs=Dpt(0., 0.);
	curpt=Dpt(0., 0.);
	eresized(0);

	for(;;) command();
}

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.