0024428: Implementation of LGPL license
[occt.git] / src / Aspect / Aspect_Convert.hxx
CommitLineData
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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
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>
18#include <Quantity_Parameter.hxx>
19
20//! Auxiliary functions for DCU <-> Pixels conversions.
21namespace 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,
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)
34 {
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;
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,
47 Quantity_Parameter& theQCenterX, Quantity_Parameter& theQCenterY,
48 Quantity_Parameter& theQSizeX, Quantity_Parameter& theQSizeY)
49 {
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);
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
84};
85
86#endif /* _Aspect_Convert_HeaderFile */