home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / DOODLE / DAREA / DAREA.HPP < prev    next >
Text File  |  1995-05-05  |  7KB  |  190 lines

  1. #ifndef DAREA_HPP
  2. #define DAREA_HPP
  3. /******************************************************************************/
  4. /* DOODLE SAMPLE PROGRAM - Version 1: Class Header (DAREA.HPP)                */
  5. /*                                                                            */
  6. /* COPYRIGHT: Copyright (C) International Business Machines Corp., 1995.      */
  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 <imndihdr.hpp>
  25. #include <imndievt.hpp>
  26. #include <ireslib.hpp>
  27. #include <imoushdr.hpp>
  28. #include <imousevt.hpp>
  29. #include <ifont.hpp>
  30. #include <istring.hpp>
  31. #include <igrect.hpp>
  32. #include <iflyhhdr.hpp>
  33. #include "darea.h"
  34.  
  35. //**************************************************************************
  36. // Class:   DrawingArea                                                    *
  37. //                                                                         *
  38. // Purpose: Subclass of IDrawingCanvas.  Class contains the handlers       *
  39. //          necessary for interactive drawing of the graphic objects.      *
  40. //                                                                         *
  41. //**************************************************************************
  42. class DrawingArea : public IDrawingCanvas,
  43.                     public IMouseHandler
  44. {
  45. public:
  46.   DrawingArea  ( unsigned long id,
  47.                  IWindow* parent,
  48.                  IWindow* owner,
  49.                  const IRectangle& rect = IRectangle() );
  50. virtual
  51.   ~DrawingArea ( );
  52.  
  53. enum DrawState {
  54.   drawing,
  55.   waitingForInput,
  56.   notDrawing
  57.   };
  58.  
  59. DrawingArea
  60.   &setDrawState        ( const DrawState newState = drawing );
  61. DrawState
  62.   drawState            ( ) const { return dState; }
  63.  
  64. DrawingArea
  65.   &setBitmapFileName   ( const IString& bitmapFile )
  66.                          { currentBitmap = bitmapFile;
  67.                            return *this; }
  68. IString
  69.   bitmapFileName       ( ) const
  70.                          { return currentBitmap; }
  71.  
  72. enum DrawObject {
  73.   move = POINTER_MOVE,
  74.   line,
  75.   freehand,
  76.   rectangle,
  77.   ellipse,
  78.   polyline,
  79.   polygon,
  80.   arc,
  81.   pie,
  82.   chord,
  83.   text,
  84.   bitmap,
  85.   stylecan,
  86.   eraser
  87.   };
  88.  
  89. virtual DrawingArea
  90.   &setDrawObject       ( const DrawObject drawObject )
  91.                          { currentObj = drawObject;
  92.                            if (flyOverHandler)
  93.                              flyOverHandler->setHelpText( handle(),
  94.                                                           IResourceId(FLYOVERTEXT_BLANK),
  95.                                                           IResourceId(currentObj+LONG_OFFSET));
  96.                            return *this; }
  97. virtual DrawObject
  98.   drawObject           ( ) const {return currentObj;}
  99.  
  100. virtual IGraphicBundle
  101.   &graphicBundle       ( ) { return currentBundle; }
  102.  
  103. virtual DrawingArea
  104.   &setCurrentFont      ( const IFont& font );
  105. virtual IFont
  106.   currentFont          ( ) const;
  107.  
  108. virtual void
  109.    setColor            ( const IColor* color )
  110.                          { graphicBundle().setFillColor(*color); }
  111.  
  112. virtual void
  113.    setFlyOverHandler   ( IFlyOverHelpHandler* handler)
  114.                          { flyOverHandler = handler;
  115.                            if (flyOverHandler)
  116.                              flyOverHandler->setHelpText( handle(),
  117.                                                           IResourceId(FLYOVERTEXT_BLANK),
  118.                                                           IResourceId(currentObj+LONG_OFFSET));
  119.                          }
  120.  
  121. virtual void
  122.    setPenColor         ( const IColor* color )
  123.                          { graphicBundle().setPenColor(*color); }
  124. virtual void
  125.    setWidth            ( unsigned long width )
  126.                          { graphicBundle().setPenWidth(width); }
  127.  
  128. virtual void
  129.    setDrawStyle        ( short value = 0 )
  130.         { switch(value)
  131.           {
  132.             case -1:    // frame
  133.               graphicBundle().setDrawOperation(IGraphicBundle::frame);
  134.               break;
  135.             case 0:     // frame & fill
  136.               graphicBundle().setDrawOperation(IGraphicBundle::fillAndFrame);
  137.               break;
  138.             case 1:     // fill
  139.               graphicBundle().setDrawOperation(IGraphicBundle::fill);
  140.               break;
  141.           }
  142.         }
  143.  
  144. protected:
  145.  
  146. virtual Boolean
  147.   mouseMoved           ( IMouseEvent&        event ),
  148.   mouseClicked         ( IMouseClickEvent&   event ),
  149.   mousePointerChange   ( IMousePointerEvent& event );
  150.  
  151. virtual DrawingArea
  152.   &button1Down         ( const IPoint&       point ),
  153.   &button1Up           ( const IPoint&       point ),
  154.   &button1DoubleClick  ( const IPoint&       point ),
  155.   &button2Down         ( const IPoint&       point ),
  156.   &button2Up           ( const IPoint&       point );
  157.  
  158. private:
  159.   IGraphicContext    gc;
  160.   IFont              currentfont;
  161.   IGraphicBundle     currentBundle;
  162.   IString            currentBitmap;
  163.   DrawState          dState;
  164.   DrawObject         currentObj;
  165.   IGraphic*          iGraphic;
  166.   IGraphic*          moveGraphic;
  167.   IGRectangle        moveRect;
  168.   IPoint             startingPt;
  169.   IPoint             previousPt;
  170.   IPoint             tempPt;
  171.   unsigned long      pointCount;
  172.   IPointerHandle     ptrCurrent;
  173.   IPointerHandle     ptrLine;
  174.   IPointerHandle     ptrFreehand;
  175.   IPointerHandle     ptrRectangle;
  176.   IPointerHandle     ptrEllipse;
  177.   IPointerHandle     ptrPolyline;
  178.   IPointerHandle     ptrPolygon;
  179.   IPointerHandle     ptrArc;
  180.   IPointerHandle     ptrPie;
  181.   IPointerHandle     ptrChord;
  182.   IPointerHandle     ptrText;
  183.   IPointerHandle     ptrBitmap;
  184.   IPointerHandle     ptrStyleCan;
  185.   IPointerHandle     ptrEraser;
  186.   IFlyOverHelpHandler*  flyOverHandler;
  187. };
  188.  
  189. #endif
  190.