00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00047
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
00055
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
00063
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
00071
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 }
00091
00092 #endif // __MYGUI_COORD_CONVERTER_H__