Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Image.h
1 /***********************************************************************
2  created: Wed Feb 16 2011
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUIImage_h_
28 #define _CEGUIImage_h_
29 
30 #include "CEGUI/ChainedXMLHandler.h"
31 #include "CEGUI/String.h"
32 #include "CEGUI/ColourRect.h"
33 #include "CEGUI/Rect.h"
34 
35 // Start of CEGUI namespace section
36 namespace CEGUI
37 {
38 
40 {
69 };
70 
71 
72 template<>
74 {
75 public:
78  typedef AutoScaledMode pass_type;
79  typedef String string_return_type;
80 
81  static const String& getDataTypeName()
82  {
83  static String type("AutoScaledMode");
84 
85  return type;
86  }
87 
88  static return_type fromString(const String& str)
89  {
90  if (str == "vertical")
91  {
92  return ASM_Vertical;
93  }
94  else if (str == "horizontal")
95  {
96  return ASM_Horizontal;
97  }
98  else if (str == "min")
99  {
100  return ASM_Min;
101  }
102  else if (str == "max")
103  {
104  return ASM_Max;
105  }
106  else if (str == "true" || str == "True")
107  {
108  return ASM_Both;
109  }
110  else
111  {
112  return ASM_Disabled;
113  }
114  }
115 
116  static string_return_type toString(pass_type val)
117  {
118  if (val == ASM_Disabled)
119  {
120  return "false";
121  }
122  else if (val == ASM_Vertical)
123  {
124  return "vertical";
125  }
126  else if (val == ASM_Horizontal)
127  {
128  return "horizontal";
129  }
130  else if (val == ASM_Min)
131  {
132  return "min";
133  }
134  else if (val == ASM_Max)
135  {
136  return "max";
137  }
138  else if (val == ASM_Both)
139  {
140  return "true";
141  }
142  else
143  {
144  assert(false && "Invalid auto scaled mode");
145  return "false";
146  }
147  }
148 };
149 
158 class CEGUIEXPORT Image :
159  public AllocatedObject<Image>,
160  public ChainedXMLHandler
161 {
162 public:
163  virtual ~Image();
164 
165  virtual const String& getName() const = 0;
166 
167  virtual const Sizef& getRenderedSize() const = 0;
168  virtual const Vector2f& getRenderedOffset() const = 0;
169 
170  virtual void render(GeometryBuffer& buffer,
171  const Rectf& dest_area,
172  const Rectf* clip_area,
173  const ColourRect& colours) const = 0;
174 
175  virtual void notifyDisplaySizeChanged(const Sizef& size) = 0;
176 
177  // Standard Image::render overloads
178  void render(GeometryBuffer& buffer,
179  const Vector2f& position,
180  const Rectf* clip_area = 0) const
181  {
182  const ColourRect colours(0XFFFFFFFF);
183  render(buffer, Rectf(position, getRenderedSize()), clip_area, colours);
184  }
185 
186  void render(GeometryBuffer& buffer,
187  const Vector2f& position,
188  const Rectf* clip_area,
189  const ColourRect& colours) const
190  {
191  render(buffer, Rectf(position, getRenderedSize()), clip_area, colours);
192  }
193 
194  void render(GeometryBuffer& buffer,
195  const Vector2f& position,
196  const Sizef& size,
197  const Rectf* clip_area = 0) const
198  {
199  const ColourRect colours(0XFFFFFFFF);
200  render(buffer, Rectf(position, size), clip_area, colours);
201  }
202 
203  void render(GeometryBuffer& buffer,
204  const Vector2f& position,
205  const Sizef& size,
206  const Rectf* clip_area,
207  const ColourRect& colours) const
208  {
209  render(buffer, Rectf(position, size), clip_area, colours);
210  }
211 
220  static void computeScalingFactors(AutoScaledMode mode,
221  const Sizef& display_size,
222  const Sizef& native_display_size,
223  float& x_scale,
224  float& y_scale);
225 
226 protected:
227  // implement chained xml handler abstract interface
228  void elementStartLocal(const String& element,
229  const XMLAttributes& attributes);
230  void elementEndLocal(const String& element);
231 };
232 
233 } // End of CEGUI namespace section
234 
235 #endif // end of guard _CEGUIImage_h_
236