home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / hello6 / aearthw6.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  11.7 KB  |  258 lines

  1. /******************************************************************************
  2. * .FILE:         aearthw6.hpp                                                 *
  3. *                                                                             *
  4. * .DESCRIPTION:  Hello World Sample Program Version 6:  AEarthWindow Header   *
  5. *                                                                             *
  6. * .CLASSES:      AEarthWindow                                                 *
  7. *                ATwinkleTimeHandler                                          *
  8. *                AEarthWindowResizeHandler                                    *
  9. *                Star                                                         *
  10. *                                                                             *
  11. * .COPYRIGHT:                                                                 *
  12. *    Licensed Material - Program-Property of IBM                              *
  13. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  14. *                                                                             *
  15. * .DISCLAIMER:                                                                *
  16. *   The following [enclosed] code is sample code created by IBM               *
  17. *   Corporation.  This sample code is not part of any standard IBM product    *
  18. *   and is provided to you solely for the purpose of assisting you in the     *
  19. *   development of your applications.  The code is provided 'AS IS',          *
  20. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  21. *   arising out of your use of the sample code, even if they have been        *
  22. *   advised of the possibility of such damages.                               *
  23. *                                                                             *
  24. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  25. ******************************************************************************/
  26. #ifndef _AEARTHW6_
  27. #define _AEARTHW6_
  28.  
  29. #include <igline.hpp>
  30. #include <igelipse.hpp>
  31. #include <igrect.hpp>
  32. #include <igbundle.hpp>
  33. #include <idrawcv.hpp>
  34. #include <iglist.hpp>
  35. #include <isizehdr.hpp>
  36. #include <igrafctx.hpp>
  37. #include <itimer.hpp>
  38.  
  39. class AEarthWindow;
  40.  
  41. /**************************************************************************
  42. * Class ATwinkleTimeHandler - Time Handler class the processes time ticks *
  43. *   for AEarthWindow.                                                     *
  44. **************************************************************************/
  45. class ATwinkleTimeHandler : public ITimerFn
  46. {
  47.   public:
  48. /*---------------------------- Constructor -------------------------------|
  49. | Constructs the object with                                              |
  50. | 1) A pointer to the earth window                                        |
  51. -------------------------------------------------------------------------*/
  52.     ATwinkleTimeHandler (AEarthWindow *a) : aew(a) {}
  53.  
  54. /*------------------------ Overridden Functions---------------------------|
  55. | timerExpired function is called each time the ITimer expires.           |
  56. -------------------------------------------------------------------------*/
  57.     virtual void
  58.       timerExpired (unsigned long);
  59.  
  60.   private:
  61.     AEarthWindow
  62.      *aew;
  63. };
  64.  
  65. /*------------------------------------------------------------------------|
  66. | An enumerated type that determines how the star will be drawn.          |
  67. -------------------------------------------------------------------------*/
  68.     enum Intensity
  69.     {
  70.       dim, twinkle, bright
  71.     };
  72.  
  73.  
  74. /**************************************************************************
  75. * Class Star -- Draws a star at a specified location                      *
  76. **************************************************************************/
  77. class Star:public IGraphic
  78. {
  79.   public:
  80. /*--------------------------- Constructor --------------------------------|
  81. | Constructs the object with:                                             |
  82. | 1) the point to put the star                                            |
  83. | 2) the point to put the star and the intensity                          |
  84. -------------------------------------------------------------------------*/
  85.     Star(const IPoint &pt) ;
  86.     Star(const IPoint &pt,Intensity &it) ;
  87.  
  88. /*--------------------------- Destructor ---------------------------------|
  89. | Destructs the object with:                                              |
  90. | 1) no parameters                                                        |
  91. -------------------------------------------------------------------------*/
  92.    ~Star();
  93.  
  94. /*------------------------------------------------------------------------|
  95. |  setPoint -- This function sets a new location to draw the star at      |
  96. |  setIntensity--This function sets the intensity of the star             |
  97. |  flicker--This function randomly causes the star to change intensity    |
  98. -------------------------------------------------------------------------*/
  99.   Star
  100.    &setPoint(const IPoint &pt),
  101.    &setIntensity(const Intensity it),
  102.    &flicker(),
  103. /*------------------------------------------------------------------------|
  104. | These function over ride the IGraphicFunctions:                         |
  105. |   drawOn--renders the star on the display                               |
  106. |   setGraphicBundle--sets the GraphicBundle for the star                 |
  107. -------------------------------------------------------------------------*/
  108.    &drawOn(IGraphicContext &gc),
  109.    &setGraphicBundle(const IGraphicBundle &igb);
  110.  
  111.   private:
  112.     Intensity
  113.       intensity;
  114.     IGLine
  115.       dimStar;
  116.     IGEllipse
  117.       noStar,
  118.       brightStar;
  119. };
  120.  
  121.  
  122. /**************************************************************************
  123. * Class AEarthWindowResizeHandler -- A handler to resize the picture      *
  124. *    according to the new dimensions of the IDrawingCanvas window.        *
  125. **************************************************************************/
  126. class AEarthWindowResizeHandler: public IResizeHandler
  127. {
  128.   public:
  129. /*--------------------------- Constructor --------------------------------|
  130. | Constructs the object with:                                             |
  131. | 1) a pointer to the EarthWindow                                         |
  132. -------------------------------------------------------------------------*/
  133.     AEarthWindowResizeHandler (AEarthWindow *aew);
  134.  
  135. /*--------------------------- Destructor ---------------------------------|
  136. | Destructs the object with:                                              |
  137. | 1) no parameters                                                        |
  138. -------------------------------------------------------------------------*/
  139.     virtual
  140.      ~AEarthWindowResizeHandler();
  141.  
  142.   protected:
  143. /*-------------------- Override windowResize Function --------------------|
  144. | The windowResize() function is called to handle resizing of             |
  145. | the IDrawingCanvas text window containing the graphics of Earth.        |
  146. |------------------------------------------------------------------------*/
  147.     virtual Boolean
  148.       windowResize(IResizeEvent & evnt);
  149.  
  150.   private:
  151.     AEarthWindow
  152.      *earthWindow;
  153. };
  154.  
  155. /**************************************************************************
  156. * Class AEarthWindow -- Earth window for the C++ Hello World sample       *
  157. *    application.                                                         *
  158. **************************************************************************/
  159. class AEarthWindow : public IDrawingCanvas
  160. {
  161.   public:
  162. /*--------------------------- Constructor --------------------------------|
  163. | Constructs the object with:                                             |
  164. | 1) the window id, the parent window, and the size of the window         |
  165. -------------------------------------------------------------------------*/
  166.     AEarthWindow(unsigned long windowId,
  167.                 IWindow * parentownerWindow,
  168.                 const IRectangle& rect=IRectangle());
  169.  
  170. /*--------------------------- Destructor ---------------------------------|
  171. | Destructs the object with:                                              |
  172. | 1) no parameters                                                        |
  173. -------------------------------------------------------------------------*/
  174.     virtual
  175.      ~AEarthWindow();
  176.  
  177. /*------------------ Paint the Earth and Stars Functions -----------------|
  178. | These functions are called to draw the Earth and stars in a static      |
  179. | text window.                                                            |
  180. |   paintWorld - Clear the background, draw the Earth and a variable      |
  181. |           number of atmosphere layers, and call paintStars to draw the  |
  182. |           stars.                                                        |
  183. |   paintStars - Draw the stars as graphical points.                      |
  184. |   twinkleStars - Causes the stars to randomly swith from bright to dim  |
  185. |------------------------------------------------------------------------*/
  186.     Boolean
  187.       paintWorld( ISize newSize ),
  188.       paintStars(),
  189.       twinkleStars();
  190. /*------------------ Earth Window Settings Functions ---------------------|
  191. | These functions are used to change the Earth window settings.           |
  192. |   enableBright - Change starIntensity to bright.                        |
  193. |   disableBright - Change starIntensity to dim.                          |
  194. |   setLayers - Change the number of atmosphere layers drawn atop the     |
  195. |           Earth arc.  Valid values are 0, 1, 2, 3.                      |
  196. |   enableTwinkle - Set twinkling to true.                                |
  197. |   disableTwinkle - Set twinkling to false.                              |
  198. |   setEarthColor - Change the color used to draw the Earth arc.          |
  199. |                                                                         |
  200. | These functions are used to query the Earth window settings.            |
  201. |   isTwinkling - Return true if the stars are set to twinkle.            |
  202. |   isBright - Return true if the stars are to be drawn with five points  |
  203. |           when they are not twinkling.                                  |
  204. |   earthColor - Return the current color used to draw the Earth arc.     |
  205. |   layers - Return the number of arcs drawn above the Earth arc.         |
  206. |------------------------------------------------------------------------*/
  207.     virtual AEarthWindow
  208.      &enableBright(Boolean makingBright=true),
  209.      &disableBright(),
  210.      &setLayers(const unsigned long atmosphereLayers),
  211.      &enableTwinkle(Boolean turningOn=true),
  212.      &disableTwinkle(),
  213.      &setEarthColor(const IColor &hue);
  214.     const Boolean
  215.       isTwinkling(),
  216.       isBright();
  217.     const IColor
  218.      &earthColor();
  219.     const unsigned long
  220.       layers();
  221.  
  222.   private:
  223.     int
  224.       atmosphereLayers;
  225.     AEarthWindowResizeHandler
  226.       earthWindowResizeHandler;
  227.     IColor
  228.       spaceColor,
  229.       globeColor,
  230.       starColor;
  231.     Star
  232.      *starlist[13];
  233.     IGEllipse
  234.      *earthArc[4];
  235.     IGRectangle
  236.       space;
  237.     IGList
  238.       graphList,
  239.       starGraphicList,
  240.       atmosphereGraphicList;
  241.     Boolean
  242.       twinkling;
  243.     Intensity
  244.       starIntensity;
  245.     ITimer
  246.        twinkleTimer;
  247.   //  ATwinkleTimeHandler
  248.   //     twinklefn;
  249. /*------------------------------ Operators -------------------------------|
  250. | Operators defined for this class:                                       |
  251. |  =  -- Assignment operator                                              |
  252. -------------------------------------------------------------------------*/
  253.     AEarthWindow
  254.      &operator=(const AEarthWindow&);    //Default assignment operator
  255.  
  256. };
  257. #endif
  258.