diff options
author | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
commit | a9022b5972dc49d86f617a27940fafe9c4d0e7e7 (patch) | |
tree | 61405aa4ade91ed1057f863ddf118ceb38e14f8e /gfx.h |
Initial import of (very old) vidoom sources.
Diffstat (limited to 'gfx.h')
-rw-r--r-- | gfx.h | 319 |
1 files changed, 319 insertions, 0 deletions
@@ -0,0 +1,319 @@ +/* + + 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 VIDOOM_GFX_H + +#define VIDOOM_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 + +/* The following aren't required by viDOOM (but can be used) +*/ +#define GFX_MSWHEELUP 0x08 +#define GFX_MSWHEELDOWN 0x10 + + +/* 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 */ |