![]() |
AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
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(_CZ_ACTOR_TEXT_H_) 00015 #define _CZ_ACTOR_TEXT_H_ 00016 00017 #include "CzActor.h" 00018 00019 00020 /** 00021 @addtogroup Actors 00022 @{ 00023 */ 00024 00025 /** 00026 @class CzActorText 00027 00028 @brief A text based actor that can display text. 00029 00030 Text actors can be created directly but are usually used in conjunction with some other actor. For example user interface controls usually host a text actor on an image actor that 00031 represents the background to the user interface control. Lets take a look at text actor properties: 00032 - Font (font) - Name of font to use to draw the text 00033 - Rect (x, y, width, height) - The area that the text should be drawn inside of. If not provided then the area will be calculated based on the screen size or the parent actor 00034 - Text (string) - String to display 00035 - AlignH (centre, left, right) - Horizontal alignment, default is centre 00036 - AlignV (middle, top, bottom) - Vertical alignment, default is middle 00037 - Wrap (boolean) - If true then text is wrapped onto next line if too long to fit on one line, if not then text will overhand its container 00038 - Skew (top, bottom, left, right) - Four parameter skewing, which allows the actor to be skewed in four different directions 00039 - BeforeChildren (boolean) - When set to true this actor will be rendered before its children, otherwise it will be rendered afterwards (default is true) 00040 - Filter (boolean) - When set to true this actor will rendered using filtering (default is true) 00041 - AlphaMode (alpha_mode) - Sets the mode to use when mixing transparency (alpha) from the actor. AlphaMode can be one of none, half, add, sub and blend (default mode is blend) 00042 - AutoHeight (boolean) - When set to true the height of the text actor will be recalculated to make it large enough to fit its text content. For example, if you set the original 00043 Rect to only hold a single line but the text takes 3 lines then the actor will be resized to fit all 3 lines of text (default is false). 00044 - Anchor (topleft or centre) - Sets the draw anchor (topleft causes the actor to be displayed relative to its top-left cornr whilst centre will use the actors centre) 00045 00046 Notes: 00047 - A font must be specified 00048 - Because a text actor inherits from a basic actor, it inherits all of the basic actors properties as well as those properties shown above. 00049 00050 Now lets take a quick look at a text actor definition in XOML: 00051 00052 @pat XOML Example 00053 @code 00054 <ActorText Font="serif" Text="Hello World" Position="10, 20" /> 00055 @endcode 00056 00057 */ 00058 00059 class CzActorText : public CzActor 00060 { 00061 public: 00062 // Properties 00063 protected: 00064 bool AutoHeight; ///< When true the contained text will decide the height of the text display rect 00065 bool MarginIsPadding; ///< if true then the margin parameter will be used as padding instead 00066 public: 00067 void setText(const char* text); 00068 const char* getText() const; 00069 void setRect(const CzIRect& rect); 00070 CzIRect getRect() const; 00071 void setFlags(eCzFontFlags flags); 00072 void setFont(CzFont* font); 00073 CzFont* getFont(); 00074 void setAlignH(eCzAlignH align); 00075 void setAlignV(eCzAlignV align); 00076 void setMarginIsPadding(bool enable) { MarginIsPadding = true; } 00077 bool setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta); 00078 bool setProperty(unsigned int property_name, const CzString& data, bool delta); 00079 bool getProperty(unsigned int property_name, CzXomlProperty& prop); 00080 void setAutoHeight(bool enable) { AutoHeight = enable; recalculateHeight(); } 00081 bool isAutoHeight() const { return AutoHeight; } 00082 bool isFontLoaded() const { return FontLoaded; } 00083 // Properties end 00084 protected: 00085 CzIRect OriginallRect; 00086 bool FontLoaded; 00087 bool UpdateBinding(unsigned int property_name, CzXomlVariable* var); 00088 void recalculateHeight(); 00089 00090 public: 00091 CzActorText() : CzActor(), AutoHeight(false), FontLoaded(false), MarginIsPadding(false) { setActualClassType("actortext"); IsTappable = false; } 00092 virtual ~CzActorText() {} 00093 00094 virtual bool Init(CzFont* font, const CzIRect& rect, const CzString& text, int flags); 00095 virtual bool UpdateVisual(); 00096 00097 // Event handlers 00098 virtual void NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation); 00099 00100 // Implementation of IzXomlClass interface 00101 int LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node); 00102 00103 // Implementation of IzAnimTarget interface 00104 bool UpdateFromAnimation(CzAnimInstance *animation); 00105 00106 // Internal (used by XOML system to setup and cleanup the XOML class properties system 00107 protected: 00108 static CzXomlClassDef* ActorTextClassDef; // XOML class definition 00109 00110 public: 00111 static void InitClass(); 00112 static void ReleaseClass(); 00113 00114 static bool _setText(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00115 static CzXomlProperty _getText(IzXomlResource* target); 00116 static bool _setFont(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00117 static CzXomlProperty _getFont(IzXomlResource* target); 00118 static bool _setRect(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00119 static CzXomlProperty _getRect(IzXomlResource* target); 00120 static bool _setAlignH(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00121 static bool _setAlignV(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00122 static bool _setWrap(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00123 static bool _setSkew(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00124 static CzXomlProperty _getSkew(IzXomlResource* target); 00125 static bool _setBeforeChildren(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00126 static CzXomlProperty _getBeforeChildren(IzXomlResource* target); 00127 static bool _setFilter(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00128 static CzXomlProperty _getFilter(IzXomlResource* target); 00129 static bool _setAutoHeight(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00130 static CzXomlProperty _getAutoHeight(IzXomlResource* target); 00131 static bool _setAlphaMode(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00132 static CzXomlProperty _getAlphaMode(IzXomlResource* target); 00133 static CzXomlProperty _getTextSize(IzXomlResource* target); 00134 00135 }; 00136 00137 00138 /// @} 00139 00140 /** 00141 @class CzActorTextCreator 00142 00143 @brief Creates an instance of a text based text actor object. 00144 00145 Used by the XOML system to instantiate a CzActorText object. 00146 00147 */ 00148 00149 class CzActorTextCreator : public IzXomlClassCreator 00150 { 00151 public: 00152 CzActorTextCreator() 00153 { 00154 setClassName("actortext"); 00155 } 00156 IzXomlResource* CreateInstance(IzXomlResource* parent) { return new CzActorText(); } 00157 }; 00158 00159 #endif // _CZ_ACTOR_TEXT_H_