home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / examples / mgldemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  64.5 KB  |  2,410 lines

  1. /****************************************************************************
  2. *
  3. *                        MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: mgldemo.c $
  9. * Version:        $Revision: 1.3 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MS DOS)
  13. *
  14. * Description:    Demo program for the MegaGraph graphics library. This
  15. *                program is very similar to the graphics demo program
  16. *                that comes with Borland's range of compiler, but has
  17. *                been extended to fully test the MGL library.
  18. *
  19. *                This is also useful as a comparison between the MGL and
  20. *                Borland's BGI environment.
  21. *
  22. *                NOTE:    Fonts are searched for relative to the directory
  23. *                        where the driver files are found. This demo
  24. *                        expects the driver files to be in the current
  25. *                        directory or in the previous subdirectory, and all
  26. *                        fonts to be in the directory 'fonts' relative to
  27. *                        the directory where the drivers were found.
  28. *
  29. *                        If the driver files are linked with the program
  30. *                        code, fonts are searched relative to the path
  31. *                        specified to MGL_init().
  32. *
  33. *                If you wish to compile the flood fill demo, define the
  34. *                macro FLOODFILL_DEMO, but you will also need to compile
  35. *                and link the program with the 'ffill.c' source file.
  36. *
  37. *
  38. * $Id: mgldemo.c 1.3 1994/03/10 09:25:52 kjb release $
  39. *
  40. ****************************************************************************/
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <stdarg.h>
  45. #include <string.h>
  46. #include <dos.h>
  47. #include <ctype.h>
  48. #include <conio.h>
  49. #include <math.h>
  50.  
  51. #include "mgraph.h"
  52. #include "mouse.h"
  53. #include "getopt.h"
  54.  
  55. /*--------------------------- Macros and typedefs -------------------------*/
  56.  
  57. #define ESC        0x1B
  58.  
  59. /* Macro to swap two integer values */
  60.  
  61. #define SWAP(a,b)    { a^=b; b^=a; a^=b; }
  62.  
  63. #define M_PI        3.14159265358979323846
  64.  
  65. /*----------------------------- Global Variables --------------------------*/
  66.  
  67. int                driver;                /* Graphics device driver type        */
  68. int                mode;                /* Selected graphics mode            */
  69. color_t            maxcolor;            /* Maximum color value                */
  70. int                palsize;            /* Size of video palette            */
  71. int                aspect;                /* Video mode aspect ratio            */
  72. double            aspectRatio;        /* Aspect ratio of pixels            */
  73. int                err;                /* Error code                        */
  74. palette            far *pal;            /* Pointer to palette on heap        */
  75. text_settings    defaultTextSettings;/* Default text settings            */
  76. font            far *largeFont;        /* Large font for labelling            */
  77. int                forceDriver = grDETECT;
  78. bool            slowpalette = false;
  79. bool            biospalette = false;
  80. int                snowlevel = -1;
  81.  
  82. /* Viewport rectangles used throught program    */
  83.  
  84. rect    fullView;                    /* Full screen viewport                */
  85. rect    titleView;                    /* Title text viewport                */
  86. rect    statusView;                    /* Status line viewport                */
  87. rect    demoView;                    /* Viewport to draw demo stuff in    */
  88.  
  89. char *markerStyle[] = {                /* Marker style names                */
  90.     "MARKER_SQUARE",
  91.     "MARKER_CIRCLE",
  92.     "MARKER_X"
  93.     };
  94.  
  95. char *writeMode[] = {                /* Write mode operation names        */
  96.     "REPLACE_MODE",
  97.     "AND_MODE",
  98.     "OR_MODE",
  99.     "XOR_MODE"
  100.     };
  101.  
  102. char *fillStyle[] = {                /* Fill style names                    */
  103.     "SOLID_PATTERN",
  104.     "BITMAP_PATTERN_OPAQUE",
  105.     "BITMAP_PATTERN_TRANSPARENT",
  106.     "PIXMAP_PATTERN"
  107.     };
  108.  
  109. char *polyStyle[] = {                /* Polygon style names                */
  110.     "CONVEX_POLYGON",
  111.     "COMPLEX_POLYGON",
  112.     "AUTO_POLYGON"
  113.     };
  114.  
  115. char *textDirection[] = {            /* Text direction names                */
  116.     "LEFT_DIR",
  117.     "UP_DIR",
  118.     "RIGHT_DIR",
  119.     "DOWN_DIR"
  120.     };
  121.  
  122. char *horizJust[] = {                /* Horizontal justification names    */
  123.     "LEFT_TEXT",
  124.     "CENTER_TEXT",
  125.     "RIGHT_TEXT"
  126.     };
  127.  
  128. char *vertJust[] = {                /* Vertical justification names        */
  129.     "TOP_TEXT",
  130.     "CENTER_TEXT",
  131.     "BOTTOM_TEXT"
  132.     };
  133.  
  134. /* Names of all fonts on disk */
  135.  
  136. #define    NUMFONTS    (sizeof(fontFilename) / sizeof(fontFilename[0]))
  137.  
  138. char *fontFilename[] = {
  139.     "astrolog.fnt",
  140.     "cyrillc.fnt",
  141.     "gotheng.fnt",
  142.     "gothger.fnt",
  143.     "gothita.fnt",
  144.     "greekc.fnt",
  145.     "greekcs.fnt",
  146.     "greeks.fnt",
  147.     "italicc.fnt",
  148.     "italiccs.fnt",
  149.     "italict.fnt",
  150.     "japanese.fnt",
  151.     "little.fnt",
  152.     "mathbig.fnt",
  153.     "mathsmal.fnt",
  154.     "musical.fnt",
  155.     "romanc.fnt",
  156.     "romancs.fnt",
  157.     "romand.fnt",
  158.     "romans.fnt",
  159.     "romant.fnt",
  160.     "scriptc.fnt",
  161.     "scripts.fnt",
  162.     "symbol.fnt",
  163.     };
  164.  
  165. /* Different mouse cursors */
  166.  
  167. cursor CHECK = {
  168.     0xFFF0, 0xFFE0, 0xFFC0, 0xFF81,
  169.     0xFF03, 0x0607, 0x000F, 0x001F,
  170.     0x803F, 0xC07F, 0xE0FF, 0xF1FF,
  171.     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  172.  
  173.     0x0000, 0x0006, 0x000C, 0x0018,
  174.     0x0030, 0x0060, 0x70C0, 0x3980,
  175.     0x1F00, 0x0E00, 0x0400, 0x0000,
  176.     0x0000, 0x0000, 0x0000, 0x0000,
  177.     0x0005, 0x000A };
  178.  
  179. cursor CROSS = {
  180.     0xF01F, 0xE00F, 0xC007, 0x8003,
  181.     0x0441, 0x0C61, 0x0381, 0x0381,
  182.     0x0381, 0x0C61, 0x0441, 0x8003,
  183.     0xC007, 0xE00F, 0xF01F, 0xFFFF,
  184.  
  185.     0x0000, 0x07C0, 0x0920, 0x1110,
  186.     0x2108, 0x4004, 0x4004, 0x783C,
  187.     0x4004, 0x4004, 0x2108, 0x1110,
  188.     0x0920, 0x07C0, 0x0000, 0x0000,
  189.     0x0007, 0x0007 };
  190.  
  191. cursor GLOVE = {
  192.     0xF3FF, 0xE1FF, 0xE1FF, 0xE1FF,
  193.     0xE1FF, 0xE049, 0xE000, 0x8000,
  194.     0x0000, 0x0000, 0x07FC, 0x07F8,
  195.     0x9FF9, 0x8FF1, 0xC003, 0xE007,
  196.  
  197.     0x0C00, 0x1200, 0x1200, 0x1200,
  198.     0x1200, 0x13B6, 0x1249, 0x7249,
  199.     0x9249, 0x9001, 0x9001, 0x8001,
  200.     0x4002, 0x4002, 0x2004, 0x1FF8,
  201.     0x0004, 0x0000 };
  202.  
  203. cursor IBEAM = {
  204.     0xF39F, 0xFD7F, 0xFEFF, 0xFEFF,
  205.     0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF,
  206.     0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF,
  207.     0xFEFF, 0xFEFF, 0xFD7F, 0xF39F,
  208.  
  209.     0x0C60, 0x0280, 0x0100, 0x0100,
  210.     0x0100, 0x0100, 0x0100, 0x0100,
  211.     0x0100, 0x0100, 0x0100, 0x0100,
  212.     0x0100, 0x0100, 0x0280, 0x0C60,
  213.     0x0007, 0x0008 };
  214.  
  215. /* Array of useful patterns */
  216.  
  217. #define    NUMPATS    (sizeof(bitpat) / sizeof(bitpat[0]))
  218.  
  219. pattern bitpat[] = {
  220.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  221.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  222.     {0x7F, 0xFF, 0xF7, 0xFF, 0x7F, 0xFF, 0xF7, 0xFF},
  223.     {0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77},
  224.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  225.     {0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF},
  226.     {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
  227.     {0xEE, 0xDD, 0xBB, 0x77, 0xEE, 0xDD, 0xBB, 0x77},
  228.     {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88},
  229.     {0xB1, 0x30, 0x03, 0x1B, 0xD8, 0xC0, 0x0C, 0x8D},
  230.     {0x80, 0x10, 0x02, 0x20, 0x01, 0x08, 0x40, 0x04},
  231.     {0xFF, 0x88, 0x88, 0x88, 0xFF, 0x88, 0x88, 0x88},
  232.     {0xFF, 0x80, 0x80, 0x80, 0xFF, 0x08, 0x08, 0x08},
  233.     {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  234.     {0x80, 0x40, 0x20, 0x00, 0x02, 0x04, 0x08, 0x00},
  235.     {0x82, 0x44, 0x39, 0x44, 0x82, 0x01, 0x01, 0x01},
  236.     {0xF8, 0x74, 0x22, 0x47, 0x8F, 0x17, 0x22, 0x71},
  237.     {0x55, 0xA0, 0x40, 0x40, 0x55, 0x0A, 0x04, 0x04},
  238.     {0x20, 0x50, 0x88, 0x88, 0x88, 0x88, 0x05, 0x02},
  239.     {0xBF, 0x00, 0xBF, 0xBF, 0xB0, 0xB0, 0xB0, 0xB0},
  240.  
  241.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  242.     {0x80, 0x00, 0x08, 0x00, 0x80, 0x00, 0x08, 0x00},
  243.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  244.     {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22},
  245.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  246.     {0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00},
  247.     {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88},
  248.     {0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00},
  249.     {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80},
  250.     {0xAA, 0x00, 0x80, 0x00, 0x88, 0x00, 0x80, 0x00},
  251.     {0xFF, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
  252.     {0x08, 0x1C, 0x22, 0xC1, 0x80, 0x01, 0x02, 0x04},
  253.     {0x88, 0x14, 0x22, 0x41, 0x88, 0x00, 0xAA, 0x00},
  254.     {0x40, 0xA0, 0x00, 0x00, 0x04, 0x0A, 0x00, 0x00},
  255.     {0x03, 0x84, 0x48, 0x30, 0x0C, 0x02, 0x01, 0x01},
  256.     {0x80, 0x80, 0x41, 0x3E, 0x08, 0x08, 0x14, 0xE3},
  257.     {0x10, 0x20, 0x54, 0xAA, 0xFF, 0x02, 0x04, 0x08},
  258.     {0x77, 0x89, 0x8F, 0x8F, 0x77, 0x98, 0xF8, 0xF8},
  259.     {0x00, 0x08, 0x14, 0x2A, 0x55, 0x2A, 0x14, 0x08},
  260.     {0x00, 0x08, 0x14, 0x2A, 0x55, 0x2A, 0x14, 0x08},
  261.  
  262.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  263.     {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  264.     {0x80, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00},
  265.     {0x88, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00},
  266.     {0x88, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00},
  267.     {0x88, 0x00, 0x20, 0x00, 0x88, 0x00, 0x00, 0x00},
  268.     {0x88, 0x00, 0x20, 0x00, 0x88, 0x00, 0x02, 0x00},
  269.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x02, 0x00},
  270.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  271.     {0xA8, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  272.     {0xA8, 0x00, 0x22, 0x00, 0x8A, 0x00, 0x22, 0x00},
  273.     {0xAA, 0x00, 0x22, 0x00, 0x8A, 0x00, 0x22, 0x00},
  274.     {0xAA, 0x00, 0x22, 0x00, 0xAA, 0x00, 0x22, 0x00},
  275.     {0xAA, 0x00, 0xA2, 0x00, 0xAA, 0x00, 0x22, 0x00},
  276.     {0xAA, 0x00, 0xA2, 0x00, 0xAA, 0x00, 0x2A, 0x00},
  277.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0x2A, 0x00},
  278.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  279.     {0xAA, 0x40, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  280.     {0xAA, 0x40, 0xAA, 0x00, 0xAA, 0x04, 0xAA, 0x00},
  281.     {0xAA, 0x44, 0xAA, 0x00, 0xAA, 0x04, 0xAA, 0x00},
  282.     {0xAA, 0x44, 0xAA, 0x00, 0xAA, 0x44, 0xAA, 0x00},
  283.     {0xAA, 0x44, 0xAA, 0x10, 0xAA, 0x44, 0xAA, 0x00},
  284.     {0xAA, 0x44, 0xAA, 0x10, 0xAA, 0x44, 0xAA, 0x01},
  285.     {0xAA, 0x44, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x01},
  286.     {0xAA, 0x44, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x11},
  287.     {0xAA, 0x54, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x11},
  288.     {0xAA, 0x54, 0xAA, 0x11, 0xAA, 0x45, 0xAA, 0x11},
  289.     {0xAA, 0x55, 0xAA, 0x11, 0xAA, 0x45, 0xAA, 0x11},
  290.     {0xAA, 0x55, 0xAA, 0x11, 0xAA, 0x55, 0xAA, 0x11},
  291.     {0xAA, 0x55, 0xAA, 0x51, 0xAA, 0x55, 0xAA, 0x11},
  292.     {0xAA, 0x55, 0xAA, 0x51, 0xAA, 0x55, 0xAA, 0x15},
  293.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x15},
  294.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  295.     {0xEA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  296.     {0xEA, 0x55, 0xAA, 0x55, 0xAE, 0x55, 0xAA, 0x55},
  297.     {0xEE, 0x55, 0xAA, 0x55, 0xAE, 0x55, 0xAA, 0x55},
  298.     {0xEE, 0x55, 0xAA, 0x55, 0xEE, 0x55, 0xAA, 0x55},
  299.     {0xEE, 0x55, 0xBA, 0x55, 0xEE, 0x55, 0xAA, 0x55},
  300.     {0xEE, 0x55, 0xBA, 0x55, 0xEE, 0x55, 0xAB, 0x55},
  301.     {0xEE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xAB, 0x55},
  302.     {0xEE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xBB, 0x55},
  303.     {0xFE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xBB, 0x55},
  304.     {0xFE, 0x55, 0xBB, 0x55, 0xEF, 0x55, 0xBB, 0x55},
  305.     {0xFF, 0x55, 0xBB, 0x55, 0xEF, 0x55, 0xBB, 0x55},
  306.     {0xFF, 0x55, 0xBB, 0x55, 0xFF, 0x55, 0xBB, 0x55},
  307.     {0xFF, 0x55, 0xFB, 0x55, 0xFF, 0x55, 0xBB, 0x55},
  308.     {0xFF, 0x55, 0xFB, 0x55, 0xFF, 0x55, 0xBF, 0x55},
  309.     {0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xBF, 0x55},
  310.     {0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55},
  311.     {0xFF, 0xD5, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55},
  312.     {0xFF, 0xD5, 0xFF, 0x55, 0xFF, 0x5D, 0xFF, 0x55},
  313.     {0xFF, 0xDD, 0xFF, 0x55, 0xFF, 0x5D, 0xFF, 0x55},
  314.     {0xFF, 0xDD, 0xFF, 0x55, 0xFF, 0xDD, 0xFF, 0x55},
  315.     {0xFF, 0xDD, 0xFF, 0x75, 0xFF, 0xDD, 0xFF, 0x55},
  316.     {0xFF, 0xDD, 0xFF, 0x75, 0xFF, 0xDD, 0xFF, 0x57},
  317.     {0xFF, 0xDD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x57},
  318.     {0xFF, 0xDD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x77},
  319.     {0xFF, 0xFD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x77},
  320.     {0xFF, 0xFD, 0xFF, 0x77, 0xFF, 0xDF, 0xFF, 0x77},
  321.     {0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xDF, 0xFF, 0x77},
  322.     {0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xFF, 0xFF, 0x77},
  323.     {0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x77},
  324.     {0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x7F},
  325.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F},
  326.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
  327.     };
  328.  
  329. /*---------------------------- Implementation -----------------------------*/
  330.  
  331. void help(void)
  332. /****************************************************************************
  333. *
  334. * Function:        help
  335. *
  336. * Description:    Provide usage information about the program.
  337. *
  338. ****************************************************************************/
  339. {
  340.     int        i,driver,mode;
  341.     int        *modeList;
  342.  
  343.     MGL_detectGraph(&driver,&mode);
  344.     if (forceDriver < driver && forceDriver != grDETECT)
  345.         driver = forceDriver;
  346.     modeList = MGL_availableModes(driver);
  347.  
  348.     printf("Usage: mgldemo [-ega|vga|vesa] [-hfbsp] [mode]\n\n");
  349.     printf("-ega    Force system to work as standard 256k EGA\n");
  350.     printf("-vga    Force system to work as standard VGA\n");
  351.     printf("-vesa   Force system to work with VESA VBE if available. By default the\n");
  352.     printf("        system will try to use the accelerated drivers\n");
  353.     printf("-f      Turn off special SuperVGA performance enhancements.\n");
  354.     printf("-b      Program the palette via the BIOS (XGA and Non VGA style SuperVGA's).\n");
  355.     printf("-s      Use slower palette routines for VLB compatability.\n");
  356.     printf("-p<arg> Set the palette snow level factor (defaults to 100).\n");
  357.     printf("-h      Provide this usage information.\n\n");
  358.     printf("Valid modes to specify are:\n\n");
  359.  
  360.     i = 0;
  361.     while(modeList[i] != -1) {
  362.         printf("    \"%s\" - %d page\n",MGL_modeName(modeList[i]),
  363.             MGL_availablePages(driver,modeList[i]));
  364.         i++;
  365.         }
  366.  
  367.     printf("\nFor example, to run the demo with EGA 320x200 16 color mode, type the\n");
  368.     printf("following:\n\n");
  369.     printf("    mgldemo \"320 x 200 EGA 16 color\"\n");
  370.  
  371.     exit(1);
  372. }
  373.  
  374. void cdecl exitFunc(void)
  375. /****************************************************************************
  376. *
  377. * Function:        exitFunc
  378. *
  379. * Description:    Exit function to ensure that the graphics system is shut
  380. *                down correctly.
  381. *
  382. ****************************************************************************/
  383. {
  384.     MGL_exit();
  385. }
  386.  
  387. void fatalError(char *msg)
  388. /****************************************************************************
  389. *
  390. * Function:        fatalError
  391. * Parameters:    msg    - Message to display on exit
  392. *
  393. * Description:    This routine is called when a fatal error occurs and
  394. *                the program must be exited gracefully.
  395. *
  396. ****************************************************************************/
  397. {
  398.     MGL_exit();
  399.     printf(msg);
  400.     exit(EXIT_FAILURE);
  401. }
  402.  
  403. void startGraphics(char *modeName)
  404. /****************************************************************************
  405. *
  406. * Function:        startGraphics
  407. *
  408. * Description:    Attempts to initialise the graphics system in the
  409. *                specified manner. Reports any intialisation errors if
  410. *                the occur.
  411. *
  412. ****************************************************************************/
  413. {
  414.     int        i,height;
  415.     int        far *modeList;
  416.  
  417. #ifdef    USE_LINKED
  418.     MGL_registerDriver(EGANAME,EGA_driver);
  419.     MGL_registerDriver(VGANAME,VGA_driver);
  420.     MGL_registerDriver(VGA256NAME,VGA256_driver);
  421.     MGL_registerDriver(VGAXNAME,VGAX_driver);
  422.     MGL_registerDriver(SVGA256NAME,SVGA256_driver);
  423.     MGL_registerDriver(SVGA32KNAME,SVGA32K_driver);
  424.     MGL_registerDriver(SVGA64KNAME,SVGA64K_driver);
  425.     MGL_registerDriver(SVGA16MNAME,SVGA16M_driver);
  426.     MGL_registerDriver(SVGAS3NAME,SVGAS3_driver);
  427. #endif
  428.  
  429.     /* Detect the video subsystem type, and if determine which video mode
  430.      * to use.
  431.      */
  432.  
  433.     MGL_detectGraph(&driver,&mode);
  434.     if (forceDriver < driver && forceDriver != grDETECT) {
  435.         if ((driver = forceDriver) == grEGA)
  436.             mode = grEGA_640x350x16;
  437.         }
  438.     if (modeName != NULL) {
  439.         modeList = MGL_availableModes(driver);
  440.  
  441.         /* Check if the user asked for help */
  442.  
  443.         if (modeName[0] == '-' && modeName[1] == 'h')
  444.             help();
  445.  
  446.         /* Look up the mode number given it's name */
  447.  
  448.         i = 0;
  449.         while (true) {
  450.             if ((mode = modeList[i++]) == -1)
  451.                 break;
  452.             if (strcmp(MGL_modeName(mode),modeName) == 0)
  453.                 break;
  454.             }
  455.         if (mode == -1) {
  456.             printf("Invalid video mode selected\n");
  457.             exit(1);
  458.             }
  459.         }
  460.  
  461.     atexit(exitFunc);                /* Register exit routine            */
  462.  
  463.     _installMouse = true;            /* Install mouse handling stuff        */
  464.  
  465. #ifdef    USE_LINKED
  466.     MGL_init(&driver,&mode,"");
  467. #else
  468.     MGL_init(&driver,&mode,"..\\");
  469. #endif
  470.  
  471.     if ((err = MGL_result()) != grOK) {
  472.         printf("Graphics error: %s\n",MGL_errorMsg(err));
  473.         printf("Driver: %s, Mode: %s\n",
  474.             MGL_driverName(driver),
  475.             MGL_modeName(mode));
  476.         exit(1);
  477.         }
  478.  
  479.     /* Change default startup options from command line */
  480.  
  481.     if (snowlevel != -1) MGL_setPaletteSnowLevel(snowlevel);
  482.  
  483.     /* Load a large font for labelling */
  484.  
  485.     largeFont = MGL_loadFont("fonts\\romant.fnt");
  486.     if ((err = MGL_result()) != grOK) {
  487.         MGL_exit();
  488.         printf("Graphics error: %s\n",MGL_errorMsg(err));
  489.         exit(1);
  490.         }
  491.  
  492.     /* Obtain a few useful constant */
  493.  
  494.     maxcolor = MGL_maxColor();
  495.     aspect = MGL_getAspectRatio();    /* Aspect ratio for display mode    */
  496.     aspectRatio = 1000.0 / aspect;
  497.     MGL_getTextSettings(&defaultTextSettings);
  498.  
  499.     /* Allocate space for the palette, and read the default palette        */
  500.  
  501.     if ((palsize = MGL_getPaletteSize()) != -1) {
  502.         pal = malloc(palsize * sizeof(palette));
  503.         if (pal == NULL)
  504.             fatalError("Out of memory!\n");
  505.         MGL_getDefaultPalette(pal);
  506.         }
  507.     else pal = NULL;
  508.  
  509.     /* Determine the size of the viewports required */
  510.  
  511.     MGL_getViewport(&fullView);
  512.     height = MGL_textHeight();        /* Height of default font            */
  513.  
  514.     titleView = fullView;
  515.     titleView.bottom = titleView.top + height + 5;
  516.  
  517.     statusView = fullView;
  518.     statusView.top = statusView.bottom - height - 5;
  519.  
  520.     demoView = fullView;
  521.     demoView.top = titleView.bottom;
  522.     demoView.bottom = statusView.top+1;
  523. }
  524.  
  525. int gprintf(char *fmt, ... )
  526. /****************************************************************************
  527. *
  528. * Function:        gprintf
  529. * Parameters:    fmt        - Format string
  530. *                ...        - Standard printf style parameters
  531. * Returns:        Number of items converted successfully.
  532. *
  533. * Description:    Simple printf style output routine for sending text to
  534. *                the current viewport. It begins drawing the string at
  535. *                the current CP location, and move the CP to the start of
  536. *                the next logical line.
  537. *
  538. ****************************************************************************/
  539. {
  540.     va_list    argptr;                    /* Argument list pointer            */
  541.     char    buf[255];                /* Buffer to build sting into        */
  542.     int        cnt;                    /* Result of SPRINTF for return     */
  543.     point    CP;
  544.  
  545.     va_start(argptr,fmt);
  546.  
  547.     cnt = vsprintf(buf,fmt,argptr);
  548.     MGL_getCP(&CP);
  549.     MGL_drawStr(buf);                /* Display the string                */
  550.     CP.y += MGL_textHeight();        /* Advance to next line                */
  551.     MGL_moveTo(CP);
  552.  
  553.     va_end(argptr);
  554.  
  555.     return cnt;                        /* Return the conversion count        */
  556. }
  557.  
  558. #ifdef __MSC__
  559.  
  560. int random(int max)
  561. {
  562.     return ((long)rand() * (long)max) / RAND_MAX;
  563. }
  564.  
  565. #endif
  566.  
  567. #if defined(__MSC__) || defined(__SYMC__)
  568.  
  569. void delay(int milliseconds)
  570. {
  571.     int i,j,k;
  572.  
  573.     for (i = 0; i < milliseconds; i++)
  574.         for (j = 0; j < 1000; j++)
  575.             k += i * j;
  576. }
  577.  
  578. #endif
  579.  
  580. long randoml(long max)
  581. /****************************************************************************
  582. *
  583. * Function:        randoml
  584. * Parameters:    max    - Maximum random number value+1
  585. * Returns:        Random long between 0 and max-1.
  586. *
  587. * Description:    Routine to compute random long numbers. We do this simply
  588. *                by expanding a random integer into the correct range,
  589. *                which means some values will never get generated :-(,
  590. *                but hell, it works for what we want (it will also fail
  591. *                for large numbers).
  592. *
  593. ****************************************************************************/
  594. {
  595.     return ((float)rand() * max) / (float)RAND_MAX;
  596. }
  597.  
  598. void drawBorder(void)
  599. /****************************************************************************
  600. *
  601. * Function:        drawBorder
  602. *
  603. * Description:    Draws a border around the currently active viewport. The
  604. *                border is drawn just inside the bounds of the viewport.
  605. *
  606. ****************************************************************************/
  607. {
  608.     rect    view;
  609.  
  610.     MGL_getViewport(&view);
  611.     MGL_setViewport(fullView);
  612.     MGL_rect(view);
  613.     MGL_setViewport(view);
  614. }
  615.  
  616. void statusLine(char *msg)
  617. /****************************************************************************
  618. *
  619. * Function:        statusLine
  620. * Parameters:    msg    - Message to display in status bar
  621. *
  622. * Description:    Displays a message in the status bar. The status bar is
  623. *                cleared before the message is displayed.
  624. *
  625. ****************************************************************************/
  626. {
  627.     text_settings    tset;
  628.  
  629.     MS_hide();                        /* Hide mouse cursor                */
  630.  
  631.     MGL_pushViewport();
  632.     MGL_insetRect(statusView,1,1);
  633.     MGL_setViewport(statusView);
  634.     MGL_clearViewport();
  635.  
  636.     MGL_getTextSettings(&tset);
  637.     MGL_setTextSettings(&defaultTextSettings);
  638.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  639.     MGL_drawStrXY(MGL_maxx()/2, MGL_maxy()/2, msg);
  640.     MGL_setTextSettings(&tset);
  641.  
  642.     MGL_insetRect(statusView,-1,-1);
  643.     MGL_popViewport();
  644.  
  645.     MS_show();                        /* Show mouse cursor                */
  646. }
  647.  
  648. void pause(void)
  649. /****************************************************************************
  650. *
  651. * Function:        pause
  652. *
  653. * Description:    Pause until a key is pressed. If the key is the ESC key,
  654. *                the exit the program.
  655. *
  656. ****************************************************************************/
  657. {
  658.     static char    msg[] = "Esc aborts or press a key...";
  659.     int            ch;
  660.  
  661.     statusLine(msg);        /* Display status message                    */
  662.  
  663.     ch = getch();
  664.  
  665.     if (ch == ESC)
  666.         exit(1);
  667.  
  668.     if (ch == 0)            /* Swallow extended key codes                 */
  669.         ch = getch();
  670. }
  671.  
  672. void mainWindow(char *heading)
  673. /****************************************************************************
  674. *
  675. * Function:        mainWindow
  676. * Parameters:    heading    - Text describing the demo
  677. *
  678. * Description:    Displays a heading for the demo, sets the viewport for
  679. *                the demo code and draws a border around the viewport. We
  680. *                also restore the default attributes.
  681. *
  682. ****************************************************************************/
  683. {
  684.     text_settings    tset;
  685.     rect            r;
  686.  
  687.     MS_hide();                        /* Hide mouse cursor                */
  688.  
  689.     MGL_defaultAttributes();        /* Restore default attributes        */
  690.     MGL_clearDevice();                /* Clear the graphics screen        */
  691.  
  692.     MGL_setViewport(titleView);
  693.  
  694.     MGL_getTextSettings(&tset);
  695.     MGL_setTextSettings(&defaultTextSettings);
  696.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  697.     MGL_drawStrXY(MGL_maxx()/2, MGL_maxy()/2, heading);
  698.     MGL_setTextSettings(&tset);
  699.  
  700.     MGL_setViewport(statusView);
  701.     drawBorder();
  702.     MGL_setViewport(demoView);
  703.     drawBorder();
  704.  
  705.     r = demoView;
  706.     MGL_insetRect(r,1,1);
  707.     MGL_setViewport(r);
  708.  
  709.     MS_show();                        /* Show mouse cursor                */
  710. }
  711.  
  712. void reportStatus(void)
  713. /****************************************************************************
  714. *
  715. * Function:        reportStatus
  716. *
  717. * Description:    Report the current graphics system configuration after
  718. *                graphics has been initialised.
  719. *
  720. ****************************************************************************/
  721. {
  722.     attributes        attr;
  723.     text_settings    tset;
  724.  
  725.     mainWindow("Status report after MGL_init");
  726.  
  727.     MGL_moveToCoord(10,4);
  728.  
  729.     /* Get required information */
  730.  
  731.     MGL_getAttributes(&attr);
  732.  
  733.     gprintf("Graphics device    : (%d) %s", driver, MGL_driverName(driver));
  734.     gprintf("Graphics mode      : (%d) %s", mode, MGL_modeName(mode));
  735.     gprintf("Screen resolution  : ( 0, 0, %d, %d )",MGL_sizex(),MGL_sizey());
  736.     gprintf("View port          : ( %d, %d, %d, %d )",
  737.         attr.viewport.left,attr.viewport.top,
  738.         attr.viewport.right,attr.viewport.bottom);
  739.     gprintf("Clipping rectangle : ( %d, %d, %d, %d )",
  740.         attr.clipRect.left,attr.clipRect.top,
  741.         attr.clipRect.right,attr.clipRect.bottom);
  742.     gprintf("Clipping           : %s", attr.clip ? "ON" : "OFF");
  743.     gprintf("Current position   : ( %d, %d )", MGL_getX(),MGL_getY());
  744.     gprintf("Colors available   : %ld", maxcolor+1);
  745.     gprintf("Color              : %ld", attr.color);
  746.     gprintf("Background color   : %ld", attr.backColor);
  747.     gprintf("Border dark color  : %ld", attr.bdr_dark);
  748.     gprintf("Border bright color: %ld", attr.bdr_bright);
  749.     gprintf("Marker color       : %ld", attr.markerColor);
  750.     gprintf("Marker size        : %d", attr.markerSize);
  751.     gprintf("Marker style       : %s", markerStyle[attr.markerStyle]);
  752.     gprintf("Write mode         : %s", writeMode[attr.writeMode]);
  753.     gprintf("Pen height         : %d", attr.penHeight);
  754.     gprintf("Pen width          : %d", attr.penWidth);
  755.     gprintf("Fill style         : %s", fillStyle[attr.penStyle]);
  756.     gprintf("Polygon style      : %s", polyStyle[attr.poly_type]);
  757.     gprintf("Maximum Page Index : %d", MGL_maxPage());
  758.  
  759.     tset = attr.tsettings;        /* Make an alias */
  760.  
  761.     gprintf("");
  762.     gprintf("Text settings");
  763.     gprintf("");
  764.  
  765.     gprintf("Current font       : %s", tset.fnt->name);
  766.     gprintf("Text direction     : %s", textDirection[tset.dir]);
  767.     gprintf("Horizontal justify : %s", horizJust[tset.horiz_just]);
  768.     gprintf("Vertical justify   : %s", vertJust[tset.vert_just]);
  769.     gprintf("Horizontal size    : ( %d / %d )", tset.sz_numerx,tset.sz_denomx);
  770.     gprintf("Vertical size      : ( %d / %d )", tset.sz_numery,tset.sz_denomy);
  771.     gprintf("Space extra        : %d", tset.space_extra);
  772.  
  773.     pause();
  774. }
  775.  
  776. void colorDemo(void)
  777. /****************************************************************************
  778. *
  779. * Function:        colorDemo
  780. *
  781. * Description:    Display the current color palette on the screen.
  782. *
  783. ****************************************************************************/
  784. {
  785.     int        color,width,height,x,y,i,j,top,bottom,start;
  786.     palette    pal[256],temp[256];
  787.  
  788.     mainWindow("Color Demonstration");
  789.  
  790.     if (maxcolor <= 15) {
  791.         /* Simple color demonstration for 16 color displays */
  792.  
  793.         width = 2 * ((MGL_maxx()+1) / 16);
  794.         height = 2 * ((MGL_maxy()-10)  / 10);
  795.  
  796.         x = width / 2;
  797.         y = height / 2;
  798.         color = 1;
  799.         for (j = 0; j < 3; j++) {
  800.             for (i = 0; i < 5; i++) {
  801.                 MGL_setColor(color++);
  802.                 MGL_fillRectCoord(x,y,x+width,y+height);
  803.                 x += (width/2) * 3;
  804.                 }
  805.             y += (height / 2) * 3;
  806.             x = width / 2;
  807.             }
  808.         }
  809.     else if (maxcolor == 255) {
  810.         /* Color demonstration for large numbers of colors */
  811.  
  812.         width = 2 * ((MGL_maxx()+1) / 46);
  813.         height = 2 * ((MGL_maxy()-10)  / 47);
  814.  
  815.         x = width / 2;
  816.         y = height / 2;
  817.         color = 1;
  818.         for (j = 0; j < 16; j++) {
  819.             for (i = 0; i < 16; i++) {
  820.                 MGL_setColor(color++);
  821.                 MGL_fillRectCoord(x,y,x+width,y+height);
  822.                 x += (width/2) * 3;
  823.                 }
  824.             y += (height / 2) * 3;
  825.             x = width / 2;
  826.             }
  827.  
  828.         MGL_setColor(MGL_defaultColor());
  829.         statusLine("Press a key to rotate palette");
  830.         getch();
  831.         statusLine("Press a key to rotate other direction");
  832.  
  833.         // Palette rotations
  834.  
  835.         MGL_getPalette(pal,palsize,0);
  836.         while (!kbhit()) {
  837.             MGL_rotatePalette(pal+1,palsize-1,PAL_ROTATE_UP);
  838.             MGL_setPalette(pal+1,palsize-1,1);
  839.             }
  840.         getch();
  841.         statusLine("Press a key to fade palette");
  842.  
  843.         while (!kbhit()) {
  844.             MGL_rotatePalette(pal+1,palsize-1,PAL_ROTATE_DOWN);
  845.             MGL_setPalette(pal+1,palsize-1,1);
  846.             }
  847.         getch();
  848.  
  849.         // Palette fade out
  850.  
  851.         temp[0] = pal[0];
  852.         for (i = 31; i >= 0; i--) {
  853.             MGL_fadePalette(temp+1,pal+1,palsize-1,(uchar)(i*8));
  854.             MGL_setPalette(temp+1,palsize-1,1);
  855.             }
  856.  
  857.         // Palette fade in
  858.         for (i = 0; i <= 31; i++) {
  859.             MGL_fadePalette(temp+1,pal+1,palsize-1,(uchar)(i*8));
  860.             MGL_setPalette(temp+1,palsize-1,1);
  861.             }
  862.         }
  863.     else {
  864.         /* Color demonstration for HiColor and TrueColor modes */
  865.  
  866.         start = MGL_maxx()/8;
  867.         width = MGL_maxx() - start*2;
  868.         MGL_beginDrawing();
  869.  
  870.         top = MGL_maxy()/8;
  871.         bottom = MGL_maxy()/8 + MGL_maxy()/5;
  872.         for (x = 0; x < width; x++) {
  873.             MGL_setColor(MGL_packColor((x * 255L) / width,0,0));
  874.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  875.             }
  876.  
  877.         top += MGL_maxy()/5;
  878.         bottom += MGL_maxy()/5;
  879.         for (x = 0; x < width; x++) {
  880.             MGL_setColor(MGL_packColor(0,(x * 255L) / width,0));
  881.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  882.             }
  883.  
  884.         top += MGL_maxy()/5;
  885.         bottom += MGL_maxy()/5;
  886.         for (x = 0; x < width; x++) {
  887.             MGL_setColor(MGL_packColor(0,0,(x * 255L) / width));
  888.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  889.             }
  890.  
  891.         top += MGL_maxy()/5;
  892.         bottom += MGL_maxy()/5;
  893.         for (x = 0; x < width/2; x++) {
  894.             MGL_setColor(MGL_packColor((((width/2)-x) * 255L) / (width/2),
  895.                 (x * 255L) / (width/2),0));
  896.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  897.             }
  898.         for (; x < width; x++) {
  899.             MGL_setColor(MGL_packColor(0,
  900.                 ( ((width/2) - (x - (width/2))) * 255L) / (width/2),
  901.                 ((x-width/2) * 255L) / (width/2) ));
  902.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  903.             }
  904.         MGL_endDrawing();
  905.         }
  906.  
  907.     MGL_setColor(MGL_defaultColor());
  908.     pause();
  909.     MGL_setDefaultPalette();
  910. }
  911.  
  912. void paletteDemo(void)
  913. /****************************************************************************
  914. *
  915. * Function:        paletteDemo
  916. *
  917. * Description:    Change the palette of the screen until the user has had
  918. *                enough.
  919. *
  920. ****************************************************************************/
  921. {
  922.     int     i,j,x,y,color,height,width;
  923.  
  924.     if (maxcolor > 255)
  925.         return;
  926.  
  927.     mainWindow("Palette Demonstration");
  928.     statusLine("Press any key to continue, ESC to Abort");
  929.  
  930.     width  = (MGL_maxx()+1) / 15;        /* Compute width of boxes        */
  931.     height = (MGL_maxy()+1) / 10;        /* Compute height of boxes        */
  932.  
  933.     x = y = 0;                            /* Start in upper corner        */
  934.     color = 1;                            /* Begin width 1st color        */
  935.  
  936.     for (j = 0; j < 10; j++) {            /* For 10 rows of boxes         */
  937.         for (i = 0; i < 15; i++) {        /* For 15 columns of boxes        */
  938.             MGL_setColor(color++);
  939.             MGL_fillRectCoord(x,y,x+width+1,y+height+1);
  940.             x += width + 1;                /* Advance to next col            */
  941.  
  942.             /* Choose color out of order */
  943.  
  944.             color = 1 + (color % 14);
  945.             }
  946.         x = 0;
  947.         y += height + 1;
  948.         }
  949.  
  950.     while (!kbhit()) {                    /* Until user hits a key...        */
  951.         MGL_setPaletteEntry(1+random(14),
  952.             (uchar)random(PALMAX+1),
  953.             (uchar)random(PALMAX+1),
  954.             (uchar)random(PALMAX+1));
  955.         }
  956.  
  957.     MGL_setColor(MGL_defaultColor());
  958.     MGL_setDefaultPalette();
  959.     pause();
  960. }
  961.  
  962. void pixelDemo(void)
  963. /****************************************************************************
  964. *
  965. * Function:        pixelDemo
  966. *
  967. * Description:    Display a pattern of random dots on the screen and
  968. *                pick them back up again.
  969. *
  970. ****************************************************************************/
  971. {
  972.     int        seed = 1958;
  973.     int        i,x,y,maxx,maxy;
  974.     color_t    color;
  975.  
  976.     mainWindow("MGL_pixel / MGL_getPixel Demonstration");
  977.  
  978.     maxx = MGL_maxx();
  979.     maxy = MGL_maxy();
  980.  
  981.     srand(seed);            /* Seed random number gen with known value    */
  982.  
  983.     MGL_beginPixel();
  984.     for (i = 0; i < 10000; i++) {        /* Put 5000 pixels on screen    */
  985.         x = 1 + random(maxx);            /* Generate a random location    */
  986.         y = 1 + random(maxy);
  987.         MGL_setColor(1 + randoml(maxcolor));
  988.         MGL_pixelCoord(x,y);
  989.         }
  990.  
  991.     srand(seed);            /* Reseed random number gen with same value    */
  992.  
  993.     MGL_setColor(MGL_realColor(BLACK));            /* Draw over in black             */
  994.  
  995.     for (i = 0; i < 10000; i++) {        /* Take the 5000 pixels off        */
  996.         x = 1 + random(maxx);            /* Generate a random location    */
  997.         y = 1 + random(maxy);
  998.         color = MGL_getPixelCoord(x,y);
  999.         if (color == 1 + randoml(maxcolor))    /* Keep random in sync        */
  1000.             MGL_pixelCoord(x,y);
  1001.         }
  1002.     MGL_endPixel();
  1003.  
  1004.     MGL_setColor(MGL_defaultColor());
  1005.     pause();
  1006. }
  1007.  
  1008. #define    RADIUS        20                    /* Dimensions of saucer            */
  1009. #define    STARTX        100
  1010. #define    STARTY        50
  1011. #define    PAUSETIME    60
  1012.  
  1013. void imageDemo(void)
  1014. /****************************************************************************
  1015. *
  1016. * Function:        imageDemo
  1017. *
  1018. * Description:    Moves the image of a saucer randomly around the screen,
  1019. *                using very simple XOR animation.
  1020. *
  1021. ****************************************************************************/
  1022. {
  1023.     rect    extent;
  1024.     void    far *saucer;
  1025.     int        i,x,y,width,height,maxx,maxy,step;
  1026.     size_t    size;
  1027.  
  1028.     mainWindow("MGL_getImage / MGL_putImage Demonstration");
  1029.     statusLine("Press any key to continue, ESC to Abort");
  1030.  
  1031.     maxx = MGL_maxx();
  1032.     maxy = MGL_maxy();
  1033.  
  1034.     /* Draw the flying saucer */
  1035.  
  1036.     extent.left = STARTX - RADIUS;
  1037.     extent.top = STARTY - ((RADIUS/3)+2);
  1038.     extent.right = STARTX + RADIUS + 1;
  1039.     extent.bottom = STARTY + ((RADIUS/3)+2) + 1;
  1040.  
  1041.     MGL_fillEllipse(extent);
  1042.  
  1043.     MGL_lineCoord(STARTX+7, STARTY-6, STARTX+10, STARTY-12);
  1044.     MGL_lineCoord(STARTX-7, STARTY-6, STARTX-10, STARTY-12);
  1045.  
  1046.     extent.left = STARTX-10 - 2;
  1047.     extent.top = STARTY-12 - 2;
  1048.     extent.right = STARTX-10 + 2 + 1;
  1049.     extent.bottom = STARTY-12 + 2 + 1;
  1050.  
  1051.     MGL_ellipse(extent);
  1052.     MGL_offsetRect(extent,20,0);
  1053.     MGL_ellipse(extent);
  1054.  
  1055.     /* Read the image of the saucer */
  1056.  
  1057.     extent.left = STARTX-(RADIUS+1);
  1058.     extent.top = STARTY-14;
  1059.     extent.right = STARTX+(RADIUS+1) + 1;
  1060.     extent.bottom = STARTY+(RADIUS/3)+3 + 1;
  1061.     width = extent.right - extent.left;
  1062.     height = extent.bottom - extent.top;
  1063.  
  1064.     size = MGL_imageSize(extent);
  1065.     saucer = malloc(size);
  1066.  
  1067.     if (saucer == NULL)
  1068.         fatalError("Out of memory!\n");
  1069.  
  1070.     MGL_getImage(extent,saucer);
  1071.     MGL_putImage(extent,saucer,XOR_MODE);
  1072.  
  1073.     /* Plot some "stars" for the background */
  1074.  
  1075.     MGL_beginPixel();
  1076.     for (i = 0; i < 1000; i++) {
  1077.         MGL_setColor(randoml(maxcolor)+1);
  1078.         MGL_pixelCoord(random(maxx),random(maxy));
  1079.         }
  1080.     MGL_endPixel();
  1081.  
  1082.     /* Start in the middle of the viewport */
  1083.  
  1084.     x = maxx/2;        y = maxy/2;
  1085.  
  1086.     /* Repeat moving the saucer until a key is pressed */
  1087.  
  1088.     while (!kbhit()) {
  1089.         /* Draw the Saucer, pause for a while and erase it */
  1090.  
  1091.         MGL_putImageCoord(x,y,x+width+1,y+height+1,saucer,XOR_MODE);
  1092.         delay(PAUSETIME);
  1093.         MGL_putImageCoord(x,y,x+width+1,y+height+1,saucer,XOR_MODE);
  1094.  
  1095.         /* Move Saucer to a new location */
  1096.  
  1097.         step = random(2*RADIUS);
  1098.         if ((step/2) % 2 == 0)
  1099.             x += step;
  1100.         else
  1101.             x -= step;
  1102.  
  1103.         step = random(RADIUS);
  1104.         if ((step/2) % 2 == 0)
  1105.             y += step;
  1106.         else
  1107.             y -= step;
  1108.  
  1109.         /* Ensure that is has not moved off the edge of the viewport */
  1110.  
  1111.         if (x + width-1 > maxx)
  1112.             x = maxx - width+1;
  1113.         else if (x < 0)
  1114.             x = 0;
  1115.  
  1116.         if (y + height-1 > maxy)
  1117.             y = maxy - height+1;
  1118.         else if (y < 0)
  1119.             y = 0;
  1120.         }
  1121.     free((void*)saucer);
  1122.  
  1123.     MGL_setColor(MGL_defaultColor());
  1124.     pause();
  1125. }
  1126.  
  1127. void rectangleDemo(void)
  1128. /****************************************************************************
  1129. *
  1130. * Function:        rectangleDemo
  1131. *
  1132. * Description:    Display a number of random rectangles with random
  1133. *                attributes.
  1134. *
  1135. ****************************************************************************/
  1136. {
  1137.     int        maxx,maxy,val;
  1138.     rect    r;
  1139.  
  1140.     mainWindow("Random rectangles");
  1141.     statusLine("Press any key to continue, ESC to Abort");
  1142.  
  1143.     maxx = MGL_maxx();
  1144.     maxy = MGL_maxy();
  1145.  
  1146.     while (!kbhit()) {
  1147.         r.left = random(maxx);
  1148.         r.right = random(maxx);
  1149.         r.top = random(maxy);
  1150.         r.bottom = random(maxy);
  1151.  
  1152.         /* Fix the rectangle so it is not empty */
  1153.  
  1154.         if (r.right < r.left)
  1155.             SWAP(r.left,r.right);
  1156.         if (r.bottom < r.top)
  1157.             SWAP(r.top,r.bottom);
  1158.  
  1159.         MGL_setColor(randoml(maxcolor)+1);
  1160.         MGL_setBackColor(randoml(maxcolor)+1);
  1161.  
  1162.         if ((val = random(3)) == 0) {
  1163.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1164.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1165.             }
  1166.         else if (val == 1) {
  1167.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1168.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1169.             }
  1170.         else {
  1171.             MGL_setPenStyle(SOLID_PATTERN);
  1172.             }
  1173.  
  1174.         MGL_fillRect(r);
  1175.         }
  1176.  
  1177.     MGL_defaultAttributes();
  1178.     pause();
  1179. }
  1180.  
  1181. void circleDemo(void)
  1182. /****************************************************************************
  1183. *
  1184. * Function:        circleDemo
  1185. *
  1186. * Description:    Display a random pattern of circles on the screen
  1187. *                until the user hits a key.
  1188. *
  1189. ****************************************************************************/
  1190. {
  1191.     int     maxx,maxy,val;
  1192.     rect    r;
  1193.  
  1194.     mainWindow("Circle Demonstration");
  1195.     statusLine("Press any key to continue, ESC to Abort");
  1196.  
  1197.     maxx = MGL_maxx();
  1198.     maxy = MGL_maxy();
  1199.  
  1200.     while (!kbhit()) {
  1201.         r.left = random(maxx-100);
  1202.         r.top = random(maxy-100);
  1203.         r.right = r.left + random(100);
  1204.         r.bottom = r.top + random(100);
  1205.  
  1206.         MGL_setColor(randoml(maxcolor)+1);
  1207.         MGL_setBackColor(randoml(maxcolor)+1);
  1208.  
  1209.         MGL_setPenSize(random(5)+1,random(5)+1);
  1210.  
  1211.         if ((val = random(10)) == 0) {
  1212.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1213.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1214.             }
  1215.         else if (val == 1) {
  1216.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1217.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1218.             }
  1219.         else {
  1220.             MGL_setPenStyle(SOLID_PATTERN);
  1221.             }
  1222.  
  1223.         MGL_ellipse(r);
  1224.         }
  1225.  
  1226.     MGL_defaultAttributes();
  1227.     pause();
  1228. }
  1229.  
  1230. void filledCircleDemo(void)
  1231. /****************************************************************************
  1232. *
  1233. * Function:        filledCircleDemo
  1234. *
  1235. * Description:    Display a random pattern of filled circles on the screen
  1236. *                until the user hits a key.
  1237. *
  1238. ****************************************************************************/
  1239. {
  1240.     int     maxx,maxy,val;
  1241.     rect    r;
  1242.  
  1243.     mainWindow("Filled circle Demonstration");
  1244.     statusLine("Press any key to continue, ESC to Abort");
  1245.  
  1246.     maxx = MGL_maxx();
  1247.     maxy = MGL_maxy();
  1248.  
  1249.     while (!kbhit()) {
  1250.         r.left = random(maxx-100);
  1251.         r.top = random(maxy-100);
  1252.         r.right = r.left + random(100);
  1253.         r.bottom = r.top + random(100);
  1254.  
  1255.         MGL_setColor(randoml(maxcolor)+1);
  1256.         MGL_setBackColor(randoml(maxcolor)+1);
  1257.  
  1258.         if ((val = random(5)) == 0) {
  1259.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1260.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1261.             }
  1262.         else if (val == 1) {
  1263.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1264.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1265.             }
  1266.         else {
  1267.             MGL_setPenStyle(SOLID_PATTERN);
  1268.             }
  1269.  
  1270.         MGL_fillEllipse(r);
  1271.         }
  1272.  
  1273.     MGL_defaultAttributes();
  1274.     pause();
  1275. }
  1276.  
  1277. void arcDemo(void)
  1278. /****************************************************************************
  1279. *
  1280. * Function:        arcDemo
  1281. *
  1282. * Description:    Display a random pattern of elliptical arc's on the screen
  1283. *                until the user hits a key.
  1284. *
  1285. ****************************************************************************/
  1286. {
  1287.     int     maxx,maxy,startAngle,endAngle;
  1288.     rect    r;
  1289.  
  1290.     mainWindow("Arc Demonstration");
  1291.     statusLine("Press any key to continue, ESC to Abort");
  1292.  
  1293.     maxx = MGL_maxx();
  1294.     maxy = MGL_maxy();
  1295.  
  1296.     while (!kbhit()) {
  1297.         r.left = random(maxx-100);
  1298.         r.top = random(maxy-100);
  1299.         r.right = r.left + random(100);
  1300.         r.bottom = r.top + random(100);
  1301.         startAngle = random(360);
  1302.         endAngle = random(360);
  1303.  
  1304.         MGL_setColor(randoml(maxcolor)+1);
  1305.         MGL_ellipseArc(r,startAngle,endAngle);
  1306.         }
  1307.  
  1308.     MGL_defaultAttributes();
  1309.     pause();
  1310. }
  1311.  
  1312. void filledArcDemo(void)
  1313. /****************************************************************************
  1314. *
  1315. * Function:        filledArcDemo
  1316. *
  1317. * Description:    Display a random pattern of filled arcs on the screen
  1318. *                until the user hits a key.
  1319. *
  1320. ****************************************************************************/
  1321. {
  1322.     int     maxx,maxy,startAngle,endAngle,val;
  1323.     rect    r;
  1324.  
  1325.     mainWindow("Filled Arc Demonstration");
  1326.     statusLine("Press any key to continue, ESC to Abort");
  1327.  
  1328.     maxx = MGL_maxx();
  1329.     maxy = MGL_maxy();
  1330.  
  1331.     while (!kbhit()) {
  1332.         r.left = random(maxx-100);
  1333.         r.top = random(maxy-100);
  1334.         r.right = r.left + random(100);
  1335.         r.bottom = r.top + random(100);
  1336.         startAngle = random(360);
  1337.         endAngle = random(360);
  1338.  
  1339.         MGL_setColor(randoml(maxcolor)+1);
  1340.         MGL_setBackColor(randoml(maxcolor)+1);
  1341.  
  1342.         if ((val = random(5)) == 0) {
  1343.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1344.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1345.             }
  1346.         else if (val == 1) {
  1347.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1348.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1349.             }
  1350.         else {
  1351.             MGL_setPenStyle(SOLID_PATTERN);
  1352.             }
  1353.  
  1354.         MGL_fillEllipseArc(r,startAngle,endAngle);
  1355.         }
  1356.  
  1357.     MGL_defaultAttributes();
  1358.     pause();
  1359. }
  1360.  
  1361. #define adjasp(y)    ((int)(aspectRatio * (double)(y)))
  1362. #define torad(d)    (( (double)(d) * M_PI ) / 180.0 )
  1363.  
  1364. void pieDemo(void)
  1365. /****************************************************************************
  1366. *
  1367. * Function:        pieDemo
  1368. *
  1369. * Description:    Draws a simple pie chart on the screen.
  1370. *
  1371. ****************************************************************************/
  1372. {
  1373.     int            xcenter,ycenter,radius,lradius;
  1374.     int         x,y;
  1375.     double        radians,piesize;
  1376.     arc_coords    coords;
  1377.  
  1378.     mainWindow("Pie Chart Demonstration");
  1379.  
  1380.     xcenter = MGL_maxx()/2;                /* Center the Pie horizontally    */
  1381.     ycenter = MGL_maxy()/2 + 20;        /* Center the Pie vertically    */
  1382.     radius  = MGL_maxx()/5;                /* It will cover 2/5ths screen    */
  1383.     piesize = MGL_maxy() / 4.0;            /* Optimum height ratio of pie    */
  1384.  
  1385.     while ((aspectRatio*radius) < piesize)
  1386.         radius++;
  1387.  
  1388.     lradius = radius + (radius/5);        /* Labels placed 20% farther    */
  1389.  
  1390.     MGL_useFont(largeFont);
  1391.     MGL_setTextJustify(CENTER_TEXT,TOP_TEXT);
  1392.     MGL_drawStrXY(MGL_maxx()/2, 6, "This is a Pie Chart");
  1393.  
  1394.     MGL_setTextSize(2,3,2,3);
  1395.  
  1396.     MGL_setColor(MGL_realColor(RED));
  1397.     MGL_fillEllipseArcCoord(xcenter+10,ycenter-adjasp(10),
  1398.         radius,adjasp(radius),0,90);
  1399.     MGL_setColor(MGL_realColor(WHITE));
  1400.     MGL_setPenStyle(SOLID_PATTERN);
  1401.     MGL_ellipseArcCoord(xcenter+10,ycenter-adjasp(10),
  1402.         radius,adjasp(radius),0,90);
  1403.     MGL_getArcCoords(&coords);
  1404.     MGL_lineCoord(coords.x,coords.y,coords.startX,coords.startY);
  1405.     MGL_lineCoord(coords.x,coords.y,coords.endX,coords.endY);
  1406.     radians = torad(45);
  1407.     x = xcenter + (int)(cos(radians) * (double)lradius );
  1408.     y = ycenter - (int)(sin(radians) * (double)lradius * aspectRatio );
  1409.     MGL_setTextJustify(LEFT_TEXT,BOTTOM_TEXT);
  1410.     MGL_drawStrXY(x,y,"25 %");
  1411.  
  1412.     MGL_setColor(MGL_realColor(GREEN));
  1413.     MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1414.     MGL_setPenBitmapPattern(&bitpat[3]);
  1415.     MGL_fillEllipseArcCoord(xcenter,ycenter,radius,adjasp(radius),90,135);
  1416.     MGL_setColor(MGL_realColor(WHITE));
  1417.     MGL_setPenStyle(SOLID_PATTERN);
  1418.     MGL_ellipseArcCoord(xcenter,ycenter,radius,adjasp(radius),90,135);
  1419.     MGL_getArcCoords(&coords);
  1420.     MGL_lineCoord(coords.x,coords.y,coords.startX,coords.startY);
  1421.     MGL_lineCoord(coords.x,coords.y,coords.endX,coords.endY);
  1422.     radians = torad(113);
  1423.     x = xcenter + (int)(cos(radians) * (double)lradius );
  1424.     y = ycenter - (int)(sin(radians) * (double)lradius * aspectRatio );
  1425.     MGL_setTextJustify(RIGHT_TEXT,BOTTOM_TEXT);
  1426.     MGL_drawStrXY(x,y,"12.5 %");
  1427.  
  1428.     MGL_setColor(MGL_realColor(YELLOW));
  1429.     MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1430.     MGL_setPenBitmapPattern(&bitpat[7]);
  1431.     MGL_fillEllipseArcCoord(xcenter-10,ycenter,radius,adjasp(radius),135,225);
  1432.     MGL_setColor(MGL_realColor(WHITE));
  1433.     MGL_setPenStyle(SOLID_PATTERN);
  1434.     MGL_ellipseArcCoord(xcenter-10,ycenter,radius,adjasp(radius),135,225);
  1435.     MGL_getArcCoords(&coords);
  1436.     MGL_lineCoord(coords.x,coords.y,coords.startX,coords.startY);
  1437.     MGL_lineCoord(coords.x,coords.y,coords.endX,coords.endY);
  1438.     radians = torad(180);
  1439.     x = xcenter + (int)(cos(radians) * (double)lradius );
  1440.     y = ycenter - (int)(sin(radians) * (double)lradius * aspectRatio );
  1441.     MGL_setTextJustify(RIGHT_TEXT,CENTER_TEXT);
  1442.     MGL_drawStrXY(x,y,"25 %");
  1443.  
  1444.     MGL_setColor(MGL_realColor(LIGHTBLUE));
  1445.     MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1446.     MGL_setPenBitmapPattern(&bitpat[10]);
  1447.     MGL_fillEllipseArcCoord(xcenter,ycenter,radius,adjasp(radius),225,360);
  1448.     MGL_setColor(MGL_realColor(WHITE));
  1449.     MGL_setPenStyle(SOLID_PATTERN);
  1450.     MGL_ellipseArcCoord(xcenter,ycenter,radius,adjasp(radius),225,360);
  1451.     MGL_getArcCoords(&coords);
  1452.     MGL_lineCoord(coords.x,coords.y,coords.startX,coords.startY);
  1453.     MGL_lineCoord(coords.x,coords.y,coords.endX,coords.endY);
  1454.     radians = torad(293);
  1455.     x = xcenter + (int)(cos(radians) * (double)lradius );
  1456.     y = ycenter - (int)(sin(radians) * (double)lradius * aspectRatio );
  1457.     MGL_setTextJustify(LEFT_TEXT,TOP_TEXT);
  1458.     MGL_drawStrXY(x,y,"37.5 %");
  1459.  
  1460.     MGL_defaultAttributes();
  1461.     pause();
  1462. }
  1463.  
  1464. void lineRelDemo(void)
  1465. /****************************************************************************
  1466. *
  1467. * Function:        lineRelDemo
  1468. *
  1469. * Description:    Display a pattern using relative move and line commands.
  1470. *
  1471. ****************************************************************************/
  1472. {
  1473.     int     h,w,dx,dy,cx,cy;
  1474.     point    outs[7];
  1475.  
  1476.     mainWindow("MGL_moveRel / MGL_lineRel Demonstration");
  1477.  
  1478.     cx = MGL_maxx() / 2;                /* Center of the viewport        */
  1479.     cy = MGL_maxy() / 2;
  1480.     h  = MGL_maxy() / 8;
  1481.     w  = MGL_maxx() / 9;
  1482.     dx = 2 * w;
  1483.     dy = 2 * h;
  1484.  
  1485.     MGL_setBackColor(MGL_realColor(BLUE));
  1486.     MGL_clearViewport();
  1487.  
  1488.     outs[0].x = cx -  dx;
  1489.     outs[0].y = cy -  dy;
  1490.     outs[1].x = cx - (dx-w);
  1491.     outs[1].y = cy - (dy+h);
  1492.     outs[2].x = cx +  dx;
  1493.     outs[2].y = cy - (dy+h);
  1494.     outs[3].x = cx +  dx;
  1495.     outs[3].y = cy +  dy;
  1496.     outs[4].x = cx + (dx-w);
  1497.     outs[4].y = cy + (dy+h);
  1498.     outs[5].x = cx -  dx;
  1499.     outs[5].y = cy + (dy+h);
  1500.     outs[6].x = cx -  dx;
  1501.     outs[6].y = cy -  dy;
  1502.  
  1503.     MGL_setColor(MGL_realColor(WHITE));
  1504.     MGL_fillPolygon(7,outs,0,0);
  1505.  
  1506.     outs[0].x = cx - (w/2);
  1507.     outs[0].y = cy + h;
  1508.     outs[1].x = cx + (w/2);
  1509.     outs[1].y = cy + h;
  1510.     outs[2].x = cx + (w/2);
  1511.     outs[2].y = cy - h;
  1512.     outs[3].x = cx - (w/2);
  1513.     outs[3].y = cy - h;
  1514.     outs[4].x = cx - (w/2);
  1515.     outs[4].y = cy + h;
  1516.  
  1517.     MGL_setColor(MGL_realColor(BLUE));
  1518.     MGL_fillPolygon(5,outs,0,0);
  1519.  
  1520.     /*    Draw a Tesseract object on the screen using the MGL_lineRel and    */
  1521.     /*    MGL_moveRel drawing commands.                                    */
  1522.  
  1523.     MGL_moveToCoord(cx-dx,cy-dy);
  1524.     MGL_lineRelCoord(w,-h);
  1525.     MGL_lineRelCoord(3*w,0);
  1526.     MGL_lineRelCoord(0, 5*h);
  1527.     MGL_lineRelCoord(-w,h);
  1528.     MGL_lineRelCoord(-3*w,0);
  1529.     MGL_lineRelCoord(0,-5*h);
  1530.  
  1531.     MGL_moveRelCoord(w,-h);
  1532.     MGL_lineRelCoord(0,5*h);
  1533.     MGL_lineRelCoord(w+(w/2),0);
  1534.     MGL_lineRelCoord(0,-3*h);
  1535.     MGL_lineRelCoord(w/2,-h);
  1536.     MGL_lineRelCoord(0,5*h);
  1537.  
  1538.     MGL_moveRelCoord(0,-5*h);
  1539.     MGL_lineRelCoord(-(w+(w/2)),0);
  1540.     MGL_lineRelCoord(0,3*h);
  1541.     MGL_lineRelCoord(-w/2,h);
  1542.  
  1543.     MGL_moveRelCoord(w/2,-h);
  1544.     MGL_lineRelCoord(w,0);
  1545.  
  1546.     MGL_moveRelCoord(0,-2*h);
  1547.     MGL_lineRelCoord(-w,0);
  1548.  
  1549.     MGL_defaultAttributes();
  1550.     pause();
  1551. }
  1552.  
  1553. #define MAXPTS    15
  1554.  
  1555. void lineToDemo(void)
  1556. /****************************************************************************
  1557. *
  1558. * Function:        lineToDemo
  1559. *
  1560. * Description:    Display a pattern using MGL_lineTo and MGL_moveTo commands.
  1561. *
  1562. ****************************************************************************/
  1563. {
  1564.     point    points[MAXPTS];
  1565.     int     i,j,h,w,xcenter,ycenter;
  1566.     int     radius,angle,step;
  1567.     double  rads;
  1568.  
  1569.     mainWindow("MGL_moveTo / MGL_lineTo Demonstration");
  1570.  
  1571.     w = MGL_maxx();
  1572.     h = MGL_maxy();
  1573.  
  1574.     xcenter = w / 2;                /* Determine the center of circle    */
  1575.     ycenter = h / 2;
  1576.     radius  = (h - 30) / (aspectRatio * 2);
  1577.     step    = 360 / MAXPTS;            /* Determine # of increments        */
  1578.  
  1579.     angle = 0;
  1580.     for(i = 0; i < MAXPTS; i++) {        /* Determine circle intercepts    */
  1581.         rads = (double)angle * M_PI / 180.0;/* Convert angle to radians    */
  1582.         points[i].x = xcenter + (int)(cos(rads) * radius );
  1583.         points[i].y = ycenter - (int)(sin(rads) * radius * aspectRatio);
  1584.         angle += step;                    /* Move to next increment        */
  1585.         }
  1586.  
  1587.     /* Draw bounding circle */
  1588.  
  1589.     MGL_ellipseCoord(xcenter,ycenter,radius,(int)(radius*aspectRatio));
  1590.  
  1591.     for (i = 0; i < MAXPTS; i++) {        /* Draw the chords to the circle */
  1592.         for (j = i; j < MAXPTS; j++) {    /* For each remaining intersect */
  1593.             MGL_moveTo(points[i]);        /* Move to beginning of chord    */
  1594.             MGL_lineTo(points[j]);         /* Draw the chord                */
  1595.             }
  1596.         }
  1597.  
  1598.     pause();
  1599. }
  1600.  
  1601. void lineDemo(void)
  1602. /****************************************************************************
  1603. *
  1604. * Function:        lineDemo
  1605. *
  1606. * Description:    Draw a whole bunch of random lines with random pen sizes
  1607. *                and pattern modes.
  1608. *
  1609. ****************************************************************************/
  1610. {
  1611.     int        maxx,maxy,val;
  1612.     point    p1,p2;
  1613.  
  1614.     mainWindow("Line Demonstration");
  1615.     statusLine("Press any key to continue, ESC to Abort");
  1616.  
  1617.     maxx = MGL_maxx();
  1618.     maxy = MGL_maxy();
  1619.  
  1620.     MGL_beginDrawing();
  1621.  
  1622.     while (!kbhit()) {
  1623.         p1.x = random(maxx);
  1624.         p1.y = random(maxy);
  1625.         p2.x = random(maxx);
  1626.         p2.y = random(maxy);
  1627.  
  1628.         MGL_setColor(randoml(maxcolor)+1);
  1629.         MGL_setBackColor(randoml(maxcolor)+1);
  1630.         MGL_setPenSize(random(5)+1,random(5)+1);
  1631.  
  1632.         if ((val = random(5)) == 0) {
  1633.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1634.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1635.             }
  1636.         else if (val == 1) {
  1637.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1638.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1639.             }
  1640.         else {
  1641.             MGL_setPenStyle(SOLID_PATTERN);
  1642.             }
  1643.  
  1644.         MGL_lineFast(p1,p2);
  1645.         }
  1646.  
  1647.     MGL_endDrawing();
  1648.  
  1649.     MGL_defaultAttributes();
  1650.     pause();
  1651. }
  1652.  
  1653. void textDump(void)
  1654. /****************************************************************************
  1655. *
  1656. * Function:        textDump
  1657. *
  1658. * Description:    Displays all the characters in each of the fonts in
  1659. *                the distribution.
  1660. *
  1661. ****************************************************************************/
  1662. {
  1663.     int        i,j,maxx;
  1664.     font    far *font;
  1665.     char    buf[80];
  1666.  
  1667.     maxx = MGL_maxx();
  1668.  
  1669.     for (i = 0; i < NUMFONTS; i++) {    /* For each available font        */
  1670.         /* Attempt to load the font file from disk. If it cannot be
  1671.          * found, then go onto the next one
  1672.          */
  1673.  
  1674.         strcpy(buf,"fonts\\");
  1675.         strcat(buf,fontFilename[i]);
  1676.         font = MGL_loadFont(buf);
  1677.         err = MGL_result();
  1678.         if (err == grFontNotFound)
  1679.             continue;
  1680.  
  1681.         if ((err = MGL_result()) != grOK) {
  1682.             MGL_exit();
  1683.             printf("Graphics error: %s\n",MGL_errorMsg(err));
  1684.             exit(1);
  1685.             }
  1686.  
  1687.         sprintf(buf,"Character set (%s)", font->name);
  1688.         mainWindow(buf);
  1689.  
  1690.         /* Display all characters on the screen */
  1691.  
  1692.         MGL_useFont(font);
  1693.         buf[1] = '\0';
  1694.         for (j = ' '; j < 256; j++) {
  1695.             buf[0] = j;
  1696.             MGL_drawStr(buf);
  1697.             if (MGL_getX() + MGL_maxCharWidth() > maxx) {
  1698.                 MGL_moveToCoord(0,MGL_getY() + MGL_textHeight());
  1699.                 }
  1700.             }
  1701.  
  1702.         /* Unload the font from memory */
  1703.  
  1704.         MGL_unloadFont(font);
  1705.         MGL_useFont(DEFAULT_FONT);
  1706.         pause();
  1707.         }
  1708.     MGL_defaultAttributes();
  1709. }
  1710.  
  1711. void textStyleDemo(void)
  1712. /****************************************************************************
  1713. *
  1714. * Function:        textDemo
  1715. *
  1716. * Description:    Show the large font in several different sizes and
  1717. *                orientations.
  1718. *
  1719. ****************************************************************************/
  1720. {
  1721.     int        i,x,y;
  1722.     char    buf[80];
  1723.  
  1724.     mainWindow("Text styles Demonstration");
  1725.  
  1726.     MGL_useFont(largeFont);
  1727.  
  1728.     x = y = 5;
  1729.     for (i = 5; i > 1; i--) {
  1730.         MGL_setTextSize(2,i,2,i);
  1731.         sprintf(buf,"Size (2/%d)",i);
  1732.         MGL_drawStrXY(x,y,buf);
  1733.         y += MGL_textHeight();
  1734.         }
  1735.  
  1736.     MGL_setTextSize(2,3,2,3);
  1737.  
  1738.     x = MGL_maxx()/2;
  1739.     y = MGL_maxy()/2;
  1740.  
  1741.     MGL_setTextDirection(LEFT_DIR);
  1742.     MGL_drawStrXY(x,y,"This goes left");
  1743.  
  1744.     MGL_setTextDirection(UP_DIR);
  1745.     MGL_drawStrXY(x,y,"This goes up");
  1746.  
  1747.     MGL_setTextDirection(RIGHT_DIR);
  1748.     MGL_drawStrXY(x,y,"This goes right");
  1749.  
  1750.     MGL_setTextDirection(DOWN_DIR);
  1751.     MGL_drawStrXY(x,y,"This goes down");
  1752.  
  1753.     MGL_defaultAttributes();
  1754.     pause();
  1755. }
  1756.  
  1757. void CRTModeDemo(void)
  1758. /****************************************************************************
  1759. *
  1760. * Function:        CRTModeDemo
  1761. *
  1762. * Description:    Demonstrate the ability to switch between text and
  1763. *                graphics mode.
  1764. *
  1765. ****************************************************************************/
  1766. {
  1767.     mainWindow("MGL_restoreCRTMode / MGL_setGraphMode demo");
  1768.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  1769.  
  1770.     MGL_drawStrXY(MGL_maxx()/2,MGL_maxy()/2,"Now you are in graphics mode...");
  1771.     statusLine("Press any key to for text mode...");
  1772.  
  1773.     getch();
  1774.  
  1775.     MGL_restoreCRTMode();
  1776.     printf( "Now you are in text mode.\n\n" );
  1777.     printf( "Press any key to go back to graphics..." );
  1778.     getch();
  1779.  
  1780.     MGL_setGraphMode();
  1781.     mainWindow("MGL_restoreCRTMode / MGL_setGraphMode demo");
  1782.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  1783.     MGL_drawStrXY(MGL_maxx()/2,MGL_maxy()/2,"Back in graphics mode...");
  1784.  
  1785.     pause();
  1786. }
  1787.  
  1788. void patternDemo(void)
  1789. /****************************************************************************
  1790. *
  1791. * Function:        patternDemo
  1792. *
  1793. * Description:    Display the set of fill patterns defined in this demo
  1794. *                program.
  1795. *
  1796. ****************************************************************************/
  1797. {
  1798.     int     i,j,x,y,height,width;
  1799.  
  1800.     mainWindow("Pattern Demonstration");
  1801.  
  1802.     width  = (MGL_maxx()+1) / 20;        /* Compute width of boxes        */
  1803.     height = (MGL_maxy()+1) / 9;        /* Compute height of boxes        */
  1804.  
  1805.     x = y = 10;                            /* Start in upper corner        */
  1806.     MGL_setColor(MGL_realColor(LIGHTGRAY));
  1807.     MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1808.  
  1809.  
  1810.     for (j = 0; j < 7; j++) {            /* For 7 rows of boxes         */
  1811.         for (i = 0; i < 15; i++) {        /* For 15 columns of boxes        */
  1812.             MGL_setPenBitmapPattern(&bitpat[j*15 + i]);
  1813.             MGL_fillRectCoord(x,y,x+width+1,y+height+1);
  1814.             x += width + 10;            /* Advance to next col            */
  1815.             }
  1816.         x = 10;
  1817.         y += height + 10;
  1818.         }
  1819.  
  1820.     MGL_setColor(MGL_defaultColor());
  1821.     pause();
  1822. }
  1823.  
  1824. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1825.  
  1826. void polyDemo(void)
  1827. /****************************************************************************
  1828. *
  1829. * Function:        polyDemo
  1830. *
  1831. * Description:    Display a random pattern of polygons on the screen with
  1832. *                random fill styles.
  1833. *
  1834. ****************************************************************************/
  1835. {
  1836.     int        i,maxx,maxy,val;
  1837.     point    poly[MaxPts];            /* Space to hold polygon data    */
  1838.  
  1839.     mainWindow("MGL_fillPolygon Demonstration");
  1840.     statusLine("Press any key to continue, ESC to Abort");
  1841.  
  1842.     maxx = MGL_maxx();
  1843.     maxy = MGL_maxy();
  1844.  
  1845.     while (!kbhit()) {
  1846.         /* Define a random polygon */
  1847.  
  1848.         for (i = 0; i < MaxPts; i++) {
  1849.             poly[i].x = random(maxx);
  1850.             poly[i].y = random(maxy);
  1851.             }
  1852.  
  1853.         MGL_setColor(randoml(maxcolor)+1);
  1854.         MGL_setBackColor(randoml(maxcolor)+1);
  1855.  
  1856.         if ((val = random(3)) == 0) {
  1857.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  1858.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1859.             }
  1860.         else if (val == 1) {
  1861.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  1862.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  1863.             }
  1864.         else {
  1865.             MGL_setPenStyle(SOLID_PATTERN);
  1866.             }
  1867.  
  1868.         MGL_fillPolygon(MaxPts,poly,0,0);
  1869.         }
  1870.  
  1871.     MGL_defaultAttributes();
  1872.     pause();
  1873. }
  1874.  
  1875. void fastPolyDemo(void)
  1876. /****************************************************************************
  1877. *
  1878. * Function:        fastPolyDemo
  1879. *
  1880. * Description:    Display a random pattern of convex triangular polygons
  1881. *                in replace mode at full speed.
  1882. *
  1883. ****************************************************************************/
  1884. {
  1885.     int        maxx,maxy;
  1886.     point    poly[3];            /* Space to hold polygon data    */
  1887.  
  1888.     mainWindow("MGL_fillPolygonFast Demonstration");
  1889.     statusLine("Press any key to continue, ESC to Abort");
  1890.  
  1891.     maxx = MGL_maxx();
  1892.     maxy = MGL_maxy();
  1893.  
  1894.     MGL_beginDrawing();
  1895.  
  1896.     while (!kbhit()) {
  1897.         /* Define a random polygon */
  1898.  
  1899.         poly[0].x = random(maxx);
  1900.         poly[0].y = random(maxy);
  1901.         poly[1].x = random(maxx);
  1902.         poly[1].y = random(maxy);
  1903.         poly[2].x = random(maxx);
  1904.         poly[2].y = random(maxy);
  1905.  
  1906.         MGL_setColor(randoml(maxcolor)+1);
  1907.         MGL_fillPolygon(3,poly,0,0);
  1908.         }
  1909.  
  1910.     MGL_endDrawing();
  1911.  
  1912.     MGL_defaultAttributes();
  1913.     pause();
  1914. }
  1915.  
  1916. void gouraudPolyDemo(void)
  1917. /****************************************************************************
  1918. *
  1919. * Function:        gouraudPolyDemo
  1920. *
  1921. * Description:    Display a random pattern of convex gouraud shaded
  1922. *                triangular polygons    at full speed.
  1923. *
  1924. ****************************************************************************/
  1925. {
  1926.     int        i,maxx,maxy;
  1927.     point    poly[3];            /* Space to hold polygon data            */
  1928.     color_t    colors[3];            /* Colors for each vertex of polygon    */
  1929.  
  1930.     /* Gouraud shading is not supported for devices with less than 256
  1931.      * colors.
  1932.      */
  1933.  
  1934.     if (maxcolor < 255)    return;
  1935.  
  1936.     mainWindow("MGL_fillGouraudPolygon Demonstration");
  1937.     statusLine("Press any key to continue, ESC to Abort");
  1938.  
  1939.     maxx = MGL_maxx();
  1940.     maxy = MGL_maxy();
  1941.  
  1942.     /* Setup the palette to show smooth shading between bright red and
  1943.      * bright blue. Note that we leave color 0 as black.
  1944.      */
  1945.  
  1946. //    if (maxcolor == 255) {
  1947.         pal[0].red = pal[0].green = pal[0].blue = 0;
  1948.         for (i = 1; i <= 255; i++) {
  1949.             pal[i].red = ((long)PALMAX * i) / 255;
  1950.             pal[i].green = 0;
  1951.             pal[i].blue = ((long)PALMAX * (255 - i)) / 255;
  1952.             }
  1953.         MGL_setPalette(pal,MGL_getPaletteSize(),0);
  1954. //        }
  1955.  
  1956.     MGL_beginDrawing();
  1957.  
  1958.     while (!kbhit()) {
  1959.         for (i = 0; i < 3; i++) {
  1960.             poly[i].x = random(maxx);
  1961.             poly[i].y = random(maxy);
  1962.             colors[i] = 1 + randoml(maxcolor-1);
  1963.             }
  1964.         MGL_fillGouraudPolygon(3,poly,colors,0,0);
  1965.         }
  1966.  
  1967.     MGL_endDrawing();
  1968.  
  1969.     MGL_defaultAttributes();
  1970.     MGL_setDefaultPalette();
  1971.     pause();
  1972. }
  1973.  
  1974. int fixAngle(int angle)
  1975. /****************************************************************************
  1976. *
  1977. * Function:        fixAngle
  1978. * Parameters:    angle
  1979. * Returns:        Equivalent angle in the range 0-360 degrees.
  1980. *
  1981. ****************************************************************************/
  1982. {
  1983.     while (angle < 0)
  1984.         angle += 360;
  1985.     while (angle >= 360)
  1986.         angle -= 360;
  1987.     return angle;
  1988. }
  1989.  
  1990. void pageFlipDemo(void)
  1991. /****************************************************************************
  1992. *
  1993. * Function:        pageFlipDemo
  1994. *
  1995. * Description:    If page flipping is available, this routine will perform
  1996. *                a reasonably complex animation sequence. We use a smart
  1997. *                dirty rectangle animation technique to only clear the
  1998. *                portion of the display page that has changed to get high
  1999. *                speed animation.
  2000. *
  2001. ****************************************************************************/
  2002. {
  2003.     int        maxx,maxy,stepx,stepy,secAngle,minAngle;
  2004.     rect    extent,dirtyRect;
  2005.  
  2006.     if (MGL_doubleBuffer()) {
  2007.         mainWindow("Page flip animation demo");
  2008.         statusLine("Press any key to continue, ESC to Abort");
  2009.  
  2010.         maxx = MGL_maxx();
  2011.         maxy = MGL_maxy();
  2012.  
  2013.         /* Draw title again for hidden page */
  2014.  
  2015.         MGL_swapBuffers();
  2016.         mainWindow("Page flip animation demo");
  2017.         statusLine("Press any key to continue, ESC to Abort");
  2018.  
  2019.         extent.left = extent.top = 0;
  2020.         extent.right = maxx/5;
  2021.         extent.bottom = ((long)extent.right * 1000) / aspect;
  2022.         dirtyRect = extent;
  2023.  
  2024.         stepx = 1;
  2025.         stepy = 1;
  2026.         secAngle = minAngle = 90;
  2027.  
  2028.         while (!kbhit()) {
  2029.             MGL_setColor(MGL_realColor(BLACK));
  2030.             MGL_fillRect(dirtyRect);
  2031.             MGL_setColor(MGL_realColor(RED));
  2032.             MGL_fillEllipse(extent);
  2033.             MGL_setColor(MGL_realColor(WHITE));
  2034.             MGL_fillEllipseArc(extent,secAngle-5,secAngle);
  2035.             MGL_fillEllipseArc(extent,minAngle-5,minAngle);
  2036.  
  2037.             /* Swap the display buffers */
  2038.  
  2039.             MGL_swapBuffers();
  2040.  
  2041.             /* Bounce the clock off the walls */
  2042.  
  2043.             dirtyRect = extent;
  2044.             MGL_insetRect(dirtyRect,-ABS(stepx),-ABS(stepy));
  2045.             if (extent.left + stepx < 0)
  2046.                 stepx = -stepx;
  2047.             if (extent.right + stepx > maxx)
  2048.                 stepx = -stepx;
  2049.  
  2050.             if (extent.top + stepy < 0)
  2051.                 stepy = -stepy;
  2052.             if (extent.bottom + stepy > maxy)
  2053.                 stepy = -stepy;
  2054.  
  2055.             MGL_offsetRect(extent,stepx,stepy);
  2056.  
  2057.             /* Update the hand movement */
  2058.  
  2059.             secAngle = fixAngle(secAngle - 5);
  2060.             if (secAngle == 90)
  2061.                 minAngle = fixAngle(minAngle - 5);
  2062.             }
  2063.  
  2064.         MGL_singleBuffer();
  2065.         MGL_defaultAttributes();
  2066.         pause();
  2067.         }
  2068.     else {
  2069.         mainWindow("Page flip animation demo");
  2070.  
  2071.         maxx = MGL_maxx();
  2072.         maxy = MGL_maxy();
  2073.  
  2074.         MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  2075.         MGL_moveToCoord(maxx/2,maxy/2);
  2076.         MGL_drawStr("Video mode does not support page flipping");
  2077.  
  2078.         pause();
  2079.         }
  2080. }
  2081.  
  2082. void mouseCursorDemo(void)
  2083. /****************************************************************************
  2084. *
  2085. * Function:        mouseCursorDemo
  2086. *
  2087. * Description:    Display the mouse cursor on the screen, and change it to
  2088. *                a number of different styles.
  2089. *
  2090. ****************************************************************************/
  2091. {
  2092.     /* First check to ensure that a mouse is actually installed in the
  2093.      * system. MS_init() will return 0 if no mouse is installed, or the
  2094.      * number of buttons if it is.
  2095.      */
  2096.  
  2097.     if (MS_init() > 0) {
  2098.         MS_show();
  2099.         mainWindow("Mouse Cursor Demonstration");
  2100.         statusLine("Press any key for CHECK cursor");
  2101.  
  2102.         getch();
  2103.         MS_setCursor(&CHECK);
  2104.         statusLine("Press any key for CROSS cursor");
  2105.  
  2106.         getch();
  2107.         MS_setCursor(&CROSS);
  2108.         statusLine("Press any key for GLOVE cursor");
  2109.  
  2110.         getch();
  2111.         MS_setCursor(&GLOVE);
  2112.         statusLine("Press any key for IBEAM cursor");
  2113.  
  2114.         getch();
  2115.         MS_setCursor(&IBEAM);
  2116.         statusLine("Press any key for DEFAULT cursor");
  2117.  
  2118.         getch();
  2119.         MS_setCursor(&DEF_CURSOR);
  2120.  
  2121.         pause();
  2122.         MS_hide();
  2123.         }
  2124. }
  2125.  
  2126. #ifdef    FLOODFILL_DEMO
  2127.  
  2128. /* Function prototypes for floodfill routines in 'ffill.c' */
  2129.  
  2130. void MGL_interiorFill(int x,int y);
  2131. void MGL_boundaryFill(int x,int y,color_t bdr);
  2132.  
  2133. /* We need a rather large stack to fill high resolution displays! */
  2134.  
  2135. #ifdef  __TURBOC__
  2136. extern unsigned _stklen = 51200U;
  2137. #endif
  2138.  
  2139. void boundaryFillDemo(void)
  2140. /****************************************************************************
  2141. *
  2142. * Function:        boundaryFillDemo
  2143. *
  2144. * Description:    Demonstrate the boundary flood fill routine.
  2145. *
  2146. ****************************************************************************/
  2147. {
  2148.     int     i,j,maxx,maxy;
  2149.     color_t color;
  2150.     point    poly[6];
  2151.  
  2152.     mainWindow("MGL_boundaryFill Demonstration");
  2153.  
  2154.     maxx = MGL_maxx();
  2155.     maxy = MGL_maxy();
  2156.  
  2157.     srand(200);
  2158.  
  2159.     /* Draw a set of polygons */
  2160.  
  2161.     for (j = 0; j < 3; j++) {
  2162.         color = random(10);                /* Keep random in sync            */
  2163.         color = (j == 0) ? BLUE : (j == 1) ? RED : YELLOW;
  2164.  
  2165.         for (i = 0; i < 6; i++) {
  2166.             poly[i].x = random(maxx);
  2167.             poly[i].y = random(maxy);
  2168.             }
  2169.  
  2170.         MGL_setColor(MGL_realColor(color));
  2171.         MGL_fillPolygon(6,poly,0,0);
  2172.         }
  2173.  
  2174.     MGL_setColor(MGL_defaultColor());
  2175.     statusLine("Press a key for boundary fill");
  2176.     getch();
  2177.  
  2178.     MGL_setColor(MGL_realColor(GREEN));
  2179.     MGL_boundaryFill(10,10,MGL_realColor(RED));
  2180.  
  2181.     MGL_setColor(MGL_defaultColor());
  2182.     pause();
  2183. }
  2184.  
  2185. void interiorFillDemo(void)
  2186. /****************************************************************************
  2187. *
  2188. * Function:        interiorFillDemo
  2189. *
  2190. * Description:    Demonstrate the interior flood fill routine.
  2191. *
  2192. ****************************************************************************/
  2193. {
  2194.     int     i,j,maxx,maxy;
  2195.     color_t color;
  2196.     point    poly[6];
  2197.  
  2198.     mainWindow("MGL_interiorFill Demonstration");
  2199.  
  2200.     maxx = MGL_maxx();
  2201.     maxy = MGL_maxy();
  2202.  
  2203.     srand(200);
  2204.  
  2205.     /* Draw a set of polygons */
  2206.  
  2207.     for (j = 0; j < 3; j++) {
  2208.         color = random(10);                /* Keep random in sync            */
  2209.         color = (j == 0) ? BLUE : (j == 1) ? RED : YELLOW;
  2210.  
  2211.         for (i = 0; i < 6; i++) {
  2212.             poly[i].x = random(maxx);
  2213.             poly[i].y = random(maxy);
  2214.             }
  2215.  
  2216.         MGL_setColor(MGL_realColor(color));
  2217.         MGL_fillPolygon(6,poly,0,0);
  2218.         }
  2219.  
  2220.     MGL_setColor(MGL_defaultColor());
  2221.     statusLine("Press a key for interior fill");
  2222.     getch();
  2223.  
  2224.     MGL_setColor(MGL_realColor(GREEN));
  2225.     MGL_interiorFill(10,10);
  2226.  
  2227.     MGL_setColor(MGL_defaultColor());
  2228.     pause();
  2229. }
  2230.  
  2231. #endif
  2232.  
  2233. #define    POINTS    10
  2234.  
  2235. int        data1[POINTS] = { 1, 3, 5, 4, 3, 2, 1, 5, 4, 2 };
  2236. int        data2[POINTS] = { 4, 6, 10, 2, 6, 4, 8, 10, 6, 2 };
  2237. int        data3[POINTS] = { 1, 3, 2, 5, 7, 9, 5, 4, 5, 8 };
  2238.  
  2239. void markerDemo(void)
  2240. /****************************************************************************
  2241. *
  2242. * Function:        markerDemo
  2243. *
  2244. * Description:    Draws a simple graph using markers to show to points on
  2245. *                the graph.
  2246. *
  2247. ****************************************************************************/
  2248. {
  2249.     int        i,stepx,stepy,maxy,maxx;
  2250.     point    p[POINTS];
  2251.  
  2252.     mainWindow("Marker Demonstration");
  2253.  
  2254.     maxx = MGL_maxx();
  2255.     maxy = MGL_maxy();
  2256.     stepx = maxx / 12;
  2257.     stepy = maxy / 12;
  2258.  
  2259.     /* Draw the graph axes */
  2260.  
  2261.     MGL_lineCoord(stepx,maxy - stepy,stepx*11,maxy-stepy);
  2262.     MGL_lineCoord(stepx,maxy - stepy,stepx,maxy - stepy*11);
  2263.  
  2264.     for (i = stepx*11; i >= stepx; i -= stepx)
  2265.         MGL_lineCoord(i,maxy - stepy - 3,i,maxy - stepy + 3);
  2266.  
  2267.     for (i = maxy - stepy; i >= maxy-stepy*11; i -= stepy)
  2268.         MGL_lineCoord(stepx-3,i,stepx+3,i);
  2269.  
  2270.     /* Draw the first set of data */
  2271.  
  2272.     for (i = 0; i < POINTS; i++) {
  2273.         p[i].x = stepx + i*stepx;
  2274.         p[i].y = maxy - stepy - data1[i]*stepy;
  2275.         }
  2276.  
  2277.     MGL_setMarkerSize(4);
  2278.     MGL_setColor(MGL_realColor(LIGHTRED));
  2279.     MGL_polyLine(POINTS,p);
  2280.     MGL_setMarkerColor(MGL_realColor(MAGENTA));
  2281.     MGL_polyMarker(POINTS,p);
  2282.  
  2283.     /* Draw the second set of data */
  2284.  
  2285.     for (i = 0; i < POINTS; i++) {
  2286.         p[i].x = stepx + i*stepx;
  2287.         p[i].y = maxy - stepy - data2[i]*stepy;
  2288.         }
  2289.  
  2290.     MGL_setColor(MGL_realColor(LIGHTGREEN));
  2291.     MGL_polyLine(POINTS,p);
  2292.     MGL_setMarkerColor(MGL_realColor(MAGENTA));
  2293.     MGL_setMarkerStyle(MARKER_CIRCLE);
  2294.     MGL_polyMarker(POINTS,p);
  2295.  
  2296.     /* Draw the third set of data */
  2297.  
  2298.     for (i = 0; i < POINTS; i++) {
  2299.         p[i].x = stepx + i*stepx;
  2300.         p[i].y = maxy - stepy - data3[i]*stepy;
  2301.         }
  2302.  
  2303.     MGL_setColor(MGL_realColor(LIGHTBLUE));
  2304.     MGL_polyLine(POINTS,p);
  2305.     MGL_setMarkerColor(MGL_realColor(MAGENTA));
  2306.     MGL_setMarkerStyle(MARKER_X);
  2307.     MGL_polyMarker(POINTS,p);
  2308.  
  2309.     MGL_defaultAttributes();
  2310.     pause();
  2311. }
  2312.  
  2313. void finale(void)
  2314. /****************************************************************************
  2315. *
  2316. * Function:        finale
  2317. *
  2318. * Description:    Display a goodbye message before signing off.
  2319. *
  2320. ****************************************************************************/
  2321. {
  2322.     mainWindow("Finale");
  2323.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  2324.  
  2325.     MGL_useFont(largeFont);
  2326.     MGL_drawStrXY(MGL_maxx()/2,MGL_maxy()/2,"Thats all folks!");
  2327.     statusLine("Press any key exit...");
  2328.     pause();
  2329. }
  2330.  
  2331. void cdecl main(int argc,char *argv[])
  2332. {
  2333.     int        option;
  2334.     char    *argument;
  2335.  
  2336.     /* Parse command line options */
  2337.     do {
  2338.         option = getopt(argc,argv,"Ee:Vv:FfBbSsPp:Hh",&argument);
  2339.         if (option > 0) option = tolower(option);
  2340.         switch(option) {
  2341.             case 'e':
  2342.                 forceDriver = grEGA;
  2343.                 break;
  2344.             case 'v':
  2345.                 if (tolower(argument[0]) == 'g')
  2346.                     forceDriver = grVGA;
  2347.                 else if (tolower(argument[0]) == 'e')
  2348.                     forceDriver = grSVGA;
  2349.                 else help();
  2350.                 break;
  2351.             case 'f':
  2352.                 MGL_slowSuperVGA(true);
  2353.                 break;
  2354.             case 'b':
  2355.                 MGL_useBIOSPalette(true);
  2356.                 break;
  2357.             case 's':
  2358.                 MGL_slowPalette(true);
  2359.                 break;
  2360.             case 'p':
  2361.                 snowlevel = atoi(argument);
  2362.                 break;
  2363.             case INVALID:
  2364.             case 'h':
  2365.                 help();
  2366.             }
  2367.         } while (option != ALLDONE && option != PARAMETER);
  2368.  
  2369.     /* Set the system into graphics mode */
  2370.  
  2371.     if (nextargv >= argc)
  2372.         startGraphics(NULL);
  2373.     else
  2374.         startGraphics(argv[nextargv]);
  2375.  
  2376.     reportStatus();        /* Report status of graphics system                */
  2377.     colorDemo();
  2378.     paletteDemo();
  2379.     pixelDemo();
  2380.     imageDemo();
  2381.     rectangleDemo();
  2382.     circleDemo();
  2383.     filledCircleDemo();
  2384.     arcDemo();
  2385.     filledArcDemo();
  2386.     polyDemo();
  2387.     fastPolyDemo();
  2388.     gouraudPolyDemo();
  2389.     pieDemo();
  2390.     lineDemo();
  2391.     lineRelDemo();
  2392.     lineToDemo();
  2393.     patternDemo();
  2394.     markerDemo();
  2395.     pageFlipDemo();
  2396.  
  2397. #if defined(FLOODFILL_DEMO) && !defined(__MSC__)
  2398.     boundaryFillDemo();
  2399.     interiorFillDemo();
  2400. #endif
  2401.  
  2402.     mouseCursorDemo();
  2403.     textDump();
  2404.     textStyleDemo();
  2405.     CRTModeDemo();
  2406.     finale();
  2407.  
  2408.     MGL_exit();            /* Close graphics system and restore text mode    */
  2409. }
  2410.