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
CzUISlider.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_SLIDER_H_)
00015 #define _CCZ_UI_SLIDER_H_
00016 
00017 #include "CzUIBase.h"
00018 #include "CzScene.h"
00019 #include "CzBrush.h"
00020 #include "CzInput.h"
00021 
00022 //
00023 //
00024 //
00025 //
00026 // CzUISlider - UI class that allows the user to select a value using a sliding scale (horizontal, vertical and round)
00027 //
00028 //
00029 //
00030 //
00031 
00032 
00033 class CzUISlider : public CzUIBase
00034 {
00035 public:
00036     enum eSliderType
00037     {
00038         SliderType_Horizontal, 
00039         SliderType_Vertical, 
00040     };
00041 
00042     // Properties
00043 protected:
00044     eSliderType             SliderType;             // Type of slider
00045     float                   Value;                  // Position of thumb within the range
00046     CzVec2                  ValueRange;             // The tange of the thumb
00047     int                     OriginalSliderSize;     // Original size of slider
00048     int                     SliderSize;             // Size of slider
00049 public:
00050     void                    setValue(float pos, bool affect_thumb);
00051     float                   getValue() const                { return Value; }
00052     void                    setValueRange(CzVec2& range);
00053     CzVec2                  getValueRange() const           { return ValueRange; }
00054     void                    setSliderType(eSliderType type);
00055     eSliderType             getSliderType() const           { return SliderType; }
00056     void                    setSliderSize(int size);
00057     int                     getSliderSize() const           { return SliderSize; }
00058 
00059     bool                    setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00060     bool                    setProperty(unsigned int property_name, const CzString& data, bool delta);
00061     bool                    getProperty(unsigned int property_name, CzXomlProperty& prop);
00062     // Properties end
00063 protected:
00064     bool                    ThumbChanged;           // True when slidee value changed
00065     bool                    UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00066     void                    UpdateSliderSize();
00067         
00068 public:
00069 
00070     CzUISlider() : CzUIBase(), Value(0), ValueRange(0, 1.0f), SliderType(SliderType_Horizontal), SliderSize(0), ThumbChanged(false) { IsDraggable = true; HoldFocus = true; }
00071 
00072     bool                Update(float dt);
00073 
00074     // Event handlers
00075     void                NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation);
00076     void                NotifyBeginTouch(int index, int x, int y, bool allow_bubble = true);
00077     void                NotifyEndTouch(int index, int x, int y, bool allow_bubble = true);
00078     virtual void        NotifyValueChanged(float old_value, float new_value);
00079 
00080     // Implementation of IzXomlClass interface
00081     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00082 
00083     // Implementation of IzAnimTarget interface
00084     bool                UpdateFromAnimation(CzAnimInstance *animation);
00085 
00086     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00087 protected:
00088     static CzXomlClassDef*  UISliderClassDef;                               // XOML class definition
00089 public:
00090     static void             InitClass();
00091     static void             ReleaseClass();
00092 
00093     static bool             _setSliderType(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00094     static CzXomlProperty   _getSliderType(IzXomlResource* target);
00095     static bool             _setValue(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00096     static CzXomlProperty   _getValue(IzXomlResource* target);
00097     static bool             _setValueRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00098     static CzXomlProperty   _getValueRange(IzXomlResource* target);
00099     static bool             _setSliderSize(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00100     static CzXomlProperty   _getSliderSize(IzXomlResource* target);
00101     static bool             _setOnValueChanged(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00102 
00103 };
00104 
00105 //
00106 //  CzUISliderCreator - Creates an instance of a Slider UI actor object
00107 //
00108 class CzUISliderCreator : public IzXomlClassCreator
00109 {
00110 public:
00111     CzUISliderCreator()
00112     {
00113         setClassName("slider");
00114     }
00115     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzUISlider(); }
00116 };
00117 
00118 #endif  // _CCZ_UI_SLIDER_H_
00119