home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / 2D-DRAW / 2D-DRAW.HPP < prev    next >
Text File  |  1995-04-04  |  8KB  |  217 lines

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