+Button::Button()
+: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+ mAutoRepeatingTimer(),
+ mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default.
+ mSelectedColor( Color::WHITE ),
+ mDisabled( false ),
+ mAutoRepeating( false ),
+ mTogglableButton( false ),
+ mSelected( false ),
+ mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
+ mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
+ mAnimationTime( 0.0f ),
+ mClickActionPerforming( false ),
+ mState( ButtonUp ),
+ mPaintState( UnselectedState )
+{
+}
+
+Button::~Button()
+{
+}
+
+void Button::SetDisabled( bool disabled )
+{
+ if( disabled == mDisabled )
+ {
+ return;
+ }
+
+ StopTransitionAnimation();
+
+ mDisabled = disabled;
+
+ // Notifies the derived class the button has been disabled.
+ OnDisabled();
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ //Layer Order
+ //(3) mDisabledContent (Inserted)
+ //(4) mUnselectedContent
+ //(2) mDisabledBackgroundContent (Inserted)
+ //(1) mBackgroundContent
+
+ AddButtonImage( mBackgroundContent );
+ TransitionButtonImage( mDisabledBackgroundContent );
+ AddButtonImage( mUnselectedContent );
+ TransitionButtonImage( mDisabledContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
+ TransitionOut( mUnselectedContent );
+ TransitionOut( mSelectedContent );
+ TransitionOut( mBackgroundContent );
+ TransitionOut( mSelectedBackgroundContent );
+ TransitionOut( mDisabledSelectedContent );
+
+ mPaintState = DisabledUnselectedState;
+ break;
+ }
+ case SelectedState:
+ {
+ //Layer Order
+ //(5) mDisabledSelectedContent (Inserted)
+ //(4) mSelectedContent
+ //(3) mDisabledBackgroundContent (Inserted)
+ //(2) mSelectedBackgroundContent
+ //(1) mBackgroundContent
+
+ AddButtonImage( mBackgroundContent );
+ AddButtonImage( mSelectedBackgroundContent );
+ TransitionButtonImage( mDisabledBackgroundContent );
+ AddButtonImage( mSelectedContent );
+ TransitionButtonImage( mDisabledSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
+ TransitionOut( mUnselectedContent );
+ TransitionOut( mSelectedContent );
+ TransitionOut( mBackgroundContent );
+ TransitionOut( mSelectedBackgroundContent );
+ TransitionOut( mDisabledContent );
+
+ mPaintState = DisabledSelectedState;
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ //Layer Order
+ //(3) mUnselectedContent (Inserted)
+ //(4) mDisabledContent
+ //(2) mBackgroundContent (Inserted)
+ //(1) mDisabledBackgroundContent
+
+ AddButtonImage( mDisabledBackgroundContent );
+ TransitionButtonImage( mBackgroundContent );
+ AddButtonImage( mDisabledContent );
+ TransitionButtonImage( mUnselectedContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
+ TransitionOut( mSelectedContent );
+ TransitionOut( mSelectedBackgroundContent );
+ TransitionOut( mDisabledContent );
+ TransitionOut( mDisabledSelectedContent );
+ TransitionOut( mDisabledBackgroundContent );
+
+ mPaintState = UnselectedState;
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ //Layer Order
+ //(4) mSelectedContent (Inserted)
+ //(5) mDisabledSelectedContent
+ //(3) mSelectedBackgroundContent (Inserted)
+ //(2) mBackgroundContent (Inserted)
+ //(1) mDisabledBackgroundContent
+
+ AddButtonImage( mDisabledBackgroundContent );
+ TransitionButtonImage( mBackgroundContent );
+ TransitionButtonImage( mSelectedBackgroundContent );
+ AddButtonImage( mDisabledSelectedContent );
+ TransitionButtonImage( mSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
+ TransitionOut( mUnselectedContent );
+ TransitionOut( mDisabledContent );
+ TransitionOut( mDisabledSelectedContent );
+ TransitionOut( mDisabledBackgroundContent );
+
+ mPaintState = SelectedState;
+ break;
+ }
+ }
+
+ StartTransitionAnimation();
+}
+
+bool Button::IsDisabled() const
+{
+ return mDisabled;
+}
+
+void Button::SetAutoRepeating( bool autoRepeating )
+{
+ mAutoRepeating = autoRepeating;
+
+ // An autorepeating button can't be a togglable button.
+ if( autoRepeating )
+ {
+ mTogglableButton = false;
+
+ if( mSelected )
+ {
+ // Emit a signal is not wanted, only change the appearance.
+ SetSelected( false, false );
+ }
+ }
+}
+
+bool Button::IsAutoRepeating() const
+{
+ return mAutoRepeating;
+}
+
+void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
+{
+ DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
+ mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
+}
+
+float Button::GetInitialAutoRepeatingDelay() const
+{
+ return mInitialAutoRepeatingDelay;
+}
+
+void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+{
+ DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
+ mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
+}
+
+float Button::GetNextAutoRepeatingDelay() const
+{
+ return mNextAutoRepeatingDelay;
+}
+
+void Button::SetTogglableButton( bool togglable )
+{
+ mTogglableButton = togglable;
+
+ // A togglable button can't be an autorepeating button.
+ if( togglable )
+ {
+ mAutoRepeating = false;
+ }
+}
+
+bool Button::IsTogglableButton() const
+{
+ return mTogglableButton;
+}
+
+void Button::SetSelected( bool selected )
+{
+ if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
+ {
+ SetSelected( selected, true );
+ }
+}
+
+void Button::SetSelected( bool selected, bool emitSignal )
+{
+ StopTransitionAnimation();
+
+ mSelected = selected;
+
+ // Notifies the derived class the button has been selected.
+ OnSelected();
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ //Layer Order
+ //(3) mSelectedContent (Inserted)
+ //(4) mUnselectedContent
+ //(2) mSelectedBackgroundContent (Inserted)
+ //(1) mBackgroundContent
+
+ AddButtonImage( mBackgroundContent );
+ TransitionButtonImage( mSelectedBackgroundContent );
+ AddButtonImage( mUnselectedContent );
+ TransitionButtonImage( mSelectedContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
+ TransitionOut( mUnselectedContent );
+ TransitionOut( mDisabledContent );
+ TransitionOut( mDisabledSelectedContent );
+ TransitionOut( mDisabledBackgroundContent );
+
+ mPaintState = SelectedState;
+ break;
+ }
+ case SelectedState:
+ {
+ //Layer Order
+ //(3) mUnselectedContent (Inserted)
+ //(2) mSelectedContent
+ //(1) mBackgroundContent
+
+ AddButtonImage( mBackgroundContent );
+ AddButtonImage( mSelectedContent );
+ TransitionButtonImage( mUnselectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
+ TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
+
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
+ TransitionOut( mSelectedContent );
+ TransitionOut( mSelectedBackgroundContent );
+ TransitionOut( mDisabledContent );
+ TransitionOut( mDisabledSelectedContent );
+ TransitionOut( mDisabledBackgroundContent );
+
+ mPaintState = UnselectedState;
+ break;
+ }
+ case DisabledUnselectedState:
+ case DisabledSelectedState:
+ {
+ DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
+ break;
+ }
+ }
+
+ StartTransitionAnimation();
+
+ if( emitSignal )
+ {
+ Toolkit::Button handle( GetOwner() );
+
+ // Emit signal.
+ mStateChangedSignal.Emit( handle );
+ }
+
+ RelayoutRequest();
+}
+
+bool Button::IsSelected() const
+{
+ return mTogglableButton && mSelected;
+}
+
+void Button::SetAnimationTime( float animationTime )
+{
+ mAnimationTime = animationTime;
+}
+
+float Button::GetAnimationTime() const
+{
+ return mAnimationTime;
+}
+
+void Button::SetLabelText( const std::string& label )
+{
+ Property::Map labelProperty;
+ labelProperty.Insert( "text", label );
+ ModifyLabel( labelProperty );
+}
+
+std::string Button::GetLabelText() const
+{
+ Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
+ if( label )
+ {
+ return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
+ }
+ return std::string();
+}
+
+void Button::ModifyLabel( const Property::Map& properties )
+{
+ // If we don't have a label yet, create one.
+ if( !mLabel )
+ {
+ // If we don't have a label, create one and set it up.
+ // Note: The label text is set from the passed in property map after creation.
+ mLabel = Toolkit::TextLabel::New();
+ mLabel.SetPosition( 0.0f, 0.0f );
+ // label should be the top of the button
+ Self().Add( mLabel );
+ }
+
+ // Set any properties specified for the label by iterating through all property key-value pairs.
+ for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
+ {
+ const StringValuePair& propertyPair( properties.GetPair( i ) );
+
+ // Convert the property string to a property index.
+ Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
+ if( setPropertyIndex != Property::INVALID_INDEX )
+ {
+ // If the conversion worked, we have a valid property index,
+ // Set the property to the new value.
+ mLabel.SetProperty( setPropertyIndex, propertyPair.second );
+ }
+ }
+
+ // Notify derived button classes of the change.
+ OnLabelSet( false );
+
+ RelayoutRequest();
+}
+
+Actor& Button::GetLabelActor()
+{
+ return mLabel;
+}
+
+void Button::SetDecoration( DecorationState state, Actor actor )
+{
+ if( mDecoration[ state ] && mDecoration[ state ].GetParent() )
+ {
+ mDecoration[ state ].Unparent();
+ }
+
+ mDecoration[ state ] = actor;
+ mDecoration[ state ].SetColorMode( USE_OWN_COLOR );
+
+ ResetImageLayers();
+ RelayoutRequest();
+}
+
+Actor& Button::GetDecoration( DecorationState state )
+{
+ return mDecoration[ state ];
+}
+
+void Button::SetupContent( Actor& actorToModify, Actor newActor )
+{
+ if( newActor )
+ {
+ StopTransitionAnimation();
+
+ if( actorToModify && actorToModify.GetParent() )
+ {
+ actorToModify.Unparent();
+ }
+
+ actorToModify = newActor;
+
+ if( actorToModify )
+ {
+ actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ actorToModify.SetPosition( 0.f, 0.f );
+ }
+
+ ResetImageLayers();
+ }
+}
+
+void Button::SetUnselectedColor( const Vector4& color )
+{
+ mUnselectedColor = color;
+
+ if( mUnselectedContent && !GetUnselectedImageFilename().empty() )
+ {
+ // If there is existing unselected content, change the color on it directly.
+ mUnselectedContent.SetColor( mUnselectedColor );
+ }
+ else
+ {
+ // If there is no existing content, create a new actor to use for flat color.
+ Toolkit::Control unselectedContentActor = Toolkit::Control::New();
+ unselectedContentActor.SetBackgroundColor( mUnselectedColor );
+ SetupContent( mUnselectedContent, unselectedContentActor );
+ mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ }
+}
+
+const Vector4 Button::GetUnselectedColor() const
+{
+ return mUnselectedColor;
+}
+
+void Button::SetSelectedColor( const Vector4& color )
+{
+ mSelectedColor = color;
+
+ if( mSelectedContent && !GetSelectedImageFilename().empty() )
+ {
+ // If there is existing unselected content, change the color on it directly.
+ mSelectedContent.SetColor( mSelectedColor );
+ }
+ else
+ {
+ // If there is no existing content, create a new actor to use for flat color.
+ Toolkit::Control selectedContentActor = Toolkit::Control::New();
+ selectedContentActor.SetBackgroundColor( mSelectedColor );
+ SetupContent( mSelectedContent, selectedContentActor );
+ mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ }
+}
+
+const Vector4 Button::GetSelectedColor() const
+{
+ return mSelectedColor;
+}
+
+void Button::SetUnselectedImage( const std::string& filename )
+{
+ Toolkit::ImageView newContent;
+ if( !filename.empty() )
+ {
+ newContent = Toolkit::ImageView::New( filename );
+ }
+ else
+ {
+ newContent = Toolkit::ImageView::New();
+ }
+
+ if( newContent )
+ {
+ SetupContent( mUnselectedContent, newContent );
+
+ mUnselectedContent.SetColor( mUnselectedColor );
+
+ OnUnselectedImageSet();
+ RelayoutRequest();
+ }
+}
+
+Actor& Button::GetUnselectedImage()
+{
+ return mUnselectedContent;
+}
+
+void Button::SetSelectedImage( const std::string& filename )
+{
+ Toolkit::ImageView newContent;
+ if( !filename.empty() )
+ {
+ newContent = Toolkit::ImageView::New( filename );
+ }
+ else
+ {
+ newContent = Toolkit::ImageView::New();
+ }
+
+ if( newContent )
+ {
+ SetupContent( mSelectedContent, newContent );
+
+ mSelectedContent.SetColor( mSelectedColor );
+
+ OnSelectedImageSet();
+ RelayoutRequest();
+ }
+}
+
+Actor& Button::GetSelectedImage()
+{
+ return mSelectedContent;
+}
+
+void Button::SetBackgroundImage( const std::string& filename )