00001 // $Id: penedit.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 pen edit header file, providing operations used by the pen tool 00099 // Created by Mike on 25/9/94 00100 00101 00102 #ifndef INC_PENEDIT 00103 #define INC_PENEDIT 00104 00105 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "stockcol.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 00108 // #include "pentool.h" 00109 00110 #define OPTOKEN_PENHANDLES _T("PenHandles") 00111 #define OPTOKEN_PENCREATEINTERNAL _T("CreatePenPoint") 00112 #define OPTOKEN_PENEDITINTERNAL _T("EditPenPoint") 00113 #define OPTOKEN_PENCREATEPATH _T("CreatePenPath") 00114 #define OPTOKEN_PENADDELEMENT _T("AddPenElement") 00115 #define OPTOKEN_PENCLOSEPATH _T("ClosePenPath") 00116 00117 #define OPTOKEN_ADDPATH _T("AddPath") 00118 #define OPTOKEN_ADDNEWPATH _T("AddNewPath") 00119 #define OPTOKEN_ADDPATHTOPATH _T("AddPathToPath") 00120 #define OPTOKEN_CLOSEPATHWITHPATH _T("ClosePathWithPath") 00121 00122 00123 // define some types to act as return parameters. These tell a calling 00124 // do function what type of endop execute to call 00125 enum ExecuteType { 00126 ExeNone, 00127 ExeInclusive, 00128 ExeExclusive 00129 }; 00130 00131 00132 /******************************************************************************************** 00133 00134 > class HandleFlags 00135 00136 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00137 Created: 5/10/94 00138 Purpose: Used to determin what to do when rendering drag handles. ie which handles 00139 should be rendered and how they relate to the drag mouse coord. 00140 00141 ********************************************************************************************/ 00142 00143 class HandleFlags 00144 { 00145 public: 00146 HandleFlags(BOOL rTrackEnd = TRUE, 00147 BOOL rGhostEnd = TRUE, 00148 BOOL TrackPtMoves = TRUE, 00149 BOOL GhostPtMoves = TRUE, 00150 BOOL TrackPtSpins = FALSE, 00151 BOOL GhostPtSpins = FALSE); 00152 00153 BYTE RenderTrackEnd : 1; 00154 BYTE RenderGhostEnd : 1; 00155 BYTE TrackPointMoves : 1; 00156 BYTE GhostPointMoves : 1; 00157 BYTE TrackPointSpins : 1; 00158 BYTE GhostPointSpins : 1; 00159 BYTE Spare1 : 1; 00160 BYTE Spare2 : 1; 00161 }; 00162 00163 00164 00165 /******************************************************************************************** 00166 00167 > class WobbleFlags 00168 00169 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00170 Created: 5/10/94 00171 Purpose: Used to determin what to wobble when recalculating curve control points 00172 during a drag. The flags affect which handles around a curve endpoint are 00173 repositioned. 00174 00175 ********************************************************************************************/ 00176 00177 class WobbleFlags 00178 { 00179 public: 00180 WobbleFlags(BOOL pSister = FALSE, 00181 BOOL pBrother = TRUE, 00182 BOOL nBrother = FALSE, 00183 BOOL nSister = FALSE); 00184 00185 BYTE PrevSister : 1; 00186 BYTE PrevBrother : 1; 00187 BYTE NextBrother : 1; 00188 BYTE NextSister : 1; 00189 }; 00190 00191 00192 /******************************************************************************************** 00193 00194 > class ControlPts 00195 00196 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00197 Created: 5/10/94 00198 Purpose: 00199 00200 ********************************************************************************************/ 00201 00202 class ControlPts 00203 { 00204 public: 00205 ControlPts(); 00206 ~ControlPts(); 00207 00208 public: 00209 DocCoord HndClick; 00210 DocCoord HndDrag; 00211 Spread* pHndSpread; 00212 }; 00213 00214 00215 00216 00217 /******************************************************************************************** 00218 00219 > class OpPenHandles : public Operation 00220 00221 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00222 Created: 26/9/94 00223 Purpose: This operation simply provides functions for other operations to use. 00224 It is not intended to be used as an operation in its own right. Most 00225 useful pen classes are derived from this. 00226 00227 ********************************************************************************************/ 00228 00229 class OpPenHandles : public Operation 00230 { 00231 00232 CC_DECLARE_DYNCREATE(OpPenHandles) 00233 00234 public: 00235 OpPenHandles(); 00236 00237 protected: 00238 void RenderHandles(); 00239 void UpdateHandles( RenderRegion* ); 00240 DocRect GetHandlesRect(); 00241 void RecalcHandles(DocCoord, BOOL); 00242 void SetDragHandles(HandleFlags, DocCoord, DocCoord, DocCoord, Spread* ); 00243 void ChangeTrackHandle(DocCoord, BOOL); 00244 DocCoord GetTrackHandle() const; 00245 DocCoord GetGhostHandle() const; 00246 DocCoord GetMidHandle() const; 00247 DocCoord CalcGhostEnd(DocCoord start, DocCoord end) const; 00248 void RenderTestRect( DocRect, Spread*, StockColour ); 00249 BOOL HasMouseMoved(DocCoord& OriginalPoint, DocCoord& PointerPos, double threshold=2); 00250 00251 HandleFlags Hflags; // set some flags to control the handle positions 00252 00253 DocCoord StartMousePos; // first click position 00254 DocCoord CurrentMousePos; // follow the mouse around 00255 Spread* StartSpread; // first click spread 00256 00257 private: 00258 void SetHandleEnds(DocCoord, DocCoord, DocCoord); 00259 00260 DocCoord TrackEnd; // end that follows the mouse usually 00261 DocCoord MidPoint; 00262 DocCoord GhostEnd; // other end 00263 00264 00265 }; 00266 00267 00268 00269 /******************************************************************************************** 00270 00271 > class OpPenDragBlobs : public OpPenHandles 00272 00273 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00274 Created: 26/9/94 00275 Purpose: This op class is defined as a base class only. It provides common dragging 00276 functionality which is inherited by create and edit pen classes. 00277 00278 ********************************************************************************************/ 00279 00280 class OpPenDragBlobs : public OpPenHandles 00281 { 00282 00283 CC_DECLARE_DYNCREATE(OpPenDragBlobs) 00284 00285 public: 00286 OpPenDragBlobs(); 00287 BOOL DoPenDragBlobs(); 00288 virtual void DragPointerMove(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL bSolidDrag); 00289 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00290 virtual void RenderDragBlobs( DocRect, Spread* , BOOL bSolidDrag); 00291 }; 00292 00293 00294 00295 /******************************************************************************************** 00296 00297 > class OpPenCreateInternal : public OpPenDragBlobs 00298 00299 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00300 Created: 27/9/94 00301 Purpose: This operation is started by the pen tool when it receives a click on the 00302 document with no previous internal or external state set. ie the pen tool 00303 is not holding a moveto element inside iteslf from a previous click and there 00304 are no selected endpoints to add to. 00305 00306 ********************************************************************************************/ 00307 00308 class OpPenCreateInternal : public OpPenDragBlobs 00309 { 00310 00311 CC_DECLARE_DYNCREATE(OpPenCreateInternal) 00312 00313 public: 00314 OpPenCreateInternal(); 00315 static BOOL Init(); 00316 static OpState GetState(String_256*, OpDescriptor*); 00317 void DoPenCreateInternal( DocCoord, Spread*, ControlPts*); 00318 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00319 00320 private: 00321 ControlPts* pUserHandles; // keep a pointer passed in by the caller 00322 00323 }; 00324 00325 00326 /******************************************************************************************** 00327 00328 > class OpPenEditInternal : public OpPenDragBlobs 00329 00330 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00331 Created: 27/9/94 00332 Purpose: This operation is started by the pen tool when it receives a click over its 00333 internal moveto point. The point will be converted into a dragto if a drag 00334 occurs. 00335 00336 ********************************************************************************************/ 00337 00338 class OpPenEditInternal : public OpPenDragBlobs 00339 { 00340 00341 CC_DECLARE_DYNCREATE(OpPenEditInternal) 00342 00343 public: 00344 OpPenEditInternal(); 00345 static BOOL Init(); 00346 static OpState GetState(String_256*, OpDescriptor*); 00347 void DoPenEditInternal(ControlPts*); 00348 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00349 00350 private: 00351 ControlPts* pUserHandles; // keep a pointer passed in by the caller 00352 00353 }; 00354 00355 00356 00357 /******************************************************************************************** 00358 00359 > class OpPenEditPath : public OpPenHandles 00360 00361 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00362 Created: 29/9/94 00363 Purpose: This operation is started by the pen tool when it receives a click on a 00364 document and needs to create a new path. The idea is, it will drag edit 00365 a path until such time as the user lets go of the mouse. and then add the 00366 path to the tree. The operation handles the internals of rendering the 00367 eor path. 00368 00369 ********************************************************************************************/ 00370 00371 class OpPenEditPath : public OpPenHandles 00372 { 00373 00374 CC_DECLARE_DYNCREATE(OpPenEditPath) 00375 00376 public: 00377 OpPenEditPath(); 00378 static BOOL Init(); 00379 static OpState GetState(String_256*, OpDescriptor*); 00380 BOOL DoPenDragPath(); 00381 virtual void DragPointerMove(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL bSolidDrag); 00382 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00383 virtual void RenderDragBlobs(DocRect, Spread*, BOOL bSolidDrag); 00384 00385 protected: 00386 DocRect GetBoundingRect(); // return the bounding rect of blobs and path 00387 void ConvertToLine(const INT32 index); // convert the edited curve element to a line 00388 void RemoveRotateEnd(const INT32 index); 00389 BOOL InsertBezier(DocCoord pt1, DocCoord pt2, DocCoord pt3); 00390 BOOL InsertCurvedLine(DocCoord pt1, DocCoord pt2); 00391 BOOL InsertGhostedBezier(DocCoord pt1, DocCoord pt2, DocCoord pt3); 00392 BOOL ConvertPathEnd(Path* pDocPath); 00393 void SetWobbleIndex(WobbleFlags wibble, const INT32 index); 00394 void WobbleCoords(); 00395 00396 Path* pEditPath; // keep track of edit path 00397 INT32 WobbleIndex; // index of element being dragged 00398 WobbleFlags Wobble; // which controls on the edit curve do we wobble? 00399 00400 }; 00401 00402 00403 /******************************************************************************************** 00404 00405 > class OpPenCreatePath : public OpPenEditPath 00406 00407 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00408 Created: 29/9/94 00409 Purpose: This op is concerned with creating a new path in the tree. It is derived 00410 from OpPenEditPath, which handles all the dragging and redraw of a new 00411 path element. This op will use 00412 00413 ********************************************************************************************/ 00414 00415 class OpPenCreatePath : public OpPenEditPath 00416 { 00417 00418 CC_DECLARE_DYNCREATE(OpPenCreatePath) 00419 00420 public: 00421 OpPenCreatePath(); 00422 static BOOL Init(); 00423 static OpState GetState(String_256*, OpDescriptor*); 00424 void DoPenCreatePath(ControlPts*, DocCoord, Spread*, Path*); 00425 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00426 00427 private: 00428 DocCoord Handle0; // control handles of previous path element. 00429 DocCoord Handle1; 00430 00431 }; 00432 00433 00434 /******************************************************************************************** 00435 00436 > class OpPenAddElement : public OpPenEditPath 00437 00438 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00439 Created: 30/9/94 00440 Purpose: Given a path in the tree with a selected end point, this operation will 00441 control the creation of a new element (through clicks and drags), at the end 00442 of the path. It is derived from OpPenEditPath which controls all the eoring 00443 of path elements such as blobs and lines. 00444 00445 ********************************************************************************************/ 00446 00447 class OpPenAddElement : public OpPenEditPath 00448 { 00449 00450 CC_DECLARE_DYNCREATE(OpPenAddElement) 00451 00452 public: 00453 OpPenAddElement(); 00454 static BOOL Init(); 00455 static OpState GetState(String_256*, OpDescriptor*); 00456 void DoPenAddElement(NodePath*, INT32, DocCoord, Spread*, Path*); 00457 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00458 00459 private: 00460 NodePath* pEditNode; // keep track of the node we are editing in the document 00461 INT32 EditIndex; 00462 }; 00463 00464 00465 00466 /******************************************************************************************** 00467 00468 > class OpPenClosePath : public OpPenEditPath 00469 00470 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00471 Created: 4/10/94 00472 Purpose: This op controls the closing of an open path. It performs the eoring of path 00473 elements a blobs during a click or drag action. 00474 It is primarily used by the pen tool an is brought into being when a click 00475 occurs over the startpoint of a path, having a selected endpoint. 00476 00477 ********************************************************************************************/ 00478 00479 class OpPenClosePath : public OpPenEditPath 00480 { 00481 00482 CC_DECLARE_DYNCREATE(OpPenClosePath) 00483 00484 public: 00485 OpPenClosePath(); 00486 static BOOL Init(); 00487 static OpState GetState(String_256*, OpDescriptor*); 00488 void DoPenClosePath(NodePath*, INT32, Spread*, Path*); 00489 virtual void DragPointerMove(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL bSolidDrag); 00490 virtual void DragFinished(DocCoord Pos, ClickModifiers Mods, Spread* pSpread, BOOL Success, BOOL bSolidDrag); 00491 00492 private: 00493 BOOL AddFirstElement(Spread* pSpread); 00494 00495 NodePath* pEditNode; // keep track of the node we are editing in the document 00496 INT32 EditIndex; 00497 BOOL OnMoveto; 00498 00499 INT32 NumElements; 00500 BOOL FirstDrag; 00501 WobbleFlags FirstWFlags; 00502 HandleFlags FirstHFlags; 00503 00504 }; 00505 00506 00507 /******************************************************************************************** 00508 00509 > class OpAddPath : public SelOperation 00510 00511 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00512 Created: 7/10/94 00513 Purpose: The base class for various addpath operations. This is not really an 00514 operation in its own right as it does not provide an init and getstate 00515 function. Its use is to provide common functions required by distinct 00516 addpath operations. 00517 00518 ********************************************************************************************/ 00519 00520 class OpAddPath : public SelOperation 00521 { 00522 00523 CC_DECLARE_DYNCREATE(OpAddPath) 00524 00525 public: 00526 OpAddPath(); 00527 00528 protected: 00529 ExecuteType AugmentPathWithPath(Path*, NodePath*, INT32); 00530 ActionCode DeselectPoint(NodePath* pDestNode, INT32 position); 00531 ActionCode DeselectHandle(NodePath* pDestNode, INT32 position); 00532 00533 }; 00534 00535 00536 00537 /******************************************************************************************** 00538 00539 > class OpAddNewPath : public OpAddPath 00540 00541 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00542 Created: 30/9/94 00543 Purpose: This op actually adds a new path to the current document. The path has 00544 been created and edited with OpPenCreatePath() which will handle EOR drawing 00545 It can now be instantiated as a physical object by this op. 00546 00547 ********************************************************************************************/ 00548 00549 class OpAddNewPath : public OpAddPath 00550 { 00551 00552 CC_DECLARE_DYNCREATE(OpAddNewPath) 00553 00554 public: 00555 OpAddNewPath(); 00556 static BOOL Init(); 00557 static OpState GetState(String_256*, OpDescriptor*); 00558 void GetOpName(String_256* OpName); 00559 void DoAddNewPath(Path* pAddPath, Spread* pSpread); 00560 }; 00561 00562 00563 /******************************************************************************************** 00564 00565 > class OpAddPathToPath : public OpAddPath 00566 00567 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00568 Created: 3/9/94 00569 Purpose: This op will add an element to an existing path within the tree. The new 00570 element and context path should be passed into the do function as parameters. 00571 00572 ********************************************************************************************/ 00573 00574 class OpAddPathToPath : public OpAddPath 00575 { 00576 00577 CC_DECLARE_DYNCREATE(OpAddPathToPath) 00578 00579 public: 00580 OpAddPathToPath(); 00581 static BOOL Init(); 00582 static OpState GetState(String_256*, OpDescriptor*); 00583 void GetOpName(String_256* OpName); 00584 void DoAddPathToPath(NodePath* pDestinNode, Path* pAddPath, INT32 index); 00585 00586 }; 00587 00588 00589 /******************************************************************************************** 00590 00591 > class OpClosePathWithPath : public OpAddPath 00592 00593 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00594 Created: 7/10/94 00595 Purpose: This op deals with a destination path being edited, and a source path which 00596 may be the result of a drag edit operation. 00597 The idea is that the op will take the components of the source path and add 00598 them in a deterministic way to the destination path, resulting in a closed 00599 destination path. 00600 The source path is assumed to have either 1 or 2 elements in it. The first 00601 element will be added to the end of the destination path and act as a 00602 closing piece. The second element of the source path will affect the 00603 first element in the destination path. If both elements match in type, ie 00604 are two curves, then the none end control handles of the source will be 00605 copied to the destination. 00606 This op as can be seen is rather specific, and is used by the pen tool to 00607 close an open path. Imagine clicking on the first control point of a path 00608 and draging out control handles. The handles will affect the previous and 00609 next elements of the path. The previous being a close element and the next 00610 being the first element of the path. Hence the need for this strange op. 00611 00612 ********************************************************************************************/ 00613 00614 class OpClosePathWithPath : public OpAddPath 00615 { 00616 00617 CC_DECLARE_DYNCREATE(OpClosePathWithPath) 00618 00619 public: 00620 OpClosePathWithPath(); 00621 static BOOL Init(); 00622 static OpState GetState(String_256*, OpDescriptor*); 00623 void GetOpName(String_256* OpName); 00624 void DoClosePathWithPath(NodePath* pDestinNode, Path* pAddPath, INT32 index); 00625 00626 }; 00627 00628 00629 00630 #endif