File: libg.h

package info (click to toggle)
wily 0.13.41-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,560 kB
  • ctags: 3,426
  • sloc: ansic: 25,364; perl: 580; makefile: 445; sh: 415; python: 30; exp: 17
file content (284 lines) | stat: -rw-r--r-- 7,514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* Copyright (c) 1992 AT&T - All rights reserved. */
#ifndef _LIBG_H
#define _LIBG_H

/*
 *  Like Plan9's libg.h, but suitable for inclusion on non-Plan9 machines
 */

enum{ EMAXMSG = 128+8192 };	/* max event size */

/*
 * Types
 */

typedef	struct	Bitmap		Bitmap;
typedef struct	Point		Point;
typedef struct	Rectangle 	Rectangle;
typedef struct	Cursor		Cursor;
typedef struct	Mouse		Mouse;
typedef struct	Menu		Menu;
typedef struct	Font		Font;
typedef struct	Fontchar	Fontchar;
typedef struct	Subfont		Subfont;
typedef struct	Cachesubf	Cachesubf;
typedef struct	Event		Event;
typedef struct	RGB		RGB;

struct	Point
{
	int	x;
	int	y;
};

struct Rectangle
{
	Point min;
	Point max;
};

struct	Bitmap
{
	Rectangle r;		/* rectangle in data area, local coords */
	Rectangle clipr;	/* clipping region */
	int	ldepth;
	int	id;		/* as known by the X server */
	Bitmap	*cache;		/* zero; distinguishes bitmap from layer */
	int	flag;		/* flag used by X implementation of libg */
};

struct	Mouse
{
	int		buttons; /* bit array: LMR=124 */
	Point		xy;
	unsigned long	msec;
};

struct	Cursor
{
	Point		offset;
	unsigned char	clr[2*16];
	unsigned char	set[2*16];
	int		id;	/* init to zero; used by library */
};

struct Menu
{
	char	**item;
	char	*(*gen)(int);
	int	lasthit;
};

/*
 * Subfonts:
 *
 * The "true width", cwidth, is the sum of the left and right
 * bearings of the character - the number of pixels actually
 * occupied by the glyph.  The width, supplied by the server and
 * stored in field "width", is the number of pixels to advance to
 * the right beyond the origin of the current character to the origin
 * of the next character.
 */

struct	Fontchar
{
	short		cwidth;		/* width of glyph */
	unsigned char	top;		/* first non-zero scan-line */
	unsigned char	bottom;		/* last non-zero scan-line */
	signed char	left;		/* offset of baseline */
	unsigned char	width;		/* advance to next char's origin */
};

struct	Subfont
{
	short		minrow;	/* first character row in font (for X subfonts) */
	short		mincol;	/* first character col in font (for X subfonts) */
	short		minchar; /* first char code in subfont */
	short		maxchar; /* last char code in subfont */
	short		width;	/* number of chars in row */
	short		n;	/* number of chars in font */
	unsigned char	height;	/* height of bitmap */
	char		ascent;	/* top of bitmap to baseline */
	Fontchar	*info;	/* n+1 character descriptors */
	int		id;	/* of font */
};

struct	Cachesubf
{
	Rune		min;	/* rune value of 0th char in subfont */
	Rune		max;	/* rune value+1 of last char in subfont */
	char		*name;
	Subfont		*f;	/* attached subfont */
};

struct Font
{
	char		*name;
	unsigned char	height;	/* max height of bitmap, interline spacing */
	char		ascent;	/* top of bitmap to baseline */
	char		width;	/* widest so far; used in caching only */
	char		ldepth;	/* of images */
	short		id;	/* of font */
	unsigned short		nsubf;	/* number of subfonts */
	Cachesubf	*subf;	/* as read from file */
};

struct	Event
{
	int		kbdc;
	Mouse		mouse;
	int		n;		/* number of characters in mesage */
	unsigned char	data[EMAXMSG];	/* message from an arbitrary file descriptor */
};

struct RGB
{
	unsigned long	red;
	unsigned long	green;
	unsigned long	blue;
};

/*
 * Codes for bitblt etc.
 *
 *	       D
 *	     0   1
 *         ---------
 *	 0 | 1 | 2 |
 *     S   |---|---|
 * 	 1 | 4 | 8 |
 *         ---------
 *
 *	Usually used as D|S; DorS is so tracebacks are readable.
 */
typedef
enum	Fcode
{
	Zero		= 0x0,
	DnorS		= 0x1,
	DandnotS	= 0x2,
	notS		= 0x3,
	notDandS	= 0x4,
	notD		= 0x5,
	DxorS		= 0x6,
	DnandS		= 0x7,
	DandS		= 0x8,
	DxnorS		= 0x9,
	D		= 0xA,
	DornotS		= 0xB,
	S		= 0xC,
	notDorS		= 0xD,
	DorS		= 0xE,
	F		= 0xF
} Fcode;

/*
 * Miscellany
 */

typedef void	 (*Errfunc)(char *);

extern Point	 add(Point, Point);
extern Point	 sub(Point, Point);
extern Point	 mul(Point, int);
extern Point	 divpt(Point, int);
extern Rectangle rsubp(Rectangle, Point);
extern Rectangle raddp(Rectangle, Point);
extern Rectangle inset(Rectangle, int);
extern Rectangle rmul(Rectangle, int);
extern Rectangle rdiv(Rectangle, int);
extern Rectangle rshift(Rectangle, int);
extern int	rectinrect(Rectangle , Rectangle );
extern Rectangle rcanon(Rectangle);
extern Bitmap*	 balloc(Rectangle, int);
extern void	 bfree(Bitmap*);
extern int	 rectclip(Rectangle*, Rectangle);
extern void	 xtbinit(Errfunc, char*, int*, char**, char**);
extern void	 bclose(void);
extern void	 berror(char*);
extern void	 bitblt(Bitmap*, Point, Bitmap*, Rectangle, Fcode);
extern void	 copymasked(Bitmap*, Point, Bitmap*, Bitmap*, Rectangle);
extern int	 bitbltclip(void*);
extern Subfont*	 getsubfont(char*);
extern Font	*rdfontfile(char*, int);
extern void	 ffree(Font*);
extern Font	*mkfont(Subfont*);
extern void	 subffree(Subfont*);
extern int	 cachechars(Font*, char**, void*, int, int*, unsigned short*);
extern Point	 string(Bitmap*, Point, Font*, char*, Fcode);
extern void	 segment(Bitmap*, Point, Point, int, Fcode);
extern void	 point(Bitmap*, Point, int, Fcode);
extern void	 arc(Bitmap*, Point, Point, Point, int, Fcode);
extern void	 circle(Bitmap*, Point, int, int, Fcode);
extern void	 disc(Bitmap*, Point, int, int, Fcode);
extern void	 ellipse(Bitmap*, Point, int, int, int, Fcode);
extern void	 polysegment(Bitmap *, int, Point *, int, Fcode);
extern long	 strwidth(Font*, char*);
extern Point	 strsize(Font*, char*);
extern long	 charwidth(Font*, Rune);
extern void	 texture(Bitmap*, Rectangle, Bitmap*, Fcode);
extern void	 wrbitmap(Bitmap*, int, int, unsigned char*);
extern void	 rdbitmap(Bitmap*, int, int, unsigned char*);
extern void	 wrbitmapfile(int, Bitmap*);
extern Bitmap*	 rdbitmapfile(int);
extern int	 ptinrect(Point, Rectangle);
extern int	 rectXrect(Rectangle, Rectangle);
extern int	 eqpt(Point, Point);
extern int	 eqrect(Rectangle, Rectangle);
extern void	 border(Bitmap*, Rectangle, int, Fcode);
extern void	 cursorswitch(Cursor*);
extern void	 cursorset(Point);
extern Rectangle bscreenrect(Rectangle*);
extern void	 bflush(void);
extern int	 clipline(Rectangle, Point*, Point*);
extern int	 clipr(Bitmap*, Rectangle);
extern int	 scrpix(int*,int*);

extern void	 einit(unsigned long);
extern unsigned long estart(unsigned long, int, int);
extern void estop(unsigned long);
extern unsigned long etimer(unsigned long, long);
extern void estoptimer(unsigned long);
extern unsigned long event(Event*);
extern unsigned long eread(unsigned long, Event*);
extern Mouse	 emouse(void);
extern int	 ekbd(void);
extern int	 ecanread(unsigned long);
extern int	 ecanmouse(void);
extern int	 ecankbd(void);
extern void	 ereshaped(Rectangle);	/* supplied by user */
extern void	 eflush(unsigned long);
extern int	 menuhit(int, Mouse*, Menu*);
extern Rectangle getrect(int, Mouse*);
extern unsigned long rgbpix(Bitmap*, RGB);
extern void	 rdcolmap(Bitmap*, RGB*);
extern void	 wrcolmap(Bitmap*, RGB*);

/* Extra functions supplied by libXg */
extern int	snarfswap(char*, int, char**);
char*		select_get(void);
void			select_put(char*);
extern int	scrollfwdbut(void);

enum{
	Emouse		= 1,
	Ekeyboard	= 2
};

extern Point	 Pt(int, int);
extern Rectangle Rect(int, int, int, int);
extern Rectangle Rpt(Point, Point);


#define	Dx(r)	((r).max.x-(r).min.x)
#define	Dy(r)	((r).max.y-(r).min.y)

extern	Bitmap	screen;
extern	Font	*font, *fixed;

#define	BGSHORT(p)		(((p)[0]<<0) | ((p)[1]<<8))
#define	BGLONG(p)		((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
#define	BPSHORT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
#define	BPLONG(p, v)		(BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))

#endif