vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

draw.h (15844B)


      1 
      2 typedef struct	Cachefont Cachefont;
      3 typedef struct	Cacheinfo Cacheinfo;
      4 typedef struct	Cachesubf Cachesubf;
      5 typedef struct	Display Display;
      6 typedef struct	Font Font;
      7 typedef struct	Fontchar Fontchar;
      8 typedef struct	Image Image;
      9 typedef struct	Mouse Mouse;
     10 typedef struct	Point Point;
     11 typedef struct	Rectangle Rectangle;
     12 typedef struct	RGB RGB;
     13 typedef struct	Screen Screen;
     14 typedef struct	Subfont Subfont;
     15 
     16 
     17 extern	int	Rfmt(Fmt*);
     18 extern	int	Pfmt(Fmt*);
     19 
     20 enum
     21 {
     22 	DOpaque		= 0xFFFFFFFF,
     23 	DTransparent	= 0x00000000,		/* only useful for allocimage, memfillcolor */
     24 	DBlack		= 0x000000FF,
     25 	DWhite		= 0xFFFFFFFF,
     26 	DRed		= 0xFF0000FF,
     27 	DGreen		= 0x00FF00FF,
     28 	DBlue		= 0x0000FFFF,
     29 	DCyan		= 0x00FFFFFF,
     30 	DMagenta		= 0xFF00FFFF,
     31 	DYellow		= 0xFFFF00FF,
     32 	DPaleyellow	= 0xFFFFAAFF,
     33 	DDarkyellow	= 0xEEEE9EFF,
     34 	DDarkgreen	= 0x448844FF,
     35 	DPalegreen	= 0xAAFFAAFF,
     36 	DMedgreen	= 0x88CC88FF,
     37 	DDarkblue	= 0x000055FF,
     38 	DPalebluegreen= 0xAAFFFFFF,
     39 	DPaleblue		= 0x0000BBFF,
     40 	DBluegreen	= 0x008888FF,
     41 	DGreygreen	= 0x55AAAAFF,
     42 	DPalegreygreen	= 0x9EEEEEFF,
     43 	DYellowgreen	= 0x99994CFF,
     44 	DMedblue		= 0x000099FF,
     45 	DGreyblue	= 0x005DBBFF,
     46 	DPalegreyblue	= 0x4993DDFF,
     47 	DPurpleblue	= 0x8888CCFF,
     48 
     49 	DNotacolor	= 0xFFFFFF00,
     50 	DNofill		= DNotacolor,
     51 	
     52 };
     53 
     54 enum
     55 {
     56 	Displaybufsize	= 8000,
     57 	ICOSSCALE	= 1024,
     58 	Borderwidth =	4,
     59 };
     60 
     61 enum
     62 {
     63 	/* refresh methods */
     64 	Refbackup	= 0,
     65 	Refnone		= 1,
     66 	Refmesg		= 2
     67 };
     68 #define	NOREFRESH	((void*)-1)
     69 
     70 enum
     71 {
     72 	/* line ends */
     73 	Endsquare	= 0,
     74 	Enddisc		= 1,
     75 	Endarrow	= 2,
     76 	Endmask		= 0x1F
     77 };
     78 
     79 #define	ARROW(a, b, c)	(Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
     80 
     81 typedef enum
     82 {
     83 	/* Porter-Duff compositing operators */
     84 	Clear	= 0,
     85 
     86 	SinD	= 8,
     87 	DinS	= 4,
     88 	SoutD	= 2,
     89 	DoutS	= 1,
     90 
     91 	S		= SinD|SoutD,
     92 	SoverD	= SinD|SoutD|DoutS,
     93 	SatopD	= SinD|DoutS,
     94 	SxorD	= SoutD|DoutS,
     95 
     96 	D		= DinS|DoutS,
     97 	DoverS	= DinS|DoutS|SoutD,
     98 	DatopS	= DinS|SoutD,
     99 	DxorS	= DoutS|SoutD,	/* == SxorD */
    100 
    101 	Ncomp = 12,
    102 } Drawop;
    103 
    104 /*
    105  * image channel descriptors 
    106  */
    107 enum {
    108 	CRed = 0,
    109 	CGreen,
    110 	CBlue,
    111 	CGrey,
    112 	CAlpha,
    113 	CMap,
    114 	CIgnore,
    115 	NChan,
    116 };
    117 
    118 #define __DC(type, nbits)	((((type)&15)<<4)|((nbits)&15))
    119 #define CHAN1(a,b)	__DC(a,b)
    120 #define CHAN2(a,b,c,d)	(CHAN1((a),(b))<<8|__DC((c),(d)))
    121 #define CHAN3(a,b,c,d,e,f)	(CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
    122 #define CHAN4(a,b,c,d,e,f,g,h)	(CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
    123 
    124 #define NBITS(c) ((c)&15)
    125 #define TYPE(c) (((c)>>4)&15)
    126 
    127 enum {
    128 	GREY1	= CHAN1(CGrey, 1),
    129 	GREY2	= CHAN1(CGrey, 2),
    130 	GREY4	= CHAN1(CGrey, 4),
    131 	GREY8	= CHAN1(CGrey, 8),
    132 	CMAP8	= CHAN1(CMap, 8),
    133 	RGB15	= CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
    134 	RGB16	= CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
    135 	RGB24	= CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
    136 	RGBA32	= CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
    137 	ARGB32	= CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8),	/* stupid VGAs */
    138 	XRGB32	= CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
    139 	BGR24	= CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
    140 	ABGR32	= CHAN4(CAlpha, 8, CBlue, 8, CGreen, 8, CRed, 8),
    141 	XBGR32	= CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
    142 };
    143 
    144 extern	char*	chantostr(char*, ulong);
    145 extern	ulong	strtochan(char*);
    146 extern	int		chantodepth(ulong);
    147 
    148 struct	Point
    149 {
    150 	int	x;
    151 	int	y;
    152 };
    153 
    154 struct Rectangle
    155 {
    156 	Point	min;
    157 	Point	max;
    158 };
    159 
    160 typedef void	(*Reffn)(Image*, Rectangle, void*);
    161 
    162 struct Screen
    163 {
    164 	int	id;		/* id of system-held Screen */
    165 	Image	*image;		/* unused; for reference only */
    166 	Image	*fill;		/* color to paint behind windows */
    167 };
    168 
    169 struct Display
    170 {
    171 	int		locking;	/*program is using lockdisplay */
    172 	int		dirno;
    173 	int		fd;
    174 	int		reffd;
    175 	int		ctlfd;
    176 	int		imageid;
    177 	int		local;
    178 	void		(*error)(Display*, char*);
    179 	char		*devdir;
    180 	char		*windir;
    181 	char		oldlabel[64];
    182 	ulong		dataqid;
    183 	Image		*white;
    184 	Image		*black;
    185 	Image		*opaque;
    186 	Image		*transparent;
    187 	Image		*image;
    188 	uchar		*buf;
    189 	int		bufsize;
    190 	uchar		*bufp;
    191 	Font		*defaultfont;
    192 	Subfont		*defaultsubfont;
    193 	Image		*windows;
    194 	Image		*screenimage;
    195 	int		_isnewdisplay;
    196 };
    197 
    198 struct Image
    199 {
    200 	Display		*display;	/* display holding data */
    201 	int		id;		/* id of system-held Image */
    202 	Rectangle	r;		/* rectangle in data area, local coords */
    203 	Rectangle 	clipr;		/* clipping region */
    204 	int		depth;		/* number of bits per pixel */
    205 	ulong		chan;
    206 	int		repl;		/* flag: data replicates to tile clipr */
    207 	Screen		*screen;	/* 0 if not a window */
    208 	Image		*next;	/* next in list of windows */
    209 };
    210 
    211 struct RGB
    212 {
    213 	ulong	red;
    214 	ulong	green;
    215 	ulong	blue;
    216 };
    217 
    218 /*
    219  * Subfonts
    220  *
    221  * given char c, Subfont *f, Fontchar *i, and Point p, one says
    222  *	i = f->info+c;
    223  *	draw(b, Rect(p.x+i->left, p.y+i->top,
    224  *		p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
    225  *		color, f->bits, Pt(i->x, i->top));
    226  *	p.x += i->width;
    227  * to draw characters in the specified color (itself an Image) in Image b.
    228  */
    229 
    230 struct	Fontchar
    231 {
    232 	int		x;		/* left edge of bits */
    233 	uchar		top;		/* first non-zero scan-line */
    234 	uchar		bottom;		/* last non-zero scan-line + 1 */
    235 	char		left;		/* offset of baseline */
    236 	uchar		width;		/* width of baseline */
    237 };
    238 
    239 struct	Subfont
    240 {
    241 	char		*name;
    242 	short		n;		/* number of chars in font */
    243 	uchar		height;		/* height of image */
    244 	char		ascent;		/* top of image to baseline */
    245 	Fontchar 	*info;		/* n+1 character descriptors */
    246 	Image		*bits;		/* of font */
    247 	int		ref;
    248 };
    249 
    250 enum
    251 {
    252 	/* starting values */
    253 	LOG2NFCACHE =	6,
    254 	NFCACHE =	(1<<LOG2NFCACHE),	/* #chars cached */
    255 	NFLOOK =	5,			/* #chars to scan in cache */
    256 	NFSUBF =	2,			/* #subfonts to cache */
    257 	/* max value */
    258 	MAXFCACHE =	1024+NFLOOK,		/* upper limit */
    259 	MAXSUBF =	50,			/* generous upper limit */
    260 	/* deltas */
    261 	DSUBF = 	4,
    262 	/* expiry ages */
    263 	SUBFAGE	=	10000,
    264 	CACHEAGE =	10000
    265 };
    266 
    267 struct Cachefont
    268 {
    269 	Rune		min;	/* lowest rune value to be taken from subfont */
    270 	Rune		max;	/* highest rune value+1 to be taken from subfont */
    271 	int		offset;	/* position in subfont of character at min */
    272 	char		*name;			/* stored in font */
    273 	char		*subfontname;		/* to access subfont */
    274 };
    275 
    276 struct Cacheinfo
    277 {
    278 	ushort		x;		/* left edge of bits */
    279 	uchar		width;		/* width of baseline */
    280 	schar		left;		/* offset of baseline */
    281 	Rune		value;	/* value of character at this slot in cache */
    282 	ushort		age;
    283 };
    284 
    285 struct Cachesubf
    286 {
    287 	ulong		age;	/* for replacement */
    288 	Cachefont	*cf;	/* font info that owns us */
    289 	Subfont		*f;	/* attached subfont */
    290 };
    291 
    292 struct Font
    293 {
    294 	char		*name;
    295 	Display		*display;
    296 	short		height;	/* max height of image, interline spacing */
    297 	short		ascent;	/* top of image to baseline */
    298 	short		width;	/* widest so far; used in caching only */	
    299 	short		nsub;	/* number of subfonts */
    300 	ulong		age;	/* increasing counter; used for LRU */
    301 	int		maxdepth;	/* maximum depth of all loaded subfonts */
    302 	int		ncache;	/* size of cache */
    303 	int		nsubf;	/* size of subfont list */
    304 	Cacheinfo	*cache;
    305 	Cachesubf	*subf;
    306 	Cachefont	**sub;	/* as read from file */
    307 	Image		*cacheimage;
    308 };
    309 
    310 #define	Dx(r)	((r).max.x-(r).min.x)
    311 #define	Dy(r)	((r).max.y-(r).min.y)
    312 
    313 /*
    314  * One of a kind
    315  */
    316 extern int		mousescrollsize(int);
    317 
    318 /*
    319  * Image management
    320  */
    321 extern Image*	_allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
    322 extern Image*	allocimage(Display*, Rectangle, ulong, int, ulong);
    323 extern uchar*	bufimage(Display*, int);
    324 extern int	bytesperline(Rectangle, int);
    325 extern void	closedisplay(Display*);
    326 extern void	drawerror(Display*, char*);
    327 extern int	flushimage(Display*, int);
    328 extern int	freeimage(Image*);
    329 extern int	_freeimage1(Image*);
    330 extern int	geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
    331 extern int	initdraw(void(*)(Display*, char*), char*, char*);
    332 extern int	newwindow(char*);
    333 extern Display*	initdisplay(char*, char*, void(*)(Display*, char*));
    334 extern int	loadimage(Image*, Rectangle, uchar*, int);
    335 extern int	cloadimage(Image*, Rectangle, uchar*, int);
    336 extern int	getwindow(Display*, int);
    337 extern int	gengetwindow(Display*, char*, Image**, Screen**, int);
    338 extern Image* readimage(Display*, int, int);
    339 extern Image* creadimage(Display*, int, int);
    340 extern int	unloadimage(Image*, Rectangle, uchar*, int);
    341 extern int	wordsperline(Rectangle, int);
    342 extern int	writeimage(int, Image*, int);
    343 extern Image*	namedimage(Display*, char*);
    344 extern int	nameimage(Image*, char*, int);
    345 extern Image* allocimagemix(Display*, ulong, ulong);
    346 
    347 /*
    348  * Colors
    349  */
    350 extern	void	readcolmap(Display*, RGB*);
    351 extern	void	writecolmap(Display*, RGB*);
    352 extern	ulong	setalpha(ulong, uchar);
    353 
    354 /*
    355  * Windows
    356  */
    357 extern Screen*	allocscreen(Image*, Image*, int);
    358 extern Image*	_allocwindow(Image*, Screen*, Rectangle, int, ulong);
    359 extern Image*	allocwindow(Screen*, Rectangle, int, ulong);
    360 extern void	bottomnwindows(Image**, int);
    361 extern void	bottomwindow(Image*);
    362 extern int	freescreen(Screen*);
    363 extern Screen*	publicscreen(Display*, int, ulong);
    364 extern void	topnwindows(Image**, int);
    365 extern void	topwindow(Image*);
    366 extern int	originwindow(Image*, Point, Point);
    367 
    368 /*
    369  * Geometry
    370  */
    371 extern Point		Pt(int, int);
    372 extern Rectangle	Rect(int, int, int, int);
    373 extern Rectangle	Rpt(Point, Point);
    374 extern Point		addpt(Point, Point);
    375 extern Point		subpt(Point, Point);
    376 extern Point		divpt(Point, int);
    377 extern Point		mulpt(Point, int);
    378 extern int		eqpt(Point, Point);
    379 extern int		eqrect(Rectangle, Rectangle);
    380 extern Rectangle	insetrect(Rectangle, int);
    381 extern Rectangle	rectaddpt(Rectangle, Point);
    382 extern Rectangle	rectsubpt(Rectangle, Point);
    383 extern Rectangle	canonrect(Rectangle);
    384 extern int		rectXrect(Rectangle, Rectangle);
    385 extern int		rectinrect(Rectangle, Rectangle);
    386 extern void		combinerect(Rectangle*, Rectangle);
    387 extern int		rectclip(Rectangle*, Rectangle);
    388 extern int		ptinrect(Point, Rectangle);
    389 extern void		replclipr(Image*, int, Rectangle);
    390 extern int		drawreplxy(int, int, int);	/* used to be drawsetxy */
    391 extern Point	drawrepl(Rectangle, Point);
    392 extern int		rgb2cmap(int, int, int);
    393 extern int		cmap2rgb(int);
    394 extern int		cmap2rgba(int);
    395 extern void		icossin(int, int*, int*);
    396 extern void		icossin2(int, int, int*, int*);
    397 
    398 /*
    399  * Graphics
    400  */
    401 extern void	draw(Image*, Rectangle, Image*, Image*, Point);
    402 extern void	drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
    403 extern void	gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
    404 extern void	gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
    405 extern void	line(Image*, Point, Point, int, int, int, Image*, Point);
    406 extern void	lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
    407 extern void	poly(Image*, Point*, int, int, int, int, Image*, Point);
    408 extern void	polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
    409 extern void	fillpoly(Image*, Point*, int, int, Image*, Point);
    410 extern void	fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
    411 extern Point	string(Image*, Point, Image*, Point, Font*, char*);
    412 extern Point	stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
    413 extern Point	stringn(Image*, Point, Image*, Point, Font*, char*, int);
    414 extern Point	stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
    415 extern Point	runestring(Image*, Point, Image*, Point, Font*, Rune*);
    416 extern Point	runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
    417 extern Point	runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
    418 extern Point	runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
    419 extern Point	stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
    420 extern Point	stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
    421 extern Point	stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
    422 extern Point	stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
    423 extern Point	runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
    424 extern Point	runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
    425 extern Point	runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
    426 extern Point	runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
    427 extern Point	_string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
    428 extern Point	stringsubfont(Image*, Point, Image*, Subfont*, char*);
    429 extern int		bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
    430 extern int		bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
    431 extern int		bezspline(Image*, Point*, int, int, int, int, Image*, Point);
    432 extern int		bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
    433 extern int		bezsplinepts(Point*, int, Point**);
    434 extern int		fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
    435 extern int		fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
    436 extern int		fillbezspline(Image*, Point*, int, int, Image*, Point);
    437 extern int		fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
    438 extern void	ellipse(Image*, Point, int, int, int, Image*, Point);
    439 extern void	ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
    440 extern void	fillellipse(Image*, Point, int, int, Image*, Point);
    441 extern void	fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
    442 extern void	arc(Image*, Point, int, int, int, Image*, Point, int, int);
    443 extern void	arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
    444 extern void	fillarc(Image*, Point, int, int, Image*, Point, int, int);
    445 extern void	fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
    446 extern void	border(Image*, Rectangle, int, Image*, Point);
    447 extern void	borderop(Image*, Rectangle, int, Image*, Point, Drawop);
    448 
    449 /*
    450  * Font management
    451  */
    452 extern Font*	openfont(Display*, char*);
    453 extern Font*	buildfont(Display*, char*, char*);
    454 extern void	freefont(Font*);
    455 extern Font*	mkfont(Subfont*, Rune);
    456 extern int	cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
    457 extern void	agefont(Font*);
    458 extern Subfont*	allocsubfont(char*, int, int, int, Fontchar*, Image*);
    459 extern Subfont*	lookupsubfont(Display*, char*);
    460 extern void	installsubfont(char*, Subfont*);
    461 extern void	uninstallsubfont(Subfont*);
    462 extern void	freesubfont(Subfont*);
    463 extern Subfont*	readsubfont(Display*, char*, int, int);
    464 extern Subfont*	readsubfonti(Display*, char*, int, Image*, int);
    465 extern int	writesubfont(int, Subfont*);
    466 extern void	_unpackinfo(Fontchar*, uchar*, int);
    467 extern Point	stringsize(Font*, char*);
    468 extern int	stringwidth(Font*, char*);
    469 extern int	stringnwidth(Font*, char*, int);
    470 extern Point	runestringsize(Font*, Rune*);
    471 extern int	runestringwidth(Font*, Rune*);
    472 extern int	runestringnwidth(Font*, Rune*, int);
    473 extern Point	strsubfontwidth(Subfont*, char*);
    474 extern int	loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
    475 extern char*	subfontname(char*, char*, int);
    476 extern Subfont*	_getsubfont(Display*, char*);
    477 extern Subfont*	getdefont(Display*);
    478 extern void		lockdisplay(Display*);
    479 extern void	unlockdisplay(Display*);
    480 extern int		drawlsetrefresh(ulong, int, void*, void*);
    481 
    482 /*
    483  * Predefined 
    484  */
    485 extern	uchar	defontdata[];
    486 extern	int		sizeofdefont;
    487 extern	Point		ZP;
    488 extern	Rectangle	ZR;
    489 
    490 /*
    491  * Set up by initdraw()
    492  */
    493 extern	Font		*font;
    494 extern	int	_cursorfd;
    495 extern	int	_drawdebug;	/* set to 1 to see errors from flushimage */
    496 extern	void	_setdrawop(Display*, Drawop);
    497 
    498 #define	BGSHORT(p)		(((p)[0]<<0) | ((p)[1]<<8))
    499 #define	BGLONG(p)		((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
    500 #define	BPSHORT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
    501 #define	BPLONG(p, v)		(BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
    502 
    503 /*
    504  * Compressed image file parameters and helper routines
    505  */
    506 #define	NMATCH	3		/* shortest match possible */
    507 #define	NRUN	(NMATCH+31)	/* longest match possible */
    508 #define	NMEM	1024		/* window size */
    509 #define	NDUMP	128		/* maximum length of dump */
    510 #define	NCBLOCK	6000		/* size of compressed blocks */
    511 extern	void	_twiddlecompressed(uchar*, int);
    512 extern	int	_compblocksize(Rectangle, int);
    513 
    514 /* XXX backwards helps; should go */
    515 extern	ulong	drawld2chan[];
    516 extern	void		drawsetdebug(int);