| 1 |
schorsch |
2.9 |
/* RCSid $Id: driver.h,v 2.8 2003/08/20 10:00:09 schorsch Exp $ */
|
| 2 |
greg |
1.1 |
/*
|
| 3 |
|
|
* driver.h - header file for interactive device drivers.
|
| 4 |
greg |
2.4 |
*/
|
| 5 |
schorsch |
2.6 |
#ifndef _RAD_DRIVER_H_
|
| 6 |
|
|
#define _RAD_DRIVER_H_
|
| 7 |
schorsch |
2.8 |
|
| 8 |
|
|
#include "color.h"
|
| 9 |
|
|
|
| 10 |
schorsch |
2.6 |
#ifdef __cplusplus
|
| 11 |
|
|
extern "C" {
|
| 12 |
|
|
#endif
|
| 13 |
greg |
1.1 |
|
| 14 |
schorsch |
2.9 |
typedef struct driver *dr_initf_t(char *dname, char *id);
|
| 15 |
|
|
typedef int dr_getchf_t(void);
|
| 16 |
|
|
typedef void dr_newcolrf_t(int ndx, int r, int g, int b);
|
| 17 |
|
|
|
| 18 |
|
|
typedef void dr_closef_t(void);
|
| 19 |
|
|
typedef void dr_clearf_t(int, int);
|
| 20 |
|
|
typedef void dr_paintrf_t(COLOR col, int xmin, int ymin, int xmax, int ymax);
|
| 21 |
|
|
typedef int dr_getcurf_t(int*,int*);
|
| 22 |
|
|
typedef void dr_comoutf_t(char*);
|
| 23 |
|
|
typedef void dr_cominf_t(char*,char*);
|
| 24 |
|
|
typedef void dr_flushf_t(void);
|
| 25 |
|
|
|
| 26 |
greg |
1.1 |
struct driver { /* driver functions */
|
| 27 |
schorsch |
2.9 |
dr_closef_t *close; /* close device */
|
| 28 |
|
|
dr_clearf_t *clear; /* clear device */
|
| 29 |
|
|
dr_paintrf_t *paintr; /* paint rectangle */
|
| 30 |
|
|
dr_getcurf_t *getcur; /* get cursor position */
|
| 31 |
|
|
dr_comoutf_t *comout; /* command line output */
|
| 32 |
|
|
dr_cominf_t *comin; /* command line input */
|
| 33 |
|
|
dr_flushf_t *flush; /* flush output */
|
| 34 |
greg |
1.4 |
double pixaspect; /* pixel aspect ratio */
|
| 35 |
greg |
1.1 |
int xsiz, ysiz; /* device size */
|
| 36 |
|
|
int inpready; /* input ready on device */
|
| 37 |
|
|
};
|
| 38 |
greg |
1.3 |
/* magic numbers for verification */
|
| 39 |
|
|
#define COM_SENDM 0x6f37
|
| 40 |
|
|
#define COM_RECVM 0x51da
|
| 41 |
greg |
1.1 |
/* stream commands */
|
| 42 |
|
|
#define COM_CLEAR 0
|
| 43 |
|
|
#define COM_PAINTR 1
|
| 44 |
|
|
#define COM_GETCUR 2
|
| 45 |
|
|
#define COM_COMOUT 3
|
| 46 |
|
|
#define COM_COMIN 4
|
| 47 |
greg |
1.6 |
#define COM_FLUSH 5
|
| 48 |
|
|
#define NREQUESTS 6 /* number of valid requests */
|
| 49 |
greg |
1.1 |
|
| 50 |
greg |
1.4 |
extern struct device { /* interactive device */
|
| 51 |
greg |
1.1 |
char *name; /* device name */
|
| 52 |
|
|
char *descrip; /* description */
|
| 53 |
schorsch |
2.9 |
dr_initf_t *init; /* initialize device */
|
| 54 |
|
|
} devtable[]; /* supported devices */
|
| 55 |
greg |
1.1 |
|
| 56 |
greg |
1.8 |
extern char dev_default[]; /* default device name */
|
| 57 |
|
|
|
| 58 |
greg |
1.1 |
#define MB1 ('\n') /* mouse button 1 */
|
| 59 |
|
|
#define MB2 ('\r') /* mouse button 2 */
|
| 60 |
|
|
#define MB3 (' ') /* mouse button 3 */
|
| 61 |
|
|
#define ABORT ('C'-'@') /* abort key */
|
| 62 |
|
|
|
| 63 |
|
|
/*
|
| 64 |
schorsch |
2.9 |
* How to write an interactive display driver for rview.
|
| 65 |
|
|
* ----------------------------------------------------
|
| 66 |
|
|
*
|
| 67 |
|
|
* static struct driver dname_driver;
|
| 68 |
|
|
*
|
| 69 |
|
|
* extern dr_initf_t dname_init;
|
| 70 |
|
|
*
|
| 71 |
|
|
* extern struct driver *
|
| 72 |
|
|
* dname_init(
|
| 73 |
|
|
* char *name,
|
| 74 |
|
|
* char *id
|
| 75 |
|
|
* )
|
| 76 |
greg |
1.1 |
* {
|
| 77 |
|
|
* Initialize device and return pointer to driver
|
| 78 |
schorsch |
2.9 |
* dname_driver. Return NULL if an error occurred.
|
| 79 |
greg |
1.3 |
* The name string identifies the driver,
|
| 80 |
|
|
* and the id string identifies the client.
|
| 81 |
greg |
1.1 |
* A device can be open by at most one client.
|
| 82 |
gregl |
2.3 |
* Be verbose in error reports; call eputs().
|
| 83 |
|
|
* If device has its own error output, set erract.
|
| 84 |
schorsch |
2.9 |
* This function then needs to be inserted into the
|
| 85 |
|
|
* device table in devtable.c.
|
| 86 |
greg |
1.1 |
* }
|
| 87 |
schorsch |
2.9 |
*
|
| 88 |
|
|
*
|
| 89 |
|
|
* static dr_closef_t dname_close;
|
| 90 |
|
|
*
|
| 91 |
|
|
* dname_driver.close = dname_close;
|
| 92 |
|
|
*
|
| 93 |
|
|
* static void
|
| 94 |
|
|
* dname_close(void)
|
| 95 |
greg |
1.1 |
* {
|
| 96 |
greg |
1.2 |
* Close the device. Reset error vectors.
|
| 97 |
greg |
1.1 |
* }
|
| 98 |
schorsch |
2.9 |
*
|
| 99 |
|
|
*
|
| 100 |
|
|
* static dr_clearf_t dname_clear;
|
| 101 |
|
|
*
|
| 102 |
|
|
* dname_driver.clear = dname_clear;
|
| 103 |
|
|
*
|
| 104 |
|
|
* static void
|
| 105 |
|
|
* dname_clear(
|
| 106 |
|
|
* int xres,
|
| 107 |
|
|
* int yres;
|
| 108 |
|
|
* )
|
| 109 |
greg |
1.1 |
* {
|
| 110 |
greg |
1.2 |
* Clear the device for xres by yres output. This call will
|
| 111 |
greg |
1.1 |
* be made prior to any output.
|
| 112 |
|
|
* }
|
| 113 |
schorsch |
2.9 |
*
|
| 114 |
|
|
*
|
| 115 |
|
|
* static dr_paintrf_t dname_paintr;
|
| 116 |
|
|
*
|
| 117 |
|
|
* dname_driver.paintr = dname_paintr;
|
| 118 |
|
|
*
|
| 119 |
|
|
* static void
|
| 120 |
|
|
* dname_paintr(
|
| 121 |
|
|
* COLOR col,
|
| 122 |
|
|
* int xmin,
|
| 123 |
|
|
* int ymin,
|
| 124 |
|
|
* int xmax,
|
| 125 |
|
|
* int ymax
|
| 126 |
|
|
* )
|
| 127 |
greg |
1.1 |
* {
|
| 128 |
|
|
* Paint a half-open rectangle from (xmin,ymin) to (xmax,ymax)
|
| 129 |
greg |
1.6 |
* with the color col.
|
| 130 |
greg |
1.1 |
* }
|
| 131 |
schorsch |
2.9 |
*
|
| 132 |
|
|
*
|
| 133 |
|
|
* static dr_getcurf_t dname_getcur;
|
| 134 |
|
|
*
|
| 135 |
|
|
* dname_driver.getcur = dname_getcur;
|
| 136 |
|
|
*
|
| 137 |
|
|
* static int
|
| 138 |
|
|
* dname_getcur(
|
| 139 |
|
|
* int *xp,
|
| 140 |
|
|
* int *yp
|
| 141 |
|
|
* )
|
| 142 |
greg |
1.1 |
* {
|
| 143 |
|
|
* Get the cursor position entered by the user via mouse,
|
| 144 |
|
|
* joystick, etc. Return the key hit by the user (usually
|
| 145 |
|
|
* MB1 or MB2). Return ABORT to cancel.
|
| 146 |
|
|
* Can be NULL for devices without this capability.
|
| 147 |
|
|
* }
|
| 148 |
schorsch |
2.9 |
*
|
| 149 |
|
|
*
|
| 150 |
|
|
* static dr_comoutf_t dname_comout;
|
| 151 |
|
|
*
|
| 152 |
|
|
* dname_driver.comout = dname_comout;
|
| 153 |
|
|
*
|
| 154 |
|
|
* static void
|
| 155 |
|
|
* dname_comout(
|
| 156 |
|
|
* char *out
|
| 157 |
|
|
* )
|
| 158 |
greg |
1.1 |
* {
|
| 159 |
|
|
* Print the string out on the device command line. If the
|
| 160 |
|
|
* string ends with '\n', the message is considered complete,
|
| 161 |
|
|
* and the next call can erase it.
|
| 162 |
|
|
* }
|
| 163 |
schorsch |
2.9 |
*
|
| 164 |
|
|
*
|
| 165 |
|
|
* static dr_cominf_t dname_comin;
|
| 166 |
|
|
*
|
| 167 |
|
|
* dname_driver.comin = dname_comin;
|
| 168 |
|
|
*
|
| 169 |
|
|
* static void
|
| 170 |
|
|
* dname_comin(
|
| 171 |
|
|
* char *in,
|
| 172 |
|
|
* char *prompt
|
| 173 |
|
|
* )
|
| 174 |
greg |
1.1 |
* {
|
| 175 |
greg |
1.5 |
* Print a prompt then read an edited input command line
|
| 176 |
|
|
* assuming the in buffer is big enough. Unless prompt is NULL,
|
| 177 |
|
|
* the driver may substitute its own rview command. This is
|
| 178 |
|
|
* the most reliable way to repaint areas of the screen.
|
| 179 |
greg |
1.7 |
* If the user enters an unrecognized control character,
|
| 180 |
greg |
1.5 |
* terminate input and return the string with only that character.
|
| 181 |
|
|
* The input string should not contain a newline. The routines in
|
| 182 |
|
|
* editline.c may be useful. Comin must work in consort with comout.
|
| 183 |
greg |
1.6 |
* }
|
| 184 |
schorsch |
2.9 |
*
|
| 185 |
|
|
*
|
| 186 |
|
|
* static dr_flushf_t dname_flush;
|
| 187 |
|
|
*
|
| 188 |
|
|
* dname_driver.flush = dname_flush;
|
| 189 |
|
|
*
|
| 190 |
|
|
* static void
|
| 191 |
|
|
* dname_flush(void)
|
| 192 |
greg |
1.6 |
* {
|
| 193 |
|
|
* Flush output to the display. This is guaranteed to be called
|
| 194 |
|
|
* frequently enough to keep the display up to date.
|
| 195 |
|
|
* This is an ideal time to check for device input.
|
| 196 |
|
|
* This function can be NULL for devices that don't need it.
|
| 197 |
greg |
1.1 |
* }
|
| 198 |
schorsch |
2.9 |
*
|
| 199 |
|
|
*
|
| 200 |
|
|
* dname_driver.xsiz
|
| 201 |
|
|
* dname_driver.ysiz
|
| 202 |
|
|
*
|
| 203 |
greg |
1.1 |
* The maximum allowable x and y dimensions. If any
|
| 204 |
|
|
* size is allowable, these should be set to MAXRES.
|
| 205 |
schorsch |
2.9 |
*
|
| 206 |
|
|
*
|
| 207 |
|
|
* dname_driver.inpready
|
| 208 |
|
|
*
|
| 209 |
greg |
1.2 |
* This variable should be made positive asynchronously
|
| 210 |
|
|
* when characters are ready on the input. (Often easiest
|
| 211 |
|
|
* to check for input during calls to paintr.)
|
| 212 |
greg |
1.1 |
*/
|
| 213 |
greg |
2.4 |
|
| 214 |
|
|
/* defined in editline.c */
|
| 215 |
schorsch |
2.9 |
extern void editline(char *buf, dr_getchf_t *c_get, dr_comoutf_t *s_put);
|
| 216 |
greg |
2.4 |
extern void tocombuf(char *b, struct driver *d);
|
| 217 |
|
|
extern int fromcombuf(char *b, struct driver *d);
|
| 218 |
schorsch |
2.9 |
|
| 219 |
greg |
2.4 |
/* defined in devcomm.c */
|
| 220 |
schorsch |
2.9 |
extern dr_initf_t slave_init; /* XXX should probably be in a seperate file */
|
| 221 |
greg |
2.4 |
extern struct driver *comm_init(char *dname, char *id);
|
| 222 |
schorsch |
2.9 |
|
| 223 |
greg |
2.4 |
/* defined in colortab.c */
|
| 224 |
|
|
extern int new_ctab(int ncolors);
|
| 225 |
schorsch |
2.9 |
extern int get_pixel(COLOR col, dr_newcolrf_t *newcolr);
|
| 226 |
greg |
2.4 |
extern void make_gmap(double gam);
|
| 227 |
|
|
extern void set_cmap(BYTE *rmap, BYTE *gmap, BYTE *bmap);
|
| 228 |
|
|
extern void map_color(BYTE rgb[3], COLOR col);
|
| 229 |
|
|
|
| 230 |
schorsch |
2.6 |
|
| 231 |
|
|
#ifdef __cplusplus
|
| 232 |
|
|
}
|
| 233 |
greg |
2.4 |
#endif
|
| 234 |
schorsch |
2.6 |
#endif /* _RAD_DRIVER_H_ */
|
| 235 |
|
|
|