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
CzUIBase.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_H_)
00015 #define _CCZ_UI_H_
00016 
00017 #include "CzActorImage.h"
00018 #include "CzScene.h"
00019 #include "CzBrush.h"
00020 #include "CzInput.h"
00021 #include "CzAnim.h"
00022 
00023 /**
00024  @class CzUIBase
00025 
00026  @brief Base class of all UI components.
00027 
00028  CzUIBase is the basic class that all UI actors are derived from. CzUIBase appends additional functionality to the normal image actor such as:
00029  - Selected, normal and disabled states
00030  - Individual brushes amd colours for each of the 3 states
00031  - Toggle state
00032  - Hide and show timelines
00033  - Automatic re-sizing to contents
00034  - Content scrolling
00035  - Content clipping
00036  - Colour offsetting
00037 
00038  All new user interface actors should be derived from this class or a derivative of this class.
00039 
00040  The following UI classes are derived from this base class:
00041  - CzUIIcon - An icon / image based button
00042  - CzUILabel - A text label that can display text and an image based background
00043  - CzUIGrid - A grid container that organises content in a columns and rows. Supports data binding
00044  - CzUIImageView - An image container with support for pinch zoom / pan
00045  - CzUIListBox - A list box container that stacks selectable content either vertically or horizontally that can be scrolled. Supports data binding
00046  - CzUICanvas - A container that organises docked and undocked content onto a 2D canvas that can be scrolled
00047  - CzUIStackPanel - A container that stacks content either vertically or horizontally
00048  - CzUIWrapPanel - A container that stacks content either vertically or horizontally, wrapping over hanging content to thenext row or column
00049  - CzUISlider - Enables the user to select a value by sliding a thumb either up / down or left / right
00050  - CzUITabBar - Enables navigation of a number of different views (container UI components such as the Canvas).
00051  - CzUITextBox - A text entry box with a background
00052  - CzUITextView - A text based container with support for pinch zoom / pan
00053  - CzUIVideoOverlay - Displays video overlays
00054  - CzUIWebView - Displays web content
00055 
00056  */
00057 
00058 class CzUIBase : public CzActorImage
00059 {
00060 public:
00061 
00062     /**
00063      @enum  eSelectType
00064     
00065      @brief Values that represent different types of selection modes.
00066      */
00067     enum eSelectType
00068     {
00069         SelectType_Normal, ///< Normal selection mode, the actor will remasin selected whilst it has touch focus.
00070         SelectType_Toggle, ///< Toggle selection mode, the actors sekected state will toggle on and off each time it is selected.
00071         SelectType_Sticky, ///< Sticky selection mode, the actors sekected state will remain selected once selected.
00072     };
00073 
00074     /**
00075      @enum  eAxis
00076     
00077      @brief Values that represent horizonal, vertical and both axis. 
00078      */
00079     enum eAxis
00080     {
00081         Axis_None,          ///< Affects no axis.
00082         Axis_X,             ///< Affects x axis.
00083         Axis_Y,             ///< Affects y axis.
00084         Axis_XY,            ///< Affects both x and y axis.
00085     };
00086     // Properties
00087 protected:
00088     bool                PrevSelected;                       ///< Previous Selected status
00089     bool                ToggledOn;                          ///< ToggledOn state
00090     bool                Selected;                           ///< Selected status
00091     IzBrush*            BackgroundBrush;                    ///< Default none selected brush
00092     CzColour            BackgroundColour;                   ///< Default none selected colour
00093     IzBrush*            SelectedBackgroundBrush;            ///< Selected brush
00094     CzColour            SelectedBackgroundColour;           ///< Selected colour
00095     IzBrush*            DisabledBackgroundBrush;            ///< Disabled brush
00096     CzColour            DisabledBackgroundColour;           ///< Disabled colour
00097     bool                Enabled;                            ///< Enabled state
00098     bool                LayoutDirty;                        ///< When true the layout of this element and any children is re-calculated
00099     eSelectType         SelectType;                         ///< Selection method used for this UI element
00100     CzIRect             OriginalClippingMargin;             ///< Original margin that is used to adjust the clipping rectangle
00101     CzIRect             ClippingMargin;                     ///< Margin that is used to adjust the clipping rectangle
00102     CzVec2              PreviousScrollPos;                  ///< Previous scroll position
00103     CzVec2              ScrollPos;                          ///< Current scroll position
00104     CzVec2              ScrollVelocity;                     ///< Current scroll velocity
00105     CzIRect             ScrollRange;                        ///< X and Y ranges of scroll
00106     bool                EnableSpring;                       ///< Enables drag release spring
00107     eAxis               SizeToContentAxis;                  ///< Determines if and how an element should size to its content
00108     CzAnimTimeline*     ShowTimeline;                       ///< Timeline to play when this UI element is made visible
00109     CzAnimTimeline*     HideTimeline;                       ///< Timeline to play when this UI element is made invisible
00110     bool                NeedsResize;                        ///< Set to true when child actors sizes have changed
00111     CzIRect             ColourOffset;                       ///< Amount to offset the current colour of the actor
00112 public:
00113     void                setVisible(bool visible, bool force_set = false);
00114     void                setBackgroundBrush(IzBrush* brush);
00115     IzBrush*            getBackgroundBrush() const                      { return BackgroundBrush; }
00116     void                setBackgroundColour(const CzColour& colour);
00117     CzColour            getBackgroundColour() const                     { return BackgroundColour; }
00118     void                setSelectedBackgroundBrush(IzBrush* brush);
00119     IzBrush*            getSelectedBackgroundBrush() const              { return SelectedBackgroundBrush; }
00120     void                setSelectedBackgroundColour(const CzColour& colour);
00121     CzColour            getSelectedBackgroundColour() const             { return SelectedBackgroundColour; }
00122     void                setDisabledBackgroundBrush(IzBrush* brush);
00123     IzBrush*            getDisabledBackgroundBrush() const              { return DisabledBackgroundBrush; }
00124     void                setDisabledBackgroundColour(const CzColour& colour);
00125     CzColour            getDisabledBackgroundColour() const             { return DisabledBackgroundColour; }
00126     void                setSelectType(eSelectType type)                 { SelectType = type; }
00127     eSelectType         getSelectType() const                           { return SelectType; }
00128     void                setSelected(bool selected, bool force_select = false);
00129     bool                isSelected() const                              { return Selected; }
00130     virtual void        setEnabled(bool enabled);
00131     bool                isEnabled() const                               { return Enabled; }
00132     bool                setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00133     bool                setProperty(unsigned int property_name, const CzString& data, bool delta);
00134     bool                getProperty(unsigned int property_name, CzXomlProperty& prop);
00135     void                setLayoutDirty(bool dirty);
00136     bool                isLayoutDirty() const                           { return LayoutDirty; }
00137     void                setClippingMargin(int x, int y, int w, int h)   { ClippingMargin.x = x; ClippingMargin.y = y; ClippingMargin.w = w; ClippingMargin.h = h; }
00138     CzIRect             getClippingMargin()                             { return ClippingMargin; }
00139     void                setScrollPos(float x, float y);
00140     CzVec2              getScrollPos() const                            { return ScrollPos; }
00141     CzVec2              getPreviousScrollPos() const                    { return PreviousScrollPos; }
00142     void                setScrollVelocity(float x, float y)             { ScrollVelocity.x = x; ScrollVelocity.y = y; }
00143     CzVec2              getScrollVelocity() const                       { return ScrollVelocity; }
00144     void                setScrollRange(int x, int y, int w, int h)      { ScrollRange.x = x; ScrollRange.y = y; ScrollRange.w = w; ScrollRange.h = h; } 
00145     CzIRect             getScrollRange() const                          { return ScrollRange; }
00146     void                setToggledOn(bool toggled_on);
00147     bool                isToggledOn() const                             { return ToggledOn; }
00148     void                setShowTimeline(CzAnimTimeline* timeline);
00149     CzAnimTimeline*     getShowTimeline() const                         { return ShowTimeline; }
00150     void                setHideTimeline(CzAnimTimeline* timeline);
00151     CzAnimTimeline*     getHideTimeline() const                         { return HideTimeline; }
00152     void                setNeedsResize(bool resize);
00153     bool                getNeedsResize() const                          { return NeedsResize; }
00154     void                setSizeToContentAxis(eAxis axis)                { SizeToContentAxis = axis; }
00155     eAxis               getSizeToContentAxis() const                    { return SizeToContentAxis; }
00156     void                NotifyParentsResize();
00157     void                setColourOffset(const CzIRect& offset)          { ColourOffset = offset; setEnabled(Enabled); }
00158     void                resetColourOffset()                             { ColourOffset.x = 0; ColourOffset.y = 0; ColourOffset.w = 0; ColourOffset.h = 0; setEnabled(Enabled); }
00159     CzIRect             getColourOffset() const                         { return ColourOffset; }
00160     void                setShowTimeline(const char* timeline_name);
00161     void                setHideTimeline(const char* timeline_name);
00162     void                setEnableSpring(bool enable)                    { EnableSpring = enable; }
00163     bool                getEnableSpring() const                         { return EnableSpring; }
00164     // Properties end
00165 protected:
00166     bool                Tapped;
00167     CzVec2              InitialScrollPos;
00168     bool                UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00169     virtual bool        UpdateLayout();                                 // Updates the layout of the child items
00170     bool                ScrollRangeCheck();
00171 
00172 public:
00173     CzUIBase();
00174     virtual ~CzUIBase();
00175     bool                Init(IzBrush* brush, int width, int height);
00176 
00177     bool                Update(float dt);
00178     virtual void        ResizeToContent();
00179 
00180     // Event handlers
00181     void                NotifyTapped(int index, int x, int y, bool allow_bubble);
00182     void                NotifyBeginTouch(int index, int x, int y, bool allow_bubble);
00183     void                NotifyEndTouch(int index, int x, int y, bool allow_bubble);
00184     virtual void        NotifyToggledOn();
00185     virtual void        NotifyToggledOff();
00186     virtual void        NotifyBackKey();
00187     virtual void        NotifyMenuKey();
00188     void                NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation);
00189 
00190     // Implementation of IzXomlClass interface
00191     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00192 
00193     // Implementation of IzAnimTarget interface
00194     bool                UpdateFromAnimation(CzAnimInstance *animation);
00195 
00196     // Preset UI animations
00197 public:
00198     static CzList<CzAnim*>  PresetAnimations;
00199     static void             InitPresetAnimations();
00200     static void             ReleasePresetAnimations();
00201     static void             UpdatePresetAnimations();
00202     static CzAnim*          FindPresetAnimation(unsigned int name_hash);
00203 
00204     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00205 protected:
00206     static CzXomlClassDef*  UIBaseClassDef;                             // XOML class definition
00207 
00208 public:
00209     static void             InitClass();
00210     static void             ReleaseClass();
00211 
00212     static bool             _setSize(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00213     static CzXomlProperty   _getSize(IzXomlResource* target);
00214     static bool             _setBackground(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00215     static CzXomlProperty   _getBackground(IzXomlResource *target);
00216     static bool             _setSelectedBackground(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00217     static CzXomlProperty   _getSelectedBackground(IzXomlResource *target);
00218     static bool             _setDisabledBackground(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00219     static CzXomlProperty   _getDisabledBackground(IzXomlResource *target);
00220     static bool             _setBackgroundColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00221     static CzXomlProperty   _getBackgroundColour(IzXomlResource *target);
00222     static bool             _setSelectedColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00223     static CzXomlProperty   _getSelectedColour(IzXomlResource *target);
00224     static bool             _setDisabledColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00225     static CzXomlProperty   _getDisabledColour(IzXomlResource *target);
00226     static bool             _setEnabled(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00227     static CzXomlProperty   _getEnabled(IzXomlResource *target);
00228     static bool             _setSelected(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00229     static CzXomlProperty   _getSelected(IzXomlResource *target);
00230     static bool             _setScrollPos(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00231     static CzXomlProperty   _getScrollPos(IzXomlResource *target);
00232     static bool             _setSelectType(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00233     static CzXomlProperty   _getSelectType(IzXomlResource *target);
00234     static bool             _setSpring(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00235     static CzXomlProperty   _getSpring(IzXomlResource *target);
00236     static bool             _setOnToggledOn(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00237     static bool             _setOnToggledOff(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00238     static bool             _setOnBackKey(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00239     static bool             _setOnMenuKey(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00240     static bool             _setClipMargin(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00241     static CzXomlProperty   _getClipMargin(IzXomlResource *target);
00242     static bool             _setScrollRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00243     static CzXomlProperty   _getScrollRange(IzXomlResource *target);
00244     static bool             _setShowTimeline(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00245     static CzXomlProperty   _getShowTimeline(IzXomlResource *target);
00246     static bool             _setHideTimeline(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00247     static CzXomlProperty   _getHideTimeline(IzXomlResource *target);
00248     static bool             _setSizeToContentAxis(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00249     static CzXomlProperty   _getSizeToContentAxis(IzXomlResource *target);
00250     static bool             _setKeyFocus(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00251     static CzXomlProperty   _getKeyFocus(IzXomlResource *target);
00252     static bool             _setToggledOn(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00253     static CzXomlProperty   _getToggledOn(IzXomlResource *target);
00254     static bool             _setColourOffset(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00255     static CzXomlProperty   _getColourOffset(IzXomlResource *target);
00256 
00257 };
00258 
00259 
00260 
00261 
00262 
00263 
00264 #endif  // _CCZ_UI_H_