From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- include/draw.h | 549 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 549 insertions(+) create mode 100644 include/draw.h (limited to 'include/draw.h') diff --git a/include/draw.h b/include/draw.h new file mode 100644 index 00000000..2815653f --- /dev/null +++ b/include/draw.h @@ -0,0 +1,549 @@ +#pragma src "/usr/inferno/libdraw" + +#pragma varargck argpos _drawprint 2 + +typedef struct Cachefont Cachefont; +typedef struct Cacheinfo Cacheinfo; +typedef struct Cachesubf Cachesubf; +typedef struct Display Display; +typedef struct Font Font; +typedef struct Fontchar Fontchar; +typedef struct Image Image; +typedef struct Mouse Mouse; +typedef struct Point Point; +typedef struct Rectangle Rectangle; +typedef struct RGB RGB; +typedef struct Refreshq Refreshq; +typedef struct Screen Screen; +typedef struct Subfont Subfont; + +#pragma varargck type "R" Rectangle +#pragma varargck type "P" Point +extern int Rfmt(Fmt*); +extern int Pfmt(Fmt*); + +enum +{ + DOpaque = 0xFFFFFFFF, + DTransparent = 0x00000000, /* only useful for allocimage, memfillcolor */ + DBlack = 0x000000FF, + DWhite = 0xFFFFFFFF, + DRed = 0xFF0000FF, + DGreen = 0x00FF00FF, + DBlue = 0x0000FFFF, + DCyan = 0x00FFFFFF, + DMagenta = 0xFF00FFFF, + DYellow = 0xFFFF00FF, + DPaleyellow = 0xFFFFAAFF, + DDarkyellow = 0xEEEE9EFF, + DDarkgreen = 0x448844FF, + DPalegreen = 0xAAFFAAFF, + DMedgreen = 0x88CC88FF, + DDarkblue = 0x000055FF, + DPalebluegreen= 0xAAFFFFFF, + DPaleblue = 0x0000BBFF, + DBluegreen = 0x008888FF, + DGreygreen = 0x55AAAAFF, + DPalegreygreen = 0x9EEEEEFF, + DYellowgreen = 0x99994CFF, + DMedblue = 0x000099FF, + DGreyblue = 0x005DBBFF, + DPalegreyblue = 0x4993DDFF, + DPurpleblue = 0x8888CCFF, + + DNotacolor = 0xFFFFFF00, + DNofill = DNotacolor, + +}; + +enum +{ + Displaybufsize = 8000, + ICOSSCALE = 1024, + Borderwidth = 4, +}; + +enum +{ + /* refresh methods */ + Refbackup = 0, + Refnone = 1, + Refmesg = 2 +}; +#define NOREFRESH ((void*)-1) + +enum +{ + /* line ends */ + Endsquare = 0, + Enddisc = 1, + Endarrow = 2, + Endmask = 0x1F +}; + +#define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23)) + +/* + * image channel descriptors + */ +enum { + CRed = 0, + CGreen, + CBlue, + CGrey, + CAlpha, + CMap, + CIgnore, + NChan, +}; + +#define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15)) +#define CHAN1(a,b) __DC(a,b) +#define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d))) +#define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f))) +#define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h))) + +#define NBITS(c) ((c)&15) +#define TYPE(c) (((c)>>4)&15) + +enum { + GREY1 = CHAN1(CGrey, 1), + GREY2 = CHAN1(CGrey, 2), + GREY4 = CHAN1(CGrey, 4), + GREY8 = CHAN1(CGrey, 8), + CMAP8 = CHAN1(CMap, 8), + RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5), + RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5), + RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8), + RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8), + ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */ + XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8), +}; + +/* compositing operators */ + +typedef enum +{ + SinD = 1<<3, + DinS = 1<<2, + SoutD = 1<<1, + DoutS = 1 <<0, + + S = SinD|SoutD, + SoverD = SinD|SoutD|DoutS, + SatopD = SinD|DoutS, + SxorD = SoutD|DoutS, + + D = DinS|DoutS, + DoverS = DinS|DoutS|SoutD, + DatopS = DinS|SoutD, + DxorS = DoutS|SoutD, + + Clear = 0, + + Ncomp = 12, +} Drawop; + +extern char* chantostr(char*, ulong); +extern ulong strtochan(char*); +extern int chantodepth(ulong); + +struct Point +{ + int x; + int y; +}; + +struct Rectangle +{ + Point min; + Point max; +}; + +typedef void (*Reffn)(Image*, Rectangle, void*); + +struct Screen +{ + Display *display; /* display holding data */ + int id; /* id of system-held Screen */ + Image *image; /* unused; for reference only */ + Image *fill; /* color to paint behind windows */ +}; + +struct Refreshq +{ + Reffn reffn; + void *refptr; + Rectangle r; + Refreshq *next; +}; + +struct Display +{ + void* qlock; + int locking; /*program is using lockdisplay */ + int dirno; + void *datachan; + void *refchan; + void *ctlchan; + int imageid; + int local; + int depth; + ulong chan; + void (*error)(Display*, char*); + char *devdir; + char *windir; + char oldlabel[64]; + ulong dataqid; + Image *white; + Image *black; + Image *image; + Image *opaque; + Image *transparent; + uchar buf[Displaybufsize+1]; /* +1 for flush message */ + int bufsize; + uchar *bufp; + Font *defaultfont; + Subfont *defaultsubfont; + Image *windows; + void *limbo; + Refreshq *refhead; + Refreshq *reftail; +}; + +struct Image +{ + Display *display; /* display holding data */ + int id; /* id of system-held Image */ + Rectangle r; /* rectangle in data area, local coords */ + Rectangle clipr; /* clipping region */ + int depth; /* number of bits per pixel */ + ulong chan; + int repl; /* flag: data replicates to tile clipr */ + Screen *screen; /* 0 if not a window */ + Image *next; /* next in list of windows */ + Reffn reffn; + void *refptr; +}; + +struct RGB +{ + ulong red; + ulong green; + ulong blue; +}; + +/* + * Subfonts + * + * given char c, Subfont *f, Fontchar *i, and Point p, one says + * i = f->info+c; + * draw(b, Rect(p.x+i->left, p.y+i->top, + * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom), + * color, f->bits, Pt(i->x, i->top)); + * p.x += i->width; + * to draw characters in the specified color (itself an Image) in Image b. + */ + +struct Fontchar +{ + int x; /* left edge of bits */ + uchar top; /* first non-zero scan-line */ + uchar bottom; /* last non-zero scan-line + 1 */ + char left; /* offset of baseline */ + uchar width; /* width of baseline */ +}; + +struct Subfont +{ + char *name; + short n; /* number of chars in font */ + uchar height; /* height of image */ + char ascent; /* top of image to baseline */ + Fontchar *info; /* n+1 character descriptors */ + Image *bits; /* of font */ + int ref; +}; + +enum +{ + /* starting values */ + LOG2NFCACHE = 6, + NFCACHE = (1<>8)) +#define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16)) + +/* + * Compressed image file parameters + */ +#define NMATCH 3 /* shortest match possible */ +#define NRUN (NMATCH+31) /* longest match possible */ +#define NMEM 1024 /* window size */ +#define NDUMP 128 /* maximum length of dump */ +#define NCBLOCK 6000 /* size of compressed blocks */ +extern void _twiddlecompressed(uchar*, int); +extern int _compblocksize(Rectangle, int); + +/* XXX backwards helps; should go */ +extern ulong drawld2chan[]; +extern void drawsetdebug(int); + +/* + * Inferno interface + */ +extern Font* font_open(Display*, char*); +extern void font_close(Font*); + +/* + * Macros to convert between C and Limbo types + */ +#define IRECT(r) (*(Rectangle*)&(r)) +#define DRECT(r) (*(Draw_Rect*)&(r)) +#define IPOINT(p) (*(Point*)&(p)) +#define DPOINT(p) (*(Draw_Point*)&(p)) + +#define P2P(p1, p2) (p1).x = (p2).x, (p1).y = (p2).y +#define R2R(r1, r2) (r1).min.x = (r2).min.x, (r1).min.y = (r2).min.y,\ + (r1).max.x = (r2).max.x, (r1).max.y = (r2).max.y +extern Image* display_open(Display*, char*); -- cgit v1.2.3