home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / pallet.hpp < prev    next >
C/C++ Source or Header  |  1999-07-12  |  15KB  |  386 lines

  1. #ifndef TWOD_HPP
  2. #define TWOD_HPP
  3.  
  4. /*
  5. -------------------------------------------------------------------------------
  6. Copyright (c) IBM Corporation 1996, 1997.
  7. All Rights Reserved.
  8.  
  9. Permission is granted to copy, use, modify, and merge this software into your
  10. applications and to permit others to do any of the foregoing. You must include
  11. this permission and copyright notice in all copies and modified versions of
  12. this software. THIS SOFTWARE IS PROVIDED IN ITS 'AS IS' CONDITION.
  13. IBM DISCLAIMS ANY LIABILITY OF ANY KIND FOR DAMAGES WHATSOEVER RESULTING
  14. FROM THE USE OF THIS SOFTWARE.
  15. -------------------------------------------------------------------------------
  16. */
  17.  
  18. #include <iexcept.hpp>
  19. #include <iframe.hpp>              // IBM Open Class Headers
  20. #include <iinfoa.hpp>
  21. #include <isizehdr.hpp>
  22. #include <icmdhdr.hpp>
  23. #include <imenubar.hpp>
  24. #include <ireslib.hpp>
  25. #include <imoushdr.hpp>
  26. #include <imousevt.hpp>
  27. #include <istattxt.hpp>
  28. #include <itbar.hpp>
  29. #include <itbarbut.hpp>
  30. #include <ipainhdr.hpp>
  31. #include <ipainevt.hpp>
  32. #include <ititle.hpp>
  33. #include <ipushbut.hpp>
  34. #include <icoordsy.hpp>
  35. #include <ifontdlg.hpp>
  36. #include <ifont.hpp>
  37. #include <ientryfd.hpp>
  38. #include <ipopmenu.hpp>
  39. #include <imcelcv.hpp>
  40.  
  41. #include <igraph2d.hpp>
  42. #include <igrport.hpp>
  43. #include <iimage.hpp>
  44. #include <igraftxt.hpp>
  45.  
  46. #include <itrace.hpp>
  47.  
  48. #include <ibcolor.hpp>
  49.  
  50. #ifndef FVT_NOPRINT
  51. // Printing headers
  52. #ifndef Taligent_PRINT
  53. #endif
  54. #ifndef IC_PAGECOMPOSITOR
  55. #endif
  56. #ifndef Taligent_PRINTBUTLER
  57. #endif
  58. #endif
  59.  
  60. #include "pallet.h"
  61.  
  62. #if 0
  63.  
  64. extern "C" { void PerfStart(void); }
  65. extern "C" { void PerfStop(void); }
  66.  
  67. #endif
  68.  
  69.  
  70.  
  71. //**************************************************************************
  72. // Class:   IColorSelector                                                 *
  73. //                                                                         *
  74. // Purpose: Control for varying the R,G,B, and Gray values of the selected *
  75. //          color.  Used with IPalletDialog.                               *
  76. //**************************************************************************
  77.  
  78. class IColorSelector : public ICanvas, public IPaintHandler, public IMouseHandler
  79. {
  80.   public:
  81.     enum ColorType { Red_type, Green_type, Blue_type, Gray_type };
  82.     IColorSelector(long id, IWindow* parent, IWindow* owner,
  83.                    IColorSelector::ColorType t, bool h);
  84.     ~IColorSelector();
  85.     CharIntensity GetValue();
  86.     CharIntensity SetValue(CharIntensity val);
  87.   protected:
  88.     virtual bool paintWindow(IPaintEvent& event);
  89.     virtual bool mouseClicked(IMouseClickEvent&   event),
  90.                     mouseMoved(IMouseEvent& event);
  91.   private:
  92.     IManagedPresSpaceHandle *managedPresSpacePtr;
  93.     IWindow* win;
  94.     CharIntensity value;
  95.     ColorType type;
  96.     bool capturing;
  97.     bool horizontal;
  98. };
  99.  
  100. //**************************************************************************
  101. // Class:   IColorSquare                                                   *
  102. //                                                                         *
  103. // Purpose: Class draws a square of the color selected in the              *
  104. //          IColorPalletCanvas (see below) for use with IPalletDialog      *
  105. //**************************************************************************
  106.  
  107. class IColorSquare : public ICanvas, public IPaintHandler
  108. {
  109.   public:
  110.     IColorSquare(const unsigned long id, IWindow* parent, IWindow* owner);
  111.     ~IColorSquare();
  112.   protected:
  113.     virtual bool paintWindow(IPaintEvent& event);
  114.   private:
  115.     IManagedPresSpaceHandle *managedPresSpacePtr;
  116.     IWindow* win;
  117. };
  118.  
  119. //**************************************************************************
  120. // Class:   IPalletCanvas                                                  *
  121. //                                                                         *
  122. // Purpose: Acts as a control for handling color selection in the          *
  123. //          IPalletDialog                                                  *
  124. //**************************************************************************
  125.  
  126. class IPalletCanvas : public ICanvas, public IPaintHandler, public IMouseHandler
  127. {
  128.   public:
  129.     IPalletCanvas(const unsigned long id, IWindow* parent, IWindow* owner, int& pX, int& pY);
  130.     ~IPalletCanvas();
  131.     IBaseColor color();
  132.     void SetColor();
  133.     int GetPosX() { return *posX; }
  134.     int GetPosY() { return *posY; }
  135.   protected:
  136.     virtual bool paintWindow(IPaintEvent& event);
  137.     virtual bool mouseClicked(IMouseClickEvent& event);
  138.   private:
  139.     IManagedPresSpaceHandle *managedPresSpacePtr;
  140.     void InitTables();
  141.     IWindow* win;
  142.     IGRect2D* squareTable[8][8];
  143.     int paintAllFlag;
  144.     int* posX;
  145.     int* posY;
  146. };
  147.  
  148. //**************************************************************************
  149. // Class:   IControlCanvas                                                 *
  150. //                                                                         *
  151. // Purpose: This class holds the controls for the IPalletDialog            *
  152. //**************************************************************************
  153.  
  154. class IControlCanvas : public ICanvas, public ICommandHandler
  155. {
  156.   public:
  157.     IControlCanvas(const unsigned long id, IWindow* parent, IWindow* owner)
  158.       : ICanvas(id,parent,owner),
  159.        win(owner)
  160.       { handleEventsFor(this); }
  161.     ~IControlCanvas()
  162.       { stopHandlingEventsFor(this); }
  163.   protected:
  164.     virtual bool command(ICommandEvent& event);
  165.   private:
  166.     IWindow* win;
  167. };
  168.  
  169. //**************************************************************************
  170. // Class:   IPalletDialog                                                  *
  171. //                                                                         *
  172. // Purpose: Class is used as a dialog to allow the user to select a color  *
  173. //          for framing of filling a graphic                               *
  174. //**************************************************************************
  175.  
  176. class IPalletDialog : public IFrameWindow
  177. {
  178.   public:
  179.     IPalletDialog(const char* title, int& pX, int& pY, IWindow * ownerWnd);
  180.     ~IPalletDialog();
  181.     IBaseColor color();
  182.     void SetValues(CharIntensity rV, CharIntensity gV, CharIntensity bV, CharIntensity grV);
  183.     void SetValue(CharIntensity val, IColorSelector::ColorType t);
  184.     void SetColor(IBaseColor color);
  185.   private:
  186.     IControlCanvas controlCanvas;
  187.     IPalletCanvas palletCanvas;
  188.     IColorSquare colorSquare;
  189.     IPushButton OkBut,CancelBut,ResetBut;
  190.     IBaseColor currentColor;
  191.     IColorSelector rSelector,gSelector,bSelector,grSelector;
  192.     ITitle dialogTitle;
  193.     bool grayColor;
  194.     CharIntensity rVal,gVal,bVal,grVal;
  195.     IBaseColor fColor;
  196. };
  197. #if 0
  198. //**************************************************************************
  199. // Class:   ITextDialog                                                    *
  200. //                                                                         *
  201. // Purpose: Class is used as a dialog to allow the user to enter text to   *
  202. //          be placed on the drawing canvas.                               *
  203. //**************************************************************************
  204.  
  205. class ITextDialog : public IFrameWindow, public ICommandHandler
  206. {
  207.   public:
  208.     ITextDialog(const char* title, IWindow * ownerWnd);
  209.     ~ITextDialog() { stopHandlingEventsFor(this); }
  210.     IString getText() { return entryField.text(); }
  211.   protected:
  212.     virtual bool command(ICommandEvent& event);
  213.   private:
  214.     IMultiCellCanvas controlCanvas;
  215.     IEntryField entryField;
  216.     IPushButton OkBut;
  217.     ITitle dialogTitle;
  218. };
  219.  
  220. //**************************************************************************
  221. // Class:   DrawingArea                                                    *
  222. //                                                                         *
  223. // Purpose: Class contains the handlers necessray for interactive drawing  *
  224. //          and manipulation of graphical objects                          *
  225. //**************************************************************************
  226.  
  227. class DrawingArea : public ICanvas, public IMouseHandler, public IPaintHandler, public IResizeHandler
  228. {
  229.   public:
  230.     DrawingArea(unsigned long windowId, IWindow* parent,
  231.                 IWindow* owner, const IRectangle& intial = IRectangle() );
  232.     virtual ~DrawingArea ( );
  233.  
  234.     enum DrawingState { drawing, waitForInput, notDrawing };
  235.  
  236.     DrawingArea &SetDrawState(const DrawingState newState = drawing);
  237.     DrawingState GetDrawState( ) const { return dState; }
  238.  
  239.     enum DrawObject { attribStyle = PALLET_STYLE, pointer, rotate,
  240.                       scale, clip, area, line, freeHand, rectangle,
  241.                       ellipse, polyline, polygon, curve, loop,  text,
  242.                       bitmap, arc, pie, chord, cbezier, acurve,
  243.                       lbezier, aloop, add, subtract, multiply, Xor};
  244.  
  245.     virtual DrawingArea &SetDrawObject( const DrawObject drawObject)
  246.             { currentObj = drawObject; return *this; }
  247.  
  248.     // window management methods
  249.     void Init();
  250.     void Clear();
  251.     void ResetDrawingDevices();
  252.     void Draw(IRectangle invalidRect);
  253.  
  254.     // transfer mode set methods
  255.     void SetFrameTransferMode(unsigned long mode);
  256.     void SetFillTransferMode(unsigned long mode);
  257.  
  258.     // pattern set methods
  259.     void SetFramePattern(unsigned long mode);
  260.     void SetFillPattern(unsigned long mode);
  261.  
  262.     // attribute color set methods
  263.     void SetPenColor(IBaseColor color);
  264.     void SetFillColor(IBaseColor color);
  265.  
  266.     // miscelaneous attribute set methods
  267.     void SetDrawingOp(IAttributeState::EDrawOperation op);
  268.     void SetPenWidth(int width);
  269.  
  270.     // graphic text set methods
  271.     void SetGraphicText(IText text) { graphicText = text; }
  272.  
  273.     // set methods for the information text
  274.     void SetInfoText(IString text);
  275.     void SetInfoText(unsigned long id);
  276.  
  277.     // Get/Create methods
  278.     void setPenType(int type);
  279.  
  280.     IGraphicGroup *GetGraphicGroup() { return fGraphicGroup; }
  281.   protected:
  282.     bool paintWindow(IPaintEvent&);
  283.  
  284.     virtual bool mouseClicked(IMouseClickEvent&   event),
  285. #ifndef IC_MOTIF
  286.                     mousePointerChange(IMousePointerEvent& event),
  287. #endif
  288.                     mouseMoved(IMouseEvent& event);
  289.     virtual bool windowResize(IResizeEvent& event);
  290.  
  291.     virtual DrawingArea &button1Down(const IPoint& point),
  292.                         &button1Up(const IPoint& point),
  293.                         &button1DoubleClick(const IPoint& point),
  294.                         &button2or3DoubleClick(const IPoint& point),
  295.                         &button2or3Down(const IPoint& point);
  296.  
  297.   private:
  298.     IRectangle& convertGraphicToView( IRectangle& graphicRect );
  299.     IMGraphic* getTopGraphicUnderPoint(const IGPoint2D& point, IGraphicGroup* group);
  300.     IGArea *GraphicToArea(IMGraphic *mgraphic);
  301.  
  302.     IManagedPresSpaceHandle *managedPresSpacePtr;
  303.     IGrafPort*         myDisplayPort;      // rendering graphics to the window
  304.     IGrafPort*         parentPort;         // the parent port is used when clipping
  305.  
  306.     IGraphicGroup*     fGraphicGroup;      // the list of graphics on the canvas
  307.  
  308.     unsigned long      clickCount;         // tracks different stages of curve definition
  309.     unsigned long      pointCount;         // tracks the number of the number of control points
  310.  
  311.     bool               clipping;           // specifies whether clipping is on/off
  312.     bool               paintedLastResize;  // used to determine whether this window was visible before resize
  313.     const IGArea       *clipArea;          // the clipping area (when clipping is on)
  314.  
  315.     DrawingState          dState;             // the drawing state
  316.     DrawObject         currentObj;         // the current object to be drawn
  317.  
  318. #ifndef IC_MOTIF
  319. #define kNumberOfPointers 14
  320.     IPointerHandle     ptrArray[kNumberOfPointers];       // the mouse pointers
  321. #endif
  322.     IGPoint2D            startingPoint;      // points used for defining graphic
  323.     IGPoint2D            previousPoint;      //
  324.     IGPoint2D            c1,c2,c3,c4;        // control points for curves
  325.  
  326.     IMGraphic*          currentGraphic;     // current graphic being defined or selected
  327.     IMGraphic*          moveGraphic;        // used for moving graphics
  328.  
  329.     IGrafBundle         drawingBundle;      // black framing bundle
  330.  
  331.     // use IGrafBundle to hold all frame and fill info
  332.     IGrafBundle         currentBundle;
  333.  
  334.     IPolygon*          tempPolygon;        // used for the defining of polygons
  335.     IPolyline*         tempPolyline;       // used for the defining of polylines
  336.     IPolygon*          moveRect;           // used in moving graphics
  337.  
  338.     IGRPoint2DArray      pointArray;         // used for defining nurbs/loops
  339.     IText            graphicText;        // the current string for a text graphic
  340.  
  341. };
  342.  
  343. //**************************************************************************
  344. // Class:   MainWindow                                                     *
  345. //                                                                         *
  346. // Purpose: Main Window for C++ Starter Set 2D Graphics Application        *
  347. //**************************************************************************
  348.  
  349. class MainWindow : public IFrameWindow, public ICommandHandler,
  350.         public IResizeHandler
  351. {
  352.   public:
  353.     MainWindow(unsigned long windowId);
  354.     virtual ~MainWindow();
  355.     // set methods for the information text
  356.     void SetInfoText(IString text);
  357.     void SetInfoText(unsigned long id);
  358.     // pallete management methods
  359.     void InitPallet();
  360.     void ClearPallet();
  361.     const IToolBar& toolbar(){ return toolBar1; }
  362.   protected:
  363.     virtual bool command(ICommandEvent& event);
  364.     virtual bool windowResize(IResizeEvent& event);
  365.   private:
  366.     DrawingArea         drawingArea;                  // the drawing space
  367.     IToolBar            toolBar1;                     // the tool bar
  368.     IMenuBar            menuBar;                      // the information (help) text
  369.     IStaticText         infoText;                     // the flyover text control
  370.     unsigned long       lastPenTypeId;                // used to unmark menu items
  371.     unsigned long       lastPenWidthId;               // ect.
  372.     unsigned long       lastDrawOperationId;
  373.     int                 frameX,frameY,fillX,fillY;    // color table indexes
  374.     int                 canvasX,canvasY;
  375.     int                 bframeX,bframeY,bfillX,bfillY;
  376. #define kNumberOfButtons  16
  377.     IToolBarButton      *buttonArray[kNumberOfButtons];             // the tool bar buttons
  378.     IToolBarButton      *lastButton;                  // the last tool bar button used
  379.     int                 groupButtIndex;               // determines where to split the tool bar
  380.  
  381. };
  382.  
  383. #endif
  384.  
  385. #endif
  386.