home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / HELLO6 / AEARTHW6.CPP < prev    next >
C/C++ Source or Header  |  1995-04-07  |  45KB  |  589 lines

  1. /*****************************************************************************
  2. * HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (aearthw6.cpp)*
  3. *                                                                            *
  4. * COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
  5. *                                                                            *
  6. * DISCLAIMER OF WARRANTIES:                                                  *
  7. *   The following [enclosed] code is sample code created by IBM              *
  8. *   Corporation.  This sample code is not part of any standard IBM product   *
  9. *   and is provided to you solely for the purpose of assisting you in the    *
  10. *   development of your applications.  The code is provided "AS IS",         *
  11. *   without warranty of any kind.  IBM shall not be liable for any damages   *
  12. *   arising out of your use of the sample code, even if they have been       *
  13. *   advised of the possibility of such damages.                              *
  14. *****************************************************************************/
  15. // NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16.  
  17. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  18.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  19. #endif                                  //  is defined.
  20. #ifdef IC_PM                            //For PM,                             V5
  21.   #define INCL_GPIPRIMITIVES            //  include the                       V5
  22.   #define INCL_GPIPATHS                 //  drawing routines                  V5
  23.   #include <os2.h>                      //  from the OS/2 libraries           V5
  24. #endif                                                                      //V5
  25.  
  26. #ifdef IC_MOTIF                         //For MOTIF,                          V5
  27.   extern "C" {                          //  include the X-Windows             V5
  28.     #include <X11/Xlib.h>               //  libraries for drawing and         V5
  29.     #include <X11/Intrinsic.h>          //  XtDisplay and XtWindow intrinsics V5
  30.   }                                                                         //V5
  31. #endif                                                                      //V5
  32.  
  33. #include <stdlib.h>                     //Include rand function for twinkle   V6
  34.  
  35. #include "aearthw6.hpp"                                                     //v6
  36.  
  37. /**************************************************************************   V5
  38. * AEarthWindow :: AEarthWindow - Constructor for the Earth window         *   V5
  39. **************************************************************************/ //V5
  40. AEarthWindow :: AEarthWindow(unsigned long windowId,                        //V5
  41.                              IWindow * parowWindow,                         //V5
  42.                              const IRectangle& rect)                        //V5
  43.                :IStaticText(windowId, parowWindow, parowWindow, rect)       //V5
  44.                 ,atmosphereLayers(3)                                        //V5
  45.                 ,spaceColor(IColor::black)                                  //V5
  46.                 ,globeColor(IColor::cyan)                                   //V5
  47.                 ,starColor(IColor::white)                                   //V5
  48.                 ,starIntensity(bright)                                      //V6
  49.                 ,twinkling(false)                                           //V6
  50. {                                                                           //V5
  51. /*-------------------- Construct Paint Handler and Show ------------------|   V5
  52. | The paintHandler is attached to the AEarthWindow object to begin        |   V5
  53. |   handling paint events.  Each time the static text window needs to     |   V5
  54. |   be repainted, the APaintHandler::paintWindow function will be         |   V5
  55. |   called.  The first repaint occurs because of IWindow::show.           |   V5
  56. |------------------------------------------------------------------------*/ //V5
  57.   paintHandler.handleEventsFor(this);                                       //V5
  58.   show();                                                                   //V5
  59. } /* end AEarthWindow :: AEarthWindow(...) */                               //V5
  60.  
  61. /**************************************************************************   V5
  62. * AEarthWindow :: ~AEarthWindow - Destructor for Earth window             *   V5
  63. **************************************************************************/ //V5
  64. AEarthWindow :: ~AEarthWindow()                                             //V5
  65. {                                                                           //V5
  66. /*-------------------- Stop and Delete Paint Handler ---------------------|   V5
  67. | Tell paintHandler to stop handling events for AEarthWindow.             |   V5
  68. |------------------------------------------------------------------------*/ //V5
  69.   paintHandler.stopHandlingEventsFor(this);                                 //V5
  70. } /* end AEarthWindow :: ~AEarthWindow() */                                 //V5
  71.  
  72. /**************************************************************************   V5
  73. * APaintHandler :: paintWindow                                            *   V5
  74. *   This function calls the paintWorld function for the                   *   V5
  75. *   AEarthWindow object which repaints the entire static text window.     *   V5
  76. *   The IParameter2 parameter of the IPaintEvent is always passed to      *   V5
  77. *   paintWorld, but it is only used for the AIX implementation.           *   V5
  78. **************************************************************************/ //V5
  79. IBase::Boolean                                                              //V5
  80.   APaintHandler :: paintWindow(IPaintEvent & paintEvent)                    //V5
  81. {                                                                           //V5
  82.  
  83. /*------------------ Call AEarthWindow Paint World Function --------------|   V5
  84. | Get a pointer the AEarthWindow object from the paint event and use it   |   V5
  85. |   to call the paintWorld function.                                      |   V5
  86. |------------------------------------------------------------------------*/ //V5
  87.   return ( ((AEarthWindow *)paintEvent.window())->paintWorld());            //V5
  88.  
  89. } /* end APaintHandler :: paintWindow(...) */                               //V5
  90.  
  91. /**************************************************************************   V5
  92. * AEarthWindow :: paintWorld - paint a view of Earth from space           *   v5
  93. *   This function provides an example of how to use underlying low-level  *   V5
  94. *   calls in conjuction with the User Interface Class Library.  In this   *   V5
  95. *   case, native graphics routines are used to draw a view of Earth from  *   V5
  96. *   space in an IStaticText control.                                      *   V5
  97. **************************************************************************/ //V5
  98. IBase::Boolean                                                              //V5
  99.   AEarthWindow :: paintWorld()                                              //V5
  100. {                                                                           //V5
  101. Boolean worldPainted = false;
  102. /*----------------------- Construct Color Objects ------------------------|   V5
  103. | Construct an IColor object for each color used in the graphical window. |   V5
  104. |------------------------------------------------------------------------*/ //V5
  105. const IColor                                                                //V5
  106.   arcColor[4] =                                                             //V5
  107.         {globeColor, IColor::blue, IColor::darkCyan, IColor::darkBlue};     //V5
  108.  
  109. /*------------------- Get Presentation Space Objects ---------------------|   V5
  110. | Get the presentation space handle (called "graphics context" in AIX)    |   V5
  111. |   and the rectangle of the area that needs to be painted.               |   V5
  112. |------------------------------------------------------------------------*/ //V5
  113. const IPresSpaceHandle                                                      //V5
  114.   hps(presSpace());                                                         //V5
  115. const IRectangle                                                            //V5
  116.   psRect(rect());                                                           //V5
  117.  
  118. /*------------------- Construct Squares for Arc Casings ------------------|   V5
  119. | Construct four squares such that the leftCenter, topCenter, and         |   v5
  120. |   rightCenter points describe the arcs to be drawn for the Earth and    |   V5
  121. |   its atmosphere.  The squares are constructed from IRectangle objects  |   V5
  122. |   positioned initially at the center of the presentation space          |   V5
  123. |   rectangle and then moved 1/2 the square's width to the left and a     |   V5
  124. |   full square's height plus an arbitrary offset down.                   |   v5
  125. |------------------------------------------------------------------------*/ //V5
  126. const int arcs=4;                                                           //V5
  127. const float                                                                 //V5
  128.   arcDropFactor[arcs] = {1.0/8,  1.0/16,  1.0/32, 0},                       //V5
  129.   arcSizeFactor[arcs] = {9.0/4, 21.0/8,  45.0/16, 3};                       //V5
  130. const long                                                                  //V5
  131.   psHeight=psRect.height();                                                 //V5
  132. long                                                                        //V5
  133.   arcDrop,                                                                  //V5
  134.   arcDiameter;                                                              //V5
  135. IPair                                                                       //V5
  136.   arcOffset;                                                                //V5
  137. IRectangle                                                                  //V5
  138.   arcSquare[arcs];                                                          //V5
  139. int i;                                                                      //V5
  140.  
  141.   for (i=0;i<arcs;i++ )                                                     //V5
  142.   {                                                                         //V5
  143.     arcDrop = psHeight*arcDropFactor[i];                                    //V5
  144.     arcDiameter = psHeight*arcSizeFactor[i];                                //V5
  145.     arcOffset = IPair(-1*arcDiameter/2,-1*arcDiameter-arcDrop);             //V5
  146.     arcSquare[i] = IRectangle(psRect.center(),                              //V5
  147.                                 ISize(arcDiameter, arcDiameter));           //V5
  148.     arcSquare[i].moveBy(arcOffset);                                         //V5
  149.   }                                                                         //V5
  150.  
  151. #ifdef IC_MOTIF                                                             //V5
  152. /**************************************************************************   V5
  153. *****  MOTIF-specific code - BEGIN                                    *****   V5
  154. **************************************************************************/ //V5
  155. /*----------------- Construct X-lib Draw Function Arguments --------------|   V5
  156. | Construct the window and display objects needed by the X-lib drawing    |   V5
  157. |   functions from the window handle, which is the widget ID.             |   V5
  158. |   XtWindow and XtDisplay are X-lib intrinsic functions.                 |   V5
  159. |------------------------------------------------------------------------*/ //V5
  160. const Window                                                                //V5
  161.   xWindow(XtWindow(handle()));                                              //V5
  162. Display                                                                     //V5
  163.  *xDisplay(XtDisplay(handle()));                                            //V5
  164.  
  165. /*------------------------------- Color Space ----------------------------|   V5
  166. | Set the background color to space, which is IColor::black.              |   V5
  167. |      Note that because the X-Windows origin is at the top of the        |   V5
  168. |      window as opposed to the bottom in PM, the X-Windows rectangle     |   V5
  169. |      top must be computed by subtracting the arc rectangle's top        |   V5
  170. |      coordinate from the presentation space rectangle's height.         |   V5
  171. |------------------------------------------------------------------------*/ //V5
  172.   XSetForeground(xDisplay, hps, spaceColor.asPixel());                      //V5
  173.   XFillRectangle(xDisplay, xWindow, hps,                                    //V5
  174.             psRect.left(),                                                  //V5
  175.             psRect.height()-psRect.top(),                                   //V5
  176.             psRect.width(),                                                 //V5
  177.             psRect.height());                                               //V5
  178.  
  179. /*-------------------- Draw the Earth and Atmosphere ---------------------|   V5
  180. | Draw the earth and the number of layers of atmosphere specified in      |   V5
  181. |   atmosphereLayers.  arcSquare[0] contains the arc dimension for the    |   V5
  182. |   earth and the other arcSquare objects specify each atmosphere layer.  |   V5
  183. | Each arc is drawn by calling the Xlib functions for setting the         |   V5
  184. |   foreground color and for drawing an arc and filling it with the       |   V5
  185. |   foreground color.  The arc is described using rectangle coordinates.  |   V5
  186. |      Note that because the X-Windows origin is at the top of the        |   V5
  187. |      window as opposed to the bottom in PM, the X-Windows rectangle     |   V5
  188. |      top must be computed by subtracting the arc rectangle's top        |   V5
  189. |      coordinate from the presentation space rectangle's height.         |   V5
  190. |------------------------------------------------------------------------*/ //V5
  191.   for(i=atmosphereLayers;i>=0;i--)                                          //V5
  192.   {                                                                         //V5
  193.     XSetForeground(xDisplay, hps, arcColor[i].asPixel());                   //V5
  194.     XFillArc(xDisplay, xWindow, hps,                                        //V5
  195.             arcSquare[i].left(),                                            //V5
  196.             psHeight-arcSquare[i].top(),                                    //V5
  197.             arcSquare[i].width(),                                           //V5
  198.             arcSquare[i].height(),                                          //V5
  199.             0,180*64 );                                                     //V5
  200.   }                                                                         //V5
  201. /**************************************************************************   V5
  202. *****  MOTIF-specific code - END                                      *****   V5
  203. **************************************************************************/ //V5
  204. #endif                                                                      //V5
  205. #ifdef IC_PM                                                                //V5
  206. /**************************************************************************   V5
  207. *****  PM-specific code - BEGIN                                       *****   V5
  208. **************************************************************************/ //V5
  209. /*------------------------------- Color Space ----------------------------|   V5
  210. | Set the background color to space, which is IColor::black.              |   V5
  211. |------------------------------------------------------------------------*/ //V5
  212. POINTL                                                                      //V5
  213.   origin=IPoint(0,0).asPOINTL(),                                            //V5
  214.   maxPoint=((IPoint)psRect.size()).asPOINTL();                              //V5
  215.                                                                             //V5
  216.   GpiMove (hps, &origin);                                                   //V5
  217.   GpiSetColor (hps, spaceColor.index()) ;                                   //V5
  218.   GpiBox (hps, DRO_OUTLINEFILL, &maxPoint, 0, 0) ;                          //V5
  219.  
  220. /*-------------------- Draw the Earth and Atmosphere ---------------------|   V5
  221. | Draw the earth and the number of layers of atmosphere specified in      |   V5
  222. |   atmosphereLayers.  arcSquare[0] contains the arc dimension for the    |   V5
  223. |   earth and the other arcSquare objects specify each atmosphere layer.  |   V5
  224. | Each arc is drawn by calling the PM Gpi functions for setting the       |   V5
  225. |   foreground color and for drawing an arc and filling it with the       |   V5
  226. |   foreground color.  The arc is described using rectangle coordinates.  |   V5
  227. |------------------------------------------------------------------------*/ //V5
  228. POINTL                                                                      //V5
  229.   ptlist[3];                                                                //V5
  230.   for(i=atmosphereLayers;i>=0;i--)                                          //V5
  231.   {                                                                         //V5
  232.     ptlist[0]=arcSquare[i].leftCenter().asPOINTL();                         //V5
  233.     ptlist[1]=arcSquare[i].topCenter().asPOINTL();                          //V5
  234.     ptlist[2]=arcSquare[i].rightCenter().asPOINTL();                        //V5
  235.     GpiSetColor(hps, arcColor[i].index());                                  //V5
  236.     GpiBeginPath(hps, 1L);                                                  //V5
  237.     GpiMove(hps,&ptlist[0]);                                                //V5
  238.     GpiPointArc(hps,&ptlist[1]);                                            //V5
  239.     GpiLine(hps,&ptlist[0]);                                                //V5
  240.     GpiEndPath(hps);                                                        //V5
  241.     GpiFillPath(hps,1L,FPATH_ALTERNATE);                                    //V5
  242.   }                                                                         //V5
  243. /**************************************************************************   V5
  244. *****  PM-specific code - END                                         *****   V5
  245. **************************************************************************/ //V5
  246. #endif                                                                      //V5
  247.  
  248. /*--------------------------- Paint the Stars ----------------------------|   V5
  249. | Call the AEarthWindow function for painting the stars.                  |   V5
  250. |------------------------------------------------------------------------*/ //V5
  251.   worldPainted=paintStars();                                                //V5
  252.   return (worldPainted);                                                    //V5
  253.  
  254. } /* end AEarthWindow :: paintWorld(..) */                                  //V5
  255.  
  256. /**************************************************************************   V5
  257. * AEarthWindow :: paintStars - paint the stars in the Earth window        *   v5
  258. *   This function extends the example of how to use underlying low-level  *   V5
  259. *   calls in conjuction with the User Interface Class Library.  In this   *   V5
  260. *   case, native graphics routines are used to draw points which appear   *   V5
  261. *   as stars in space.                                                    *   V5
  262. **************************************************************************/ //V5
  263. IBase::Boolean                                                              //V5
  264.   AEarthWindow :: paintStars()                                              //V5
  265. {                                                                           //V5
  266. Boolean starsPainted = false;                                               //V5
  267.  
  268. /*------------------- Get Presentation Space Objects ---------------------|   V5
  269. | Get the presentation space handle (called "graphics context" in AIX)    |   V5
  270. |   and the rectangle of the area that needs to be painted.               |   V5
  271. |------------------------------------------------------------------------*/ //V5
  272. const IPresSpaceHandle                                                      //V5
  273.   hps(presSpace());                                                         //V5
  274. const IRectangle                                                            //V5
  275.   psRect(rect());                                                           //V5
  276.  
  277. /*------------------- Construct Stars from IPoints -----------------------|   V5
  278. | Construct a star array where each star is a point within the            |   V5
  279. |   presentation space rectangle.  Each point is computed as a fraction   |   V5
  280. |   of the psRect size offset from the origin of the psRect.  The         |   V5
  281. |   starIntensity will indicate if the star is made up of one point(dim), |   V5
  282. |   made up of five points(bright), or randomly dim or bright(twinkle).   |   V5
  283. |------------------------------------------------------------------------*/ //V5
  284. const int                                                                   //V5
  285.   stars=13;                                                                 //V5
  286. const IPair                                                                 //V5
  287.   psOrigin(psRect.bottomLeft()),                                            //V5
  288.   psSize(psRect.size());                                                    //V5
  289. Intensity                                                                   //V6
  290.   currentIntensity;                                                         //V6
  291. int                                                                         //V5
  292.   i, j;                                                                     //v6
  293.  
  294.   if (twinkling) currentIntensity = twinkle;                                //V6
  295.   else           currentIntensity = starIntensity;                          //V6
  296. AStar                                                                       //v6
  297.   star[stars];                                                              //v6
  298.   star[0] =AStar(psOrigin+psSize.scaledBy(0.98,0.43),currentIntensity);     //v6
  299.   star[1] =AStar(psOrigin+psSize.scaledBy(0.70,0.69),currentIntensity);     //v6
  300.   star[2] =AStar(psOrigin+psSize.scaledBy(0.20,0.50),currentIntensity);     //v6
  301.   star[3] =AStar(psOrigin+psSize.scaledBy(0.80,0.63),currentIntensity);     //v6
  302.   star[4] =AStar(psOrigin+psSize.scaledBy(0.05,0.41),currentIntensity);     //v6
  303.   star[5] =AStar(psOrigin+psSize.scaledBy(0.50,0.69),currentIntensity);     //v6
  304.   star[6] =AStar(psOrigin+psSize.scaledBy(0.60,0.94),currentIntensity);     //v6
  305.   star[7] =AStar(psOrigin+psSize.scaledBy(0.10,0.87),currentIntensity);     //v6
  306.   star[8] =AStar(psOrigin+psSize.scaledBy(0.40,0.81),currentIntensity);     //v6
  307.   star[9] =AStar(psOrigin+psSize.scaledBy(0.25,0.69),currentIntensity);     //v6
  308.   star[10]=AStar(psOrigin+psSize.scaledBy(0.75,0.63),currentIntensity);     //v6
  309.   star[11]=AStar(psOrigin+psSize.scaledBy(0.30,0.87),currentIntensity);     //v6
  310.   star[12]=AStar(psOrigin+psSize.scaledBy(0.95,0.87),currentIntensity);     //v6
  311.  
  312. #ifdef IC_MOTIF                                                             //V5
  313. /**************************************************************************   V5
  314. *****  MOTIF-specific code - BEGIN                                    *****   V5
  315. **************************************************************************/ //V5
  316. /*----------------- Construct X-lib Draw Function Arguments --------------|   V5
  317. | Construct the window and display objects needed by the X-lib drawing    |   V5
  318. |   functions from the window handle, which is the widget ID.             |   V5
  319. |   XtWindow and XtDisplay are X-lib intrinsic functions.                 |   V5
  320. |------------------------------------------------------------------------*/ //V5
  321. const Window                                                                //V5
  322.   xWindow(XtWindow(handle()));                                              //V5
  323. Display                                                                     //V5
  324.  *xDisplay(XtDisplay(handle()));                                            //V5
  325.  
  326. /*--------------------------- Draw the Stars -----------------------------|   V5
  327. | Set the foreground color to white, and then draw each star by calling   |   V5
  328. |   the Xlib function for drawing a point.  The thirteen stars are each   |   V5
  329. |   described as coordinates within the presentation space.               |   V5
  330. |      Note that because the X-Windows origin is at the top of the        |   V5
  331. |      window as opposed to the bottom in PM, the y coordinate of the     |   V5
  332. |      X-Windows point must be computed by subtracting the star's y       |   V5
  333. |      coordinate from the presentation space rectangle's height.         |   V5
  334. |------------------------------------------------------------------------*/ //V5
  335. const long                                                                  //V5
  336.   psHeight=psRect.height();                                                 //V5
  337. IPoint                                                                      //V6
  338.   starPoint;                                                                //V6
  339.   for (i=0;i<stars;i++)                                                     //V5
  340.   {                                                                         //V5
  341.     XSetForeground(xDisplay, hps, starColor.asPixel());                     //V5
  342.     for(j=0;j<5;j++)                                                        //V6
  343.     {                                                                       //V6
  344.       starPoint=star[i].point(j);                                           //V6
  345.       if (j==1 && star[i].intensity()==dim)                                 //V6
  346.         XSetForeground(xDisplay, hps, spaceColor.asPixel());                //V6
  347.       XDrawPoint(xDisplay, xWindow, hps,                                    //V5
  348.                 starPoint.x(), psHeight-starPoint.y());                     //v6
  349.     }                                                                       //V6
  350.   }                                                                         //V5
  351.   starsPainted = true;                                                      //V5
  352. /**************************************************************************   V5
  353. *****  MOTIF-specific code - END                                      *****   V5
  354. **************************************************************************/ //V5
  355. #endif                                                                      //V5
  356. #ifdef IC_PM                                                                //V5
  357. /**************************************************************************   V5
  358. *****  PM-specific code - BEGIN                                       *****   V5
  359. **************************************************************************/ //V5
  360. /*----------------------------- Draw the Stars ---------------------------|   V5
  361. | Draw the stars by setting the foreground color to white and calling     |   V5
  362. |   the PM graphics functions for drawing points.                         |   V5
  363. |------------------------------------------------------------------------*/ //V5
  364. POINTL                                                                      //V5
  365.   ptlist[5];                                                                //v6
  366.   GpiSetMarker(hps, MARKSYM_DOT) ;                                          //V5
  367.   for (i=0;i<stars;i++)                                                     //V5
  368.   {                                                                         //V5
  369.     GpiSetColor(hps, starColor.index()) ;                                   //V5
  370.     for(j=0;j<5;j++)                                                        //V6
  371.     {                                                                       //V6
  372.       ptlist[j]=star[i].point(j).asPOINTL();                                //v6
  373.     }                                                                       //V6
  374.     if (star[i].intensity()==dim)                                           //V6
  375.       {                                                                     //V6
  376.         GpiPolyMarker(hps, 1, &ptlist[0]);                                  //V5
  377.         GpiSetColor(hps, spaceColor.index()) ;                              //V6
  378.         GpiPolyMarker(hps, 4, &ptlist[1]);                                  //V6
  379.       }                                                                     //V6
  380.     else                                                                    //V6
  381.         GpiPolyMarker(hps, 5, &ptlist[0]);                                  //V6
  382.   }                                                                         //V6
  383.   starsPainted = true;                                                      //V5
  384. /**************************************************************************   V5
  385. *****  PM-specific code - END                                         *****   V5
  386. **************************************************************************/ //V5
  387. #endif                                                                      //V5
  388.   return (starsPainted);                                                    //V5
  389.  
  390. } /* end AEarthWindow :: paintStars(...) */                                 //V5
  391.  
  392. /**************************************************************************   V6
  393. * AEarthWindow :: AStar :: AStar                                          *   V6
  394. *   Constructor for Earth window stars                                    *   V6
  395. **************************************************************************/ //V6
  396. AEarthWindow :: AStar :: AStar(IPair coordinates, Intensity starGlow)       //v6
  397.                :currentIntensity(starGlow)                                  //V6
  398. {                                                                           //V6
  399. /*--------------------------- Construct the Star -------------------------|   V6
  400. | Each star is constructed as five points.  The first point is            |   v6
  401. |   constructed from the IPair passed in.  The other four are created     |   v6
  402. |   by offsetting the first point by one in each direction; up, down,     |   V6
  403. |   left, and right.                                                      |   V6
  404. |------------------------------------------------------------------------*/ //V6
  405.   starPoint[0]=coordinates;                                                 //V6
  406.   starPoint[1]=starPoint[0]+IPair(0,1);                                     //V6
  407.   starPoint[2]=starPoint[0]+IPair(1,0);                                     //V6
  408.   starPoint[3]=starPoint[0]+IPair(0,-1);                                    //V6
  409.   starPoint[4]=starPoint[0]+IPair(-1,0);                                    //V6
  410.   if (currentIntensity==twinkle)                                            //V6
  411.   {                                                                         //V6
  412.     if (flicker()) currentIntensity=bright;                                 //V6
  413.     else currentIntensity=dim;                                              //V6
  414.   }                                                                         //V6
  415.  
  416. } /* end AEarthWindow :: AStar :: AStar(...) */                             //V6
  417.  
  418. /**************************************************************************   V6
  419. * AEarthWindow :: AStar :: intensity                                      *   V6
  420. *   Return the current intensity of the star.                             *   V6
  421. **************************************************************************/ //V6
  422. AEarthWindow::Intensity                                                     //V6
  423.   AEarthWindow :: AStar :: intensity()                                      //V6
  424. {                                                                           //V6
  425.   return (currentIntensity);                                                //V6
  426. } /* end AEarthWindow :: AStar :: intensity(...) */                         //V6
  427.  
  428. /**************************************************************************   V6
  429. * AEarthWindow :: AStar :: point                                          *   V6
  430. *   Return star point.                                                    *   V6
  431. **************************************************************************/ //V6
  432. const IPoint                                                                //V6
  433.   AEarthWindow :: AStar :: point(const unsigned long i)                     //V6
  434. {                                                                           //V6
  435.   return starPoint[i];                                                      //V6
  436. } /* end AEarthWindow :: AStar :: point(...) */                             //V6
  437.  
  438. /**************************************************************************   V6
  439. * AEarthWindow :: AStar :: flicker                                        *   V6
  440. *   Static function that randomly returns true or false.                  *   V6
  441. **************************************************************************/ //V6
  442. IBase::Boolean                                                              //V6
  443.   AEarthWindow :: AStar :: flicker()                                        //V6
  444. {                                                                           //V6
  445.   Boolean flickered;                                                        //V6
  446.   if (rand()%2) flickered=true;                                             //V6
  447.   else          flickered=false;                                            //V6
  448.   return (flickered);                                                       //V6
  449. } /* end AEarthWindow :: AStar :: flicker() */                              //V6
  450.  
  451. /**************************************************************************   V6
  452. * AEarthWindow :: enableBright                                            *   V6
  453. *   Set the star intensity to bright or dim.                              *   V6
  454. **************************************************************************/ //V6
  455. AEarthWindow                                                                //V6
  456.   &AEarthWindow :: enableBright(IBase::Boolean makingBright)                //V6
  457. {                                                                           //V6
  458.   if (makingBright && starIntensity != bright)                              //V6
  459.   {                                                                         //V6
  460.     starIntensity = bright;                                                 //V6
  461.     refresh();                                                              //V6
  462.   }                                                                         //V6
  463.   else if (!makingBright && starIntensity != dim)                           //V6
  464.   {                                                                         //V6
  465.     starIntensity = dim;                                                    //V6
  466.     refresh();                                                              //V6
  467.   }                                                                         //V6
  468.   return (*this);                                                           //V6
  469. } /* end AEarthWindow :: enableBright */                                    //V6
  470.  
  471. /**************************************************************************   V6
  472. * AEarthWindow :: disableBright                                           *   V6
  473. *   Set the star intensity to dim.                                        *   V6
  474. **************************************************************************/ //V6
  475. AEarthWindow                                                                //V6
  476.   &AEarthWindow :: disableBright()                                          //V6
  477. {                                                                           //V6
  478.   return (enableBright(false));                                             //V6
  479. } /* end AEarthWindow :: disableBright */                                   //V6
  480.  
  481. /**************************************************************************   V6
  482. * AEarthWindow :: isBright                                                *   V6
  483. *   Return true if starIntensity is bright, else return false.            *   V6
  484. **************************************************************************/ //V6
  485. const IBase::Boolean                                                        //V6
  486.   AEarthWindow :: isBright()                                                //V6
  487. {                                                                           //V6
  488.   return (starIntensity==bright);                                           //V6
  489. } /* end AEarthWindow :: isBright */                                        //V6
  490.  
  491. /**************************************************************************   V6
  492. * AEarthWindow :: setLayers                                               *   V6
  493. *   Set the atmosphere layers to 0, 1, 2, or 3.                           *   V6
  494. **************************************************************************/ //V6
  495. AEarthWindow                                                                //V6
  496.   &AEarthWindow :: setLayers(const unsigned long layers)                    //V6
  497. {                                                                           //V6
  498.   if(layers>=3) atmosphereLayers=3;                                         //V6
  499.   else atmosphereLayers=layers;                                             //V6
  500.   refresh();                                                                //V6
  501.   return (*this);                                                           //V6
  502. } /* end AEarthWindow :: setLayers */                                       //V6
  503.  
  504. /**************************************************************************   V6
  505. * AEarthWindow :: layers                                                  *   V6
  506. *   Return the current number of layers of atmosphere.                    *   V6
  507. **************************************************************************/ //V6
  508. const unsigned long                                                         //V6
  509.   AEarthWindow :: layers()                                                  //V6
  510. {                                                                           //V6
  511.   return (atmosphereLayers);                                                //V6
  512. } /* end AEarthWindow :: layers */                                          //V6
  513.  
  514. /**************************************************************************   V6
  515. * AEarthWindow :: enableTwinkle                                           *   V6
  516. *   Make the stars twinkle.                                               *   V6
  517. **************************************************************************/ //V6
  518. AEarthWindow                                                                //V6
  519.   &AEarthWindow :: enableTwinkle(IBase::Boolean turningOn)                  //V6
  520. {                                                                           //V6
  521.   if (turningOn && !twinkling)                                              //V6
  522.   {                                                                         //V6
  523.     twinkling=true;                                                         //V6
  524.     twinkleHandler.handleEventsFor(this);                                   //V6
  525.   }                                                                         //V6
  526.   else if (!turningOn && twinkling)                                         //V6
  527.   {                                                                         //V6
  528.     twinkling=false;                                                        //V6
  529.     twinkleHandler.stopHandlingEventsFor(this);                             //V6
  530.   }                                                                         //V6
  531.   refresh();                                                                //V6
  532.   return (*this);                                                           //V6
  533. } /* end AEarthWindow :: enableTwinkle (...) */                             //V6
  534.  
  535. /**************************************************************************   V6
  536. * AEarthWindow :: disableTwinkle                                          *   V6
  537. *   Make the stars stop twinkling.                                        *   V6
  538. **************************************************************************/ //V6
  539. AEarthWindow                                                                //V6
  540.   &AEarthWindow :: disableTwinkle()                                         //V6
  541. {                                                                           //V6
  542.   return (enableTwinkle(false));                                            //V6
  543. } /* end AEarthWindow :: disableTwinkle() */                                //V6
  544.  
  545. /**************************************************************************   V6
  546. * AEarthWindow :: isTwinkling                                             *   V6
  547. *   Are the stars twinkling?  Is twinkling == true ?                      *   V6
  548. **************************************************************************/ //V6
  549. const IBase::Boolean                                                        //V6
  550.   AEarthWindow :: isTwinkling()                                             //V6
  551. {                                                                           //V6
  552.   return (twinkling);                                                       //V6
  553. } /* end AEarthWindow :: disableTwinkle() */                                //V6
  554.  
  555. /**************************************************************************   V6
  556. * AEarthWindow :: setEarthColor                                           *   V6
  557. *   Set the color used for drawing the inner arc that represents Earth.   *   V6
  558. **************************************************************************/ //V6
  559. AEarthWindow                                                                //V6
  560.   &AEarthWindow :: setEarthColor(const IColor &hue)                         //V6
  561. {                                                                           //V6
  562.   globeColor = hue;                                                         //V6
  563.   refresh();                                                                //V6
  564.   return (*this);                                                           //V6
  565. } /* end AEarthWindow :: setEarthColor(...) */                              //V6
  566.  
  567. /**************************************************************************   V6
  568. * AEarthWindow :: earthColor                                              *   V6
  569. *   Return the current color being used to draw the Earth.                *   V6
  570. **************************************************************************/ //V6
  571. const IColor                                                                //V6
  572.   &AEarthWindow :: earthColor()                                             //V6
  573. {                                                                           //V6
  574.   return (globeColor);                                                      //V6
  575. } /* end AEarthWindow :: earthColor() */                                    //V6
  576.  
  577. /**************************************************************************   V6
  578. * ATwinkleTimeHandler :: tick                                             *   V6
  579. *   Process ATimeHandler ticks by calling the AEarthWindow function       *   V6
  580. *     for twinkling the stars.                                            *   V6
  581. **************************************************************************/ //V6
  582. IBase::Boolean                                                              //V6
  583.   ATwinkleTimeHandler::tick(IEvent& evt)                                    //V6
  584. {                                                                           //V6
  585.   ((AEarthWindow *)evt.window())->paintStars();                             //V6
  586.   return (true);                        //Event is always processed           V6
  587. }                                                                           //V6
  588.  
  589.