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
|
/*
viDOOM - level editor for DOOM
Copyright (C) 2000 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
-------------------------------------------------------------------------
Provides a skin of graphics and input functions (in case of future
ports).
Assumes these features:
- A true, or hicolor, display
- A Fixed font
- Default origin is in the top left of the display, with X positve
along and Y positive down
- A buffered display. The screen contents should not change until
GFX_redraw() is called. If not honoured viDOOM should still work up
to a point, but it's use of the XOR mode may not be apparent to the
user.
$Id$
*/
#ifndef _GFX_H
#define _GFX_H
/* Opaque type to define a bitmap object and the public creator type, along
with the picklist data providers. Note that the bitmap object is assumed
to have a maximum of 256 unique colours.
*/
typedef void *GFX_IMAGE;
#define MAX_GFXBM_W 256
#define MAX_GFXBM_H 256
typedef struct
{
int w; /* Width */
int h; /* Height */
int pal[256]; /* Palette */
unsigned char *data; /* Accessed as data+(x)+(y)*(width) */
} GFX_BITMAP;
/* Key press structure
*/
typedef struct
{
int type; /* Event type (for GFX_await_input()) */
int shift; /* Is shift pressed? */
int ctrl; /* Is control pressed? */
int alt; /* Is ALT pressed? */
char ascii; /* ASCII code for the char. If zero ... */
int code; /* ... this holds a special code defined below */
} GFXKey;
/* Special non-ASCII keys that can be returned
*/
#define GFX_ASCII 0 /* Not a special key - just ASCII */
#define GFX_F1 1001
#define GFX_F2 1002
#define GFX_F3 1003
#define GFX_F4 1004
#define GFX_F5 1005
#define GFX_F6 1006
#define GFX_F7 1007
#define GFX_F8 1008
#define GFX_F9 1009
#define GFX_F10 1010
#define GFX_F11 1011
#define GFX_F12 1012
#define GFX_ESC 1021
#define GFX_INSERT 1022
#define GFX_HOME 1023
#define GFX_PGUP 1024
#define GFX_DELETE 1025
#define GFX_END 1026
#define GFX_PGDN 1027
#define GFX_UP 1028
#define GFX_DOWN 1029
#define GFX_LEFT 1030
#define GFX_RIGHT 1031
#define GFX_ENTER 1032
#define GFX_BACKSPACE 1033
#define GFX_TAB 1034
/* Mouse buttons
*/
#define GFX_BUTLEFT 0x01
#define GFX_BUTRIGHT 0x02
#define GFX_BUTMIDDLE 0x04
/* Event structs for GFX_await_input().
*/
#define GFX_KEY_EVENT 1 /* Key pressed */
#define GFX_MOUSE_EVENT 2 /* Mouse button pressed or mouse moved */
typedef struct GFXMouse
{
int type; /* Event type (for GFX_await_input()) */
int shift; /* Is shift pressed? */
int ctrl; /* Is control pressed? */
int alt; /* Is ALT pressed? */
int x; /* Mouse X co-ord */
int y; /* Mouse X co-ord */
int b; /* Mouse button mask */
} GFXMouse;
typedef union GFXEvent
{
int type;
GFXKey key;
GFXMouse mouse;
} GFXEvent;
/* Assume an intensity of 0-255 for each RGB component. The library assumes
that colours are represented as an RGB triplet in that order.
*/
#define V_RGB(r,g,b) ((r)<<16|(g)<<8|(b))
#define BLACK 0x000000
#define WHITE 0xffffff
#define RED 0xff0000
#define GREEN 0x00ff00
#define BLUE 0x0000ff
#define GREY(l) V_RGB(l,l,l)
/* Initialise graphics. This is pretty much called the first thing called.
After calling this it must be that the following functions at least are
operational:
GFX_close()
GFX_open()
GFX_exit()
GFX_create_image()
The platform GFX driver can assume no drawing primitives are called till
the screen is opended.
*/
void GFX_init(void);
/* Closedown for clean, non-error exits. See GFX_exit() for error exits
*/
void GFX_close(void);
/* Create a GFX_IMAGE for the passed GFX_BITMAP. Returns NULL on failure.
*/
GFX_IMAGE GFX_create_image(GFX_BITMAP *bm);
/* Destory a bitmap
*/
void GFX_destroy_image(GFX_IMAGE img);
/* Draw an image
*/
void GFX_draw_image(GFX_IMAGE i,int x,int y);
/* Fill the screen with an image. Not really crucial as it's just used for
the splash screen. If it cannot be honoured properly just drawing the
GFX_IMAGE centred in the screen should be adequate
*/
void GFX_fill_screen(GFX_IMAGE i);
/* Open a screen/window/whatever. Expected to be true colour, or an
approximation of. Should exit cleanly on failure.
*/
void GFX_open(int width, int height);
/* Clear the screen to a colour
*/
void GFX_clear(int col);
/* It is assumed by viDOOM that what has been drawn will NOT appear on screen
till this is called.
*/
void GFX_redraw(void);
/* Draw a line
*/
void GFX_line(int x1, int y1, int x2, int y2, int col);
/* Plot a point
*/
void GFX_plot(int x, int y, int col);
/* Draw a circle (and filled version)
*/
void GFX_circle(int x, int y, int radius, int col);
void GFX_fcircle(int x, int y, int radius, int col);
/* Draw a rectangle (and filled version). Note that zero and negative width
and heights must be allowed.
*/
void GFX_rect(int x, int y, int w, int h, int col);
void GFX_frect(int x, int y, int w, int h, int col);
/* Sets and clears XOR mode (used for rubber bands, etc).
*/
void GFX_set_XOR_mode(void);
void GFX_clear_XOR_mode(void);
/* printf() text at x,y. The baseline is assumed to be the top left corner of
the box enclosing the text and text is assumed to be transparent
*/
void GFX_print(int x, int y, int col, char *fmt, ...);
/* Return the dimension of the (fixed width!) font used for printing
*/
int GFX_fh(void);
int GFX_fw(void);
/* Return the number of mouse buttons. Should be at least 2.
*/
int GFX_mouse_buttons(void);
/* Sample the current state of the mouse. Return is the button mask. If X or
Y is NULL that position is not returned.
*/
int GFX_mouse(int *x, int *y);
/* Wait for a key to be pressed. key can be NULL if you're not interested in
the key.
*/
void GFX_waitkey(GFXKey *key);
/* Check for a key to be pressed. Returns TRUE or FALSE accordingly and sets
the GFXKey struct up.
*/
int GFX_key(GFXKey *key);
/* If this platform is not event driven, this call should wait kill all keys
and mouse buttons have been released. On event driven ones this may clear
any outstanding input events.
*/
void GFX_bounce(void);
/* Await for any sort of input from the keyboard or mouse buttons. This is
included in the platform specific so that event driven environs (eg. X11)
can work naturally, while non-event driven environments (eg. DOS) can have
the busy polling loop here, rather than in the generic code.
*/
void GFX_await_input(GFXEvent *ev);
/* This works like the above call, but returns mouse movement events (as a
GFX_MOUSE_EVENT) as well.
*/
void GFX_await_input_full(GFXEvent *ev);
/* Tidy up the graphics (switch them off, release mem, etc), print the
supplied error message and then exit with the return code.
*/
void GFX_exit(int code,char *fmt,...);
/* This interface _really_ does not have to do anything. It is just on the
development system so that grabs could be made for the docs.
If you feel the urge though this should save a snap shot of the current
screen in the passed file.
*/
void GFX_save_screen(char *path);
#endif
/* END OF FILE */
|