973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #ifndef _Aspect_Convert_HeaderFile |
15 | #define _Aspect_Convert_HeaderFile |
16 | |
17 | #include <Standard.hxx> |
ee2be2a8 |
18 | #include <Standard_Real.hxx> |
7fd59977 |
19 | |
20 | //! Auxiliary functions for DCU <-> Pixels conversions. |
21 | namespace Aspect_Convert |
22 | { |
23 | |
24 | inline Standard_Integer Round (Standard_Real theValue) |
25 | { |
26 | return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 )); |
27 | } |
28 | |
29 | inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY, |
ee2be2a8 |
30 | const Standard_Real theQCenterX, const Standard_Real theQCenterY, |
31 | const Standard_Real theQSizeX, const Standard_Real theQSizeY, |
7fd59977 |
32 | Standard_Integer& thePxLeft, Standard_Integer& thePxTop, |
33 | Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY) |
34 | { |
ee2be2a8 |
35 | Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY); |
7fd59977 |
36 | thePxSizeX = Round (theQSizeX * theParentSizeMin); |
37 | thePxSizeY = Round (theQSizeY * theParentSizeMin); |
ee2be2a8 |
38 | Standard_Integer thePxCenterX = Round(theQCenterX * Standard_Real (theParentPxSizeX)); |
39 | Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Standard_Real (theParentPxSizeY)); |
7fd59977 |
40 | thePxLeft = thePxCenterX - thePxSizeX / 2; |
41 | thePxTop = thePxCenterY - thePxSizeY / 2; |
42 | } |
43 | |
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, |
ee2be2a8 |
47 | Standard_Real& theQCenterX, Standard_Real& theQCenterY, |
48 | Standard_Real& theQSizeX, Standard_Real& theQSizeY) |
7fd59977 |
49 | { |
ee2be2a8 |
50 | Standard_Real theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY); |
51 | theQSizeX = Standard_Real(thePxSizeX) / theParentSizeMin; |
52 | theQSizeY = Standard_Real(thePxSizeY) / theParentSizeMin; |
7fd59977 |
53 | Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2; |
54 | Standard_Integer thePxCenterY = thePxTop + thePxSizeY / 2; |
ee2be2a8 |
55 | theQCenterX = Standard_Real (thePxCenterX) / Standard_Real (theParentPxSizeX); |
56 | theQCenterY = 1.0 - Standard_Real (thePxCenterY) / Standard_Real (theParentPxSizeY); |
7fd59977 |
57 | } |
58 | |
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) |
62 | { |
63 | if (thePxLeft < 0) |
64 | { |
65 | //thePxSizeX -= 2 * thePxLeft; |
66 | thePxLeft = 0; |
67 | } |
68 | if ((thePxLeft + thePxSizeX) > theParentPxSizeX) |
69 | { |
70 | thePxSizeX = theParentPxSizeX - thePxLeft; |
71 | } |
72 | |
73 | if (thePxTop < 0) |
74 | { |
75 | //thePxSizeY -= 2 * thePxTop; |
76 | thePxTop = 0; |
77 | } |
78 | if ((thePxTop + thePxSizeY) > theParentPxSizeY) |
79 | { |
80 | thePxSizeY = theParentPxSizeY - thePxTop; |
81 | } |
82 | } |
83 | |
68858c7d |
84 | } // namespace Aspect_Convert |
7fd59977 |
85 | |
86 | #endif /* _Aspect_Convert_HeaderFile */ |