1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Aspect_Convert_HeaderFile
15 #define _Aspect_Convert_HeaderFile
17 #include <Standard.hxx>
18 #include <Quantity_Parameter.hxx>
20 //! Auxiliary functions for DCU <-> Pixels conversions.
21 namespace Aspect_Convert
24 inline Standard_Integer Round (Standard_Real theValue)
26 return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 ));
29 inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
30 const Quantity_Parameter theQCenterX, const Quantity_Parameter theQCenterY,
31 const Quantity_Parameter theQSizeX, const Quantity_Parameter theQSizeY,
32 Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
33 Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
35 Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
36 thePxSizeX = Round (theQSizeX * theParentSizeMin);
37 thePxSizeY = Round (theQSizeY * theParentSizeMin);
38 Standard_Integer thePxCenterX = Round(theQCenterX * Quantity_Parameter (theParentPxSizeX));
39 Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Quantity_Parameter (theParentPxSizeY));
40 thePxLeft = thePxCenterX - thePxSizeX / 2;
41 thePxTop = thePxCenterY - thePxSizeY / 2;
44 inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
45 const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
46 const Standard_Integer thePxSizeX, const Standard_Integer thePxSizeY,
47 Quantity_Parameter& theQCenterX, Quantity_Parameter& theQCenterY,
48 Quantity_Parameter& theQSizeX, Quantity_Parameter& theQSizeY)
50 Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
51 theQSizeX = Quantity_Parameter(thePxSizeX) / theParentSizeMin;
52 theQSizeY = Quantity_Parameter(thePxSizeY) / theParentSizeMin;
53 Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
54 Standard_Integer thePxCenterY = thePxTop + thePxSizeY / 2;
55 theQCenterX = Quantity_Parameter (thePxCenterX) / Quantity_Parameter (theParentPxSizeX);
56 theQCenterY = 1.0 - Quantity_Parameter (thePxCenterY) / Quantity_Parameter (theParentPxSizeY);
59 inline void FitIn (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
60 Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
61 Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
65 //thePxSizeX -= 2 * thePxLeft;
68 if ((thePxLeft + thePxSizeX) > theParentPxSizeX)
70 thePxSizeX = theParentPxSizeX - thePxLeft;
75 //thePxSizeY -= 2 * thePxTop;
78 if ((thePxTop + thePxSizeY) > theParentPxSizeY)
80 thePxSizeY = theParentPxSizeY - thePxTop;
86 #endif /* _Aspect_Convert_HeaderFile */