MyGUI  3.0.3
MyGUI_CoordConverter.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_COORD_CONVERTER_H__
00024 #define __MYGUI_COORD_CONVERTER_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Types.h"
00028 
00029 namespace MyGUI
00030 {
00031 
00032     class MYGUI_EXPORT CoordConverter
00033     {
00034     public:
00036         static FloatRect convertTextureCoord(const IntCoord& _coord, const IntSize& _textureSize)
00037         {
00038             if (!_textureSize.width || !_textureSize.height) return FloatRect();
00039             return FloatRect(
00040             (float)_coord.left / (float)_textureSize.width,
00041             (float)_coord.top / (float)_textureSize.height,
00042             (float)_coord.right() / (float)_textureSize.width,
00043             (float)_coord.bottom() / (float)_textureSize.height);
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 
00090 } // namespace MyGUI
00091 
00092 #endif // __MYGUI_COORD_CONVERTER_H__