opsquash.cpp

Go to the documentation of this file.
00001 // $Id: opsquash.cpp 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 Squash transform Operation
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "opsquash.h"
00105 
00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "trans2d.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "rik.h"
00109 #include "selector.h"
00110 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "clikdrag.h"
00112 
00113 
00114 DECLARE_SOURCE("$Revision: 1282 $");
00115 
00116 // An implement to match the Declare in the .h file.
00117 CC_IMPLEMENT_DYNCREATE(OpSquashTrans, TransOperation)
00118 
00119 // This will get Camelot to display the filename and linenumber of any memory allocations
00120 // that are not released at program exit
00121 #define new CAM_DEBUG_NEW
00122 
00123 
00124 
00125 
00126 /********************************************************************************************
00127 
00128 >   OpSquashTrans::OpSquashTrans()
00129 
00130     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00131     Created:    20/7/93
00132     Purpose:    Constructor. Does nothing.
00133 
00134 ********************************************************************************************/
00135 
00136 OpSquashTrans::OpSquashTrans(): TransOperation()
00137 {
00138     // Reset all the infomation about things
00139     SelWidth = SelHeight = 0;
00140 
00141     // Default to horizontal
00142     SquashType = SQUASH_RIGHT;
00143 
00144     // Set the default scale factors
00145     XScale =  YScale = FIXED16(1.0);
00146 
00147     // Set status help
00148     StatusHelpID = _R(IDS_SQUASHTRANS_STATUS1);
00149     StatusHelpID2 = _R(IDS_SQUASHTRANS_STATUS2);
00150 }
00151 
00152 
00153 /********************************************************************************************
00154 
00155 >   virtual void OpSquashTrans::InitTransformImmediate(OpParam* pOpParam)
00156 
00157     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00158     Created:    27/7/94
00159     Inputs:     pOpParam - The parameters that were passed into the operation
00160     Purpose:    Sets up the transform ready for an immediate rotation. This is called from
00161                 DoWithParam()
00162     SeeAlso:    TransOperation::DoWithParam()
00163 
00164 ********************************************************************************************/
00165 
00166 void OpSquashTrans::InitTransformImmediate(OpParam* pOpParam)
00167 {
00168     // Depending on the which way we are scaling this object
00169     switch (SquashType)
00170     {
00171         case SQUASH_UP :
00172         case SQUASH_DOWN :
00173         {
00174             // Stretch it vertically
00175             XScale = FIXED16(1.0);
00176             YScale = *((FIXED16*)PVOID(pOpParam->Param2));
00177             break;
00178         }
00179 
00180         case SQUASH_LEFT :
00181         case SQUASH_RIGHT :
00182         {
00183             // Stretch it horizintally
00184             XScale = *((FIXED16*)PVOID(pOpParam->Param2));
00185             YScale = FIXED16(1.0);
00186             break;
00187         }
00188     }
00189 }
00190 
00191 
00192 
00193 
00194 /********************************************************************************************
00195 
00196 >   void OpSquashTrans::SetStartBlob(INT32 StartBlob)
00197 
00198     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00199     Created:    25/7/94
00200     Inputs:     StartBlob  - the Number of the blob that the operation was initiated on,
00201                 if applicabale. They are numbered as follows :-
00202                 MonoOn
00203                 1  2  3
00204                 4     5
00205                 6  7  8
00206                 MonoOff
00207                 All operations that were not started from one of the 8 blobs should use 0
00208     Purpose:    Allows the operations to know how it was started. This operation is
00209                 interested in the horizontal / vertical nature of the transform
00210 
00211 ********************************************************************************************/
00212 
00213 void OpSquashTrans::SetStartBlob(INT32 StartBlob)
00214 {
00215     switch (StartBlob)
00216     {
00217         case 2:
00218             SquashType = SQUASH_UP;
00219             break;
00220 
00221         case 4:
00222             SquashType = SQUASH_LEFT;
00223             break;
00224 
00225         case 5:
00226             SquashType = SQUASH_RIGHT;
00227             break;
00228 
00229         case 7:
00230             SquashType = SQUASH_DOWN;
00231             break;
00232 
00233         default:
00234             ERROR3("OpSquashTrans started from a blob that it should not have done");
00235             break;
00236     }
00237 }
00238 
00239 
00240 
00241 
00242 /********************************************************************************************
00243 
00244 >   virtual void OpSquashTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00245 
00246     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00247     Created:    19/7/94
00248     Inputs:     PointerPos - The position of the mouse at the start of the drag
00249                 ClickMods - the keyboard modifiers that were active at the start of the drag
00250     Purpose:    Sets up the parameters needed to build the transform matrix at the start
00251                 of the drag. This base class version of this function does nothing.
00252 
00253 ********************************************************************************************/
00254 
00255 void OpSquashTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00256 {
00257     // Make a note of the latest position of the mouse
00258     LastPos = PointerPos;
00259 
00260     // At the start of the drag the Squash factor will always by none
00261     XScale = FIXED16(1);
00262     YScale = FIXED16(1);
00263 
00264     // Use the Width and Height of the object AS PASSED IN from the caller
00265     // (If we just use the width/height of the selection, we may get it all horribly wrong, as
00266     // they may want to scale with or without including the effects of attributes, which
00267     // can significantly affect the size of the bounding rectangle to be used)
00268     SelWidth  = BoundingData.Width;
00269     SelHeight = BoundingData.Height;
00270 }
00271 
00272 
00273 
00274 
00275 /********************************************************************************************
00276 
00277 >   virtual void OpSquashTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread*, ClickModifiers&)
00278 
00279     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00280     Created:    19/7/94
00281     Inputs:     PointerPos - The latest position of the mouse
00282                 Spread the mouse is over - not used
00283                 Clickmodifiers in place - not used
00284     Purpose:    Does the calculations needed when the mouse moves to keep all the params
00285                 needed to build the rotation matrix up to date.
00286                 Note by Phil: This algorithm needs four cases because the scale factors
00287                 involved must be positive whether dragging the left or right handle. It should
00288                 only go negative when the pointer crosses a line through the transform origin.
00289 
00290 ********************************************************************************************/
00291 
00292 void OpSquashTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread* pClickSpread, ClickModifiers& ClickMods)
00293 {
00294     // Make sure that the cursor does not wrap around at the edge of spreads
00295     if (pClickSpread != StartSpread)
00296         PointerPos = MakeRelativeToSpread(StartSpread, pClickSpread, PointerPos);
00297 
00298     // Apply snapping to the pointer pos
00299     if (!ClickMods.Constrain)
00300         DocView::SnapSelected(pClickSpread, &PointerPos, FALSE, TRUE);
00301 
00302     // Make a note of the latest position of the mouse
00303     LastPos = PointerPos;
00304     INT32 Offset;
00305 
00306     // copy the height anf width params so that we can party on them
00307     INT32 WorkingHeight = SelHeight;
00308     INT32 WorkingWidth = SelWidth;
00309 
00310     // if Adjust is being used, adjust the height and width so that scaling still works
00311     if (ClickMods.Adjust)
00312     {
00313         WorkingHeight /= 2;
00314         WorkingWidth /= 2;
00315     }
00316 
00317     // Avoid fp div zero bugs.
00318     if (WorkingHeight == 0)
00319         WorkingHeight = 1;
00320     if (WorkingWidth == 0)
00321         WorkingWidth = 1;
00322 
00323     // Work out the shear factor
00324     switch (SquashType)
00325     {
00326         case SQUASH_UP:
00327             Offset = LastPos.y - CentreOfTrans.y;
00328             YScale = FIXED16( (double)Offset / (double)WorkingHeight);
00329         break;
00330 
00331         case SQUASH_LEFT:
00332             Offset = CentreOfTrans.x - LastPos.x;
00333             XScale = FIXED16( (double)Offset / (double)WorkingWidth);
00334         break;
00335 
00336         case SQUASH_RIGHT:
00337             Offset = LastPos.x - CentreOfTrans.x;
00338             XScale = FIXED16( (double)Offset / (double)WorkingWidth);
00339         break;
00340 
00341         case SQUASH_DOWN:
00342             Offset = CentreOfTrans.y - LastPos.y;
00343             YScale = FIXED16( (double)Offset / (double)WorkingHeight);
00344         break;
00345 
00346     }
00347 
00348     // Deal with Constrain...
00349     // This has to be done in here and not in the ConstrainDrag function because it has to
00350     // modify the scale factors computed by the switch statement above.
00351     if (ClickMods.Constrain)
00352     {
00353         // Constrained squash forces scale to whole number multiple of original size...
00354         FIXED16 Sign;
00355 
00356         Sign = (XScale<0 ? -1 : 1);                 // Compute sign of pure scale
00357         XScale+=FIXED16((double)0.5);               // Round scale to nearest integer
00358         XScale = XScale.MakeShort();
00359         if (XScale==0) XScale = Sign;               // Prevent scale from being zero by setting
00360                                                     // it to +/- 1 depending on sign of pure scale.
00361         Sign = (YScale<0 ? -1 : 1);
00362         YScale+=FIXED16((double)0.5);
00363         YScale = YScale.MakeShort();
00364         if (YScale==0) YScale = Sign;
00365     }
00366 
00367     BoundingData.XScale = XScale;
00368     BoundingData.YScale = YScale;
00369     BoundingData.ScaleChanged = TRUE;
00370     // See also, UpdateTransformBoundingData below!
00371 }
00372 
00373 
00374 
00375 /********************************************************************************************
00376 
00377 >   void OpSquashTrans::BuildMatrix()
00378 
00379     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00380     Created:    19/7/94
00381     Purpose:    Builds the transform matrix required to Shear the selection about the
00382                 point CentreOfRot
00383 
00384 ********************************************************************************************/
00385 
00386 void OpSquashTrans::BuildMatrix()
00387 {
00388     // Translate to the origin
00389     Transform = Matrix(-CentreOfTrans.x, -CentreOfTrans.y);
00390 
00391     // We will need a matrix to put the Scale in
00392     Matrix Squash(XScale, YScale);
00393 
00394     // translate back again
00395     Matrix TransFromOrigin(CentreOfTrans.x, CentreOfTrans.y);
00396 
00397     // Combine the 3 of them into a single matrix
00398     Transform *= Squash;
00399     Transform *= TransFromOrigin;
00400 }
00401 
00402 
00403 
00404 
00405 /********************************************************************************************
00406 
00407 >   BOOL OpSquashTrans::Declare()
00408 
00409     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00410     Created:    5/7/93
00411     Returns:    TRUE if all went OK, False otherwise
00412     Purpose:    Adds the operation to the list of all known operations
00413 
00414 ********************************************************************************************/
00415 
00416 BOOL OpSquashTrans::Declare()
00417 {
00418     return (RegisterOpDescriptor(
00419                                 0, 
00420                                 _R(IDS_SQUASHTRANS),
00421                                 CC_RUNTIME_CLASS(OpSquashTrans),
00422                                 OPTOKEN_SQUASH,
00423                                 TransOperation::GetState)); 
00424 }
00425 
00426 
00427 
00428 /********************************************************************************************
00429 
00430 >   void OpSquashTrans::UpdateTransformBoundingData()
00431 
00432     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00433     Created:    04/9/94
00434     Purpose:    Override the base class version of this fn to ensure that new bounds
00435                 are calculated and placed in the BoundingData structure.
00436 
00437 ********************************************************************************************/
00438 
00439 void OpSquashTrans::UpdateTransformBoundingData()
00440 {
00441 #ifndef STANDALONE
00442     if (pSelTool != NULL)
00443     {
00444         ComputeNewBounds();
00445 
00446         // Tell the tool about the current transform bounding data
00447         pSelTool->DragMove(&BoundingData);
00448     }
00449 #endif
00450 }
00451 
00452 
00453 

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