Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIUDim.h

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUIUDim.h
00003     created:    Tue May 31 2005
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009  
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014  
00015     This library 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 GNU
00018     Lesser General Public License for more details.
00019  
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #ifndef _CEGUIUDim_h_
00025 #define _CEGUIUDim_h_
00026 
00027 #include "CEGUIRect.h"
00028 #include "CEGUIVector.h"
00029 
00030 // some macros to aid in the creation of UDims
00031 #define cegui_absdim(x)     UDim(0,(x))
00032 #define cegui_reldim(x)     UDim((x),0)
00033 
00034 
00035 // Start of CEGUI namespace section
00036 namespace CEGUI
00037 {
00038     class CEGUIEXPORT UDim
00039     {
00040     public:
00041         UDim() {}
00042         UDim(float scale, float offset) : d_scale(scale), d_offset(offset) {}
00043         ~UDim() {}
00044 
00045         float asAbsolute(float base) const    { return PixelAligned(base * d_scale) + d_offset; }
00046         float asRelative(float base) const    { return (base != 0.0f) ? d_offset / base + d_scale : 0.0f; }
00047 
00048         UDim operator+(const UDim& other) const     { return UDim(d_scale + other.d_scale, d_offset + other.d_offset); }
00049         UDim operator-(const UDim& other) const     { return UDim(d_scale - other.d_scale, d_offset - other.d_offset); }
00050         UDim operator/(const UDim& other) const     { return UDim(d_scale / other.d_scale, d_offset / other.d_offset); }
00051         UDim operator*(const UDim& other) const     { return UDim(d_scale * other.d_scale, d_offset * other.d_offset); }
00052 
00053         const UDim& operator+=(const UDim& other)   { d_scale += other.d_scale; d_offset += other.d_offset; return *this; }
00054         const UDim& operator-=(const UDim& other)   { d_scale -= other.d_scale; d_offset -= other.d_offset; return *this; }
00055         const UDim& operator/=(const UDim& other)   { d_scale /= other.d_scale; d_offset /= other.d_offset; return *this; }
00056         const UDim& operator*=(const UDim& other)   { d_scale *= other.d_scale; d_offset *= other.d_offset; return *this; }
00057 
00058         bool operator==(const UDim& other) const    { return d_scale == other.d_scale && d_offset == other.d_offset; }
00059         bool operator!=(const UDim& other) const    { return !operator==(other); }
00060 
00061         float d_scale, d_offset;
00062     };
00063 
00064 
00065     class CEGUIEXPORT UVector2
00066     {
00067     public:
00068         UVector2() {}
00069         UVector2(const UDim& x, const UDim& y) : d_x(x), d_y(y) {}
00070         ~UVector2() {}
00071 
00072         Vector2 asAbsolute(const Size& base) const    { return Vector2(d_x.asAbsolute(base.d_width), d_y.asAbsolute(base.d_height)); }
00073         Vector2 asRelative(const Size& base) const    { return Vector2(d_x.asRelative(base.d_width), d_y.asRelative(base.d_height)); }
00074 
00075         UVector2 operator+(const UVector2& other) const     { return UVector2(d_x + other.d_x, d_y + other.d_y); }
00076         UVector2 operator-(const UVector2& other) const     { return UVector2(d_x - other.d_x, d_y - other.d_y); }
00077         UVector2 operator/(const UVector2& other) const     { return UVector2(d_x / other.d_x, d_y / other.d_y); }
00078         UVector2 operator*(const UVector2& other) const     { return UVector2(d_x * other.d_x, d_y * other.d_y); }
00079 
00080         const UVector2& operator+=(const UVector2& other)   { d_x += other.d_x; d_y += other.d_y; return *this; }
00081         const UVector2& operator-=(const UVector2& other)   { d_x -= other.d_x; d_y -= other.d_y; return *this; }
00082         const UVector2& operator/=(const UVector2& other)   { d_x /= other.d_x; d_y /= other.d_y; return *this; }
00083         const UVector2& operator*=(const UVector2& other)   { d_x *= other.d_x; d_y *= other.d_y; return *this; }
00084         
00085         bool operator==(const UVector2& other) const    { return d_x == other.d_x && d_y == other.d_y; }
00086         bool operator!=(const UVector2& other) const    { return !operator==(other); }
00087 
00088         UDim d_x, d_y;
00089     };
00090 
00091 
00092     class CEGUIEXPORT URect
00093     {
00094     public:
00095         URect() {}
00096         
00097         URect(const UVector2& min, const UVector2& max) : d_min(min), d_max(max) {}
00098         
00099         URect(const UDim& left, const UDim& top, const UDim& right, const UDim& bottom)
00100         {
00101             d_min.d_x = left;
00102             d_min.d_y = top;
00103             d_max.d_x = right;
00104             d_max.d_y = bottom;
00105         }
00106         
00107         ~URect() {}
00108     
00109         Rect asAbsolute(const Size& base) const
00110         {
00111             return Rect(
00112                     d_min.d_x.asAbsolute(base.d_width),
00113                     d_min.d_y.asAbsolute(base.d_height),
00114                     d_max.d_x.asAbsolute(base.d_width),
00115                     d_max.d_y.asAbsolute(base.d_height)
00116                 );
00117         }
00118 
00119         Rect asRelative(const Size& base) const
00120         {
00121             return Rect(
00122                     d_min.d_x.asRelative(base.d_width),
00123                     d_min.d_y.asRelative(base.d_height),
00124                     d_max.d_x.asRelative(base.d_width),
00125                     d_max.d_y.asRelative(base.d_height)
00126                 );
00127         }
00128 
00129         const UVector2& getPosition() const     { return d_min; }
00130         UVector2 getSize() const                { return d_max - d_min; }
00131         UDim getWidth() const                   { return d_max.d_x - d_min.d_x; }
00132         UDim getHeight() const                  { return d_max.d_y - d_min.d_y; }
00133 
00134         void setPosition(const UVector2& pos)
00135         {
00136             UVector2 sz(d_max - d_min);
00137             d_min = pos;
00138             d_max = d_min + sz;
00139         }
00140 
00141         void setSize(const UVector2& sz)
00142         {
00143             d_max = d_min + sz;
00144         }
00145 
00146         void setWidth(const UDim& w)        { d_max.d_x = d_min.d_x + w; }
00147         void setHeight(const UDim& h)       { d_max.d_y = d_min.d_y + h; }
00148 
00149         void offset(const UVector2& sz)
00150         {
00151             d_min += sz;
00152             d_max += sz;
00153         }
00154         
00155         UVector2 d_min, d_max;
00156     };
00157 
00158 } // End of  CEGUI namespace section
00159 
00160 
00161 #endif  // end of guard _CEGUIUDim_h_

Generated on Wed Sep 7 09:56:34 2005 for Crazy Eddies GUI System by  doxygen 1.4.3