MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_COORD_CONVERTER_H__ 00023 #define __MYGUI_COORD_CONVERTER_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Types.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 class MYGUI_EXPORT CoordConverter 00032 { 00033 public: 00035 static FloatRect convertTextureCoord(const IntCoord& _coord, const IntSize& _textureSize) 00036 { 00037 if (!_textureSize.width || !_textureSize.height) return FloatRect(); 00038 return FloatRect( 00039 (float)_coord.left / (float)_textureSize.width, 00040 (float)_coord.top / (float)_textureSize.height, 00041 (float)_coord.right() / (float)_textureSize.width, 00042 (float)_coord.bottom() / (float)_textureSize.height 00043 ); 00044 } 00045 00046 /* Convert from relative to pixel coordinates. 00047 @param _coord relative coordinates. 00048 */ 00049 static IntCoord convertFromRelative(const FloatCoord& _coord, const IntSize& _view) 00050 { 00051 return IntCoord(int(_coord.left * _view.width), int(_coord.top * _view.height), int(_coord.width * _view.width), int(_coord.height * _view.height)); 00052 } 00053 00054 /* Convert from relative to pixel coordinates. 00055 @param _coord relative coordinates. 00056 */ 00057 static IntSize convertFromRelative(const FloatSize& _size, const IntSize& _view) 00058 { 00059 return IntSize(int(_size.width * _view.width), int(_size.height * _view.height)); 00060 } 00061 00062 /* Convert from relative to pixel coordinates. 00063 @param _coord relative coordinates. 00064 */ 00065 static IntPoint convertFromRelative(const FloatPoint& _point, const IntSize& _view) 00066 { 00067 return IntPoint(int(_point.left * _view.width), int(_point.top * _view.height)); 00068 } 00069 00070 /* Convert from pixel to relative coordinates. 00071 @param _coord pixel coordinates. 00072 */ 00073 static FloatCoord convertToRelative(const IntCoord& _coord, const IntSize& _view) 00074 { 00075 return FloatCoord(_coord.left / (float)_view.width, _coord.top / (float)_view.height, _coord.width / (float)_view.width, _coord.height / (float)_view.height); 00076 } 00077 00078 static FloatSize convertToRelative(const IntSize& _size, const IntSize& _view) 00079 { 00080 return FloatSize(_size.width / (float)_view.width, _size.height / (float)_view.height); 00081 } 00082 00083 static FloatPoint convertToRelative(const IntPoint& _point, const IntSize& _view) 00084 { 00085 return FloatPoint(_point.left / (float)_view.width, _point.top / (float)_view.height); 00086 } 00087 }; 00088 00089 } // namespace MyGUI 00090 00091 #endif // __MYGUI_COORD_CONVERTER_H__