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

  1. /******************************************************************************
  2. * .FILE:         2d-draw.hpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION:  2D Graphics Drawing Program : Class Definitions              *
  5. *                                                                             *
  6. * .CLASSES:      MainWindow                                                   *
  7. *                DrawingArea                                                  *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #ifndef TWOD_HPP
  26. #define TWOD_HPP
  27. #include <iframe.hpp>
  28. #include <isizehdr.hpp>
  29. #include <icmdhdr.hpp>
  30. #include <igrafctx.hpp>
  31. #include <igbundle.hpp>
  32. #include <idrawcv.hpp>
  33. #include <imenubar.hpp>
  34. #include <imndihdr.hpp>
  35. #include <imndievt.hpp>
  36. #include <ireslib.hpp>
  37. #include <imoushdr.hpp>
  38. #include <imousevt.hpp>
  39. #include <iflyhhdr.hpp>
  40. #include <iflytext.hpp>
  41. #include <ifont.hpp>
  42. #include <iinfoa.hpp>
  43. #include <itbar.hpp>
  44. #include <itbarbut.hpp>
  45. #include <igrect.hpp>
  46. #include "2ddraw.h"
  47.  
  48. //**************************************************************************
  49. // Class:   DrawingArea                                                    *
  50. //                                                                         *
  51. // Purpose: Subclass of IDrawingCanvas.  Class contains the handlers       *
  52. //          necessary for interactive drawing of the graphic objects.      *
  53. //                                                                         *
  54. //**************************************************************************
  55. class DrawingArea : public IDrawingCanvas,
  56.                     public IMouseHandler
  57. {
  58. public:
  59.   DrawingArea  ( unsigned long windowId,
  60.                  IWindow* parent,
  61.                  IWindow* owner,
  62.                  const IRectangle& intial = IRectangle() );
  63. virtual
  64.   ~DrawingArea ( );
  65.  
  66. enum DrawState {
  67.   drawing,
  68.   waitingForInput,
  69.   notDrawing
  70.   };
  71.  
  72. DrawingArea
  73.   &setDrawState        ( const DrawState newState = drawing );
  74. DrawState
  75.   drawState            ( ) const { return dState; }
  76.  
  77. DrawingArea
  78.   &setBitmapFileName   ( const IString& bitmapFile )
  79.                          { currentBitmap = bitmapFile;
  80.                            return *this; }
  81. IString
  82.   bitmapFileName       ( ) const
  83.                          { return currentBitmap; }
  84.  
  85. enum DrawObject {
  86.   pointer = PALLET_NORM,
  87.   line,
  88.   freeHand,
  89.   rectangle,
  90.   ellipse,
  91.   polyline,
  92.   polygon,
  93.   arc,
  94.   pie,
  95.   chord,
  96.   text,
  97.   bitmap
  98.   };
  99.  
  100. virtual DrawingArea
  101.   &setDrawObject       ( const DrawObject drawObject )
  102.                          { currentObj = drawObject;
  103.                            return *this; }
  104. virtual DrawObject
  105.   drawObject           ( ) const {return currentObj;}
  106.  
  107. virtual IGraphicBundle
  108.   &graphicBundle       ( ) { return currentBundle; }
  109.  
  110. virtual DrawingArea
  111.   &setCurrentFont      ( const IFont& font );
  112. virtual IFont
  113.   currentFont          ( ) const;
  114.  
  115. protected:
  116.  
  117. virtual Boolean
  118.   mouseMoved           ( IMouseEvent&        event ),
  119.   mouseClicked         ( IMouseClickEvent&   event ),
  120.   mousePointerChange   ( IMousePointerEvent& event );
  121.  
  122. virtual DrawingArea
  123.   &button1Down         ( const IPoint&       point ),
  124.   &button1Up           ( const IPoint&       point ),
  125.   &button1DoubleClick  ( const IPoint&       point ),
  126.   &button2Down         ( const IPoint&       point ),
  127.   &button2Up           ( const IPoint&       point );
  128.  
  129. private:
  130.   IFont              currentfont;
  131.   IGraphicBundle     currentBundle;
  132.   IGraphicBundle     animateBundle;
  133.   IString            currentBitmap;
  134.   DrawState          dState;
  135.   DrawObject         currentObj;
  136.   IGraphic*          iGraphic;
  137.   IGraphic*          moveGraphic;
  138.   IGRectangle        moveRect;
  139.   IPoint             startingPt;
  140.   IPoint             previousPt;
  141.   IPoint             tempPt;
  142.   unsigned long      pointCount;
  143.   IPointerHandle     ptrLine;
  144.   IPointerHandle     ptrDraw;
  145.   IPointerHandle     ptrRectangle;
  146.   IPointerHandle     ptrEllipse;
  147.   IPointerHandle     ptrPolyline;
  148.   IPointerHandle     ptrPolygon;
  149.   IPointerHandle     ptrArc;
  150.   IPointerHandle     ptrPie;
  151.   IPointerHandle     ptrChord;
  152.   IPointerHandle     ptrText;
  153.   IPointerHandle     ptrBitmap;
  154.   IPointerHandle     ptrCurrent;
  155. };
  156.  
  157. //**************************************************************************
  158. // Class:   MainWindow                                                     *
  159. //                                                                         *
  160. // Purpose: Main Window for C++ Hello World sample application             *
  161. //          It is a subclass of IFrameWindow                               *
  162. //                                                                         *
  163. //**************************************************************************
  164. class MainWindow : public IFrameWindow,
  165.                    public ICommandHandler,
  166.                    public IMenuDrawItemHandler
  167. {
  168. public:                               //Define the Public Information
  169.  
  170.   MainWindow(unsigned long windowId); //Constructor for this class
  171.  
  172. virtual
  173.   ~MainWindow();
  174.  
  175. static IColor
  176.   penColorFromId                ( unsigned long Identifier ),
  177.   fillColorFromId               ( unsigned long Identifier ),
  178.   backColorFromId               ( unsigned long Identifier );
  179.  
  180. static unsigned long
  181.   patternFromId                 ( unsigned long Identifier ),
  182.   penWidthFromId                ( unsigned long Identifier );
  183.  
  184. static IGraphicBundle::PenType
  185.   penTypeFromId                 ( unsigned long Identifier );
  186.  
  187. protected:
  188.  
  189. virtual Boolean
  190.   setSize                       ( IMenuDrawItemEvent& evt,
  191.                                   ISize&              newSize ),
  192.   draw                          ( IMenuDrawItemEvent& evt,
  193.                                   DrawFlag&           flag    ),
  194.  
  195.   command                       ( ICommandEvent&      event   );
  196.  
  197. private:                              //Define Private Information
  198.   DrawingArea         drawingArea;    // move back to top of list.
  199.   IToolBar            toolBar;
  200.   IMenuBar            menuBar;
  201.   IInfoArea           infoArea;
  202.   IFlyText            flyText;
  203.   IFlyOverHelpHandler flyOver;
  204.   unsigned long       lastPenColorId;
  205.   unsigned long       lastFillColorId;
  206.   unsigned long       lastPenPatternId;
  207.   unsigned long       lastFillPatternId;
  208.   unsigned long       lastPenTypeId;
  209.   unsigned long       lastPenWidthId;
  210.   unsigned long       lastBackId;
  211.   unsigned long       lastDrawOperationId;
  212.   IToolBarButton      normalButton,
  213.                       lineButton,
  214.                       drawButton,
  215.                       rectangleButton,
  216.                       ellipseButton,
  217.                       polylineButton,
  218.                       polygonButton,
  219.                       arcButton,
  220.                       pieButton,
  221.                       chordButton,
  222.                       textButton,
  223.                       bitmapButton;
  224. };
  225. #endif
  226.