Crazy Eddie's GUI System  0.8.7
Dimensions.h
1 /***********************************************************************
2  created: Mon Jun 13 2005
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2012 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 _CEGUIFalDimensions_h_
28 #define _CEGUIFalDimensions_h_
29 
30 #include "./Enums.h"
31 #include "../String.h"
32 #include "../UDim.h"
33 #include "../Rect.h"
34 #include "../XMLSerializer.h"
35 
36 // Start of CEGUI namespace section
37 namespace CEGUI
38 {
40 class CEGUIEXPORT BaseDim :
41  public AllocatedObject<BaseDim>
42 {
43 public:
44  BaseDim();
45 
46  virtual ~BaseDim();
47 
59  virtual float getValue(const Window& wnd) const = 0;
60 
78  virtual float getValue(const Window& wnd, const Rectf& container) const = 0;
79 
89  virtual BaseDim* clone() const = 0;
90 
98  virtual void writeXMLToStream(XMLSerializer& xml_stream) const;
99 
101  virtual bool handleFontRenderSizeChange(Window& window,
102  const Font* font) const;
103 protected:
105  virtual void writeXMLElementName_impl(XMLSerializer& xml_stream) const = 0;
106 
108  virtual void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const = 0;
109 };
110 
116 class CEGUIEXPORT OperatorDim : public BaseDim
117 {
118 public:
119  OperatorDim();
121  OperatorDim(DimensionOperator op, BaseDim* left, BaseDim* right);
122  ~OperatorDim();
123 
125  void setLeftOperand(const BaseDim* operand);
126 
128  BaseDim* getLeftOperand() const;
129 
131  void setRightOperand(const BaseDim* operand);
132 
134  BaseDim* getRightOperand() const;
135 
137  void setOperator(DimensionOperator op);
138 
140  DimensionOperator getOperator() const;
141 
143  void setNextOperand(const BaseDim* operand);
144 
145  // Implementation of the base class interface
146  float getValue(const Window& wnd) const;
147  float getValue(const Window& wnd, const Rectf& container) const;
148  BaseDim* clone() const;
149 
150 protected:
151  float getValueImpl(const float lval, const float rval) const;
152  // Implementation of the base class interface
153  void writeXMLToStream(XMLSerializer& xml_stream) const;
154  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
155  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
156 
157  BaseDim* d_left;
158  BaseDim* d_right;
159  DimensionOperator d_op;
160 };
161 
167 class CEGUIEXPORT AbsoluteDim : public BaseDim
168 {
169 public:
170  AbsoluteDim() {};
171  AbsoluteDim(float val);
172 
174  float getBaseValue() const;
175 
177  void setBaseValue(float val);
178 
179  // Implementation of the base class interface
180  float getValue(const Window& wnd) const;
181  float getValue(const Window& wnd, const Rectf& container) const;
182  BaseDim* clone() const;
183 
184 protected:
185  // Implementation of the base class interface
186  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
187  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
188 
189 private:
191  float d_val;
192 };
193 
199 class CEGUIEXPORT ImageDimBase : public BaseDim
200 {
201 public:
202  ImageDimBase() {};
203 
213 
222  DimensionType getSourceDimension() const;
223 
232  void setSourceDimension(DimensionType dim);
233 
234  // Implementation of the base class interface
235  float getValue(const Window& wnd) const;
236  float getValue(const Window& wnd, const Rectf& container) const;
237 
238 protected:
240  virtual const Image* getSourceImage(const Window& wnd) const = 0;
241 
242  // Implementation of the base class interface
243  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
244 
247 };
248 
250 class CEGUIEXPORT ImageDim : public ImageDimBase
251 {
252 public:
253  ImageDim() {};
254  ImageDim(const String& image_name, DimensionType dim);
255 
257  const String& getSourceImage() const;
259  void setSourceImage(const String& image_name);
260 
261  // Implementation of the base class interface
262  BaseDim* clone() const;
263 
264 protected:
265  // Implementation / overrides of functions in superclasses
266  const Image* getSourceImage(const Window& wnd) const;
267  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
268  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
269 
272 };
273 
275 class CEGUIEXPORT ImagePropertyDim : public ImageDimBase
276 {
277 public:
278  ImagePropertyDim() {};
279 
293  ImagePropertyDim(const String& property_name, DimensionType dim);
294 
296  const String& getSourceProperty() const;
298  void setSourceProperty(const String& property_name);
299 
300  // Implementation of the base class interface
301  BaseDim* clone() const;
302 
303 protected:
304  // Implementation / overrides of functions in superclasses
305  const Image* getSourceImage(const Window& wnd) const;
306  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
307  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
308 
311 };
312 
323 class CEGUIEXPORT WidgetDim : public BaseDim
324 {
325 public:
326  WidgetDim() {};
338  WidgetDim(const String& name, DimensionType dim);
339 
347  const String& getWidgetName() const;
348 
359  void setWidgetName(const String& name);
360 
369  DimensionType getSourceDimension() const;
370 
379  void setSourceDimension(DimensionType dim);
380 
381  // Implementation of the base class interface
382  float getValue(const Window& wnd) const;
383  float getValue(const Window& wnd, const Rectf& container) const;
384  BaseDim* clone() const;
385 
386 protected:
387  // Implementation of the base class interface
388  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
389  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
390 
391 private:
393  String d_widgetName;
395  DimensionType d_what;
396 };
397 
403 class CEGUIEXPORT UnifiedDim : public BaseDim
404 {
405 public:
406  UnifiedDim(){};
419  UnifiedDim(const UDim& value, DimensionType dim);
420 
422  const UDim& getBaseValue() const;
423 
425  void setBaseValue(const UDim& val);
426 
436  DimensionType getSourceDimension() const;
437 
447  void setSourceDimension(DimensionType dim);
448 
449  // Implementation of the base class interface
450  float getValue(const Window& wnd) const;
451  float getValue(const Window& wnd, const Rectf& container) const;
452  BaseDim* clone() const;
453 
454 protected:
455  // Implementation of the base class interface
456  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
457  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
458 
459 private:
461  UDim d_value;
463  DimensionType d_what;
464 };
465 
471 class CEGUIEXPORT FontDim : public BaseDim
472 {
473 public:
474  FontDim() {};
499  FontDim(const String& name, const String& font, const String& text,
500  FontMetricType metric, float padding = 0);
501 
503  const String& getName() const;
504 
506  void setName(const String& name);
507 
509  const String& getFont() const;
510 
512  void setFont(const String& font);
513 
515  const String& getText() const;
516 
518  void setText(const String& text);
519 
521  FontMetricType getMetric() const;
522 
524  void setMetric(FontMetricType metric);
525 
527  float getPadding() const;
528 
530  void setPadding(float padding);
531 
532  // overridden from BaseDim.
533  bool handleFontRenderSizeChange(Window& window,
534  const Font* font) const;
535 
536  // Implementation of the base class interface
537  float getValue(const Window& wnd) const;
538  float getValue(const Window& wnd, const Rectf& container) const;
539  BaseDim* clone() const;
540 
541 protected:
542  // Implementation of the base class interface
543  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
544  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
545 
546  const Font* getFontObject(const Window& window) const;
547 
548 private:
550  String d_font;
552  String d_text;
554  String d_childName;
556  FontMetricType d_metric;
558  float d_padding;
559 };
560 
566 class CEGUIEXPORT PropertyDim : public BaseDim
567 {
568 public:
569  PropertyDim() {};
595  PropertyDim(const String& name, const String& property, DimensionType type);
603  const String& getWidgetName() const;
604 
615  void setWidgetName(const String& name);
616 
624  const String& getPropertyName() const;
625 
636  void setPropertyName(const String& property);
637 
650  DimensionType getSourceDimension() const;
651 
664  void setSourceDimension(DimensionType dim);
665 
666  // Implementation of the base class interface
667  float getValue(const Window& wnd) const;
668  float getValue(const Window& wnd, const Rectf& container) const;
669  BaseDim* clone() const;
670 
671 protected:
672  // Implementation of the base class interface
673  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
674  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
675 
676 private:
678  String d_property;
680  String d_childName;
682  DimensionType d_type;
683 };
684 
693 class CEGUIEXPORT Dimension :
694  public AllocatedObject<Dimension>
695 {
696 public:
697  Dimension();
698  ~Dimension();
699  Dimension(const Dimension& other);
700  Dimension& operator=(const Dimension& other);
701 
712  Dimension(const BaseDim& dim, DimensionType type);
713 
722  const BaseDim& getBaseDimension() const;
723 
731  void setBaseDimension(const BaseDim& dim);
732 
740  DimensionType getDimensionType() const;
741 
749  void setDimensionType(DimensionType type);
750 
758  void writeXMLToStream(XMLSerializer& xml_stream) const;
759 
761  bool handleFontRenderSizeChange(Window& window,
762  const Font* font) const;
763 
764 private:
766  BaseDim* d_value;
768  DimensionType d_type;
769 };
770 
780 class CEGUIEXPORT ComponentArea :
781  public AllocatedObject<ComponentArea>
782 {
783 public:
784  ComponentArea();
785 
799  Rectf getPixelRect(const Window& wnd) const;
800 
818  Rectf getPixelRect(const Window& wnd, const Rectf& container) const;
819 
827  void writeXMLToStream(XMLSerializer& xml_stream) const;
828 
838  bool isAreaFetchedFromProperty() const;
839 
848  const String& getAreaPropertySource() const;
849 
862  void setAreaPropertySource(const String& property);
863 
871  const String& getNamedAreaSourceLook() const;
872 
874  void setNamedAreaSouce(const String& widget_look, const String& area_name);
875 
885  bool isAreaFetchedFromNamedArea() const;
886 
888  bool handleFontRenderSizeChange(Window& window, const Font* font) const;
889 
898 
899 private:
901  String d_namedSource;
903  String d_namedAreaSourceLook;
904 };
905 
906 } // End of CEGUI namespace section
907 
908 
909 #endif // end of guard _CEGUIFalDimensions_h_
910 
Dimension d_bottom_or_height
Either the bototm edge or the height of the area.
Definition: Dimensions.h:897
Abstract interface for a generic 'dimension' class.
Definition: Dimensions.h:40
Definition: MemoryAllocatedObject.h:109
String d_imageName
name of the Image.
Definition: Dimensions.h:271
Interface for Image.
Definition: Image.h:158
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Class representing some kind of dimension.
Definition: Dimensions.h:693
DimensionOperator
Enumeration of values representing mathematical operations on dimensions.
Definition: Enums.h:122
Class that represents a target area for a widget or imagery component.
Definition: Dimensions.h:780
DimensionType d_what
the dimension of the image that we are to represent.
Definition: Dimensions.h:246
Dimension type that represents some dimension of a Window/widget. Implements BaseDim interface...
Definition: Dimensions.h:323
Dimension type that represents some dimension of an Image. Implements BaseDim interface.
Definition: Dimensions.h:199
ImageDimBase subclass that accesses an image by its name.
Definition: Dimensions.h:250
Dimension d_right_or_width
Either the right edge or the width of the area.
Definition: Dimensions.h:895
ImageDimBase subclass that accesses an image fetched via a property.
Definition: Dimensions.h:275
String d_propertyName
name of the property from which to fetch the image name.
Definition: Dimensions.h:310
Class that encapsulates a typeface.
Definition: Font.h:58
DimensionType
Enumeration of possible values to indicate what a given dimension represents.
Definition: Enums.h:39
Dimension type that represents some metric of a Font. Implements BaseDim interface.
Definition: Dimensions.h:471
Dimension type that represents an absolute pixel value. Implements BaseDim interface.
Definition: Dimensions.h:167
Dimension d_left
Left edge of the area.
Definition: Dimensions.h:891
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:149
Dimension type that represents the result of an operation performed on two other dimension values...
Definition: Dimensions.h:116
Dimension d_top
Top edge of the area.
Definition: Dimensions.h:893
Dimension that has both a relative 'scale' portion and and absolute 'offset' portion.
Definition: UDim.h:92
Class used to create XML Document.
Definition: XMLSerializer.h:85
Dimension type that represents the value of a Window property. Implements BaseDim interface...
Definition: Dimensions.h:566
FontMetricType
Enumeration of possible values to indicate a particular font metric.
Definition: Enums.h:111
String class used within the GUI system.
Definition: String.h:62
Dimension type that represents an Unified dimension. Implements BaseDim interface.
Definition: Dimensions.h:403