AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzUILabel.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_UI_LABEL_H_)
00015 #define _CCZ_UI_LABEL_H_
00016 
00017 #include "CzUIBase.h"
00018 #include "CzActorText.h"
00019 
00020 
00021 //
00022 //
00023 //
00024 //
00025 // CzUILabel - A text based actor that acts as a label
00026 //
00027 //
00028 //
00029 //
00030 class CzUILabel : public CzUIBase
00031 {
00032     // Properties
00033 protected:
00034     CzActorText*    TextActor;
00035     CzColour        TextColour;
00036     CzString        Text;
00037     CzColour        SelectedTextColour;
00038     CzString        SelectedText;
00039     CzColour        DisabledTextColour;
00040     CzString        DisabledText;
00041 public:
00042     CzActorText*    getTextActor()                                  { return TextActor; }
00043     void            setTextColour(const CzColour& colour);
00044     CzColour        getTextColour() const                           { return TextColour; }
00045     void            setText(const char* text);
00046     CzString&       getText()                                       { return Text; }
00047     void            setSelectedTextColour(const CzColour& colour);
00048     CzColour        getSelectedTextColour() const                   { return SelectedTextColour; }
00049     void            setSelectedText(const char* text);
00050     CzString&       getSelectedText()                               { return SelectedText; }
00051     void            setDisabledTextColour(const CzColour& colour);
00052     CzColour        getDisabledTextColour() const                   { return DisabledTextColour; }
00053     void            setDisabledText(const char* text);
00054     CzString&       getDisabledText()                               { return DisabledText; }
00055     void            setEnabled(bool enabled);
00056     bool            setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00057     bool            setProperty(unsigned int property_name, const CzString& data, bool delta);
00058     bool            getProperty(unsigned int property_name, CzXomlProperty& prop);
00059     void            setIgnoreCamera(bool enable);
00060     // Properties end
00061 protected:
00062     void            UpdateSizeFromText();
00063     bool            UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00064 public:
00065     CzUILabel();
00066 
00067     virtual bool    InitTextActor(CzFont* font, const CzIRect& rect, const CzString& text, bool auto_height = false, bool text_use_parent_opacity = false, bool filter = true);
00068     virtual bool    InitTextActor(CzFont* font, const CzIRect& rect, const CzString& text, int flags, eCzAlignH align_h, eCzAlignV align_v, const CzVec4& skew, const CzIRect& text_margin, 
00069                     bool auto_height, bool text_use_parent_opacity = false, bool filter = true);
00070     void            SetFromBrush(IzBrush* brush, bool resize = false);
00071 
00072     bool            Update(float dt);
00073 
00074     // Event handlers
00075 
00076     // Implementation of IzXomlClass interface
00077     int             LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00078 
00079     // Implementation of IzAnimTarget interface
00080     bool            UpdateFromAnimation(CzAnimInstance *animation);
00081 
00082     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00083 protected:
00084     static CzXomlClassDef*  LabelClassDef;                              // XOML class definition
00085 public:
00086     static void             InitClass();
00087     static void             ReleaseClass();
00088 
00089     static bool             _setText(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00090     static CzXomlProperty   _getText(IzXomlResource* target);
00091     static bool             _setSelectedText(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00092     static CzXomlProperty   _getSelectedText(IzXomlResource* target);
00093     static bool             _setDisabledText(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00094     static CzXomlProperty   _getDisabledText(IzXomlResource* target);
00095     static bool             _setTextColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00096     static CzXomlProperty   _getTextColour(IzXomlResource* target);
00097     static bool             _setSelectedTextColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00098     static CzXomlProperty   _getSelectedTextColour(IzXomlResource* target);
00099     static bool             _setDisabledTextColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00100     static CzXomlProperty   _getDisabledTextColour(IzXomlResource* target);
00101     static bool             _setAlignH(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00102     static bool             _setAlignV(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00103     static bool             _setWrap(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00104     static bool             _setTextSkew(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00105     static CzXomlProperty   _getTextSkew(IzXomlResource* target);
00106     static bool             _setTextMargin(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00107     static CzXomlProperty   _getTextMargin(IzXomlResource* target);
00108     static bool             _setRect(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00109     static CzXomlProperty   _getRect(IzXomlResource* target);
00110     static bool             _setAutoHeight(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00111     static CzXomlProperty   _getAutoHeight(IzXomlResource* target);
00112     static bool             _setTextFilter(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00113     static CzXomlProperty   _getTextFilter(IzXomlResource* target);
00114     static CzXomlProperty   _getActorText(IzXomlResource* target);
00115     static CzXomlProperty   _getTextSize(IzXomlResource* target);
00116 };
00117 
00118 //
00119 //  CzUILabelCreator - Creates an instance of a label actor object
00120 //
00121 class CzUILabelCreator : public IzXomlClassCreator
00122 {
00123 public:
00124     CzUILabelCreator()
00125     {
00126         setClassName("label");
00127     }
00128     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzUILabel(); }
00129 };
00130 
00131 //
00132 //
00133 //
00134 //
00135 //  Helper macros
00136 //
00137 //
00138 //
00139 //
00140 #define CZ_NEW_LABEL(scene, label, name, text, background, font, size, auto_height) \
00141     CzUILabel* label = new CzUILabel();                                             \
00142     label->setName(name);                                                           \
00143     scene->addActor(label);                                                         \
00144     label->Init(background, size.x, size.y);                                        \
00145     {                                                                               \
00146         CzIRect rc = CzIRect(0, 0, -100, -100);                                     \
00147         label->InitTextActor(font, rc, text, auto_height);                          \
00148     }
00149 
00150 #endif  // _CCZ_UI_LABEL_H_