Crazy Eddie's GUI System  0.8.4
CoordConverter.h
00001 /***********************************************************************
00002     created:    Sun Sep 18 2005
00003     author:     Paul D Turner <paul@cegui.org.uk>
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUICoordConverter_h_
00028 #define _CEGUICoordConverter_h_
00029 
00030 #include "CEGUI/UDim.h"
00031 #include "CEGUI/Vector.h"
00032 #include "CEGUI/Size.h"
00033 #include "CEGUI/Rect.h"
00034 
00035 // Start of CEGUI namespace section
00036 namespace CEGUI
00037 {
00044 class CEGUIEXPORT CoordConverter
00045 {
00046 public:
00062     inline static float alignToPixels(float x)
00063     {
00064         return (float)(int)(( x ) + (( x ) > 0.0f ? 0.5f : -0.5f));
00065     }
00066     
00071     inline static float asAbsolute(const UDim& u, float base, bool pixelAlign = true)
00072     {
00073         return pixelAlign ? alignToPixels(base * u.d_scale + u.d_offset) : base * u.d_scale + u.d_offset;
00074     }
00075 
00080     inline static float asRelative(const UDim& u, float base)
00081     {
00082         return (base != 0.0f) ? u.d_offset / base + u.d_scale : 0.0f;
00083     }
00084 
00089     inline static Vector2f asAbsolute(const Vector2<UDim>& v, const Sizef& base, bool pixelAlign = true)
00090     {
00091         return Vector2f(asAbsolute(v.d_x, base.d_width, pixelAlign), asAbsolute(v.d_y, base.d_height, pixelAlign));
00092     }
00093 
00098     inline static Vector2f asRelative(const Vector2<UDim>& v, const Sizef& base)
00099     {
00100         return Vector2f(asRelative(v.d_x, base.d_width), asRelative(v.d_y, base.d_height));
00101     }
00102 
00107     inline static Sizef asAbsolute(const Size<UDim>& v, const Sizef& base, bool pixelAlign = true)
00108     {
00109         return Sizef(asAbsolute(v.d_width, base.d_width, pixelAlign), asAbsolute(v.d_height, base.d_height, pixelAlign));
00110     }
00111 
00116     inline static Sizef asRelative(const Size<UDim>& v, const Sizef& base)
00117     {
00118         return Sizef(asRelative(v.d_width, base.d_width), asRelative(v.d_height, base.d_height));
00119     }
00120 
00121     inline static Rectf asAbsolute(const URect& r, const Sizef& base, bool pixelAlign = true)
00122     {
00123         return Rectf(
00124                    asAbsolute(r.d_min.d_x, base.d_width,  pixelAlign),
00125                    asAbsolute(r.d_min.d_y, base.d_height, pixelAlign),
00126                    asAbsolute(r.d_max.d_x, base.d_width,  pixelAlign),
00127                    asAbsolute(r.d_max.d_y, base.d_height, pixelAlign)
00128                );
00129     }
00130 
00131     inline static Rectf asRelative(const URect& r, const Sizef& base)
00132     {
00133         return Rectf(
00134                    asRelative(r.d_min.d_x, base.d_width),
00135                    asRelative(r.d_min.d_y, base.d_height),
00136                    asRelative(r.d_max.d_x, base.d_width),
00137                    asRelative(r.d_max.d_y, base.d_height)
00138                );
00139     }
00140 
00156     static float screenToWindowX(const Window& window, const UDim& x);
00157 
00173     static float screenToWindowX(const Window& window, const float x);
00174 
00190     static float screenToWindowY(const Window& window, const UDim& y);
00191 
00207     static float screenToWindowY(const Window& window, const float y);
00208 
00224     static Vector2f screenToWindow(const Window& window, const UVector2& vec);
00225 
00241     static Vector2f screenToWindow(const Window& window, const Vector2f& vec);
00242 
00257     static Rectf screenToWindow(const Window& window, const URect& rect);
00258 
00273     static Rectf screenToWindow(const Window& window, const Rectf& rect);
00274 
00275 private:
00277     CoordConverter();
00278 
00290     static float getBaseXValue(const Window& window);
00291 
00303     static float getBaseYValue(const Window& window);
00304 
00316     static Vector2f getBaseValue(const Window& window);
00317 };
00318 
00319 } // End of  CEGUI namespace section
00320 
00321 
00322 #endif  // end of guard _CEGUICoordConverter_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends