home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / include / mgraph.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  30.5 KB  |  911 lines

  1. /****************************************************************************
  2. *
  3. *                        MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: mgraph.h $
  9. * Version:        $Revision: 1.3 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MS DOS)
  13. *
  14. * Description:    Header file for the MegaGraph graphics library.
  15. *
  16. * $Id: mgraph.h 1.3 1994/03/10 09:14:16 kjb release $
  17. *
  18. ****************************************************************************/
  19.  
  20. #ifndef    __MGRAPH_H
  21. #define    __MGRAPH_H
  22.  
  23. #ifndef    __DEBUG_H
  24. #include "debug.h"
  25. #endif
  26.  
  27. #ifndef    __MOUSE_H
  28. #include "mouse.h"
  29. #endif
  30.  
  31. /*---------------------- Macros and type definitions ----------------------*/
  32.  
  33. /* Define the graphics subsystems available    */
  34.  
  35. typedef enum {
  36.     grDETECT,                /* Auto detect the graphics subsystem        */
  37.     grNONE,                    /* No graphics hardware detected            */
  38.     grEGA,                    /* Standard EGA with 256k RAM                */
  39.     grVGA,                    /* Standard VGA                                */
  40.     grSVGA,                    /* VESA VBE compliant Super VGA                */
  41.     grSVGA_S3,                /* S3 accelerated SuperVGA                    */
  42.     grUSER,                    /* User drivers start here                    */
  43.     } MGL_driver;
  44.  
  45. /* Graphics modes supported    - the only video modes supported by this
  46.  * graphics library are those that support at least 16 colors per pixel.
  47.  */
  48.  
  49. typedef enum {
  50.     /* 16 color EGA video modes */
  51.  
  52.     grEGA_320x200x16,            /* 320x200 16 color 8 page                */
  53.     grEGA_640x200x16,            /* 640x200 16 color 4 page                */
  54.     grEGA_640x350x16,            /* 640x350 16 color 2 page                */
  55.  
  56.     /* 16 color VGA video modes */
  57.  
  58.     grVGA_640x400x16,            /* 640x400 16 color 2 page                */
  59.     grVGA_640x480x16,            /* 640x480 16 color 1 page                */
  60.  
  61.     /* 256 color VGA video modes */
  62.  
  63.     grVGA_320x200x256,            /* 320x200 256 color 1 page                */
  64.  
  65.     /* 256 color VGA ModeX video modes */
  66.  
  67.     grVGAX_320x200x256,            /* 320x200 256 color 4 page                */
  68.     grVGAX_320x240x256,            /* 320x240 256 color 3 page                */
  69.     grVGAX_320x400x256,            /* 320x400 256 color 2 page                */
  70.     grVGAX_320x480x256,            /* 320x480 256 color 1 page                */
  71.     grVGAX_360x200x256,            /* 360x200 256 color 3 page                */
  72.     grVGAX_360x240x256,            /* 360x240 256 color 3 page                */
  73.     grVGAX_360x400x256,            /* 360x400 256 color 1 page                */
  74.     grVGAX_360x480x256,            /* 360x480 256 color 1 page                */
  75.  
  76.     /* 16 color Super VGA video modes */
  77.  
  78.     grSVGA_800x600x16,            /* 800x600 16 color 1 page                */
  79.  
  80.     /* 256 color Super VGA video modes */
  81.  
  82.     grSVGA_640x350x256,            /* 640x250 256 color 1 page                */
  83.     grSVGA_640x400x256,            /* 640x400 256 color 1 page                */
  84.     grSVGA_640x480x256,            /* 640x480 256 color 1 page                */
  85.     grSVGA_800x600x256,            /* 800x600 256 color 1 page                */
  86.     grSVGA_1024x768x256,        /* 1024x768 256 color 1 page            */
  87.     grSVGA_1280x1024x256,        /* 1280x1024 256 color 1 page            */
  88.  
  89.     /* 32,768 color Super VGA video modes */
  90.  
  91.     grSVGA_320x200x32k,            /* 320x200 32,768 color 1 page            */
  92.     grSVGA_640x350x32k,            /* 640x350 32,768 color 1 page            */
  93.     grSVGA_640x400x32k,            /* 640x400 32,768 color 1 page            */
  94.     grSVGA_640x480x32k,            /* 640x480 32,768 color 1 page            */
  95.     grSVGA_800x600x32k,            /* 800x600 32,768 color 1 page            */
  96.     grSVGA_1024x768x32k,        /* 1024x768 32,768 color 1 page            */
  97.     grSVGA_1280x1024x32k,        /* 1280x1024 32,768 color 1 page        */
  98.  
  99.     /* 65,536 color Super VGA video modes */
  100.  
  101.     grSVGA_320x200x64k,            /* 320x200 65,536 color 1 page            */
  102.     grSVGA_640x350x64k,            /* 640x350 65,536 color 1 page            */
  103.     grSVGA_640x400x64k,            /* 640x400 65,536 color 1 page            */
  104.     grSVGA_640x480x64k,            /* 640x480 65,536 color 1 page            */
  105.     grSVGA_800x600x64k,            /* 800x600 65,536 color 1 page            */
  106.     grSVGA_1024x768x64k,        /* 1024x768 65,536 color 1 page            */
  107.     grSVGA_1280x1024x64k,        /* 1280x1024 65,536 color 1 page        */
  108.  
  109.     /* 16 million color Super VGA video modes */
  110.  
  111.     grSVGA_320x200x16m,            /* 320x200 16 million color 1 page        */
  112.     grSVGA_640x350x16m,            /* 640x350 16 million color 1 page        */
  113.     grSVGA_640x400x16m,            /* 640x400 16 million color 1 page        */
  114.     grSVGA_640x480x16m,            /* 640x480 16 million color 1 page        */
  115.     grSVGA_800x600x16m,            /* 800x600 16 million color 1 page        */
  116.     grSVGA_1024x768x16m,        /* 1024x768 16 million color 1 page        */
  117.     grSVGA_1280x1024x16m,        /* 1280x1024 16 million color 1 page    */
  118.  
  119.     grMAXMODE,                    /* Maximum mode number                    */
  120.     } MGL_mode;
  121.  
  122. /* MGL_result() error codes    */
  123.  
  124. typedef enum {
  125.     grOK            = 0,    /* No error                                    */
  126.     grNoInit        = -1,    /* Graphics driver has not been installed    */
  127.     grNotDetected    = -2,    /* Graphics hardware was not detected        */
  128.     grDriverNotFound= -3,    /* Graphics driver file was not found        */
  129.     grBadDriver        = -4,    /* File loaded was not a graphics driver    */
  130.     grLoadMem        = -5,    /* Not enough memory to load graphics driver*/
  131.     grInvalidMode    = -6,    /* Invalid graphics mode for selected driver*/
  132.     grInvalidDriver = -7,    /* Driver number is invalid                    */
  133.     grError            = -8,    /* General graphics error                    */
  134.     grInvalidName    = -9,    /* Invalid driver name                        */
  135.     grNoMem            = -10,    /* Not enough memory to perform operation    */
  136.     grNoModeSupport    = -11,    /* Select video mode not supported by hard.    */
  137.     grInvalidFont    = -12,    /* Invalid font data                        */
  138.     grBadFontFile    = -13,    /* File loaded was not a font file            */
  139.     grFontNotFound    = -14,    /* Font file was not found                    */
  140.     grOldDriver     = -15,    /* Driver file is an old version            */
  141.  
  142.     grLastError        = -15,    /* Last error number in list                */
  143.     } MGL_error;
  144.  
  145. #define    CLIPON        true
  146. #define    CLIPOFF        false
  147.  
  148. /* All colors are represented as longs by the library. This allows
  149.  * code to work correctly with up to 24 bit color device drivers. The
  150.  * device drivers themselves expect the color to be a color index if in
  151.  * a color mapped mode, or a 15/16/24 bit RGB tuple in a hicolor or truecolor
  152.  * mode. You can use the appropriate routines to pack and unpack
  153.  * colors into the color_t format.
  154.  */
  155.  
  156. typedef    long        color_t;
  157.  
  158. /* Standard colors - these colors are also defined in conio.h, so we only
  159.  * define them if they have not been defined before. This is the standard
  160.  * set of colors for the IBM PC. The default palette will have been
  161.  * programmed to contain these values when graphics modes is started. If
  162.  * the palette has been changed, they will not correspond to the actual
  163.  * colors on the screen.
  164.  */
  165.  
  166. #ifndef __COLORS
  167. #define    __COLORS
  168.  
  169. enum COLORS {
  170.     BLACK,                            /* dark colors    */
  171.     BLUE,
  172.     GREEN,
  173.     CYAN,
  174.     RED,
  175.     MAGENTA,
  176.     BROWN,
  177.     LIGHTGRAY,
  178.     DARKGRAY,                        /* light colors    */
  179.     LIGHTBLUE,
  180.     LIGHTGREEN,
  181.     LIGHTCYAN,
  182.     LIGHTRED,
  183.     LIGHTMAGENTA,
  184.     YELLOW,
  185.     WHITE,
  186.     };
  187.  
  188. #endif
  189.  
  190. /* EGA color components. These values can be used to program the palette
  191.  * with colors for the EGA. These are defined purely for convenience.
  192.  */
  193.  
  194. typedef enum {
  195.     RED0            = 0x00,
  196.     RED1            = 0x54,
  197.     RED2            = 0xA8,
  198.     RED3            = 0xFC,
  199.     GREEN0            = 0x00,
  200.     GREEN1            = 0x54,
  201.     GREEN2            = 0xA8,
  202.     GREEN3            = 0xFC,
  203.     BLUE0            = 0x00,
  204.     BLUE1            = 0x54,
  205.     BLUE2            = 0xA8,
  206.     BLUE3            = 0xFC,
  207.     } ega_colors;
  208.  
  209. typedef enum {
  210.     MARKER_SQUARE,
  211.     MARKER_CIRCLE,
  212.     MARKER_X,
  213.     } marker_style;
  214.  
  215. typedef enum {                        /* Write mode operators                */
  216.     REPLACE_MODE,                    /* Replace mode                        */
  217.     AND_MODE,                        /* AND mode                            */
  218.     OR_MODE,                        /* OR mode                            */
  219.     XOR_MODE,                        /* XOR mode                            */
  220.     } write_mode;
  221.  
  222. typedef enum {
  223.     SOLID_PATTERN,
  224.     BITMAP_PATTERN_OPAQUE,
  225.     BITMAP_PATTERN_TRANSPARENT,
  226.     PIXMAP_PATTERN,
  227.     } fill_style;
  228.  
  229. typedef enum {
  230.     CONVEX_POLYGON,                    /* Monotone vertical polygon        */
  231.     COMPLEX_POLYGON,                /* Non-Simple polygons                */
  232.     AUTO_POLYGON,                    /* Auto detect the polygon type        */
  233.     } polygon_types;
  234.  
  235. /* Text manipulation defines */
  236.  
  237. typedef enum {
  238.     LEFT_TEXT        =    0,            /* Justify from left                */
  239.     TOP_TEXT        =    0,            /* Justify from top                    */
  240.     CENTER_TEXT        =    1,            /* Center the text                    */
  241.     RIGHT_TEXT        =    2,            /* Justify from right                */
  242.     BOTTOM_TEXT        =    2,            /* Justify from bottom                */
  243.     BASELINE_TEXT    =    3,            /* Justify from the baseline        */
  244.     } text_just;
  245.  
  246. typedef enum {
  247.     LEFT_DIR        =    0,            /* Text goes to left                */
  248.     UP_DIR            =    1,            /* Text goes up                        */
  249.     RIGHT_DIR        =    2,            /* Text goes right                    */
  250.     DOWN_DIR        =    3,            /* Text goes down                    */
  251.     } text_dir;
  252.  
  253. /* Standard driver names    */
  254.  
  255. #define    EGANAME        "EGA.DRV"
  256. #define    VGANAME        "VGA.DRV"
  257. #define    VGA256NAME    "VGA256.DRV"
  258. #define VGAXNAME    "VGAX.DRV"
  259. #define    SVGA256NAME    "SVGA256.DRV"
  260. #define    SVGA32KNAME    "SVGA32K.DRV"
  261. #define    SVGA64KNAME    "SVGA64K.DRV"
  262. #define    SVGA16MNAME    "SVGA16M.DRV"
  263. #define    SVGAS3NAME    "SVGAS3.DRV"
  264.  
  265. /* Standard bitmap names    */
  266.  
  267. #define    EMPTY_FILL    __empty_pat
  268. #define    GRAY_FILL    __gray_pat
  269. #define    SOLID_FILL    __solid_pat
  270.  
  271. /* Here we define the structures used to represent points and rectangles.
  272.  * If we are compiling in C++ mode and we have included the "point.hpp"
  273.  * and "rect.hpp" file respectively, we can simply provide a typedef
  274.  * to allow us to pass C++ style points and rectangles directly to the
  275.  * MGL.
  276.  */
  277.  
  278. #if    defined(__cplusplus) && defined(__POINT_HPP)
  279.  
  280. typedef    Point    point;
  281.  
  282. #else
  283.  
  284. typedef struct {
  285.     int    x,y;
  286.     } point;
  287.  
  288. #endif
  289.  
  290. #if    defined(__cplusplus) && defined(__RECT_HPP)
  291.  
  292. typedef    Rect    rect;
  293.  
  294. #else
  295.  
  296. typedef    struct {
  297.     int    left;
  298.     int    top;
  299.     int    right;
  300.     int    bottom;
  301.     } rect;
  302.  
  303. #endif
  304.  
  305. /* Pixel format structure */
  306.  
  307. typedef struct {
  308.     char    redMask,blueMask;        /* Mask values for pixels            */
  309.     char    greenMask,rsvdMask;
  310.     int        redPos,redAdjust;        /* Blue position and adjustment        */
  311.     int        greenPos,greenAdjust;    /* Green position and adjustment    */
  312.     int        bluePos,blueAdjust;        /* Blue position and adjustment        */
  313.     int        rsvdPos,rsvdAdjust;        /* Reserved position and adjustment */
  314.     } pixel_format;
  315.  
  316. /* Structure to hold arc coordinate information */
  317.  
  318. typedef struct {
  319.     int        x,y;                    /* Centre point of the arc            */
  320.     int        startX,startY;            /* Starting point on arc            */
  321.     int        endX,endY;                /* Ending point on arc                */
  322.     } arc_coords;
  323.  
  324. /* Font types */
  325.  
  326. #define    FONT8X8        0                /* Built in 8x8 bitmap font            */
  327. #define    VECTORFONT    1                /* Vector font                        */
  328. #define    FIXEDFONT    2                /* Fixed width bitmap font            */
  329. #define    PROPFONT    3                /* Proportional width bitmap font    */
  330.  
  331. /* Default font name */
  332.  
  333. #define    DEFAULT_FONT    &__def_font    /* Built in 8x8 bitmap font            */
  334.  
  335. #define    _FNAMESIZE        58
  336.  
  337. /* Generic Font structure */
  338.  
  339. typedef struct {
  340.     char            name[_FNAMESIZE];/* Name of the font                */
  341.     short            fontType;        /* Type of font                        */
  342.     short            maxWidth;        /* Maximum character width            */
  343.     short            maxKern;        /* Maximum character kern            */
  344.     short            fontWidth;        /* Font width                        */
  345.     short            fontHeight;        /* Font height                        */
  346.     short            ascent;            /* Font ascent value                */
  347.     short            descent;        /* Font descent value                */
  348.     short            leading;        /* Font leading value                */
  349.     } font;
  350.  
  351. /* Character and font metrics structure */
  352.  
  353. typedef struct {
  354.     int                width;            /* Width of character or font        */
  355.     int                fontWidth;        /* Character width (tightest fit)    */
  356.     int                fontHeight;        /* Height of the font                */
  357.     int                ascent;            /* Ascent value                        */
  358.     int                descent;        /* Descent value                    */
  359.     int                leading;        /* Leading value                    */
  360.     int                kern;            /* Kern value                        */
  361.     } metrics;
  362.  
  363. /* Text settings structure */
  364.  
  365. typedef struct {
  366.     int                horiz_just;        /* Horizontal justfication            */
  367.     int                vert_just;        /* Vertical justification            */
  368.     int                dir;            /* Text drawing direction            */
  369.     int             sz_numerx;        /* Text x size numerator            */
  370.     int             sz_numery;        /* Text y size numerator            */
  371.     int                sz_denomx;        /* Text x size denominator            */
  372.     int                sz_denomy;        /* Text y size denominator            */
  373.     int                space_extra;    /* Space extra term                    */
  374.     font             *fnt;            /* Currently selected font            */
  375.     } text_settings;
  376.  
  377. /* Macros to access the (left,top) and (right,bottom) points of a
  378.  * rectangle.
  379.  */
  380.  
  381. #define    leftTop(r)        (((point *) &(r))[0])
  382. #define    rightBottom(r)    (((point *) &(r))[1])
  383.  
  384. typedef uchar    pattern[8];
  385. typedef color_t    pixpattern[8][8];
  386.  
  387. /* Attributes structure */
  388.  
  389. typedef struct {
  390.     color_t            color;            /* Foreground color                    */
  391.     color_t            backColor;        /* Background color                    */
  392.     int                markerSize;        /* Size of markers in pixels        */
  393.     marker_style    markerStyle;    /* Style of markers                    */
  394.     color_t            markerColor;    /* Color to draw markers in            */
  395.     color_t            bdr_bright;        /* Border bright color                */
  396.     color_t            bdr_dark;        /* Border dark color                */
  397.     point            CP;                /* Graphics pen position            */
  398.     write_mode        writeMode;        /* Scan conversion write mode op.    */
  399.     fill_style        penStyle;        /* Pen style                        */
  400.     int                penHeight;        /* Size of pen                        */
  401.     int                penWidth;
  402.     pattern            penPat;            /* Pattern for pen                    */
  403.     pixpattern        penPixPat;        /* Pixmap pattern for pen            */
  404.     rect            viewport;        /* Viewport dimensions                */
  405.     rect            clipRect;        /* Clipping rectangle dimensions    */
  406.     bool            clip;            /* Is clipping on?                    */
  407.     int                poly_type;        /* Polygon drawing type                */
  408.     text_settings    tsettings;        /* Text drawing attributes            */
  409.     } attributes;
  410.  
  411. /* Palette entry structure    */
  412.  
  413. typedef struct {
  414.     uchar    red;                    /* Blue component of color            */
  415.     uchar    green;                    /* Green component of color            */
  416.     uchar    blue;                    /* Blue component of color            */
  417.     } palette;
  418.  
  419. /* Maximum value for each palette entry component */
  420.  
  421. #define    PALMAX        255                /* Max value for palette components    */
  422.  
  423. /* Palette rotation directions */
  424.  
  425. #define    PAL_ROTATE_UP    0            /* Rotate the palette values up        */
  426. #define    PAL_ROTATE_DOWN    1            /* Rotate the palette values down    */
  427.  
  428. /* Border drawing routine styles */
  429.  
  430. #define    BDR_INSET    0                /* Interior is inset into screen    */
  431. #define    BDR_OUTSET    1                /* Interior is outset from screen    */
  432. #define    BDR_OUTLINE    2                /* Border is 3d outline                */
  433.  
  434. /* Bit Block Image header structure. The bit mask field is not used by
  435.  * the 256 color and above routines.
  436.  */
  437.  
  438. typedef struct {
  439.     ushort    pixelRows;                /* Number of rows in image            */
  440.     ushort    pixelColumns;            /* Number of columns in image        */
  441.     ushort    bytesPerRow;            /* Width of image in bytes            */
  442.     uchar    filler;                    /* Filler to keep word aligned        */
  443.     uchar    lastByteMask;            /* Last byte mask (16 color modes)    */
  444.     } image_header;
  445.  
  446. /* Icon structures. Each icon type is mode dependant, so be careful
  447.  * when using the structures that you are in the correct video mode.
  448.  * The mask is first used to punch a hole in the background, and the
  449.  * icon image data is then OR'ed onto the display.
  450.  *
  451.  * The format of the header for each icon type should be:
  452.  *
  453.  *        icon16        = { 32, 32, 16, 255 }
  454.  *        icon256        = { 32, 32, 32, 255 }
  455.  *        icon32k        = { 32, 32, 64, 255 }
  456.  *        icon16m        = { 32, 32, 96, 255 }
  457.  */
  458.  
  459. typedef struct {                    /* Basic icon structure                */
  460.     uchar            mask[128];        /* 32x32 monochrome image mask        */
  461.     image_header    image;            /* Image data header info            */
  462.     } icon_header;
  463.  
  464. typedef struct {
  465.     icon_header     icon;            /* Icon header information            */
  466.     uchar            data[512];        /* 32x32 16 color data                */
  467.     } icon16;
  468.  
  469. typedef struct {
  470.     icon_header     icon;            /* Icon header information            */
  471.     uchar            data[1024];        /* 32x32 256 color data                */
  472.     } icon256;
  473.  
  474. typedef struct {
  475.     icon_header     icon;            /* Icon header information            */
  476.     uchar            data[2048];        /* 32x32 32k color data                */
  477.     } icon32k;
  478.  
  479. typedef struct {
  480.     icon_header     icon;            /* Icon header information            */
  481.     uchar            data[2048];        /* 32x32 64k color data                */
  482.     } icon64k;
  483.  
  484. typedef struct {
  485.     icon_header     icon;            /* Icon header information            */
  486.     uchar            data[3072];        /* 32x32 16m color data                */
  487.     } icon16m;
  488.  
  489. /*---------------------- Inline functions as Macros -----------------------*/
  490.  
  491. #define    MGL_equalPoint(p1,p2)    ((p1).x == (p2).x && (p1).y == (p2).y)
  492.  
  493. #define    MGL_equalRect(r1,r2)    ((r1).left == (r2).left &&            \
  494.                                  (r1).top == (r2).top &&            \
  495.                                  (r1).right == (r2).right &&        \
  496.                                  (r1).bottom == (r2).bottom)
  497.  
  498. #define    MGL_emptyRect(r)        ((r).bottom <= (r).top ||             \
  499.                                  (r).right <= (r).left)
  500.  
  501. #define    MGL_disjointRect(r1,r2)    ((r1).right <= (r2).left ||            \
  502.                                  (r1).left >= (r2).right ||            \
  503.                                  (r1).bottom <= (r2).top ||            \
  504.                                  (r1).top >= (r2).bottom)
  505.  
  506. #define    MGL_offsetRect(r,dx,dy)                                        \
  507.     {    (r).left += dx; (r).right += dx;                            \
  508.         (r).top += dy; (r).bottom += dy; }
  509.  
  510. #define    MGL_insetRect(r,dx,dy)                                        \
  511.     {    (r).left += dx; (r).right -= dx;                            \
  512.         (r).top += dy; (r).bottom -= dy;                            \
  513.         if (MGL_emptyRect(r))                                        \
  514.             (r).left = (r).right = (r).top = (r).bottom = 0; }
  515.  
  516. #define    MGL_ptInRect(p,r)        ((p).x >= (r).left &&                \
  517.                                  (p).x < (r).right &&                \
  518.                                  (p).y >= (r).top &&                \
  519.                                  (p).y < (r).bottom)
  520.  
  521. #define    MGL_ptInRectCoord(x,y,r)    ((x) >= (r).left &&                \
  522.                                      (x) < (r).right &&                \
  523.                                      (y) >= (r).top &&                \
  524.                                      (y) < (r).bottom)
  525.  
  526. #define    MGL_pixel(p)        MGL_pixelCoord((p).x,(p).y)
  527. #define    MGL_getPixel(p)        MGL_getPixelCoord((p).x,(p).y)
  528. #define    MGL_moveTo(p)        MGL_moveToCoord((p).x,(p).y)
  529. #define MGL_moveRel(p)        MGL_moveRelCoord((p).x,(p).y)
  530. #define    MGL_line(p1,p2)        MGL_lineCoord((p1).x,(p1).y,(p2).x,(p2).y)
  531. #define    MGL_lineFast(p1,p2)    MGL_lineCoordFast((p1).x,(p1).y,(p2).x,(p2).y)
  532. #define    MGL_lineTo(p)        MGL_lineToCoord((p).x,(p).y)
  533. #define    MGL_lineRel(p)        MGL_lineRelCoord((p).x,(p).y);
  534. #define    MGL_rectPt(lt,rb)    MGL_rectCoord((lt).x,(lt).y,(rb).x,(rb).y)
  535. #define    MGL_rect(r)            MGL_rectCoord((r).left,(r).top,            \
  536.                                     (r).right,(r).bottom)
  537. #define    MGL_drawBorder(r,s,t)    MGL_drawBorderCoord((r).left,(r).top,    \
  538.                                     (r).right,(r).bottom,(s),(t))
  539. #define    MGL_fillRectPt(lt,rb)    MGL_fillRectCoord((lt).x,(lt).y,    \
  540.                                     (rb).x,(rb).y)
  541. #define    MGL_fillRect(r)            MGL_fillRectCoord((r).left,(r).top,    \
  542.                                     (r).right,(r).bottom)
  543. #define    MGL_getImage(r,image)    MGL_getImageCoord((r).left,(r).top,    \
  544.                                     (r).right,(r).bottom,image)
  545. #define    MGL_putImage(r,image,op)    MGL_putImageCoord((r).left,        \
  546.                                     (r).top,(r).right,(r).bottom,    \
  547.                                     image,op)
  548. #define    MGL_imageSize(r)        MGL_imageSizeCoord((r).left,(r).top,\
  549.                                     (r).right,(r).bottom)
  550. #define    MGL_copyImage(r,dl,dt,sp,dp) \
  551.                                 MGL_copyImageCoord((r).left,(r).top,\
  552.                                     (r).right,(r).bottom,dl,dt,sp,dp);
  553. #define    MGL_getDivot(r,divot)    MGL_getDivotCoord((r).left,(r).top,    \
  554.                                     (r).right,(r).bottom,divot)
  555. #define    MGL_divotSize(r)        MGL_divotSizeCoord((r).left,(r).top,\
  556.                                     (r).right,(r).bottom)
  557.  
  558. #ifdef    __cplusplus
  559.  
  560. // Undefine a number of troublesome macros that work with rectangles. We
  561. // will define them again later on as inline functions. This is a hack,
  562. // but it works, assuming you have left(), top(), right() and bottom()
  563. // member functions for your rectangle class.
  564.  
  565. #undef    MGL_rect
  566. #undef    MGL_drawBorder
  567. #undef    MGL_fillRect
  568. #undef    MGL_getImage
  569. #undef    MGL_putImage
  570. #undef    MGL_copyImage
  571. #undef    MGL_imageSize
  572. #undef    MGL_getDivot
  573. #undef    MGL_divotSize
  574. #endif
  575.  
  576. /*--------------------------- Global Variables ----------------------------*/
  577.  
  578. extern    pattern    __empty_pat;
  579. extern    pattern    __gray_pat;
  580. extern    pattern __solid_pat;
  581. extern    bool    _installMouse;
  582. extern    cursor    DEF_CURSOR;
  583. extern    font    __def_font;
  584.  
  585. /*------------------------- Function Prototypes ---------------------------*/
  586.  
  587. #ifdef    __cplusplus
  588. extern "C" {            /* Use "C" linkage when in C++ mode    */
  589. #endif
  590.  
  591. /* In mgraph.c */
  592.  
  593. int     PUBAPI MGL_result(void);
  594. void    PUBAPI MGL_setResult(int result);
  595. char     * PUBAPI MGL_errorMsg(int err);
  596. char    * PUBAPI MGL_modeName(int mode);
  597. char    * PUBAPI MGL_driverName(int driver);
  598. color_t    PUBAPI MGL_maxColor(void);
  599. int        PUBAPI MGL_maxPage(void);
  600. int     PUBAPI MGL_sizex(void);
  601. int     PUBAPI MGL_sizey(void);
  602. int        PUBAPI MGL_getActivePage(void);
  603. int        PUBAPI MGL_getVisualPage(void);
  604. int        PUBAPI MGL_getDriver(void);
  605. int        PUBAPI MGL_getMode(void);
  606. bool    PUBAPI MGL_doubleBuffer(void);
  607. void    PUBAPI MGL_singleBuffer(void);
  608. void    PUBAPI MGL_swapBuffers(void);
  609. int     PUBAPI MGL_getAspectRatio(void);
  610. void     PUBAPI MGL_setAspectRatio(int aspectRatio);
  611. void     PUBAPI MGL_setGraphMode(void);
  612. void     PUBAPI MGL_restoreCRTMode(void);
  613. int     PUBAPI MGL_registerDriver(const char *name,void *driver);
  614. void     PUBAPI MGL_detectGraph(int far *graphdriver,int far *graphmode);
  615. void     PUBAPI MGL_init(int *graphdriver,int *graphmode,const char *pathtodriver);
  616. void     PUBAPI MGL_exit(void);
  617. void     PUBAPI MGL_setBufSize(unsigned size);
  618. void    PUBAPI MGL_slowPalette(bool slow);
  619. void    PUBAPI MGL_useBIOSPalette(bool bios);
  620. void    PUBAPI MGL_slowSuperVGA(bool slow);
  621.  
  622. /* In modes.c */
  623.  
  624. int     * PUBAPI MGL_availableModes(int driver);
  625. int        PUBAPI MGL_availablePages(int driver,int mode);
  626.  
  627. /* In pixel.c */
  628.  
  629. void    PUBAPI MGL_beginPixel(void);
  630. void     PUBAPI MGL_pixelCoord(int x,int y);
  631. color_t    PUBAPI MGL_getPixelCoord(int x,int y);
  632. void    PUBAPI MGL_endPixel(void);
  633.  
  634. /* In line.c */
  635.  
  636. void     PUBAPI MGL_moveToCoord(int x,int y);
  637. void     PUBAPI MGL_moveRelCoord(int dx,int dy);
  638. int     PUBAPI MGL_getX(void);
  639. int     PUBAPI MGL_getY(void);
  640. void    PUBAPI MGL_getCP(point* CP);
  641. void     PUBAPI MGL_lineCoord(int x1,int y1,int x2,int y2);
  642. void    PUBAPI MGL_lineCoordFast(int x1,int y1,int x2,int y2);
  643. void     PUBAPI MGL_lineToCoord(int x,int y);
  644. void     PUBAPI MGL_lineRelCoord(int dx,int dy);
  645. bool    PUBAPI MGL_clipLine(point *p1,point *p2,rect r);
  646. void    PUBAPI MGL_lineEngine(int x1,int y1,int x2,int y2,
  647.         void (_cdecl *plotPoint)(int x,int y));
  648.  
  649. /* In polyline.c */
  650.  
  651. void     PUBAPI MGL_marker(point p);
  652. void    PUBAPI MGL_polyPoint(int count,point *vArray);
  653. void     PUBAPI MGL_polyMarker(int count,point *vArray);
  654. void     PUBAPI MGL_polyLine(int count,point *vArray);
  655.  
  656. /* In polygon.c */
  657.  
  658. bool     PUBAPI MGL_fillPolygon(int count,point *vArray,
  659.         int xOffset,int yOffset);
  660. bool    PUBAPI MGL_fillPolygonFast(int count,point *vArray,
  661.         int xOffset,int yOffset);
  662. bool     PUBAPI MGL_fillGouraudPolygon(int count,point *vArray,
  663.         color_t *cArray,int xOffset,int yOffset);
  664.  
  665. /* Note: The above fast polygon routine and gouraud shaded polygon
  666.  *          routines only work with convex polygons
  667.  */
  668.  
  669. /* In rectangl.c */
  670.  
  671. void     PUBAPI MGL_rectCoord(int left,int top,int right,int bottom);
  672. void     PUBAPI MGL_fillRectCoord(int left,int top,int right,int bottom);
  673.  
  674. /* In border.c */
  675.  
  676. void    PUBAPI MGL_drawBorderCoord(int left,int top,int right,int bottom,
  677.         int style,int thickness);
  678. void     PUBAPI MGL_drawHDivider(int y,int x1,int x2);
  679. void     PUBAPI MGL_drawVDivider(int x,int y1,int y2);
  680.  
  681. /* In ellipse.c */
  682.  
  683. bool     PUBAPI MGL_ellipseArc(rect extentRect,int startAngle,int endAngle);
  684. bool     PUBAPI MGL_ellipseArcCoord(int x,int y,int xradius,int yradius,
  685.         int startAngle,int endAngle);
  686. void    PUBAPI MGL_getArcCoords(arc_coords *coords);
  687. bool     PUBAPI MGL_ellipse(rect extentRect);
  688. bool     PUBAPI MGL_ellipseCoord(int x,int y,int xradius,int yradius);
  689. bool     PUBAPI MGL_fillEllipseArc(rect extentRect,int startAngle,int endAngle);
  690. bool     PUBAPI MGL_fillEllipseArcCoord(int x,int y,int xradius,int yradius,
  691.         int startAngle,int endAngle);
  692. bool    PUBAPI MGL_fillEllipse(rect extentRect);
  693. bool     PUBAPI MGL_fillEllipseCoord(int x,int y,int xradius,int yradius);
  694. void    PUBAPI MGL_ellipseEngine(rect extentRect,
  695.         void (_cdecl *setup)(int topY,int botY,int left,int right),
  696.         void (_cdecl *set4pixels)(bool inc_x,bool inc_y,bool region1),
  697.         void (_cdecl *finished)(void));
  698.  
  699. /* In attr.c */
  700.  
  701. color_t    PUBAPI MGL_packColor(uchar R,uchar G,uchar B);
  702. void    PUBAPI MGL_unpackColor(color_t color,uchar *R,uchar *G,uchar *B);
  703. void    PUBAPI MGL_setMarkerSize(int size);
  704. int        PUBAPI MGL_getMarkerSize(void);
  705. void    PUBAPI MGL_setMarkerStyle(int style);
  706. int        PUBAPI MGL_getMarkerStyle(void);
  707. void    PUBAPI MGL_setMarkerColor(color_t color);
  708. color_t    PUBAPI MGL_getMarkerColor(void);
  709. void    PUBAPI MGL_setBorderColors(color_t bright,color_t dark);
  710. void    PUBAPI MGL_getBorderColors(color_t *bright,color_t *dark);
  711. color_t    PUBAPI MGL_defaultColor(void);
  712. void     PUBAPI MGL_setWriteMode(int mode);
  713. int     PUBAPI MGL_getWriteMode(void);
  714. void     PUBAPI MGL_setPenStyle(int style);
  715. int     PUBAPI MGL_getPenStyle(void);
  716. void     PUBAPI MGL_setPenBitmapPattern(pattern *pat);
  717. void     PUBAPI MGL_getPenBitmapPattern(pattern *pat);
  718. void     PUBAPI MGL_setPenPixmapPattern(pixpattern *pat);
  719. void     PUBAPI MGL_getPenPixmapPattern(pixpattern *pat);
  720. void    PUBAPI MGL_setPenSize(int height,int width);
  721. void     PUBAPI MGL_getPenSize(int *height,int *width);
  722. void    PUBAPI MGL_setPolygonType(int type);
  723. int        PUBAPI MGL_getPolygonType(void);
  724. void     PUBAPI MGL_getAttributes(attributes *attr);
  725. void     PUBAPI MGL_restoreAttributes(attributes *attr);
  726. void     PUBAPI MGL_defaultAttributes(void);
  727.  
  728. /* In palette.c */
  729.  
  730. color_t    PUBAPI MGL_realColor(int color);
  731. void    PUBAPI MGL_setPaletteSnowLevel(int level);
  732. int        PUBAPI MGL_getPaletteSnowLevel(void);
  733. void     PUBAPI MGL_setPaletteEntry(int entry,uchar red,uchar green,uchar blue);
  734. void     PUBAPI MGL_getPaletteEntry(int entry,uchar *red,uchar *green,
  735.         uchar *blue);
  736. void     PUBAPI MGL_setPalette(palette *pal,int numColors,int startIndex);
  737. void     PUBAPI MGL_getPalette(palette *pal,int numColors,int startIndex);
  738. void    PUBAPI MGL_rotatePalette(palette *pal,int numColors,int direction);
  739. bool    PUBAPI MGL_fadePalette(palette *dest,palette *src,
  740.         int numColors,uchar intensity);
  741. int        PUBAPI MGL_getPaletteSize(void);
  742. void    PUBAPI MGL_getDefaultPalette(palette *pal);
  743. void     PUBAPI MGL_setDefaultPalette(void);
  744.  
  745. /* In viewport.c */
  746.  
  747. void     PUBAPI MGL_setViewport(rect view);
  748. void    PUBAPI MGL_setRelViewport(rect view);
  749. void     PUBAPI MGL_getViewport(rect *view);
  750. void    PUBAPI MGL_globalToLocal(point *p);
  751. void    PUBAPI MGL_localToGlobal(point *p);
  752. int     PUBAPI MGL_maxx(void);
  753. int     PUBAPI MGL_maxy(void);
  754. void     PUBAPI MGL_clearViewport(void);
  755. void     PUBAPI MGL_setClipRect(rect clip);
  756. void     PUBAPI MGL_getClipRect(rect *clip);
  757. void     PUBAPI MGL_setClipMode(bool mode);
  758. bool     PUBAPI MGL_getClipMode(void);
  759. void    PUBAPI MGL_pushViewport(void);
  760. void    PUBAPI MGL_popViewport(void);
  761.  
  762. /* In copypixe.c */
  763.  
  764. void     PUBAPI MGL_getImageCoord(int left,int top,int right,int bottom,
  765.         void *image);
  766. void    PUBAPI MGL_putImageCoord(int left,int top,int right,int bottom,
  767.         void *image,int op);
  768. long    PUBAPI MGL_imageSizeCoord(int left,int top,int right,int bottom);
  769. void    PUBAPI MGL_putMonoImage(int x,int y,int byteWidth,int height,
  770.         void *image);
  771. void     PUBAPI MGL_getDivotCoord(int left,int top,int right,int bottom,
  772.         void *divot);
  773. void     PUBAPI MGL_putDivot(void *divot);
  774. long     PUBAPI MGL_divotSizeCoord(int left,int top,int right,int bottom);
  775. void    PUBAPI MGL_copyImageCoord(int left,int top,int right,int bottom,
  776.         int dstLeft,int dstTop,int srcPage,int dstPage);
  777. void    PUBAPI MGL_putIcon(int x,int y,icon_header *icon);
  778.  
  779. /* In text.c */
  780.  
  781. void     PUBAPI MGL_setTextJustify(int horiz,int vert);
  782. void     PUBAPI MGL_getTextJustify(int *horiz,int *vert);
  783. void     PUBAPI MGL_setTextDirection(int direction);
  784. int     PUBAPI MGL_getTextDirection(void);
  785. void    PUBAPI MGL_setTextSize(int numerx,int denomx,int numery,int denomy);
  786. void    PUBAPI MGL_getTextSize(int *numerx,int *denomx,
  787.         int *numery,int *denomy);
  788. void    PUBAPI MGL_setSpaceExtra(int extra);
  789. int        PUBAPI MGL_getSpaceExtra(void);
  790. void    PUBAPI MGL_setTextSettings(text_settings *settings);
  791. void    PUBAPI MGL_getTextSettings(text_settings *settings);
  792. int     PUBAPI MGL_textHeight(void);
  793. int     PUBAPI MGL_textWidth(const char *str);
  794. int        PUBAPI MGL_charWidth(char ch);
  795. void    PUBAPI MGL_getFontMetrics(metrics *metrics);
  796. void    PUBAPI MGL_getCharMetrics(char ch,metrics *metrics);
  797. int        PUBAPI MGL_maxCharWidth(void);
  798. void     PUBAPI MGL_drawStr(const char *str);
  799. void    PUBAPI MGL_drawStrXY(int x,int y,const char *str);
  800. void    PUBAPI MGL_underScoreLocation(int *x,int *y,
  801.         const char *str);
  802. font     * PUBAPI MGL_loadFont(const char *fontname);
  803. bool    PUBAPI MGL_availableFont(const char *fontname);
  804. bool    PUBAPI MGL_unloadFont(font *font);
  805. bool    PUBAPI MGL_useFont(font *font);
  806. font     * PUBAPI MGL_getFont(void);
  807. bool    PUBAPI MGL_vecFontEngine(int x,int y,const char *str,
  808.         void (_cdecl *move)(int x,int y),void (_cdecl *draw)(int x,int y));
  809.  
  810. /* In mglmouse.c */
  811.  
  812. void    PUBAPI MS_obscure(void);
  813. void    PUBAPI MS_unobscure(void);
  814.  
  815. /* Globals to access routines within loaded driver */
  816.  
  817. extern void (_cdecl *MGL_beginDrawing)(void);
  818. extern void (_cdecl *MGL_endDrawing)(void);
  819. extern void (_cdecl *MGL_setColor)(color_t color);
  820. extern color_t (_cdecl *MGL_getColor)(void);
  821. extern void (_cdecl *MGL_setBackColor)(color_t color);
  822. extern color_t (_cdecl *MGL_getBackColor)(void);
  823. extern void (_cdecl *MGL_setCursorColor)(color_t color);
  824. extern color_t (_cdecl *MGL_getCursorColor)(void);
  825. extern void (_cdecl *MGL_clearDevice)(void);
  826. extern void (_cdecl *MGL_scanLine)(int y,int x1,int x2);
  827. extern void (_cdecl *MGL_beginGouraud)(void);
  828. extern void (_cdecl *MGL_gouraudScanLine)(int y,int x1,int x2,color_t c1,
  829.     color_t c2);
  830. extern void (_cdecl *MGL_endGouraud)(void);
  831. extern void (_cdecl *MGL_setActivePage)(int page);
  832. extern void (_cdecl *MGL_setVisualPage)(int page);
  833. extern int (_cdecl *MGL_scanRightForColor)(int x,int y,color_t color);
  834. extern int (_cdecl *MGL_scanLeftForColor)(int x,int y,color_t color);
  835. extern int (_cdecl *MGL_scanRightWhileColor)(int x,int y,color_t color);
  836. extern int (_cdecl *MGL_scanLeftWhileColor)(int x,int y,color_t color);
  837. extern void (_cdecl *MGL_vSync)(void);
  838.  
  839. /* In order to allow the driver files to be linked in, we need to provide
  840.  * the following declarations so that the linker can perform the appropriate
  841.  * fixup's at link time.
  842.  */
  843.  
  844. extern void _cdecl EGA_driver(void);
  845. extern void _cdecl VGA_driver(void);
  846. extern void _cdecl VGA256_driver(void);
  847. extern void _cdecl VGAX_driver(void);
  848. extern void _cdecl SVGA256_driver(void);
  849. extern void _cdecl SVGA32K_driver(void);
  850. extern void _cdecl SVGA64K_driver(void);
  851. extern void _cdecl SVGA16M_driver(void);
  852. extern void _cdecl SVGAS3_driver(void);
  853.  
  854. #ifdef    __cplusplus
  855. }                        /* End of "C" linkage for C++    */
  856.  
  857. #ifdef    __RECT_HPP
  858.  
  859. // Redefine a number of troublesome macros as inline functions for C++
  860.  
  861. inline void MGL_rect(Rect r)
  862. {
  863.     MGL_rectCoord(r.left(),r.top(),r.right(),r.bottom());
  864. }
  865.  
  866. inline void MGL_drawBorder(Rect r,int style,int width)
  867. {
  868.     MGL_drawBorderCoord(r.left(),r.top(),r.right(),r.bottom(),style,width);
  869. }
  870.  
  871. inline void MGL_fillRect(Rect r)
  872. {
  873.     MGL_fillRectCoord(r.left(),r.top(),r.right(),r.bottom());
  874. }
  875.  
  876. inline void MGL_getImage(Rect r,void *image)
  877. {
  878.     MGL_getImageCoord(r.left(),r.top(),r.right(),r.bottom(),image);
  879. }
  880.  
  881. inline void MGL_putImage(Rect r,void *image,int op)
  882. {
  883.     MGL_putImageCoord(r.left(),r.top(),r.right(),r.bottom(),image,op);
  884. }
  885.  
  886. inline void    MGL_copyImage(rect r,int dstLeft,int dstTop,int srcPage,int dstPage)
  887. {
  888.     MGL_copyImageCoord(r.left(),r.top(),r.right(),r.bottom(),
  889.         dstLeft,dstTop,srcPage,dstPage);
  890. }
  891.  
  892. inline long MGL_imageSize(Rect r)
  893. {
  894.     return MGL_imageSizeCoord(r.left(),r.top(),r.right(),r.bottom());
  895. }
  896.  
  897. inline void MGL_getDivot(Rect r,void *divot)
  898. {
  899.     MGL_getDivotCoord(r.left(),r.top(),r.right(),r.bottom(),divot);
  900. }
  901.  
  902. inline long MGL_divotSize(Rect r)
  903. {
  904.     return MGL_divotSizeCoord(r.left(),r.top(),r.right(),r.bottom());
  905. }
  906. #endif    /* __RECT_HPP */
  907.  
  908. #endif    /* __cplusplus */
  909.  
  910. #endif    /* __MGRAPH_H */
  911.