From: Heeyong Song Date: Thu, 26 Feb 2015 00:23:00 +0000 (+0900) Subject: Refactoring Button: remove painter X-Git-Tag: dali_1.0.32~4^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=38a8b42e1f7765a9b3314a033700fb25d4a6f8fd Refactoring Button: remove painter Change-Id: I37a0dc2c734458dd135834e2df1d14b2bf22b8cc --- diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index fdecbba..4f7dd86 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -94,16 +94,14 @@ PropertyRegistration property10( typeRegistration, "label-actor", Button::Button() : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), - mTogglableButton( false ), - mSelected( false ), - mPainter( NULL ), mAutoRepeatingTimer(), mDisabled( false ), mAutoRepeating( false ), -// mTogglableButton( false ), -// mSelected( false ), + mTogglableButton( false ), + mSelected( false ), mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ), mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ), + mAnimationTime( 0.0f ), mClickActionPerforming( false ), mState( ButtonUp ) { @@ -119,13 +117,11 @@ Button::~Button() void Button::SetDisabled( bool disabled ) { - mDisabled = disabled; - - // Notifies the painter. - Toolkit::Button handle( GetOwner() ); - if( mPainter ) + if( disabled != mDisabled ) { - mPainter->SetDisabled( handle, mDisabled ); + mDisabled = disabled; + + OnDisabled( mDisabled ); } } @@ -142,17 +138,17 @@ void Button::SetAutoRepeating( bool autoRepeating ) if( autoRepeating ) { mTogglableButton = false; + if( mSelected ) { // Emit a signal is not wanted, only change the appearance. - Toolkit::Button handle( GetOwner() ); - mPainter->Selected( handle ); + OnSelected( false ); + mSelected = false; + + RelayoutRequest(); } } - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } bool Button::IsAutoRepeating() const @@ -190,9 +186,6 @@ void Button::SetTogglableButton( bool togglable ) if( togglable ) { mAutoRepeating = false; - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } } @@ -205,15 +198,17 @@ void Button::SetSelected( bool selected ) { if( !mDisabled && mTogglableButton && ( selected != mSelected ) ) { + // Notifies the derived class the button has been selected. + OnSelected( selected ); + mSelected = selected; Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been selected. - mPainter->Selected( handle ); - // Emit signal. mStateChangedSignal.Emit( handle ); + + RelayoutRequest(); } } @@ -224,12 +219,12 @@ bool Button::IsSelected() const void Button::SetAnimationTime( float animationTime ) { - OnAnimationTimeSet( animationTime ); + mAnimationTime = animationTime; } float Button::GetAnimationTime() const { - return OnAnimationTimeRequested(); + return mAnimationTime; } void Button::SetLabel( const std::string& label ) @@ -237,15 +232,23 @@ void Button::SetLabel( const std::string& label ) Toolkit::TextView textView = Toolkit::TextView::New( label ); textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button SetLabel( textView ); - - RelayoutRequest(); } void Button::SetLabel( Actor label ) { - Toolkit::Button handle( GetOwner() ); + if( mLabel != label ) + { + if( mLabel && mLabel.GetParent() ) + { + mLabel.GetParent().Remove( mLabel ); + } + + mLabel = label; - mPainter->SetLabel( handle, label ); + OnLabelSet(); + + RelayoutRequest(); + } } Actor Button::GetLabel() const @@ -258,145 +261,64 @@ Actor& Button::GetLabel() return mLabel; } -void Button::SetButtonImage( Image image ) -{ - SetButtonImage( ImageActor::New( image ) ); -} - -void Button::SetButtonImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetButtonImage( handle, image ); -} - Actor Button::GetButtonImage() const { - return mButtonImage; + return mButtonContent; } Actor& Button::GetButtonImage() { - return mButtonImage; -} - -void Button::SetSelectedImage( Image image ) -{ - SetSelectedImage( ImageActor::New( image ) ); -} - -void Button::SetSelectedImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetSelectedImage( handle, image ); + return mButtonContent; } Actor Button::GetSelectedImage() const { - return mSelectedImage; + return mSelectedContent; } Actor& Button::GetSelectedImage() { - return mSelectedImage; -} - -void Button::SetBackgroundImage( Image image ) -{ - SetBackgroundImage( ImageActor::New( image ) ); -} - -void Button::SetBackgroundImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetBackgroundImage( handle, image ); + return mSelectedContent; } Actor Button::GetBackgroundImage() const { - return mBackgroundImage; + return mBackgroundContent; } Actor& Button::GetBackgroundImage() { - return mBackgroundImage; -} - -void Button::SetDisabledImage( Image image ) -{ - SetDisabledImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledImage( handle, image ); + return mBackgroundContent; } Actor Button::GetDisabledImage() const { - return mDisabledImage; + return mDisabledContent; } Actor& Button::GetDisabledImage() { - return mDisabledImage; -} - -void Button::SetDisabledSelectedImage( Image image ) -{ - SetDisabledSelectedImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledSelectedImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledSelectedImage( handle, image ); + return mDisabledContent; } Actor Button::GetDisabledSelectedImage() const { - return mDisabledSelectedImage; + return mDisabledSelectedContent; } Actor& Button::GetDisabledSelectedImage() { - return mDisabledSelectedImage; -} - -void Button::SetDisabledBackgroundImage( Image image ) -{ - SetDisabledBackgroundImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledBackgroundImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledBackgroundImage( handle, image ); + return mDisabledSelectedContent; } Actor Button::GetDisabledBackgroundImage() const { - return mDisabledBackgroundImage; + return mDisabledBackgroundContent; } Actor& Button::GetDisabledBackgroundImage() { - return mDisabledBackgroundImage; -} - -Actor& Button::GetFadeOutButtonImage() -{ - return mFadeOutButtonImage; -} - -Actor& Button::GetFadeOutSelectedImage() -{ - return mFadeOutSelectedImage; -} - -Actor& Button::GetFadeOutBackgroundImage() -{ - return mFadeOutBackgroundImage; + return mDisabledBackgroundContent; } bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ) @@ -432,16 +354,6 @@ void Button::DoClickAction( const PropertyValueContainer& attributes ) } } -void Button::OnAnimationTimeSet( float animationTime ) -{ - mPainter->SetAnimationTime( animationTime ); -} - -float Button::OnAnimationTimeRequested() const -{ - return mPainter->GetAnimationTime(); -} - void Button::OnButtonStageDisconnection() { if( ButtonDown == mState ) @@ -450,8 +362,8 @@ void Button::OnButtonStageDisconnection() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been released. - mPainter->Released( handle ); + // Notifies the derived class the button has been released. + OnReleased(); if( mAutoRepeating ) { @@ -467,8 +379,8 @@ void Button::OnButtonDown() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + // Notifies the derived class the button has been pressed. + OnPressed(); if( mAutoRepeating ) { @@ -490,17 +402,17 @@ void Button::OnButtonUp() } else { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been clicked. - mPainter->Released( handle ); - mPainter->Clicked( handle ); + // Notifies the derived class the button has been clicked. + OnReleased(); + OnClicked(); if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); } + Toolkit::Button handle( GetOwner() ); + //Emit signal. mReleasedSignal.Emit( handle ); mClickedSignal.Emit( handle ); @@ -516,8 +428,8 @@ void Button::OnTouchPointLeave() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been released. - mPainter->Released( handle ); + // Notifies the derived class the button has been released. + OnReleased(); if( mAutoRepeating ) { @@ -653,13 +565,6 @@ bool Button::OnTouchEvent(const TouchEvent& event) void Button::OnInitialize() { - // Initialize the painter and notifies subclasses. - Toolkit::Button handle( GetOwner() ); - if( mPainter ) - { - mPainter->Initialize( handle ); - } - Actor self = Self(); mTapDetector = TapGestureDetector::New(); @@ -678,15 +583,6 @@ void Button::OnActivated() DoClickAction( attributes ); } -void Button::OnControlSizeSet(const Vector3& targetSize) -{ - Toolkit::Button handle( GetOwner() ); - if( mPainter ) - { - mPainter->SetSize( handle, targetSize ); - } -} - void Button::OnTap(Actor actor, const TapGesture& tap) { // Do nothing. @@ -709,8 +605,8 @@ bool Button::AutoRepeatingSlot() Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + // Notifies the derived class the button has been pressed. + OnPressed(); //Emit signal. consumed = mReleasedSignal.Emit( handle ); @@ -727,11 +623,6 @@ void Button::OnControlStageDisconnection() mState = ButtonUp; } -void Button::SetPainter(ButtonPainterPtr painter) -{ - mPainter = painter; -} - Button::ButtonState Button::GetState() { return mState; @@ -857,7 +748,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mButtonImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map ); value = map; break; } @@ -865,7 +756,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map ); value = map; break; } @@ -873,7 +764,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map ); value = map; break; } diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index f0884e1..2c4c115 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include "button-painter-impl.h" namespace Dali { @@ -118,7 +117,7 @@ public: /** * @copydoc Dali::Toolkit::Button::SetSelected( bool selected ) */ - virtual void SetSelected( bool selected ); + void SetSelected( bool selected ); /** * @copydoc Dali::Toolkit::Button::IsSelected() const @@ -143,7 +142,7 @@ public: /** * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) */ - virtual void SetLabel( Actor label ); // TODO: After refactoring painter, virtual will be removed + void SetLabel( Actor label ); /** * @copydoc Dali::Toolkit::Button::GetLabel() @@ -151,165 +150,120 @@ public: Actor GetLabel() const; /** - * Used by the painter only. - * @return A reference to the label actor. - */ - Actor& GetLabel(); - - /** - * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image ) - */ - void SetButtonImage( Image image ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image ) - */ - void SetButtonImage( Actor image ); - - /** * @copydoc Dali::Toolkit::PushButton::GetButtonImage() */ Actor GetButtonImage() const; /** - * Used by the painter only. + * Internal use only. * @return A reference to the button image. */ Actor& GetButtonImage(); /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( const Image image ) - */ - void SetSelectedImage( Image image ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image ) - */ - void SetSelectedImage( Actor image ); - - /** * @copydoc Dali::Toolkit::PushButton::GetSelectedImage() */ Actor GetSelectedImage() const; /** - * Used by the painter only. + * Internal use only. * @return A reference to the selected image. */ Actor& GetSelectedImage(); /** - * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image ) - */ - void SetBackgroundImage( Image image ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image ) - */ - void SetBackgroundImage( Actor image ); - - /** * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage() */ Actor GetBackgroundImage() const; /** - * Used by the painter only. + * Internal use only. * @return A reference to the background image. */ Actor& GetBackgroundImage(); /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Image image ) - */ - void SetDisabledImage( Image image ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image ) - */ - void SetDisabledImage( Actor image ); - - /** * @copydoc Dali::Toolkit::PushButton::GetDisabledImage() */ Actor GetDisabledImage() const; /** - * Used by the painter only. + * Internal use only. * @return A reference to the disabled button image. */ Actor& GetDisabledImage(); /** - * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Image image ) + * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage() */ - void SetDisabledSelectedImage( Image image ); + Actor GetDisabledSelectedImage() const; /** - * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image ) + * Internal use only. + * @return A reference to the disabled selected image. */ - void SetDisabledSelectedImage( Actor image ); + Actor& GetDisabledSelectedImage(); /** - * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage() + * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage() */ - Actor GetDisabledSelectedImage() const; + Actor GetDisabledBackgroundImage() const; /** - * Used by the painter only. - * @return A reference to the disabled selected image. + * Internal use only. + * @return A reference to the disabled background image. */ - Actor& GetDisabledSelectedImage(); + Actor& GetDisabledBackgroundImage(); /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Image 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 */ - void SetDisabledBackgroundImage( Image image ); + static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ); /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image ) + * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image ) */ - void SetDisabledBackgroundImage( Actor image ); + virtual void SetButtonImage( Actor image ) {} /** - * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage() + * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image ) */ - Actor GetDisabledBackgroundImage() const; + virtual void SetSelectedImage( Actor image ) {} /** - * Used by the painter only. - * @return A reference to the disabled background image. + * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image ) */ - Actor& GetDisabledBackgroundImage(); + virtual void SetBackgroundImage( Actor image ) {} /** - * Used by the painter only. - * @return A reference to the button image that is fading out. + * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image ) */ - Actor& GetFadeOutButtonImage(); + virtual void SetDisabledImage( Actor image ) {} /** - * Used by the painter only. - * @return A reference to the selected image that is fading out. + * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image ) */ - Actor& GetFadeOutSelectedImage(); + virtual void SetDisabledSelectedImage( Actor image ) {} /** - * Used by the painter only. - * @return A reference to the background image that is fading out. + * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image ) */ - Actor& GetFadeOutBackgroundImage(); + virtual void SetDisabledBackgroundImage( Actor image ) {} + +protected: /** - * 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 + * Internal use only. + * @return A reference to the label actor. */ - static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ); + Actor& GetLabel(); private: + /** * Perform the click action to click the button. * @param[in] attributes The attributes to perfrom this action. @@ -348,24 +302,40 @@ private: virtual void OnTouchPointInterrupted(); /** - * This method is called when the animation time is set. - * Needs to be reimplemented in subclasses to set the animation time in different buttons. - * @param animationTime The animation time in seconds. + * This method is called when the button is removed from the stage. + * Could be reimplemented in subclasses to provide specific behaviour. */ - virtual void OnAnimationTimeSet( float animationTime ); + virtual void OnButtonStageDisconnection(); /** - * This method is called when the animation time is requested. - * Needs to be reimplemented in subclases to return the animation time. - * @return The animation time in seconds. + * This method is called when the label is set. */ - virtual float OnAnimationTimeRequested() const; + virtual void OnLabelSet() {} /** - * This method is called when the button is removed from the stage. - * Could be reimplemented in subclasses to provide specific behaviour. + * This method is called when the \e selected property is changed. */ - virtual void OnButtonStageDisconnection(); + virtual void OnSelected( bool selected ) {} + + /** + * This method is called when the \e disabled property is changed. + */ + virtual void OnDisabled( bool disabled ) {} + + /** + * This method is called when the button is pressed. + */ + virtual void OnPressed() {} + + /** + * This method is called when the button is released. + */ + virtual void OnReleased() {} + + /** + * This method is called when the button is clicked + */ + virtual void OnClicked() {} public: @@ -438,11 +408,6 @@ private: // From Control virtual void OnActivated(); /** - * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize ) - */ - virtual void OnControlSizeSet( const Vector3& targetSize ); - - /** * Callback received when the button is disconnected from the stage. * It resets the button status. */ @@ -479,14 +444,25 @@ protected: ButtonDown, ///< The button is down. }; - void SetPainter(ButtonPainterPtr painter); + /** + * 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. + UnselectedSelectedTransition, ///< The button is in transition from unselected to selected. + SelectedUnselectedTransition, ///< The push button is in transition from selected to unselected. + UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled. + DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected. + SelectedDisabledTransition, ///< The button is in transition from selected to disabled. + DisabledSelectedTransition ///< The button is in transition from disabled to selected. + }; ButtonState GetState(); - Actor mLabel; //TODO: After refactoring painter, this will be private - bool mTogglableButton; //TODO: After refactoring painter, this will be private - bool mSelected; //TODO: After refactoring painter, this will be private - private: // Undefined @@ -497,37 +473,32 @@ private: private: - ButtonPainterPtr mPainter; ///< Pointer to a ButtonPainter base class. - // Signals Toolkit::Button::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed. - Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released. + Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released. Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked. - Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed. + Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed. Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property. -// Actor mLabel; ///< Stores the button label. - - Actor mButtonImage; ///< Stores the unselected image. - Actor mSelectedImage; ///< Stores the selected image. - Actor mBackgroundImage; ///< Stores the background image. - Actor mDisabledImage; ///< Stores the disabled image. - Actor mDisabledSelectedImage; ///< Stores the disabled selected image. - Actor mDisabledBackgroundImage; ///< Stores the disabled background image. + Actor mLabel; ///< Stores the button label. - Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes. - Actor mFadeOutSelectedImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes. - Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes. + Actor mButtonContent; ///< Stores the unselected content. + Actor mSelectedContent; ///< Stores the selected content. + Actor mBackgroundContent; ///< Stores the background content. + Actor mDisabledContent; ///< Stores the disabled content. + Actor mDisabledSelectedContent; ///< Stores the disabled selected content. + Actor mDisabledBackgroundContent; ///< Stores the disabled background content. TapGestureDetector mTapDetector; bool mDisabled; ///< Stores the disabled property. bool mAutoRepeating; ///< Stores the autorepeating property. -// bool mTogglableButton; ///< Stores the togglable property. -// bool mSelected; ///< Stores the selected state. + bool mTogglableButton; ///< Stores the togglable property. + bool mSelected; ///< Stores the selected state. float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. + float mAnimationTime; ///< The animation time. // Actions bool mClickActionPerforming; @@ -537,7 +508,6 @@ private: } // namespace Internal - // Helpers for public-api forwarding methods inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button ) diff --git a/dali-toolkit/internal/controls/buttons/button-painter-impl.h b/dali-toolkit/internal/controls/buttons/button-painter-impl.h deleted file mode 100644 index 3a91aef..0000000 --- a/dali-toolkit/internal/controls/buttons/button-painter-impl.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_PAINTER_H__ -#define __DALI_TOOLKIT_INTERNAL_BUTTON_PAINTER_H__ - -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include -#include - -// INTERNAL INCLUDES - -namespace Dali -{ - -// Forward declarations - -struct Vector3; - -namespace Toolkit -{ - -// Forward declarations - -class Button; - -namespace Internal -{ - -// Forward declarations - -class ButtonPainter; - -// Type definitions - -typedef IntrusivePtr ButtonPainterPtr; - -/** - * ButtonPainter is an interface which provides common functionality to all painters. - */ -class ButtonPainter : public RefObject, public ConnectionTracker -{ -public: - /** - * Destructor. - * - */ - virtual ~ButtonPainter() {} - - /** - * Initializes the painter. - * - * This method is called from the Dali::Toolkit::Internal::Button. - * - * @param[inout] button The button in which all actors that form its appearance are going to be added. - */ - virtual void Initialize( Toolkit::Button& button ) = 0; - - /** - * Sets the new size. - * - * This method is called from the Dali::Toolkit::Internal::Button when its size changes. - * - * @param[inout] button The button which stores button's images. - * @param[in] size The new size. - */ - virtual void SetSize( Toolkit::Button& button, const Vector3& size ) = 0; - - /** - * This method is called from the Dali::Toolkit::Internal::Button when the \e disabled property changes. - * - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] disabled The disabled state. - */ - virtual void SetDisabled( Toolkit::Button& button, bool disabled ) = 0; - - /** - * This method is called from the Dali::Toolkit::Internal::PushButton when the \e autorepeating property changes. - * @param[in] autorepeating property. - */ - virtual void SetAutoRepeating( bool autorepeating ) {} - - /** - * Sets the animation time. - * @param [in] animationTime The animation time in seconds. - */ - virtual void SetAnimationTime( float animationTime ) = 0; - - /** - * Retrieves the animation time. - * @return The animation time in seconds. - */ - virtual float GetAnimationTime() const = 0; - - /** - * Sets the label. - * It adds the label to the root actor. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] label Button label. - */ - virtual void SetLabel( Toolkit::Button& button, Actor label ) {} - - /** - * Sets the button image. - * It adds the button image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The button image. - */ - virtual void SetButtonImage( Toolkit::Button& button, Actor image ) {} - - /** - * Sets the selected image. - * It adds the selected image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The selected image. - */ - virtual void SetSelectedImage( Toolkit::Button& button, Actor image ) {} - - /** - * Sets the background image. - * It adds the background image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The background image. - */ - virtual void SetBackgroundImage( Toolkit::Button& button, Actor image ) {} - - /** - * Sets the disabled image. - * It adds the disabled image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The disabled button image. - */ - virtual void SetDisabledImage( Toolkit::Button& button, Actor image ) {} - - /** - * Sets the disabled selected image. - * It adds the disabled selected image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The disabled selected image. - */ - virtual void SetDisabledSelectedImage( Toolkit::Button& button, Actor image ) {} - - /** - * Sets the disabled background image. - * It adds the disabled background image to the root actor and creates the image transition if needed. - * @param[inout] button The button in which all actors that form its appearance are going to be added. - * @param[in] image The disabled background image. - */ - virtual void SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ) {} - - /** - * This method is called when the Dali::Toolkit::Internal::Button, in which this - * object is registered, is pressed. - * @param[inout] button The Dali::Toolkit::Button, linked to the internal - * implementation, in which this object is registered. - */ - virtual void Pressed( Toolkit::Button& button ) {} - - /** - * This method is called when the Dali::Toolkit::Internal::Button, in which this - * object is registered, is released. - * @param[inout] button The Dali::Toolkit::Button, linked to the internal - * implementation, in which this object is registered. - */ - virtual void Released( Toolkit::Button& button ) {} - - /** - * This method is called when the Dali::Toolkit::Internal::Button, in which this - * object is registered, is clicked. - * @param[inout] button The Dali::Toolkit::Button, linked to the internal - * implementation, in which this object is registered. - */ - virtual void Clicked( Toolkit::Button& button ) {} - - /** - * This method is called when the Dali::Toolkit::Internal::Button, in which this - * object is registered, changes its state. - * @param[inout] button The Dali::Toolkit::Button, linked to the internal - * implementation, in which this object is registered. - */ - virtual void Selected( Toolkit::Button& button ) {} -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_BUTTON_PAINTER_H__ diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.cpp deleted file mode 100644 index f0d5497..0000000 --- a/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.cpp +++ /dev/null @@ -1,1000 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include "check-box-button-default-painter-impl.h" - -// EXTERNAL INCLUDES -#include -#include -#include -#include -#include - -// INTERNAL INCLUDES -#include "check-box-button-impl.h" - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -namespace -{ -const float FOREGROUND_DEPTH( 0.5f ); -const float BACKGROUND_DEPTH( 0.25f ); - -const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time - -inline Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( Toolkit::Button& button ) -{ - DALI_ASSERT_ALWAYS( button ); - - Dali::RefObject& handle = button.GetImplementation(); - - return static_cast( handle ); -} - -inline const Toolkit::Internal::CheckBoxButton& GetCheckBoxButtonImpl( const Toolkit::Button& button ) -{ - DALI_ASSERT_ALWAYS( button ); - - const Dali::RefObject& handle = button.GetImplementation(); - - return static_cast( handle ); -} - -} - -CheckBoxButtonDefaultPainter::CheckBoxButtonDefaultPainter() -: CheckBoxButtonPainter(), - mDisabled( false ), - mPaintState( UnselectedState ), - mButton(NULL), - mAnimationTime( ANIMATION_TIME ) -{ -} - -CheckBoxButtonDefaultPainter::~CheckBoxButtonDefaultPainter() -{ - if( mCheckInAnimation ) - { - mCheckInAnimation.Clear(); - } - if( mCheckOutAnimation ) - { - mCheckOutAnimation.Clear(); - } -} - -void CheckBoxButtonDefaultPainter::Initialize( Toolkit::Button& button ) -{ - Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button ); - Actor& backgroundImage = buttonImpl.GetBackgroundImage(); - Actor& selectedImage = buttonImpl.GetSelectedImage(); - Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = buttonImpl.GetDisabledSelectedImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - if( backgroundImage ) - { - SetBackgroundImage( checkBox, backgroundImage ); - } - - if( selectedImage ) - { - SetSelectedImage( checkBox, selectedImage ); - } - - if( disabledBackgroundImage ) - { - SetDisabledBackgroundImage( checkBox, disabledBackgroundImage ); - } - - if( disabledSelectedImage ) - { - SetDisabledSelectedImage( checkBox, disabledSelectedImage ); - } - - SetDisabled( button, mDisabled ); -} - -void CheckBoxButtonDefaultPainter::SetSize( Toolkit::Button& button, const Vector3& size ) -{ - Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button ); - Actor& backgroundImage = buttonImpl.GetBackgroundImage(); - Actor& selectedImage = buttonImpl.GetSelectedImage(); - Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = buttonImpl.GetDisabledSelectedImage(); - - ApplySelectedConstraint( selectedImage, FOREGROUND_DEPTH ); - ApplyConstraint( backgroundImage, BACKGROUND_DEPTH ); - ApplyConstraint( disabledSelectedImage, FOREGROUND_DEPTH ); - ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH ); -} - -void CheckBoxButtonDefaultPainter::SetDisabled( Toolkit::Button& button, bool disabled ) -{ - mDisabled = disabled; - - Toolkit::Internal::CheckBoxButton& buttonImpl = GetCheckBoxButtonImpl( button ); - Actor& backgroundImage = buttonImpl.GetBackgroundImage(); - Actor& selectedImage = buttonImpl.GetSelectedImage(); - Actor& disabledBackgroundImage = buttonImpl.GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = buttonImpl.GetDisabledSelectedImage(); - Actor& fadeOutSelectedImage = buttonImpl.GetFadeOutSelectedImage(); - Actor& fadeOutBackgroundImage = buttonImpl.GetFadeOutBackgroundImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - switch( mPaintState ) - { - case UnselectedState: - { - if( disabled ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, backgroundImage ); - FadeInImage( checkBox, disabledBackgroundImage ); - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = UnselectedDisabledTransition; - } - break; - } - case SelectedState: - { - if( disabled ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, backgroundImage ); - FadeOutImage( checkBox, Foreground, selectedImage ); - FadeInImage( checkBox, disabledSelectedImage ); - FadeInImage( checkBox, disabledBackgroundImage ); - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = SelectedDisabledTransition; - } - break; - } - case DisabledUnselectedState: - { - if( !disabled ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, disabledBackgroundImage ); - FadeInImage( checkBox, backgroundImage ); - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = DisabledUnselectedTransition; - } - break; - } - case DisabledSelectedState: - { - if( !disabled ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, disabledBackgroundImage ); - FadeOutImage( checkBox, Foreground, disabledSelectedImage ); - FadeInImage( checkBox, backgroundImage ); - FadeInImage( checkBox, selectedImage ); - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = DisabledSelectedTransition; - } - break; - } - case UnselectedSelectedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - StopCheckInAnimation(); - - FadeOutImage( checkBox, Foreground, selectedImage, opacity ); - FadeOutImage( checkBox, Background, backgroundImage ); - - FadeInImage( checkBox, disabledSelectedImage ); - FadeInImage( checkBox, disabledBackgroundImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = SelectedDisabledTransition; - } - break; - } - case SelectedUnselectedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutSelectedImage ) - { - opacity = fadeOutSelectedImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - StopCheckInAnimation(); - - button.Add( disabledSelectedImage ); - FadeOutImage( checkBox, Foreground, disabledSelectedImage, opacity ); - FadeOutImage( checkBox, Background, backgroundImage ); - - FadeInImage( checkBox, disabledBackgroundImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = UnselectedDisabledTransition; - } - break; - } - case UnselectedDisabledTransition: - { - if( !disabled ) - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox, false ); - StopCheckInAnimation(); - - FadeOutImage( checkBox, Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( checkBox, backgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = DisabledUnselectedTransition; - } - break; - } - case DisabledUnselectedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox, false ); - StopCheckInAnimation(); - - FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity ); - FadeInImage( checkBox, disabledBackgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = UnselectedDisabledTransition; - } - break; - } - case SelectedDisabledTransition: - { - if( !disabled ) - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox, false ); - StopCheckInAnimation(); - - FadeOutImage( checkBox, Foreground, disabledSelectedImage, 1.f - opacity ); - FadeOutImage( checkBox, Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( checkBox, selectedImage, opacity ); - FadeInImage( checkBox, backgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = DisabledSelectedTransition; - } - break; - } - case DisabledSelectedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox, false ); - StopCheckInAnimation(); - - FadeOutImage( checkBox, Foreground, selectedImage, 1.f - opacity ); - FadeOutImage( checkBox, Background, backgroundImage, 1.f - opacity ); - FadeInImage( checkBox, disabledSelectedImage, opacity ); - FadeInImage( checkBox, disabledBackgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - - mPaintState = SelectedDisabledTransition; - } - break; - } - default: - break; - } -} - -void CheckBoxButtonDefaultPainter::SetAnimationTime( float animationTime ) -{ - mAnimationTime = animationTime; -} - -float CheckBoxButtonDefaultPainter::GetAnimationTime() const -{ - return mAnimationTime; -} - -void CheckBoxButtonDefaultPainter::SetSelectedImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button ); - Actor& selectedImage = checkBoxImpl.GetSelectedImage(); - Actor& fadeOutSelectedImage = checkBoxImpl.GetFadeOutSelectedImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - switch( mPaintState ) - { - case SelectedState: - { - if( selectedImage && selectedImage.GetParent() ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Foreground, selectedImage ); - - selectedImage = image; - - FadeInImage( checkBox, selectedImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - } - else - { - selectedImage = image; - checkBox.Add( selectedImage ); - } - break; - } - case UnselectedSelectedTransition: // FALLTHROUGH - case DisabledSelectedTransition: - { - StopCheckInAnimation(); - checkBox.Remove( selectedImage ); - - selectedImage = image; - - FadeInImage( checkBox, selectedImage ); - StartCheckInAnimation(); - break; - } - case SelectedUnselectedTransition: // FALLTHROUGH - case SelectedDisabledTransition: - { - float opacity = 1.f; - if( fadeOutSelectedImage ) - { - opacity = fadeOutSelectedImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - - // Replaces the button image. - selectedImage = image; - - checkBox.Add( selectedImage ); - FadeOutImage( checkBox, Foreground, selectedImage, opacity ); - - StartCheckOutAnimation( checkBox ); - break; - } - default: - { - selectedImage = image; - break; - } - } - - selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplySelectedConstraint( selectedImage, FOREGROUND_DEPTH ); -} - -void CheckBoxButtonDefaultPainter::SetBackgroundImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button ); - Actor& backgroundImage = checkBoxImpl.GetBackgroundImage(); - Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - switch( mPaintState ) - { - case UnselectedState: // FALLTHROUGH - case SelectedState: - case UnselectedSelectedTransition: - case SelectedUnselectedTransition: - { - if( backgroundImage && backgroundImage.GetParent() ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, backgroundImage ); - - backgroundImage = image; - - FadeInImage( checkBox, backgroundImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - } - else - { - backgroundImage = image; - checkBox.Add( backgroundImage ); - } - break; - } - case DisabledUnselectedTransition: // FALLTHROUGH - case DisabledSelectedTransition: - { - StopCheckInAnimation(); - checkBox.Remove( backgroundImage ); - - backgroundImage = image; - - FadeInImage( checkBox, backgroundImage ); - StartCheckInAnimation(); - break; - } - case SelectedDisabledTransition: // FALLTHROUGH - case UnselectedDisabledTransition: - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - - // Replaces the button image. - backgroundImage = image; - - checkBox.Add( backgroundImage ); - FadeOutImage( checkBox, Background, backgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - break; - } - default: - { - backgroundImage = image; - break; - } - } - - backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( backgroundImage, BACKGROUND_DEPTH ); -} - -void CheckBoxButtonDefaultPainter::SetDisabledSelectedImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button ); - Actor& disabledSelectedImage = checkBoxImpl.GetDisabledSelectedImage(); - Actor& fadeOutSelectedImage = checkBoxImpl.GetFadeOutSelectedImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - switch( mPaintState ) - { - case DisabledSelectedState: - { - if( disabledSelectedImage && disabledSelectedImage.GetParent() ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Foreground, disabledSelectedImage ); - - disabledSelectedImage = image; - - FadeInImage( checkBox, disabledSelectedImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - } - else - { - disabledSelectedImage = image; - checkBox.Add( disabledSelectedImage ); - } - break; - } - case SelectedDisabledTransition: - { - StopCheckInAnimation(); - checkBox.Remove( disabledSelectedImage ); - - disabledSelectedImage = image; - - FadeInImage( checkBox, disabledSelectedImage ); - StartCheckInAnimation(); - break; - } - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( fadeOutSelectedImage ) - { - opacity = fadeOutSelectedImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - - // Replaces the button image. - disabledSelectedImage = image; - - checkBox.Add( disabledSelectedImage ); - FadeOutImage( checkBox, Foreground, disabledSelectedImage, opacity ); - - StartCheckOutAnimation( checkBox ); - break; - } - default: - { - disabledSelectedImage = image; - break; - } - } - - disabledSelectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledSelectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( disabledSelectedImage, FOREGROUND_DEPTH ); -} - -void CheckBoxButtonDefaultPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button ); - Actor& disabledBackgroundImage = checkBoxImpl.GetDisabledBackgroundImage(); - Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage(); - - Toolkit::CheckBoxButton& checkBox = static_cast( button ); - - switch( mPaintState ) - { - case DisabledSelectedState: // FALLTHROUGH - case DisabledUnselectedState: - { - if( disabledBackgroundImage && disabledBackgroundImage.GetParent() ) - { - StopCheckOutAnimation( checkBox ); - FadeOutImage( checkBox, Background, disabledBackgroundImage ); - - disabledBackgroundImage = image; - - FadeInImage( checkBox, disabledBackgroundImage ); - - StartCheckOutAnimation( checkBox ); - StartCheckInAnimation(); - } - else - { - disabledBackgroundImage = image; - checkBox.Add( disabledBackgroundImage ); - } - break; - } - case UnselectedDisabledTransition: // FALLTHROUGH - case SelectedDisabledTransition: - { - StopCheckInAnimation(); - checkBox.Remove( disabledBackgroundImage ); - - disabledBackgroundImage = image; - - FadeInImage( checkBox, disabledBackgroundImage ); - StartCheckInAnimation(); - break; - } - case DisabledUnselectedTransition: // FALLTHROUGH - case DisabledSelectedTransition: - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBox ); - - // Replaces the button image. - disabledBackgroundImage = image; - - checkBox.Add( disabledBackgroundImage ); - FadeOutImage( checkBox, Background, disabledBackgroundImage, opacity ); - - StartCheckOutAnimation( checkBox ); - break; - } - default: - { - disabledBackgroundImage = image; - break; - } - } - - disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH ); -} - -void CheckBoxButtonDefaultPainter::Selected( Toolkit::Button& button ) -{ - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( button ); - Actor& selectedImage = checkBoxImpl.GetSelectedImage(); - Actor& fadeOutSelectedImage = checkBoxImpl.GetFadeOutSelectedImage(); - - Toolkit::CheckBoxButton& checkBoxButton = static_cast( button ); - - switch( mPaintState ) - { - case UnselectedState: - { - // Fade in the 'check' actor. - FadeInImage( checkBoxButton, selectedImage ); - SetupSelectedAnimation( checkBoxButton, selectedImage ); // Animate in the check actor - StartCheckInAnimation(); - - mPaintState = UnselectedSelectedTransition; - break; - } - case SelectedState: - { - // Fade out the 'check' actor. - StopCheckOutAnimation( checkBoxButton ); - FadeOutImage( checkBoxButton, Foreground, selectedImage ); - StartCheckOutAnimation( checkBoxButton ); - - mPaintState = UnselectedState; - break; - } - case UnselectedSelectedTransition: - { - // Stop fade in and start fade out. - StopCheckOutAnimation( checkBoxButton ); - StopCheckInAnimation(); - - float opacity = 0.f; - if( selectedImage ) - { - opacity = selectedImage.GetCurrentOpacity(); - } - FadeOutImage( checkBoxButton, Foreground, selectedImage, opacity ); - StartCheckOutAnimation( checkBoxButton ); - - mPaintState = UnselectedState; - break; - } - case SelectedUnselectedTransition: - { - // Stop fade out and start fade in. - float opacity = 1.f; - if( fadeOutSelectedImage ) - { - opacity = fadeOutSelectedImage.GetCurrentOpacity(); - } - StopCheckOutAnimation( checkBoxButton ); - - FadeInImage( checkBoxButton, selectedImage, opacity ); - StartCheckInAnimation(); - - mPaintState = UnselectedSelectedTransition; - break; - } - default: - break; - } -} - -void CheckBoxButtonDefaultPainter::ApplyConstraint( Actor& actor, float depth ) -{ - if( actor ) - { - actor.RemoveConstraints(); - actor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - actor.SetZ( depth ); - } -} - -void CheckBoxButtonDefaultPainter::ApplySelectedConstraint( Actor& actor, float depth ) -{ - if( actor ) - { - actor.RemoveConstraints(); - actor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - actor.SetZ( depth ); - } -} - -void CheckBoxButtonDefaultPainter::AddToFadeInAnimation( const Actor& actor ) -{ - if( !mCheckInAnimation ) - { - mCheckInAnimation = Dali::Animation::New( mAnimationTime ); - } - - mCheckInAnimation.OpacityTo( actor, 1.f ); - -} - -void CheckBoxButtonDefaultPainter::StartCheckInAnimation() -{ - if( mCheckInAnimation ) - { - mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckInAnimationFinished ); - mCheckInAnimation.Play(); - } -} - -void CheckBoxButtonDefaultPainter::StopCheckInAnimation() -{ - if( mCheckInAnimation ) - { - mCheckInAnimation.Clear(); - mCheckInAnimation.Reset(); - } -} - -void CheckBoxButtonDefaultPainter::AddToFadeOutAnimation( const Actor& actor ) -{ - if( !mCheckOutAnimation ) - { - mCheckOutAnimation = Dali::Animation::New( mAnimationTime ); - } - - mCheckOutAnimation.OpacityTo( actor, 0.f ); -} - -void CheckBoxButtonDefaultPainter::StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox ) -{ - if( mCheckOutAnimation ) - { - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox ); - mButton = &checkBoxImpl; - - mCheckOutAnimation.FinishedSignal().Connect( this, &CheckBoxButtonDefaultPainter::CheckOutAnimationFinished ); - mCheckOutAnimation.Play(); - } -} - -void CheckBoxButtonDefaultPainter::StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove ) -{ - if( mCheckOutAnimation ) - { - mCheckOutAnimation.Clear(); - mCheckOutAnimation.Reset(); - } - - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox ); - Actor& fadeOutSelectedImage = checkBoxImpl.GetFadeOutSelectedImage(); - Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage(); - - if( remove ) - { - if( fadeOutSelectedImage && fadeOutSelectedImage.GetParent() ) - { - fadeOutSelectedImage.GetParent().Remove( fadeOutSelectedImage ); - } - - if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() ) - { - fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage ); - } - - fadeOutSelectedImage.Reset(); - fadeOutBackgroundImage.Reset(); - } -} - -void CheckBoxButtonDefaultPainter::FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity ) -{ - if( image ) - { - if( !image.GetParent() ) - { - checkBox.Add( image ); - } - - image.SetOpacity( 1.0f ); - } -} - -void CheckBoxButtonDefaultPainter::FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity ) -{ - if( image ) - { - Toolkit::Internal::CheckBoxButton& checkBoxImpl = GetCheckBoxButtonImpl( checkBox ); - Actor& fadeOutSelectedImage = checkBoxImpl.GetFadeOutSelectedImage(); - Actor& fadeOutBackgroundImage = checkBoxImpl.GetFadeOutBackgroundImage(); - - Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutSelectedImage ); - - actorLayer = image; - - actorLayer.SetOpacity( 0.0f ); - } -} - -void CheckBoxButtonDefaultPainter::AddToCheckInAnimation( const Actor& actor ) -{ - if( !mCheckInAnimation ) - { - mCheckInAnimation = Dali::Animation::New( mAnimationTime ); - } - - // UV anim - mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) ); - - // Actor size anim - Handle handle = actor; // Get rid of const - mCheckInAnimation.AnimateTo( Property( handle, Actor::SCALE_X ), 1.0f); -} - -void CheckBoxButtonDefaultPainter::SetupSelectedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image ) -{ - if( image ) - { - if( !mTickUVEffect ) - { - ImageActor imageActor = ImageActor::DownCast( image ); - mTickUVEffect = ImageRegionEffect::New(); - imageActor.SetShaderEffect( mTickUVEffect ); - } - - image.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - - mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) ); - - // Parent - if( !image.GetParent() ) - { - checkBox.Add( image ); - } - - AddToCheckInAnimation( image ); - } -} - -void CheckBoxButtonDefaultPainter::EndCheckOutAnimation() -{ - switch( mPaintState ) - { - case UnselectedSelectedTransition: - { - mPaintState = SelectedState; - break; - } - case SelectedUnselectedTransition: - { - mPaintState = UnselectedState; - break; - } - case UnselectedDisabledTransition: - { - mPaintState = DisabledUnselectedState; - break; - } - case DisabledUnselectedTransition: - { - mPaintState = UnselectedState; - break; - } - case SelectedDisabledTransition: - { - mPaintState = DisabledSelectedState; - break; - } - case DisabledSelectedTransition: - { - mPaintState = SelectedState; - break; - } - default: - { - break; - } - } -} - -void CheckBoxButtonDefaultPainter::CheckOutAnimationFinished( Dali::Animation& source ) -{ - EndCheckOutAnimation(); - - Toolkit::CheckBoxButton handle( mButton->GetOwner() ); - StopCheckOutAnimation( handle ); - mButton = NULL; -} - -void CheckBoxButtonDefaultPainter::CheckInAnimationFinished( Dali::Animation& source ) -{ - switch( mPaintState ) - { - case UnselectedSelectedTransition: - { - mPaintState = SelectedState; - break; - } - case SelectedUnselectedTransition: - { - mPaintState = UnselectedState; - break; - } - case UnselectedDisabledTransition: - { - mPaintState = DisabledUnselectedState; - break; - } - case DisabledUnselectedTransition: - { - mPaintState = UnselectedState; - break; - } - case SelectedDisabledTransition: - { - mPaintState = DisabledSelectedState; - break; - } - case DisabledSelectedTransition: - { - mPaintState = SelectedState; - break; - } - default: - { - break; - } - } - - StopCheckInAnimation(); -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.h b/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.h deleted file mode 100644 index 7985942..0000000 --- a/dali-toolkit/internal/controls/buttons/check-box-button-default-painter-impl.h +++ /dev/null @@ -1,308 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__ -#define __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__ - -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include -#include -#include -#include - -// INTERNAL INCLUDES -#include -#include "check-box-button-painter-impl.h" - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -// Forward declarations - -class CheckBoxButton; -class CheckBoxButtonDefaultPainter; - -// Type definitions - -typedef IntrusivePtr CheckBoxButtonDefaultPainterPtr; - -/** - * CheckBoxButtonDefaultPainter controls the Dali::Toolkit::CheckBoxButton appearance. - * - * This class inherits from Dali::Toolkit::Internal::CheckBoxButtonPainter and is registered in a - * Dali::Toolkit::Internal::CheckBoxButton object in order to receive the state changes. - */ -class CheckBoxButtonDefaultPainter : public CheckBoxButtonPainter -{ -public: - /** - * Constructor. - * - * Set actors and animations to NULL. - */ - CheckBoxButtonDefaultPainter(); - - /** - * Destructor. - * - * It clears all fade in or fade out animations. - */ - ~CheckBoxButtonDefaultPainter(); - - ///////////////////////////////////////////////////////////////////////////// - // ButtonPainter interface - ///////////////////////////////////////////////////////////////////////////// - - /** - * @copydoc ButtonPainter::Initialize( Toolkit::Button& button ) - */ - virtual void Initialize( Toolkit::Button& button ); - - /** - * @copydoc ButtonPainter::SetSize( Toolkit::Button& button, const Vector3& size ) - */ - virtual void SetSize( Toolkit::Button& button, const Vector3& size ); - - /** - * @copydoc ButtonPainter::SetDisabled( Toolkit::Button& button, bool disabled ) - */ - virtual void SetDisabled( Toolkit::Button& button, bool disabled ); - - /** - * @copydoc ButtonPainter::SetAnimationTime( float animationTime ) - */ - virtual void SetAnimationTime( float animationTime ); - - /** - * @copydoc ButtonPainter::GetAnimationTime() - */ - virtual float GetAnimationTime() const; - - /** - * @copydoc ButtonPainter::SetSelectedImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetSelectedImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetBackgroundImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetBackgroundImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetDisabledSelectedImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetDisabledSelectedImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ); - - ///////////////////////////////////////////////////////////////////////////// - // CheckBoxButtonPainter interface - ///////////////////////////////////////////////////////////////////////////// - - /** - * This method is called when the Dali::Toolkit::Internal::CheckBoxButton in which this object is registered - * changes its state. - * - * @param[inout] checkBox The Dali::Toolkit::CheckBoxButton in which this object is registered. - */ - void Selected( Toolkit::Button& checkBox ); - -private: - - // Undefined - CheckBoxButtonDefaultPainter( const CheckBoxButtonDefaultPainter& ); - - // Undefined - CheckBoxButtonDefaultPainter& operator=( const CheckBoxButtonDefaultPainter& ); - -private: - - /** - * Default check box button painter states. - */ - enum PaintState - { - UnselectedState, ///< The check box button is unselected. - SelectedState, ///< The check box button is selected. - DisabledUnselectedState, ///< The check box button is disabled and unselected. - DisabledSelectedState, ///< The check box button is disabled and selected. - UnselectedSelectedTransition, ///< The check box button is in transition from unselected to selected. - SelectedUnselectedTransition, ///< The check box button is in transition from selected to unselected. - UnselectedDisabledTransition, ///< The check box button is in transition from unselected to disabled. - DisabledUnselectedTransition, ///< The check box button is in transition from disabled to unselected. - SelectedDisabledTransition, ///< The check box button is in transition from selected to disabled. - DisabledSelectedTransition ///< The check box button is in transition from disabled to selected. - }; - - /** - * Used in the FadeOut functions. - */ - enum ImageLayer - { - Background, ///< Fade out the background. - Foreground ///< Fade out the foreground. - }; - -private: - /** - * Apply size and position constraints to painter actors. - * - * @param[inout] actor The actor. - * @param[in] depth Depth position. - */ - void ApplyConstraint( Actor& actor, float depth ); - - /** - * Apply size constraint to check tick - * - * @param[inout] actor The actor. - * @param[in] depth Depth position. - */ - void ApplySelectedConstraint( Actor& actor, float depth ); - - /** - * Adds the actor to the fade in animation. It creates a fade in animation if needed. - * - * @param[in] actor The actor. - */ - void AddToFadeInAnimation( const Actor& actor ); - - /** - * Starts the check in animation. - * - * CheckBoxButtonDefaultPainter::CheckInAnimationFinished slot is called when the animation finishes. - */ - void StartCheckInAnimation(); - - /** - * Stops the check in animation. - */ - void StopCheckInAnimation(); - - /** - * Adds the actor to the fade out animation. It creates a fade out animation if needed. - * - * @param[in] actor The actor. - */ - void AddToFadeOutAnimation( const Actor& actor ); - - /** - * Starts the check out animation. - * - * CheckBoxButtonDefaultPainter::CheckOutAnimationFinished slot is called when the animation finishes. - * - * @param[inout] checkBox The button which holds images. - */ - void StartCheckOutAnimation( Toolkit::CheckBoxButton& checkBox ); - - /** - * Stops the fade out animation. - * - * It removes the actor stored in CheckBoxButtonDefaultPainter::mFadeOutBackgroundImage and - * CheckBoxButtonDefaultPainter::mFadeOutSelectedImage. - * - * @param[inout] checkBox The button which holds images. - * @param[in] remove If true, removes the fadeout actor from root. - */ - void StopCheckOutAnimation( Toolkit::CheckBoxButton& checkBox, bool remove = true ); - - /** - * It adds the actor to the root actor and to the fade in animation. - * - * @param[inout] checkBox The button which holds images. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - */ - void FadeInImage( Toolkit::CheckBoxButton& checkBox, Actor& image, float opacity = 0.f ); - - /** - * It adds the actor fade out animation and stores it to be removed when the animation finishes. - * - * @param[inout] checkBox The button which holds images. - * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutSelectedImage member. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - */ - void FadeOutImage( Toolkit::CheckBoxButton& checkBox, ImageLayer layer, Actor& image, float opacity = 1.f ); - - /** - * Adds the actor to the fade in animation. It creates a fade in animation if needed. - * - * @param[in] actor The actor. - */ - void AddToCheckInAnimation( const Actor& actor ); - - /** - * It adds the actor to the root actor and to the fade in animation. - * - * @param[inout] checkBox The button which holds images. - * @param[inout] image The actor. - */ - void SetupSelectedAnimation( Toolkit::CheckBoxButton& checkBox, Actor& image ); - - /** - * Signal end of check out animation - */ - void EndCheckOutAnimation(); - - // slots - - /** - * Called when the fade out animation finishes. - * - * It changes the check button painter state and removes actors from the root. - */ - void CheckOutAnimationFinished( Dali::Animation& source ); - - /** - * Called when the fade in animation finishes. - * - * It changes the check button painter state. - */ - void CheckInAnimationFinished( Dali::Animation& source ); - -private: - bool mDisabled; ///< Stores the disabled property. - - PaintState mPaintState; ///< The painter state. - - Animation mCheckInAnimation; ///< Animation used in the state transitions. - Animation mCheckOutAnimation; ///< Animation used in the state transitions. - Internal::CheckBoxButton* mButton; ///< Temporary pointer used to remove fade out images from button. - float mAnimationTime; ///< The animation time. - - ImageRegionEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across - - Property::Index mPercentageParentSizeProperty; ///< Dynamic property on the image actor -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_DEFAULT_PAINTER_H__ diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index 9c898c7..d12eb43 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -19,11 +19,9 @@ #include "check-box-button-impl.h" // EXTERNAL INCLUDES +#include #include -// INTERNAL INCLUDES -#include "check-box-button-default-painter-impl.h" - namespace Dali { @@ -36,6 +34,13 @@ namespace Internal namespace { +const float FOREGROUND_DEPTH( 0.5f ); +const float BACKGROUND_DEPTH( 0.25f ); + +const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time + +const Vector3 DISTANCE_BETWEEN_IMAGE_AND_LABEL(5.0f, 0.0f, 0.0f); + BaseHandle Create() { return Toolkit::CheckBoxButton::New(); @@ -61,18 +66,426 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() } CheckBoxButton::CheckBoxButton() -: Button() +: Button(), + mPaintState( UnselectedState ) { - // Creates specific painter. - ButtonPainterPtr painter = new CheckBoxButtonDefaultPainter(); - SetPainter( painter ); - SetTogglableButton( true ); + + SetAnimationTime( ANIMATION_TIME ); } CheckBoxButton::~CheckBoxButton() { - SetPainter( NULL ); + if( mCheckInAnimation ) + { + mCheckInAnimation.Clear(); + } +} + +void CheckBoxButton::SetSelectedImage( Actor image ) +{ + Actor& selectedImage = GetSelectedImage(); + + switch( mPaintState ) + { + case SelectedState: + { + if( selectedImage && selectedImage.GetParent() ) + { + Self().Remove( selectedImage ); + } + + selectedImage = image; + Self().Add( selectedImage ); + break; + } + case UnselectedSelectedTransition: + { + StopCheckInAnimation(); + Self().Remove( selectedImage ); + + selectedImage = image; + Self().Add( selectedImage ); + + mPaintState = SelectedState; + break; + } + default: + { + selectedImage = image; + break; + } + } + + selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + selectedImage.SetZ( FOREGROUND_DEPTH ); +} + +void CheckBoxButton::SetBackgroundImage( Actor image ) +{ + Actor& backgroundImage = GetBackgroundImage(); + + switch( mPaintState ) + { + case UnselectedState: // FALLTHROUGH + case SelectedState: + case UnselectedSelectedTransition: + { + if( backgroundImage && backgroundImage.GetParent() ) + { + Self().Remove( backgroundImage ); + + Actor& label = GetLabel(); + + if( label ) + { + backgroundImage.Remove( label ); + image.Add( label ); + } + } + + backgroundImage = image; + Self().Add( backgroundImage ); + break; + } + default: + { + backgroundImage = image; + break; + } + } + + backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + backgroundImage.SetZ( BACKGROUND_DEPTH ); +} + +void CheckBoxButton::SetDisabledSelectedImage( Actor image ) +{ + Actor& disabledSelectedImage = GetDisabledSelectedImage(); + + switch( mPaintState ) + { + case DisabledSelectedState: + { + if( disabledSelectedImage && disabledSelectedImage.GetParent() ) + { + Self().Remove( disabledSelectedImage ); + } + + disabledSelectedImage = image; + Self().Add( disabledSelectedImage ); + break; + } + default: + { + disabledSelectedImage = image; + break; + } + } + + disabledSelectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + disabledSelectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + disabledSelectedImage.SetZ( FOREGROUND_DEPTH ); +} + +void CheckBoxButton::SetDisabledBackgroundImage( Actor image ) +{ + Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); + + switch( mPaintState ) + { + case DisabledSelectedState: + case DisabledUnselectedState: + { + if( disabledBackgroundImage && disabledBackgroundImage.GetParent() ) + { + Self().Remove( disabledBackgroundImage ); + + Actor& label = GetLabel(); + + if( label ) + { + disabledBackgroundImage.Remove( label ); + image.Add( label ); + } + } + + disabledBackgroundImage = image; + Self().Add( disabledBackgroundImage ); + break; + } + default: + { + disabledBackgroundImage = image; + break; + } + } + + disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + disabledBackgroundImage.SetZ( BACKGROUND_DEPTH ); +} + +void CheckBoxButton::OnLabelSet() +{ + Actor& label = GetLabel(); + + if( label ) + { + label.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); + label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + label.MoveBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + + if( IsDisabled() && GetDisabledBackgroundImage() ) + { + GetDisabledBackgroundImage().Add( label ); + } + else if ( GetBackgroundImage() ) + { + GetBackgroundImage().Add( label ); + } + else + { + Self().Add( label ); + } + } +} + +void CheckBoxButton::OnSelected( bool selected ) +{ + Actor& selectedImage = GetSelectedImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + AddChild( selectedImage ); + StartCheckInAnimation( selectedImage ); // Animate in the check actor + + mPaintState = UnselectedSelectedTransition; + break; + } + case SelectedState: + { + RemoveChild( selectedImage ); + + mPaintState = UnselectedState; + break; + } + case UnselectedSelectedTransition: + { + StopCheckInAnimation(); + RemoveChild( selectedImage ); + + mPaintState = UnselectedState; + break; + } + default: + break; + } +} + +void CheckBoxButton::OnDisabled( bool disabled ) +{ + Actor& backgroundImage = GetBackgroundImage(); + Actor& selectedImage = GetSelectedImage(); + Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); + Actor& disabledSelectedImage = GetDisabledSelectedImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + if( disabled ) + { + RemoveChild( backgroundImage ); + AddChild( disabledBackgroundImage ); + mPaintState = DisabledUnselectedState; + } + break; + } + case SelectedState: + { + if( disabled ) + { + RemoveChild( backgroundImage ); + RemoveChild( selectedImage ); + AddChild( disabledBackgroundImage ); + AddChild( disabledSelectedImage ); + + mPaintState = DisabledSelectedState; + } + break; + } + case DisabledUnselectedState: + { + if( !disabled ) + { + RemoveChild( disabledBackgroundImage ); + AddChild( backgroundImage ); + + mPaintState = UnselectedState; + } + break; + } + case DisabledSelectedState: + { + if( !disabled ) + { + RemoveChild( disabledBackgroundImage ); + RemoveChild( disabledSelectedImage ); + AddChild( backgroundImage ); + AddChild( selectedImage ); + + mPaintState = SelectedState; + } + break; + } + case UnselectedSelectedTransition: + { + if( disabled ) + { + StopCheckInAnimation(); + + RemoveChild( backgroundImage ); + RemoveChild( selectedImage ); + AddChild( disabledBackgroundImage ); + AddChild( disabledSelectedImage ); + + mPaintState = DisabledSelectedState; + } + break; + } + default: + break; + } + + Actor& label = GetLabel(); + + if( label ) + { + if( label.GetParent() ) + { + label.GetParent().Remove( label ); + } + + if( disabled && disabledBackgroundImage) + { + disabledBackgroundImage.Add( label ); + } + else if( backgroundImage ) + { + backgroundImage.Add( label ); + } + } +} + +void CheckBoxButton::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + Vector3 newSize; + + if( IsDisabled() && GetDisabledBackgroundImage() ) + { + newSize = GetDisabledBackgroundImage().GetNaturalSize(); + } + else if( GetBackgroundImage() ) + { + newSize = GetBackgroundImage().GetNaturalSize(); + } + + Actor& label = GetLabel(); + + if( label ) + { + // Offset the label from the radio button image + newSize.width += DISTANCE_BETWEEN_IMAGE_AND_LABEL.width; + + // Find the size of the control using size negotiation + Vector3 actorNaturalSize( label.GetNaturalSize() ); + Control::Relayout( label, Vector2( actorNaturalSize.width, actorNaturalSize.height ), container ); + + Vector3 actorSize( label.GetSize() ); + newSize.width += actorSize.width; + newSize.height = std::max( newSize.height, actorSize.height ); + } + + Self().SetSize( newSize ); +} + +void CheckBoxButton::AddChild( Actor& actor ) +{ + if( actor ) + { + Self().Add( actor); + } +} + +void CheckBoxButton::RemoveChild( Actor& actor ) +{ + if( actor ) + { + Self().Remove( actor ); + } +} + +void CheckBoxButton::StartCheckInAnimation( Actor& actor ) +{ + if( actor ) + { + if( !mTickUVEffect ) + { + ImageActor imageActor = ImageActor::DownCast( actor ); + mTickUVEffect = ImageRegionEffect::New(); + imageActor.SetShaderEffect( mTickUVEffect ); + } + + actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); + + mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) ); + + if( !mCheckInAnimation ) + { + mCheckInAnimation = Dali::Animation::New( GetAnimationTime() ); + } + + // UV anim + mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) ); + + // Actor size anim + mCheckInAnimation.AnimateTo( Property( actor, Actor::SCALE_X ), 1.0f); + + mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButton::CheckInAnimationFinished ); + mCheckInAnimation.Play(); + } +} + +void CheckBoxButton::StopCheckInAnimation() +{ + if( mCheckInAnimation ) + { + mCheckInAnimation.Clear(); + mCheckInAnimation.Reset(); + } +} + +void CheckBoxButton::CheckInAnimationFinished( Dali::Animation& source ) +{ + switch( mPaintState ) + { + case UnselectedSelectedTransition: + { + mPaintState = SelectedState; + break; + } + default: + { + break; + } + } + + StopCheckInAnimation(); } } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h index aa60871..9d4335a 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h @@ -20,9 +20,11 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include +#include #include "button-impl.h" @@ -50,7 +52,53 @@ public: */ static Dali::Toolkit::CheckBoxButton New(); -protected: +public: // From Button + + /** + * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image ) + */ + virtual void SetSelectedImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetBackgroundImage( Actor image ) + */ + virtual void SetBackgroundImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetDisabledSelectedImage( Actor image ) + */ + virtual void SetDisabledSelectedImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image ) + */ + virtual void SetDisabledBackgroundImage( Actor image ); + +private: // From Button + + /** + * @copydoc Toolkit::Internal::Button::OnLabelSet() + */ + virtual void OnLabelSet(); + + /** + * @copydoc Toolkit::Internal::Button::OnSelected() + */ + virtual void OnSelected( bool selected ); + + /** + * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled ) + */ + virtual void OnDisabled( bool disabled ); + +private: // From Control + + /** + * @copydoc Dali::Toolkit::Control::OnRelayout() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + +private: /** * Construct a new CheckBoxButton. @@ -64,11 +112,49 @@ protected: private: + /** + * Adds the actor to the button. + */ + void AddChild( Actor& actor ); + + /** + * Removes the actor from the button. + */ + void RemoveChild( Actor& actor ); + + /** + * Adds the actor to the check in animation. + * It creates a check in animation if needed and starts the check in animation. + * @param[in] actor The actor. + */ + void StartCheckInAnimation( Actor& actor ); + + /** + * Stops the check in animation. + */ + void StopCheckInAnimation(); + + // slots + + /** + * Called when the check in animation finishes. + * It changes the check button paint state. + */ + void CheckInAnimationFinished( Dali::Animation& source ); + +private: + // Undefined CheckBoxButton( const CheckBoxButton& ); // Undefined CheckBoxButton& operator=( const CheckBoxButton& ); + +private: + Animation mCheckInAnimation; ///< Animation used in the state transitions. + ImageRegionEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across + + PaintState mPaintState; ///< The paint state. }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-painter-impl.h b/dali-toolkit/internal/controls/buttons/check-box-button-painter-impl.h deleted file mode 100644 index 3151809..0000000 --- a/dali-toolkit/internal/controls/buttons/check-box-button-painter-impl.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_PAINTER_H__ -#define __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_PAINTER_H__ - -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include "button-painter-impl.h" - -namespace Dali -{ - -// Forward declarations - -class Image; - -namespace Toolkit -{ - -// Forward declarations - -class CheckBoxButton; - -namespace Internal -{ - -// Forward declarations - -class CheckBoxButtonPainter; - -/** - * CheckBoxButtonPainter methods should be implemented in a subclass. - */ -class CheckBoxButtonPainter : public ButtonPainter -{ -public: - /** - * Destructor. - */ - virtual ~CheckBoxButtonPainter() {} - - ///////////////////////////////////////////////////////////////////////////// - // ButtonPainter interface - ///////////////////////////////////////////////////////////////////////////// - - /** - * @copydoc ButtonPainter::Initialize( Toolkit::Button& button ) - */ - virtual void Initialize( Toolkit::Button& button ) = 0; - - /** - * @copydoc ButtonPainter::SetSize( Toolkit::Button& button, const Vector3& size ) - */ - virtual void SetSize( Toolkit::Button& button, const Vector3& size ) = 0; - - /** - * @copydoc ButtonPainter::SetDisabled( Toolkit::Button& button, bool disabled ) - */ - virtual void SetDisabled( Toolkit::Button& button, bool disabled ) = 0; - - /** - * @copydoc ButtonPainter::SetAnimationTime() - */ - virtual void SetAnimationTime( float animationTime ) = 0; - - /** - * @copydoc ButtonPainter::GetAnimationTime() - */ - virtual float GetAnimationTime() const = 0; -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_PAINTER_H__ diff --git a/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.cpp deleted file mode 100644 index 31176f4..0000000 --- a/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.cpp +++ /dev/null @@ -1,1323 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include "push-button-default-painter-impl.h" - -// EXTERNAL INCLUDES -#include -#include -#include -#include -#include -#include - -// INTERNAL INCLUDES -#include -#include "push-button-impl.h" - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -namespace -{ -const float LABEL_DEPTH( 0.75f ); -const float FOREGROUND_DEPTH( 0.5f ); -const float BACKGROUND_DEPTH( 0.25f ); - -const float ANIMATION_TIME( 0.2f ); - -inline Toolkit::Internal::PushButton& GetPushButtonImpl( Toolkit::Button& button ) -{ - DALI_ASSERT_ALWAYS( button ); - - Dali::RefObject& handle = button.GetImplementation(); - - return static_cast( handle ); -} - -inline const Toolkit::Internal::PushButton& GetPushButtonImpl( const Toolkit::Button& button ) -{ - DALI_ASSERT_ALWAYS( button ); - - const Dali::RefObject& handle = button.GetImplementation(); - - return static_cast( handle ); -} - -} - -PushButtonDefaultPainter::PushButtonDefaultPainter() -: PushButtonPainter(), - mAutoRepeating( false ), - mDisabled( false ), - mPaintState( ReleasedState ), - mButton( NULL ), - mAnimationTime( ANIMATION_TIME ), - mSize() -{ -} - -PushButtonDefaultPainter::~PushButtonDefaultPainter() -{ - if( mFadeInAnimation ) - { - mFadeInAnimation.Clear(); - } - if( mFadeOutAnimation ) - { - mFadeOutAnimation.Clear(); - } -} - -void PushButtonDefaultPainter::Initialize( Toolkit::Button& button ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& backgroundImage = pushButtonImpl.GetBackgroundImage(); - Actor& disabledImage = pushButtonImpl.GetDisabledImage(); - Actor& disabledBackgroundImage = pushButtonImpl.GetDisabledBackgroundImage(); - Actor& label = pushButtonImpl.GetLabel(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - if( buttonImage ) - { - SetButtonImage( pushButton, buttonImage ); - } - - if( backgroundImage ) - { - SetBackgroundImage( pushButton, backgroundImage ); - } - - if( selectedImage ) - { - SetSelectedImage( pushButton, selectedImage ); - } - - if( disabledImage ) - { - SetDisabledImage( pushButton, disabledImage ); - } - - if( disabledBackgroundImage ) - { - SetDisabledBackgroundImage( pushButton, disabledBackgroundImage ); - } - - if( label ) - { - SetLabel( pushButton, label ); - } - - SetDisabled( pushButton, mDisabled ); -} - -void PushButtonDefaultPainter::SetSize( Toolkit::Button& button, const Vector3& size ) -{ - if( size != mSize ) - { - mSize = size; - - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& backgroundImage = pushButtonImpl.GetBackgroundImage(); - Actor& disabledImage = pushButtonImpl.GetDisabledImage(); - Actor& disabledBackgroundImage = pushButtonImpl.GetDisabledBackgroundImage(); - Actor& label = pushButtonImpl.GetLabel(); - - ApplyConstraint( buttonImage, FOREGROUND_DEPTH ); - ApplyConstraint( backgroundImage, BACKGROUND_DEPTH ); - ApplyConstraint( selectedImage, FOREGROUND_DEPTH ); - ApplyConstraint( disabledImage, FOREGROUND_DEPTH ); - ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH ); - - if( label ) - { - label.SetPosition( 0.f, 0.f, LABEL_DEPTH ); - label.SetSize( mSize ); - } - } -} - -void PushButtonDefaultPainter::SetDisabled( Toolkit::Button& button, bool disabled ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& backgroundImage = pushButtonImpl.GetBackgroundImage(); - Actor& disabledImage = pushButtonImpl.GetDisabledImage(); - Actor& disabledBackgroundImage = pushButtonImpl.GetDisabledBackgroundImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - mDisabled = disabled; - - switch( mPaintState ) - { - case ReleasedState: - { - if( disabled ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, backgroundImage ); - FadeOutImage( pushButton, Foreground, buttonImage ); - FadeInImage( pushButton, disabledBackgroundImage ); - FadeInImage( pushButton, disabledImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = ReleasedDisabledTransition; - } - else - { - mPaintState = DisabledReleasedState; - } - } - break; - } - case PressedState: - { - if( disabled ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, backgroundImage ); - FadeOutImage( pushButton, Foreground, selectedImage ); - FadeInImage( pushButton, disabledBackgroundImage ); - FadeInImage( pushButton, disabledImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = PressedDisabledTransition; - } - else - { - mPaintState = DisabledPressedState; - } - } - break; - } - case DisabledReleasedState: - { - if( !disabled ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, disabledBackgroundImage ); - FadeOutImage( pushButton, Foreground, disabledImage ); - FadeInImage( pushButton, backgroundImage ); - FadeInImage( pushButton, buttonImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = DisabledReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - } - break; - } - case DisabledPressedState: - { - if( !disabled ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, disabledBackgroundImage ); - FadeOutImage( pushButton, Foreground, disabledImage ); - FadeInImage( pushButton, backgroundImage ); - FadeInImage( pushButton, selectedImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = DisabledPressedTransition; - } - else - { - mPaintState = PressedState; - } - } - break; - } - case ReleasedPressedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, selectedImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, backgroundImage ); - - FadeInImage( pushButton, disabledImage ); - FadeInImage( pushButton, disabledBackgroundImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = PressedDisabledTransition; - } - else - { - mPaintState = DisabledPressedState; - } - } - break; - } - case PressedReleasedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, buttonImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, backgroundImage ); - - FadeInImage( pushButton, disabledImage ); - FadeInImage( pushButton, disabledBackgroundImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = ReleasedDisabledTransition; - } - else - { - mPaintState = DisabledReleasedState; - } - } - break; - } - case ReleasedDisabledTransition: - { - if( !disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, disabledImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( pushButton, buttonImage, opacity ); - FadeInImage( pushButton, backgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = DisabledReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - } - break; - } - case DisabledReleasedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, buttonImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, backgroundImage, 1.f - opacity ); - FadeInImage( pushButton, disabledImage, opacity ); - FadeInImage( pushButton, disabledBackgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = ReleasedDisabledTransition; - } - else - { - mPaintState = DisabledReleasedState; - } - } - break; - } - case PressedDisabledTransition: - { - if( !disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, disabledImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( pushButton, selectedImage, opacity ); - FadeInImage( pushButton, backgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = DisabledPressedTransition; - } - else - { - mPaintState = PressedState; - } - } - break; - } - case DisabledPressedTransition: - { - if( disabled ) - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, selectedImage, 1.f - opacity ); - FadeOutImage( pushButton, Background, backgroundImage, 1.f - opacity ); - FadeInImage( pushButton, disabledImage, opacity ); - FadeInImage( pushButton, disabledBackgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) - { - mPaintState = PressedDisabledTransition; - } - else - { - mPaintState = DisabledPressedState; - } - } - break; - } - default: - break; - } -} - -void PushButtonDefaultPainter::SetAnimationTime( float animationTime ) -{ - mAnimationTime = animationTime; -} - -float PushButtonDefaultPainter::GetAnimationTime() const -{ - return mAnimationTime; -} - -void PushButtonDefaultPainter::SetAutoRepeating( bool autorepeating ) -{ - mAutoRepeating = autorepeating; -} - -void PushButtonDefaultPainter::SetLabel( Toolkit::Button& button, Actor label ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& labelActor = pushButtonImpl.GetLabel(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - if( labelActor && labelActor.GetParent() ) - { - labelActor.GetParent().Remove( labelActor ); - } - - labelActor = label; - labelActor.SetAnchorPoint( AnchorPoint::CENTER ); - labelActor.SetParentOrigin( ParentOrigin::CENTER ); - - labelActor.SetPosition( 0.f, 0.f, LABEL_DEPTH ); - labelActor.SetSize( mSize ); - - pushButton.Add( labelActor ); -} - -void PushButtonDefaultPainter::SetButtonImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case ReleasedState: - { - if( buttonImage && buttonImage.GetParent() ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, buttonImage ); - - buttonImage = image; - - FadeInImage( pushButton, buttonImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - } - else - { - buttonImage = image; - pushButton.Add( buttonImage ); - } - break; - } - case ReleasedPressedTransition: // FALLTHROUGH - case ReleasedDisabledTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - - // Replaces the button image. - buttonImage = image; - - pushButton.Add( buttonImage ); - FadeOutImage( pushButton, Foreground, buttonImage, opacity ); - - StartFadeOutAnimation( pushButton ); - break; - } - case PressedReleasedTransition: // FALLTHROUGH - case DisabledReleasedTransition: - { - StopFadeInAnimation(); - pushButton.Remove( buttonImage ); - - buttonImage = image; - - FadeInImage( pushButton, buttonImage ); - StartFadeInAnimation(); - break; - } - default: - buttonImage = image; - break; - } - - buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( buttonImage, FOREGROUND_DEPTH ); -} - -void PushButtonDefaultPainter::SetSelectedImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case PressedState: - { - if( selectedImage && selectedImage.GetParent() ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, selectedImage ); - - selectedImage = image; - - FadeInImage( pushButton, selectedImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - } - else - { - selectedImage = image; - pushButton.Add( selectedImage ); - } - break; - } - case PressedReleasedTransition: // FALLTHROUGH - case PressedDisabledTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - - // Replaces the button image. - selectedImage = image; - - pushButton.Add( selectedImage ); - FadeOutImage( pushButton, Foreground, selectedImage, opacity ); - - StartFadeOutAnimation( pushButton ); - break; - } - case ReleasedPressedTransition: // FALLTHROUGH - case DisabledPressedTransition: - { - StopFadeInAnimation(); - pushButton.Remove( selectedImage ); - - selectedImage = image; - - FadeInImage( pushButton, selectedImage ); - StartFadeInAnimation(); - break; - } - default: - selectedImage = image; - break; - } - - selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( selectedImage, FOREGROUND_DEPTH ); -} - -void PushButtonDefaultPainter::SetBackgroundImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& backgroundImage = pushButtonImpl.GetBackgroundImage(); - Actor& fadeOutBackgroundImage = pushButtonImpl.GetFadeOutBackgroundImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case ReleasedState: // FALLTHROUGH - case PressedState: - case ReleasedPressedTransition: - case PressedReleasedTransition: - { - if( backgroundImage && backgroundImage.GetParent() ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, backgroundImage ); - - backgroundImage = image; - - FadeInImage( pushButton, backgroundImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - } - else - { - backgroundImage = image; - pushButton.Add( backgroundImage ); - } - break; - } - case ReleasedDisabledTransition: // FALLTHROUGH - case PressedDisabledTransition: - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - - // Replaces the button image. - backgroundImage = image; - - pushButton.Add( backgroundImage ); - FadeOutImage( pushButton, Background, backgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - break; - } - case DisabledReleasedTransition: // FALLTHROUGH - case DisabledPressedTransition: - { - StopFadeInAnimation(); - pushButton.Remove( backgroundImage ); - - backgroundImage = image; - - FadeInImage( pushButton, backgroundImage ); - StartFadeInAnimation(); - break; - } - default: - backgroundImage = image; - break; - } - - backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( backgroundImage, BACKGROUND_DEPTH ); -} - -void PushButtonDefaultPainter::SetDisabledImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& disabledImage = pushButtonImpl.GetDisabledImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case DisabledReleasedState: // FALLTHROUGH - case DisabledPressedState: - { - if( disabledImage && disabledImage.GetParent() ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, disabledImage ); - - disabledImage = image; - - FadeInImage( pushButton, disabledImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - } - else - { - disabledImage = image; - pushButton.Add( disabledImage ); - } - break; - } - case ReleasedDisabledTransition: // FALLTHROUGH - case PressedDisabledTransition: - { - StopFadeInAnimation(); - pushButton.Remove( disabledImage ); - - disabledImage = image; - - FadeInImage( pushButton, disabledImage ); - StartFadeInAnimation(); - break; - } - case DisabledReleasedTransition: // FALLTHROUGH - case DisabledPressedTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - - // Replaces the button image. - disabledImage = image; - - pushButton.Add( disabledImage ); - FadeOutImage( pushButton, Foreground, disabledImage, opacity ); - - StartFadeOutAnimation( pushButton ); - break; - } - default: - disabledImage = image; - break; - } - - disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( disabledImage, FOREGROUND_DEPTH ); -} - -void PushButtonDefaultPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& disabledBackgroundImage = pushButtonImpl.GetDisabledBackgroundImage(); - Actor& fadeOutBackgroundImage = pushButtonImpl.GetFadeOutBackgroundImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case DisabledReleasedState: // FALLTHROUGH - case DisabledPressedState: - { - if( disabledBackgroundImage && disabledBackgroundImage.GetParent() ) - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Background, disabledBackgroundImage ); - - disabledBackgroundImage = image; - - FadeInImage( pushButton, disabledBackgroundImage ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - } - else - { - disabledBackgroundImage = image; - pushButton.Add( disabledBackgroundImage ); - } - break; - } - case ReleasedDisabledTransition: // FALLTHROUGH - case PressedDisabledTransition: - { - StopFadeInAnimation(); - pushButton.Remove( disabledBackgroundImage ); - - disabledBackgroundImage = image; - - FadeInImage( pushButton, disabledBackgroundImage ); - StartFadeInAnimation(); - break; - } - case DisabledReleasedTransition: // FALLTHROUGH - case DisabledPressedTransition: - { - float opacity = 1.f; - if( fadeOutBackgroundImage ) - { - opacity = fadeOutBackgroundImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton ); - - // Replaces the button image. - disabledBackgroundImage = image; - - pushButton.Add( disabledBackgroundImage ); - FadeOutImage( pushButton, Background, disabledBackgroundImage, opacity ); - - StartFadeOutAnimation( pushButton ); - break; - } - default: - disabledBackgroundImage = image; - break; - } - - disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - ApplyConstraint( disabledBackgroundImage, BACKGROUND_DEPTH ); -} - -void PushButtonDefaultPainter::Pressed( Toolkit::Button& button ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case ReleasedState: - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, buttonImage ); - FadeInImage( pushButton, selectedImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = ReleasedPressedTransition; - } - else - { - mPaintState = PressedState; - } - break; - } - case ReleasedPressedTransition: - { - if( !mAutoRepeating ) - { - mPaintState = PressedReleasedTransition; - } - break; - } - case PressedReleasedTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, buttonImage, 1.f - opacity ); - FadeInImage( pushButton, selectedImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = ReleasedPressedTransition; - } - else - { - mPaintState = PressedState; - } - break; - } - default: - break; - } -} - -void PushButtonDefaultPainter::Released( Toolkit::Button& button ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case PressedState: - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, selectedImage ); - FadeInImage( pushButton, buttonImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = PressedReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - break; - } - case ReleasedPressedTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, selectedImage, 1.f - opacity ); - FadeInImage( pushButton, buttonImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = PressedReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - break; - } - default: - { - break; - } - } -} - -void PushButtonDefaultPainter::Clicked( Toolkit::Button& button ) -{ - Released( button ); -} - -void PushButtonDefaultPainter::Selected( Toolkit::Button& button ) -{ - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( button ); - Actor& selectedImage = pushButtonImpl.GetSelectedImage(); - Actor& buttonImage = pushButtonImpl.GetButtonImage(); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - - Toolkit::PushButton& pushButton = static_cast( button ); - - switch( mPaintState ) - { - case ReleasedState: - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, buttonImage ); - FadeInImage( pushButton, selectedImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = ReleasedPressedTransition; - } - else - { - mPaintState = PressedState; - } - break; - } - case PressedState: - { - StopFadeOutAnimation( pushButton ); - FadeOutImage( pushButton, Foreground, selectedImage ); - FadeInImage( pushButton, buttonImage ); - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = PressedReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - break; - } - case ReleasedPressedTransition: - { - float opacity = 1.f; - if( fadeOutButtonImage ) - { - opacity = fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, selectedImage, 1.f - opacity ); - FadeInImage( pushButton, buttonImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = PressedReleasedTransition; - } - else - { - mPaintState = ReleasedState; - } - break; - } - case PressedReleasedTransition: - { - float opacity = 0.f; - if( fadeOutButtonImage ) - { - opacity = 1.f - fadeOutButtonImage.GetCurrentOpacity(); - } - StopFadeOutAnimation( pushButton, false ); - StopFadeInAnimation(); - - FadeOutImage( pushButton, Foreground, buttonImage, 1.f - opacity ); - FadeInImage( pushButton, selectedImage, opacity ); - - StartFadeOutAnimation( pushButton ); - StartFadeInAnimation(); - - if( buttonImage || selectedImage ) - { - mPaintState = ReleasedPressedTransition; - } - else - { - mPaintState = PressedState; - } - break; - } - default: - { - break; - } - } -} - -void PushButtonDefaultPainter::ApplyConstraint( Actor& actor, float depth ) -{ - if( actor ) - { - actor.SetPosition( 0.f, 0.f, depth ); - actor.RemoveConstraints(); - actor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - } -} - -void PushButtonDefaultPainter::AddToFadeInAnimation( const Actor& actor ) -{ - if( !mFadeInAnimation ) - { - mFadeInAnimation = Dali::Animation::New( mAnimationTime ); - } - - mFadeInAnimation.OpacityTo( actor, 1.f ); -} - -void PushButtonDefaultPainter::StartFadeInAnimation() -{ - if( mFadeInAnimation ) - { - mFadeInAnimation.FinishedSignal().Connect( this, &PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished ); - mFadeInAnimation.Play(); - } -} - -void PushButtonDefaultPainter::StopFadeInAnimation() -{ - if( mFadeInAnimation ) - { - mFadeInAnimation.Clear(); - mFadeInAnimation.Reset(); - } -} - -void PushButtonDefaultPainter::AddToFadeOutAnimation( const Actor& actor ) -{ - if( !mFadeOutAnimation ) - { - mFadeOutAnimation = Dali::Animation::New( mAnimationTime ); - } - - mFadeOutAnimation.OpacityTo( actor, 0.f ); -} - -void PushButtonDefaultPainter::StartFadeOutAnimation( Toolkit::PushButton& pushButton ) -{ - if( mFadeOutAnimation ) - { - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( pushButton ); - mButton = &pushButtonImpl; - - mFadeOutAnimation.FinishedSignal().Connect( this, &PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished ); - mFadeOutAnimation.Play(); - } -} - -void PushButtonDefaultPainter::StopFadeOutAnimation( Toolkit::PushButton& pushButton, bool remove ) -{ - if( mFadeOutAnimation ) - { - mFadeOutAnimation.Clear(); - } - - mFadeOutAnimation.Reset(); - - if( remove ) - { - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( pushButton ); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - Actor& fadeOutBackgroundImage = pushButtonImpl.GetFadeOutBackgroundImage(); - - if( fadeOutButtonImage && fadeOutButtonImage.GetParent() ) - { - fadeOutButtonImage.GetParent().Remove( fadeOutButtonImage ); - } - - if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() ) - { - fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage ); - } - - fadeOutButtonImage.Reset(); - fadeOutBackgroundImage.Reset(); - } -} - -void PushButtonDefaultPainter::FadeInImage( Toolkit::PushButton& pushButton, Actor& image, float opacity ) -{ - if( image ) - { - image.SetOpacity( opacity ); - if( !image.GetParent() ) - { - pushButton.Add( image ); - } - - AddToFadeInAnimation( image ); - } -} - -void PushButtonDefaultPainter::FadeOutImage( Toolkit::PushButton& pushButton, ImageLayer layer, Actor& image, float opacity ) -{ - if( image ) - { - Toolkit::Internal::PushButton& pushButtonImpl = GetPushButtonImpl( pushButton ); - Actor& fadeOutButtonImage = pushButtonImpl.GetFadeOutButtonImage(); - Actor& fadeOutBackgroundImage = pushButtonImpl.GetFadeOutBackgroundImage(); - - Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutButtonImage ); - - actorLayer = image; - actorLayer.SetOpacity( opacity ); - - AddToFadeOutAnimation( actorLayer ); - } -} - -void PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished( Dali::Animation& source ) -{ - switch( mPaintState ) - { - case ReleasedPressedTransition: - { - mPaintState = PressedState; - break; - } - case PressedReleasedTransition: - { - mPaintState = ReleasedState; - break; - } - case ReleasedDisabledTransition: - { - mPaintState = DisabledReleasedState; - break; - } - case DisabledReleasedTransition: - { - mPaintState = ReleasedState; - break; - } - case PressedDisabledTransition: - { - mPaintState = DisabledPressedState; - break; - } - case DisabledPressedTransition: - { - mPaintState = PressedState; - break; - } - default: - { - break; - } - } - - Toolkit::PushButton handle( mButton->GetOwner() ); - StopFadeOutAnimation( handle ); - mButton = NULL; -} - -void PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished( Dali::Animation& source ) -{ - switch( mPaintState ) - { - case ReleasedPressedTransition: - { - mPaintState = PressedState; - break; - } - case PressedReleasedTransition: - { - mPaintState = ReleasedState; - break; - } - case ReleasedDisabledTransition: - { - mPaintState = DisabledReleasedState; - break; - } - case DisabledReleasedTransition: - { - mPaintState = ReleasedState; - break; - } - case PressedDisabledTransition: - { - mPaintState = DisabledPressedState; - break; - } - case DisabledPressedTransition: - { - mPaintState = PressedState; - break; - } - default: - { - break; - } - } - - StopFadeInAnimation(); -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali diff --git a/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.h b/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.h deleted file mode 100644 index 312a43c..0000000 --- a/dali-toolkit/internal/controls/buttons/push-button-default-painter-impl.h +++ /dev/null @@ -1,296 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__ -#define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__ - -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include -#include -#include -#include - -// INTERNAL INCLUDES -#include "push-button-painter-impl.h" - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -// Forward declarations - -class PushButton; -class PushButtonDefaultPainter; - -// Type definitions - -typedef IntrusivePtr PushButtonDefaultPainterPtr; - -/** - * PushButtonDefaultPainter controls the Dali::Toolkit::PushButton appearance. - * - * This class inherits from Dali::Toolkit::Internal::PushButtonPainter and is registered in a - * Dali::Toolkit::Internal::PushButton object in order to receive the state changes. - */ -class PushButtonDefaultPainter : public PushButtonPainter -{ -public: - - /** - * Constructor. - * - * Set actors and animations to NULL. - */ - PushButtonDefaultPainter(); - - /** - * Destructor. - * - * It clears all fade in or fade out animations. - */ - ~PushButtonDefaultPainter(); - - ///////////////////////////////////////////////////////////////////////////// - // ButtonPainter interface - ///////////////////////////////////////////////////////////////////////////// - - /** - * @copydoc ButtonPainter::Initialize( Toolkit::Button& button ) - */ - virtual void Initialize( Toolkit::Button& button ); - - /** - * @copydoc ButtonPainter::SetSize( Toolkit::Button& button, const Vector3& size ) - */ - virtual void SetSize( Toolkit::Button& button, const Vector3& size ); - - /** - * @copydoc ButtonPainter::SetDisabled( Toolkit::Button& button, bool disabled ) - */ - virtual void SetDisabled( Toolkit::Button& button, bool disabled ); - - /** - * @copydoc ButtonPainter::SetAnimationTime( float animationTime ) - */ - virtual void SetAnimationTime( float animationTime ); - - /** - * @copydoc ButtonPainter::GetAnimationTime() - */ - virtual float GetAnimationTime() const; - - /** - * @copydoc ButtonPainter::SetLabel( Toolkit::Button& button, Actor label ) - */ - virtual void SetLabel( Toolkit::Button& button, Actor label ); - - /** - * @copydoc ButtonPainter::SetAutoRepeating( bool autorepeating ) - */ - virtual void SetAutoRepeating( bool autorepeating ); - - /** - * @copydoc ButtonPainter::SetButtonImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetButtonImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetSelectedImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetSelectedImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetBackgroundImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetBackgroundImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetDisabledImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetDisabledImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ) - */ - virtual void SetDisabledBackgroundImage( Toolkit::Button& button, Actor image ); - - /** - * @copydoc ButtonPainter::Pressed( Toolkit::Button& button ) - */ - void Pressed( Toolkit::Button& button ); - - /** - * @copydoc ButtonPainter::Released( Toolkit::Button& button ) - */ - void Released( Toolkit::Button& button ); - - /** - * @copydoc ButtonPainter::Clicked( Toolkit::Button& button ) - */ - void Clicked( Toolkit::Button& button ); - - /** - * @copydoc ButtonPainter::Selected( Toolkit::Button& button ) - */ - void Selected( Toolkit::Button& button ); - -private: - - // Undefined - PushButtonDefaultPainter( const PushButtonDefaultPainter& ); - - // Undefined - PushButtonDefaultPainter& operator=( const PushButtonDefaultPainter& ); - -private: - - /** - * Default push button painter states. - */ - enum PaintState - { - ReleasedState, ///< The push button is released. - PressedState, ///< The push button is pressed. - DisabledReleasedState, ///< The push button is disabled and released. - DisabledPressedState, ///< The push button is Disabled and pressed. - ReleasedPressedTransition, ///< The push button is in transition from released to pressed. - PressedReleasedTransition, ///< The push button is in transition from pressed to released. - ReleasedDisabledTransition, ///< The push button is in transition from released to disabled. - DisabledReleasedTransition, ///< The push button is in transition from disabled to released. - PressedDisabledTransition, ///< The push button is in transition from pressed to disabled. - DisabledPressedTransition ///< The push button is in transition from disabled to pressed. - }; - - /** - * Used in the FadeOut functions. - */ - enum ImageLayer - { - Background, ///< Fade out the background. - Foreground ///< Fade out the foreground. - }; - -private: - /** - * Apply size and position constraints to painter actors. - * - * @param[inout] actor The actor. - * @param[in] depth Depth position. - */ - void ApplyConstraint( Actor& actor, float depth ); - - /** - * Adds the actor to the fade in animation. It creates a fade in animation if needed. - * - * @param[in] actor The actor. - */ - void AddToFadeInAnimation( const Actor& actor ); - - /** - * Starts the fade in animation. - * - * PushButtonDefaultPainter::PressedReleasedFadeInAnimationFinished slot is called when the animation finishes. - */ - void StartFadeInAnimation(); - - /** - * Stops the fade in animation. - */ - void StopFadeInAnimation(); - - /** - * Adds the actor to the fade out animation. It creates a fade out animation if needed. - */ - void AddToFadeOutAnimation( const Actor& actor ); - - /** - * Starts the fade out animation. - * - * PushButtonDefaultPainter::PressedReleasedFadeOutAnimationFinished slot is called when the animation finishes. - * @param[inout] pushButton The button which holds images. - */ - void StartFadeOutAnimation( Toolkit::PushButton& pushButton ); - - /** - * Stops the fade out animation. - * - * It removes the actor stored in PushButtonDefaultPainter::mFadeOutBackgroundImage and - * PushButtonDefaultPainter::mFadeOutCheckedImage. - * - * @param[inout] pushButton The button which holds images. - * @param[in] remove If true, removes the fadeout actor from root. - */ - void StopFadeOutAnimation( Toolkit::PushButton& pushButton, bool remove = true ); - - /** - * It adds the actor to the root actor and to the fade in animation. - * - * @param[inout] pushButton The button which holds images. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - */ - void FadeInImage( Toolkit::PushButton& pushButton, Actor& image, float opacity = 0.f ); - - /** - * It adds the actor fade out animation and stores it to be removed when the animation finishes. - * @param[inout] pushButton The button which holds images. - * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member. - * @param[inout] image The actor. - * @param[in] opacity The initial opacity. - */ - void FadeOutImage( Toolkit::PushButton& pushButton, ImageLayer layer, Actor& image, float opacity = 1.f ); - - // slots - - /** - * Called when the fade out animation finishes. - * - * It changes the check button painter state and removes actors from the root. - */ - void PressedReleasedFadeOutAnimationFinished( Dali::Animation& source ); - - /** - * Called when the fade in animation finishes. - * - * It changes the check button painter state. - */ - void PressedReleasedFadeInAnimationFinished( Dali::Animation& source ); - -private: - bool mAutoRepeating; ///< Stores the autorepeating property. - bool mDisabled; ///< Stores the disabled property. - - PaintState mPaintState; ///< The painter state. - Animation mFadeInAnimation; ///< Animation used in the state transitions. - Animation mFadeOutAnimation; ///< Animation used in the state transitions. - Internal::PushButton* mButton; ///< Temporary pointer used to remove fade out images from button. - float mAnimationTime; ///< The animation time. - Vector3 mSize; ///< The button's size. -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_DEFAULT_PAINTER_H__ diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 0df4e3c..4aae15b 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -19,13 +19,10 @@ #include "push-button-impl.h" // EXTERNAL INCLUDES -#include #include #include // INTERNAL INCLUDES -#include "push-button-default-painter-impl.h" - #include #include @@ -41,6 +38,14 @@ namespace Internal namespace { +const float TEXT_PADDING = 12.0f; + +const float LABEL_DEPTH( 0.75f ); +const float FOREGROUND_DEPTH( 0.5f ); +const float BACKGROUND_DEPTH( 0.25f ); + +const float ANIMATION_TIME( 0.2f ); + BaseHandle Create() { return Toolkit::PushButton::New(); @@ -53,8 +58,6 @@ TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit:: namespace { -const float TEXT_PADDING = 12.0f; - /** * Find the first image actor in the actor hierarchy */ @@ -76,7 +79,6 @@ ImageActor FindImageActor( Actor root ) return imageActor; } - } // unnamed namespace Dali::Toolkit::PushButton PushButton::New() @@ -94,6 +96,373 @@ Dali::Toolkit::PushButton PushButton::New() return pushButton; } +PushButton::PushButton() +: Button(), + mSize(), + mPaintState( UnselectedState ) +{ + SetAnimationTime( ANIMATION_TIME ); +} + +PushButton::~PushButton() +{ +} + +void PushButton::SetButtonImage( Actor image ) +{ + Actor& buttonImage = GetButtonImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + if( buttonImage && buttonImage.GetParent() ) + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, buttonImage ); + + buttonImage = image; + + FadeInImage( buttonImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + } + else + { + buttonImage = image; + Self().Add( buttonImage ); + } + break; + } + case UnselectedSelectedTransition: // FALLTHROUGH + case UnselectedDisabledTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + + // Replaces the button image. + buttonImage = image; + + Self().Add( buttonImage ); + FadeOutImage( Foreground, buttonImage, opacity ); + + StartFadeOutAnimation(); + break; + } + case SelectedUnselectedTransition: // FALLTHROUGH + case DisabledUnselectedTransition: + { + StopFadeInAnimation(); + Self().Remove( buttonImage ); + + buttonImage = image; + + FadeInImage( buttonImage ); + StartFadeInAnimation(); + break; + } + default: + buttonImage = image; + break; + } + + buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + buttonImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); + buttonImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); +} + +void PushButton::SetSelectedImage( Actor image ) +{ + Actor& selectedImage = GetSelectedImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case SelectedState: + { + if( selectedImage && selectedImage.GetParent() ) + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, selectedImage ); + + selectedImage = image; + + FadeInImage( selectedImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + } + else + { + selectedImage = image; + Self().Add( selectedImage ); + } + break; + } + case SelectedUnselectedTransition: // FALLTHROUGH + case SelectedDisabledTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + + // Replaces the button image. + selectedImage = image; + + Self().Add( selectedImage ); + FadeOutImage( Foreground, selectedImage, opacity ); + + StartFadeOutAnimation(); + break; + } + case UnselectedSelectedTransition: // FALLTHROUGH + case DisabledSelectedTransition: + { + StopFadeInAnimation(); + Self().Remove( selectedImage ); + + selectedImage = image; + + FadeInImage( selectedImage ); + StartFadeInAnimation(); + break; + } + default: + selectedImage = image; + break; + } + + selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + selectedImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); + selectedImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); +} + +void PushButton::SetBackgroundImage( Actor image ) +{ + Actor& backgroundImage = GetBackgroundImage(); + Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage(); + + switch( mPaintState ) + { + case UnselectedState: // FALLTHROUGH + case SelectedState: + case UnselectedSelectedTransition: + case SelectedUnselectedTransition: + { + if( backgroundImage && backgroundImage.GetParent() ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, backgroundImage ); + + backgroundImage = image; + + FadeInImage( backgroundImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + } + else + { + backgroundImage = image; + Self().Add( backgroundImage ); + } + break; + } + case UnselectedDisabledTransition: // FALLTHROUGH + case SelectedDisabledTransition: + { + float opacity = 1.f; + if( fadeOutBackgroundImage ) + { + opacity = fadeOutBackgroundImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + + // Replaces the button image. + backgroundImage = image; + + Self().Add( backgroundImage ); + FadeOutImage( Background, backgroundImage, opacity ); + + StartFadeOutAnimation(); + break; + } + case DisabledUnselectedTransition: // FALLTHROUGH + case DisabledSelectedTransition: + { + StopFadeInAnimation(); + Self().Remove( backgroundImage ); + + backgroundImage = image; + + FadeInImage( backgroundImage ); + StartFadeInAnimation(); + break; + } + default: + backgroundImage = image; + break; + } + + backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + backgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH ); + backgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); +} + +void PushButton::SetDisabledImage( Actor image ) +{ + Actor& disabledImage = GetDisabledImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case DisabledUnselectedState: // FALLTHROUGH + case DisabledSelectedState: + { + if( disabledImage && disabledImage.GetParent() ) + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, disabledImage ); + + disabledImage = image; + + FadeInImage( disabledImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + } + else + { + disabledImage = image; + Self().Add( disabledImage ); + } + break; + } + case UnselectedDisabledTransition: // FALLTHROUGH + case SelectedDisabledTransition: + { + StopFadeInAnimation(); + Self().Remove( disabledImage ); + + disabledImage = image; + + FadeInImage( disabledImage ); + StartFadeInAnimation(); + break; + } + case DisabledUnselectedTransition: // FALLTHROUGH + case DisabledSelectedTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + + // Replaces the button image. + disabledImage = image; + + Self().Add( disabledImage ); + FadeOutImage( Foreground, disabledImage, opacity ); + + StartFadeOutAnimation(); + break; + } + default: + disabledImage = image; + break; + } + + disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + disabledImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); + disabledImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); +} + +void PushButton::SetDisabledBackgroundImage( Actor image ) +{ + Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); + Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage(); + + switch( mPaintState ) + { + case DisabledUnselectedState: // FALLTHROUGH + case DisabledSelectedState: + { + if( disabledBackgroundImage && disabledBackgroundImage.GetParent() ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, disabledBackgroundImage ); + + disabledBackgroundImage = image; + + FadeInImage( disabledBackgroundImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + } + else + { + disabledBackgroundImage = image; + Self().Add( disabledBackgroundImage ); + } + break; + } + case UnselectedDisabledTransition: // FALLTHROUGH + case SelectedDisabledTransition: + { + StopFadeInAnimation(); + Self().Remove( disabledBackgroundImage ); + + disabledBackgroundImage = image; + + FadeInImage( disabledBackgroundImage ); + StartFadeInAnimation(); + break; + } + case DisabledUnselectedTransition: // FALLTHROUGH + case DisabledSelectedTransition: + { + float opacity = 1.f; + if( fadeOutBackgroundImage ) + { + opacity = fadeOutBackgroundImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + + // Replaces the button image. + disabledBackgroundImage = image; + + Self().Add( disabledBackgroundImage ); + FadeOutImage( Background, disabledBackgroundImage, opacity ); + + StartFadeOutAnimation(); + break; + } + default: + disabledBackgroundImage = image; + break; + } + + disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); + disabledBackgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH ); + disabledBackgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); +} + void PushButton::OnButtonInitialize() { // Push button requires the Leave event. @@ -101,17 +470,562 @@ void PushButton::OnButtonInitialize() root.SetLeaveRequired( true ); } -PushButton::PushButton() -: Button() +void PushButton::OnLabelSet() { - // Creates specific painter.GetBu - ButtonPainterPtr painter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() ); - SetPainter( painter ); + Actor& label = GetLabel(); + + if( label ) + { + label.SetAnchorPoint( AnchorPoint::CENTER ); + label.SetParentOrigin( ParentOrigin::CENTER ); + label.SetPosition( 0.f, 0.f, LABEL_DEPTH ); + label.SetSize( mSize ); + + Self().Add( label ); + } } -PushButton::~PushButton() +void PushButton::OnSelected( bool selected ) +{ + Actor& selectedImage = GetSelectedImage(); + Actor& buttonImage = GetButtonImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, buttonImage ); + FadeInImage( selectedImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = UnselectedSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + break; + } + case SelectedState: + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, selectedImage ); + FadeInImage( buttonImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = SelectedUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + break; + } + case UnselectedSelectedTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, selectedImage, 1.f - opacity ); + FadeInImage( buttonImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = SelectedUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + break; + } + case SelectedUnselectedTransition: + { + float opacity = 0.f; + if( fadeOutButtonImage ) + { + opacity = 1.f - fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, buttonImage, 1.f - opacity ); + FadeInImage( selectedImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = UnselectedSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + break; + } + default: + { + break; + } + } +} + +void PushButton::OnDisabled( bool disabled ) +{ + Actor& buttonImage = GetButtonImage(); + Actor& selectedImage = GetSelectedImage(); + Actor& backgroundImage = GetBackgroundImage(); + Actor& disabledImage = GetDisabledImage(); + Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + if( disabled ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, backgroundImage ); + FadeOutImage( Foreground, buttonImage ); + FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = UnselectedDisabledTransition; + } + else + { + mPaintState = DisabledUnselectedState; + } + } + break; + } + case SelectedState: + { + if( disabled ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, backgroundImage ); + FadeOutImage( Foreground, selectedImage ); + FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = SelectedDisabledTransition; + } + else + { + mPaintState = DisabledSelectedState; + } + } + break; + } + case DisabledUnselectedState: + { + if( !disabled ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, disabledBackgroundImage ); + FadeOutImage( Foreground, disabledImage ); + FadeInImage( backgroundImage ); + FadeInImage( buttonImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = DisabledUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + } + break; + } + case DisabledSelectedState: + { + if( !disabled ) + { + StopFadeOutAnimation(); + FadeOutImage( Background, disabledBackgroundImage ); + FadeOutImage( Foreground, disabledImage ); + FadeInImage( backgroundImage ); + FadeInImage( selectedImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = DisabledSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + } + break; + } + case UnselectedSelectedTransition: + { + if( disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + StopFadeInAnimation(); + + FadeOutImage( Foreground, selectedImage, 1.f - opacity ); + FadeOutImage( Background, backgroundImage ); + + FadeInImage( disabledImage ); + FadeInImage( disabledBackgroundImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = SelectedDisabledTransition; + } + else + { + mPaintState = DisabledSelectedState; + } + } + break; + } + case SelectedUnselectedTransition: + { + if( disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation(); + StopFadeInAnimation(); + + FadeOutImage( Foreground, buttonImage, 1.f - opacity ); + FadeOutImage( Background, backgroundImage ); + + FadeInImage( disabledImage ); + FadeInImage( disabledBackgroundImage ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = UnselectedDisabledTransition; + } + else + { + mPaintState = DisabledUnselectedState; + } + } + break; + } + case UnselectedDisabledTransition: + { + if( !disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, disabledImage, 1.f - opacity ); + FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity ); + FadeInImage( buttonImage, opacity ); + FadeInImage( backgroundImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = DisabledUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + } + break; + } + case DisabledUnselectedTransition: + { + if( disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, buttonImage, 1.f - opacity ); + FadeOutImage( Background, backgroundImage, 1.f - opacity ); + FadeInImage( disabledImage, opacity ); + FadeInImage( disabledBackgroundImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = UnselectedDisabledTransition; + } + else + { + mPaintState = DisabledUnselectedState; + } + } + break; + } + case SelectedDisabledTransition: + { + if( !disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, disabledImage, 1.f - opacity ); + FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity ); + FadeInImage( selectedImage, opacity ); + FadeInImage( backgroundImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = DisabledSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + } + break; + } + case DisabledSelectedTransition: + { + if( disabled ) + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, selectedImage, 1.f - opacity ); + FadeOutImage( Background, backgroundImage, 1.f - opacity ); + FadeInImage( disabledImage, opacity ); + FadeInImage( disabledBackgroundImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage ) + { + mPaintState = SelectedDisabledTransition; + } + else + { + mPaintState = DisabledSelectedState; + } + } + break; + } + default: + break; + } +} + +void PushButton::OnPressed() { - SetPainter( NULL ); + Actor& selectedImage = GetSelectedImage(); + Actor& buttonImage = GetButtonImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case UnselectedState: + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, buttonImage ); + FadeInImage( selectedImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = UnselectedSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + break; + } + case UnselectedSelectedTransition: + { + if( !IsAutoRepeating() ) + { + mPaintState = SelectedUnselectedTransition; + } + break; + } + case SelectedUnselectedTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, buttonImage, 1.f - opacity ); + FadeInImage( selectedImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = UnselectedSelectedTransition; + } + else + { + mPaintState = SelectedState; + } + break; + } + default: + break; + } +} + +void PushButton::OnReleased() +{ + Actor& selectedImage = GetSelectedImage(); + Actor& buttonImage = GetButtonImage(); + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + + switch( mPaintState ) + { + case SelectedState: + { + StopFadeOutAnimation(); + FadeOutImage( Foreground, selectedImage ); + FadeInImage( buttonImage ); + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = SelectedUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + break; + } + case UnselectedSelectedTransition: + { + float opacity = 1.f; + if( fadeOutButtonImage ) + { + opacity = fadeOutButtonImage.GetCurrentOpacity(); + } + StopFadeOutAnimation( false ); + StopFadeInAnimation(); + + FadeOutImage( Foreground, selectedImage, 1.f - opacity ); + FadeInImage( buttonImage, opacity ); + + StartFadeOutAnimation(); + StartFadeInAnimation(); + + if( buttonImage || selectedImage ) + { + mPaintState = SelectedUnselectedTransition; + } + else + { + mPaintState = UnselectedState; + } + break; + } + default: + { + break; + } + } +} + +void PushButton::OnClicked() +{ + OnReleased(); +} + +void PushButton::OnControlSizeSet( const Vector3& targetSize ) +{ + if( targetSize != mSize ) + { + mSize = targetSize; + + Actor& label = GetLabel(); + + if( label ) + { + label.SetSize( mSize ); + } + } } Vector3 PushButton::GetNaturalSize() @@ -177,6 +1091,207 @@ Vector3 PushButton::GetNaturalSize() return size; } +Actor& PushButton::GetFadeOutButtonImage() +{ + return mFadeOutButtonContent; +} + +Actor& PushButton::GetFadeOutBackgroundImage() +{ + return mFadeOutBackgroundContent; +} + +void PushButton::AddToFadeInAnimation( const Actor& actor ) +{ + if( !mFadeInAnimation ) + { + mFadeInAnimation = Dali::Animation::New( GetAnimationTime() ); + } + + mFadeInAnimation.OpacityTo( actor, 1.f ); +} + +void PushButton::StartFadeInAnimation() +{ + if( mFadeInAnimation ) + { + mFadeInAnimation.FinishedSignal().Connect( this, &PushButton::FadeInAnimationFinished ); + mFadeInAnimation.Play(); + } +} + +void PushButton::StopFadeInAnimation() +{ + if( mFadeInAnimation ) + { + mFadeInAnimation.Clear(); + mFadeInAnimation.Reset(); + } +} + +void PushButton::AddToFadeOutAnimation( const Actor& actor ) +{ + if( !mFadeOutAnimation ) + { + mFadeOutAnimation = Dali::Animation::New( GetAnimationTime() ); + } + + mFadeOutAnimation.OpacityTo( actor, 0.f ); +} + +void PushButton::StartFadeOutAnimation() +{ + if( mFadeOutAnimation ) + { + mFadeOutAnimation.FinishedSignal().Connect( this, &PushButton::FadeOutAnimationFinished ); + mFadeOutAnimation.Play(); + } +} + +void PushButton::StopFadeOutAnimation( bool remove ) +{ + if( mFadeOutAnimation ) + { + mFadeOutAnimation.Clear(); + mFadeOutAnimation.Reset(); + } + + if( remove ) + { + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage(); + + if( fadeOutButtonImage && fadeOutButtonImage.GetParent() ) + { + fadeOutButtonImage.GetParent().Remove( fadeOutButtonImage ); + } + + if( fadeOutBackgroundImage && fadeOutBackgroundImage.GetParent() ) + { + fadeOutBackgroundImage.GetParent().Remove( fadeOutBackgroundImage ); + } + + fadeOutButtonImage.Reset(); + fadeOutBackgroundImage.Reset(); + } +} + +void PushButton::FadeInImage( Actor& image, float opacity ) +{ + if( image ) + { + image.SetOpacity( opacity ); + if( !image.GetParent() ) + { + Self().Add( image ); + } + + AddToFadeInAnimation( image ); + } +} + +void PushButton::FadeOutImage( ImageLayer layer, Actor& image, float opacity ) +{ + if( image ) + { + Actor& fadeOutButtonImage = GetFadeOutButtonImage(); + Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage(); + + Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutButtonImage ); + + actorLayer = image; + actorLayer.SetOpacity( opacity ); + + AddToFadeOutAnimation( actorLayer ); + } +} + +void PushButton::FadeOutAnimationFinished( Dali::Animation& source ) +{ + switch( mPaintState ) + { + case UnselectedSelectedTransition: + { + mPaintState = SelectedState; + break; + } + case SelectedUnselectedTransition: + { + mPaintState = UnselectedState; + break; + } + case UnselectedDisabledTransition: + { + mPaintState = DisabledUnselectedState; + break; + } + case DisabledUnselectedTransition: + { + mPaintState = UnselectedState; + break; + } + case SelectedDisabledTransition: + { + mPaintState = DisabledSelectedState; + break; + } + case DisabledSelectedTransition: + { + mPaintState = SelectedState; + break; + } + default: + { + break; + } + } + + StopFadeOutAnimation(); +} + +void PushButton::FadeInAnimationFinished( Dali::Animation& source ) +{ + switch( mPaintState ) + { + case UnselectedSelectedTransition: + { + mPaintState = SelectedState; + break; + } + case SelectedUnselectedTransition: + { + mPaintState = UnselectedState; + break; + } + case UnselectedDisabledTransition: + { + mPaintState = DisabledUnselectedState; + break; + } + case DisabledUnselectedTransition: + { + mPaintState = UnselectedState; + break; + } + case SelectedDisabledTransition: + { + mPaintState = DisabledSelectedState; + break; + } + case DisabledSelectedTransition: + { + mPaintState = SelectedState; + break; + } + default: + { + break; + } + } + + StopFadeInAnimation(); +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.h b/dali-toolkit/internal/controls/buttons/push-button-impl.h index 730b746..2784bab 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -49,29 +50,180 @@ public: */ static Dali::Toolkit::PushButton New(); -protected: // From Button +protected: /** - * Sets the Leave signal. + * Construct a new PushButton. + */ + PushButton(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~PushButton(); + +public: // From Button + + /** + * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image ) + */ + virtual void SetButtonImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image ) + */ + virtual void SetSelectedImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetBackgroundImage( Actor image ) + */ + virtual void SetBackgroundImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetDisabledImage( Actor image ) + */ + virtual void SetDisabledImage( Actor image ); + + /** + * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image ) + */ + virtual void SetDisabledBackgroundImage( Actor image ); + +private: // From Button + + /** + * @copydoc Toolkit::Internal::Button::OnButtonInitialize() */ virtual void OnButtonInitialize(); -protected: // From Control + /** + * @copydoc Toolkit::Internal::Button::OnLabelSet() + */ + virtual void OnLabelSet(); + + /** + * @copydoc Toolkit::Internal::Button::OnSelected() + */ + virtual void OnSelected( bool selected ); + + /** + * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled ) + */ + virtual void OnDisabled( bool disabled ); + + /** + * @copydoc Toolkit::Internal::Button::OnPressed() + */ + virtual void OnPressed(); + + /** + * @copydoc Toolkit::Internal::Button::OnReleased() + */ + virtual void OnReleased(); + + /** + * @copydoc Toolkit::Internal::Button::OnClicked() + */ + virtual void OnClicked(); + +private: // From Control + + /** + * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize ) + */ + virtual void OnControlSizeSet( const Vector3& targetSize ); /** - * @copydoc Control::GetNaturalSize() + * @copydoc Toolkit::Control::GetNaturalSize() */ virtual Vector3 GetNaturalSize(); +private: + /** - * Construct a new PushButton. + * Used in the FadeOut functions. */ - PushButton(); + enum ImageLayer + { + Background, ///< Fade out the background. + Foreground ///< Fade out the foreground. + }; /** - * A reference counted object may only be deleted by calling Unreference() + * Gets the button image that is fading out. + * @return A reference to the button image that is fading out. */ - virtual ~PushButton(); + Actor& GetFadeOutButtonImage(); + + /** + * Gets the background image that is fading out. + * @return A reference to the background image that is fading out. + */ + Actor& GetFadeOutBackgroundImage(); + + /** + * Adds the actor to the fade in animation. It creates a fade in animation if needed. + * @param[in] actor The actor. + */ + void AddToFadeInAnimation( const Actor& actor ); + + /** + * Starts the fade in animation. + * PushButton::FadeInAnimationFinished slot is called when the animation finishes. + */ + void StartFadeInAnimation(); + + /** + * Stops the fade in animation. + */ + void StopFadeInAnimation(); + + /** + * Adds the actor to the fade out animation. It creates a fade out animation if needed. + */ + void AddToFadeOutAnimation( const Actor& actor ); + + /** + * Starts the fade out animation. + * PushButton::FadeOutAnimationFinished slot is called when the animation finishes. + */ + void StartFadeOutAnimation(); + + /** + * Stops the fade out animation. + * It removes the actor stored in PushButton::mFadeOutBackgroundImage and PushButton::mFadeOutCheckedImage. + * @param[in] remove If true, removes the fadeout actor from root. + */ + void StopFadeOutAnimation( bool remove = true ); + + /** + * It adds the actor to the root actor and to the fade in animation. + * @param[inout] image The actor. + * @param[in] opacity The initial opacity. + */ + void FadeInImage( Actor& image, float opacity = 0.f ); + + /** + * It adds the actor fade out animation and stores it to be removed when the animation finishes. + * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member. + * @param[inout] image The actor. + * @param[in] opacity The initial opacity. + */ + void FadeOutImage( ImageLayer layer, Actor& image, float opacity = 1.f ); + + // slots + + /** + * Called when the fade out animation finishes. + * It changes the check button paint state and removes actors from the root. + */ + void FadeOutAnimationFinished( Dali::Animation& source ); + + /** + * Called when the fade in animation finishes. + * It changes the check button paint state. + */ + void FadeInAnimationFinished( Dali::Animation& source ); private: @@ -80,6 +232,18 @@ private: // Undefined PushButton& operator=( const PushButton& ); + +private: + + Animation mFadeInAnimation; ///< Animation used in the state transitions. + Animation mFadeOutAnimation; ///< Animation used in the state transitions. + + Actor mFadeOutButtonContent; ///< Stores a foreground content, which is in a fade out animation, to be removed when the animation finishes. + Actor mFadeOutBackgroundContent; ///< Stores a background content, which is in a fade out animation, to be removed when the animation finishes. + + Vector3 mSize; ///< The button's size. + + PaintState mPaintState; ///< The paint state. }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/push-button-painter-impl.h b/dali-toolkit/internal/controls/buttons/push-button-painter-impl.h deleted file mode 100644 index 9c43fe9..0000000 --- a/dali-toolkit/internal/controls/buttons/push-button-painter-impl.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_PAINTER_H__ -#define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_PAINTER_H__ - -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include "button-painter-impl.h" - -namespace Dali -{ - -// Forward declarations - -class Image; - -namespace Toolkit -{ - -// Forward declarations - -class PushButton; - -namespace Internal -{ - -// Forward declarations - -class PushButtonPainter; - -/** - * PushButtonPainter methods should be implemented in a subclass. - */ -class PushButtonPainter : public ButtonPainter -{ -public: - /** - * Destructor. - * - */ - virtual ~PushButtonPainter() {} - - ///////////////////////////////////////////////////////////////////////////// - // ButtonPainter interface - ///////////////////////////////////////////////////////////////////////////// - - /** - * @copydoc ButtonPainter::Initialize( Toolkit::Button& button ) - */ - virtual void Initialize( Toolkit::Button& button ) = 0; - - /** - * @copydoc ButtonPainter::SetSize( Toolkit::Button& button, const Vector3& size ) - */ - virtual void SetSize( Toolkit::Button& button, const Vector3& size ) = 0; - - /** - * @copydoc ButtonPainter::SetDisabled( Toolkit::Button& button, bool disabled ) - */ - virtual void SetDisabled( Toolkit::Button& button, bool disabled ) = 0; - - /** - * @copydoc ButtonPainter::SetAnimationTime() - */ - virtual void SetAnimationTime( float animationTime ) = 0; - - /** - * @copydoc ButtonPainter::GetAnimationTime() - */ - virtual float GetAnimationTime() const = 0; -}; - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_PAINTER_H__ diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp index 4ef25d9..d279697 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp @@ -23,8 +23,14 @@ #include #include -using namespace Dali; -using namespace Dali::Toolkit::Internal; +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ namespace { @@ -59,82 +65,171 @@ Dali::Toolkit::RadioButton RadioButton::New() RadioButton::RadioButton() { - mUnselectedImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR ); - mSelectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR ); - - mRadioIcon = Dali::ImageActor::New( mUnselectedImage ); - -// SetTogglableButton(true); - mTogglableButton = true; // TODO: Use SetTogglableButton() after refactoring painter + SetTogglableButton(true); } RadioButton::~RadioButton() { } -void RadioButton::SetLabel( Actor label ) +void RadioButton::SetButtonImage( Actor image ) { - if( mLabel != label ) + Actor& buttonImage = GetButtonImage(); + + if( !IsSelected() ) { - if( mLabel ) + if( buttonImage && buttonImage.GetParent() ) { - mRadioIcon.Remove( mLabel ); + buttonImage.GetParent().Remove( buttonImage ); + buttonImage.Reset(); } + Self().Add( image ); + + Actor& label = GetLabel(); + if( label ) { - label.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - label.MoveBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - mRadioIcon.Add( label ); + buttonImage.Remove( label ); + image.Add( label ); } + } - mLabel = label; + buttonImage = image; - RelayoutRequest(); + buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); +} + +void RadioButton::SetSelectedImage( Actor image ) +{ + Actor& selectedImage = GetSelectedImage(); + + if( IsSelected() ) + { + if( selectedImage && selectedImage.GetParent() ) + { + selectedImage.GetParent().Remove( selectedImage ); + selectedImage.Reset(); + } + + Self().Add( image ); + + Actor& label = GetLabel(); + + if( label ) + { + selectedImage.Remove( label ); + image.Add( label ); + } } + + selectedImage = image; + + selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); +} + +void RadioButton::OnButtonInitialize() +{ + Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR ); + Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR ); + + SetButtonImage( ImageActor::New( buttonImage ) ); + SetSelectedImage( ImageActor::New( selectedImage ) ); + + RelayoutRequest(); } -void RadioButton::SetSelected( bool selected ) +void RadioButton::OnButtonUp() { - if( IsSelected() != selected ) + if( ButtonDown == GetState() ) { - if( selected ) + // Don't allow selection on an already selected radio button + if( !IsSelected() ) { - Actor parent = Self().GetParent(); - if( parent ) - { - for( unsigned int i = 0; i < parent.GetChildCount(); ++i ) - { - Dali::Toolkit::RadioButton rbChild = Dali::Toolkit::RadioButton::DownCast(parent.GetChildAt(i)); + SetSelected(!IsSelected()); + } + } +} - if( rbChild ) - { - rbChild.SetSelected(false); - } - } - } +void RadioButton::OnLabelSet() +{ + Actor& label = GetLabel(); - mSelected = true; - mRadioIcon.SetImage(mSelectedImage); + if( label ) + { + label.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); + label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + label.MoveBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + + if( IsSelected() ) + { + GetSelectedImage().Add( label ); } else { - mSelected = false; - mRadioIcon.SetImage(mUnselectedImage); + GetButtonImage().Add( label ); } + } +} - // Raise state changed signal - Toolkit::RadioButton handle( GetOwner() ); - StateChangedSignal().Emit( handle ); +void RadioButton::OnSelected( bool selected ) +{ + Actor& buttonImage = GetButtonImage(); + Actor& selectedImage = GetSelectedImage(); + Actor& label = GetLabel(); + + if( selected ) + { + Actor parent = Self().GetParent(); + if( parent ) + { + for( unsigned int i = 0; i < parent.GetChildCount(); ++i ) + { + Dali::Toolkit::RadioButton rbChild = Dali::Toolkit::RadioButton::DownCast(parent.GetChildAt(i)); + + if( rbChild ) + { + rbChild.SetSelected(false); + } + } + } + + buttonImage.GetParent().Remove( buttonImage ); + Self().Add( selectedImage ); + + if( label ) + { + label.GetParent().Remove( label ); + selectedImage.Add( label ); + } + } + else + { + selectedImage.GetParent().Remove( selectedImage ); + Self().Add( buttonImage ); - RelayoutRequest(); + if( label ) + { + label.GetParent().Remove( label ); + buttonImage.Add( label ); + } } } void RadioButton::OnRelayout( const Vector2& /*size*/, ActorSizeContainer& container ) { - Vector3 newSize( mRadioIcon.GetNaturalSize() ); + Vector3 newSize; + + if( IsSelected() ) + { + newSize = GetSelectedImage().GetNaturalSize(); + } + else + { + newSize = GetButtonImage().GetNaturalSize(); + } Actor& label = GetLabel(); @@ -155,23 +250,8 @@ void RadioButton::OnRelayout( const Vector2& /*size*/, ActorSizeContainer& conta Self().SetSize( newSize ); } -void RadioButton::OnInitialize() -{ - mRadioIcon.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - mRadioIcon.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - Self().Add( mRadioIcon ); +} // namespace Internal - RelayoutRequest(); -} +} // namespace Toolkit -void RadioButton::OnButtonUp() -{ - if( ButtonDown == GetState() ) - { - // Don't allow selection on an already selected radio button - if( !IsSelected() ) - { - SetSelected(!IsSelected()); - } - } -} +} // namespace Dali diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.h b/dali-toolkit/internal/controls/buttons/radio-button-impl.h index dc31882..db28905 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.h @@ -41,7 +41,7 @@ namespace Internal */ class RadioButton: public Button { - public: +public: /** * Create a new RadioButton. @@ -70,45 +70,54 @@ class RadioButton: public Button */ virtual ~RadioButton(); +public: // From Button + /** - * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) + * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image ) */ - virtual void SetLabel( Actor label ); // TODO: After refactoring painter, this will be removed + virtual void SetButtonImage( Actor image ); /** - * @copydoc Dali::Toolkit::Button::SetSelected( bool selected ) + * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image ) */ - virtual void SetSelected( bool selected ); + virtual void SetSelectedImage( Actor image ); + +private: // From Button /** - * @copydoc Dali::Toolkit::Control::OnRelayout() + * @copydoc Toolkit::Internal::Button::OnButtonInitialize() */ - virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + virtual void OnButtonInitialize(); - protected: // From Control + /** + * @copydoc Toolkit::Internal::Button::OnButtonUp() + */ + virtual void OnButtonUp(); /** - * Sets the relative position of image and label. + * @copydoc Toolkit::Internal::Button::OnSelected() */ - virtual void OnInitialize(); + virtual void OnSelected( bool selected ); - protected: // From Button /** - * Change button state when the button is pressed. + * @copydoc Toolkit::Internal::Button::OnLabelSet() */ - virtual void OnButtonUp(); + virtual void OnLabelSet(); - private: +private: // From Control + + /** + * @copydoc Dali::Toolkit::Control::OnRelayout() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + +private: // Undefined RadioButton( const RadioButton& origin ); // Undefined RadioButton& operator=( const RadioButton& origin ); - - Image mUnselectedImage; ///< Stores the unselected image - Image mSelectedImage; ///< Stores the selected image - ImageActor mRadioIcon; ///< Stores the current image }; } // namespace Internal diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index da91a77..ccf5de4 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -14,9 +14,7 @@ toolkit_src_files = \ $(toolkit_src_dir)/controls/bloom-view/bloom-view-impl.cpp \ $(toolkit_src_dir)/controls/bubble-effect/bubble-emitter-impl.cpp \ $(toolkit_src_dir)/controls/buttons/button-impl.cpp \ - $(toolkit_src_dir)/controls/buttons/check-box-button-default-painter-impl.cpp \ $(toolkit_src_dir)/controls/buttons/check-box-button-impl.cpp \ - $(toolkit_src_dir)/controls/buttons/push-button-default-painter-impl.cpp \ $(toolkit_src_dir)/controls/buttons/push-button-impl.cpp \ $(toolkit_src_dir)/controls/buttons/radio-button-impl.cpp \ $(toolkit_src_dir)/controls/cluster/cluster-impl.cpp \ diff --git a/dali-toolkit/public-api/controls/buttons/check-box-button.cpp b/dali-toolkit/public-api/controls/buttons/check-box-button.cpp index b288451..179304d 100644 --- a/dali-toolkit/public-api/controls/buttons/check-box-button.cpp +++ b/dali-toolkit/public-api/controls/buttons/check-box-button.cpp @@ -22,6 +22,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -64,7 +65,7 @@ CheckBoxButton CheckBoxButton::DownCast( BaseHandle handle ) void CheckBoxButton::SetBackgroundImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( ImageActor::New( image ) ); } void CheckBoxButton::SetBackgroundImage( Actor image ) @@ -79,7 +80,7 @@ Actor CheckBoxButton::GetBackgroundImage() const void CheckBoxButton::SetSelectedImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( ImageActor::New( image ) ); } void CheckBoxButton::SetSelectedImage( Actor image ) @@ -87,7 +88,6 @@ void CheckBoxButton::SetSelectedImage( Actor image ) Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( image ); } - Actor CheckBoxButton::GetSelectedImage() const { return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage(); @@ -95,7 +95,7 @@ Actor CheckBoxButton::GetSelectedImage() const void CheckBoxButton::SetDisabledBackgroundImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( ImageActor::New( image ) ); } void CheckBoxButton::SetDisabledBackgroundImage( Actor image ) @@ -110,7 +110,7 @@ Actor CheckBoxButton::GetDisabledBackgroundImage() const void CheckBoxButton::SetDisabledSelectedImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( ImageActor::New( image ) ); } void CheckBoxButton::SetDisabledSelectedImage( Actor image ) diff --git a/dali-toolkit/public-api/controls/buttons/push-button.cpp b/dali-toolkit/public-api/controls/buttons/push-button.cpp index b3d4dd2..d2ae939 100644 --- a/dali-toolkit/public-api/controls/buttons/push-button.cpp +++ b/dali-toolkit/public-api/controls/buttons/push-button.cpp @@ -22,6 +22,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -75,7 +76,7 @@ PushButton PushButton::DownCast( BaseHandle handle ) void PushButton::SetButtonImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetButtonImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetButtonImage( ImageActor::New( image ) ); } void PushButton::SetButtonImage( Actor image ) @@ -90,7 +91,7 @@ Actor PushButton::GetButtonImage() const void PushButton::SetBackgroundImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( ImageActor::New( image ) ); } void PushButton::SetBackgroundImage( Actor image ) @@ -105,7 +106,7 @@ Actor PushButton::GetBackgroundImage() const void PushButton::SetSelectedImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( ImageActor::New( image ) ); } void PushButton::SetSelectedImage( Actor image ) @@ -120,7 +121,7 @@ Actor PushButton::GetSelectedImage() const void PushButton::SetDisabledBackgroundImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( ImageActor::New( image ) ); } void PushButton::SetDisabledBackgroundImage( Actor image ) @@ -135,7 +136,7 @@ Actor PushButton::GetDisabledBackgroundImage() const void PushButton::SetDisabledImage( Image image ) { - Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( image ); + Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( ImageActor::New( image ) ); } void PushButton::SetDisabledImage( Actor image )