summaryrefslogtreecommitdiff
path: root/Xbit.h
blob: 0804b556b80ebaf4e787d42107660f491f9e7637 (plain)
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/*

    lunar - Simple X11 Lunar Lander

    Copyright (C) 2005  Ian Cowburn (ianc@noddybox.demon.co.uk)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    -------------------------------------------------------------------------

*/

#ifndef XBIT_H
#define XBIT_H "$Id$"


/*
    Version 2 of the Bitmap manipulation library for X

    Now supports :

        Multiple windows
        Pixmaps bigger than the window
	Mutiple pixmap buffers (upto a maxim of 256 per window)
	XImage print routines
        Better XImage support, defaulting to shared memory usage.

	IMPORTANT NOTES ON MIT-SHM SUPPORT :

		1. Only call CreateXImage() ONCE per window.

		2. If you wish resources to be freed properly on completion, it
		   is important that DestroyXImage() is called before exiting
		   with the window the XImage was created in relation to set
		   as the current window.

		3. Allow the user to toggle MIT-SHM from a switch, as if the
		   server supports it, but using it is failing for some other
		   reason, then your program will be unable to run.

*/
#include <X11/X.h>
#include <X11/Xlib.h>


/* Just as I'm a lazy typer
*/
typedef unsigned char	uchar;
typedef unsigned long	ulong;


/* Maximums for PutPlots()
*/
#define MAX_PUTPLOTS    4096


/* Types and constants
*/
#define MIN_ANG         0
#define MAX_ANG         23040

typedef enum
{
    XFUNCCONT,
    XFUNCIGNORE,
    XFUNCSTOP
} XFuncControl;

typedef struct
{
    int             x,y;
    unsigned short  w,h;
    int             lx,ly;      /* This field is 'private' */
    Pixmap          data;       /* This field is 'private' */
    Pixmap          mask;       /* This field is 'private' */
    Pixmap          save;       /* This field is 'private' */
} XSprite;

typedef enum
{
    XSPRSAVE,
    XSPRNOSAVE
} XSpriteControl;


typedef struct
{
    int             r,g,b;
} Colour;

typedef Colour      Color;


typedef enum
{
    XPRESS,
    XRELEASE
} XPressRelease;


typedef XFuncControl	(*XVoidCallback)(void);
typedef XFuncControl	(*XMoveCallBack)(Window w, int x, int y);
typedef XFuncControl	(*XButtonCallback)(Window w, XPressRelease mode,
					   int button, int x, int y);
typedef XFuncControl	(*XKeyCallback)(Window w, XPressRelease mode,
					XEvent *event);

typedef struct
{
    Window		w;
    XMoveCallBack	func;
} XWindowMoveCallBack;

typedef struct
{
    Window		w;
    XButtonCallback	func;
} XWindowButtonCallback;

typedef struct
{
    Window		w;
    XKeyCallback	func;
} XWindowKeyCallback;


/* XImage font defs
*/
typedef enum
{
    XI_FONT1,
    XI_FONT2
} XImageFont;


/* Portable sprite data definitions - allows sprite data and colormap data to
				      be read from a list of files, returning
				      an array of RGB triplets defining the
				      colormap, and array of pixels
				      corresponding to those colours and a
				      series of sprite images with converted 
				      pixel values.  This means you can use
				      data normally read in just for the
				      XSprite routines on any format of display
				      mechanism.
*/
#define SPRD_AT(spr,x,y)	(*(spr.data+(x)+((y)*(spr.w))))

typedef struct
{
    int			w,h;		/* Width, height */
    ulong 		*data;		/* Data */
} SpriteData;

typedef struct
{
    int			no_col;		/* No of colours used by sprites */
    ulong		pix[256];	/* Array of pixel values */
    int			no_spr;
    SpriteData		*spr;		/* Array of sprite data */
} SpriteDataSet;


/* Function Prototypes
*/

Window  OpenWin
        (
	int argc,
        char *argv[],
        char *title,
        int Win_X,
	int Win_Y,
	int Win_Width,
	int Win_Height,
        int Pix_Width,
	int Pix_Height,
        unsigned long event_mask,
        XSizeHints *hints,
        ulong *black,
	ulong *white 
        );

Window  OpenRootWin
        (
	ulong *black, ulong *white,
	int *w, int *h, int Pix_Width, int Pix_Height
        );

void    SetCurrentWin
        (
	Window w 
        );

XImage  *CreateXImage(void);

void	ClsXImage
        (
        XImage *img
        );

void	DestroyXImage
        (
	XImage *img
        );

XFontStruct 
        *XUseFont
        (
	const char *font_name
        );

void    XUseCursor
        (
	const char *bitmap_filename,
	const char *mask_filename,
        XColor fg,
	XColor bg
        );

void    SetAsBackdrop(void);

void    DisableDoubleBuffer(void);

void    DisablePixmap(void);

void    DisableShm(void);

void	EnableBuffers
	(
	int no,
	ulong clscol
	);

void    LoadBitmap
        (
	const char *fn,
        int x,
	int y,
        int resize
        );

Pixmap  GetBitmap
        (
	const char *fn,
        int *width,
	int *height,
	int *hot_x,
	int *hot_y
        );

/* These 2 are for manipulating your own XImage structures
*/
Pixmap  GetCurrentPixmap(void);
GC      GetCurrentGC(void);

void    Redraw
        (
	int off_x,
	int off_y
        );

void    DrawXImage
        (
	XImage *img
        );

/* Note that if this used with EnableBuffers() on, this will move to the next
   buffer
*/
void    Pageflip(void);

void    Resize
        (
	int pix_w,
	int pix_h
        );

void    XSetLineStyle
        (
	unsigned int line_width,
        int line_style,
	int cap_style,
	int join_style
        );

void    XUseFunction
        (
	int GC_function
        );

void    XCls
        (
	ulong colour
        );

void    XPlot
        (
	int x,
	int y,
	ulong colour
        );

void    XLine
        (
	int x1,
	int y1,
	int x2,
	int y2,
	ulong colour
        );

void    SetSplineThresh
        (
	int thresh
        );

void    XSpline
        (
	int x1,
	int y1,
	int x2,
	int y2,
	int x3,
	int y3,
	ulong colour
        );

void    XPrint
        (
	int x,
	int y,
        const char *string,
        ulong colour
        );

void    Xprintf
        (
	int x,
	int y,
        ulong colour,
        const char *fmt,
        ...
        );

void    XISetFont
        (
	XImageFont font_no
        );

void    XIprintf
        (
	XImage *img,
	int x,
	int y,
	int scale_x,
	int scale_y,
        ulong colour,
        const char *fmt,
        ...
        );

void    XBox
        (
	int x,
	int y,
	int w,
	int h,
	ulong colour
        );

void    XFillBox
        (
	int x,
	int y,
	int w,
	int h,
	ulong colour
        );

void    XCircle
        (
	int x,
	int y,
	int rx,
	int ry,
	int ang1,
	int ang2,
	ulong colour
        );

void    XFillCircle
        (
	int x,
	int y,
	int rx,
	int ry,
	int ang1,
	int ang2,
	ulong colour
        );

void    XStartPlots(void);

void    XAddPlot
        (
	int x,
	int y
        );

void    XPutPlots
        (
	ulong col
        );

void    XPutPlotsAsLines
        (
	ulong col
        );

void    XFillPoly
        (
	XPoint xp[],
        int no_points,
        int shape,
        ulong col
        );

void    XScroll
        (
	int dx,
	int dy
        );

void    XCopy
        (
	int srcx,
	int srcy,
        int w,
	int h,
        int destx,
	int desty
        );

void    XPut
        (
	Pixmap src,
        int srcx,
	int srcy,
        int w,
	int h,
        int destx,
	int desty
        );

void    XGet
        (
	Pixmap dest,
        int srcx,
	int srcy,
        int w,
	int h,
        int destx,
	int desty
        );

void    ScreenCopy(void);

Display *GetDisplay(void);

void    XFinished(void);

/* The following event routines expect mouse events to be set in the
   event mask */

void    XDoTillButtonPress
        (
	XVoidCallback func
        );

void    XDoMouse
        (
	XButtonCallback mouse_button,
	XMoveCallBack mouse_movement,
	XVoidCallback process
        );

void    XDoWindows
        (
        XWindowButtonCallback mouse_button[],
        XWindowMoveCallBack mouse_movement[],
        XWindowKeyCallback key_press[],
        XFuncControl  (*process) ()
        );


/* Sprite routines */
void    LoadSprite
        (
        const char *filename,
        XSprite *sprite,
	const XColor xc[256]
        );


void    XDrawSprites
        (
        XSprite *sprites[],
        int no,
        XSpriteControl control
        );

void    XEraseSprites
        (
        XSprite *sprites[],
        int no
        );

void    LoadColormap
        (
        const char *filename,
        XColor xc[256]
        );

#define AllocColors AllocColours
void    AllocColours
        (
        int no,
        ulong pixels[],
        const char *colname[]
        );

#define AllocColorsRGB AllocColoursRGB
void    AllocColoursRGB
        (
        int no,
        ulong pixels[],
        const Colour cols[]
        );

void	LoadSpriteDataSet
	(
  	const char *cmap_filename,
	const char *sprite_filenames[],
	SpriteDataSet *set
	);


/*

    File  Formats:

    NB: all ushorts are stored in network format.  See ntohs(3).

    Colormap:
        
        red.ushort      - Red component color 0
        green.ushort    - Red component color 0
        blue.ushort     - Red component color 0
        ...
        ...
        red.ushort      - Red component color 255
        green.ushort    - Red component color 255
        blue.ushort     - Red component color 255


    Sprite:

        "XbitSprite"    - Magic string (NULL terminated)
        width.ushort    - width of sprite
        height.ushort   - height of sprite
        byte.uchar      - Pixel value for (0,0)
        byte.uchar      - Pixel value for (1,0)
        ...
        ...
        byte.uchar      - Pixel value for (width-1,height-1)

*/

#endif

/* END OF FILE */