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