Bugfix : Zooming works correct, no more errors on screen.
[xara-cairo.git] / wxOil / oilcoord.cpp
blob3bdff788f2492bc49395d904a177599ca50f7b40
1 // $Id: oilcoord.cpp 1282 2006-06-09 09:46:49Z alex $
2 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
3 ================================XARAHEADERSTART===========================
5 Xara LX, a vector drawing and manipulation program.
6 Copyright (C) 1993-2006 Xara Group Ltd.
7 Copyright on certain contributions may be held in joint with their
8 respective authors. See AUTHORS file for details.
10 LICENSE TO USE AND MODIFY SOFTWARE
11 ----------------------------------
13 This file is part of Xara LX.
15 Xara LX is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License version 2 as published
17 by the Free Software Foundation.
19 Xara LX and its component source files are distributed in the hope
20 that it will be useful, but WITHOUT ANY WARRANTY; without even the
21 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License along
25 with Xara LX (see the file GPL in the root directory of the
26 distribution); if not, write to the Free Software Foundation, Inc., 51
27 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 ADDITIONAL RIGHTS
31 -----------------
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
35 rights.
37 The additional rights are to use, modify, and distribute the software
38 together with the wxWidgets library, the wxXtra library, and the "CDraw"
39 library and any other such library that any version of Xara LX relased
40 by Xara Group Ltd requires in order to compile and execute, including
41 the static linking of that library to XaraLX. In the case of the
42 "CDraw" library, you may satisfy obligation under the GNU General Public
43 License to provide source code by providing a binary copy of the library
44 concerned and a copy of the license accompanying it.
46 Nothing in this section restricts any of the rights you have under
47 the GNU General Public License.
50 SCOPE OF LICENSE
51 ----------------
53 This license applies to this program (XaraLX) and its constituent source
54 files only, and does not necessarily apply to other Xara products which may
55 in part share the same code base, and are subject to their own licensing
56 terms.
58 This license does not apply to files in the wxXtra directory, which
59 are built into a separate library, and are subject to the wxWindows
60 license contained within that directory in the file "WXXTRA-LICENSE".
62 This license does not apply to the binary libraries (if any) within
63 the "libs" directory, which are subject to a separate license contained
64 within that directory in the file "LIBS-LICENSE".
67 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
68 ----------------------------------------------
70 Subject to the terms of the GNU Public License (see above), you are
71 free to do whatever you like with your modifications. However, you may
72 (at your option) wish contribute them to Xara's source tree. You can
73 find details of how to do this at:
74 http://www.xaraxtreme.org/developers/
76 Prior to contributing your modifications, you will need to complete our
77 contributor agreement. This can be found at:
78 http://www.xaraxtreme.org/developers/contribute/
80 Please note that Xara will not accept modifications which modify any of
81 the text between the start and end of this header (marked
82 XARAHEADERSTART and XARAHEADEREND).
85 MARKS
86 -----
88 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
89 designs are registered or unregistered trademarks, design-marks, and/or
90 service marks of Xara Group Ltd. All rights in these marks are reserved.
93 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
94 http://www.xara.com/
96 =================================XARAHEADEREND============================
100 #include "camtypes.h"
102 //#include "oilcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
103 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED]
104 //#include "wrkcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
105 //#include "rect.h" - in camtypes.h [AUTOMATICALLY REMOVED]
106 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
107 #include "paper.h"
108 //#include "xmatrix.h" - in camtypes.h [AUTOMATICALLY REMOVED]
109 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
110 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
111 #include "chapter.h"
112 //#include "view.h" - in camtypes.h [AUTOMATICALLY REMOVED]
114 DECLARE_SOURCE("$Revision: 1282 $");
119 /*********************************************************************************************
120 > OilCoord::OilCoord(MILLIPOINT xx, MILLIPOINT yy)
122 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
123 Created: 27th August 1993
124 Inputs: Two INT32s (measured in millipoints).
125 Outputs: -
126 Returns: -
127 Purpose: Constructs an OIL coordinate.
128 Errors: -
129 Scope: Public
131 **********************************************************************************************/
133 OilCoord::OilCoord(MILLIPOINT xx, MILLIPOINT yy) : Coord(xx, yy)
145 /********************************************************************************************
147 > WinCoord OilCoord::ToWin(View *pView) const;
149 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
150 Created: 5/8/93
151 Inputs: The view we are converting to.
152 Purpose: Converts an OilCoord to a WinCoord.
154 ********************************************************************************************/
156 WinCoord OilCoord::ToWin(View *pView) const
158 // Note that we have to negate the y coord, because Windows starts with 0 at the top
159 // and then positive coordinates in a downward direction, i.e. the opposite to
160 // Camelot's coordinate systems.
162 // NB. More importantly, we add 1 to the y coord, because the flipping of the y axis
163 // causes a misalignment in the pixel systems. This is because Camelot coords
164 // specify the bottom left of the pixel, whereas GDI coords specify the top-left.
165 // (See coord.doc for more details)
167 // return WinCoord(INT32(MPtoPixel(x, xPixelScale)), -INT32(MPtoPixel(y, yPixelScale) + 1));
169 // New info: (Phil, 17/11/94)
170 // The one pixel bodge is no longer required because the pixel model has been modified
171 // so that pixel coordinates are in the centres of pixels, not on any edge.
172 // This allows coordinate systems to be negated without any extra work.
174 // Get pixel size for this view
175 FIXED16 PixelWidth, PixelHeight;
176 pView->GetPixelSize(&PixelWidth, &PixelHeight);
178 // Do the conversion and return the results.
179 return WinCoord(INT32(MPtoPixel(x, PixelWidth)), -INT32(MPtoPixel(y, PixelHeight) ));
183 /********************************************************************************************
185 > WinCoord OilCoord::ToWin( const INT32 dpi ) const;
187 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
188 Created: 30/11/93
189 Inputs: Transform Matrix.
190 dpi the value of the destination dpi rather than assuming screen dpi
191 Outputs: None
192 Returns: None.
193 Purpose: Same as above in that it converts an OilCoord to a WinCoord but instead of
194 assuming screen dpi, as in using x/yPixelScale, it uses the specified dpi
195 to work out the transformation.
196 Errors: None.
198 ********************************************************************************************/
200 //WinCoord OilCoord::ToWin( const INT32 dpi ) const
202 // See above ToWin routine for conversion comments
203 // Work out our x and y pixel scaling factors for the specified destination dpi
204 // FIXED16 PixScale = 72000.0/dpi;
206 // return WinCoord(INT32(MPtoPixel(x, PixScale)), -INT32(MPtoPixel(y, PixScale) ));
209 /********************************************************************************************
211 > WinCoord OilCoord::ToWin( const double dpi ) const;
213 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
214 Created: 30/11/93
215 Inputs: Transform Matrix.
216 dpi the value of the destination dpi rather than assuming screen dpi
217 Outputs: None
218 Returns: None.
219 Purpose: Same as above in that it converts an OilCoord to a WinCoord but instead of
220 assuming screen dpi, as in using x/yPixelScale, it uses the specified dpi
221 to work out the transformation.
222 Different to above in that it takes a double dpi instead of a INT32 dpi. Now
223 superceeds the above. Changed 12/12/95.
224 Errors: None.
226 ********************************************************************************************/
228 WinCoord OilCoord::ToWin( const double dpi ) const
230 // See above ToWin routine for conversion comments
231 // Work out our x and y pixel scaling factors for the specified destination dpi
232 FIXED16 PixScale = 72000.0/dpi;
234 return WinCoord(INT32(MPtoPixel(x, PixScale)), -INT32(MPtoPixel(y, PixScale) ));
240 /********************************************************************************************
242 > WorkCoord OilCoord::ToWork(const WorkCoord& ScrollOffset) const
244 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
245 Created: 5/8/93
246 Inputs: Scroll offset.
247 Outputs: None
248 Returns: None.
249 Purpose: Converts an OilCoord to a WorkCoord.
250 Errors: None.
252 ********************************************************************************************/
254 WorkCoord OilCoord::ToWork(const WorkCoord& ScrollOffset) const
256 // Add the scroll offsets to get workarea values...
257 return WorkCoord(ScrollOffset.x + x, ScrollOffset.y + y);
263 /********************************************************************************************
265 > void OilCoord::ToWork(const WorkCoord& scrollOffset, WorkCoord* result ) const
267 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
268 Created: 5/8/93
269 Inputs: Scroll offset.
270 Outputs: None
271 Returns: None.
272 Purpose: Converts an OilCoord to a WorkCoord.
273 Errors: None.
275 ********************************************************************************************/
277 Technical notes:
279 ********************************************************************************************/
281 void OilCoord::ToWork(const WorkCoord& scrollOffset, WorkCoord* result ) const
283 // Implementation...
284 // Then add the scroll offsets to get workarea values...
285 result->x = scrollOffset.x + x;
286 result->y = scrollOffset.y + y;
292 /********************************************************************************************
294 > DocCoord OilCoord::ToDoc(const Spread* pSpread, View *pView) const
296 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
297 Created: 22/12/93
298 Inputs: pSpread - The spread that we know that the oil coord is in
299 View - the view to use when converting.
300 Returns: This coordinate as measured in DocCoords
301 Purpose: Convert an OilCoord to a DocCoord
303 ********************************************************************************************/
305 DocCoord OilCoord::ToDoc(const Spread* pSpread, View* pView) const
307 DocCoord Return;
308 WorkCoord Point((XLONG)(this->x), (XLONG)(this->y));
310 // First, convert the OilCoord into a LogicalCoord...
311 FIXED16 ViewScale = pView->GetViewScale();
312 WorkCoord ScrollOffset = pView->GetScrollOffsets();
314 Point.x = MakeXLong( double(Point.x + ScrollOffset.x) / ViewScale.MakeDouble());
315 Point.y = MakeXLong( double(Point.y + ScrollOffset.y) / ViewScale.MakeDouble());
317 // Find the parent chapter
318 Chapter* pChapter = (Chapter*) pSpread->FindParent();
319 ENSURE( pChapter != NULL, "Spread had no parent" );
320 ENSURE( pChapter->IsKindOf(CC_RUNTIME_CLASS(Chapter)), "Chapter is not a chapter" );
322 // Find the depth of the chapter
323 XLONG ChapDepth = pChapter->GetChapterDepth();
325 // Find the chapters position
326 DocCoord ChapterPos;
327 ChapterPos.x = pChapter->GetPasteboardRect(TRUE, pView).lo.x;
328 ChapterPos.y = pChapter->GetPasteboardRect(TRUE, pView).hi.y;
330 // Build the return value up
331 Return.x = Point.x + ChapterPos.x;
332 Return.y = Point.y + MakeXLong(ChapterPos.y) + ChapDepth;
334 return (Return);