home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / contrib / libgrx / docs / libgrx.doc < prev    next >
Encoding:
Text File  |  1993-12-06  |  79.7 KB  |  1,508 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                         LIBGRX
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                       A 16/256 color graphics library for DJGPP
  27.  
  28.                                     User's Manual
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.                                      Written by:
  43.                                      Csaba Biegl
  44.  
  45.  
  46.                                    August 10, 1992
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.             LIBGRX graphics library user's manual                                        2
  55.  
  56.  
  57.           Abstract
  58.  
  59.                   LIBGRX is a graphics library for DJGPP or Turbo C programs. (The Turbo C
  60.             version  was tested using TC++ 1.01) Currently  it supports VGA (32768, 256 or
  61.             16 colors),  EGA (16  colors), 8514/A (256  colors) and S3-based  (256 colors)
  62.             cards. Planned future improvements include support for Hercules cards as well.
  63.             It is upward compatible with the graphics library in DJGPP (the C part, no C++
  64.             classes).  It can use the same drivers as  the graphics library in DJGPP or it
  65.             can work  with a new driver format supporting programmable number of colors as
  66.             well.
  67.  
  68.  
  69.             Data types, function declarations
  70.  
  71.                   All  public data structures and  graphics primitives meant  for usage by
  72.             the  application program are declared/prototyped  in the header  files (in the
  73.             'include' sub-directory):
  74.  
  75.                   GRDRIVER.H        graphics driver format specifications
  76.                   MOUSEX.H          cursor, mouse and keyboard handling
  77.                   GRX.H             drawing-related structures and functions
  78.                   GRXFILE.H         file formats and file access routines
  79.                   GRXFONT.H         format of a font when loaded into memory
  80.  
  81.  
  82.             Setting video modes
  83.  
  84.                   Before a program  can do any  graphics drawing it  has to configure  the
  85.             display  adapter of the PC for the desired  graphics mode. It is done with the
  86.             'GrSetMode' function as follows:
  87.  
  88.                  #ifdef __cplusplus
  89.                    void  GrSetMode(int which,int width=0,int height=0,int colors=0);
  90.                  #else
  91.                    void  GrSetMode(int which,...);
  92.                  #endif
  93.  
  94.             The  'mode' parameter  can be  one  of the  following  constants, declared  in
  95.             "grx.h":
  96.  
  97.             typedef enum {
  98.                      GR_80_25_text,
  99.                      GR_default_text,
  100.                      GR_width_height_text,
  101.                      GR_biggest_text,
  102.                      GR_320_200_graphics,
  103.                      GR_default_graphics,
  104.                      GR_width_height_graphics,
  105.                      GR_biggest_noninterlaced_graphics,
  106.                      GR_biggest_graphics,
  107.                      GR_width_height_color_graphics
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.                  LIBGRX graphics library user's manual                                                         3
  116.  
  117.  
  118.           } GR_graphics_modes;
  119.  
  120.                   The 'GR_width_height_text' and 'GR_width_height_graphics'  modes require
  121.             the two optional size arguments, and the 'GR_width_height_color_graphics' mode
  122.             requires all  three optional arguments.  A call with  any other mode  does not
  123.             require any of the optional arguments.
  124.  
  125.             NOTE: the 'GR_width_height_color_graphics' mode  is a new mode supported  only
  126.             if:  (1)  you  have  a  new  format  graphics  driver  (see  the  accompanying
  127.             documentation in the file "DRIVERS.DOC"),  and (2) you have a  recent (version
  128.             1.06, dated after the middle  of April 1992) copy  of GO32 which knows how  to
  129.             deal with the new driver format.
  130.  
  131.             New  format graphics drivers operating  in the proper  environment (see above)
  132.             can provide a table of the supported text and graphics modes using:
  133.  
  134.                  void  GrGetDriverModes(GR_DRIVER_MODE_ENTRY **ttable,GR_DRIVER_MODE_ENTRY **gtable)
  135.  
  136.             The arguments  'ttable' and 'gtable'  should be addresses  of pointers  to the
  137.             'GR_DRIVER_MODE_ENTRY'  structure defined  in  the include  file "grdriver.h".
  138.             Upon  return  the  pointer  variables  will  point  to  two  arrays  of  these
  139.             structures,   one  for   the  text   modes,  the   other  for   graphics.  The
  140.             'GR_DRIVER_MODE_ENTRY' structure has the following fields:
  141.  
  142.             typedef struct {
  143.                      unsigned short  width;
  144.                      unsigned short  height;
  145.                      unsigned short  number_of_colors;
  146.                      unsigned char   BIOS_mode;
  147.                      unsigned char   special;
  148.                  } GR_DRIVER_MODE_ENTRY;
  149.  
  150.             The first four structure  members should be obvious,  but the 'special'  field
  151.             may  deserve some explanation. It is non-zero  if the driver does some special
  152.             "tricks" to put the card into the desired mode. An example might be the 43 row
  153.             EGA text mode:  for this first  the "standard" 80x25 text  mode is set  up and
  154.             then  the  character  generator is  re-loaded  with  a  smaller font.  If  the
  155.             'special' field is zero then the  driver simply invokes the INT 10  function 0
  156.             BIOS routine with the mode in the 'BIOS_mode' slot.
  157.  
  158.                   A user-defined  function can be  invoked every  time the  video mode  is
  159.             changed  (i.e. 'GrSetMode'  is  called). This  function  should not  take  any
  160.             parameters and its return value (if any) is  ignored. It can be installed (for
  161.             all subsequent 'GrSetMode' calls) with the:
  162.  
  163.             void    GrSetModeHook(void (*callback)(void));
  164.  
  165.             function. The current graphics  mode (one of the valid  'mode' argument values
  166.             for 'GrSetMode') can be obtained with the:
  167.  
  168.             int     GrCurrentMode(void);
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.             LIBGRX graphics library user's manual                                        4
  177.  
  178.  
  179.           function, while the  type of the installed graphics adapter  can be determined
  180.             with the
  181.  
  182.             int     GrAdapterType(void);
  183.  
  184.             function.  'GrAdapterType' returns  the  type of  the adapter  as  one of  the
  185.             following three symbolic constants (defined in "grx.h"):
  186.  
  187.             #define GR_VGA          0               /* VGA adapter */
  188.                  #define GR_EGA          1               /* EGA adapter */
  189.                  #define GR_HERC         2               /* Hercules mono adapter */
  190.                  #define GR_8514A        3               /* 8514/A or compatible */
  191.                  #define GR_S3           4               /* S3 graphics accelerator */
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.             LIBGRX graphics library user's manual                                        5
  200.  
  201.  
  202.           Graphics contexts
  203.  
  204.                   The library supports  a set  of drawing regions  called 'contexts'  (the
  205.             'GrContext'  structure). These  can be  in video memory  or in  system memory.
  206.             Contexts  in system  memory always  have the  same memory organization  as the
  207.             video memory. When  'GrSetMode' is called, a default context  is created which
  208.             maps to the whole  graphics screen. Contexts are described by  the 'GrContext'
  209.             data structure:
  210.  
  211.                  typedef struct _GR_context_ {
  212.                      char  far *gc_baseaddr;             /* base address of display memory */
  213.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  214.                      long  gc_planeoffset;               /* offset to next color plane */
  215.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  216.                      char  gc_onscreen;                  /* is it in video memory ? */
  217.                      char  gc_memflags;                  /* memory allocation flags */
  218.                      int   gc_xmax;                      /* max X coord (width  - 1) */
  219.                      int   gc_ymax;                      /* max Y coord (height - 1) */
  220.                      int   gc_xcliplo;                   /* low X clipping limit */
  221.                      int   gc_ycliplo;                   /* low Y clipping limit */
  222.                      int   gc_xcliphi;                   /* high X clipping limit */
  223.                      int   gc_ycliphi;                   /* high Y clipping limit */
  224.                      int   gc_usrxbase;                  /* user window min X coordinate */
  225.                      int   gc_usrybase;                  /* user window min Y coordinate */
  226.                      int   gc_usrwidth;                  /* user window width */
  227.                      int   gc_usrheight;                 /* user window height */
  228.                      int   gc_xoffset;                   /* X offset from root's base */
  229.                      int   gc_yoffset;                   /* Y offset from root's base */
  230.                      struct _GR_context_ *gc_root;       /* context which owns frame buf */
  231.                  } GrContext;
  232.  
  233.                   There  is  a  subtype  of   the  'GrContext'  structure.  The  structure
  234.             'GrVidRAM' contains only the  first slots of a  context describing the  memory
  235.             layout  of a  context. This  structure is  used as a  component of  other more
  236.             complex data structures in the library.
  237.  
  238.             typedef struct {
  239.                      char  far *gc_baseaddr;             /* base address of display memory */
  240.                      long  gc_frameaddr;                 /* upper left corner coordinate */
  241.                      long  gc_planeoffset;               /* offset to next color plane */
  242.                      int   gc_lineoffset;                /* offset to next scan line in bytes */
  243.                      char  gc_onscreen;                  /* is it in video memory ? */
  244.                      char  gc_memflags;                  /* memory allocation flags */
  245.                  } GrVidRAM;
  246.  
  247.                   The  following four functions return information about the layout of and
  248.             memory  occupied by  a graphics  context of  size 'width'  by 'height'  in the
  249.             current graphics mode (as set up by 'GrSetMode'):
  250.  
  251.             int     GrLineOffset(int width);
  252.                  int     GrNumPlanes(void);
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.                  LIBGRX graphics library user's manual                                                         6
  261.  
  262.  
  263.           long    GrPlaneSize(int w,int h);
  264.                  long    GrContextSize(int w,int h);
  265.  
  266.             'GrLineOffset'  always returns the offset between successive pixel rows of the
  267.             context in  bytes. 'GrNumPlanes'  returns the number  of bitmap planes  in the
  268.             current graphics mode. 'GrContextSize' calculates  the total amount of  memory
  269.             needed by a context, while 'GrPlaneSize' calculates the size of  a bitplane in
  270.             the context. The function:
  271.  
  272.             GrContext *GrCreateContext(int w,int h,char far *memory,GrContext *where);
  273.  
  274.             can be used to create a new context in system memory. The NULL pointer is also
  275.             accepted  as the value of the 'memory' and 'where' arguments, in this case the
  276.             library allocates the necessary amount of memory internally.
  277.  
  278.                   It  is  a general  convention in  the  library that  functions returning
  279.             pointers to any  LIBGRX specific data structure have a  last argument (most of
  280.             the time  named 'where'  in the  prototypes)  which can  be used  to pass  the
  281.             address of the data structure  which should be filled with the result. If this
  282.             'where' pointer  has the value of  NULL, then the library  allocates space for
  283.             the data structure internally. 
  284.  
  285.             The function:
  286.  
  287.             GrContext *GrCreateSubContext(int x1,int y1,int x2,int y2,GrContext *parent,GrContext *where);
  288.  
  289.             creates a  new sub-context which  maps to a part  of an existing  context. The
  290.             coordinate  arguments  ('x1' through  'y2')  are interpreted  relative  to the
  291.             parent context's limits. Pixel addressing is zero-based even  in sub-contexts,
  292.             i.e.  the address of the top  left pixel is (0,0) even  in a sub-context which
  293.             has been mapped onto the interior of its parent context.
  294.  
  295.                   Sub-contexts  can  be  resized,  but not  their  parents  (i.e. anything
  296.             returned by  'GrCreateContext' or set up  by 'GrSetMode' cannot be  resized --
  297.             because  this  could  lead to  irrecoverable  "loss"  of  drawing memory.  The
  298.             following function can be used for this purpose:
  299.  
  300.             void    GrResizeSubContext(GrContext *context,int x1,int y1,int x2,int y2);
  301.  
  302.                   The current context  structure is  stored in  a static  location in  the
  303.             library. (For efficiency reasons -- it  is used quite frequently, and this way
  304.             no  pointer  dereferencing  is  necessary.) The  context  stores  all relevant
  305.             information  about  the  video  organization, coordinate  limits,  etc...  The
  306.             current context can be set with the:
  307.  
  308.             void    GrSetContext(GrContext *context);
  309.  
  310.             function.  This function will reset  the current context  to the full graphics
  311.             screen if it is passed the NULL  pointer as argument. The value of the current
  312.             context can be saved into a 'GrContext' structure pointed to by 'where' using:
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.                  LIBGRX graphics library user's manual                                                         7
  321.  
  322.  
  323.           GrContext *GrSaveContext(GrContext *where);
  324.  
  325.             (Again, if  'where' is NULL, the library allocates the space.) Contexts can be
  326.             destroyed with: 
  327.  
  328.             void    GrDestroyContext(GrContext *context);
  329.  
  330.             This function  will free the  memory occupied  by the context  only if  it was
  331.             allocated originally by the library. The next three functions set up and query
  332.             the clipping limits associated with the context:
  333.  
  334.             void    GrSetClipBox(int x1,int y1,int x2,int y2);
  335.                  void    GrGetClipBox(int *x1p,int *y1p,int *x2p,int *y2p);
  336.                  void    GrResetClipBox(void);
  337.  
  338.             'GrResetClipBox' sets the  clipping limits to the limits of context. These are
  339.             the limits set  up initially  when a  context is  created. The  limits of  the
  340.             current context can be obtained using the following functions:
  341.  
  342.             int     GrMaxX(void);
  343.                  int     GrMaxY(void);
  344.                  int     GrSizeX(void);
  345.                  int     GrSizeY(void);
  346.  
  347.             The  'Max' functions  return the  biggest valid  coordinate, while  the 'Size'
  348.             functions return  a  value  one higher.  The  limits of  the  graphics  screen
  349.             (regardless of the current context) can be obtained with: 
  350.  
  351.             int     GrScreenX(void);
  352.                  int     GrScreenY(void);
  353.  
  354.  
  355.             Color management
  356.  
  357.                   The  library supports two models for color management. In the 'indirect'
  358.             (or  color table)  mode colors can  be allocated  with the  highest resolution
  359.             supported  by the  hardware (EGA:  2 bits,  VGA: 6  bits) with respect  to the
  360.             component color  intensities. In  the 'direct' or  RGB mode color  indices map
  361.             directly into  component color  intensities with non-overlapping  bitfields of
  362.             the color index representing  the component colors. The RGB mode  is supported
  363.             in 256 color and 32768 color VGA modes only (for 32768 colors this is the only
  364.             mode because of  the limitations of the VGA hardware with HiColor DAC). In RGB
  365.             mode the color index maps to component color intensities as follows:
  366.  
  367.                 256:    rrrgggbb          (3 bits for red and green, 2 for blue)
  368.                 32768:  xrrrrrgggggbbbbb  (5 bits for each component color)
  369.  
  370.                   The RGB mode is not supported in 16 color EGA and VGA modes as there are
  371.             too few available  colors to provide adequate  coverage. The advantage  of the
  372.             RGB  mode  is  faster   color  allocation  (no  table  lookup,   DAC  register
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.             LIBGRX graphics library user's manual                                        8
  381.  
  382.  
  383.           programming, etc...) its disadvantage is the relatively crude approximation of
  384.             the component color intensities.
  385.  
  386.                   After  the first 'GrSetMode' call  two colors are  always defined: black
  387.             and white. The indices of these two colors are returned by the functions:
  388.  
  389.             int     GrBlack(void);
  390.                  int     GrWhite(void);
  391.  
  392.             NOTE: unlike  the original DJGPP library,  LIBGRX does not  guarantee that the
  393.             white color
  394.             has the color index value of one. (GrBlack still returns 0). 
  395.  
  396.                   The  library supports  four  write modes:  write,  XOR, logical  OR  and
  397.             logical AND. These can be selected with OR-ing the color index with one of the
  398.             following constants declared in "grx.h":
  399.  
  400.             #ifdef __TURBOC__
  401.                  # define GrXOR          0x100           /* to "XOR" any color to the screen */
  402.                  # define GrOR           0x200           /* to "OR" to the screen */
  403.                  # define GrAND          0x300           /* to "AND" to the screen */
  404.                  #endif
  405.                  #ifdef __GNUC__                         /* changed for 16 bit colors */
  406.                  # define GrXOR          0x10000         /* to "XOR" any color to the screen */
  407.                  # define GrOR           0x20000         /* to "OR" to the screen */
  408.                  # define GrAND          0x30000         /* to "AND" to the screen */
  409.                  #endif
  410.                  #define GrWRITE         0               /* write color */
  411.                  #define GrNOCOLOR       (GrXOR | 0)     /* GrNOCOLOR is used for "no" color */
  412.  
  413.             NOTE: 'GrXOR'  was declared to be  "0x100" in the original  DJGPP library, but
  414.             its value had to be changed  in LIBGRX in anticipation of the 32768  color VGA
  415.             support.
  416.  
  417.             By convention, the no-op color is  obtained by combining color index 0 (black)
  418.             with  the  XOR operation.  This no-op  color has  been  defined in  "grx.h" as
  419.             'GrNOCOLOR'.
  420.  
  421.             The number of colors in the current graphics mode is returned by the:
  422.  
  423.             int     GrNumColors(void);
  424.  
  425.             function,  while the  number of  unused, available  color  can be  obtained by
  426.             calling:
  427.  
  428.             int     GrNumFreeColors(void);
  429.  
  430.             Colors can be allocated with the:
  431.  
  432.             int     GrAllocColor(int r,int g,int b);
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.             LIBGRX graphics library user's manual                                        9
  441.  
  442.  
  443.           function (component intensities can range from 0 to 255), or with the:
  444.  
  445.             int     GrAllocCell(void);
  446.  
  447.             function. In the second case the  component intensities of the returned  color
  448.             can be set with:
  449.  
  450.             void    GrSetColor(int color,int r,int g,int b);
  451.  
  452.             Both  'Alloc' functions  return 'GrNOCOLOR' if  there are no  more free colors
  453.             available. Additionally  'GrAllocCell'  always returns  'GrNOCOLOR'  when  the
  454.             color system is in RGB mode, as colors returned  by 'GrAllocCell' are meant to
  455.             be changed --  what is not  supposed to be  done in RGB  mode. Also note  that
  456.             'GrAllocColor' operates  much more efficiently in RGB  mode, and that it never
  457.             returns 'GrNOCOLOR' in this case.
  458.  
  459.             Color table entries can be freed (when not in RGB mode) by calling:
  460.  
  461.             void    GrFreeColor(int color);
  462.  
  463.             The component intensities of any color can be queried using the function:
  464.  
  465.             void    GrQueryColor(int c,int *r,int *g,int *b);
  466.  
  467.                   Initially  the color system is  in color table  (indirect) mode. (Except
  468.             for  the 32768 color VGA  modes which are  always in RGB mode.)  256 color VGA
  469.             modes can be put into the RGB mode by calling:
  470.  
  471.             void    GrSetRGBcolorMode(void);
  472.  
  473.             The  color system  can  be reset  (i.e.  put back  into  color table  mode  if
  474.             possible, all colors freed except for black and white) by calling:
  475.  
  476.             void    GrResetColors(void);
  477.  
  478.             The function:
  479.  
  480.             void    GrRefreshColors(void);
  481.  
  482.             reloads the currently  allocated color  values into the  video hardware.  This
  483.             function is not needed in typical applications, unless the  display adapter is
  484.             programmed directly by the application.
  485.  
  486.             Graphics primitives
  487.  
  488.                   The  screen, the current context or the  current clip box can be cleared
  489.             (i.e.set toadesired backgroundcolor)by usingoneof thefollowingthree functions:
  490.  
  491.             void    GrClearScreen(int bg);
  492.                  void    GrClearContext(int bg);
  493.                  void    GrClearClipBox(int bg);
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.             LIBGRX graphics library user's manual                                       10
  502.  
  503.  
  504.           The following line drawing graphics primitives are supported by the library:
  505.  
  506.             void    GrPlot(int x,int y,int c);
  507.                  void    GrLine(int x1,int y1,int x2,int y2,int c);
  508.                  void    GrHLine(int x1,int x2,int y,int c);
  509.                  void    GrVLine(int x,int y1,int y2,int c);
  510.                  void    GrBox(int x1,int y1,int x2,int y2,int c);
  511.                  void    GrCircle(int xc,int yc,int r,int c);
  512.                  void    GrEllipse(int xc,int yc,int xa,int ya,int c);
  513.                  void    GrCircleArc(int xc,int yc,int r,int start,int end,int c);
  514.                  void    GrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  515.                  void    GrPolyLine(int numpts,int points[][2],int c);
  516.                  void    GrPolygon(int numpts,int points[][2],int c);
  517.  
  518.                   All  primitives  operate  on  the  current  graphics context.  The  last
  519.             argument of these  functions is always the color index to use for the drawing.
  520.             The 'HLine' and  'VLine' primitives  are for drawing  horizontal and  vertical
  521.             lines. They  have been included in the library because they are more efficient
  522.             than the general line drawing provided by 'GrLine'. The ellipse primitives can
  523.             only draw  ellipses with their  major axis  parallel with  either the  X or  Y
  524.             coordinate axis. They take the half X and  Y axis length in the 'xa' and  'ya'
  525.             arguments.  The arc (circle and ellipse) drawing  functions take the start and
  526.             end  angles in  tenths of  degrees (i.e.  meaningful range:  0 ...  3600). The
  527.             angles  are interpreted counter-clockwise  starting from the  positive X axis.
  528.             The polyline and polygon primitives take  the address of an n by  2 coordinate
  529.             array. The X values should be stored in the elements with 0 second  index, and
  530.             the Y values in the elements with a second index value of 1. Coordinate arrays
  531.             passed  to the polygon primitives can either  contain or omit the closing edge
  532.             of the polygon -- the primitive will append it to the list if it is missing.
  533.  
  534.             The following filled primitives are available:
  535.  
  536.             void    GrFilledBox(int x1,int y1,int x2,int y2,int c);
  537.                  void    GrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  538.                  void    GrFilledCircle(int xc,int yc,int r,int c);
  539.                  void    GrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  540.                  void    GrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  541.                  void    GrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  542.                  void    GrFilledPolygon(int numpts,int points[][2],int c);
  543.                  void    GrFilledConvexPolygon(int numpts,int points[][2],int c);
  544.  
  545.                   Similarly to the line  drawing, all of  the above primitives operate  on
  546.             the current  graphics context. The 'GrFramedBox' primitive can be used to draw
  547.             motif-like shaded boxes and  "ordinary" framed boxes as well. The 'x1' through
  548.             'y2' coordinates specify the interior  of the box, the border is  outside this
  549.             area. The  primitive  uses five  different colors  for the  interior and  four
  550.             borders of the box which are specified in the 'GrFBoxColors' structure:
  551.  
  552.             typedef struct {
  553.                      int  fbx_intcolor;
  554.                      int  fbx_topcolor;
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.                  LIBGRX graphics library user's manual                                                       11
  563.  
  564.  
  565.               int  fbx_rightcolor;
  566.                      int  fbx_bottomcolor;
  567.                      int  fbx_leftcolor;
  568.                  } GrFBoxColors;
  569.  
  570.             The  'GrFilledConvexPolygon' primitive can be used to fill convex polygons. It
  571.             can  also  be used  to  fill some  concave  polygons whose  boundaries  do not
  572.             intersect any horizontal scan line more than twice. All other concave polygons
  573.             have  to  be  filled  with the  (somewhat  less  efficient)  'GrFilledPolygon'
  574.             primitive.  This primitive  can also  be used  to  fill several  disjoint non-
  575.             overlapping polygons in a single operation.
  576.  
  577.             The  current color value of  any pixel in the current  context can be obtained
  578.             with:
  579.  
  580.             int     GrPixel(int x,int y);
  581.  
  582.             Rectangular areas can be  transferred within a context or between  contexts by
  583.             calling:
  584.  
  585.             void    GrBitBlt(GrContext *dest,int x,int y,GrContext *source,int x1,int y1,int x2,int y2,int oper);
  586.  
  587.             The 'oper'  argument should be one  of supported color modes  (write, XOR, OR,
  588.             AND), it will control how the pixels from the source context are combined with
  589.             the pixels in the destination context. If either the source or the destination
  590.             context argument is the NULL pointer then the current context is used for that
  591.             argument.
  592.  
  593.  
  594.             Non-clipping graphics primitives
  595.  
  596.                   There  is a non-clipping version  of some of  the elementary primitives.
  597.             These are somewhat more efficient  than the regular versions. These are  to be
  598.             used only  in situations when it is absolutely certain that no drawing will be
  599.             performed  beyond the boundaries of the current context. Otherwise the program
  600.             will almost certainly crash! The reason for including these functions  is that
  601.             they are somewhat  more efficient  than the regular,  clipping versions.  ALSO
  602.             NOTE: These  function do not check  for conflicts with the  mouse cursor. (See
  603.             the explanation about  the mouse cursor handling later in  this document.) The
  604.             list of the supported non-clipping primitives:
  605.  
  606.             void    GrPlotNC(int x,int y,int c);
  607.                  void    GrLineNC(int x1,int y1,int x2,int y2,int c);
  608.                  void    GrHLineNC(int x1,int x2,int y,int c);
  609.                  void    GrVLineNC(int x,int y1,int y2,int c);
  610.                  void    GrBoxNC(int x1,int y1,int x2,int y2,int c);
  611.                  void    GrFilledBoxNC(int x1,int y1,int x2,int y2,int c);
  612.                  void    GrFramedBoxNC(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  613.                  void    GrBitBltNC(GrContext *dst,int x,int y,GrContext *src,int x1,int y1,int x2,int y2,int oper);
  614.                  int     GrPixelNC(int x,int y);
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.             LIBGRX graphics library user's manual                                       12
  623.  
  624.  
  625.           Customized line drawing
  626.  
  627.                   The basic  line drawing graphics primitives  described previously always
  628.             draw continuous lines which are one pixel wide. There is another group of line
  629.             drawing functions which can be used to draw wide and/or patterned lines. These
  630.             functions  have similar parameter passing  conventions as the  basic ones with
  631.             one  difference: instead of the color  value a pointer to  a structure of type
  632.             'GrLineOption' has to be passed to them. The definition  of the 'GrLineOption'
  633.             structure:
  634.  
  635.             typedef struct {
  636.                      int  lno_color;                     /* color used to draw line */
  637.                      int  lno_width;                     /* width of the line */
  638.                      int  lno_pattlen;                   /* length of the dash pattern */
  639.                      unsigned char *lno_dashpat;         /* draw/nodraw pattern */
  640.                  } GrLineOption;
  641.  
  642.             The  'lno_pattlen'  structure  element  should  be  equal  to  the  number  of
  643.             alternating draw  -- no draw section length values  in the array pointed to by
  644.             the 'lno_dashpat' element.  The dash pattern array is assumed  to begin with a
  645.             drawn section. If the  pattern length is  equal to zero  a continuous line  is
  646.             drawn. The available custom line drawing primitives:
  647.  
  648.           void    GrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  649.                  void    GrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  650.                  void    GrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  651.                  void    GrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  652.                  void    GrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  653.                  void    GrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  654.                  void    GrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  655.                  void    GrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  656.  
  657.  
  658.             Pattern filled graphics primitives
  659.  
  660.                   The library  also supports a pattern filled  version of the basic filled
  661.             primitives  described above.  These functions  have similar  parameter passing
  662.             conventions as the basic ones with  one difference: instead of the color value
  663.             a  pointer to  an union  of type  'GrPattern' has  to be  passed to  them. The
  664.             'GrPattern' union  can contain either a  bitmap or a pixmap  fill pattern. The
  665.             first  integer slot  in the  union determines  which type  it is.  Bitmap fill
  666.             patterns  are  rectangular  arrays of  bits,  each  set  bit representing  the
  667.             foreground  color of  the fill operation,  and each zero  bit representing the
  668.             background. Both the foreground and background colors can be combined with any
  669.             of  the   supported  logical  operations.   Bitmap  fill  patterns   have  one
  670.             restriction: their width must be  eight pixels. Pixmap fill patterns are  very
  671.             similar to contexts,  the data is  transferred to the  filled primitive  using
  672.             'BitBlt' operations. The relevant structure declarations (from "grx.h"):
  673.  
  674.             /*
  675.                   * BITMAP: a mode independent way to specify a fill pattern of two
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.                  LIBGRX graphics library user's manual                                                       13
  684.  
  685.  
  686.            *   colors. It is always 8 pixels wide (1 byte per scan line), its
  687.                   *   height is user-defined. SET THE TYPE FLAG TO ZERO!!!
  688.                   */
  689.                  typedef struct {
  690.                      int  bmp_ispixmap;                  /* type flag for pattern union */
  691.                      int  bmp_height;                    /* bitmap height */
  692.                      unsigned char *bmp_data;            /* pointer to the bit pattern */
  693.                      int  bmp_fgcolor;                   /* foreground color for fill */
  694.                      int  bmp_bgcolor;                   /* background color for fill */
  695.                      int  bmp_memflags;                  /* set if dynamically allocated */
  696.                  } GrBitmap;
  697.  
  698.                  /*
  699.                   * PIXMAP: a fill pattern stored in a layout identical to the video RAM
  700.                   *   for filling using 'bitblt'-s. It is mode dependent, typically one
  701.                   *   of the library functions is used to build it. KEEP THE TYPE FLAG
  702.                   *   NONZERO!!!
  703.                   */
  704.                  typedef struct {
  705.                      int  pxp_ispixmap;                  /* type flag for pattern union */
  706.                      int  pxp_width;                     /* pixmap width (in pixels)  */
  707.                      int  pxp_height;                    /* pixmap height (in pixels) */
  708.                      int  pxp_oper;                      /* bitblt mode (SET, OR, XOR, AND) */
  709.                      GrVidRAM pxp_source;                /* source context for fill */
  710.                  } GrPixmap;
  711.  
  712.                  /*
  713.                   * Fill pattern union -- can either be a bitmap or a pixmap
  714.                   */
  715.                  typedef union {
  716.                      int      gp_ispixmap;               /* nonzero for pixmaps */
  717.                      GrBitmap gp_bitmap;                 /* fill bitmap */
  718.                      GrPixmap gp_pixmap;                 /* fill pixmap */
  719.                  } GrPattern;
  720.  
  721.                  #define gp_bmp_data                     gp_bitmap.bmp_data
  722.                  #define gp_bmp_height                   gp_bitmap.bmp_height
  723.                  #define gp_bmp_fgcolor                  gp_bitmap.bmp_fgcolor
  724.                  #define gp_bmp_bgcolor                  gp_bitmap.bmp_bgcolor
  725.  
  726.                  #define gp_pxp_width                    gp_pixmap.pxp_width
  727.                  #define gp_pxp_height                   gp_pixmap.pxp_height
  728.                  #define gp_pxp_oper                     gp_pixmap.pxp_oper
  729.                  #define gp_pxp_source                   gp_pixmap.pxp_source
  730.  
  731.             Bitmap  patterns can  be easily  built from  initialized character  arrays and
  732.             static structures  by the C compiler,  thus no special support  is included in
  733.             the library for creating  them. The only action required  from the application
  734.             program  might be  changing the  foreground and  background colors  as needed.
  735.             Pixmap patterns  are more difficult to  build as they replicate  the layout of
  736.             the video  memory which changes for different video modes. For this reason the
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.             LIBGRX graphics library user's manual                                       14
  745.  
  746.  
  747.           library  provides three  functions  to  create  pixmap  patterns  in  a  mode-
  748.             independent way:
  749.  
  750.             GrPattern *GrBuildPixmap(char *pixels,int w,int h,GrColorTableP colors);
  751.                  GrPattern *GrBuildPixmapFromBits(char *bits,int w,int h,int fgc,int bgc);
  752.                  GrPattern *GrConvertToPixmap(GrContext *src);
  753.  
  754.             'GrBuildPixmap' build  a pixmap from a  two dimensional ('w' by  'h') array of
  755.             characters. The  elements in this  array are  used as indices  into the  color
  756.             table specified with the  argument 'colors'. (This means that  pixmaps created
  757.             this way can use at most 256 colors.) The color table pointer:
  758.  
  759.             typedef int *GrColorTableP;
  760.  
  761.             should  point to an array of integers with  the first element being the number
  762.             of  colors in  the table and  the color  indices themselves  starting with the
  763.             second element.  NOTE: any color modifiers  (GrXOR, GrOR, GrAND) OR-ed  to the
  764.             elements of the color table are ignored.
  765.  
  766.             The 'GrBuildPixmapFromBits' function builds a pixmap fill pattern  from bitmap
  767.             data. It  is useful if the  width of the bitmap  pattern is not  eight as such
  768.             bitmap patterns can not be used to build a 'GrBitmap' structure.
  769.  
  770.             The  'GrConvertToPixmap' function converts a graphics context to a pixmap fill
  771.             pattern. It  is useful when the  pattern can be created  with graphics drawing
  772.             operations.  NOTE: the  pixmap  pattern and  the  original context  share  the
  773.             drawing RAM, thus if the context is redrawn the fill pattern changes as well. 
  774.  
  775.                   Fill patterns which were built by library routines can be destroyed when
  776.             no longer needed (i.e. the space occupied by them can be freed) by calling:
  777.  
  778.             void    GrDestroyPattern(GrPattern *p);
  779.  
  780.             NOTE: when pixmap  fill patterns  converted from contexts  are destroyed,  the
  781.             drawing RAM is not freed. It is  freed when the original context is destroyed.
  782.             Fill patterns built by the application have to be destroyed by the application
  783.             as well (if this is needed). 
  784.  
  785.                   The list of supported pattern filled graphics primitives is shown below.
  786.             These  functions are  very similar  to their  solid filled  counterparts, only
  787.             their last argument is different:
  788.  
  789.             void    GrPatternFilledPlot(int x,int y,GrPattern *p);
  790.                  void    GrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p);
  791.                  void    GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  792.                  void    GrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  793.                  void    GrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  794.                  void    GrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  795.                  void    GrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  796.                  void    GrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
  797.                  void    GrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.             LIBGRX graphics library user's manual                                       15
  806.  
  807.  
  808.           Strictly  speaking the  plot and  line functions  in the  above group  are not
  809.             filled, but they have been included here for convenience.
  810.  
  811.  
  812.             Patterned line drawing
  813.  
  814.                   The custom line drawing  functions introduced above also have  a version
  815.             when the  drawn sections can be filled with a (pixmap or bitmap) fill pattern.
  816.             To achieve  this these functions  must be  passed both a  custom line  drawing
  817.             option  ('GrLineOption' structure)  and  a fill  pattern ('GrPattern'  union).
  818.             These two have been combined into the 'GrLinePattern' structure:
  819.  
  820.             typedef struct {
  821.                      GrPattern     *lnp_pattern;         /* fill pattern */
  822.                      GrLineOption  *lnp_option;          /* width + dash pattern */
  823.                  } GrLinePattern;
  824.  
  825.             All patterned line drawing functions take a pointer to this structure as their
  826.             last argument. The list of available functions:
  827.  
  828.             void    GrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  829.                  void    GrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  830.                  void    GrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  831.                  void    GrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  832.                  void    GrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  833.                  void    GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  834.                  void    GrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  835.                  void    GrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  836.  
  837.  
  838.             Text drawing
  839.  
  840.                   The  library supports  loadable bit-mapped  (i.e. not  scalable!) fonts.
  841.             Some of  these fonts were converted  from VGA BIOS fonts and  fonts on utility
  842.             diskettes  coming with VGA  cards. These fonts  have all  256 characters. Some
  843.             additional fonts were converted from fonts in the MIT X11  distribution. These
  844.             have  a variable number of  characters, some support  all 256 character codes,
  845.             some only the  printable ASCII codes. Fonts also have  family names, which are
  846.             used in  a font lookup  procedure supported  by the library  (see later).  The
  847.             following font families are included in the distribution:
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.             LIBGRX graphics library user's manual                                       16
  856.  
  857.  
  858.                Font file name:         Family:     Description:
  859.  
  860.                   pc<W>x<H>[t].fnt        pc    BIOS font, fixed 
  861.                   xm<W>x<H>[b][i].fnt     X_misc      X11, fixed, miscellaneous group  
  862.                   char<H>[b][i].fnt char  X11, proportional, charter family
  863.                   cour<H>[b][i].fnt cour  X11, fixed, courier
  864.                   helve<H>[b][i].fnt      helve X11, proportional, helvetica 
  865.                   lucb<H>[b][i].fnt lucb  X11, proportional, lucida bright
  866.                   lucs<H>[b][i].fnt lucs  X11, proportional, lucida sans serif
  867.                   luct<H>[b][i].fnt       luct  X11, fixed, lucida typewriter
  868.                   ncen<H>[b][i].fnt ncen  X11, proportional, new century schoolbook
  869.                   symb<H>.fnt             symbol      X11,  proportional,  greek  letters,
  870.             symbols
  871.                   tms<H>[b][i].fnt        times X11, proportional, times
  872.  
  873.             In the font  names <W> means the  font width, <H>  the font height. Many  font
  874.             families  have bold and/or italic  variants. The files  containing these fonts
  875.             contain a  'b' and/or 'i' character  in their name just  before the extension.
  876.             Additionally,  the strings  "_bold" and/or  "_ital" are  appended to  the font
  877.             family names. Some of the pc BIOS  fonts come in thin formats also, these  are
  878.             denoted by a  't' in their file  names and the string "_thin"  in their family
  879.             names. 
  880.  
  881.             NOTE:  the basic libgrx  distribution ("cbgrx101.zip") contains  only the full
  882.             "pc", "courier",  "helve", "symbol"  and  "times" font  families and  selected
  883.             sizes  from the "X_misc" family. (Because of archive size considerations!) The
  884.             full  compliment   of  fonts   can  be  found   in  the  archive   file  named
  885.             "cbgrxfnt.zip", which should  be available from the same site  where the basic
  886.             library was obtained from.
  887.  
  888.                   Fonts are loaded  with the 'GrLoadFont' function. If  the font file name
  889.             starts  with  any path  separator  character  or character  sequence  ('<drive
  890.             letter>:',  '/'  or  '\') then  it  is  loaded from  the  specified directory,
  891.             otherwise the font  is loaded from the default font path. The font path can be
  892.             set up with the 'GrSetFontPath' function. If the font path is not set then the
  893.             value  of the  'GRXFONT' environment  variable is  used as  the font  path. If
  894.             'GrLoadFont'  is called again with the name  of an already loaded font then it
  895.             will  return a pointer  to the result  of the first loading.  The special font
  896.             names "@:pc8x8.fnt", "@:pc8x14.fnt" and "@:pc8x16.fnt" will cause 'GrLoadFont'
  897.             to load the font from  the BIOS of the graphics card of the  PC (provided that
  898.             it has the desired  font). Alternatively, 'GrLoadBIOSFont' can also  be called
  899.             to load  a  font  which resides  in  the BIOS  of  the display  adapter.  (The
  900.             difference is that 'GrLoadFont' will look at the disk as well if the BIOS does
  901.             not have the font. For example: EGA-s don't have a 16 row font in their BIOS.)
  902.             Both font loading  routines return NULL if  the font was  not found. When  not
  903.             needed  any more,  fonts can be  unloaded (i.e.  the storage  occupied by them
  904.             freed)  by  calling  'GrUnloadFont'.  The  prototype  declarations  for  these
  905.             functions:
  906.  
  907.             GrFont *GrLoadFont(char *name);
  908.                  GrFont *GrLoadBIOSFont(char *name);
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.                  LIBGRX graphics library user's manual                                                       17
  917.  
  918.  
  919.           void    GrUnloadFont(GrFont *font);
  920.                  void    GrSetFontPath(char *path);
  921.  
  922.                   The 'GrFont' structure is actually a font header, the real  font data is
  923.             right  next to  this header  in memory, but  it is  typically hidden  from the
  924.             application  program. If needed, the include file "grxfont.h" can provide more
  925.             details. The 'GrFont' structure:
  926.  
  927.             typedef struct {
  928.                      short   fnt_width;                  /* width (average for proportional) */
  929.                      short   fnt_height;                 /* font height */
  930.                      short   fnt_minchar;                /* lowest character code in font */
  931.                      short   fnt_maxchar;                /* highest character code in font */
  932.                      short   fnt_isfixed;                /* nonzero if fixed font */
  933.                      short   fnt_internal;               /* nonzero if BIOS font */
  934.                      short   fnt_baseline;               /* baseline from top of font */
  935.                      short   fnt_undwidth;               /* underline width (at bottom) */
  936.                      char    fnt_name[GR_NAMEWIDTH];     /* font file name (w/o path) */
  937.                      char    fnt_family[GR_NAMEWIDTH];   /* font family name */
  938.                  } GrFont;
  939.  
  940.                   There  is  a function:  'GrFindBestFont'  which returns  the  font which
  941.             matches  best  a desired  size.  (Best  match: not  bigger,  but  as close  as
  942.             possible).  The application can  specify whether it  wants 'GrFindBestFont' to
  943.             find  the best  match using fonts  in their  original sizes  only, or possibly
  944.             enlarged (with  the value of the  'magnify' argument -- 0:  no, nonzero: yes).
  945.             'GrFindBestFont'  also takes a string argument which specifies the font family
  946.             from which to select the font. The string can specify  several family patterns
  947.             separated  by the  ':' character.  Each pattern  can contain  the '?'  and '*'
  948.             wildcard characters which work the  usual way (in UNIX sense --  i.e. "X*ital"
  949.             will match "X_misc_ital", but not "X_misc_bold"..).
  950.  
  951.             GrTextOption *GrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  952.  
  953.             The 'GrTextOption' structure specifies how to draw a character string:
  954.  
  955.             typedef struct {
  956.                      GrFont *txo_font;                   /* font to be used */
  957.                      int     txo_xmag;                   /* X magnification */
  958.                      int     txo_ymag;                   /* Y magnification */
  959.                      union {
  960.                          int v;                          /* color when no attributes */
  961.                          GrColorTableP p;                /* ptr to color table otherwise */
  962.                      } txo_fgcolor,txo_bgcolor;          /* foreground, background */
  963.                      char    txo_direct;                 /* direction */
  964.                      char    txo_xalign;                 /* X alignment */
  965.                      char    txo_yalign;                 /* Y alignment */
  966.                      char    txo_chrtype;                /* character type */
  967.                  } GrTextOption;
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.             LIBGRX graphics library user's manual                                       18
  976.  
  977.  
  978.           The font can be enlarged independently in the X and  Y directions, ('txo_xmag'
  979.             and  'txo_ymag' slots  --  values:  1  and up)  the  text  can be  rotated  in
  980.             increments  of  90  degrees ('txo_direct'),  alignments  can  be  set in  both
  981.             directions ('txo_xalign'  and 'txo_yalign'), and separate  fore and background
  982.             colors can be specified. The accepted text direction values:
  983.  
  984.             #define GR_TEXT_RIGHT           0       /* normal */
  985.                  #define GR_TEXT_DOWN            1       /* downward */
  986.                  #define GR_TEXT_LEFT            2       /* upside down, right to left */
  987.                  #define GR_TEXT_UP              3       /* upward */
  988.                  #define GR_TEXT_DEFAULT         GR_TEXT_RIGHT
  989.  
  990.             The accepted horizontal and vertical alignment option values:
  991.  
  992.             #define GR_ALIGN_LEFT           0       /* X only */
  993.                  #define GR_ALIGN_TOP            0       /* Y only */
  994.                  #define GR_ALIGN_CENTER         1       /* X, Y */
  995.                  #define GR_ALIGN_RIGHT          2       /* X only */
  996.                  #define GR_ALIGN_BOTTOM         2       /* Y only */
  997.                  #define GR_ALIGN_BASELINE       3       /* Y only */
  998.                  #define GR_ALIGN_DEFAULT        GR_ALIGN_LEFT
  999.  
  1000.             Text strings can be of three different types: one character per byte (i.e. the
  1001.             usual C  character string, this is the default), one character per 16-bit word
  1002.             (suitable  for  fonts with  a  large number  of  characters),  and a  PC-style
  1003.             character-attribute pair. In the  last case the 'GrTextOption' structure  must
  1004.             contain a pointer to  a color table of size 16 (fg color  bits in attrib) or 8
  1005.             (bg color  bits). (The color table format  is explained in more  detail in the
  1006.             previous section explaining the methods to build fill patterns.) The supported
  1007.             text types:
  1008.  
  1009.             #define GR_BYTE_TEXT            0       /* one byte per character */
  1010.                  #define GR_WORD_TEXT            1       /* two bytes per character */
  1011.                  #define GR_ATTR_TEXT            2       /* char w/ PC style attribute byte */
  1012.  
  1013.             The  PC-style  attribute text  uses the  same  layout (first  byte: character,
  1014.             second: attributes) and bitfields  as the text mode screen on the PC. The only
  1015.             difference  is that the  'blink' bit is  not supported (it would  be very time
  1016.             consuming -- the PC text mode does it with hardware support). This bit is used
  1017.             instead to control the  underlined display of characters. For  convenience the
  1018.             following attribute manipulation macros have been declared in "grx.h":
  1019.  
  1020.             #define GR_BUILD_ATTR(fgcolor,bgcolor,underline)  \
  1021.                      ((fgcolor) & 15) | (((bgcolor) & 7) << 4) | (((underline) & 1) << 7))
  1022.                  #define GR_ATTR_FGCOLOR(attr)   ((attr) & 15)
  1023.                  #define GR_ATTR_BGCOLOR(attr)   (((attr) >> 4) & 7)
  1024.                  #define GR_ATTR_UNDERLINE(attr) (((attr) >> 7) & 1)
  1025.  
  1026.             Text strings of  the types 'GR_BYTE_TEXT' and 'GR_WORD_TEXT" can also be drawn
  1027.             underlined. This is  controlled by OR-ing the  constant 'GR_UNDERLINE_TEXT' to
  1028.             the foreground color value:
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.                  LIBGRX graphics library user's manual                                                       19
  1037.  
  1038.  
  1039.           #define GR_UNDERLINE_TEXT                 (GrXOR << 6)
  1040.  
  1041.                   After the  application  initializes a  text  option structure  with  the
  1042.             desired values it can call one of the following two text drawing functions:
  1043.  
  1044.             void    GrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1045.                  void    GrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1046.  
  1047.             NOTE: text drawing is fastest  when the font is not magnified, it  is drawn in
  1048.             the 'normal' direction, and the character does not have to be clipped. It this
  1049.             case the library can  use the appropriate low-level  video RAM access  routine
  1050.             (see  "INTERNAL.DOC" for more  details), while in  any other case  the text is
  1051.             drawn   pixel-by-pixel  (or   rectangle-by-rectangle   if  enlarged)   by  the
  1052.             higher-level code.
  1053.  
  1054.                   The function 'GrTextXY' is provided for compatibility with the  original
  1055.             256 color DJGPP graphics library. It draws the text in the standard direction,
  1056.             unmagnified, and  using the 16 row  BIOS font on VGA-s  or the 14  row font on
  1057.             EGA-s. 
  1058.  
  1059.             void    GrTextXY(int x,int y,char *text,int fg,int bg);
  1060.  
  1061.                   The  size of a  font, a character  or a text  string can be  obtained by
  1062.             calling  one  of  the following  functions.  These  functions  also take  into
  1063.             consideration  the  magnification and  text  direction specified  in  the text
  1064.             option structure passed to them.
  1065.  
  1066.             int     GrFontHeight(GrTextOption *opt);
  1067.                  int     GrFontWidth(GrTextOption *opt);
  1068.                  int     GrCharWidth(int chr,GrTextOption *opt);
  1069.                  int     GrCharHeight(int chr,GrTextOption *opt);
  1070.                  int     GrStringWidth(char *text,int length,GrTextOption *opt);
  1071.                  int     GrStringHeight(char *text,int length,GrTextOption *opt);
  1072.  
  1073.                   The 'GrTextRegion' structure and its associated functions can be used to
  1074.             implement  a fast  (as much as  possible in  graphics modes)  rectangular text
  1075.             window using a fixed font. Clipping for such windows is done in character size
  1076.             increments  instead of  pixels (i.e.  no partial  characters are  drawn). Only
  1077.             fixed  fonts can be  used in their  natural size. 'GrDumpText'  will cache the
  1078.             code of the drawn characters in the buffer pointed to by the 'backup' slot (if
  1079.             it  is non-NULL)  and  will draw  a  character only  if  the previously  drawn
  1080.             character in  that grid element is different. This can speed up text scrolling
  1081.             significantly in  graphics modes.  The supported  text types are  the same  as
  1082.             above.
  1083.  
  1084.             typedef struct {
  1085.                      GrFont *txr_font;                   /* font to be used */
  1086.                      char   *txr_buffer;                 /* pointer to text buffer */
  1087.                      char   *txr_backup;                 /* optional backup buffer */
  1088.                      int     txr_xpos;                   /* upper left corner X coordinate */
  1089.                      int     txr_ypos;                   /* upper left corner Y coordinate */
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.                  LIBGRX graphics library user's manual                                                       20
  1098.  
  1099.  
  1100.               int     txr_width;                  /* width of area in chars */
  1101.                      int     txr_height;                 /* height of area in chars */
  1102.                      int     txr_lineoffset;             /* offset in buffer(s) between lines */
  1103.                      union {
  1104.                          int v;                          /* color when no attributes */
  1105.                          GrColorTableP p;                /* ptr to color table otherwise */
  1106.                      } txr_fgcolor,txr_bgcolor;          /* foreground, background */
  1107.                      char    txr_chrtype;                /* character type (see above) */
  1108.                  } GrTextRegion;
  1109.  
  1110.                  void    GrDumpChar(int chr,int col,int row,GrTextRegion *r);
  1111.                  void    GrDumpText(int col,int row,int wdt,int hgt,GrTextRegion *r);
  1112.                  void    GrDumpTextRegion(GrTextRegion *r);
  1113.  
  1114.             The  'GrDumpTextRegion'   function  outputs  the  whole   text  region,  while
  1115.             'GrDumpText'  draws only a user-specified part of it. 'GrDumpChar' updates the
  1116.             character  in the  buffer at  the specified  location with  the new  character
  1117.             passed  to it as  argument and then draws  the new character  on the screen as
  1118.             well. 
  1119.  
  1120.  
  1121.             Drawing in user coordinates
  1122.  
  1123.                  There is a second set  of the graphics primitives which operates  in user
  1124.             coordinates.  Every context has a user to screen coordinate mapping associated
  1125.             with  it.  An   application  specifies   the  user  window   by  calling   the
  1126.             'GrSetUserWindow' function.
  1127.  
  1128.             void    GrSetUserWindow(int x1,int y1,int x2,int y2);
  1129.  
  1130.             A call to  this function it  in fact specifies  the virtual coordinate  limits
  1131.             which  will be mapped onto  the current context regardless  of the size of the
  1132.             context. For example, the call:
  1133.  
  1134.             GrSetUserWindow(0,0,11999,8999);
  1135.  
  1136.             tells the  library that the program  will perform its drawing  operations in a
  1137.             coordinate system X:0...11999 (width = 12000)  and Y:0...8999 (height = 9000).
  1138.             This  coordinate  range will  be mapped  onto the  total  area of  the current
  1139.             context. The virtual coordinate system can also be shifted. For example:
  1140.  
  1141.             GrSetUserWindow(5000,2000,16999,10999);
  1142.  
  1143.             The user coordinates can even be used to turn the usual left-handed coordinate
  1144.             system (0:0  corresponds to the upper left corner)  to a right handed one (0:0
  1145.             corresponds to the bottom left corner) by calling:
  1146.  
  1147.             GrSetUserWindow(0,8999,11999,0);
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.             LIBGRX graphics library user's manual                                       21
  1156.  
  1157.  
  1158.                The library also  provides three utility functions for the  query of the
  1159.             current user coordinate limits  and for converting user coordinates  to screen
  1160.             coordinates and vice versa.
  1161.  
  1162.             void    GrGetUserWindow(int *x1,int *y1,int *x2,int *y2);
  1163.                  void    GrGetScreenCoord(int *x,int *y);
  1164.                  void    GrGetUserCoord(int *x,int *y);
  1165.  
  1166.                   If  an  application wants  to  take  advantage  of the  user  to  screen
  1167.             coordinate mapping it  has to use  the user  coordinate version  of
  1168.           the graphics  primitives. These  have exactly the  same parameter
  1169.           passing  conventions  as  their  screen  coordinate counterparts.
  1170.           NOTE: the  user  coordinate  system is  not  initialized  by  the
  1171.           library! The  application has  to set  up its  coordinate mapping
  1172.           before  calling any of  the use  coordinate drawing  functions --
  1173.           otherwise the  program will  almost  certainly exit  (in a  quite
  1174.           ungraceful  fashion) with a 'division by zero' error. The list of
  1175.           supported user coordinate drawing functions:
  1176.  
  1177.           void    GrUsrPlot(int x,int y,int c);
  1178.                  void    GrUsrLine(int x1,int y1,int x2,int y2,int c);
  1179.                  void    GrUsrHLine(int x1,int x2,int y,int c);
  1180.                  void    GrUsrVLine(int x,int y1,int y2,int c);
  1181.                  void    GrUsrBox(int x1,int y1,int x2,int y2,int c);
  1182.                  void    GrUsrFilledBox(int x1,int y1,int x2,int y2,int c);
  1183.                  void    GrUsrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
  1184.                  void    GrUsrCircle(int xc,int yc,int r,int c);
  1185.                  void    GrUsrEllipse(int xc,int yc,int xa,int ya,int c);
  1186.                  void    GrUsrCircleArc(int xc,int yc,int r,int start,int end,int c);
  1187.                  void    GrUsrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1188.                  void    GrUsrFilledCircle(int xc,int yc,int r,int c);
  1189.                  void    GrUsrFilledEllipse(int xc,int yc,int xa,int ya,int c);
  1190.                  void    GrUsrFilledCircleArc(int xc,int yc,int r,int start,int end,int c);
  1191.                  void    GrUsrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int c);
  1192.                  void    GrUsrPolyLine(int numpts,int points[][2],int c);
  1193.                  void    GrUsrPolygon(int numpts,int points[][2],int c);
  1194.                  void    GrUsrFilledConvexPolygon(int numpts,int points[][2],int c);
  1195.                  void    GrUsrFilledPolygon(int numpts,int points[][2],int c);
  1196.                  int     GrUsrPixel(int x,int y);
  1197.  
  1198.                  void    GrUsrCustomLine(int x1,int y1,int x2,int y2,GrLineOption *o);
  1199.                  void    GrUsrCustomBox(int x1,int y1,int x2,int y2,GrLineOption *o);
  1200.                  void    GrUsrCustomCircle(int xc,int yc,int r,GrLineOption *o);
  1201.                  void    GrUsrCustomEllipse(int xc,int yc,int xa,int ya,GrLineOption *o);
  1202.                  void    GrUsrCustomCircleArc(int xc,int yc,int r,int start,int end,GrLineOption *o);
  1203.                  void    GrUsrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLineOption *o);
  1204.                  void    GrUsrCustomPolyLine(int numpts,int points[][2],GrLineOption *o);
  1205.                  void    GrUsrCustomPolygon(int numpts,int points[][2],GrLineOption *o);
  1206.  
  1207.                  void    GrUsrPatternedPlot(int x,int y,GrPattern *p);
  1208.                  void    GrUsrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.                  LIBGRX graphics library user's manual                                                       22
  1217.  
  1218.  
  1219.           void    GrUsrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
  1220.                  void    GrUsrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
  1221.                  void    GrUsrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
  1222.                  void    GrUsrPatternedCircleArc(int xc,int yc,int r,int start,int end,GrLinePattern *lp);
  1223.                  void    GrUsrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrLinePattern *lp);
  1224.                  void    GrUsrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
  1225.                  void    GrUsrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
  1226.  
  1227.                  void    GrUsrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
  1228.                  void    GrUsrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
  1229.                  void    GrUsrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
  1230.                  void    GrUsrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,GrPattern *p);
  1231.                  void    GrUsrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,GrPattern *p);
  1232.                  void    GrUsrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
  1233.                  void    GrUsrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
  1234.  
  1235.                  GrTextOption *GrUsrFindBestFont(int width,int height,int magnify,char *family,GrTextOption *where);
  1236.                  void    GrUsrDrawChar(int chr,int x,int y,GrTextOption *opt);
  1237.                  void    GrUsrDrawString(char *text,int length,int x,int y,GrTextOption *opt);
  1238.                  void    GrUsrTextXY(int x,int y,char *text,int fg,int bg);
  1239.  
  1240.  
  1241.             Graphics cursors
  1242.  
  1243.                   The library provides support for the creation and usage of  an unlimited
  1244.             number of  graphics cursors.  An application  can  use these  cursors for  any
  1245.             purpose. Cursors  always save the area they occupy before they are drawn. When
  1246.             moved or  erased they  restore  this area.  As a  general  rule of  thumb,  an
  1247.             application should erase a cursor before making changes to an area it occupies
  1248.             and  redraw the  cursor  after finishing  the  drawing. All  cursor and  mouse
  1249.             related  declaration are in the  include file "mousex.h".  Cursors are created
  1250.             with the 'GrBuildCursor' function:
  1251.  
  1252.             GrCursor *GrBuildCursor(char *data,int w,int h,int xo,int yo,GrColorTableP c);
  1253.  
  1254.             The 'data',  'w' (=width), 'h' (=height) and 'c' (= color table) arguments are
  1255.             similar  to  the   arguments  of   the  pixmap   building  library   function:
  1256.             'GrBuildPixmap'. (See  that paragraph for  a more  detailed explanation.)  The
  1257.             only difference is that  the pixmap data is interpreted  slightly differently:
  1258.             any  pixel  with value  zero  is  taken as  a  "transparent"  pixel, i.e.  the
  1259.             background will show  through the cursor pattern at that  pixel. A pixmap data
  1260.             byte with value = 1 will refer to the first color in the table, and so on. The
  1261.             'xo' (= X offset) and  'yo' (= Y offset) arguments specify  the position (from
  1262.             the top left corner of  the cursor pattern)  of the cursor's  "hot point". The
  1263.             'GrCursor' data structure:
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.                  LIBGRX graphics library user's manual                                                       23
  1272.  
  1273.  
  1274.           typedef struct {
  1275.                      GrVidRAM  cr_andmask;               /* cursor bitmap to AND */
  1276.                      GrVidRAM  cr_ormask;                /* cursor bitmap to OR */
  1277.                      GrVidRAM  cr_work;                  /* work area */
  1278.                      GrVidRAM  cr_save;                  /* screen save area */
  1279.                      int   cr_xcord,cr_ycord;            /* cursor position on screen */
  1280.                      int   cr_xsize,cr_ysize;            /* cursor size */
  1281.                      int   cr_xoffs,cr_yoffs;            /* LU corner to hot point offset */
  1282.                      int   cr_xwork,cr_ywork;            /* save/work area sizes */
  1283.                      int   cr_xwpos,cr_ywpos;            /* save/work area position on screen */
  1284.                      int   cr_displayed;                 /* set if displayed */
  1285.                  } GrCursor;
  1286.  
  1287.             is typically  not used (i.e. read  or changed) by the  application program, it
  1288.             should  just  pass pointers  to these  structures  to the  appropriate library
  1289.             functions. Other cursor manipulation functions:
  1290.  
  1291.             void GrDestroyCursor(GrCursor *cursor);
  1292.                  void GrDisplayCursor(GrCursor *cursor);
  1293.                  void GrEraseCursor(GrCursor *cursor);
  1294.                  void GrMoveCursor(GrCursor *cursor,int x,int y);
  1295.  
  1296.  
  1297.             Mouse event handling
  1298.  
  1299.                   All mouse  services  need  the presence  of  a mouse  and  an  installed
  1300.             Microsoft compatible mouse  driver. An application can test whether a mouse is
  1301.             available by calling the function:
  1302.  
  1303.             int  MouseDetect(void);
  1304.  
  1305.             which will  return zero  if no  mouse (or mouse  driver) is  present, non-zero
  1306.             otherwise. If the mouse is present the  application may decide if it wants  to
  1307.             use  the  mouse  in  interrupt-driven  or polled  mode.  The  polled  mode  is
  1308.             compatible with previous releases of DJGPP and the 256 color graphics library,
  1309.             it  uses the mouse  driver interrupts (INT  33h) to query  the mouse about its
  1310.             position and  buttons. This  method  is adequate  if the  program  can do  the
  1311.             polling in  a tight enough loop.  If the program does  lengthy computations in
  1312.             the background  during which a  "frozen" mouse  and the loss  of mouse  button
  1313.             presses would be  disturbing it has  to use the  interrupt driven method.  For
  1314.             this a  patched version of  GO32 is needed --  a GO32 version  dated after the
  1315.             middle of April  1992 should work. The interrupt  driven mouse event mechanism
  1316.             uses an event  queue library  (described in the  document "EVENTS.DOC")  which
  1317.             stores all  user interaction  events (mouse  presses and  keyboard hits) in  a
  1318.             queue,  timestamped, in  the  order of  occurrence.  The disadvantage  of  the
  1319.             interrupt-driven  mouse event mechanism is that it  may be harder to debug. To
  1320.             select between the two modes the following function needs to be called:
  1321.  
  1322.             void MouseEventMode(int use_interrupts);
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.             LIBGRX graphics library user's manual                                       24
  1331.  
  1332.  
  1333.           If the  'use_interrupts' parameter is zero  the mouse is put  into polled mode
  1334.             (this  is  the  default),  otherwise  it  will  work  interrupt-driven.  After
  1335.             selecting the mode, the mouse can be initialized by calling:
  1336.  
  1337.             void MouseInit(void);
  1338.  
  1339.             It  is   not  necessary  to  call   this  function  as  the   first  call  the
  1340.             'MouseGetEvent'  (see later)  function will  also perform  the initialization.
  1341.             However,  if the mouse  event mode is  changed after using  'MouseGetEvent', a
  1342.             call to 'MouseInit' is the only way to enforce the change. 
  1343.  
  1344.                   If the mouse is used in interrupt-driven mode, it  is a good practice to
  1345.             call 'MouseUnInit' before exiting the program. This will restore any interrupt
  1346.             vectors hooked by the program to their original values.
  1347.  
  1348.             void MouseUnInit(void);
  1349.  
  1350.             The mouse can be controlled with the following functions:
  1351.  
  1352.             void MouseSetSpeed(int speed);
  1353.                  void MouseSetAccel(int thresh,int accel);
  1354.                  void MouseSetLimits(int x1,int y1,int x2,int y2);
  1355.                  void MouseGetLimits(int *x1,int *y1,int *x2,int *y2);
  1356.                  void MouseWarp(int x,int y);
  1357.  
  1358.             The library calculates the mouse position only from the mouse mickey counters.
  1359.             (To avoid the limit and 'rounding to  the next multiple of eight' problem with
  1360.             the Microsoft mouse driver when it finds itself in a graphics  mode unknown to
  1361.             it.)  The  'speed' parameter  to  the 'MouseSetSpeed'  function is  used  as a
  1362.             divisor, i.e. coordinate changes  are obtained by dividing the  mickey counter
  1363.             changes by this value. In high resolution graphics modes the value of one just
  1364.             works  fine, in low resolution  modes (320x200 or similar)  it is best set the
  1365.             speed to  two or three.  (Of course,  it also depends  on the sensitivity  the
  1366.             mouse.)  The 'MouseSetAccel' function is used to control the ballistic effect:
  1367.             if a mouse coordinate changes between  two samplings by more than the 'thresh'
  1368.             parameter, the change is multiplied by the 'accel' parameter. NOTE: some mouse
  1369.             drivers  perform  similar calculations  before  reporting  the coordinates  in
  1370.             mickeys. In this case the acceleration  done by the library will be additional
  1371.             to  the one already  performed by  the mouse driver.  The limits  of the mouse
  1372.             movement  can  be set  (passed  limits will  be  clipped to  the  screen) with
  1373.             'MouseSetLimits'  (default is the whole screen)  and the current limits can be
  1374.             obtained with  'MouseGetLimits'.  'MouseWarp' sets  the  mouse cursor  to  the
  1375.             specified position.
  1376.  
  1377.                   As typical  mouse drivers do not know how  to draw mouse cursors in high
  1378.             resolution graphics modes, the mouse cursor is drawn by the library. The mouse
  1379.             cursor can be set with:
  1380.  
  1381.             void MouseSetCursor(GrCursor *cursor);
  1382.                  void MouseSetColors(int fg,int bg);
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.             LIBGRX graphics library user's manual                                       25
  1391.  
  1392.  
  1393.           'MouseSetColors' uses an  internal arrow pattern, the color 'fg'  will be used
  1394.             as  the interior of it and  'bg' will be the border.  The current mouse cursor
  1395.             can be obtained with:
  1396.  
  1397.             GrCursor *MouseGetCursor(void);
  1398.  
  1399.             The mouse cursor can be displayed/erased with:
  1400.  
  1401.             void MouseDisplayCursor(void);
  1402.                  void MouseEraseCursor(void);
  1403.  
  1404.             The  mouse cursor can be  left permanently displayed.  All graphics primitives
  1405.             except for the few non-clipping  functions check for conflicts with the  mouse
  1406.             cursor and erase it before the drawing if necessary. Of course, it may be more
  1407.             efficient  to erase  the cursor  manually before a  long drawing  sequence and
  1408.             redraw it after  completion. The library provides an alternative pair of calls
  1409.             for this purpose which  will erase the cursor  only if it interferes  with the
  1410.             drawing:
  1411.  
  1412.             int  MouseBlock(GrContext *c,int x1,int y1,int x2,int y2);
  1413.                  void MouseUnBlock(void);
  1414.  
  1415.             'MouseBlock' should be passed the context in which the drawing will take place
  1416.             (the  usual convention of  NULL meaning the current  context is supported) and
  1417.             the  limits  of  the  affected area.  It  will  erase the  cursor  only  if it
  1418.             interferes  with  the   drawing.  If   it  returns  a   non-zero  value   then
  1419.             'MouseUnBlock' has to be called at the end of the drawing, otherwise it should
  1420.             not be called.
  1421.  
  1422.                   The library supports (beside  the simple cursor drawing) three  types of
  1423.             "rubberband" attached  to the mouse cursor.  The 'MouseSetCursorMode' function
  1424.             is used to select the cursor drawing mode.
  1425.  
  1426.             void MouseSetCursorMode(int mode,...);
  1427.  
  1428.             The parameter 'mode' can have the following values:
  1429.  
  1430.             /*
  1431.                   * MOUSE CURSOR modes:
  1432.                   *  M_CUR_NORMAL -- just the cursor
  1433.                   *  M_CUR_RUBBER -- rectangular rubber band (XOR-d to the screen)
  1434.                   *  M_CUR_LINE   -- line attached to the cursor
  1435.                   *  M_CUR_BOX    -- rectangular box dragged by the cursor
  1436.                   */
  1437.                  #define M_CUR_NORMAL    0
  1438.                  #define M_CUR_RUBBER    1
  1439.                  #define M_CUR_LINE      2
  1440.                  #define M_CUR_BOX       3
  1441.  
  1442.             'MouseSetCursorMode'  takes  different  parameters  depending  on  the  cursor
  1443.             drawing mode selected. The accepted call formats are:
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.                  LIBGRX graphics library user's manual                                                       26
  1452.  
  1453.  
  1454.           MouseSetCursorMode(M_CUR_NORMAL);
  1455.                  MouseSetCursorMode(M_CUR_RUBBER,xanchor,yanchor,color);
  1456.                  MouseSetCursorMode(M_CUR_LINE,xanchor,yanchor,color);
  1457.                  MouseSetCursorMode(M_CUR_BOX,dx1,dy1,dx2,dy2,color);
  1458.  
  1459.             The anchor parameters for the rubberband  and rubberline modes specify a fixed
  1460.             screen location to which the other corner of the primitive is bound. The 'dx1'
  1461.             through 'dy2' parameters define the offsets  of the corners of the dragged box
  1462.             from the hotpoint of the mouse cursor. The color value passed is always XOR-ed
  1463.             to the  screen, i.e.  if an application  wants the  rubberband to appear  in a
  1464.             given  color on a given  background then it  has to pass the  XOR of these two
  1465.             colors to 'MouseSetCursorMode'.
  1466.  
  1467.             The   status  of   the   mouse   cursor   can   be   obtained   with   calling
  1468.             'MouseCursorIsDisplayed'. This function will return non-zero if  the cursor is
  1469.             displayed, zero if it is erased.
  1470.  
  1471.             int  MouseCursorIsDisplayed(void);
  1472.  
  1473.                   The  'MouseGetEvent'  function  is used  to  obtain  the  next mouse  or
  1474.             keyboard event. It takes a  flag with various bits encoding the type  of event
  1475.             needed.  It  returns  the event  in  a  'MouseEvent'  structure. The  relevant
  1476.             declarations from "mousex.h":
  1477.  
  1478.             void MouseGetEvent(int flags,MouseEvent *event);
  1479.  
  1480.                  typedef struct {
  1481.                      int  flags;                         /* flags (see above) */
  1482.                      int  x,y;                           /* coordinates */
  1483.                      int  buttons;                       /* button state */
  1484.                      int  key;                           /* key code from keyboard */
  1485.                      int  kbstat;                        /* keybd status (ALT, CTRL, etc..) */
  1486.                      long time;                          /* time stamp of the event */
  1487.                  } MouseEvent;
  1488.  
  1489.             The event  structure has been  extended with  a keyboard status  word (thus  a
  1490.             program  can check for combinations  like ALT-<left mousebutton  press>) and a
  1491.             time  stamp (in DOS clock  ticks since the start of  the program) which can be
  1492.             used to check for double clicks, etc... The following macros have been defined
  1493.             in "mousex.h" to  help in creating  the control  flag for 'MouseGetEvent'  and
  1494.             decoding the various bits in the event structure:
  1495.  
  1496.             /*
  1497.                   * MOUSE event flag bits
  1498.                   */
  1499.                  #define M_MOTION        0x001
  1500.                  #define M_LEFT_DOWN     0x002
  1501.                  #define M_LEFT_UP       0x004
  1502.                  #define M_RIGHT_DOWN    0x008
  1503.                  #define M_RIGHT_UP      0x010
  1504.                  #define M_MIDDLE_DOWN   0x020
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.                  LIBGRX graphics library user's manual                                                       27
  1513.  
  1514.  
  1515.           #define M_MIDDLE_UP     0x040
  1516.                  #define M_BUTTON_DOWN   (M_LEFT_DOWN | M_MIDDLE_DOWN | M_RIGHT_DOWN)
  1517.                  #define M_BUTTON_UP     (M_LEFT_UP   | M_MIDDLE_UP   | M_RIGHT_UP)
  1518.                  #define M_BUTTON_CHANGE (M_BUTTON_UP | M_BUTTON_DOWN )
  1519.  
  1520.                  /*
  1521.                   * MOUSE button status bits
  1522.                   */
  1523.                  #define M_LEFT          1
  1524.                  #define M_RIGHT         2
  1525.                  #define M_MIDDLE        4
  1526.  
  1527.                  /*
  1528.                   * Other bits and combinations
  1529.                   */
  1530.                  #define M_KEYPRESS      0x080           /* keypress */
  1531.                  #define M_POLL          0x100           /* do not wait for the event */
  1532.                  #define M_NOPAINT       0x200
  1533.                  #define M_EVENT         (M_MOTION | M_KEYPRESS | M_BUTTON_DOWN | M_BUTTON_UP)
  1534.  
  1535.                  /*
  1536.                   * KEYBOARD status word bits
  1537.                   */
  1538.                  #define KB_RIGHTSHIFT   0x01            /* right shift key depressed */
  1539.                  #define KB_LEFTSHIFT    0x02            /* left shift key depressed */
  1540.                  #define KB_CTRL         0x04            /* CTRL depressed */
  1541.                  #define KB_ALT          0x08            /* ALT depressed */
  1542.                  #define KB_SCROLLOCK    0x10            /* SCROLL LOCK active */
  1543.                  #define KB_NUMLOCK      0x20            /* NUM LOCK active */
  1544.                  #define KB_CAPSLOCK     0x40            /* CAPS LOCK active */
  1545.                  #define KB_INSERT       0x80            /* INSERT state active */
  1546.  
  1547.                  #define KB_SHIFT        (KB_LEFTSHIFT | KB_RIGHTSHIFT)
  1548.  
  1549.             'MouseGetEvent' will display the mouse cursor if it  was previously erased and
  1550.             the 'M_NOPAINT' bit is not set in the flag passed to it. In this case it  will
  1551.             also erase the cursor after an event has been obtained.
  1552.  
  1553.             NOTE: some  of the mouse  event constants  have different values  than in  the
  1554.             original  DJGPP graphics library. This  change was necessary  to better follow
  1555.             the mouse driver conventions for assigning bits with similar functions.
  1556.  
  1557.             The  generation of  mouse and keyboard  events can be  individually enabled or
  1558.             disabled   (by  passing  a  non-zero  or  zero,  respectively,  value  in  the
  1559.             corresponding 'enable_XX' parameter) by calling:
  1560.  
  1561.             void MouseEventEnable(int enable_kb,int enable_ms);
  1562.