MyGUI 3.5.3
MyGUI_CoordConverter.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
9
10namespace MyGUI
11{
12
13 FloatRect CoordConverter::convertTextureCoord(const IntCoord& _coord, const IntSize& _textureSize)
14 {
15 if (!_textureSize.width || !_textureSize.height)
16 return {};
17 return {
18 (float)_coord.left / (float)_textureSize.width,
19 (float)_coord.top / (float)_textureSize.height,
20 (float)_coord.right() / (float)_textureSize.width,
21 (float)_coord.bottom() / (float)_textureSize.height};
22 }
23
24 IntCoord CoordConverter::convertFromRelative(const FloatCoord& _coord, const IntSize& _view)
25 {
26 return {
27 int(_coord.left * _view.width),
28 int(_coord.top * _view.height),
29 int(_coord.width * _view.width),
30 int(_coord.height * _view.height)};
31 }
32
33 IntSize CoordConverter::convertFromRelative(const FloatSize& _size, const IntSize& _view)
34 {
35 return {int(_size.width * _view.width), int(_size.height * _view.height)};
36 }
37
38 IntPoint CoordConverter::convertFromRelative(const FloatPoint& _point, const IntSize& _view)
39 {
40 return {int(_point.left * _view.width), int(_point.top * _view.height)};
41 }
42
43 FloatCoord CoordConverter::convertToRelative(const IntCoord& _coord, const IntSize& _view)
44 {
45 return {
46 _coord.left / (float)_view.width,
47 _coord.top / (float)_view.height,
48 _coord.width / (float)_view.width,
49 _coord.height / (float)_view.height};
50 }
51
52 FloatSize CoordConverter::convertToRelative(const IntSize& _size, const IntSize& _view)
53 {
54 return {_size.width / (float)_view.width, _size.height / (float)_view.height};
55 }
56
57 FloatPoint CoordConverter::convertToRelative(const IntPoint& _point, const IntSize& _view)
58 {
59 return {_point.left / (float)_view.width, _point.top / (float)_view.height};
60 }
61
62 IntCoord CoordConverter::convertFromRelative(const DoubleCoord& _coord, const IntSize& _view)
63 {
64 return {
65 int(_coord.left * _view.width),
66 int(_coord.top * _view.height),
67 int(_coord.width * _view.width),
68 int(_coord.height * _view.height)};
69 }
70
71 DoubleCoord CoordConverter::convertToRelativeD(const IntCoord& _coord, const IntSize& _view)
72 {
73 return {
74 _coord.left / (double)_view.width,
75 _coord.top / (double)_view.height,
76 _coord.width / (double)_view.width,
77 _coord.height / (double)_view.height};
78 }
79
80 std::tuple<IntCoord, bool, bool> CoordConverter::applyAlign(
81 Align _align,
82 const IntCoord& _coord,
83 const IntSize& _parentSize,
84 const IntSize& _oldsize)
85 {
86 IntCoord result = _coord;
87 bool resize = false;
88 bool move = false;
89
90 if (_align.isHStretch())
91 {
92 result.width = _coord.width + (_parentSize.width - _oldsize.width);
93 resize = true;
94 }
95 else if (_align.isRight())
96 {
97 result.left = _coord.left + (_parentSize.width - _oldsize.width);
98 move = true;
99 }
100 else if (_align.isHCenter())
101 {
102 result.left = (_parentSize.width - _coord.width) / 2;
103 move = true;
104 }
105
106 if (_align.isVStretch())
107 {
108 result.height = _coord.height + (_parentSize.height - _oldsize.height);
109 resize = true;
110 }
111 else if (_align.isBottom())
112 {
113 result.top = _coord.top + (_parentSize.height - _oldsize.height);
114 move = true;
115 }
116 else if (_align.isVCenter())
117 {
118 result.top = (_parentSize.height - _coord.height) / 2;
119 move = true;
120 }
121
122 return {result, resize, move};
123 }
124
125} // namespace MyGUI
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:26
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:36
types::TRect< float > FloatRect
Definition MyGUI_Types.h:33
types::TCoord< double > DoubleCoord
Definition MyGUI_Types.h:37
types::TPoint< float > FloatPoint
Definition MyGUI_Types.h:27
types::TSize< float > FloatSize
Definition MyGUI_Types.h:30
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29