MyGUI  3.0.1
MyGUI_CoordConverter.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_COORD_CONVERTER_H__
24 #define __MYGUI_COORD_CONVERTER_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Types.h"
28 
29 namespace MyGUI
30 {
31 
33  {
34  public:
36  static FloatRect convertTextureCoord(const IntCoord& _coord, const IntSize& _textureSize)
37  {
38  if (!_textureSize.width || !_textureSize.height) return FloatRect();
39  return FloatRect(
40  (float)_coord.left / (float)_textureSize.width,
41  (float)_coord.top / (float)_textureSize.height,
42  (float)_coord.right() / (float)_textureSize.width,
43  (float)_coord.bottom() / (float)_textureSize.height);
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 
90 } // namespace MyGUI
91 
92 #endif // __MYGUI_COORD_CONVERTER_H__