tranlate.cpp

Go to the documentation of this file.
00001 // $Id: tranlate.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 // Operation for doing an interactive Translation of the selection
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "tranlate.h"
00105 
00106 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "rik.h"
00108 //#include "clikdrag.h"
00109 
00110 // Register my files version number
00111 DECLARE_SOURCE("$Revision: 1282 $");
00112 
00113 // An implement to match the Declare in the .h file.
00114 CC_IMPLEMENT_DYNCREATE(OpTranslateTrans, TransOperation)
00115 
00116 // This will get Camelot to display the filename and linenumber of any memory allocations
00117 // that are not released at program exit
00118 #define new CAM_DEBUG_NEW
00119 
00120 
00121 
00122 
00123 
00124 /********************************************************************************************
00125 
00126 >   OpTranslateTrans::OpTranslateTrans()
00127 
00128     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00129     Created:    20/7/93
00130     Purpose:    Constructor. Does nothing.
00131 
00132 ********************************************************************************************/
00133 
00134 OpTranslateTrans::OpTranslateTrans(): TransOperation()
00135 {
00136     //Set status line help
00137     StatusHelpID = _R(IDS_TRANSLTRANS_STATUS1);
00138     StatusHelpID2 = _R(IDS_TRANSLTRANS_STATUS2);
00139     CanScaleLines = FALSE;
00140 }
00141 
00142 
00143 
00144 
00145 /********************************************************************************************
00146 
00147 >   void OpTranslateTrans::InitTransformImmediate(OpParam* pOpParam)
00148 
00149     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00150     Created:    27/7/94
00151     Inputs:     pOpParam - The parameters that were passed into the operation
00152     Purpose:    Sets up the transform ready for an immediate translation. This is called from
00153                 DoWithParam()
00154     SeeAlso:    TransOperation::DoWithParam()
00155 
00156 ********************************************************************************************/
00157 
00158 void OpTranslateTrans::InitTransformImmediate(OpParam* pOpParam)
00159 {
00160     // Set the initial position
00161     StartPos = DocCoord(0,0);
00162     RawStartPos = StartPos;
00163     MagStartPos = StartPos;
00164 
00165     // and copy the offset to translate by from Param2
00166     DocCoord* Offset = (DocCoord*)( PVOID(pOpParam->Param2) );
00167     LastPos.x = Offset->x;
00168     LastPos.y = Offset->y;
00169 
00170     OriginalGridOffset.x=0;
00171     OriginalGridOffset.y=0;
00172 }
00173 
00174 
00175 /********************************************************************************************
00176 
00177 >   virtual void OpTranslateTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00178 
00179     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00180     Created:    19/7/94
00181     Inputs:     PointerPos - The position of the mouse at the start of the drag
00182                 ClickMods - the keyboard modifiers that were active at the start of the drag
00183     Purpose:    Sets up the parameters needed to build the transform matrix at the start
00184                 of the drag. This base class version of this function does nothing.
00185 
00186 ********************************************************************************************/
00187 
00188 void OpTranslateTrans::InitTransformOnDrag(DocCoord PointerPos, ClickModifiers ClickMods)
00189 {
00190     // make a note of the current mouse position
00191     LastPos = PointerPos;
00192 
00193     // Record the offset from the mouse pos to the grid
00194     OriginalGridOffset = GetStartPos();
00195     DocView::ForceSnapToGrid(StartSpread, &OriginalGridOffset);
00196     OriginalGridOffset = GetStartPos() - OriginalGridOffset;
00197 }
00198 
00199 
00200 
00201 
00202 /********************************************************************************************
00203 
00204 >   virtual void OpTranslateTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread* pSpread,
00205                                     ClickModifiers& ClickMods)
00206 
00207     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00208     Created:    19/7/94
00209     Inputs:     PointerPos - The latest position of the mouse
00210     Purpose:    Does the calculations needed when the mouse moves to keep all the params
00211                 needed to build the rotation matrix up to date.
00212 
00213 ********************************************************************************************/
00214 
00215 void OpTranslateTrans::UpdateTransformOnDrag(DocCoord PointerPos, Spread* pSpread, ClickModifiers& ClickMods)
00216 {
00217     if (!ClickMods.Constrain)
00218     {
00219         // Apply snapping to the pointer pos
00220         // First apply magnetic snapping alone
00221         if (MagneticGripPoint && DocView::SnapSelected(pSpread, &PointerPos, TRUE, FALSE))
00222         {
00223             // Magnetic snapping worked!
00224         }
00225         else
00226         {
00227             // Magnetic snapping failed!
00228             // If magnetic snapping failed then try grid snapping
00229             // on the adjusted coordinate
00230             if (ClickMods.Alternative1)
00231             {
00232                 PointerPos = PointerPos - OriginalGridOffset;
00233                 DocView::SnapSelected(pSpread, &PointerPos, FALSE, TRUE);
00234                 PointerPos = PointerPos + OriginalGridOffset;
00235             }
00236             else
00237             {
00238                 DocCoord Offset = PointerPos - LastPos;
00239                 DocRect Bounds( BoundingData.x, BoundingData.y,
00240                                 BoundingData.x+BoundingData.Width, BoundingData.y+BoundingData.Height
00241                                );
00242                 Bounds.lo = Bounds.lo + Offset;
00243                 Bounds.hi = Bounds.hi + Offset;
00244                 DocRect SnappedBounds = Bounds;
00245                 DocView::SnapSelected(pSpread,&SnappedBounds,LastRawPos,RawPos);
00246                 PointerPos = PointerPos + (SnappedBounds.lo - Bounds.lo);
00247             }
00248         }
00249     }
00250 
00251     // Work out the offset from the last mouse pos
00252     INT32 dx = PointerPos.x - LastPos.x;
00253     INT32 dy = PointerPos.y - LastPos.y;
00254 
00255     // Add the offset into the structure
00256     BoundingData.x += dx;
00257     BoundingData.y += dy;
00258     BoundingData.XYChanged = TRUE;
00259 
00260     // Make a mental note of the current position
00261     LastPos = PointerPos;
00262 
00263     // Update the current spread (must do this if CanChangeSpread returns TRUE)
00264     CurrentSpread = pSpread;
00265 }
00266 
00267 
00268 
00269 /********************************************************************************************
00270 
00271 >   virtual BOOL OpTranslateTrans::CanChangeSpread()
00272 
00273     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00274     Created:    05/June/2006
00275     Inputs:     -
00276     Outputs:    -
00277     Returns:    TRUE if this transform allows the drag to be transferred to another spread
00278     Purpose:    Tell the baseclass functions whether to draw drag feedback only on the start
00279                 spread or to allow drag rendering to be done on other spreads too.
00280 
00281 ********************************************************************************************/
00282 
00283 BOOL OpTranslateTrans::CanChangeSpread()
00284 {
00285     return TRUE;
00286 }
00287 
00288 
00289 /********************************************************************************************
00290 
00291 >   void OpTranslateTrans::BuildMatrix()
00292 
00293     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00294     Created:    19/7/94
00295     Purpose:    Builds the transform matrix required to rotate the selection about the
00296                 point CentreOfRot by the required number of degrees
00297 
00298 ********************************************************************************************/
00299 
00300 void OpTranslateTrans::BuildMatrix()
00301 {
00302     // Build a translation matrix by takeing the offset from the last mouse position
00303     // to the start mouse position
00304         Transform = Matrix(LastPos.x-GetStartPos().x, LastPos.y-GetStartPos().y);
00305 }
00306 
00307 
00308 
00309 /********************************************************************************************
00310 
00311 >   virtual BOOL OpTranslateTrans::ShouldPointerBeOffset()
00312 
00313     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    13/9/94
00315     Returns:    FALSE
00316     Purpose:    Tells the base class of the operation that we want our mouse coords to be
00317                 left alone
00318 
00319 ********************************************************************************************/
00320 
00321 BOOL OpTranslateTrans::ShouldPointerBeOffset()
00322 {
00323     return FALSE;
00324 }
00325 
00326 
00327 
00328 
00329 /********************************************************************************************
00330 
00331 >   virtual void OpTranslateTrans::ConstrainDrag(DocCoord* PointerPos)
00332 
00333     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00334     Created:    19/7/94
00335     Inputs:     PointerPos - The current position of the mouse that needs to be constrained
00336     Outputs:    PointerPos - The position of the mouse after it has been constrained
00337     Purpose:    Will constrain the mouse position to lie along rays from the centre of
00338                 rotation at the constrain angle apart (45 degrees by default)
00339 
00340 ********************************************************************************************/
00341 
00342 void OpTranslateTrans::ConstrainDrag(DocCoord* PointerPos)
00343 {
00344     // Lock the mouse to move along the axis or diagonally
00345     DocCoord Blobby = GetStartPos();
00346     DocView::ConstrainToAngle(Blobby, PointerPos);
00347 }
00348 
00349 
00350 /********************************************************************************************
00351 
00352 >   BOOL OpTranslateTrans::Declare()
00353 
00354     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00355     Created:    5/7/93
00356     Returns:    TRUE if all went OK, False otherwise
00357     Purpose:    Adds the operation to the list of all known operations
00358 
00359 ********************************************************************************************/
00360 
00361 BOOL OpTranslateTrans::Declare()
00362 {
00363     return (RegisterOpDescriptor(0, _R(IDS_SELECTOR_MOVE), CC_RUNTIME_CLASS(OpTranslateTrans),
00364                                 OPTOKEN_TRANSLATE, TransOperation::GetState)); 
00365 }

Generated on Sat Nov 10 03:48:02 2007 for Camelot by  doxygen 1.4.4