OpScaleTrans Class Reference

This is the interactive and immediate scale operation. More...

#include <opscale.h>

Inheritance diagram for OpScaleTrans:

TransOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpScaleTrans ()
 Constructor. Does nothing.
virtual FIXED16 GetScalar ()
 Returns the Transforms idea of the equivalent scale factor for the transform. This is mainly used to help with the scaling of line widths to save them trying to extract the scale factor from the matrix.

Static Public Member Functions

static BOOL Declare ()
 Adds the operation to the list of all known operations.

Protected Member Functions

virtual void InitTransformImmediate (OpParam *)
virtual void InitTransformOnDrag (DocCoord, ClickModifiers)
 Sets up the parameters needed to build the transform matrix at the start of the drag. This base class version of this function does nothing.
virtual void UpdateTransformOnDrag (DocCoord, Spread *, ClickModifiers &)
 Does the calculations needed when the mouse moves to keep all the params needed to build the rotation matrix up to date.
virtual void BuildMatrix ()
 Builds the transform matrix required to rotate the selection about the point CentreOfRot by the required number of degrees.
virtual void ConstrainDrag (DocCoord *)
 Will constrain the mouse position to lie along rays from the centre of rotation at the constrain angle apart (45 degrees by default).
virtual void UpdateTransformBoundingData ()
 Override the base class version of this fn to ensure that new bounds are calculated and placed in the BoundingData structure.
virtual void SetStartBlob (INT32 ThisStartBlob)
 Allows the operations to know how it was started. Some operation do different things depending on if they are going vertically or horizontally and this will allow you to figure that out. Overide this function if you need to deal with this situation (ie the Shear operation). The base class version does nothing. This function is called from the DragStarted() function.

Private Member Functions

 CC_DECLARE_DYNCREATE (OpScaleTrans)

Private Attributes

FIXED16 XScaleFactor
FIXED16 YScaleFactor
INT32 UnitWidth
INT32 UnitHeight
DocCoord PointerStart
DocCoord BoundsStartPoint
INT32 StartBlob

Detailed Description

This is the interactive and immediate scale operation.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/7/94

Definition at line 120 of file opscale.h.


Constructor & Destructor Documentation

OpScaleTrans::OpScaleTrans  ) 
 

Constructor. Does nothing.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/7/93

Definition at line 137 of file opscale.cpp.

00137                           : TransOperation()
00138 {
00139     StatusHelpID = _R(IDS_SCALETRANS_STATUS1);
00140     StatusHelpID2 = _R(IDS_SCALETRANS_STATUS2);
00141 }


Member Function Documentation

void OpScaleTrans::BuildMatrix  )  [protected, virtual]
 

Builds the transform matrix required to rotate the selection about the point CentreOfRot by the required number of degrees.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/94

Reimplemented from TransOperation.

Definition at line 366 of file opscale.cpp.

00367 {
00368     // Build a matrix to scale by the correct amount and one to translate back from the origin
00369     Matrix ScaleBy(XScaleFactor, YScaleFactor);
00370     Matrix TransFromOrigin(CentreOfTrans.x, CentreOfTrans.y);
00371 
00372     // First translate the centre of scaling to the origin, then scale, then translate back
00373     Transform = Matrix(-CentreOfTrans.x, -CentreOfTrans.y);
00374     Transform *= ScaleBy;
00375     Transform *= TransFromOrigin;
00376 }

OpScaleTrans::CC_DECLARE_DYNCREATE OpScaleTrans   )  [private]
 

void OpScaleTrans::ConstrainDrag DocCoord PointerPos  )  [protected, virtual]
 

Will constrain the mouse position to lie along rays from the centre of rotation at the constrain angle apart (45 degrees by default).

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/94
Parameters:
PointerPos - The current position of the mouse that needs to be constrained [INPUTS]
PointerPos - The position of the mouse after it has been constrained [OUTPUTS]

Reimplemented from TransOperation.

Definition at line 395 of file opscale.cpp.

00396 {
00397     // Constrain the mouse movement to hoizontal, vertical or diagonal
00398     DocView::ConstrainToAngle(CentreOfTrans, PointerPos);
00399 }

BOOL OpScaleTrans::Declare  )  [static]
 

Adds the operation to the list of all known operations.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/93
Returns:
TRUE if all went OK, False otherwise

Reimplemented from TransOperation.

Definition at line 413 of file opscale.cpp.

00414 {
00415     return (RegisterOpDescriptor(0, _R(IDS_SCALETRANS), CC_RUNTIME_CLASS(OpScaleTrans),
00416                                 OPTOKEN_SCALE, TransOperation::GetState)); 
00417 }

FIXED16 OpScaleTrans::GetScalar  )  [virtual]
 

Returns the Transforms idea of the equivalent scale factor for the transform. This is mainly used to help with the scaling of line widths to save them trying to extract the scale factor from the matrix.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/01/2004
Returns:
FIXED16 value of the equivalent scale factor for the transform.

Definition at line 461 of file opscale.cpp.

00462 {
00463     // Just return the current value of the scale factor
00464     return YScaleFactor;
00465 }

void OpScaleTrans::InitTransformImmediate OpParam pParam  )  [protected, virtual]
 

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/11/94
Parameters:
pParam --- pointer an OpParam whose Param2 member is a pointer [INPUTS] to two FIXED16's that represent the scale factor for the width and height of the selction.
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from TransOperation.

Definition at line 162 of file opscale.cpp.

00163 {
00164 
00165     FIXED16* pfx = (FIXED16*) PVOID(pParam->Param2);
00166     XScaleFactor = *pfx;
00167     YScaleFactor = *(pfx + 1);
00168 
00169 
00170     if (XScaleFactor == 0)
00171         XScaleFactor = 1.0;
00172 
00173     if (YScaleFactor == 0)
00174         YScaleFactor = 1.0;
00175 
00176 }

void OpScaleTrans::InitTransformOnDrag DocCoord  PointerPos,
ClickModifiers  ClickMods
[protected, virtual]
 

Sets up the parameters needed to build the transform matrix at the start of the drag. This base class version of this function does nothing.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/94
Parameters:
PointerPos - The position of the mouse at the start of the drag [INPUTS] ClickMods - the keyboard modifiers that were active at the start of the drag

Reimplemented from TransOperation.

Definition at line 196 of file opscale.cpp.

00197 {
00198     // WEBSTER - markn 14/2/97
00199     // Rewritten so it will work when "snap to the grid" is on
00200 
00201     // Note the pointer pos at the beginning of the drag
00202     PointerStart.x = PointerPos.x;
00203     PointerStart.y = PointerPos.y;
00204 
00205     // Note the width & height of the original bounds - used to calc scale factors
00206     UnitWidth  = BoundingData.Width;
00207     UnitHeight = BoundingData.Height;
00208 
00209     // Work out which x point of the bounds to take, based on the blob that was clicked on
00210     switch (StartBlob)
00211     {
00212         case 3:
00213         case 8: BoundsStartPoint.x = BoundingData.x + BoundingData.Width;
00214                 break;
00215         case 1:
00216         case 6: BoundsStartPoint.x = BoundingData.x;
00217                 UnitWidth = -UnitWidth;                 // if low x, then we need -ve x scale factors
00218                 break;
00219 
00220         default: ERROR3("Unrecognised blob values"); break;
00221     }
00222 
00223     // Work out which x point of the bounds to take, based on the blob that was clicked on
00224     switch (StartBlob)
00225     {
00226         case 1:
00227         case 3: BoundsStartPoint.y = BoundingData.y + BoundingData.Height;
00228                 break;
00229         case 6:
00230         case 8: BoundsStartPoint.y = BoundingData.y;
00231                 UnitHeight = -UnitHeight;               // if low y, then we need -ve y scale factors
00232                 break;
00233 
00234         default: ERROR3("Unrecognised blob values"); break;
00235     }
00236 
00237     // Make sure that they are not zero
00238     if (UnitWidth==0)   UnitWidth = 1;
00239     if (UnitHeight==0)  UnitHeight = 1;
00240 
00241     // Set the scale factors to 1 (ie no scale)
00242     XScaleFactor = FIXED16(1);
00243     YScaleFactor = FIXED16(1);
00244 }

virtual void OpScaleTrans::SetStartBlob INT32  ThisStartBlob  )  [inline, protected, virtual]
 

Allows the operations to know how it was started. Some operation do different things depending on if they are going vertically or horizontally and this will allow you to figure that out. Overide this function if you need to deal with this situation (ie the Shear operation). The base class version does nothing. This function is called from the DragStarted() function.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/7/94
Parameters:
StartBlob - the Number of the blob that the operation was initiated on, [INPUTS] if applicabale. They are numbered as follows :- MonoOn 1 2 3 4 5 6 7 8 MonoOff All operations that were not started from one of the 8 blobs should use 0

Reimplemented from TransOperation.

Definition at line 145 of file opscale.h.

00145 { StartBlob = ThisStartBlob; }

void OpScaleTrans::UpdateTransformBoundingData  )  [protected, virtual]
 

Override the base class version of this fn to ensure that new bounds are calculated and placed in the BoundingData structure.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
04/9/94

Reimplemented from TransOperation.

Definition at line 432 of file opscale.cpp.

00433 {
00434 #ifndef STANDALONE
00435     if (pSelTool != NULL)
00436     {
00437 
00438         ComputeNewBounds();
00439         // Tell the tool about the current transform bounding data
00440         pSelTool->DragMove(&BoundingData);
00441     }
00442 #endif
00443 }

void OpScaleTrans::UpdateTransformOnDrag DocCoord  PointerPos,
Spread pClickSpread,
ClickModifiers ClickMods
[protected, virtual]
 

Does the calculations needed when the mouse moves to keep all the params needed to build the rotation matrix up to date.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/94
Parameters:
PointerPos - The latest position of the mouse [INPUTS] Spread* - The spread the mouse is over ClickModifiers - The click modifiers in place now

Reimplemented from TransOperation.

Definition at line 263 of file opscale.cpp.

00264 {
00265     // Make sure that the cursor does not wrap around at the edge of spreads
00266     if (pClickSpread != StartSpread)
00267         PointerPos = MakeRelativeToSpread(StartSpread, pClickSpread, PointerPos);
00268 
00269     // Snap the pointer position
00270     if (!ClickMods.Constrain)
00271         DocView::SnapSelected(pClickSpread, &PointerPos, FALSE, TRUE);
00272 
00273     // If the Adjust key is down then we should adjust the Unit sizes to compensate
00274     // for the moving centre of transform
00275     INT32 WorkingHeight = UnitHeight;
00276     INT32 WorkingWidth = UnitWidth;
00277 
00278     // if Adjust is being used, adjust the height and width so that scaling still works
00279     if (ClickMods.Adjust)
00280     {
00281         WorkingHeight /= 2;
00282         WorkingWidth /= 2;
00283     }
00284 
00285     // WEBSTER - markn 14/2/97
00286     // Rewritten so it will work when "snap to the grid" is on
00287 
00288     // Work out how far the pointer has moved compared with the initial pointer pos
00289     INT32 pdx = PointerPos.x - PointerStart.x;
00290     INT32 pdy = PointerPos.y - PointerStart.y;
00291 
00292     // Move the bounds point by the distance the mouse pointer has moved and
00293     // calc the snapped version of the new bounds pos
00294     DocCoord SnappedBoundsPoint(BoundsStartPoint.x + pdx,BoundsStartPoint.y + pdy);
00295 
00296     if (!ClickMods.Constrain)
00297         DocView::SnapSelected(StartSpread, &SnappedBoundsPoint, FALSE, TRUE);
00298 
00299     // Calc the proportion the bounds have changed compared with the original working dimensions
00300     INT32 dx = (SnappedBoundsPoint.x - BoundsStartPoint.x) + WorkingWidth;
00301     INT32 dy = (SnappedBoundsPoint.y - BoundsStartPoint.y) + WorkingHeight;
00302 
00303     // Calc the scale factors as a fraction of the change between the origin & scaled dimensions
00304     XScaleFactor = FIXED16(double(dx) / double(WorkingWidth));
00305     YScaleFactor = FIXED16(double(dy) / double(WorkingHeight));
00306 
00307     // Deal with the aspect ratio being locked
00308     if (LockAspect)
00309     {
00310         // If the aspect ratio is locked, X and Y should be the same.
00311         // Always take the greatest scale factor. 
00312         // But be careful to retain the sign of the scale factors - only make their
00313         // magnitudes equal! (Sorry about the yucky implementation of this!)
00314         if (YScaleFactor > XScaleFactor)
00315         {
00316             FIXED16 AbsY = (YScaleFactor < 0 ? -YScaleFactor : YScaleFactor);
00317             XScaleFactor = (XScaleFactor < 0 ? -AbsY : AbsY);
00318         }
00319         else
00320         {
00321             FIXED16 AbsX = (XScaleFactor < 0 ? -XScaleFactor : XScaleFactor);
00322             YScaleFactor = (YScaleFactor < 0 ? -AbsX : AbsX);
00323         }
00324     }
00325 
00326     // Deal with constrain.
00327     // Constrain scale factors to be whole numbers.
00328     // This has to be done here instead of overriding the ConstrainDrag function.
00329     if (ClickMods.Constrain)
00330     {
00331         // Constrained squash forces scale to whole number multiple of original size...
00332         FIXED16 Sign;
00333 
00334         Sign = (XScaleFactor<0 ? -1 : 1);           // Compute sign of pure scale
00335         XScaleFactor+=FIXED16((double)0.5);         // Round scale to nearest integer
00336         XScaleFactor = XScaleFactor.MakeShort();
00337         if (XScaleFactor==0) XScaleFactor = Sign;   // Prevent scale from being zero by setting
00338                                                     // it to +/- 1 depending on sign of pure scale.
00339         Sign = (YScaleFactor<0 ? -1 : 1);
00340         YScaleFactor+=FIXED16((double)0.5);
00341         YScaleFactor = YScaleFactor.MakeShort();
00342         if (YScaleFactor==0) YScaleFactor = Sign;
00343     }
00344 
00345     // Update information for the user...
00346     // Must update x,y,w,h,scale and possible angle.
00347     BoundingData.XScale = XScaleFactor;
00348     BoundingData.YScale = YScaleFactor;
00349     BoundingData.ScaleChanged = TRUE;
00350     // See also UpdateTransformBoundingData function in this file...
00351 }


Member Data Documentation

DocCoord OpScaleTrans::BoundsStartPoint [private]
 

Definition at line 160 of file opscale.h.

DocCoord OpScaleTrans::PointerStart [private]
 

Definition at line 159 of file opscale.h.

INT32 OpScaleTrans::StartBlob [private]
 

Definition at line 162 of file opscale.h.

INT32 OpScaleTrans::UnitHeight [private]
 

Definition at line 155 of file opscale.h.

INT32 OpScaleTrans::UnitWidth [private]
 

Definition at line 154 of file opscale.h.

FIXED16 OpScaleTrans::XScaleFactor [private]
 

Definition at line 150 of file opscale.h.

FIXED16 OpScaleTrans::YScaleFactor [private]
 

Definition at line 151 of file opscale.h.


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