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

  1. /****************************************************************************
  2. *
  3. *                    Demo - Demonstration Program for the
  4. *                        MegaGraph Graphics Library
  5. *
  6. *                    Copyright (C) 1994 SciTech Software.
  7. *                            All rights reserved.
  8. *
  9. * Filename:        $RCSfile: demo.cpp $
  10. * Version:        $Revision: 1.3 $
  11. *
  12. * Language:        C++ 3.0
  13. * Environment:    any
  14. *
  15. * Description:    Implementation for the demo program.
  16. *
  17. * $Id: demo.cpp 1.3 1994/03/09 11:29:32 kjb release $
  18. *
  19. ****************************************************************************/
  20.  
  21. #include "demo.hpp"
  22.  
  23. #pragma    hdrstop
  24.  
  25. #include "msgbox.hpp"
  26. #include "tmodesel.hpp"
  27. #include "explwind.hpp"
  28. #include "titlwind.hpp"
  29. #include "demowind.hpp"
  30.  
  31. /*---------------------------- Global Variables ---------------------------*/
  32.  
  33. PRIVATE    int        newMode = -1;
  34. PUBLIC    int        forcedriver = grDETECT;
  35. PUBLIC    int        snowlevel = -1;
  36.  
  37. /*------------------------------ Implementation ---------------------------*/
  38.  
  39. Demo::Demo()
  40. //      : TProgram("drivers"),
  41.       : TProgram("..\\mgraph"),
  42.       TProgInit(NULL,
  43.                 Demo::initMenuBar,
  44.                 Demo::initDeskTop,
  45.                 Demo::initVideoMode)
  46. /****************************************************************************
  47. *
  48. * Function:        Demo::Demo
  49. *
  50. * Description:    Constructor for the demo application.
  51. *
  52. ****************************************************************************/
  53. {
  54.     // Modify the way the MGL works according to the command line options.
  55.  
  56.     if (snowlevel != -1) MGL_setPaletteSnowLevel(snowlevel);
  57.  
  58.     // Set up the default windows on the desktop
  59.  
  60.     lock();
  61.  
  62.     TRect    extent,r;
  63.  
  64.     deskTop->getExtent(extent);
  65.     ExplanationWindow *ew = new ExplanationWindow(extent);
  66.     TitleWindow *tw = new TitleWindow(extent);
  67.  
  68.     r.left() = 0;
  69.     r.right() = extent.right();
  70.     r.top() = tw->getBounds().bottom();
  71.     r.bottom() = ew->getBounds().top();
  72.     DemoWindow *dw = new DemoWindow(r);
  73.  
  74.     deskTop->insert(tw);
  75.     deskTop->insert(ew);
  76.     deskTop->insert(dw);
  77.  
  78.     unlock();
  79. }
  80.  
  81. Demo::~Demo()
  82. /****************************************************************************
  83. *
  84. * Function:        Demo::~Demo
  85. *
  86. * Description:    Destructor for the Demo class.
  87. *
  88. ****************************************************************************/
  89. {
  90. }
  91.  
  92. void Demo::initVideoMode(int& driver,int& mode)
  93. /****************************************************************************
  94. *
  95. * Function:        Demo::initVideoMode
  96. * Parameters:    driver    - Video device driver number
  97. *                mode    - Video mode number
  98. *
  99. * Description:    Changes the default video mode if this was changed via the
  100. *                change video mode dialog box.
  101. *
  102. ****************************************************************************/
  103. {
  104.     if (forcedriver != grDETECT) {
  105.         switch (forcedriver) {
  106.             case grEGA:
  107.                 if (driver > grEGA) {
  108.                     driver = grEGA;
  109.                     mode = grEGA_640x350x16;
  110.                     }
  111.                 break;
  112.             case grVGA:
  113.                 if (driver > grVGA)
  114.                     driver = grVGA;
  115.                 break;
  116.             case grSVGA:
  117.                 if (driver > grSVGA)
  118.                     driver = grSVGA;
  119.                 break;
  120.             }
  121.         }
  122.     if (newMode != -1)
  123.         mode = newMode;
  124. }
  125.  
  126. TMenuBar* Demo::initMenuBar(const TRect& bounds)
  127. /****************************************************************************
  128. *
  129. * Function:        Demo::initMenuBar
  130. * Parameters:    bounds    - Bounding box for the entire application
  131. * Returns:        Pointer to the newly created menu bar.
  132. *
  133. * Description:    Creates the menu bar definition for the application.
  134. *
  135. ****************************************************************************/
  136. {
  137.     TMenu *fileMenu = new TMenu();
  138.     TMenu *demoMenu = new TMenu();
  139.     TMenu *optionsMenu = new TMenu();
  140.  
  141.     *fileMenu
  142.         + new TMenuItem("~A~bout this demo...",cmAbout)
  143.         + new TMenuItemSeparator()
  144.         + new TMenuItem("~Q~uit",cmQuit,HotKey(kbX,mdAlt),hcNoContext,"Alt+X");
  145.     fileMenu->doneDefinition();
  146.  
  147.     *demoMenu
  148.         + new TMenuItem("Lines",cmLineDemo)
  149.         + new TMenuItem("Ellipses",cmEllipseDemo)
  150.         + new TMenuItem("Elliptical Arcs",cmArcDemo)
  151.         + new TMenuItem("Rectangles",cmRectangleDemo)
  152.         + new TMenuItem("Polygons",cmPolygonDemo)
  153.         + new TMenuItem("Color control",cmColorDemo)
  154.         + new TMenuItem("Markers",cmMarkerDemo)
  155.         + new TMenuItem("Patterns",cmPatternDemo)
  156.         + new TMenuItem("Flood fill",cmFloodFillDemo)
  157.         + new TMenuItem("Animation",cmAnimationDemo);
  158.     demoMenu->doneDefinition();
  159.  
  160.     *optionsMenu
  161.         + new TMenuItem("~V~ideo mode...",cmVideoMode);
  162.     optionsMenu->doneDefinition();
  163.  
  164.     TMenuBar    *menuBar = new TMenuBar(bounds);
  165.  
  166.     *menuBar
  167.         + new TSubMenuItem("~F~ile",fileMenu)
  168.         + new TSubMenuItem("~D~emo",demoMenu)
  169.         + new TSubMenuItem("~O~ptions",optionsMenu);
  170.     menuBar->doneDefinition();
  171.  
  172.     return (TMenuBar*)validView(menuBar);
  173. }
  174.  
  175. TDeskTop *Demo::initDeskTop(const TRect& bounds)
  176. /****************************************************************************
  177. *
  178. * Function:        Demo::initDeskTop
  179. * Parameters:    bounds    - bounding rectangle for entire program view
  180. * Returns:        Pointer to created desktop.
  181. *
  182. * Description:    For this application, the entire desktop is always
  183. *                covered by the application windows, so the desktop is
  184. *                created with an empty background to save time during
  185. *                redraws.
  186. *
  187. ****************************************************************************/
  188. {
  189.     return (TDeskTop*)validView(new TDeskTop(bounds,NULL));
  190. }
  191.  
  192. void Demo::handleEvent(TEvent& event,phaseType phase)
  193. /****************************************************************************
  194. *
  195. * Function:        Demo::handleEvent
  196. * Parameters:    event    - Event to handle
  197. *                phase    - Phase of focused events
  198. *
  199. * Description:    Main event handling routine for the application. We first
  200. *                let the TProgram class take care of the events for us, then
  201. *                we check for application specific commands.
  202. *
  203. ****************************************************************************/
  204. {
  205.     TProgram::handleEvent(event,phase);
  206.  
  207.     // Now check for application commands and dispatch them
  208.  
  209.     if (event.what == evCommand) {
  210.         switch (event.message.command) {
  211.             case cmAbout:
  212.                 messageBox(
  213.                     "MegaGraph Graphics Library Demo\n"
  214.                     "Copyright (C) 1994 SciTech Software\n\n"
  215.                     "Written by Kendall Bennett\n\n"
  216.                     "Version 1.1"
  217.                     ,mfInformation | mfOKButton | mfOKDefault | mfCenterText);
  218.                 break;
  219.             case cmVideoMode:
  220.                 changeVideoMode();
  221.                 break;
  222.             case cmLineDemo:
  223.             case cmEllipseDemo:
  224.             case cmArcDemo:
  225.             case cmPolygonDemo:
  226.             case cmRectangleDemo:
  227.             case cmColorDemo:
  228.             case cmMarkerDemo:
  229.             case cmPatternDemo:
  230.             case cmFloodFillDemo:
  231.             case cmAnimationDemo:
  232.                 // Broadcast these messages to be handled by the DemoArea.
  233.  
  234.                 event.what = evBroadcast;
  235.                 putEvent(event);
  236.                 break;
  237.             default:
  238.                 return;                    // Don't clear unhandled events
  239.             }
  240.         clearEvent(event);
  241.         }
  242. }
  243.  
  244. void Demo::changeVideoMode()
  245. /****************************************************************************
  246. *
  247. * Function:        Demo::changeVideoMode
  248. *
  249. * Description:    Pops up a dialog box to allow the user to change the
  250. *                current video mode, and changes to the new mode if
  251. *                requested.
  252. *
  253. ****************************************************************************/
  254. {
  255.     TModeSelector *d = new TModeSelector("Change Video Mode",graphDriver,
  256.         graphMode,MGL_availableModes(graphDriver));
  257.     if (deskTop->execView(d) == cmOk) {
  258.         // Change to the newly selected video mode
  259.         //
  260.         // Post a cmRestart event to restart the application with the new
  261.         // video mode.
  262.  
  263.         if ((newMode = d->getMode()) != graphMode) {
  264.             TEvent event;
  265.             event.what = evCommand;
  266.             event.message.command = cmRestart;
  267.             event.message.infoPtr = NULL;
  268.             putEvent(event);
  269.             }
  270.         }
  271.     delete d;
  272. }
  273.