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 <Standard_Real.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 Standard_Real theQCenterX, const Standard_Real theQCenterY,
31 const Standard_Real theQSizeX, const Standard_Real theQSizeY,
32 Standard_Integer& thePxLeft, Standard_Integer& thePxTop,
33 Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
35 Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
36 thePxSizeX = Round (theQSizeX * theParentSizeMin);
37 thePxSizeY = Round (theQSizeY * theParentSizeMin);
38 Standard_Integer thePxCenterX = Round(theQCenterX * Standard_Real (theParentPxSizeX));
39 Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Standard_Real (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 Standard_Real& theQCenterX, Standard_Real& theQCenterY,
48 Standard_Real& theQSizeX, Standard_Real& theQSizeY)
50 Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
51 theQSizeX = Standard_Real(thePxSizeX) / theParentSizeMin;
52 theQSizeY = Standard_Real(thePxSizeY) / theParentSizeMin;
53 Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
54 Standard_Integer thePxCenterY = thePxTop + thePxSizeY / 2;
55 theQCenterX = Standard_Real (thePxCenterX) / Standard_Real (theParentPxSizeX);
56 theQCenterY = 1.0 - Standard_Real (thePxCenterY) / Standard_Real (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;
84 } // namespace Aspect_Convert
86 #endif /* _Aspect_Convert_HeaderFile */