MyGUI  3.2.0
MyGUI_CoordConverter.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_COORD_CONVERTER_H__
23 #define __MYGUI_COORD_CONVERTER_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Types.h"
27 
28 namespace MyGUI
29 {
30 
32  {
33  public:
35  static FloatRect convertTextureCoord(const IntCoord& _coord, const IntSize& _textureSize)
36  {
37  if (!_textureSize.width || !_textureSize.height) return FloatRect();
38  return FloatRect(
39  (float)_coord.left / (float)_textureSize.width,
40  (float)_coord.top / (float)_textureSize.height,
41  (float)_coord.right() / (float)_textureSize.width,
42  (float)_coord.bottom() / (float)_textureSize.height
43  );
44  }
45 
46  /* Convert from relative to pixel coordinates.
47  @param _coord relative coordinates.
48  */
49  static IntCoord convertFromRelative(const FloatCoord& _coord, const IntSize& _view)
50  {
51  return IntCoord(int(_coord.left * _view.width), int(_coord.top * _view.height), int(_coord.width * _view.width), int(_coord.height * _view.height));
52  }
53 
54  /* Convert from relative to pixel coordinates.
55  @param _coord relative coordinates.
56  */
57  static IntSize convertFromRelative(const FloatSize& _size, const IntSize& _view)
58  {
59  return IntSize(int(_size.width * _view.width), int(_size.height * _view.height));
60  }
61 
62  /* Convert from relative to pixel coordinates.
63  @param _coord relative coordinates.
64  */
65  static IntPoint convertFromRelative(const FloatPoint& _point, const IntSize& _view)
66  {
67  return IntPoint(int(_point.left * _view.width), int(_point.top * _view.height));
68  }
69 
70  /* Convert from pixel to relative coordinates.
71  @param _coord pixel coordinates.
72  */
73  static FloatCoord convertToRelative(const IntCoord& _coord, const IntSize& _view)
74  {
75  return FloatCoord(_coord.left / (float)_view.width, _coord.top / (float)_view.height, _coord.width / (float)_view.width, _coord.height / (float)_view.height);
76  }
77 
78  static FloatSize convertToRelative(const IntSize& _size, const IntSize& _view)
79  {
80  return FloatSize(_size.width / (float)_view.width, _size.height / (float)_view.height);
81  }
82 
83  static FloatPoint convertToRelative(const IntPoint& _point, const IntSize& _view)
84  {
85  return FloatPoint(_point.left / (float)_view.width, _point.top / (float)_view.height);
86  }
87  };
88 
89 } // namespace MyGUI
90 
91 #endif // __MYGUI_COORD_CONVERTER_H__