#include <opshear.h>
Inheritance diagram for OpShearTrans:
Public Member Functions | |
OpShearTrans () | |
Constructor. Does nothing. | |
Static Public Member Functions | |
static BOOL | Declare () |
Adds the operation to the list of all known operations. | |
Private Member Functions | |
CC_DECLARE_DYNCREATE (OpShearTrans) | |
virtual void | InitTransformImmediate (OpParam *pParam) |
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 &ClickMods) |
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 Shear the selection about the point CentreOfRot. | |
virtual void | SetStartBlob (INT32 StartBlob) |
Allows the operations to know how it was started. This operation is interested in the horizontal / vertical nature of the transform. | |
virtual void | ConstrainDrag (DocCoord *) |
Constrains the drag by the constrain angle. If the angle becomes too shallow (eg 90 degrees) the constrain will stop constraining and let it move freely. | |
Private Attributes | |
INT32 | SelWidth |
INT32 | SelHeight |
BOOL | IsHorizontal |
BOOL | IsNegative |
FIXED16 | ShearBy |
DocCoord | LastPos |
Definition at line 118 of file opshear.h.
|
Constructor. Does nothing.
Definition at line 137 of file opshear.cpp. 00137 : TransOperation() 00138 { 00139 // Reset all the infomation about things 00140 SelWidth = SelHeight = 0; 00141 00142 // Default to horizontal 00143 IsHorizontal = TRUE; 00144 00145 // Start off with no shearing at all 00146 ShearBy = FIXED16(0); 00147 00148 // Set status help text 00149 StatusHelpID = _R(IDS_SHEARTRANS_STATUS1); 00150 StatusHelpID2=_R(IDS_SHEARTRANS_STATUS2); 00151 }
|
|
Builds the transform matrix required to Shear the selection about the point CentreOfRot.
Reimplemented from TransOperation. Definition at line 392 of file opshear.cpp. 00393 { 00394 // Translate to the origin 00395 Transform = Matrix(-CentreOfTrans.x, -CentreOfTrans.y); 00396 00397 // We will need a matrix to put the shear in 00398 Matrix Shear; 00399 00400 // Work out how much to shear the selection by 00401 if (IsHorizontal) 00402 { 00403 // Build the shear matrix for a horizontal shear 00404 Shear = Matrix(FIXED16(1), FIXED16(0), FIXED16(ShearBy), FIXED16(1), 0, 0); 00405 } 00406 else 00407 { 00408 // Build the shear matrix for a vertical shear 00409 Shear = Matrix(FIXED16(1), FIXED16(ShearBy), FIXED16(0), FIXED16(1), 0, 0); 00410 } 00411 00412 // Apply the shear 00413 Transform *= Shear; 00414 00415 // Translate back again 00416 Transform *= Matrix(CentreOfTrans.x, CentreOfTrans.y); 00417 }
|
|
|
|
Constrains the drag by the constrain angle. If the angle becomes too shallow (eg 90 degrees) the constrain will stop constraining and let it move freely.
Reimplemented from TransOperation. Definition at line 333 of file opshear.cpp. 00334 { 00335 // Make a copy of the coord in case we want to put it back 00336 DocCoord WorkingCopy = *PointerPos; 00337 BOOL UseWorkingCopy = FALSE; 00338 00339 // Snap the pointer coord so that it runs along one of the rays 00340 DocView::ConstrainToAngle(CentreOfTrans, &WorkingCopy); 00341 00342 // find out the x & y distance from the centre 00343 INT32 dx = WorkingCopy.x - CentreOfTrans.x; 00344 INT32 dy = WorkingCopy.y - CentreOfTrans.y; 00345 00346 if (IsHorizontal) 00347 { 00348 if (dy!=0) 00349 { 00350 // This is a horizontal drag, so make sure that the pointer pos 00351 // lies on the horizon line level with the starting position 00352 // We need 64 bit numbers in the middle of the calculation so 00353 // use something that does it for us. 00354 dx = Mul32Div32(dx, StartPos.y-CentreOfTrans.y, dy); 00355 00356 // only need to change the x component as that is all that is used 00357 WorkingCopy.x = CentreOfTrans.x + dx; 00358 WorkingCopy.y = StartPos.y; 00359 UseWorkingCopy = TRUE; 00360 } 00361 } 00362 else 00363 { 00364 if (dx!=0) 00365 { 00366 // Same but in the other axis 00367 dy = Mul32Div32(dy, StartPos.x-CentreOfTrans.x, dx) ; 00368 00369 // Only change the y component this time 00370 WorkingCopy.y = CentreOfTrans.y + dy; 00371 WorkingCopy.x = StartPos.x; 00372 UseWorkingCopy = TRUE; 00373 } 00374 } 00375 00376 // See if the constrain was valid 00377 if (UseWorkingCopy) 00378 *PointerPos = WorkingCopy; 00379 }
|
|
Adds the operation to the list of all known operations.
Reimplemented from TransOperation. Definition at line 433 of file opshear.cpp. 00434 { 00435 return (RegisterOpDescriptor( 00436 0, 00437 _R(IDS_SHEARTRANS), 00438 CC_RUNTIME_CLASS(OpShearTrans), 00439 OPTOKEN_SHEAR, 00440 TransOperation::GetState)); 00441 }
|
|
Reimplemented from TransOperation. Definition at line 207 of file opshear.cpp. 00208 { 00209 FIXED16 pDegreesShearAngle = *((FIXED16*)PVOID(pParam->Param2)); 00210 double ShearAngle = pDegreesShearAngle.MakeDouble(); 00211 00212 if (ShearAngle < -89.0) // Clip the shear angle to a sensible range 00213 ShearAngle = -89.0; 00214 00215 if (ShearAngle > 89.0) 00216 ShearAngle = 89.0; 00217 00218 ShearAngle = (ShearAngle*2*PI)/360.0; // Convert to Radians 00219 ShearBy = (FIXED16)(tan(ShearAngle)); // And get the Shear distance to bung in the matrix 00220 }
|
|
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.
Reimplemented from TransOperation. Definition at line 238 of file opshear.cpp. 00239 { 00240 // Make a note of the latest position of the mouse 00241 LastPos = PointerPos; 00242 00243 // At the start of the drag the Shear factor will always by none 00244 ShearBy = FIXED16(0); 00245 00246 // Find out how big the selection is 00247 // SelRange* Selection = GetApplication()->FindSelection(); 00248 // DocRect SelRect = Selection->GetBoundingRect(); 00249 00250 // Find the width and the height of the selection 00251 // SelWidth = SelRect.Width(); 00252 // SelHeight = SelRect.Height(); 00253 00254 // Use the Width and Height of the object AS PASSED IN from the caller 00255 // (If we just use the width/height of the selection, we may get it all horribly wrong, as 00256 // they may want to scale with or without including the effects of attributes, which 00257 // can significantly affect the size of the bounding rectangle to be used) 00258 SelWidth = BoundingData.Width; 00259 SelHeight = BoundingData.Height; 00260 }
|
|
Allows the operations to know how it was started. This operation is interested in the horizontal / vertical nature of the transform.
Reimplemented from TransOperation. Definition at line 174 of file opshear.cpp. 00175 { 00176 // Only blobs 2, 7, 4 and 5 are relavant. All others are a problem 00177 ENSURE( (StartBlob==2) || (StartBlob==4) || (StartBlob==5) || (StartBlob==7), 00178 "Shear started a blob that it should not have done"); 00179 00180 // blobs 2 and 7 are the Middle Top and Middle Bottom blobs 00181 // and would suggest horizontal shearing 00182 if ((StartBlob==2) || (StartBlob==7)) 00183 IsHorizontal = TRUE; 00184 else 00185 IsHorizontal = FALSE; 00186 00187 }
|
|
Does the calculations needed when the mouse moves to keep all the params needed to build the rotation matrix up to date.
Reimplemented from TransOperation. Definition at line 279 of file opshear.cpp. 00280 { 00281 // Make sure that the cursor does not wrap around at the edge of spreads 00282 if (pClickSpread != StartSpread) 00283 PointerPos = MakeRelativeToSpread(StartSpread, pClickSpread, PointerPos); 00284 00285 if (!ClickMods.Constrain) 00286 DocView::SnapSelected(pClickSpread, &PointerPos, FALSE, TRUE); 00287 00288 // Make a note of the latest position of the mouse 00289 LastPos = PointerPos; 00290 00291 double dx = PointerPos.x - CentreOfTrans.x; 00292 double dy = PointerPos.y - CentreOfTrans.y; 00293 00294 // Work out the shear factor and angle 00295 double ShearAngle; 00296 if (IsHorizontal) 00297 { 00298 // Work out the horizontal shearing 00299 dy = StartPos.y - CentreOfTrans.y; 00300 ShearBy = FIXED16( dx / dy); 00301 ShearAngle = atan2(dx, dy); 00302 } 00303 else 00304 { 00305 // Work out the vertical shearing 00306 dx = StartPos.x - CentreOfTrans.x; 00307 ShearBy = FIXED16( dy / dx); 00308 ShearAngle = atan2(dy, dx); 00309 } 00310 00311 // Update the boundingdata infomation about the constrain 00312 ShearAngle = (ShearAngle / (2.0*PI)) * 360.0; 00313 BoundingData.Shear = (ANGLE) ShearAngle; 00314 BoundingData.ShearChanged = TRUE; 00315 }
|
|
|
|
|
|
|
|
|
|
|
|
|