Crazy Eddie's GUI System  0.8.4
Image.h
00001 /***********************************************************************
00002     created:    Wed Feb 16 2011
00003     author:     Paul D Turner <paul@cegui.org.uk>
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2011 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 _CEGUIImage_h_
00028 #define _CEGUIImage_h_
00029 
00030 #include "CEGUI/ChainedXMLHandler.h"
00031 #include "CEGUI/String.h"
00032 #include "CEGUI/ColourRect.h"
00033 #include "CEGUI/Rect.h"
00034 
00035 // Start of CEGUI namespace section
00036 namespace CEGUI
00037 {
00038 
00039 enum AutoScaledMode
00040 {
00042     ASM_Disabled,
00047     ASM_Vertical,
00052     ASM_Horizontal,
00056     ASM_Min,
00060     ASM_Max,
00068     ASM_Both
00069 };
00070 
00071 
00072 template<>
00073 class PropertyHelper<AutoScaledMode>
00074 {
00075 public:
00076     typedef AutoScaledMode return_type;
00077     typedef return_type safe_method_return_type;
00078     typedef AutoScaledMode pass_type;
00079     typedef String string_return_type;
00080 
00081     static const String& getDataTypeName()
00082     {
00083         static String type("AutoScaledMode");
00084 
00085         return type;
00086     }
00087 
00088     static return_type fromString(const String& str)
00089     {
00090         if (str == "vertical")
00091         {
00092             return ASM_Vertical;
00093         }
00094         else if (str == "horizontal")
00095         {
00096             return ASM_Horizontal;
00097         }
00098         else if (str == "min")
00099         {
00100             return ASM_Min;
00101         }
00102         else if (str == "max")
00103         {
00104             return ASM_Max;
00105         }
00106         else if (str == "true" || str == "True")
00107         {
00108             return ASM_Both;
00109         }
00110         else
00111         {
00112             return ASM_Disabled;
00113         }
00114     }
00115 
00116     static string_return_type toString(pass_type val)
00117     {
00118         if (val == ASM_Disabled)
00119         {
00120             return "false";
00121         }
00122         else if (val == ASM_Vertical)
00123         {
00124             return "vertical";
00125         }
00126         else if (val == ASM_Horizontal)
00127         {
00128             return "horizontal";
00129         }
00130         else if (val == ASM_Min)
00131         {
00132             return "min";
00133         }
00134         else if (val == ASM_Max)
00135         {
00136             return "max";
00137         }
00138         else if (val == ASM_Both)
00139         {
00140             return "true";
00141         }
00142         else
00143         {
00144             assert(false && "Invalid auto scaled mode");
00145             return "false";
00146         }
00147     }
00148 };
00149 
00158 class CEGUIEXPORT Image :
00159     public AllocatedObject<Image>,
00160     public ChainedXMLHandler
00161 {
00162 public:
00163     virtual ~Image();
00164 
00165     virtual const String& getName() const = 0;
00166 
00167     virtual const Sizef& getRenderedSize() const = 0;
00168     virtual const Vector2f& getRenderedOffset() const = 0;
00169 
00170     virtual void render(GeometryBuffer& buffer,
00171                         const Rectf& dest_area,
00172                         const Rectf* clip_area,
00173                         const ColourRect& colours) const = 0;
00174 
00175     virtual void notifyDisplaySizeChanged(const Sizef& size) = 0;
00176 
00177     // Standard Image::render overloads
00178     void render(GeometryBuffer& buffer,
00179                 const Vector2f& position,
00180                 const Rectf* clip_area = 0) const
00181     {
00182         const ColourRect colours(0XFFFFFFFF);
00183         render(buffer, Rectf(position, getRenderedSize()), clip_area, colours);
00184     }
00185 
00186     void render(GeometryBuffer& buffer,
00187                 const Vector2f& position,
00188                 const Rectf* clip_area,
00189                 const ColourRect& colours) const
00190     {
00191         render(buffer, Rectf(position, getRenderedSize()), clip_area, colours);
00192     }
00193 
00194     void render(GeometryBuffer& buffer,
00195                 const Vector2f& position,
00196                 const Sizef& size,
00197                 const Rectf* clip_area = 0) const
00198     {
00199         const ColourRect colours(0XFFFFFFFF);
00200         render(buffer, Rectf(position, size), clip_area, colours);
00201     }
00202 
00203     void render(GeometryBuffer& buffer,
00204                 const Vector2f& position,
00205                 const Sizef& size,
00206                 const Rectf* clip_area,
00207                 const ColourRect& colours) const
00208     {
00209         render(buffer, Rectf(position, size), clip_area, colours);
00210     }
00211 
00220     static void computeScalingFactors(AutoScaledMode mode,
00221                                       const Sizef& display_size,
00222                                       const Sizef& native_display_size,
00223                                       float& x_scale,
00224                                       float& y_scale);
00225 
00226 protected:
00227     // implement chained xml handler abstract interface
00228     void elementStartLocal(const String& element,
00229                            const XMLAttributes& attributes);
00230     void elementEndLocal(const String& element);
00231 };
00232 
00233 } // End of  CEGUI namespace section
00234 
00235 #endif  // end of guard _CEGUIImage_h_
00236 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends