X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.h;h=da2557fb7f95d92e6064af61072572ed5fd68d4f;hp=89f059159d00c7a2b3250d759a3e96fa2989adac;hb=958bd01cb1bc4cf43cbe740a7b041927d9d34ed6;hpb=2c8cb08997d878a5b08939cae7c109e4e7e1ede1 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index 89f0591..da2557f 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -43,232 +43,311 @@ namespace Internal class Button : public Control { -protected: - - /** - * Construct a new Button. - */ - Button(); - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~Button(); - public: /** - * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled ) + * @copydoc Dali::Toolkit::Button::SetDisabled */ void SetDisabled( bool disabled ); /** - * @copydoc Dali::Toolkit::Button::IsDisabled() const + * @copydoc Dali::Toolkit::Button::IsDisabled */ bool IsDisabled() const; /** - * @copydoc Dali::Toolkit::Button::SetAutoRepeating( bool autoRepeating ) + * @copydoc Dali::Toolkit::Button::SetAutoRepeating */ void SetAutoRepeating( bool autoRepeating ); /** - * @copydoc Dali::Toolkit::Button::IsAutoRepeating() const + * @copydoc Dali::Toolkit::Button::IsAutoRepeating */ bool IsAutoRepeating() const; /** - * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) + * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay */ void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ); /** - * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay() const + * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay */ float GetInitialAutoRepeatingDelay() const; /** - * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) + * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay */ void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ); /** - * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const + * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay */ float GetNextAutoRepeatingDelay() const; /** - * @copydoc Dali::Toolkit::Button::SetTogglableButton( bool togglable ) + * @copydoc Dali::Toolkit::Button::SetTogglableButton */ void SetTogglableButton( bool togglable ); /** - * @copydoc Dali::Toolkit::Button::IsTogglableButton() const + * @copydoc Dali::Toolkit::Button::IsTogglableButton */ bool IsTogglableButton() const; /** - * @copydoc Dali::Toolkit::Button::SetSelected( bool selected ) + * @copydoc Dali::Toolkit::Button::SetSelected */ void SetSelected( bool selected ); /** - * @copydoc Dali::Toolkit::Button::IsSelected() const + * @copydoc Dali::Toolkit::Button::IsSelected */ bool IsSelected() const; /** - * @copydoc Dali::Toolkit::Button::SetAnimationTime() + * @copydoc Dali::Toolkit::Button::SetAnimationTime */ void SetAnimationTime( float animationTime ); /** - * @copydoc Dali::Toolkit::Button::GetAnimationTime() + * @copydoc Dali::Toolkit::Button::GetAnimationTime */ float GetAnimationTime() const; /** - * @copydoc Dali::Toolkit::Button::SetLabel( const std::string& label ) + * @copydoc Dali::Toolkit::Button::SetLabelText */ - void SetLabel( const std::string& label ); + void SetLabelText( const std::string& label ); /** - * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) + * @copydoc Dali::Toolkit::Button::GetLabelText */ - void SetLabel( Actor label ); + std::string GetLabelText() const; /** - * @copydoc Dali::Toolkit::Button::GetLabel() + * @copydoc Dali::Toolkit::PushButton::SetUnselectedImage */ - Actor GetLabel() const; + void SetUnselectedImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image ) + * @copydoc Dali::Toolkit::PushButton::SetSelectedImage */ - void SetButtonImage( Actor image ); + void SetSelectedImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::PushButton::GetButtonImage() + * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage */ - Actor GetButtonImage() const; + void SetBackgroundImage( const std::string& filename ); /** - * Internal use only. - * @return A reference to the button image. + * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage */ - Actor& GetButtonImage(); + void SetSelectedBackgroundImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image ) + * @copydoc Dali::Toolkit::PushButton::SetDisabledImage */ - void SetSelectedImage( Actor image ); + void SetDisabledImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::PushButton::GetSelectedImage() + * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage */ - Actor GetSelectedImage() const; + void SetDisabledSelectedImage( const std::string& filename ); /** - * Internal use only. - * @return A reference to the selected image. + * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage */ - Actor& GetSelectedImage(); + void SetDisabledBackgroundImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image ) + * @return The filename used for the button image. */ - void SetBackgroundImage( Actor image ); + std::string GetUnselectedImageFilename() const; /** - * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage() + * @return The filename used for the selected image. */ - Actor GetBackgroundImage() const; + std::string GetSelectedImageFilename() const; /** - * Internal use only. - * @return A reference to the background image. + * @return The filename used for the background image. */ - Actor& GetBackgroundImage(); + std::string GetBackgroundImageFilename() const; /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage( Actor image ) + * @return The filename used for the selected background image. */ - void SetSelectedBackgroundImage( Actor image ); + std::string GetSelectedBackgroundImageFilename() const; /** - * @copydoc Dali::Toolkit::PushButton::GetSelectedBackgroundImage() + * @return The filename used for the disabled button image. */ - Actor GetSelectedBackgroundImage() const; + std::string GetDisabledImageFilename() const; /** - * Internal use only. - * @return A reference to the selected background image. + * @return The filename used for the disabled selected image. */ - Actor& GetSelectedBackgroundImage(); + std::string GetDisabledSelectedImageFilename() const; /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image ) + * @return The filename used for the disabled background image. */ - void SetDisabledImage( Actor image ); + std::string GetDisabledBackgroundImageFilename() const; /** - * @copydoc Dali::Toolkit::PushButton::GetDisabledImage() + * @brief Sets the specified properties on the button label. + * If the label does not exist yet, it is created. + * The derived buttons are notified if any properties are changed. + * @param[in] properties A Property::Map of key-value pairs of properties to set. */ - Actor GetDisabledImage() const; + void ModifyLabel( const Property::Map& properties ); /** - * Internal use only. - * @return A reference to the disabled button image. + * Performs actions as requested using the action name. + * @param[in] object The object on which to perform the action. + * @param[in] actionName The action to perform. + * @param[in] attributes The attributes with which to perfrom this action. + * @return true if action has been accepted by this control */ - Actor& GetDisabledImage(); + static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ); + +public: // Deprecated API /** - * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image ) + * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) */ - void SetDisabledSelectedImage( Actor image ); + void SetLabel( Actor label ); /** - * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage() + * @deprecated Sets the unselected image with an Actor. + * @param[in] image The Actor to use. */ - Actor GetDisabledSelectedImage() const; + void SetButtonImage( Actor image ); /** - * Internal use only. - * @return A reference to the disabled selected image. + * @deprecated Sets the selected image with an Actor. + * @param[in] image The Actor to use. */ - Actor& GetDisabledSelectedImage(); + void SetSelectedImage( Actor image ); /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image ) + * @deprecated Sets the background image with an Actor. + * @param[in] image The Actor to use. */ - void SetDisabledBackgroundImage( Actor image ); + void SetBackgroundImage( Actor image ); /** - * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage() + * @deprecated Sets the selected background image with an Actor. + * @param[in] image The Actor to use. */ - Actor GetDisabledBackgroundImage() const; + void SetSelectedBackgroundImage( Actor image ); /** - * Internal use only. - * @return A reference to the disabled background image. + * @deprecated Sets the disabled image with an Actor. + * @param[in] image The Actor to use. */ - Actor& GetDisabledBackgroundImage(); + void SetDisabledImage( Actor image ); /** - * Performs actions as requested using the action name. - * @param[in] object The object on which to perform the action. - * @param[in] actionName The action to perform. - * @param[in] attributes The attributes with which to perfrom this action. - * @return true if action has been accepted by this control + * @deprecated Sets the disabled selected image with an Actor. + * @param[in] image The Actor to use. */ - static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ); + void SetDisabledSelectedImage( Actor image ); + + /** + * @deprecated Sets the disabled background image with an Actor. + * @param[in] image The Actor to use. + */ + void SetDisabledBackgroundImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::Button::GetButtonImage + */ + Actor GetButtonImage() const; + + /** + * @copydoc Dali::Toolkit::Button::GetSelectedImage + */ + Actor GetSelectedImage() const; protected: + enum ButtonState + { + ButtonUp, ///< The button is up. + ButtonDown, ///< The button is down. + }; + + /** + * Button paint states. + */ + enum PaintState + { + UnselectedState, ///< The button is unselected. + SelectedState, ///< The button is selected. + DisabledUnselectedState, ///< The button is disabled and unselected. + DisabledSelectedState, ///< The button is disabled and selected. + }; + + /** + * Enum to specify which decoration when getting and setting decorations. + */ + enum DecorationState + { + UNSELECTED_DECORATION = 0, + SELECTED_DECORATION, + DECORATION_STATES + }; + + /** + * Construct a new Button. + */ + Button(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~Button(); /** * @return A reference to the label actor. */ - Actor& GetLabel(); + Actor& GetLabelActor(); + + /** + * @return A reference to the unselected button image. + */ + Actor& GetUnselectedImage(); + + /** + * @return A reference to the selected image. + */ + Actor& GetSelectedImage(); + + /** + * @return A reference to the background image. + */ + Actor& GetBackgroundImage(); + + /** + * @return A reference to the selected background image. + */ + Actor& GetSelectedBackgroundImage(); + + /** + * @return A reference to the disabled button image. + */ + Actor& GetDisabledImage(); + + /** + * @return A reference to the disabled selected image. + */ + Actor& GetDisabledSelectedImage(); + + /** + * @return A reference to the disabled background image. + */ + Actor& GetDisabledBackgroundImage(); private: @@ -280,20 +359,15 @@ private: bool DoClickAction( const Property::Map& attributes ); /** - * This method is called after the button initialization. - * Could be reimplemented in subclasses to provide specific behaviour. - */ - virtual void OnButtonInitialize() { } - - /** * This method is called when the label is set. + * @param[in] noPadding Used to bypass padding if the label is to be treated generically. */ - virtual void OnLabelSet() {} + virtual void OnLabelSet( bool noPadding ) {} /** - * This method is called when the button image is set + * This method is called when the unselected button image is set */ - virtual void OnButtonImageSet() {} + virtual void OnUnselectedImageSet() {} /** * This method is called when the selected image is set @@ -326,37 +400,30 @@ private: virtual void OnDisabledBackgroundImageSet() {} /** - * This method is called from the OnTouchEvent method when the button is down. + * This method is called the button is down. * Could be reimplemented in subclasses to provide specific behaviour. */ virtual void OnButtonDown(); /** - * This method is called from the OnTouchEvent method when the button is up. + * This method is called when the button is up. * Could be reimplemented in subclasses to provide specific behaviour. */ virtual void OnButtonUp(); /** - * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or - * more than one touch points are received. + * This method is called when touch leaves the boundary of the button or several touch points are received. * Could be reimplemented in subclasses to provide specific behaviour. */ virtual void OnTouchPointLeave(); /** - * This method is called from the OnTouchEvent method when the touch point is interrupted. + * This method is called when the touch is interrupted. * Could be reimplemented in subclasses to provide specific behaviour. */ virtual void OnTouchPointInterrupted(); /** - * This method is called when the button is removed from the stage. - * Could be reimplemented in subclasses to provide specific behaviour. - */ - virtual void OnButtonStageDisconnection(); - - /** * This method is called when the \e selected property is changed. */ virtual void OnSelected() {} @@ -427,17 +494,11 @@ public: */ static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex ); -protected: // From CustomActorImpl - - /** - * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event ) - */ - virtual bool OnTouchEvent( const TouchEvent& event ); - -private: // From Control +protected: // From Control /** * @copydoc Toolkit::Control::OnInitialize() + * @note If overridden by deriving button classes, then an up-call to Button::OnInitialize MUST be made at the start. */ virtual void OnInitialize(); @@ -452,14 +513,23 @@ private: // From Control virtual bool OnKeyboardEnter(); /** - * Callback received when the button is disconnected from the stage. - * It resets the button status. + * @copydoc Toolkit::Control::OnStageDisconnection() + * @note If overridden by deriving button classes, then an up-call to Button::OnStageDisconnection MUST be made at the end. */ - void OnControlStageDisconnection(); + void OnStageDisconnection(); + private: /** + * @brief Handler for touch data + * @param[in] actor The touched actor. + * @param[in] touch The touch info. + * @return true, if consumed, false otherwise. + */ + bool OnTouch( Actor actor, const TouchData& touch ); + + /** * Handler for tap events. * We do not actually do anything when we receive a tap as the button handles tap event through * the touch event system itself as it requires more than just tap handling (e.g. leave events). @@ -497,27 +567,41 @@ private: */ void Released(); -protected: + /** + * Used to perform common setup applied to images within button. + * This will replace the current image with the specifed one. + * @param[in] actorToModify The image to replace. + * @param[out] newActor The new image to use. + */ + void SetupContent( Actor& actorToModify, Actor newActor ); - enum ButtonState - { - ButtonUp, ///< The button is up. - ButtonDown, ///< The button is down. - }; + /** + * Gets the unselected content color. + * @return The currently used unselected color. + */ + const Vector4 GetUnselectedColor() const; /** - * Button paint states. + * Sets the color of button in selected or unselected state, if image also supplied this color will be appplied to it. + * If no visual exists, it is created. + * @param[in] color The color to use. + * @param[in] selectedState The state to apply the color to, SelectedState or DisabledUnselectedState. */ - enum PaintState - { - UnselectedState, ///< The button is unselected. - SelectedState, ///< The button is selected. - DisabledUnselectedState, ///< The button is disabled and unselected. - DisabledSelectedState, ///< The button is disabled and selected. - }; + void SetColor( const Vector4& color, PaintState selectedState ); + + /** + * Gets the selected content color. + * @return The currently used selected color. + */ + const Vector4 GetSelectedColor() const; + +protected: ButtonState GetState(); PaintState GetPaintState(); + void SetDecoration( DecorationState state, Actor actor ); + Actor& GetDecoration( DecorationState state ); + /** * Returns the animation to be used for transitioning creating the animation if needed. @@ -554,6 +638,7 @@ protected: virtual void OnTransitionOut( Actor actor ) {} private: + /** * Starts the transition animation. * Button::TransitionFinished is called when the animation finishes. @@ -578,45 +663,43 @@ private: void ResetImageLayers(); /** - * Transitions in the actor, inserting the actor above childLower below the childUpper. - * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + * Transitions out the actor */ - void TransitionInBetween( Actor childLower, Actor childUpper, Actor actor ); + void TransitionOut( Actor actor ); /** - * Transitions in the actor, inserting the actor above the child if the child exists or at the bottom otherwise - * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + * Removes the actor from the button and prepares it to be transitioned out */ - void TransitionInAbove( Actor child, Actor actor ); + void RemoveButtonImage( Actor& actor ); /** - * Transitions in the actor, inserting the actor at the index - * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + * Finds the index of the actor. + * If the actor doesn't exist, return the last index + 1. */ - void TransitionInAtIndex( unsigned int index, Actor actor ); + unsigned int FindChildIndex( Actor& actor ); /** - * Transitions out the actor + * Adds an actor to the hierarchy and prepares it to be transitioned. + * @param[in] actor The actor to add */ - void TransitionOut( Actor actor ); + void PrepareAddButtonImage( Actor& actor ); /** - * Inserts the actor to the button and prepares it to be transitioned out - * @return true if the child was inserted, false otherwise + * Adds an actor to the hierarchy and marks it to be transitioned. + * @param[in] actor The actor to add */ - bool InsertButtonImage( unsigned int index, Actor& actor ); + void TransitionButtonImage( Actor& actor ); /** - * Removes the actor from the button and prepares it to be transitioned out + * Adds an actor to the hierarchy. + * @param[in] actor The actor to add */ - void RemoveButtonImage( Actor& actor ); + void AddButtonImage( Actor& actor ); /** - * Finds the index of the actor. - * If the actor doesn't exist, return the last index + 1. + * (Re)Adds the label (if exists) to the hierarchy (so it is always on top). */ - unsigned int FindChildIndex( Actor& actor ); - + void ReAddLabel(); // Undefined Button( const Button& ); @@ -636,6 +719,8 @@ private: Actor mLabel; ///< Stores the button label. + Actor mDecoration[ DECORATION_STATES ]; ///< Stores the decorations for both selected and unselected states. + Actor mUnselectedContent; ///< Stores the unselected content. Actor mSelectedContent; ///< Stores the selected content. Actor mBackgroundContent; ///< Stores the background content. @@ -648,6 +733,9 @@ private: TapGestureDetector mTapDetector; + Vector4 mUnselectedColor; ///< Color to use for unselected content. + Vector4 mSelectedColor; ///< Color to use for selected content. + bool mDisabled; ///< Stores the disabled property. bool mAutoRepeating; ///< Stores the autorepeating property. bool mTogglableButton; ///< Stores the togglable property.