X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.cpp;h=4548ac94b9e8ebbf78583bea9770657a76f2f991;hp=fb617239be2dc6829a11e25be05d1e952d6d3b79;hb=f3da11c2818c6d17706fbb2417f21b602b3190f5;hpb=ee3bdc95f623f41feb37be10f21bef1d9da1e805 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index fb61723..4548ac9 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -19,11 +19,41 @@ #include "button-impl.h" // EXTERNAL INCLUDES +#include // for strcmp #include +#include #include +#include #include -#include -#include +#include + +// INTERNAL INCLUDES +#include +#include + +/** + * Button states and contents + * (3) mSelectedContent + * (2) mUnselectedContent (2) mSelectedBackgroundContent + * (1) mBackgroundContent (1) mBackgroundContent + * < unselected > ----------------------- < selected > + * | OnSelect() | + * | OnDisabled() | OnDisabled() + * | | + * < disabled > < disabled-selected > + * (2) mDisabledContent (2) mDisabledSelectedContent + * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent + * + * The drawing order of child actors is as follows. + * + * Top mLabel + * | mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent + * | mSelectedBackgroundContent + * Bottom mBackgroundContent / mDisabledBackgroundContent + * + * Some of contents may be missed. + * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image. + */ namespace Dali { @@ -31,100 +61,201 @@ namespace Dali namespace Toolkit { -const Property::Index Button::PROPERTY_DISABLED = Internal::Button::BUTTON_PROPERTY_START_INDEX; -const Property::Index Button::PROPERTY_AUTO_REPEATING = Internal::Button::BUTTON_PROPERTY_START_INDEX + 1; -const Property::Index Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 2; -const Property::Index Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 3; -const Property::Index Button::PROPERTY_TOGGLABLE = Internal::Button::BUTTON_PROPERTY_START_INDEX + 4; -const Property::Index Button::PROPERTY_SELECTED = Internal::Button::BUTTON_PROPERTY_START_INDEX + 5; -const Property::Index Button::PROPERTY_NORMAL_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 6; -const Property::Index Button::PROPERTY_SELECTED_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 7; -const Property::Index Button::PROPERTY_DISABLED_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 8; -const Property::Index Button::PROPERTY_LABEL_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 9; - namespace Internal { namespace { -const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); -const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); - -// Signals - -const char* const SIGNAL_PRESSED = "pressed"; -const char* const SIGNAL_RELEASED = "released"; -const char* const SIGNAL_CLICKED = "clicked"; -const char* const SIGNAL_STATE_CHANGED = "state-changed"; - -// Actions - -const char* const ACTION_BUTTON_CLICK = "button-click"; - BaseHandle Create() { // empty handle as we cannot create button (but type registered for clicked signal) return BaseHandle(); } -TypeRegistration typeRegistration( typeid( Toolkit::Button ), typeid( Toolkit::Control ), Create ); +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create ); + +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", STRING, UNSELECTED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", STRING, SELECTED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", STRING, DISABLED_STATE_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL ) + +// Deprecated properties: +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT ) -SignalConnectorType signalConnector1( typeRegistration, SIGNAL_PRESSED , &Button::DoConnectSignal ); -SignalConnectorType signalConnector2( typeRegistration, SIGNAL_RELEASED, &Button::DoConnectSignal ); -SignalConnectorType signalConnector3( typeRegistration, SIGNAL_CLICKED, &Button::DoConnectSignal ); -SignalConnectorType signalConnector4( typeRegistration, SIGNAL_STATE_CHANGED, &Button::DoConnectSignal ); +// Signals: +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED ) -TypeAction action1( typeRegistration, ACTION_BUTTON_CLICK, &Button::DoAction ); +// Actions: +DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK ) -PropertyRegistration property1( typeRegistration, "disabled", Toolkit::Button::PROPERTY_DISABLED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property2( typeRegistration, "auto-repeating", Toolkit::Button::PROPERTY_AUTO_REPEATING, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property3( typeRegistration, "initial-auto-repeating-delay", Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property4( typeRegistration, "next-auto-repeating-delay", Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY, Property::FLOAT, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property5( typeRegistration, "togglable", Toolkit::Button::PROPERTY_TOGGLABLE, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property6( typeRegistration, "selected", Toolkit::Button::PROPERTY_SELECTED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property7( typeRegistration, "normal-state-actor", Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property8( typeRegistration, "selected-state-actor", Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property9( typeRegistration, "disabled-state-actor", Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty ); -PropertyRegistration property10( typeRegistration, "label-actor", Toolkit::Button::PROPERTY_LABEL_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty ); +DALI_TYPE_REGISTRATION_END() + +const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); +const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); } // unnamed namespace Button::Button() : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), - mTogglableButton( false ), - mSelected( false ), - mPainter( NULL ), 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 ), + mTogglableButton( false ), + mSelected( false ), mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ), mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ), + mAnimationTime( 0.0f ), mClickActionPerforming( false ), - mState( ButtonUp ) + mState( ButtonUp ), + mPaintState( UnselectedState ) { } Button::~Button() { - if( mAutoRepeatingTimer ) - { - mAutoRepeatingTimer.Reset(); - } } void Button::SetDisabled( bool disabled ) { + if( disabled == mDisabled ) + { + return; + } + + StopTransitionAnimation(); + mDisabled = disabled; - // Notifies the painter. - Toolkit::Button handle( GetOwner() ); - if( mPainter ) + // Notifies the derived class the button has been disabled. + OnDisabled(); + + switch( mPaintState ) { - mPainter->SetDisabled( handle, mDisabled ); + 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 @@ -140,17 +271,13 @@ 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 ); - mSelected = false; + SetSelected( false, false ); } } - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } bool Button::IsAutoRepeating() const @@ -188,9 +315,6 @@ void Button::SetTogglableButton( bool togglable ) if( togglable ) { mAutoRepeating = false; - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } } @@ -203,16 +327,91 @@ void Button::SetSelected( bool selected ) { if( !mDisabled && mTogglableButton && ( selected != mSelected ) ) { - mSelected = selected; + SetSelected( selected, true ); + } +} - Toolkit::Button handle( GetOwner() ); +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; + } + } - // Notifies the painter the button has been selected. - mPainter->Selected( handle ); + StartTransitionAnimation(); + + if( emitSignal ) + { + Toolkit::Button handle( GetOwner() ); // Emit signal. mStateChangedSignal.Emit( handle ); } + + RelayoutRequest(); } bool Button::IsSelected() const @@ -222,182 +421,398 @@ 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 ) +void Button::SetLabelText( 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 ); + Property::Map labelProperty; + labelProperty.Insert( "text", label ); + ModifyLabel( labelProperty ); +} - RelayoutRequest(); +std::string Button::GetLabelText() const +{ + Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel ); + if( label ) + { + return label.GetProperty( Dali::Toolkit::TextLabel::Property::TEXT ); + } + return std::string(); } -void Button::SetLabel( Actor label ) +void Button::ModifyLabel( const Property::Map& properties ) { - Toolkit::Button handle( GetOwner() ); + // 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 ); + } - mPainter->SetLabel( handle, label ); + // 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::GetLabel() const +Actor& Button::GetLabelActor() { return mLabel; } -Actor& Button::GetLabel() +void Button::SetDecoration( DecorationState state, Actor actor ) { - return mLabel; + if( mDecoration[ state ] && mDecoration[ state ].GetParent() ) + { + mDecoration[ state ].Unparent(); + } + + mDecoration[ state ] = actor; + mDecoration[ state ].SetColorMode( USE_OWN_COLOR ); + + ResetImageLayers(); + RelayoutRequest(); } -void Button::SetButtonImage( Image image ) +Actor& Button::GetDecoration( DecorationState state ) { - SetButtonImage( ImageActor::New( image ) ); + return mDecoration[ state ]; } -void Button::SetButtonImage( Actor image ) +void Button::SetupContent( Actor& actorToModify, Actor newActor ) { - Toolkit::Button handle( GetOwner() ); - mPainter->SetButtonImage( handle, image ); + 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(); + } } -Actor Button::GetButtonImage() const +void Button::SetUnselectedColor( const Vector4& color ) { - return mButtonImage; + 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. + SetupContent( mUnselectedContent, CreateSolidColorActor( mUnselectedColor ) ); + mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + } } -Actor& Button::GetButtonImage() +const Vector4 Button::GetUnselectedColor() const { - return mButtonImage; + return mUnselectedColor; } -void Button::SetSelectedImage( Image image ) +void Button::SetSelectedColor( const Vector4& color ) { - SetSelectedImage( ImageActor::New( image ) ); + 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. + SetupContent( mSelectedContent, CreateSolidColorActor( mSelectedColor ) ); + mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + } } -void Button::SetSelectedImage( Actor image ) +const Vector4 Button::GetSelectedColor() const { - Toolkit::Button handle( GetOwner() ); - mPainter->SetSelectedImage( handle, image ); + return mSelectedColor; } -Actor Button::GetSelectedImage() const +void Button::SetUnselectedImage( const std::string& filename ) { - return mSelectedImage; + ImageActor newContent; + if( !filename.empty() ) + { + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + newContent = ImageActor::New( resourceimage ); + } + } + else + { + newContent = ImageActor::New(); + } + + if( newContent ) + { + SetupContent( mUnselectedContent, newContent ); + + mUnselectedContent.SetColor( mUnselectedColor ); + + OnUnselectedImageSet(); + RelayoutRequest(); + } } -Actor& Button::GetSelectedImage() +Actor& Button::GetUnselectedImage() { - return mSelectedImage; + return mUnselectedContent; } -void Button::SetBackgroundImage( Image image ) +void Button::SetSelectedImage( const std::string& filename ) { - SetBackgroundImage( ImageActor::New( image ) ); + ImageActor newContent; + if( !filename.empty() ) + { + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + newContent = ImageActor::New( resourceimage ); + } + } + else + { + newContent = ImageActor::New(); + } + + if( newContent ) + { + SetupContent( mSelectedContent, newContent ); + + mSelectedContent.SetColor( mSelectedColor ); + + OnSelectedImageSet(); + RelayoutRequest(); + } } -void Button::SetBackgroundImage( Actor image ) +Actor& Button::GetSelectedImage() { - Toolkit::Button handle( GetOwner() ); - mPainter->SetBackgroundImage( handle, image ); + return mSelectedContent; } -Actor Button::GetBackgroundImage() const +void Button::SetBackgroundImage( const std::string& filename ) { - return mBackgroundImage; + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mBackgroundContent, ImageActor::New( resourceimage ) ); + + OnBackgroundImageSet(); + RelayoutRequest(); + } } Actor& Button::GetBackgroundImage() { - return mBackgroundImage; + return mBackgroundContent; } -void Button::SetDisabledImage( Image image ) +void Button::SetSelectedBackgroundImage( const std::string& filename ) { - SetDisabledImage( ImageActor::New( image ) ); + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mSelectedBackgroundContent, ImageActor::New( resourceimage ) ); + + OnSelectedBackgroundImageSet(); + RelayoutRequest(); + } } -void Button::SetDisabledImage( Actor image ) +Actor& Button::GetSelectedBackgroundImage() { - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledImage( handle, image ); + return mSelectedBackgroundContent; } -Actor Button::GetDisabledImage() const +void Button::SetDisabledImage( const std::string& filename ) { - return mDisabledImage; + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mDisabledContent, ImageActor::New( resourceimage ) ); + + OnDisabledImageSet(); + RelayoutRequest(); + } } Actor& Button::GetDisabledImage() { - return mDisabledImage; + return mDisabledContent; } -void Button::SetDisabledSelectedImage( Image image ) +void Button::SetDisabledSelectedImage( const std::string& filename ) { - SetDisabledSelectedImage( ImageActor::New( image ) ); + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mDisabledSelectedContent, ImageActor::New( resourceimage ) ); + + OnDisabledSelectedImageSet(); + RelayoutRequest(); + } } -void Button::SetDisabledSelectedImage( Actor image ) +Actor& Button::GetDisabledSelectedImage() { - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledSelectedImage( handle, image ); + return mDisabledSelectedContent; } -Actor Button::GetDisabledSelectedImage() const +void Button::SetDisabledBackgroundImage( const std::string& filename ) { - return mDisabledSelectedImage; + Image resourceimage = Dali::ResourceImage::New( filename ); + if( resourceimage ) + { + SetupContent( mDisabledBackgroundContent, ImageActor::New( resourceimage ) ); + + OnDisabledBackgroundImageSet(); + RelayoutRequest(); + } } -Actor& Button::GetDisabledSelectedImage() +Actor& Button::GetDisabledBackgroundImage() { - return mDisabledSelectedImage; + return mDisabledBackgroundContent; } -void Button::SetDisabledBackgroundImage( Image image ) +std::string Button::GetUnselectedImageFilename() const { - SetDisabledBackgroundImage( ImageActor::New( image ) ); + if( mUnselectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mUnselectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -void Button::SetDisabledBackgroundImage( Actor image ) +std::string Button::GetSelectedImageFilename() const { - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledBackgroundImage( handle, image ); + if( mSelectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mSelectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor Button::GetDisabledBackgroundImage() const +std::string Button::GetBackgroundImageFilename() const { - return mDisabledBackgroundImage; + if( mBackgroundContent ) + { + ResourceImage image = ResourceImage::DownCast( mBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetDisabledBackgroundImage() +std::string Button::GetSelectedBackgroundImageFilename() const { - return mDisabledBackgroundImage; + if( mSelectedBackgroundContent ) + { + ResourceImage image = ResourceImage::DownCast( mSelectedBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetFadeOutButtonImage() +std::string Button::GetDisabledImageFilename() const { - return mFadeOutButtonImage; + if( mDisabledContent ) + { + ResourceImage image = ResourceImage::DownCast( mDisabledContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetFadeOutSelectedImage() +std::string Button::GetDisabledSelectedImageFilename() const { - return mFadeOutSelectedImage; + if( mDisabledSelectedContent ) + { + ResourceImage image = ResourceImage::DownCast( mDisabledSelectedContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -Actor& Button::GetFadeOutBackgroundImage() +std::string Button::GetDisabledBackgroundImageFilename() const { - return mFadeOutBackgroundImage; + if( mDisabledBackgroundContent ) + { + ResourceImage image = ResourceImage::DownCast( mDisabledBackgroundContent ); + if( image ) + { + return image.GetUrl(); + } + } + return std::string(); } -bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ) +bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) { bool ret = false; @@ -409,14 +824,13 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) ) { - GetImplementation( button ).DoClickAction( attributes ); - ret = true; + ret = GetImplementation( button ).DoClickAction( attributes ); } return ret; } -void Button::DoClickAction( const PropertyValueContainer& attributes ) +bool Button::DoClickAction( const Property::Map& attributes ) { // Prevents the button signals from doing a recursive loop by sending an action // and re-emitting the signals. @@ -427,17 +841,11 @@ void Button::DoClickAction( const PropertyValueContainer& attributes ) mState = ButtonDown; OnButtonUp(); mClickActionPerforming = false; - } -} -void Button::OnAnimationTimeSet( float animationTime ) -{ - mPainter->SetAnimationTime( animationTime ); -} + return true; + } -float Button::OnAnimationTimeRequested() const -{ - return mPainter->GetAnimationTime(); + return false; } void Button::OnButtonStageDisconnection() @@ -446,10 +854,7 @@ void Button::OnButtonStageDisconnection() { if( !mTogglableButton ) { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been released. - mPainter->Released( handle ); + Released(); if( mAutoRepeating ) { @@ -463,19 +868,17 @@ void Button::OnButtonDown() { if( !mTogglableButton ) { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + Pressed(); if( mAutoRepeating ) { SetUpTimer( mInitialAutoRepeatingDelay ); } - - //Emit signal. - mPressedSignal.Emit( handle ); } + + // The pressed signal should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mPressedSignal.Emit( handle ); } void Button::OnButtonUp() @@ -488,21 +891,18 @@ void Button::OnButtonUp() } else { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been clicked. - mPainter->Released( handle ); - mPainter->Clicked( handle ); + Released(); if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); } - - //Emit signal. - mReleasedSignal.Emit( handle ); - mClickedSignal.Emit( handle ); } + + // The clicked and released signals should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); + mClickedSignal.Emit( handle ); } } @@ -512,19 +912,17 @@ void Button::OnTouchPointLeave() { if( !mTogglableButton ) { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been released. - mPainter->Released( handle ); + Released(); if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); } - - //Emit signal. - mReleasedSignal.Emit( handle ); } + + // The released signal should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); } } @@ -651,13 +1049,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(); @@ -669,20 +1060,24 @@ void Button::OnInitialize() self.SetKeyboardFocusable( true ); } -void Button::OnActivated() +bool Button::OnAccessibilityActivated() { - // When the button is activated, it performs the click action - PropertyValueContainer attributes; - DoClickAction( attributes ); + return OnKeyboardEnter(); } -void Button::OnControlSizeSet(const Vector3& targetSize) +bool Button::OnKeyboardEnter() { - Toolkit::Button handle( GetOwner() ); - if( mPainter ) - { - mPainter->SetSize( handle, targetSize ); - } + // When the enter key is pressed, or button is activated, the click action is performed. + Property::Map attributes; + bool ret = DoClickAction( attributes ); + + return ret; +} + +void Button::OnControlStageDisconnection() +{ + OnButtonStageDisconnection(); // Notification for derived classes. + mState = ButtonUp; } void Button::OnTap(Actor actor, const TapGesture& tap) @@ -705,10 +1100,9 @@ bool Button::AutoRepeatingSlot() // Restart the autorepeat timer. SetUpTimer( mNextAutoRepeatingDelay ); - Toolkit::Button handle( GetOwner() ); + Pressed(); - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + Toolkit::Button handle( GetOwner() ); //Emit signal. consumed = mReleasedSignal.Emit( handle ); @@ -719,15 +1113,75 @@ bool Button::AutoRepeatingSlot() return consumed; } -void Button::OnControlStageDisconnection() +void Button::Pressed() { - OnButtonStageDisconnection(); // Notification for derived classes. - mState = ButtonUp; + if( mPaintState == UnselectedState ) + { + StopTransitionAnimation(); + + // Notifies the derived class the button has been pressed. + OnPressed(); + + //Layer Order + //(4) mSelectedContent (Inserted) + //(3) 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; + + StartTransitionAnimation(); + } } -void Button::SetPainter(ButtonPainterPtr painter) +void Button::Released() { - mPainter = painter; + if( mPaintState == SelectedState ) + { + StopTransitionAnimation(); + + // Notifies the derived class the button has been released. + OnReleased(); + + //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; + + StartTransitionAnimation(); + } } Button::ButtonState Button::GetState() @@ -735,6 +1189,225 @@ Button::ButtonState Button::GetState() return mState; } +Button::PaintState Button::GetPaintState() +{ + return mPaintState; +} + +void Button::PrepareAddButtonImage( Actor& actor ) +{ + if( actor ) + { + actor.Unparent(); + Self().Add( actor ); + PrepareForTranstionOut( actor ); + } +} + +void Button::TransitionButtonImage( Actor& actor ) +{ + if( actor ) + { + if( !actor.GetParent() ) + { + Self().Add( actor ); + } + + OnTransitionIn( actor ); + } +} + +void Button::AddButtonImage( Actor& actor ) +{ + if( actor ) + { + actor.Unparent(); + Self().Add( actor ); + } +} + +void Button::ReAddLabel() +{ + if( mLabel ) + { + mLabel.Unparent(); + Self().Add( mLabel ); + } +} + +void Button::RemoveButtonImage( Actor& actor ) +{ + if( actor ) + { + if( actor.GetParent() ) + { + Self().Remove( actor ); + } + PrepareForTranstionIn( actor ); + } +} + +unsigned int Button::FindChildIndex( Actor& actor ) +{ + Actor self = Self(); + unsigned int childrenNum = self.GetChildCount(); + + for( unsigned int i = 0; i < childrenNum; i++ ) + { + Actor child = self.GetChildAt( i ); + if( child == actor ) + { + return i; + } + } + + return childrenNum; +} + +void Button::TransitionOut( Actor actor ) +{ + OnTransitionOut( actor ); +} + +void Button::ResetImageLayers() +{ + // Ensure that all layers are in the correct order and state according to the paint state + + switch( mPaintState ) + { + case UnselectedState: + { + //Layer Order + //(2) mUnselectedContent + //(1) mBackgroundContent + + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mSelectedBackgroundContent ); + RemoveButtonImage( mDisabledContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mDisabledBackgroundContent ); + + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mUnselectedContent ); + + PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + break; + } + case SelectedState: + { + //Layer Order + //(3) mSelectedContent + //(2) mSelectedBackgroundContent + //(1) mBackgroundContent + + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mDisabledContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mDisabledBackgroundContent ); + + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mSelectedBackgroundContent ); + PrepareAddButtonImage( mSelectedContent ); + + PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + break; + } + case DisabledUnselectedState: + { + //Layer Order + //(2) mDisabledContent + //(1) mDisabledBackgroundContent + + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mBackgroundContent ); + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mDisabledSelectedContent ); + RemoveButtonImage( mSelectedBackgroundContent ); + + PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ); + PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent ); + + PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + ReAddLabel(); + break; + } + case DisabledSelectedState: + { + //Layer Order + // (2) mDisabledSelectedContent + // (1) mDisabledBackgroundContent + + RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); + RemoveButtonImage( mUnselectedContent ); + RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); + RemoveButtonImage( mSelectedContent ); + RemoveButtonImage( mBackgroundContent ); + RemoveButtonImage( mSelectedBackgroundContent ); + RemoveButtonImage( mDisabledContent ); + + if( mDisabledBackgroundContent ) + { + PrepareAddButtonImage( mDisabledBackgroundContent ); + } + else + { + PrepareAddButtonImage( mBackgroundContent ); + PrepareAddButtonImage( mSelectedBackgroundContent ); + } + + PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent ); + + PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); + ReAddLabel(); + break; + } + } +} + +void Button::StartTransitionAnimation() +{ + if( mTransitionAnimation ) + { + mTransitionAnimation.Play(); + } + else + { + ResetImageLayers(); + } +} + +void Button::StopTransitionAnimation() +{ + if( mTransitionAnimation ) + { + mTransitionAnimation.Clear(); + mTransitionAnimation.Reset(); + } +} + +Dali::Animation Button::GetTransitionAnimation() +{ + if( !mTransitionAnimation ) + { + mTransitionAnimation = Dali::Animation::New( GetAnimationTime() ); + mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished ); + } + + return mTransitionAnimation; +} + +void Button::TransitionAnimationFinished( Dali::Animation& source ) +{ + StopTransitionAnimation(); + ResetImageLayers(); +} + void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) { Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) ); @@ -743,65 +1416,88 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope { switch ( index ) { - case Toolkit::Button::PROPERTY_DISABLED: + case Toolkit::Button::Property::DISABLED: { - GetImplementation( button ).SetDisabled( value.Get() ); + GetImplementation( button ).SetDisabled( value.Get< bool >() ); break; } - case Toolkit::Button::PROPERTY_AUTO_REPEATING: + case Toolkit::Button::Property::AUTO_REPEATING: { GetImplementation( button ).SetAutoRepeating( value.Get< bool >() ); break; } - case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY: + case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY: { GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() ); break; } - case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY: + case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY: { GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() ); break; } - case Toolkit::Button::PROPERTY_TOGGLABLE: + case Toolkit::Button::Property::TOGGLABLE: { GetImplementation( button ).SetTogglableButton( value.Get< bool >() ); break; } - case Toolkit::Button::PROPERTY_SELECTED: + case Toolkit::Button::Property::SELECTED: { GetImplementation( button ).SetSelected( value.Get< bool >() ); break; } - case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: + { + GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() ); + break; + } + + case Toolkit::Button::Property::SELECTED_STATE_IMAGE: { - GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetSelectedImage( value.Get< std::string >() ); break; } - case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR: + case Toolkit::Button::Property::DISABLED_STATE_IMAGE: { - GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetDisabledImage( value.Get< std::string >() ); break; } - case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_COLOR: { - GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetUnselectedColor( value.Get< Vector4 >() ); break; } - case Toolkit::Button::PROPERTY_LABEL_ACTOR: + case Toolkit::Button::Property::SELECTED_COLOR: { - GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) ); + GetImplementation( button ).SetSelectedColor( value.Get< Vector4 >() ); break; } + + case Toolkit::Button::Property::LABEL_TEXT: + { + GetImplementation( button ).SetLabelText( value.Get< std::string >() ); + break; + } + + case Toolkit::Button::Property::LABEL: + { + // Get a Property::Map from the property if possible. + Property::Map setPropertyMap; + if( value.Get( setPropertyMap ) ) + { + GetImplementation( button ).ModifyLabel( setPropertyMap ); + } + } + break; } } } @@ -816,71 +1512,82 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert { switch ( propertyIndex ) { - case Toolkit::Button::PROPERTY_DISABLED: + case Toolkit::Button::Property::DISABLED: { value = GetImplementation( button ).mDisabled; break; } - case Toolkit::Button::PROPERTY_AUTO_REPEATING: + case Toolkit::Button::Property::AUTO_REPEATING: { value = GetImplementation( button ).mAutoRepeating; break; } - case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY: + case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY: { value = GetImplementation( button ).mInitialAutoRepeatingDelay; break; } - case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY: + case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY: { value = GetImplementation( button ).mNextAutoRepeatingDelay; break; } - case Toolkit::Button::PROPERTY_TOGGLABLE: + case Toolkit::Button::Property::TOGGLABLE: { value = GetImplementation( button ).mTogglableButton; break; } - case Toolkit::Button::PROPERTY_SELECTED: + case Toolkit::Button::Property::SELECTED: { value = GetImplementation( button ).mSelected; break; } - case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR: + case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mButtonImage, map ); - value = map; + value = GetImplementation( button ).GetUnselectedImageFilename(); break; } - case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR: + case Toolkit::Button::Property::SELECTED_STATE_IMAGE: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedImage, map ); - value = map; + value = GetImplementation( button ).GetSelectedImageFilename(); break; } - case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR: + case Toolkit::Button::Property::DISABLED_STATE_IMAGE: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledImage, map ); - value = map; + value = GetImplementation( button ).GetDisabledImageFilename(); break; } - case Toolkit::Button::PROPERTY_LABEL_ACTOR: + case Toolkit::Button::Property::UNSELECTED_COLOR: { - Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map ); - value = map; + value = GetImplementation( button ).GetUnselectedColor(); + break; + } + + case Toolkit::Button::Property::SELECTED_COLOR: + { + value = GetImplementation( button ).GetSelectedColor(); + break; + } + + case Toolkit::Button::Property::LABEL_TEXT: + { + value = GetImplementation( button ).GetLabelText(); + break; + } + + case Toolkit::Button::Property::LABEL: + { + Property::Map emptyMap; + value = emptyMap; break; } } @@ -889,6 +1596,132 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert return value; } +// Deprecated API + +void Button::SetLabel( Actor label ) +{ + if( mLabel != label ) + { + if( mLabel && mLabel.GetParent() ) + { + mLabel.GetParent().Remove( mLabel ); + } + + mLabel = label; + mLabel.SetPosition( 0.0f, 0.0f ); + + // label should be the top of the button + Self().Add( mLabel ); + + ResetImageLayers(); + OnLabelSet( true ); + + RelayoutRequest(); + } +} + +void Button::SetButtonImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mUnselectedContent, image ); + + OnUnselectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetSelectedImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mSelectedContent, image ); + + OnSelectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mBackgroundContent, image ); + + OnBackgroundImageSet(); + RelayoutRequest(); + } +} + +void Button::SetSelectedBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mSelectedBackgroundContent, image ); + + OnSelectedBackgroundImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledContent, image ); + + OnDisabledImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledSelectedImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledSelectedContent, image ); + + OnDisabledSelectedImageSet(); + RelayoutRequest(); + } +} + +void Button::SetDisabledBackgroundImage( Actor image ) +{ + if( image ) + { + StopTransitionAnimation(); + + SetupContent( mDisabledBackgroundContent, image ); + + OnDisabledBackgroundImageSet(); + RelayoutRequest(); + } +} + +Actor Button::GetButtonImage() const +{ + return mUnselectedContent; +} + +Actor Button::GetSelectedImage() const +{ + return mSelectedContent; +} + + } // namespace Internal } // namespace Toolkit