1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #ifndef _Aspect_Convert_HeaderFile
19 #define _Aspect_Convert_HeaderFile
21 #include <Standard.hxx>
22 #include <Quantity_Parameter.hxx>
24 //! Auxiliary functions for DCU <-> Pixels conversions.
25 namespace Aspect_Convert
28 inline Standard_Integer Round (Standard_Real theValue)
30 return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 ));
33 inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
34 const Quantity_Parameter theQCenterX, const Quantity_Parameter theQCenterY,
35 const Quantity_Parameter theQSizeX, const Quantity_Parameter theQSizeY,
36 Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
37 Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
39 Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
40 thePxSizeX = Round (theQSizeX * theParentSizeMin);
41 thePxSizeY = Round (theQSizeY * theParentSizeMin);
42 Standard_Integer thePxCenterX = Round(theQCenterX * Quantity_Parameter (theParentPxSizeX));
43 Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Quantity_Parameter (theParentPxSizeY));
44 thePxLeft = thePxCenterX - thePxSizeX / 2;
45 thePxTop = thePxCenterY - thePxSizeY / 2;
48 inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
49 const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
50 const Standard_Integer thePxSizeX, const Standard_Integer thePxSizeY,
51 Quantity_Parameter& theQCenterX, Quantity_Parameter& theQCenterY,
52 Quantity_Parameter& theQSizeX, Quantity_Parameter& theQSizeY)
54 Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
55 theQSizeX = Quantity_Parameter(thePxSizeX) / theParentSizeMin;
56 theQSizeY = Quantity_Parameter(thePxSizeY) / theParentSizeMin;
57 Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
58 Standard_Integer thePxCenterY = thePxTop + thePxSizeY / 2;
59 theQCenterX = Quantity_Parameter (thePxCenterX) / Quantity_Parameter (theParentPxSizeX);
60 theQCenterY = 1.0 - Quantity_Parameter (thePxCenterY) / Quantity_Parameter (theParentPxSizeY);
63 inline void FitIn (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
64 Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
65 Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
69 //thePxSizeX -= 2 * thePxLeft;
72 if ((thePxLeft + thePxSizeX) > theParentPxSizeX)
74 thePxSizeX = theParentPxSizeX - thePxLeft;
79 //thePxSizeY -= 2 * thePxTop;
82 if ((thePxTop + thePxSizeY) > theParentPxSizeY)
84 thePxSizeY = theParentPxSizeY - thePxTop;
90 #endif /* _Aspect_Convert_HeaderFile */