Crazy Eddie's GUI System  0.8.4
Dimensions.h
00001 /***********************************************************************
00002     created:    Mon Jun 13 2005
00003     author:     Paul D Turner <paul@cegui.org.uk>
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2012 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 _CEGUIFalDimensions_h_
00028 #define _CEGUIFalDimensions_h_
00029 
00030 #include "./Enums.h"
00031 #include "../String.h"
00032 #include "../UDim.h"
00033 #include "../Rect.h"
00034 #include "../XMLSerializer.h"
00035 
00036 // Start of CEGUI namespace section
00037 namespace CEGUI
00038 {
00040 class CEGUIEXPORT BaseDim :
00041     public AllocatedObject<BaseDim>
00042 {
00043 public:
00044     BaseDim();
00045 
00046     virtual ~BaseDim();
00047 
00059     virtual float getValue(const Window& wnd) const = 0;
00060 
00078     virtual float getValue(const Window& wnd, const Rectf& container) const = 0;
00079 
00089     virtual BaseDim* clone() const = 0;
00090 
00098     virtual void writeXMLToStream(XMLSerializer& xml_stream) const;
00099 
00101     virtual bool handleFontRenderSizeChange(Window& window,
00102                                             const Font* font) const;
00103 protected:
00105     virtual void writeXMLElementName_impl(XMLSerializer& xml_stream) const = 0;
00106 
00108     virtual void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const = 0;
00109 };
00110 
00116 class CEGUIEXPORT OperatorDim : public BaseDim
00117 {
00118 public:
00119     OperatorDim();
00120     OperatorDim(DimensionOperator op);
00121     OperatorDim(DimensionOperator op, BaseDim* left, BaseDim* right);
00122     ~OperatorDim();
00123 
00125     void setLeftOperand(const BaseDim* operand);
00126 
00128     BaseDim* getLeftOperand() const;
00129 
00131     void setRightOperand(const BaseDim* operand);
00132 
00134     BaseDim* getRightOperand() const;
00135 
00137     void setOperator(DimensionOperator op);
00138 
00140     DimensionOperator getOperator() const;
00141 
00143     void setNextOperand(const BaseDim* operand);
00144 
00145     // Implementation of the base class interface
00146     float getValue(const Window& wnd) const;
00147     float getValue(const Window& wnd, const Rectf& container) const;
00148     BaseDim* clone() const;
00149 
00150 protected:
00151     float getValueImpl(const float lval, const float rval) const;
00152     // Implementation of the base class interface
00153     void writeXMLToStream(XMLSerializer& xml_stream) const;
00154     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00155     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00156 
00157     BaseDim* d_left;
00158     BaseDim* d_right;
00159     DimensionOperator d_op;
00160 };
00161 
00167 class CEGUIEXPORT AbsoluteDim : public BaseDim
00168 {
00169 public:
00170     AbsoluteDim() {};
00171     AbsoluteDim(float val);
00172 
00174     float getBaseValue() const;
00175 
00177     void setBaseValue(float val);
00178 
00179     // Implementation of the base class interface
00180     float getValue(const Window& wnd) const;
00181     float getValue(const Window& wnd, const Rectf& container) const;
00182     BaseDim* clone() const;
00183 
00184 protected:
00185     // Implementation of the base class interface
00186     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00187     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00188 
00189 private:
00191     float d_val;
00192 };
00193 
00199 class CEGUIEXPORT ImageDimBase : public BaseDim
00200 {
00201 public:
00202     ImageDimBase() {};
00203 
00212     ImageDimBase(DimensionType dim);
00213 
00222     DimensionType getSourceDimension() const;
00223 
00232     void setSourceDimension(DimensionType dim);
00233 
00234     // Implementation of the base class interface
00235     float getValue(const Window& wnd) const;
00236     float getValue(const Window& wnd, const Rectf& container) const;
00237 
00238 protected:
00240     virtual const Image* getSourceImage(const Window& wnd) const = 0;
00241 
00242     // Implementation of the base class interface
00243     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00244 
00246     DimensionType d_what;
00247 };
00248 
00250 class CEGUIEXPORT ImageDim : public ImageDimBase
00251 {
00252 public:
00253     ImageDim() {};
00254     ImageDim(const String& image_name, DimensionType dim);
00255 
00257     const String& getSourceImage() const;
00259     void setSourceImage(const String& image_name);
00260 
00261     // Implementation of the base class interface
00262     BaseDim* clone() const;
00263 
00264 protected:
00265     // Implementation / overrides of functions in superclasses
00266     const Image* getSourceImage(const Window& wnd) const;
00267     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00268     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00269 
00271     String d_imageName;
00272 };
00273 
00275 class CEGUIEXPORT ImagePropertyDim : public ImageDimBase
00276 {
00277 public:
00278     ImagePropertyDim() {};
00279 
00293     ImagePropertyDim(const String& property_name, DimensionType dim);
00294 
00296     const String& getSourceProperty() const;
00298     void setSourceProperty(const String& property_name);
00299 
00300     // Implementation of the base class interface
00301     BaseDim* clone() const;
00302 
00303 protected:
00304     // Implementation / overrides of functions in superclasses
00305     const Image* getSourceImage(const Window& wnd) const;
00306     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00307     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00308 
00310     String d_propertyName;
00311 };
00312 
00323 class CEGUIEXPORT WidgetDim : public BaseDim
00324 {
00325 public:
00326     WidgetDim() {};
00338     WidgetDim(const String& name, DimensionType dim);
00339 
00347     const String& getWidgetName() const;
00348 
00359     void setWidgetName(const String& name);
00360 
00369     DimensionType getSourceDimension() const;
00370 
00379     void setSourceDimension(DimensionType dim);
00380 
00381     // Implementation of the base class interface
00382     float getValue(const Window& wnd) const;
00383     float getValue(const Window& wnd, const Rectf& container) const;
00384     BaseDim* clone() const;
00385 
00386 protected:
00387     // Implementation of the base class interface
00388     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00389     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00390 
00391 private:
00393     String d_widgetName;
00395     DimensionType d_what;
00396 };
00397 
00403 class CEGUIEXPORT UnifiedDim : public BaseDim
00404 {
00405 public:
00406     UnifiedDim(){};
00419     UnifiedDim(const UDim& value, DimensionType dim);
00420 
00422     const UDim& getBaseValue() const;
00423 
00425     void setBaseValue(const UDim& val);
00426 
00436     DimensionType getSourceDimension() const;
00437 
00447     void setSourceDimension(DimensionType dim);
00448 
00449     // Implementation of the base class interface
00450     float getValue(const Window& wnd) const;
00451     float getValue(const Window& wnd, const Rectf& container) const;
00452     BaseDim* clone() const;
00453 
00454 protected:
00455     // Implementation of the base class interface
00456     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00457     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00458 
00459 private:
00461     UDim d_value;
00463     DimensionType d_what;
00464 };
00465 
00471 class CEGUIEXPORT FontDim : public BaseDim
00472 {
00473 public:
00474     FontDim() {};
00499     FontDim(const String& name, const String& font, const String& text,
00500             FontMetricType metric, float padding = 0);
00501 
00503     const String& getName() const;
00504 
00506     void setName(const String& name);
00507 
00509     const String& getFont() const;
00510 
00512     void setFont(const String& font);
00513 
00515     const String& getText() const;
00516 
00518     void setText(const String& text);
00519 
00521     FontMetricType getMetric() const;
00522 
00524     void setMetric(FontMetricType metric);
00525 
00527     float getPadding() const;
00528 
00530     void setPadding(float padding);
00531 
00532     // overridden from BaseDim.
00533     bool handleFontRenderSizeChange(Window& window,
00534                                     const Font* font) const;
00535 
00536     // Implementation of the base class interface
00537     float getValue(const Window& wnd) const;
00538     float getValue(const Window& wnd, const Rectf& container) const;
00539     BaseDim* clone() const;
00540 
00541 protected:
00542     // Implementation of the base class interface
00543     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00544     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00545 
00546     const Font* getFontObject(const Window& window) const;
00547 
00548 private:
00550     String d_font;
00552     String d_text;
00554     String d_childName;
00556     FontMetricType d_metric;
00558     float d_padding;
00559 };
00560 
00566 class CEGUIEXPORT PropertyDim : public BaseDim
00567 {
00568 public:
00569     PropertyDim() {};
00595     PropertyDim(const String& name, const String& property, DimensionType type);
00603     const String& getWidgetName() const;
00604 
00615     void setWidgetName(const String& name);
00616 
00624     const String& getPropertyName() const;
00625 
00636     void setPropertyName(const String& property);
00637 
00650     DimensionType getSourceDimension() const;
00651 
00664     void setSourceDimension(DimensionType dim);
00665 
00666     // Implementation of the base class interface
00667     float getValue(const Window& wnd) const;
00668     float getValue(const Window& wnd, const Rectf& container) const;
00669     BaseDim* clone() const;
00670 
00671 protected:
00672     // Implementation of the base class interface
00673     void writeXMLElementName_impl(XMLSerializer& xml_stream) const;
00674     void writeXMLElementAttributes_impl(XMLSerializer& xml_stream) const;
00675 
00676 private:
00678     String d_property;
00680     String d_childName;
00682     DimensionType d_type;
00683 };
00684 
00693 class CEGUIEXPORT Dimension :
00694     public AllocatedObject<Dimension>
00695 {
00696 public:
00697     Dimension();
00698     ~Dimension();
00699     Dimension(const Dimension& other);
00700     Dimension& operator=(const Dimension& other);
00701 
00712     Dimension(const BaseDim& dim, DimensionType type);
00713 
00722     const BaseDim& getBaseDimension() const;
00723 
00731     void setBaseDimension(const BaseDim& dim);
00732 
00740     DimensionType getDimensionType() const;
00741 
00749     void setDimensionType(DimensionType type);
00750 
00758     void writeXMLToStream(XMLSerializer& xml_stream) const;
00759 
00761     bool handleFontRenderSizeChange(Window& window,
00762                                     const Font* font) const;
00763 
00764 private:
00766     BaseDim* d_value;
00768     DimensionType d_type;
00769 };
00770 
00780 class CEGUIEXPORT ComponentArea :
00781     public AllocatedObject<ComponentArea>
00782 {
00783 public:
00784     ComponentArea();
00785 
00799     Rectf getPixelRect(const Window& wnd) const;
00800 
00818     Rectf getPixelRect(const Window& wnd, const Rectf& container) const;
00819 
00827     void writeXMLToStream(XMLSerializer& xml_stream) const;
00828 
00838     bool isAreaFetchedFromProperty() const;
00839 
00848     const String& getAreaPropertySource() const;
00849 
00862     void setAreaPropertySource(const String& property);
00863 
00865     void setNamedAreaSouce(const String& widget_look, const String& area_name);
00866 
00876     bool isAreaFetchedFromNamedArea() const;
00877 
00879     bool handleFontRenderSizeChange(Window& window, const Font* font) const;
00880 
00882     Dimension d_left;
00884     Dimension d_top;
00886     Dimension d_right_or_width;
00888     Dimension d_bottom_or_height;
00889 
00890 private:
00892     String d_namedSource;
00894     String d_namedAreaSourceLook;
00895 };
00896 
00897 } // End of  CEGUI namespace section
00898 
00899 
00900 #endif  // end of guard _CEGUIFalDimensions_h_
00901 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends