home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / demo / demoarea.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  32.8 KB  |  1,204 lines

  1. /****************************************************************************
  2. *
  3. *                Visual - A 3D Scientific Visualisation Program
  4. *
  5. *                    Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: demoarea.cpp $
  9. * Version:        $Revision: 1.2 $
  10. *
  11. * Language:        C++ 3.0
  12. * Environment:    any
  13. *
  14. * Description:    Member functions for the class DemoArea, a class for
  15. *                performing demos in a double buffered rendering area.
  16. *
  17. *                Note that the rendering area does not use the standard
  18. *                MegaVision color model, but uses the native color model of
  19. *                the current MGL video mode (color mapped or RGB).
  20. *
  21. * $Id: demoarea.cpp 1.2 1994/03/09 11:29:32 kjb release $
  22. *
  23. ****************************************************************************/
  24.  
  25. #include "demo.hpp"
  26.  
  27. #pragma    hdrstop
  28.  
  29. #include "demoarea.hpp"
  30. #include <dos.h>
  31. #include <stdio.h>
  32. #include <stdarg.h>
  33.  
  34. /*----------------------------- Implementation ----------------------------*/
  35.  
  36. // We need a rather large stack to flood fill high resolution displays!
  37.  
  38. extern unsigned _stklen = 51200U;
  39.  
  40. // Define the text displayed in the Explanation window during the demos
  41.  
  42. char welcomeText[] = "Welcome the the MegaGraph Graphics Library, a high "
  43.                      "performance graphics library for PC's. This program "
  44.                      "will give you an idea of the kind of primitives that "
  45.                      "the library supports, and the sort of things you can "
  46.                      "do with it.";
  47.  
  48. char lineText1[] =   "The MGL can draw lines - blindingly fast! "
  49.                      "Click to continue...";
  50. char lineText2[] =   "Of course, you are not restricted to drawing lines "
  51.                      "that are a single pixel wide. You can use an "
  52.                      "arbitrary pen width, and an arbitrary pen pattern "
  53.                      "if you so desire. Click to continue...";
  54.  
  55. char ellipseText[] = "The MGL can draw ellipses any way you like. They can "
  56.                      "be outlined in an arbitrary rectangular pen, or they "
  57.                      "can of course be filled. Click to continue...";
  58.  
  59. char arcText[] =     "The MGL can draw elliptical arc's any way you like. "
  60.                      "They can be outlined, or they can of course be filled. "
  61.                      "Click to continue...";
  62.  
  63. char rectText[] =     "The MGL can draw rectangles any way you like. They "
  64.                      "can be outlined, or they can of course be filled. "
  65.                      "Click to continue...";
  66.  
  67. char polyText1[] =      "The MGL can draw arbitrary polgyons in any pattern "
  68.                      "you like. Click to continue...";
  69. char polyText2[] =   "However the MGL can also render convex polygons "
  70.                      "- blindingly fast! Click to continue...";
  71. char polyText3[] =   "But that is not all, how about some smooth shaded "
  72.                      "polygons? Click to continue...";
  73.  
  74. char colorText1[] =  "The MGL works with 24 bit color values internally "
  75.                      "and in color mapped modes like this you can assign "
  76.                      "a color value to any index you like. This mode can "
  77.                      "handle sixteen simulataneous colors at once. ";
  78. char colorText2[] =  "The MGL works with 24 bit color values internally "
  79.                      "and in color mapped modes like this you can assign "
  80.                      "a color value to any index you like. This mode can "
  81.                      "handle 256 simulataneous colors at once. Click to "
  82.                      "continue...";
  83. char colorText3[] =  "The MGL can also do high speed palette rotations. "
  84.                      "Click to continue...";
  85. char colorText4[] =  "Of course you can rotate the other direction also. "
  86.                      "Click to continue...";
  87. char colorText5[] =  "And naturally you can perform the classic palette "
  88.                      "fade in and out!";
  89. char colorText6[] =  "The MGL works with 24 bit color values internally "
  90.                      "and in TrueColor (or direct color) modes like this "
  91.                      "you can specify each color value directly.";
  92.  
  93. char patText[] =      "The MGL can fill with any arbitrary pattern that "
  94.                      "you can think up. Naturally it comes with a good "
  95.                      "selection of patterns that you can use right away.";
  96.  
  97. char markerText[] =     "The MGL can also plot markers, which are great for "
  98.                      "creating graphs and charts.";
  99.  
  100. char floodText1[] =  "The MGL can also perform very fast flood fills, both "
  101.                      "boundary fills and interior fills. Click to perform "
  102.                      "a boundary fill...";
  103. char floodText2[] =  "Click to continue...";
  104. char floodText3[] =  "Click to perform an interior fill...";
  105.  
  106. char animText1[] =      "The MGL can also perform smooth animation using "
  107.                      "double buffering techniques. Click to continue...";
  108. char animText2[] =   "Unfortunately this video mode does not support "
  109.                      "buffering, so the animation is unavailable.";
  110.  
  111. #define SWAP(a,b)    { a^=b; b^=a; a^=b; }
  112. #define    MAXNUM    1000
  113.  
  114. int            backColor = scJade;
  115. int            maxx,maxy,val;
  116. attributes    attr;
  117. color_t        maxcolor;
  118. point        p[MAXNUM+1];
  119.  
  120. // Array of useful patterns
  121.  
  122. #define    NUMPATS    (sizeof(bitpat) / sizeof(bitpat[0]))
  123.  
  124. pattern bitpat[] = {
  125.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  126.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  127.     {0x7F, 0xFF, 0xF7, 0xFF, 0x7F, 0xFF, 0xF7, 0xFF},
  128.     {0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77},
  129.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  130.     {0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF},
  131.     {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
  132.     {0xEE, 0xDD, 0xBB, 0x77, 0xEE, 0xDD, 0xBB, 0x77},
  133.     {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88},
  134.     {0xB1, 0x30, 0x03, 0x1B, 0xD8, 0xC0, 0x0C, 0x8D},
  135.     {0x80, 0x10, 0x02, 0x20, 0x01, 0x08, 0x40, 0x04},
  136.     {0xFF, 0x88, 0x88, 0x88, 0xFF, 0x88, 0x88, 0x88},
  137.     {0xFF, 0x80, 0x80, 0x80, 0xFF, 0x08, 0x08, 0x08},
  138.     {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  139.     {0x80, 0x40, 0x20, 0x00, 0x02, 0x04, 0x08, 0x00},
  140.     {0x82, 0x44, 0x39, 0x44, 0x82, 0x01, 0x01, 0x01},
  141.     {0xF8, 0x74, 0x22, 0x47, 0x8F, 0x17, 0x22, 0x71},
  142.     {0x55, 0xA0, 0x40, 0x40, 0x55, 0x0A, 0x04, 0x04},
  143.     {0x20, 0x50, 0x88, 0x88, 0x88, 0x88, 0x05, 0x02},
  144.     {0xBF, 0x00, 0xBF, 0xBF, 0xB0, 0xB0, 0xB0, 0xB0},
  145.  
  146.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  147.     {0x80, 0x00, 0x08, 0x00, 0x80, 0x00, 0x08, 0x00},
  148.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  149.     {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22},
  150.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  151.     {0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00},
  152.     {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88},
  153.     {0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00},
  154.     {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80},
  155.     {0xAA, 0x00, 0x80, 0x00, 0x88, 0x00, 0x80, 0x00},
  156.     {0xFF, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
  157.     {0x08, 0x1C, 0x22, 0xC1, 0x80, 0x01, 0x02, 0x04},
  158.     {0x88, 0x14, 0x22, 0x41, 0x88, 0x00, 0xAA, 0x00},
  159.     {0x40, 0xA0, 0x00, 0x00, 0x04, 0x0A, 0x00, 0x00},
  160.     {0x03, 0x84, 0x48, 0x30, 0x0C, 0x02, 0x01, 0x01},
  161.     {0x80, 0x80, 0x41, 0x3E, 0x08, 0x08, 0x14, 0xE3},
  162.     {0x10, 0x20, 0x54, 0xAA, 0xFF, 0x02, 0x04, 0x08},
  163.     {0x77, 0x89, 0x8F, 0x8F, 0x77, 0x98, 0xF8, 0xF8},
  164.     {0x00, 0x08, 0x14, 0x2A, 0x55, 0x2A, 0x14, 0x08},
  165.     {0x00, 0x08, 0x14, 0x2A, 0x55, 0x2A, 0x14, 0x08},
  166.  
  167.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  168.     {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  169.     {0x80, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00},
  170.     {0x88, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00},
  171.     {0x88, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00},
  172.     {0x88, 0x00, 0x20, 0x00, 0x88, 0x00, 0x00, 0x00},
  173.     {0x88, 0x00, 0x20, 0x00, 0x88, 0x00, 0x02, 0x00},
  174.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x02, 0x00},
  175.     {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  176.     {0xA8, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
  177.     {0xA8, 0x00, 0x22, 0x00, 0x8A, 0x00, 0x22, 0x00},
  178.     {0xAA, 0x00, 0x22, 0x00, 0x8A, 0x00, 0x22, 0x00},
  179.     {0xAA, 0x00, 0x22, 0x00, 0xAA, 0x00, 0x22, 0x00},
  180.     {0xAA, 0x00, 0xA2, 0x00, 0xAA, 0x00, 0x22, 0x00},
  181.     {0xAA, 0x00, 0xA2, 0x00, 0xAA, 0x00, 0x2A, 0x00},
  182.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0x2A, 0x00},
  183.     {0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  184.     {0xAA, 0x40, 0xAA, 0x00, 0xAA, 0x00, 0xAA, 0x00},
  185.     {0xAA, 0x40, 0xAA, 0x00, 0xAA, 0x04, 0xAA, 0x00},
  186.     {0xAA, 0x44, 0xAA, 0x00, 0xAA, 0x04, 0xAA, 0x00},
  187.     {0xAA, 0x44, 0xAA, 0x00, 0xAA, 0x44, 0xAA, 0x00},
  188.     {0xAA, 0x44, 0xAA, 0x10, 0xAA, 0x44, 0xAA, 0x00},
  189.     {0xAA, 0x44, 0xAA, 0x10, 0xAA, 0x44, 0xAA, 0x01},
  190.     {0xAA, 0x44, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x01},
  191.     {0xAA, 0x44, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x11},
  192.     {0xAA, 0x54, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x11},
  193.     {0xAA, 0x54, 0xAA, 0x11, 0xAA, 0x45, 0xAA, 0x11},
  194.     {0xAA, 0x55, 0xAA, 0x11, 0xAA, 0x45, 0xAA, 0x11},
  195.     {0xAA, 0x55, 0xAA, 0x11, 0xAA, 0x55, 0xAA, 0x11},
  196.     {0xAA, 0x55, 0xAA, 0x51, 0xAA, 0x55, 0xAA, 0x11},
  197.     {0xAA, 0x55, 0xAA, 0x51, 0xAA, 0x55, 0xAA, 0x15},
  198.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x15},
  199.     {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  200.     {0xEA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55},
  201.     {0xEA, 0x55, 0xAA, 0x55, 0xAE, 0x55, 0xAA, 0x55},
  202.     {0xEE, 0x55, 0xAA, 0x55, 0xAE, 0x55, 0xAA, 0x55},
  203.     {0xEE, 0x55, 0xAA, 0x55, 0xEE, 0x55, 0xAA, 0x55},
  204.     {0xEE, 0x55, 0xBA, 0x55, 0xEE, 0x55, 0xAA, 0x55},
  205.     {0xEE, 0x55, 0xBA, 0x55, 0xEE, 0x55, 0xAB, 0x55},
  206.     {0xEE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xAB, 0x55},
  207.     {0xEE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xBB, 0x55},
  208.     {0xFE, 0x55, 0xBB, 0x55, 0xEE, 0x55, 0xBB, 0x55},
  209.     {0xFE, 0x55, 0xBB, 0x55, 0xEF, 0x55, 0xBB, 0x55},
  210.     {0xFF, 0x55, 0xBB, 0x55, 0xEF, 0x55, 0xBB, 0x55},
  211.     {0xFF, 0x55, 0xBB, 0x55, 0xFF, 0x55, 0xBB, 0x55},
  212.     {0xFF, 0x55, 0xFB, 0x55, 0xFF, 0x55, 0xBB, 0x55},
  213.     {0xFF, 0x55, 0xFB, 0x55, 0xFF, 0x55, 0xBF, 0x55},
  214.     {0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xBF, 0x55},
  215.     {0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55},
  216.     {0xFF, 0xD5, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x55},
  217.     {0xFF, 0xD5, 0xFF, 0x55, 0xFF, 0x5D, 0xFF, 0x55},
  218.     {0xFF, 0xDD, 0xFF, 0x55, 0xFF, 0x5D, 0xFF, 0x55},
  219.     {0xFF, 0xDD, 0xFF, 0x55, 0xFF, 0xDD, 0xFF, 0x55},
  220.     {0xFF, 0xDD, 0xFF, 0x75, 0xFF, 0xDD, 0xFF, 0x55},
  221.     {0xFF, 0xDD, 0xFF, 0x75, 0xFF, 0xDD, 0xFF, 0x57},
  222.     {0xFF, 0xDD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x57},
  223.     {0xFF, 0xDD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x77},
  224.     {0xFF, 0xFD, 0xFF, 0x77, 0xFF, 0xDD, 0xFF, 0x77},
  225.     {0xFF, 0xFD, 0xFF, 0x77, 0xFF, 0xDF, 0xFF, 0x77},
  226.     {0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xDF, 0xFF, 0x77},
  227.     {0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xFF, 0xFF, 0x77},
  228.     {0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x77},
  229.     {0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x7F},
  230.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F},
  231.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
  232.     };
  233.  
  234. long randoml(long max)
  235. /****************************************************************************
  236. *
  237. * Function:        randoml
  238. * Parameters:    max    - Maximum random number value+1
  239. * Returns:        Random long between 0 and max-1.
  240. *
  241. * Description:    Routine to compute random long numbers. We do this simply
  242. *                by expanding a random integer into the correct range,
  243. *                which means some values will never get generated :-(,
  244. *                but hell, it works for what we want (it will also fail
  245. *                for large numbers).
  246. *
  247. ****************************************************************************/
  248. {
  249.     return ((float)random(MAXINT) * max) / (float)MAXINT;
  250. }
  251.  
  252. bool done(void)
  253. /****************************************************************************
  254. *
  255. * Function:        done
  256. * Returns:        True if a mouse click or key was pressed.
  257. *
  258. ****************************************************************************/
  259. {
  260.     TEvent    evt;
  261.  
  262.     if (eventQueue.getNext(evt) && (evt.what & (evKeyboard | evMouseUp)))
  263.         return true;
  264.     return false;
  265. }
  266.  
  267. void halt(void)
  268. /****************************************************************************
  269. *
  270. * Function:        halt
  271. *
  272. * Description:    Halts until a key is pressed or the mouse is clicked.
  273. *
  274. ****************************************************************************/
  275. {
  276.     eventQueue.flush();
  277.     while (!done());
  278. }
  279.  
  280. void clearView(void)
  281. {
  282.     MGL_setColor(MGL_realColor(backColor));
  283.     MGL_fillRectCoord(0,0,MGL_maxx()+1,MGL_maxy()+1);
  284. }
  285.  
  286. void beginDemo(void)
  287. /****************************************************************************
  288. *
  289. * Function:        beginDemo
  290. *
  291. * Description:    Begin the next demo.
  292. *
  293. ****************************************************************************/
  294. {
  295.     maxx = MGL_maxx();
  296.     maxy = MGL_maxy();
  297.     maxcolor = MGL_maxColor();
  298.     MGL_getAttributes(&attr);
  299.     TProgram::application->setSystemPalette();
  300.     clearView();
  301.     eventQueue.flush();
  302. }
  303.  
  304. void endDemo(void)
  305. /****************************************************************************
  306. *
  307. * Function:        endDemo
  308. *
  309. * Description:    Ends the demonstration
  310. *
  311. ****************************************************************************/
  312. {
  313.     MGL_restoreAttributes(&attr);
  314. }
  315.  
  316. DemoArea::DemoArea(const TRect& bounds)
  317.     : TRenderArea(bounds)
  318. /****************************************************************************
  319. *
  320. * Function:        DemoArea::DemoArea
  321. * Parameters:    bounds        - Bounding box for the rendering area
  322. *
  323. * Description:    Constructor for the DemoArea class.
  324. *
  325. ****************************************************************************/
  326. {
  327.     cntDemo = -1;
  328. }
  329.  
  330. void DemoArea::handleEvent(TEvent& event,phaseType)
  331. /****************************************************************************
  332. *
  333. * Function:        DemoArea::handleEvent
  334. * Parameters:    event    - Event to handle
  335. *                phase    - Current phase for the event (pre,focus,post)
  336. *
  337. * Description:    Event handling routine for the DemoArea class.
  338. *
  339. ****************************************************************************/
  340. {
  341.     if (event.what == evBroadcast) {
  342.         switch (event.message.command) {
  343.             case cmLineDemo:
  344.             case cmEllipseDemo:
  345.             case cmArcDemo:
  346.             case cmPolygonDemo:
  347.             case cmRectangleDemo:
  348.             case cmColorDemo:
  349.             case cmMarkerDemo:
  350.             case cmPatternDemo:
  351.             case cmFloodFillDemo:
  352.             case cmAnimationDemo:
  353.                 cntDemo = event.message.command;
  354.                 repaint();                // Force repaint to execute the demo
  355.                 clearEvent(event);
  356.                 break;
  357.             }
  358.         }
  359. }
  360.  
  361. static int gprintf(char *fmt, ... )
  362. /****************************************************************************
  363. *
  364. * Function:        gprintf
  365. * Parameters:    fmt        - Format string
  366. *                ...        - Standard printf style parameters
  367. * Returns:        Number of items converted successfully.
  368. *
  369. * Description:    Simple printf style output routine for sending text to
  370. *                the current viewport. It begins drawing the string at
  371. *                the current CP location, and move the CP to the start of
  372. *                the next logical line.
  373. *
  374. ****************************************************************************/
  375. {
  376.     va_list    argptr;                    /* Argument list pointer            */
  377.     char    buf[255];                /* Buffer to build sting into        */
  378.     int        cnt;                    /* Result of SPRINTF for return     */
  379.     Point    CP;
  380.  
  381.     va_start(argptr,fmt);
  382.  
  383.     cnt = vsprintf(buf,fmt,argptr);
  384.     MGL_getCP(&CP);
  385.     MGL_drawStr(buf);                /* Display the string                */
  386.     CP.y += MGL_textHeight();        /* Advance to next line                */
  387.     MGL_moveTo(CP);
  388.  
  389.     va_end(argptr);
  390.  
  391.     return cnt;                        /* Return the conversion count        */
  392. }
  393.  
  394. void DemoArea::displayStatusInfo()
  395. /****************************************************************************
  396. *
  397. * Function:        DemoArea::displayStatusInfo
  398. *
  399. * Description:    Displays status information about the current video mode.
  400. *                This is used to paint the demonstration window when no
  401. *                demonstration is currently running.
  402. *
  403. ****************************************************************************/
  404. {
  405.     setDemoTitle("Status Information");
  406.     setInfoText(welcomeText);
  407.  
  408.     MGL_moveToCoord(10,10);
  409.  
  410.     /* Get required information */
  411.  
  412.     MGL_setColor(MGL_realColor(scWhite));
  413.  
  414.     gprintf("Graphics device: (%d) %s", MGL_getDriver(),
  415.         MGL_driverName(MGL_getDriver()));
  416.     gprintf("Graphics mode: (%d) %s", MGL_getMode(),
  417.         MGL_modeName(MGL_getMode()));
  418.     gprintf("Screen resolution: ( 0, 0, %d, %d )",MGL_sizex(),MGL_sizey());
  419.     gprintf("Colors available: %ld", MGL_maxColor()+1);
  420.     gprintf("Maximum Page Index: %d", MGL_maxPage());
  421.  
  422.     attributes        attr;
  423.     text_settings    tset;
  424.  
  425.     MGL_getAttributes(&attr);
  426.     tset = attr.tsettings;        /* Make an alias */
  427.     gprintf("Current font: %s", tset.fnt->name);
  428. }
  429.  
  430. void lineSpeedDemo()
  431. {
  432.     int        i,j;
  433.  
  434.     beginDemo();
  435.  
  436.     for (i = 0; i < MAXNUM; i++) {
  437.         p[i].x = random(maxx);
  438.         p[i].y = random(maxy);
  439.         }
  440.  
  441.     MGL_beginDrawing();
  442.     for (j = 0; j < 10; j++) {
  443.         MGL_setColor(MGL_realColor(j+1));
  444.         for (i = 0; i < MAXNUM; i++)
  445.             MGL_lineFast(p[i],p[i+1]);
  446.         }
  447.     MGL_endDrawing();
  448.     endDemo();
  449. }
  450.  
  451. void lineNormalDemo()
  452. {
  453.     point        p1,p2;
  454.  
  455.     beginDemo();
  456.     MGL_beginDrawing();
  457.     while (!done()) {
  458.         p1.x = random(maxx);
  459.         p1.y = random(maxy);
  460.         p2.x = random(maxx);
  461.         p2.y = random(maxy);
  462.  
  463.         MGL_setColor(randoml(maxcolor)+1);
  464.         MGL_setBackColor(randoml(maxcolor)+1);
  465.         MGL_setPenSize(random(5)+1,random(5)+1);
  466.  
  467.         if ((val = random(5)) == 0) {
  468.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  469.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  470.             }
  471.         else if (val == 1) {
  472.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  473.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  474.             }
  475.         else MGL_setPenStyle(SOLID_PATTERN);
  476.  
  477.         MGL_lineFast(p1,p2);
  478.         }
  479.     MGL_endDrawing();
  480.     endDemo();
  481. }
  482.  
  483. void DemoArea::lineDemo()
  484. {
  485.     setDemoTitle("Line Demonstration");
  486.     setInfoText(lineText1);
  487.     halt();
  488.     setInfoText("");
  489.     lineSpeedDemo();
  490.     delay(500);
  491.     setInfoText(lineText2);
  492.     lineNormalDemo();
  493.     cntDemo = -1;
  494. }
  495.  
  496. void DemoArea::ellipseDemo()
  497. {
  498.     setDemoTitle("Ellipse Demonstration");
  499.     setInfoText(ellipseText);
  500.     beginDemo();
  501.  
  502.     TRect    r;
  503.  
  504.     while (!done()) {
  505.         r.left() = random(maxx-100);
  506.         r.top() = random(maxy-100);
  507.         r.right() = r.left() + random(100);
  508.         r.bottom() = r.top() + random(100);
  509.  
  510.         MGL_setColor(randoml(maxcolor)+1);
  511.         MGL_setBackColor(randoml(maxcolor)+1);
  512.  
  513.         MGL_setPenSize(random(5)+1,random(5)+1);
  514.  
  515.         if ((val = random(5)) == 1) {
  516.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  517.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  518.             }
  519.         else if (val == 2) {
  520.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  521.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  522.             }
  523.         else MGL_setPenStyle(SOLID_PATTERN);
  524.  
  525.         if (random(3) == 0)
  526.             MGL_fillEllipse(r);
  527.         else
  528.             MGL_ellipse(r);
  529.         }
  530.  
  531.     endDemo();
  532.     cntDemo = -1;
  533. }
  534.  
  535. void DemoArea::arcDemo()
  536. {
  537.     setDemoTitle("Elliptical Arc Demonstration");
  538.     setInfoText(arcText);
  539.     beginDemo();
  540.  
  541.     int     startAngle,endAngle;
  542.     TRect    r;
  543.  
  544.     beginDemo();
  545.     while (!done()) {
  546.         r.left() = random(maxx-100);
  547.         r.top() = random(maxy-100);
  548.         r.right() = r.left() + random(100);
  549.         r.bottom() = r.top() + random(100);
  550.         startAngle = random(360);
  551.         endAngle = random(360);
  552.  
  553.         MGL_setColor(randoml(maxcolor)+1);
  554.         MGL_setBackColor(randoml(maxcolor)+1);
  555.  
  556.         MGL_setPenSize(random(5)+1,random(5)+1);
  557.  
  558.         if ((val = random(5)) == 1) {
  559.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  560.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  561.             }
  562.         else if (val == 2) {
  563.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  564.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  565.             }
  566.         else MGL_setPenStyle(SOLID_PATTERN);
  567.  
  568.         if (random(3) == 0)
  569.             MGL_fillEllipseArc(r,startAngle,endAngle);
  570.         else
  571.             MGL_ellipseArc(r,startAngle,endAngle);
  572.         }
  573.     endDemo();
  574.     cntDemo = -1;
  575. }
  576.  
  577. void DemoArea::rectangleDemo()
  578. {
  579.     setDemoTitle("Rectangle Demonstration");
  580.     setInfoText(rectText);
  581.     beginDemo();
  582.  
  583.     TRect    r;
  584.  
  585.     while (!done()) {
  586.         r.left() = random(maxx);
  587.         r.right() = random(maxx);
  588.         r.top() = random(maxy);
  589.         r.bottom() = random(maxy);
  590.  
  591.         /* Fix the rectangle so it is not empty */
  592.  
  593.         if (r.right() < r.left())
  594.             SWAP(r.left(),r.right());
  595.         if (r.bottom() < r.top())
  596.             SWAP(r.top(),r.bottom());
  597.  
  598.         MGL_setColor(randoml(maxcolor)+1);
  599.         MGL_setBackColor(randoml(maxcolor)+1);
  600.  
  601.         MGL_setPenSize(random(5)+1,random(5)+1);
  602.  
  603.         if ((val = random(5)) == 1) {
  604.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  605.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  606.             }
  607.         else if (val == 2) {
  608.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  609.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  610.             }
  611.         else MGL_setPenStyle(SOLID_PATTERN);
  612.  
  613.         if (random(3) == 0)
  614.             MGL_rect(r);
  615.         else
  616.             MGL_fillRect(r);
  617.         }
  618.  
  619.     endDemo();
  620.     cntDemo = -1;
  621. }
  622.  
  623. #define MaxPts        6                // Maximum # of pts in polygon
  624.  
  625. void polyDemo(void)
  626. {
  627.     int        i;
  628.     point    poly[MaxPts];            // Space to hold polygon data
  629.  
  630.     beginDemo();
  631.     while (!done()) {
  632.         for (i = 0; i < MaxPts; i++) {
  633.             poly[i].x = random(maxx);
  634.             poly[i].y = random(maxy);
  635.             }
  636.  
  637.         MGL_setColor(randoml(maxcolor)+1);
  638.         MGL_setBackColor(randoml(maxcolor)+1);
  639.  
  640.         if ((val = random(3)) == 0) {
  641.             MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  642.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  643.             }
  644.         else if (val == 1) {
  645.             MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  646.             MGL_setPenBitmapPattern(&bitpat[random(NUMPATS)+1]);
  647.             }
  648.         else MGL_setPenStyle(SOLID_PATTERN);
  649.  
  650.         MGL_fillPolygon(MaxPts,poly,0,0);
  651.         }
  652.  
  653.     endDemo();
  654. }
  655.  
  656. void convexPolyDemo(void)
  657. {
  658.     point    poly[3];
  659.  
  660.     beginDemo();
  661.     MGL_beginDrawing();
  662.     MGL_setPolygonType(CONVEX_POLYGON);
  663.     while (!done()) {
  664.         poly[0].x = random(maxx);
  665.         poly[0].y = random(maxy);
  666.         poly[1].x = random(maxx);
  667.         poly[1].y = random(maxy);
  668.         poly[2].x = random(maxx);
  669.         poly[2].y = random(maxy);
  670.  
  671.         MGL_setColor(randoml(maxcolor)+1);
  672.         MGL_fillPolygon(3,poly,0,0);
  673.         }
  674.     MGL_endDrawing();
  675.     endDemo();
  676. }
  677.  
  678. void shadedPolyDemo(void)
  679. {
  680.     int        i;
  681.     point    poly[3];
  682.     color_t    colors[3];
  683.     palette    pal[255];
  684.  
  685.     // Setup the palette to show smooth shading between bright red and
  686.     // bright blue.
  687.  
  688.     beginDemo();
  689.     if (maxcolor == 255) {
  690.         MGL_getPalette(pal,255,0);
  691.         for (i = scUser; i <= maxcolor; i++) {
  692.             pal[i].red = ((long)PALMAX * (i-scUser)) / (maxcolor-scUser);
  693.             pal[i].green = 0;
  694.             pal[i].blue = ((long)PALMAX * ((maxcolor-scUser)-(i-scUser))) / (maxcolor-scUser);
  695.             }
  696.         MGL_setPalette(pal,255,0);
  697.         }
  698.  
  699.     MGL_beginDrawing();
  700.  
  701.     while (!done()) {
  702.         for (i = 0; i < 3; i++) {
  703.             poly[i].x = random(maxx);
  704.             poly[i].y = random(maxy);
  705.             colors[i] = scUser + randoml(maxcolor-scUser);
  706.             }
  707.         MGL_fillGouraudPolygon(3,poly,colors,0,0);
  708.         }
  709.  
  710.     MGL_endDrawing();
  711.     endDemo();
  712. }
  713.  
  714. void DemoArea::polygonDemo()
  715. {
  716.     setDemoTitle("Polygon Demonstration");
  717.     setInfoText(polyText1);
  718.     polyDemo();
  719.     setInfoText(polyText2);
  720.     convexPolyDemo();
  721.     if (MGL_maxColor() == 255) {
  722.         setInfoText(polyText3);
  723.         shadedPolyDemo();
  724.         }
  725.     cntDemo = -1;
  726. }
  727.  
  728. void DemoArea::colorDemo()
  729. {
  730.     int        color,width,height,x,y,i,j,top,bottom,start,palsize;
  731.     palette    pal[256],temp[256];
  732.  
  733.     setDemoTitle("Color Demonstration");
  734.  
  735.     beginDemo();
  736.     if (maxcolor <= 15) {
  737.         // Simple color demonstration for 16 color displays
  738.  
  739.         setInfoText(colorText1);
  740.         width = 2 * ((MGL_maxx()+1) / 16);
  741.         height = 2 * ((MGL_maxy()-10)  / 10);
  742.  
  743.         x = width / 2;
  744.         y = height / 2;
  745.         color = 1;
  746.         for (j = 0; j < 3; j++) {
  747.             for (i = 0; i < 5; i++) {
  748.                 MGL_setColor(color++);
  749.                 MGL_fillRectCoord(x,y,x+width,y+height);
  750.                 x += (width/2) * 3;
  751.                 }
  752.             y += (height / 2) * 3;
  753.             x = width / 2;
  754.             }
  755.         }
  756.     else if (maxcolor == 255) {
  757.         // Color demonstration for color mapped displays with 255 colors
  758.  
  759.         setInfoText(colorText2);
  760.         width = 2 * ((MGL_maxx()+1) / 47);
  761.         height = 2 * ((MGL_maxy()-10)  / 48);
  762.         palsize = maxcolor - scUser + 1;
  763.  
  764.         x = width / 2;
  765.         y = height / 2;
  766.         color = scUser;
  767.         for (j = 0; j < maxcolor-scUser+1; j++) {
  768.             MGL_setColor(color++);
  769.             MGL_fillRectCoord(x,y,x+width,y+height);
  770.             x += (width/2) * 3;
  771.             if (((j+1) % 16) == 0) {
  772.                 y += (height / 2) * 3;
  773.                 x = width / 2;
  774.                 }
  775.             }
  776.  
  777.         halt();
  778.         setInfoText(colorText3);
  779.  
  780.         // Palette rotations
  781.  
  782.         MGL_getPalette(pal,palsize,scUser);
  783.         while (!done()) {
  784.             MGL_rotatePalette(pal,palsize,PAL_ROTATE_UP);
  785.             MGL_setPalette(pal,palsize,scUser);
  786.             }
  787.         setInfoText(colorText4);
  788.         while (!done()) {
  789.             MGL_rotatePalette(pal,palsize,PAL_ROTATE_DOWN);
  790.             MGL_setPalette(pal,palsize,scUser);
  791.             }
  792.         setInfoText(colorText5);
  793.  
  794.         // Palette fade out
  795.  
  796.         MGL_getPalette(pal,MGL_getPaletteSize(),0);
  797.         for (i = 31; i >= 0; i--) {
  798.             MGL_fadePalette(temp,pal,MGL_getPaletteSize(),(uchar)(i*8));
  799.             MGL_setPalette(temp,MGL_getPaletteSize(),0);
  800.             }
  801.  
  802.         // Palette fade in
  803.  
  804.         delay(1000);
  805.         for (i = 0; i <= 31; i++) {
  806.             MGL_fadePalette(temp,pal,MGL_getPaletteSize(),(uchar)(i*8));
  807.             MGL_setPalette(temp,MGL_getPaletteSize(),0);
  808.             }
  809.         }
  810.     else {
  811.         // Color demonstration for HiColor and TrueColor modes
  812.  
  813.         setInfoText(colorText6);
  814.  
  815.         start = MGL_maxx()/8;
  816.         width = MGL_maxx() - start*2;
  817.         MGL_beginDrawing();
  818.  
  819.         top = MGL_maxy()/8;
  820.         bottom = MGL_maxy()/8 + MGL_maxy()/5;
  821.         for (x = 0; x < width; x++) {
  822.             MGL_setColor(MGL_packColor((x * 255L) / width,0,0));
  823.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  824.             }
  825.  
  826.         top += MGL_maxy()/5;
  827.         bottom += MGL_maxy()/5;
  828.         for (x = 0; x < width; x++) {
  829.             MGL_setColor(MGL_packColor(0,(x * 255L) / width,0));
  830.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  831.             }
  832.  
  833.         top += MGL_maxy()/5;
  834.         bottom += MGL_maxy()/5;
  835.         for (x = 0; x < width; x++) {
  836.             MGL_setColor(MGL_packColor(0,0,(x * 255L) / width));
  837.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  838.             }
  839.  
  840.         top += MGL_maxy()/5;
  841.         bottom += MGL_maxy()/5;
  842.         for (x = 0; x < width/2; x++) {
  843.             MGL_setColor(MGL_packColor((((width/2)-x) * 255L) / (width/2),
  844.                 (x * 255L) / (width/2),0));
  845.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  846.             }
  847.         for (; x < width; x++) {
  848.             MGL_setColor(MGL_packColor(0,
  849.                 ( ((width/2) - (x - (width/2))) * 255L) / (width/2),
  850.                 ((x-width/2) * 255L) / (width/2) ));
  851.             MGL_lineCoordFast(start+x,top,start+x,bottom);
  852.             }
  853.         MGL_endDrawing();
  854.         }
  855.     endDemo();
  856.     cntDemo = -1;
  857. }
  858.  
  859. #define    POINTS    10
  860.  
  861. int        data1[POINTS] = { 1, 3, 5, 4, 3, 2, 1, 5, 4, 2 };
  862. int        data2[POINTS] = { 4, 6, 10, 2, 6, 4, 8, 10, 6, 2 };
  863. int        data3[POINTS] = { 1, 3, 2, 5, 7, 9, 5, 4, 5, 8 };
  864.  
  865. void DemoArea::markerDemo()
  866. {
  867.     int        i,stepx,stepy;
  868.     point    p[POINTS];
  869.  
  870.     setDemoTitle("Marker Demonstration");
  871.     setInfoText(markerText);
  872.  
  873.     beginDemo();
  874.     stepx = maxx / 12;
  875.     stepy = maxy / 12;
  876.  
  877.     // Draw the graph axes
  878.  
  879.     MGL_setColor(MGL_realColor(scWhite));
  880.     MGL_lineCoord(stepx,maxy - stepy,stepx*11,maxy-stepy);
  881.     MGL_lineCoord(stepx,maxy - stepy,stepx,maxy - stepy*11);
  882.  
  883.     for (i = stepx*11; i >= stepx; i -= stepx)
  884.         MGL_lineCoord(i,maxy - stepy - 3,i,maxy - stepy + 3);
  885.  
  886.     for (i = maxy - stepy; i >= maxy-stepy*11; i -= stepy)
  887.         MGL_lineCoord(stepx-3,i,stepx+3,i);
  888.  
  889.     if (MGL_sizey() >= 349)
  890.         MGL_setPenSize(2,2);
  891.  
  892.     // Draw the first set of data
  893.  
  894.     for (i = 0; i < POINTS; i++) {
  895.         p[i].x = stepx + i*stepx;
  896.         p[i].y = maxy - stepy - data1[i]*stepy;
  897.         }
  898.  
  899.     if (MGL_sizey() >= 599)
  900.         MGL_setMarkerSize(6);
  901.     else MGL_setMarkerSize(4);
  902.     MGL_setColor(MGL_realColor(LIGHTRED));
  903.     MGL_polyLine(POINTS,p);
  904.     MGL_setMarkerColor(MGL_realColor(LIGHTMAGENTA));
  905.     MGL_polyMarker(POINTS,p);
  906.  
  907.     // Draw the second set of data
  908.  
  909.     for (i = 0; i < POINTS; i++) {
  910.         p[i].x = stepx + i*stepx;
  911.         p[i].y = maxy - stepy - data2[i]*stepy;
  912.         }
  913.  
  914.     MGL_setColor(MGL_realColor(LIGHTGREEN));
  915.     MGL_polyLine(POINTS,p);
  916.     MGL_setMarkerColor(MGL_realColor(LIGHTMAGENTA));
  917.     MGL_setMarkerStyle(MARKER_CIRCLE);
  918.     MGL_polyMarker(POINTS,p);
  919.  
  920.     // Draw the third set of data
  921.  
  922.     for (i = 0; i < POINTS; i++) {
  923.         p[i].x = stepx + i*stepx;
  924.         p[i].y = maxy - stepy - data3[i]*stepy;
  925.         }
  926.  
  927.     MGL_setColor(MGL_realColor(LIGHTBLUE));
  928.     MGL_polyLine(POINTS,p);
  929.     MGL_setMarkerColor(MGL_realColor(LIGHTMAGENTA));
  930.     MGL_setMarkerStyle(MARKER_X);
  931.     MGL_polyMarker(POINTS,p);
  932.  
  933.     endDemo();
  934.     cntDemo = -1;
  935. }
  936.  
  937. void DemoArea::patternDemo()
  938. {
  939.     int     i,j,x,y,height,width,space;
  940.  
  941.     setDemoTitle("Pattern Demonstration");
  942.     setInfoText(patText);
  943.  
  944.     beginDemo();
  945.     width  = (maxx+1) / 20;
  946.     height = (maxy+1) / 9;
  947.     if (MGL_sizey() < 479)
  948.         space = 3;
  949.     else space = 10;
  950.  
  951.     x = y = space;
  952.     MGL_setColor(MGL_realColor(scWhite));
  953.     MGL_setPenStyle(BITMAP_PATTERN_TRANSPARENT);
  954.  
  955.     for (j = 0; j < 7; j++) {            /* For 7 rows of boxes         */
  956.         for (i = 0; i < 15; i++) {        /* For 15 columns of boxes        */
  957.             MGL_setPenBitmapPattern(&bitpat[j*15 + i]);
  958.             MGL_fillRectCoord(x,y,x+width+1,y+height+1);
  959.             x += width + space;            /* Advance to next col            */
  960.             }
  961.         x = space;
  962.         y += height + space;
  963.         }
  964.     endDemo();
  965.     cntDemo = -1;
  966. }
  967.  
  968. // Function prototypes for floodfill routines in 'ffill.c'
  969.  
  970. extern "C" {
  971. void MGL_interiorFill(int x,int y);
  972. void MGL_boundaryFill(int x,int y,color_t bdr);
  973. }
  974.  
  975. void boundaryFillDemo(void)
  976. {
  977.     int     i,j;
  978.     color_t color;
  979.     point    poly[6];
  980.  
  981.     beginDemo();
  982.     srand(200);
  983.  
  984.     // Draw a set of polygons
  985.  
  986.     for (j = 0; j < 3; j++) {
  987.         color = random(10);                /* Keep random in sync            */
  988.         color = (j == 0) ? BLUE : (j == 1) ? RED : YELLOW;
  989.  
  990.         for (i = 0; i < 6; i++) {
  991.             poly[i].x = random(maxx);
  992.             poly[i].y = random(maxy);
  993.             }
  994.  
  995.         MGL_setColor(MGL_realColor(color));
  996.         MGL_fillPolygon(6,poly,0,0);
  997.         }
  998.     halt();
  999.  
  1000.     MGL_setColor(MGL_realColor(LIGHTGREEN));
  1001.     MGL_boundaryFill(10,10,MGL_realColor(RED));
  1002. }
  1003.  
  1004. void interiorFillDemo(void)
  1005. {
  1006.     int     i,j;
  1007.     color_t color;
  1008.     point    poly[6];
  1009.  
  1010.     beginDemo();
  1011.     srand(200);
  1012.  
  1013.     // Draw a set of polygons
  1014.  
  1015.     for (j = 0; j < 3; j++) {
  1016.         color = random(10);                /* Keep random in sync            */
  1017.         color = (j == 0) ? BLUE : (j == 1) ? RED : YELLOW;
  1018.  
  1019.         for (i = 0; i < 6; i++) {
  1020.             poly[i].x = random(maxx);
  1021.             poly[i].y = random(maxy);
  1022.             }
  1023.  
  1024.         MGL_setColor(MGL_realColor(color));
  1025.         MGL_fillPolygon(6,poly,0,0);
  1026.         }
  1027.     halt();
  1028.  
  1029.     MGL_setColor(MGL_realColor(LIGHTGREEN));
  1030.     MGL_interiorFill(10,10);
  1031. }
  1032.  
  1033. void DemoArea::floodFillDemo()
  1034. {
  1035.     setDemoTitle("Flood Fill Demonstration");
  1036.     setInfoText(floodText1);
  1037.     boundaryFillDemo();
  1038.     setInfoText(floodText2);
  1039.     halt();
  1040.     setInfoText(floodText3);
  1041.     interiorFillDemo();
  1042.     cntDemo = -1;
  1043. }
  1044.  
  1045. int fixAngle(int angle)
  1046. {
  1047.     while (angle < 0)
  1048.         angle += 360;
  1049.     while (angle >= 360)
  1050.         angle -= 360;
  1051.     return angle;
  1052. }
  1053.  
  1054. void DemoArea::animationDemo()
  1055. {
  1056.     int        stepx,stepy,secAngle,minAngle;
  1057.     rect    extent,dirtyRect;
  1058.  
  1059.     setDemoTitle("Animation Demonstration");
  1060.     if (MGL_maxPage() > 0) {
  1061.         setInfoText(animText1);
  1062.         beginDemo();
  1063.  
  1064.         cntDemo = cmEmptyDemo;
  1065.         doubleBufferOn();
  1066.  
  1067.         extent.left() = extent.top() = 0;
  1068.         extent.right() = maxx/5;
  1069.         extent.bottom() = ((long)extent.right() * 1000) / MGL_getAspectRatio();
  1070.         dirtyRect = extent;
  1071.  
  1072.         stepx = 1;
  1073.         stepy = 1;
  1074.         secAngle = minAngle = 90;
  1075.  
  1076.         while (!done()) {
  1077.             MGL_setColor(MGL_realColor(backColor));
  1078.             MGL_fillRect(dirtyRect);
  1079.             MGL_setColor(MGL_realColor(LIGHTRED));
  1080.             MGL_fillEllipse(extent);
  1081.             MGL_setColor(MGL_realColor(scWhite));
  1082.             MGL_fillEllipseArc(extent,secAngle-5,secAngle);
  1083.             MGL_fillEllipseArc(extent,minAngle-5,minAngle);
  1084.  
  1085.             swapBuffers();            // Swap the display buffers
  1086.  
  1087.             // Bounce the clock off the walls
  1088.  
  1089.             dirtyRect = extent;
  1090.             dirtyRect.inset(-ABS(stepx),-ABS(stepy));
  1091.             if (extent.left() + stepx < 0)
  1092.                 stepx = -stepx;
  1093.             if (extent.right() + stepx > maxx)
  1094.                 stepx = -stepx;
  1095.  
  1096.             if (extent.top() + stepy < 0)
  1097.                 stepy = -stepy;
  1098.             if (extent.bottom() + stepy > maxy)
  1099.                 stepy = -stepy;
  1100.  
  1101.             extent.offset(stepx,stepy);
  1102.  
  1103.             // Update the hand movement
  1104.  
  1105.             secAngle = fixAngle(secAngle - 5);
  1106.             if (secAngle == 90)
  1107.                 minAngle = fixAngle(minAngle - 5);
  1108.             }
  1109.  
  1110.         doubleBufferOff();
  1111.         endDemo();
  1112.         }
  1113.     else setInfoText(animText2);
  1114.     cntDemo = -1;
  1115. }
  1116.  
  1117. void DemoArea::setDemoTitle(char *title)
  1118. /****************************************************************************
  1119. *
  1120. * Function:        DemoArea::setDemoTitle
  1121. * Parameters:    title    - New title for the demonstration
  1122. *
  1123. * Description:    Sets the demonstration title information, and forces a
  1124. *                repaint event.
  1125. *
  1126. ****************************************************************************/
  1127. {
  1128.     TEvent    e;
  1129.  
  1130.     message(TProgram::deskTop,evBroadcast,cmSetDemoTitle,title);
  1131.     getEvent(e,evRepaint);
  1132. }
  1133.  
  1134. void DemoArea::setInfoText(char *text)
  1135. /****************************************************************************
  1136. *
  1137. * Function:        DemoArea::setInfoText
  1138. * Parameters:    text    - Text for the new window.
  1139. *
  1140. * Description:    Sets the explanation information in the information
  1141. *                window.
  1142. *
  1143. ****************************************************************************/
  1144. {
  1145.     TEvent    e;
  1146.  
  1147.     message(TProgram::deskTop,evBroadcast,cmSetExplanation,text);
  1148.     getEvent(e,evRepaint);
  1149. }
  1150.  
  1151. void DemoArea::render()
  1152. /****************************************************************************
  1153. *
  1154. * Function:        DemoArea::render
  1155. *
  1156. * Description:    Renders the data in the visualisation in either the 2D or
  1157. *                3D format depending on the current setting of the 2D view
  1158. *                flag.
  1159. *
  1160. ****************************************************************************/
  1161. {
  1162.     MGL_setColor(MGL_realColor(backColor));
  1163.     TRect clip(0,0,size.x+1,size.y+1);
  1164.     MGL_setClipRect(clip);
  1165.     MGL_fillRectCoord(0,0,size.x+1,size.y+1);
  1166.  
  1167.     switch (cntDemo) {
  1168.         case cmLineDemo:
  1169.             lineDemo();
  1170.             break;
  1171.         case cmEllipseDemo:
  1172.             ellipseDemo();
  1173.             break;
  1174.         case cmArcDemo:
  1175.             arcDemo();
  1176.             break;
  1177.         case cmPolygonDemo:
  1178.             polygonDemo();
  1179.             break;
  1180.         case cmRectangleDemo:
  1181.             rectangleDemo();
  1182.             break;
  1183.         case cmColorDemo:
  1184.             colorDemo();
  1185.             break;
  1186.         case cmMarkerDemo:
  1187.             markerDemo();
  1188.             break;
  1189.         case cmPatternDemo:
  1190.             patternDemo();
  1191.             break;
  1192.         case cmFloodFillDemo:
  1193.             floodFillDemo();
  1194.             break;
  1195.         case cmAnimationDemo:
  1196.             animationDemo();
  1197.             break;
  1198.         case cmEmptyDemo:
  1199.             break;
  1200.         default:
  1201.             displayStatusInfo();
  1202.         }
  1203. }
  1204.