beztool.h

Go to the documentation of this file.
00001 // $Id: beztool.h 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // The Bezier Tool
00099 // Created by Jim on 31/3/94
00100 // Based on the freehand tool
00101 
00102 
00103 
00104 #ifndef INC_BEZTOOL
00105 #define INC_BEZTOOL
00106 
00107 
00108 //#include "tool.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "doccoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "wrkrect.h"
00112 //#include "binds.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "rectangl.h"
00114 #include "rsmooth.h"
00115 
00116 class NodePath;
00117 class Cursor;
00118 class BezierTool;
00119 class Document;
00120 class NodeBlend;
00121 //class BezToolInfoBarOp;
00122 
00123 #define OPTOKEN_BEZTOOL _T("BezierTool")
00124 
00125 /*
00126 < clickeffect
00127 < NewPath
00128 < OnPoint
00129 < AddSegment
00130 < ReshapeLine
00131 
00132 Comment:    clickeffect is an enum used by the click and the mouse move code in the 
00133             bezier tool. The routine called in these events will say what a click should 
00134             do - either start a new path, click on an existing point, add a segment to a line, 
00135             reshape a segment of a line or close the path.
00136 
00137 Possible values are:    NewPath
00138                         OnPoint
00139                         AddSegment
00140                         ReshapeLine
00141                         ClosePath
00142 */
00143     enum clickeffect
00144     {
00145         NewPath,
00146         OnPoint,
00147         AddSegment,
00148         ReshapeLine,
00149         ClosePath
00150     };
00151 
00152 /********************************************************************************************
00153 
00154 >   class BezToolInfoBarOp : public InformationBarOp
00155 
00156     Author:     Jim_Lynn (Xara Group Ltd) <camelotdev@xara.com>
00157     Created:    16/8/94
00158     Purpose:    Class for handling the bezier tool's information bar.
00159 
00160 ********************************************************************************************/
00161 
00162 class BezToolInfoBarOp : public InformationBarOp
00163 {
00164     friend class BezierTool;
00165     CC_DECLARE_DYNCREATE( BezToolInfoBarOp )  
00166 public:
00167     BezToolInfoBarOp(ResourceID r = _R(IDD_BEZTOOLBAR)) {DlgResID = r;}             // Dummy default constructor for DYNCREATE
00168 
00169     BOOL CheckClassData ();             // arrows controls are enabled even when there disabled!
00170                                         // fix for this ....
00171     
00172     MsgResult   Message(Msg* Msg);  // All messages to the info bar come through here
00173 
00174     void        InitControls();     // Initialises the controls in the info bar
00175     void        EnableControls();   // Enables/disables the controls in the info bar
00176 
00177     virtual void UpdateState(); // Overrides the empty function in InformationBarOp
00178  
00179     // DY this will be relocated elsewhere at some point
00180     NodeBlend* GetBlendOnCurve() ;
00181 
00182 protected:
00183     void UpdateCurveButton();
00184     void UpdateLineButton();
00185     void UpdateReversePathsButton ();
00186     void UpdateSmoothButton();
00187     void UpdateCuspButton();
00188     void UpdateTextIndicator();
00189     void UpdateStartArrowButton();
00190     void UpdateEndArrowButton();
00191     void UpdatePositionFields(BOOL ForceUpdate = FALSE, BOOL ScanForCurrent = TRUE);
00192     void UpdateEditFieldsFromPath(Path* pPath, Spread* pSpread, INT32 Index, BOOL ForceUpdate, BOOL EnableData[18]);
00193     void HandleClickOnCurveButton();
00194     void HandleClickOnLineButton();
00195     void HandleClickOnReversePathButton();
00196     void HandleClickOnSmoothButton();
00197     void HandleClickOnCuspButton(BOOL WithConstrain);
00198     void HandleClickOnStartArrowButton();
00199     void HandleClickOnEndArrowButton();
00200     BOOL HandleBumpClick(CGadgetID GadgetID);
00201     BOOL HandleEditFieldCommit(CGadgetID CommitField);
00202     void ScanPointsForToggleSmooth(BOOL MakeSmooth, BOOL WithConstrain);
00203     BOOL ScanPointsForJoins(BOOL* AllSmooth, BOOL* AllCusp);
00204     BOOL SetEditLength(CGadgetID gid, INT32 nValue, Spread* pSpread, BOOL PaintNow = FALSE);
00205     BOOL SetEditPosition(CGadgetID gid, INT32 nValue, Spread* pSpread, BOOL PaintNow = FALSE);
00206     BOOL SetEditPosition(CGadgetID gidX, CGadgetID gidY, DocCoord loc, Spread* pSpread, BOOL PaintNow = FALSE);
00207     INT32 GetCurrentIndex();
00208     double GetAngle(DocCoord Origin, DocCoord Offset);
00209 
00210     BOOL HandleLAFieldCommit(CGadgetID, CGadgetID, CGadgetID, DocCoord, DocCoord, DocCoord*);
00211     BOOL HandleCoordFieldCommit(UINT32 UpperID, UINT32 LowerID, INT32 Index, DocCoord* NewPos, BOOL* Valid);
00212 
00213     INT32 GetPrevLineIndex(Path* pPath, INT32 Index);
00214     INT32 GetNextLineIndex(Path* pPath, INT32 Index);
00215 
00216     MsgResult InfobarMessage(Msg* Message) ;
00217 
00218 public:
00219     BezierTool* pBezTool;       // Pointer to instance of bezier tool
00220 
00221 private:
00222     INT32       CurrentIndex;
00223     NodePath*   CurrentNodePath;
00224     Path*       CurrentInkPath;
00225     Spread*     CurrentSpread;
00226     BOOL        IgnoreNextUpdate;
00227     INT32       LastShownPrevLength;
00228     INT32       LastShownNextLength;
00229 
00230 };
00231     
00232 
00233 /********************************************************************************************
00234 >   class BezierTool : public Tool_v1
00235 
00236     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    20/7/93
00238     Purpose:    This class handles the Free Hand Tool that is used to draw lines that follow
00239                 the path of the Mouse Pointer.
00240 ********************************************************************************************/
00241 
00242 class CCAPI BezierTool : public Tool_v1
00243 {
00244     friend class BezToolInfoBarOp;
00245 
00246 // Give my name in memory dumps
00247 CC_DECLARE_MEMDUMP(BezierTool);
00248 
00249 public:
00250     enum CurrentMode {New, Add, Change};
00251 
00252     BezierTool();
00253     ~BezierTool();
00254     BOOL Init();
00255     void Describe(void* InfoPtr);
00256     UINT32 GetID() { return TOOLID_BEZTOOL; };
00257     
00258     // Event Handlers
00259     void SelectChange(BOOL);
00260     void OnClick( DocCoord, ClickType, ClickModifiers, Spread* );
00261 
00262     virtual void RenderToolBlobs(Spread*, DocRect*);
00263 
00264     void HandleInfoBarMessage(CDlgMessage DlgMsg, CGadgetID Gadget);
00265 
00266     void OnMouseMove(DocCoord, Spread*, ClickModifiers);
00267     BOOL OnKeyPress(KeyPress*);
00268     
00269     void SetMoveTo(DocCoord MovePos, Spread* pSpread, Document* pDoc);
00270     void ClearMoveTo();
00271     BOOL GetMoveTo(Spread** ppSpread, DocCoord* pCoord, Document** ppDoc);
00272 
00273     void SetModeFlag();
00274 
00275     BOOL GetStatusLineText(String_256* ptext, Spread* pSpread, DocCoord DocPos, ClickModifiers ClickMods);
00276     void GenerateStatusLineText(String_256* ptext, Spread* pSpread, DocCoord DocPos, ClickModifiers ClickMods);
00277 
00278 protected:
00279     // Moving selected points on paths functions
00280     BOOL CyclePathPoints(BOOL Fowards);
00281     BOOL HomePathPoints();
00282     BOOL EndPathPoints();
00283 
00284     BOOL AutoClosePaths();
00285 
00286     void RemoveFloater(DocCoord* FloatPos, Spread* FloatSpread, Document* pDoc);
00287 
00288 protected:
00289     // retro smoothing functions.
00290     void RetroSmoothChanging(double Smooth);
00291     void RetroSmoothFinished();
00292     void RetroSmoothSet(INT32 percent, BOOL Enabled);
00293     void RetroSmoothInvalidate();
00294     void UpdateRetroSlider(Path* pPath);
00295     void ResetRetroSlider();
00296     Node* OneNodePathSelected();
00297 
00298 protected:
00299     static  TCHAR* FamilyName;  // The Tools Family Name
00300     static  TCHAR* ToolName;        // The Tool Name
00301     static  TCHAR* Purpose;     // What the tool is for
00302     static  TCHAR* Author;      // Who wrote it
00303 
00304     // The coord of the initial click
00305     DocCoord StartPos;
00306     Spread  *StartSpread;
00307 
00308     // The tools cursor
00309     Cursor* pcMoveBezCursor;                // Move a bezier point
00310     Cursor* pcReshapeLineCursor;            // Reshape a line segment
00311     Cursor* pcNewPathCursor;                // Add a new path
00312     Cursor* pcAddPathCursor;                // Add to an existing path
00313     Cursor* pcClosePathCursor;              // Close a path
00314     Cursor* MyCurrentCursor;                // so I don't flip cursor too often
00315     void    ChangeCursor(Cursor* cursor);   // function to change cursor
00316     INT32   CurrentCursorID;
00317 
00318     // When the tool gets a single click in space and there's no endpoint selected,
00319     // it has to start a new path, but instead of doing what ArtWorks did and inserting
00320     // a real node in the tree, this tool will do it by using tool blobs.
00321 
00322     BOOL    FloatingEndpoint;   // TRUE if there's a single MoveTo point floating about
00323     Document* MoveToDoc;        // Document the floating endpoint is in.
00324     DocCoord MoveToPoint;       // Coords of floating endpoint if present
00325     Spread*  MoveToSpread;      // Which spread the MoveTo is on
00326 
00327     // A routine which tells me what the effect of clicking will be at any point
00328     clickeffect DetermineClickEffect(DocCoord PointerPos, Spread* pSpread,
00329                                     NodeRenderableInk** ReturnNode, INT32* ReturnPosition,
00330                                     INT32* NumSelectedPaths, INT32* NumSelectedPoints );
00331 
00332     // A routine which returns the pointer to the node path we're to edit
00333     NodePath* FindEditablePath(Node* pSelected);
00334 
00335     static BezToolInfoBarOp*    pBezToolInfoBarOp;
00336 
00337     
00338     static BOOL CreateCurve;    // Flag that tells the tool to create either a line or a curve
00339     static BOOL CreateCusp;     // Flag that tells the tool to create either smooth or cusps
00340 
00341     RetroSmooth* pSmooth;       // pointer to the smoothing technology.
00342     BOOL RetroFlag;             // true if we've found a retro smooth path
00343     Node* pRetroNode;           // holds a pointer to the node we're interrested in.
00344     Spread* pRetroSpread;       // holds a pointer to the retro nodes spread.
00345 
00346     BOOL DontDrawOnClearMoveTo;
00347     
00348     CurrentMode CurrentToolMode;
00349 }; 
00350 
00351 
00352 
00353 /********************************************************************************************
00354 
00355 >   class BezToolInfoBarOpCreate : public BarCreate
00356 
00357     Author:     Jim_Lynn (Xara Group Ltd) <camelotdev@xara.com>
00358     Created:    16/8/94
00359     Purpose:    Class for creating BezToolInfoBarOps.
00360                 Derived classes of BarCreate are used by DialogBarOp::ReadBarsFromFile()
00361 
00362 ********************************************************************************************/
00363 
00364 class BezToolInfoBarOpCreate : public BarCreate
00365 {
00366 public:
00367     DialogBarOp* Create() { return (new BezToolInfoBarOp); }
00368 };
00369 
00370 
00371 #endif      //INC_BEZTOOL

Generated on Sat Nov 10 03:47:31 2007 for Camelot by  doxygen 1.4.4