MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
31 class MYGUI_EXPORT CoordConverter
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__
MyGUI::types::TCoord< int >
MyGUI::types::TPoint< int >
MyGUI_Prerequest.h
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:44
MyGUI::types::TSize< int >
MyGUI::CoordConverter::convertFromRelative
static IntCoord convertFromRelative(const FloatCoord &_coord, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:49
MyGUI::FloatCoord
types::TCoord< float > FloatCoord
Definition: MyGUI_Types.h:51
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:36
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:39
MyGUI_Types.h
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
MyGUI::types::TCoord::top
T top
Definition: MyGUI_TCoord.h:38
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:35
MyGUI::types::TCoord::right
T right() const
Definition: MyGUI_TCoord.h:165
MyGUI::types::TRect< float >
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:35
MyGUI::types::TCoord::bottom
T bottom() const
Definition: MyGUI_TCoord.h:170
MyGUI::CoordConverter::convertToRelative
static FloatCoord convertToRelative(const IntCoord &_coord, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:73
MyGUI::CoordConverter::convertToRelative
static FloatSize convertToRelative(const IntSize &_size, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:78
MyGUI::FloatRect
types::TRect< float > FloatRect
Definition: MyGUI_Types.h:48
MyGUI::CoordConverter::convertToRelative
static FloatPoint convertToRelative(const IntPoint &_point, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:83
MyGUI::FloatPoint
types::TPoint< float > FloatPoint
Definition: MyGUI_Types.h:42
MyGUI::CoordConverter::convertFromRelative
static IntPoint convertFromRelative(const FloatPoint &_point, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:65
MyGUI::CoordConverter
Definition: MyGUI_CoordConverter.h:31
MyGUI::CoordConverter::convertTextureCoord
static FloatRect convertTextureCoord(const IntCoord &_coord, const IntSize &_textureSize)
Definition: MyGUI_CoordConverter.h:35
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:36
MyGUI::types::TCoord::left
T left
Definition: MyGUI_TCoord.h:37
MyGUI::CoordConverter::convertFromRelative
static IntSize convertFromRelative(const FloatSize &_size, const IntSize &_view)
Definition: MyGUI_CoordConverter.h:57
MyGUI::FloatSize
types::TSize< float > FloatSize
Definition: MyGUI_Types.h:45
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:40
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41