Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Dimensions.h
1 /***********************************************************************
2  filename: CEGUIDimensions.h
3  created: Mon Jun 13 2005
4  author: Paul D Turner <paul@cegui.org.uk>
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2012 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 _CEGUIFalDimensions_h_
29 #define _CEGUIFalDimensions_h_
30 
31 #include "./Enums.h"
32 #include "../String.h"
33 #include "../UDim.h"
34 #include "../Rect.h"
35 #include "../XMLSerializer.h"
36 
37 // Start of CEGUI namespace section
38 namespace CEGUI
39 {
41 class CEGUIEXPORT BaseDim :
42  public AllocatedObject<BaseDim>
43 {
44 public:
45  BaseDim();
46 
47  virtual ~BaseDim();
48 
60  virtual float getValue(const Window& wnd) const = 0;
61 
79  virtual float getValue(const Window& wnd, const Rectf& container) const = 0;
80 
90  virtual BaseDim* clone() const = 0;
91 
99  virtual void writeXMLToStream(XMLSerializer& xml_stream) const;
100 
102  virtual bool handleFontRenderSizeChange(Window& window,
103  const Font* font) const;
104 protected:
106  virtual void writeXMLElementName_impl(XMLSerializer& xml_stream) const = 0;
107 
109  virtual void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const = 0;
110 };
111 
117 class CEGUIEXPORT OperatorDim : public BaseDim
118 {
119 public:
120  OperatorDim();
122  OperatorDim(DimensionOperator op, BaseDim* left, BaseDim* right);
123  ~OperatorDim();
124 
126  void setLeftOperand(const BaseDim* operand);
127 
129  BaseDim* getLeftOperand() const;
130 
132  void setRightOperand(const BaseDim* operand);
133 
135  BaseDim* getRightOperand() const;
136 
138  void setOperator(DimensionOperator op);
139 
141  DimensionOperator getOperator() const;
142 
144  void setNextOperand(const BaseDim* operand);
145 
146  // Implementation of the base class interface
147  float getValue(const Window& wnd) const;
148  float getValue(const Window& wnd, const Rectf& container) const;
149  BaseDim* clone() const;
150 
151 protected:
152  float getValueImpl(const float lval, const float rval) const;
153  // Implementation of the base class interface
154  void writeXMLToStream(XMLSerializer& xml_stream) const;
155  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
156  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
157 
158  BaseDim* d_left;
159  BaseDim* d_right;
160  DimensionOperator d_op;
161 };
162 
168 class CEGUIEXPORT AbsoluteDim : public BaseDim
169 {
170 public:
171  AbsoluteDim() {};
172  AbsoluteDim(float val);
173 
175  float getBaseValue() const;
176 
178  void setBaseValue(float val);
179 
180  // Implementation of the base class interface
181  float getValue(const Window& wnd) const;
182  float getValue(const Window& wnd, const Rectf& container) const;
183  BaseDim* clone() const;
184 
185 protected:
186  // Implementation of the base class interface
187  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
188  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
189 
190 private:
192  float d_val;
193 };
194 
200 class CEGUIEXPORT ImageDimBase : public BaseDim
201 {
202 public:
203  ImageDimBase() {};
204 
214 
223  DimensionType getSourceDimension() const;
224 
233  void setSourceDimension(DimensionType dim);
234 
235  // Implementation of the base class interface
236  float getValue(const Window& wnd) const;
237  float getValue(const Window& wnd, const Rectf& container) const;
238 
239 protected:
241  virtual const Image* getSourceImage(const Window& wnd) const = 0;
242 
243  // Implementation of the base class interface
244  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
245 
248 };
249 
251 class CEGUIEXPORT ImageDim : public ImageDimBase
252 {
253 public:
254  ImageDim() {};
255  ImageDim(const String& image_name, DimensionType dim);
256 
258  const String& getSourceImage() const;
260  void setSourceImage(const String& image_name);
261 
262  // Implementation of the base class interface
263  BaseDim* clone() const;
264 
265 protected:
266  // Implementation / overrides of functions in superclasses
267  const Image* getSourceImage(const Window& wnd) const;
268  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
269  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
270 
273 };
274 
276 class CEGUIEXPORT ImagePropertyDim : public ImageDimBase
277 {
278 public:
279  ImagePropertyDim() {};
280 
294  ImagePropertyDim(const String& property_name, DimensionType dim);
295 
297  const String& getSourceProperty() const;
299  void setSourceProperty(const String& property_name);
300 
301  // Implementation of the base class interface
302  BaseDim* clone() const;
303 
304 protected:
305  // Implementation / overrides of functions in superclasses
306  const Image* getSourceImage(const Window& wnd) const;
307  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
308  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
309 
312 };
313 
324 class CEGUIEXPORT WidgetDim : public BaseDim
325 {
326 public:
327  WidgetDim() {};
339  WidgetDim(const String& name, DimensionType dim);
340 
348  const String& getWidgetName() const;
349 
360  void setWidgetName(const String& name);
361 
370  DimensionType getSourceDimension() const;
371 
380  void setSourceDimension(DimensionType dim);
381 
382  // Implementation of the base class interface
383  float getValue(const Window& wnd) const;
384  float getValue(const Window& wnd, const Rectf& container) const;
385  BaseDim* clone() const;
386 
387 protected:
388  // Implementation of the base class interface
389  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
390  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
391 
392 private:
394  String d_widgetName;
396  DimensionType d_what;
397 };
398 
404 class CEGUIEXPORT UnifiedDim : public BaseDim
405 {
406 public:
407  UnifiedDim(){};
420  UnifiedDim(const UDim& value, DimensionType dim);
421 
423  const UDim& getBaseValue() const;
424 
426  void setBaseValue(const UDim& val);
427 
437  DimensionType getSourceDimension() const;
438 
448  void setSourceDimension(DimensionType dim);
449 
450  // Implementation of the base class interface
451  float getValue(const Window& wnd) const;
452  float getValue(const Window& wnd, const Rectf& container) const;
453  BaseDim* clone() const;
454 
455 protected:
456  // Implementation of the base class interface
457  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
458  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
459 
460 private:
462  UDim d_value;
464  DimensionType d_what;
465 };
466 
472 class CEGUIEXPORT FontDim : public BaseDim
473 {
474 public:
475  FontDim() {};
500  FontDim(const String& name, const String& font, const String& text,
501  FontMetricType metric, float padding = 0);
502 
504  const String& getName() const;
505 
507  void setName(const String& name);
508 
510  const String& getFont() const;
511 
513  void setFont(const String& font);
514 
516  const String& getText() const;
517 
519  void setText(const String& text);
520 
522  FontMetricType getMetric() const;
523 
525  void setMetric(FontMetricType metric);
526 
528  float getPadding() const;
529 
531  void setPadding(float padding);
532 
533  // overridden from BaseDim.
534  bool handleFontRenderSizeChange(Window& window,
535  const Font* font) const;
536 
537  // Implementation of the base class interface
538  float getValue(const Window& wnd) const;
539  float getValue(const Window& wnd, const Rectf& container) const;
540  BaseDim* clone() const;
541 
542 protected:
543  // Implementation of the base class interface
544  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
545  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
546 
547  const Font* getFontObject(const Window& window) const;
548 
549 private:
551  String d_font;
553  String d_text;
555  String d_childName;
557  FontMetricType d_metric;
559  float d_padding;
560 };
561 
567 class CEGUIEXPORT PropertyDim : public BaseDim
568 {
569 public:
570  PropertyDim() {};
596  PropertyDim(const String& name, const String& property, DimensionType type);
604  const String& getWidgetName() const;
605 
616  void setWidgetName(const String& name);
617 
625  const String& getPropertyName() const;
626 
637  void setPropertyName(const String& property);
638 
651  DimensionType getSourceDimension() const;
652 
665  void setSourceDimension(DimensionType dim);
666 
667  // Implementation of the base class interface
668  float getValue(const Window& wnd) const;
669  float getValue(const Window& wnd, const Rectf& container) const;
670  BaseDim* clone() const;
671 
672 protected:
673  // Implementation of the base class interface
674  void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
675  void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
676 
677 private:
679  String d_property;
681  String d_childName;
683  DimensionType d_type;
684 };
685 
694 class CEGUIEXPORT Dimension :
695  public AllocatedObject<Dimension>
696 {
697 public:
698  Dimension();
699  ~Dimension();
700  Dimension(const Dimension& other);
701  Dimension& operator=(const Dimension& other);
702 
713  Dimension(const BaseDim& dim, DimensionType type);
714 
723  const BaseDim& getBaseDimension() const;
724 
732  void setBaseDimension(const BaseDim& dim);
733 
741  DimensionType getDimensionType() const;
742 
750  void setDimensionType(DimensionType type);
751 
759  void writeXMLToStream(XMLSerializer& xml_stream) const;
760 
762  bool handleFontRenderSizeChange(Window& window,
763  const Font* font) const;
764 
765 private:
767  BaseDim* d_value;
769  DimensionType d_type;
770 };
771 
781 class CEGUIEXPORT ComponentArea :
782  public AllocatedObject<ComponentArea>
783 {
784 public:
785  ComponentArea();
786 
800  Rectf getPixelRect(const Window& wnd) const;
801 
819  Rectf getPixelRect(const Window& wnd, const Rectf& container) const;
820 
828  void writeXMLToStream(XMLSerializer& xml_stream) const;
829 
839  bool isAreaFetchedFromProperty() const;
840 
849  const String& getAreaPropertySource() const;
850 
863  void setAreaPropertySource(const String& property);
864 
866  void setNamedAreaSouce(const String& widget_look, const String& area_name);
867 
877  bool isAreaFetchedFromNamedArea() const;
878 
880  bool handleFontRenderSizeChange(Window& window, const Font* font) const;
881 
890 
891 private:
893  String d_namedSource;
895  String d_namedAreaSourceLook;
896 };
897 
898 } // End of CEGUI namespace section
899 
900 
901 #endif // end of guard _CEGUIFalDimensions_h_
902