OpPenClosePath Class Reference

This op controls the closing of an open path. It performs the eoring of path elements a blobs during a click or drag action. It is primarily used by the pen tool an is brought into being when a click occurs over the startpoint of a path, having a selected endpoint. More...

#include <penedit.h>

Inheritance diagram for OpPenClosePath:

OpPenEditPath OpPenHandles Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpPenClosePath ()
 OpPenClosePath constructor.
void DoPenClosePath (NodePath *, INT32, Spread *, Path *)
virtual void DragPointerMove (DocCoord Pos, ClickModifiers Mods, Spread *pSpread, BOOL bSolidDrag)
 This is called every time the mouse moves, during a drag.
virtual void DragFinished (DocCoord Pos, ClickModifiers Mods, Spread *pSpread, BOOL Success, BOOL bSolidDrag)
 This is called when a drag operation finishes.

Static Public Member Functions

static BOOL Init ()
 OpPenClosePath initialiser method.
static OpState GetState (String_256 *, OpDescriptor *)
 For finding the OpPenClosePath's state.

Private Member Functions

BOOL AddFirstElement (Spread *pSpread)
 This routine adds another element to the eor path. When closing a path the user can either click or drag on the start point of a path. Now, we dont really want to render what will become a smoothed start curve along with the close element, if just a click has occured. So we wait for the first DragPointerMove call and use this function to create the second element. This basically looks much neater on screen.

Private Attributes

NodePathpEditNode
INT32 EditIndex
BOOL OnMoveto
INT32 NumElements
BOOL FirstDrag
WobbleFlags FirstWFlags
HandleFlags FirstHFlags

Detailed Description

This op controls the closing of an open path. It performs the eoring of path elements a blobs during a click or drag action. It is primarily used by the pen tool an is brought into being when a click occurs over the startpoint of a path, having a selected endpoint.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/10/94

Definition at line 479 of file penedit.h.


Constructor & Destructor Documentation

OpPenClosePath::OpPenClosePath  ) 
 

OpPenClosePath constructor.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/10/94
See also:
-

Definition at line 1984 of file penedit.cpp.

01985 {
01986     NumElements = 0;
01987     FirstDrag = TRUE;
01988 }


Member Function Documentation

BOOL OpPenClosePath::AddFirstElement Spread pSpread  )  [private]
 

This routine adds another element to the eor path. When closing a path the user can either click or drag on the start point of a path. Now, we dont really want to render what will become a smoothed start curve along with the close element, if just a click has occured. So we wait for the first DragPointerMove call and use this function to create the second element. This basically looks much neater on screen.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/10/94
Parameters:
[INPUTS] 

Definition at line 2231 of file penedit.cpp.

02232 {
02233 
02234     // Calculate the first control point on the forward bezier.
02235     // This is calculated from the last element inserted into the
02236     // edit curve, ie the last control points ghost point.
02237 
02238     Path* pDocPath = &(pEditNode->InkPath);
02239 
02240     // Get the arrays for this path
02241     PathFlags* Flags  = pDocPath->GetFlagArray();
02242     PathVerb*  Verbs  = pDocPath->GetVerbArray();
02243     DocCoord*  Coords = pDocPath->GetCoordArray();
02244 
02245     DocCoord* EditCoords = pEditPath->GetCoordArray();
02246 
02247     INT32 Associate = EditIndex;
02248     if (OnMoveto)
02249         Associate++;
02250 
02251     PathVerb AssociateV = Verbs[Associate] & ~PT_CLOSEFIGURE;
02252 
02253     DocCoord Control;
02254     Control.x = EditCoords[3].x - (EditCoords[2].x - EditCoords[3].x);
02255     Control.y = EditCoords[3].y - (EditCoords[2].y - EditCoords[3].y);
02256 
02257     BOOL ok = TRUE;
02258             
02259     switch (AssociateV)
02260     {
02261         case PT_BEZIERTO:
02262         {
02263             FirstHFlags.RenderTrackEnd = TRUE;
02264             FirstHFlags.TrackPointMoves = FALSE;
02265             FirstHFlags.TrackPointSpins = TRUE;
02266             FirstWFlags.NextBrother = TRUE;
02267 
02268             PathFlags tempflags = Flags[Associate];
02269             if (OnMoveto)
02270                 ok = pEditPath->InsertCurveTo(Control, Coords[Associate+1], Coords[Associate+2], &tempflags);
02271             else
02272                 ok = pEditPath->InsertCurveTo(Control, Coords[Associate-2], Coords[Associate-3], &tempflags);
02273 
02274             NumElements++;
02275         }
02276         break;
02277 
02278         case PT_LINETO:
02279         {
02280             FirstHFlags.RenderTrackEnd = FALSE;
02281             FirstHFlags.TrackPointMoves = FALSE;
02282             FirstHFlags.TrackPointSpins = FALSE;
02283         }
02284         break;
02285     }
02286 
02287     // if we've created the element, set the wobble flags
02288     if (ok) 
02289     {
02290         SetWobbleIndex(FirstWFlags,3);
02291         if (OnMoveto)
02292             SetDragHandles(FirstHFlags, Coords[EditIndex], Coords[EditIndex+1], EditCoords[2], pSpread);
02293         else
02294             SetDragHandles(FirstHFlags, Coords[EditIndex], Coords[EditIndex-1], EditCoords[2], pSpread);
02295     }
02296 
02297     return ok;
02298 }

void OpPenClosePath::DoPenClosePath NodePath pNode,
INT32  ClickIndex,
Spread pSpread,
Path pPath
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/10/94
Parameters:
pNode = pointer to nodepath in document to be edited [INPUTS] ClickIndex = index of element where click occured. pSpread = pointer to spread where first click occured pPath = pointer to path to edit
- [OUTPUTS]
Returns:
-

Errors: failandexecute will be called if the operation fails in some way, most likely when no memory is available.

Definition at line 2073 of file penedit.cpp.

02077 {   
02078 
02079     BOOL ok = FALSE;
02080     pEditPath = pPath;
02081     pEditNode = pNode;
02082     EditIndex = ClickIndex;
02083 
02084     Path* pDocPath = &(pNode->InkPath);
02085 
02086     // find the extreems of this sub path. 
02087     INT32 lasti = ClickIndex;
02088     INT32 firsti = ClickIndex;
02089     pDocPath->FindEndElOfSubPath(&lasti);
02090     pDocPath->FindStartOfSubPath(&firsti);
02091 
02092     // ok the click could have occured over the begining of a subpath
02093     // or over the end of a subpath. The verb at ClickIndex should tell
02094     // us this.
02095 
02096     if ((lasti<=0) || (lasti<=firsti))
02097     {
02098         FailAndExecute();
02099         End();
02100         return;
02101     }
02102 
02103     OnMoveto = (ClickIndex == firsti);
02104 
02105     // Get the arrays for the destination path
02106     PathFlags* Flags  = pDocPath->GetFlagArray();
02107     PathVerb*  Verbs  = pDocPath->GetVerbArray();
02108     DocCoord*  Coords = pDocPath->GetCoordArray();
02109 
02110     DocCoord* EditCoords = pEditPath->GetCoordArray();
02111 
02112     // Read the final control point details
02113     PathVerb  LastV  = Verbs[lasti] & ~PT_CLOSEFIGURE;
02114     PathFlags LastF  = Flags[lasti];
02115 
02116     PathVerb  SecondV = Verbs[firsti+1] & ~PT_CLOSEFIGURE;
02117     PathFlags SecondF = Flags[firsti+1];
02118 
02119     // make sure the first index is sensible, ie offsets to a moveto
02120     if (Verbs[firsti] != PT_MOVETO)
02121     {
02122         FailAndExecute();
02123         End();
02124         return;
02125     }
02126 
02127     // dont render the track end until the pointer moves
02128     FirstHFlags.RenderTrackEnd = FALSE;
02129 
02130     // now create an element dependent on the control point type
02131 
02132     if (OnMoveto)
02133     {
02134         switch (LastV)
02135         {
02136             case PT_BEZIERTO:
02137                 if (LastF.IsRotate)
02138                     ok = InsertGhostedBezier(Coords[lasti-1], Coords[lasti], Coords[firsti]);
02139                 else
02140                 {
02141                     FirstWFlags.PrevSister = TRUE;
02142                     ok = InsertCurvedLine(Coords[lasti], Coords[firsti]);
02143                 }
02144                 NumElements++;
02145                 break;
02146         
02147             case PT_LINETO:
02148                 FirstWFlags.PrevSister = TRUE;
02149                 ok = InsertCurvedLine(Coords[lasti], Coords[firsti]);
02150                 NumElements++;
02151                 break;
02152 
02153             default:
02154                 FailAndExecute();
02155                 End();
02156                 return;
02157                 break;
02158         }
02159         if (ok)
02160             SetDragHandles(FirstHFlags, Coords[firsti], Coords[firsti], EditCoords[2], pSpread);
02161     }
02162     else
02163     {
02164         switch (SecondV)
02165         {
02166             case PT_BEZIERTO:
02167                 if (SecondF.IsRotate)
02168                     ok = InsertGhostedBezier(Coords[firsti+1], Coords[firsti], Coords[lasti]);
02169                 else
02170                 {
02171                     FirstWFlags.PrevSister = TRUE;
02172                     ok = InsertCurvedLine(Coords[firsti], Coords[lasti]);
02173                 }
02174                 NumElements++;
02175                 break;
02176         
02177             case PT_LINETO:
02178                 FirstWFlags.PrevSister = TRUE;
02179                 ok = InsertCurvedLine(Coords[firsti], Coords[lasti]);
02180                 NumElements++;
02181                 break;
02182 
02183             default:
02184                 FailAndExecute();
02185                 End();
02186                 return;
02187                 break;
02188         }
02189         if (ok)
02190             SetDragHandles(FirstHFlags, Coords[lasti], Coords[lasti], EditCoords[2], pSpread);
02191     }
02192 
02193     
02194     if (ok)
02195     {
02196         SetWobbleIndex(FirstWFlags,3);
02197         // Render the first eor version on
02198         DocRect Rect = GetBoundingRect();
02199         RenderDragBlobs(Rect, StartSpread, FALSE);
02200         // Now start the drag op on this path
02201         ok = OpPenEditPath::DoPenDragPath();
02202     }
02203 
02204     if (!ok) 
02205     {
02206         // failed to perform create so lets tidy up the path and exit
02207         pEditPath->ClearPath();
02208         FailAndExecute();
02209         End();
02210     }
02211 }   

void OpPenClosePath::DragFinished DocCoord  PointerPos,
ClickModifiers  ClickMods,
Spread pSpread,
BOOL  Success,
BOOL  bSolidDrag
[virtual]
 

This is called when a drag operation finishes.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/9/94
Parameters:
PointerPos - The position of the mouse at the end of the drag [INPUTS] ClickMods - the key modifiers being pressed Success - TRUE if the drag was terminated properly, FALSE if it was ended with the escape key being pressed
See also:
ClickModifiers

Reimplemented from OpPenEditPath.

Definition at line 2389 of file penedit.cpp.

02391 {
02392     // inform the base class to stop dragging
02393     OpPenEditPath::DragFinished( PointerPos, ClickMods, pSpread, Success, bSolidDrag);
02394 
02395     // Rub out the old EORed version of the path
02396     DocRect Rect = GetBoundingRect();
02397     RenderDragBlobs( Rect, StartSpread, bSolidDrag);
02398 
02399     if (Success)
02400     {
02401         if (!HasMouseMoved(StartMousePos,CurrentMousePos))
02402         {
02403             // if the mouse hasn't moved then we haven't edited the
02404             // first element in the path being closed, so bin our replacement
02405             // element.
02406             if (NumElements == 2)
02407             {
02408                 INT32 last = 0;
02409                 pEditPath->FindEndOfSubPath(&last);
02410                 pEditPath->DeleteFromElement(last);             
02411                 NumElements--;
02412             }
02413             ConvertPathEnd(&(pEditNode->InkPath));
02414         }
02415     }
02416     else
02417         FailAndExecute();
02418 
02419     End();
02420 }

void OpPenClosePath::DragPointerMove DocCoord  PointerPos,
ClickModifiers  ClickMods,
Spread pSpread,
BOOL  bSolidDrag
[virtual]
 

This is called every time the mouse moves, during a drag.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/9/94
Parameters:
PointerPos - The current position of the mouse in Doc Coords [INPUTS] ClickMods - Which key modifiers are being pressed
See also:
ClickModifiers

Reimplemented from OpPenEditPath.

Definition at line 2318 of file penedit.cpp.

02321 {
02322 
02323     // If drag has moved onto a different spread, convert the coord to be relative to the
02324     // original spread.
02325     if (pSpread != StartSpread)
02326         PointerPos = MakeRelativeToSpread(StartSpread, pSpread, PointerPos);
02327 
02328     // Make sure we get the grid snapping involved
02329     DocCoord SnapPos = PointerPos;
02330     DocView::SnapCurrent(pSpread,&SnapPos);
02331 
02332     if (FirstDrag)
02333     {
02334 
02335         // Rub out the old EORed version of the path and stick a new one on
02336         DocRect Rect = GetBoundingRect();
02337         RenderDragBlobs(Rect, StartSpread, bSolidDrag);
02338 
02339         if (!AddFirstElement(pSpread))
02340         {
02341             pEditPath->ClearPath();
02342             EndDrag();
02343             FailAndExecute();
02344             End();
02345             return;
02346         }
02347 
02348         Rect.IncludePoint(SnapPos);
02349 
02350         // Alter the curve drag handles
02351         ChangeTrackHandle(SnapPos, ClickMods.Constrain);
02352         
02353         // make sure we wobble all the coordinates around this control point
02354         // correctly.
02355         WobbleCoords();
02356 
02357         // Now render the blobs back on again
02358         Rect = Rect.Union(GetBoundingRect());
02359         RenderDragBlobs(Rect, StartSpread, bSolidDrag);
02360 
02361     }
02362     else
02363     {
02364         OpPenEditPath::DragPointerMove(SnapPos, ClickMods, pSpread, bSolidDrag);
02365     } 
02366 
02367     FirstDrag = FALSE;
02368 }

OpState OpPenClosePath::GetState String_256 ,
OpDescriptor
[static]
 

For finding the OpPenClosePath's state.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/10/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The state of the OpPenClosePath

Errors: -

See also:
-

Reimplemented from OpPenEditPath.

Definition at line 2042 of file penedit.cpp.

02043 {
02044     OpState OpSt;
02045     // Always enabled at the moment.
02046     return OpSt;
02047 }

BOOL OpPenClosePath::Init void   )  [static]
 

OpPenClosePath initialiser method.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/10/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the operation could be successfully initialised FALSE if no more memory could be allocated

Errors: ERROR will be called if there was insufficient memory to allocate the operation.

See also:
-

Reimplemented from OpPenEditPath.

Definition at line 2010 of file penedit.cpp.

02011 {
02012     return (RegisterOpDescriptor(0,                                     // tool ID
02013                                 _R(IDS_PENCLOSEPATHOP),                     // string resource ID
02014                                 CC_RUNTIME_CLASS(OpPenClosePath),       // runtime class for Op
02015                                 OPTOKEN_PENCLOSEPATH,                   // Ptr to token string
02016                                 OpPenClosePath::GetState,               // GetState function
02017                                 0,                                      // help ID = 0
02018                                 _R(IDBBL_PENCLOSEPATHOP),                   // bubble help ID = 0
02019                                 0                                       // resource ID = 0
02020                                 )); 
02021 
02022 }               


Member Data Documentation

INT32 OpPenClosePath::EditIndex [private]
 

Definition at line 496 of file penedit.h.

BOOL OpPenClosePath::FirstDrag [private]
 

Definition at line 500 of file penedit.h.

HandleFlags OpPenClosePath::FirstHFlags [private]
 

Definition at line 502 of file penedit.h.

WobbleFlags OpPenClosePath::FirstWFlags [private]
 

Definition at line 501 of file penedit.h.

INT32 OpPenClosePath::NumElements [private]
 

Definition at line 499 of file penedit.h.

BOOL OpPenClosePath::OnMoveto [private]
 

Definition at line 497 of file penedit.h.

NodePath* OpPenClosePath::pEditNode [private]
 

Definition at line 495 of file penedit.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:58:39 2007 for Camelot by  doxygen 1.4.4