Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Aspect / Aspect_Convert.hxx
1 #ifndef _Aspect_Convert_HeaderFile
2 #define _Aspect_Convert_HeaderFile
3
4 #include <Standard.hxx>
5 #include <Quantity_Parameter.hxx>
6
7 //! Auxiliary functions for DCU <-> Pixels conversions.
8 namespace Aspect_Convert
9 {
10
11   inline Standard_Integer Round (Standard_Real theValue)
12   {
13     return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 ));
14   }
15
16   inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
17                                   const Quantity_Parameter theQCenterX, const Quantity_Parameter theQCenterY,
18                                   const Quantity_Parameter theQSizeX,   const Quantity_Parameter theQSizeY,
19                                   Standard_Integer& thePxLeft,  Standard_Integer& thePxTop,
20                                   Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
21   {
22     Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
23     thePxSizeX = Round (theQSizeX * theParentSizeMin);
24     thePxSizeY = Round (theQSizeY * theParentSizeMin);
25     Standard_Integer thePxCenterX = Round(theQCenterX * Quantity_Parameter (theParentPxSizeX));
26     Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Quantity_Parameter (theParentPxSizeY));
27     thePxLeft = thePxCenterX - thePxSizeX / 2;
28     thePxTop  = thePxCenterY - thePxSizeY / 2;
29   }
30
31   inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
32                                   const Standard_Integer thePxLeft,  const Standard_Integer thePxTop,
33                                   const Standard_Integer thePxSizeX, const Standard_Integer thePxSizeY,
34                                   Quantity_Parameter& theQCenterX, Quantity_Parameter& theQCenterY,
35                                   Quantity_Parameter& theQSizeX,   Quantity_Parameter& theQSizeY)
36   {
37     Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
38     theQSizeX = Quantity_Parameter(thePxSizeX) / theParentSizeMin;
39     theQSizeY = Quantity_Parameter(thePxSizeY) / theParentSizeMin;
40     Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
41     Standard_Integer thePxCenterY = thePxTop  + thePxSizeY / 2;
42     theQCenterX =       Quantity_Parameter (thePxCenterX) / Quantity_Parameter (theParentPxSizeX);
43     theQCenterY = 1.0 - Quantity_Parameter (thePxCenterY) / Quantity_Parameter (theParentPxSizeY);
44   }
45
46   inline void FitIn (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
47                      Standard_Integer& thePxLeft,  Standard_Integer& thePxTop,
48                      Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
49   {
50     if (thePxLeft < 0)
51     {
52       //thePxSizeX -= 2 * thePxLeft;
53       thePxLeft = 0;
54     }
55     if ((thePxLeft + thePxSizeX) > theParentPxSizeX)
56     {
57       thePxSizeX = theParentPxSizeX - thePxLeft;
58     }
59
60     if (thePxTop < 0)
61     {
62       //thePxSizeY -= 2 * thePxTop;
63       thePxTop = 0;
64     }
65     if ((thePxTop + thePxSizeY) > theParentPxSizeY)
66     {
67       thePxSizeY = theParentPxSizeY - thePxTop;
68     }
69   }
70
71 };
72
73 #endif /* _Aspect_Convert_HeaderFile */