Back to index

radiance  4R0+20100331
driver.h
Go to the documentation of this file.
00001 /* RCSid $Id: driver.h,v 2.9 2004/03/30 16:13:01 schorsch Exp $ */
00002 /*
00003  *  driver.h - header file for interactive device drivers.
00004  */
00005 #ifndef _RAD_DRIVER_H_
00006 #define _RAD_DRIVER_H_
00007 
00008 #include "color.h"
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 typedef struct driver *dr_initf_t(char *dname, char *id);
00015 typedef int dr_getchf_t(void);
00016 typedef void dr_newcolrf_t(int ndx, int r, int g, int b);
00017 
00018 typedef void dr_closef_t(void);
00019 typedef void dr_clearf_t(int, int);
00020 typedef void dr_paintrf_t(COLOR col, int xmin, int ymin, int xmax, int ymax);
00021 typedef int  dr_getcurf_t(int*,int*);
00022 typedef void dr_comoutf_t(char*);
00023 typedef void dr_cominf_t(char*,char*);
00024 typedef void dr_flushf_t(void);
00025 
00026 struct driver {                           /* driver functions */
00027        dr_closef_t *close;                /* close device */
00028        dr_clearf_t *clear;                /* clear device */
00029        dr_paintrf_t *paintr;                     /* paint rectangle */
00030        dr_getcurf_t *getcur;                     /* get cursor position */
00031        dr_comoutf_t *comout;                     /* command line output */
00032        dr_cominf_t *comin;                /* command line input */
00033        dr_flushf_t *flush;                /* flush output */
00034        double  pixaspect;                 /* pixel aspect ratio */
00035        int  xsiz, ysiz;                   /* device size */
00036        int  inpready;                            /* input ready on device */
00037 };
00038                                    /* magic numbers for verification */
00039 #define COM_SENDM           0x6f37
00040 #define COM_RECVM           0x51da
00041                                    /* stream commands */
00042 #define COM_CLEAR           0
00043 #define COM_PAINTR          1
00044 #define COM_GETCUR          2
00045 #define COM_COMOUT          3
00046 #define COM_COMIN           4
00047 #define COM_FLUSH           5
00048 #define NREQUESTS           6      /* number of valid requests */
00049 
00050 extern struct device {                    /* interactive device */
00051        char  *name;                       /* device name */
00052        char  *descrip;                           /* description */
00053        dr_initf_t *init;           /* initialize device */
00054 }  devtable[];                     /* supported devices */
00055 
00056 extern char  dev_default[];        /* default device name */
00057 
00058 #define  MB1         ('\n')        /* mouse button 1 */
00059 #define  MB2         ('\r')        /* mouse button 2 */
00060 #define  MB3         (' ')         /* mouse button 3 */
00061 #define  ABORT              ('C'-'@')     /* abort key */
00062 
00063 /*
00064  *  How to write an interactive display driver for rview.
00065  *  ----------------------------------------------------
00066  *
00067  *  static struct driver dname_driver;
00068  *
00069  *  extern dr_initf_t dname_init;
00070  *
00071  *  extern struct driver *
00072  *  dname_init(
00073  *    char  *name,
00074  *    char  *id
00075  *  )
00076  *  {
00077  *     Initialize device and return pointer to driver
00078  *     dname_driver. Return NULL if an error occurred.
00079  *     The name string identifies the driver,
00080  *     and the id string identifies the client.
00081  *     A device can be open by at most one client.
00082  *     Be verbose in error reports; call eputs().
00083  *     If device has its own error output, set erract.
00084  *  This function then needs to be inserted into the
00085  *  device table in devtable.c.
00086  *  }
00087  *
00088  *
00089  *  static dr_closef_t dname_close;
00090  *  
00091  *  dname_driver.close = dname_close;
00092  *
00093  *  static void
00094  *  dname_close(void)
00095  *  {
00096  *     Close the device.  Reset error vectors.
00097  *  }
00098  *
00099  *
00100  *  static dr_clearf_t dname_clear;
00101  *  
00102  *  dname_driver.clear = dname_clear;
00103  *
00104  *  static void
00105  *  dname_clear(
00106  *    int  xres,
00107  *    int  yres;
00108  *  )
00109  *  {
00110  *     Clear the device for xres by yres output.  This call will
00111  *     be made prior to any output.
00112  *  }
00113  *
00114  *
00115  *  static dr_paintrf_t dname_paintr;
00116  *  
00117  *  dname_driver.paintr = dname_paintr;
00118  *
00119  *  static void
00120  *  dname_paintr(
00121  *    COLOR  col,
00122  *    int  xmin,
00123  *    int  ymin,
00124  *    int  xmax,
00125  *    int  ymax
00126  *  )
00127  *  {
00128  *     Paint a half-open rectangle from (xmin,ymin) to (xmax,ymax)
00129  *     with the color col.
00130  *  }
00131  *
00132  *
00133  *  static dr_getcurf_t dname_getcur;
00134  *  
00135  *  dname_driver.getcur = dname_getcur;
00136  *
00137  *  static int
00138  *  dname_getcur(
00139  *    int  *xp,
00140  *    int  *yp
00141  *  )
00142  *  {
00143  *     Get the cursor position entered by the user via mouse,
00144  *     joystick, etc.  Return the key hit by the user (usually
00145  *     MB1 or MB2).  Return ABORT to cancel.
00146  *     Can be NULL for devices without this capability.
00147  *  }
00148  *
00149  *
00150  *  static dr_comoutf_t dname_comout;
00151  *  
00152  *  dname_driver.comout = dname_comout;
00153  *
00154  *  static void
00155  *  dname_comout(
00156  *    char  *out
00157  *  )
00158  *  {
00159  *     Print the string out on the device command line.  If the
00160  *     string ends with '\n', the message is considered complete,
00161  *     and the next call can erase it.
00162  *  }
00163  *
00164  *
00165  *  static dr_cominf_t dname_comin;
00166  *  
00167  *  dname_driver.comin = dname_comin;
00168  *
00169  *  static void
00170  *  dname_comin(
00171  *    char  *in,
00172  *    char  *prompt
00173  *  )
00174  *  {
00175  *     Print a prompt then read an edited input command line
00176  *     assuming the in buffer is big enough.  Unless prompt is NULL,
00177  *     the driver may substitute its own rview command.  This is
00178  *     the most reliable way to repaint areas of the screen.
00179  *     If the user enters an unrecognized control character,
00180  *     terminate input and return the string with only that character.
00181  *     The input string should not contain a newline.  The routines in
00182  *     editline.c may be useful.  Comin must work in consort with comout.
00183  *  }
00184  *
00185  *
00186  *  static dr_flushf_t dname_flush;
00187  *  
00188  *  dname_driver.flush = dname_flush;
00189  *
00190  *  static void
00191  *  dname_flush(void)
00192  *  {
00193  *     Flush output to the display.  This is guaranteed to be called
00194  *     frequently enough to keep the display up to date.
00195  *     This is an ideal time to check for device input.
00196  *     This function can be NULL for devices that don't need it.
00197  *  }
00198  *
00199  *
00200  *  dname_driver.xsiz
00201  *  dname_driver.ysiz
00202  *
00203  *     The maximum allowable x and y dimensions.  If any
00204  *     size is allowable, these should be set to MAXRES.
00205  *
00206  *
00207  *  dname_driver.inpready
00208  *
00209  *     This variable should be made positive asynchronously
00210  *     when characters are ready on the input.  (Often easiest
00211  *     to check for input during calls to paintr.)
00212  */
00213 
00214                                    /* defined in editline.c */
00215 extern void   editline(char *buf, dr_getchf_t *c_get, dr_comoutf_t *s_put);
00216 extern void   tocombuf(char *b, struct driver *d);
00217 extern int    fromcombuf(char *b, struct driver *d);
00218 
00219                                    /* defined in devcomm.c */
00220 extern dr_initf_t slave_init; /* XXX should probably be in a seperate file */
00221 extern struct driver *comm_init(char *dname, char *id);
00222 
00223                                    /* defined in colortab.c */
00224 extern int    new_ctab(int ncolors);
00225 extern int    get_pixel(COLOR col, dr_newcolrf_t *newcolr);
00226 extern void   make_gmap(double gam);
00227 extern void   set_cmap(BYTE *rmap, BYTE *gmap, BYTE *bmap);
00228 extern void   map_color(BYTE rgb[3], COLOR col);
00229 
00230 
00231 #ifdef __cplusplus
00232 }
00233 #endif
00234 #endif /* _RAD_DRIVER_H_ */
00235