*/
// EXTERNAL INCLUDES
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/actors/renderable-actor.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
*/
// EXTERNAL INCLUDES
-#include <dali.h>
+#include <dali/public-api/math/rect.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector3.h>
+#include <dali/public-api/math/vector4.h>
+#include <dali/public-api/math/matrix.h>
+#include <dali/public-api/math/matrix3.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/builder/tree-node.h>
#include <sys/stat.h>
#include <boost/function.hpp>
#include <sstream>
-
+#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/object/type-info.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-
#include <dali-toolkit/public-api/controls/control.h>
#include <dali-toolkit/public-api/builder/json-parser.h>
#include <string>
#include <list>
#include <map>
+#include <dali/public-api/common/stage.h>
#include <dali/public-api/actors/actor.h>
#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/render-tasks/render-task.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
// EXTERNAL INCLUDES
#include <sstream>
+#include <dali/public-api/adaptor-framework/color-controller.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/builder/builder-impl.h>
*/
// EXTERNAL INCLUDES
-#include <dali/integration-api/debug.h>
#include <boost/function.hpp>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/object/type-info.h>
+#include <dali/public-api/object/property-notification.h>
+#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/builder/builder-impl.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+/**
+ * Button states and contents
+ * (3) mSelectedContent
+ * (2) mButtonContent (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
+ * | mButtonContent / 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
{
mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
mAnimationTime( 0.0f ),
mClickActionPerforming( false ),
- mState( ButtonUp )
+ mState( ButtonUp ),
+ mPaintState( UnselectedState )
{
}
{
if( disabled != mDisabled )
{
+ unsigned int backgroundIndex;
+ unsigned int buttonIndex;
+
+ bool animationStarted = false;
+
mDisabled = disabled;
- OnDisabled( mDisabled );
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledSelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+ InsertChild( backgroundIndex, mBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mDisabledContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mDisabledBackgroundContent );
+
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case UnselectedDisabledTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledUnselectedState;
+ }
+ break;
+ }
+ case SelectedDisabledTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = DisabledSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ animationStarted = OnDisabled();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedDisabledTransition;
+ }
+ else
+ {
+ mPaintState = DisabledSelectedState;
+ }
+ break;
+ }
+ }
}
}
if( mSelected )
{
// Emit a signal is not wanted, only change the appearance.
- OnSelected( false );
-
- mSelected = false;
-
- RelayoutRequest();
+ SetSelected( false, false );
}
}
}
{
if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
{
- // Notifies the derived class the button has been selected.
- OnSelected( selected );
+ SetSelected( selected, true );
+ }
+}
- mSelected = selected;
+void Button::SetSelected( bool selected, bool emitSignal )
+{
+ unsigned int buttonIndex, backgroundIndex;
+ bool animationStarted = false;
+ mSelected = selected;
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 2;
+ }
+ else
+ {
+ backgroundIndex = 1;
+ }
+ }
+ else if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been selected.
+ animationStarted = OnSelected();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ if( emitSignal )
+ {
Toolkit::Button handle( GetOwner() );
// Emit signal.
mStateChangedSignal.Emit( handle );
-
- RelayoutRequest();
}
+
+ RelayoutRequest();
}
bool Button::IsSelected() const
}
mLabel = label;
+ mLabel.SetPosition( 0.f, 0.f );
+
+ // label should be the top of the button
+ Self().Add( mLabel );
OnLabelSet();
return mLabel;
}
+void Button::SetButtonImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mButtonContent && mButtonContent.GetParent() )
+ {
+ Self().Remove( mButtonContent );
+ }
+
+ mButtonContent = image;
+
+ mButtonContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mButtonContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mButtonContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == UnselectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mButtonContent );
+ }
+
+ OnButtonImageSet();
+}
+
Actor Button::GetButtonImage() const
{
return mButtonContent;
return mButtonContent;
}
+void Button::SetSelectedImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mSelectedContent && mSelectedContent.GetParent() )
+ {
+ Self().Remove( mSelectedContent );
+ }
+
+ mSelectedContent = image;
+
+ mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == SelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mSelectedContent );
+ }
+
+ OnSelectedImageSet();
+}
+
Actor Button::GetSelectedImage() const
{
return mSelectedContent;
return mSelectedContent;
}
+void Button::SetBackgroundImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mBackgroundContent && mBackgroundContent.GetParent() )
+ {
+ Self().Remove( mBackgroundContent );
+ }
+
+ mBackgroundContent = image;
+
+ mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == UnselectedState || mPaintState == SelectedState )
+ {
+ Self().Insert( 0, mBackgroundContent );
+ }
+
+ OnBackgroundImageSet();
+}
+
Actor Button::GetBackgroundImage() const
{
return mBackgroundContent;
return mBackgroundContent;
}
+void Button::SetSelectedBackgroundImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+ {
+ Self().Remove( mSelectedBackgroundContent );
+ }
+
+ mSelectedBackgroundContent = image;
+
+ mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == SelectedState )
+ {
+ if( mBackgroundContent )
+ {
+ Self().Insert( 1, mSelectedBackgroundContent );
+ }
+ else
+ {
+ Self().Insert( 0, mSelectedBackgroundContent );
+ }
+ }
+
+ OnSelectedBackgroundImageSet();
+}
+
+Actor Button::GetSelectedBackgroundImage() const
+{
+ return mSelectedBackgroundContent;
+}
+
+Actor& Button::GetSelectedBackgroundImage()
+{
+ return mSelectedBackgroundContent;
+}
+
+void Button::SetDisabledImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mDisabledContent && mDisabledContent.GetParent() )
+ {
+ Self().Remove( mDisabledContent );
+ }
+
+ mDisabledContent = image;
+
+ mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mDisabledContent );
+ }
+
+ OnDisabledImageSet();
+}
+
Actor Button::GetDisabledImage() const
{
return mDisabledContent;
return mDisabledContent;
}
+void Button::SetDisabledSelectedImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+ {
+ Self().Remove( mDisabledSelectedContent );
+ }
+
+ mDisabledSelectedContent = image;
+
+ mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledSelectedState )
+ {
+ unsigned int index = FindChildIndex( mLabel );
+
+ Self().Insert( index, mDisabledSelectedContent );
+ }
+
+ OnDisabledSelectedImageSet();
+}
+
Actor Button::GetDisabledSelectedImage() const
{
return mDisabledSelectedContent;
return mDisabledSelectedContent;
}
+void Button::SetDisabledBackgroundImage( Actor image )
+{
+ StopAllAnimations();
+
+ if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+ {
+ Self().Remove( mDisabledBackgroundContent );
+ }
+
+ mDisabledBackgroundContent = image;
+
+ mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+
+ if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
+ {
+ Self().Insert( 0, mDisabledBackgroundContent );
+ }
+
+ OnDisabledBackgroundImageSet();
+}
+
Actor Button::GetDisabledBackgroundImage() const
{
return mDisabledBackgroundContent;
}
}
+void Button::UpdatePaintTransitionState()
+{
+ switch( mPaintState )
+ {
+ case UnselectedSelectedTransition:
+ {
+ RemoveChild( mButtonContent );
+ mPaintState = SelectedState;
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ RemoveChild( mSelectedBackgroundContent );
+ RemoveChild( mSelectedContent );
+ mPaintState = UnselectedState;
+ break;
+ }
+ case UnselectedDisabledTransition:
+ {
+ RemoveChild( mBackgroundContent );
+ RemoveChild( mButtonContent );
+ mPaintState = DisabledUnselectedState;
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ RemoveChild( mDisabledBackgroundContent );
+ RemoveChild( mDisabledContent );
+ mPaintState = UnselectedState;
+ break;
+ }
+ case SelectedDisabledTransition:
+ {
+ RemoveChild( mBackgroundContent );
+ RemoveChild( mSelectedBackgroundContent );
+ RemoveChild( mSelectedContent );
+ mPaintState = DisabledSelectedState;
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ RemoveChild( mDisabledBackgroundContent );
+ RemoveChild( mDisabledSelectedContent );
+ mPaintState = SelectedState;
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+}
+
void Button::OnButtonStageDisconnection()
{
if( ButtonDown == mState )
{
if( !mTogglableButton )
{
- Toolkit::Button handle( GetOwner() );
-
- // Notifies the derived class the button has been released.
- OnReleased();
+ Released();
if( mAutoRepeating )
{
{
Toolkit::Button handle( GetOwner() );
- // Notifies the derived class the button has been pressed.
- OnPressed();
+ Pressed();
if( mAutoRepeating )
{
}
else
{
- // Notifies the derived class the button has been clicked.
- OnReleased();
- OnClicked();
+ Released();
if( mAutoRepeating )
{
{
Toolkit::Button handle( GetOwner() );
- // Notifies the derived class the button has been released.
- OnReleased();
+ Released();
if( mAutoRepeating )
{
OnButtonInitialize();
+ self.SetDrawMode( DrawMode::OVERLAY );
self.SetKeyboardFocusable( true );
}
DoClickAction( attributes );
}
+void Button::OnControlStageDisconnection()
+{
+ OnButtonStageDisconnection(); // Notification for derived classes.
+ mState = ButtonUp;
+}
+
void Button::OnTap(Actor actor, const TapGesture& tap)
{
// Do nothing.
// Restart the autorepeat timer.
SetUpTimer( mNextAutoRepeatingDelay );
- Toolkit::Button handle( GetOwner() );
+ Pressed();
- // Notifies the derived class the button has been pressed.
- OnPressed();
+ Toolkit::Button handle( GetOwner() );
//Emit signal.
consumed = mReleasedSignal.Emit( handle );
return consumed;
}
-void Button::OnControlStageDisconnection()
+void Button::Pressed()
{
- OnButtonStageDisconnection(); // Notification for derived classes.
- mState = ButtonUp;
+ unsigned int buttonIndex, backgroundIndex;
+ bool animationStarted = false;
+
+ switch( mPaintState )
+ {
+ case UnselectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case SelectedUnselectedTransition:
+ {
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mSelectedContent );
+
+ if( mDisabledBackgroundContent )
+ {
+ if( mBackgroundContent )
+ {
+ backgroundIndex = 2;
+ }
+ else
+ {
+ backgroundIndex = 1;
+ }
+ }
+ else if( mBackgroundContent )
+ {
+ backgroundIndex = 1;
+ }
+ else
+ {
+ backgroundIndex = 0;
+ }
+
+ InsertChild( backgroundIndex, mSelectedBackgroundContent );
+
+ // Notifies the derived class the button has been pressed.
+ animationStarted = OnPressed();
+
+ if( animationStarted )
+ {
+ mPaintState = UnselectedSelectedTransition;
+ }
+ else
+ {
+ mPaintState = SelectedState;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void Button::Released()
+{
+ unsigned int buttonIndex;
+ bool animationStarted = false;
+
+ switch( mPaintState )
+ {
+ case SelectedState:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case UnselectedSelectedTransition:
+ {
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ buttonIndex = FindChildIndex( mLabel );
+ InsertChild( buttonIndex, mButtonContent );
+
+ // Notifies the derived class the button has been released.
+ animationStarted = OnReleased();
+
+ if( animationStarted )
+ {
+ mPaintState = SelectedUnselectedTransition;
+ }
+ else
+ {
+ mPaintState = UnselectedState;
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
}
Button::ButtonState Button::GetState()
return mState;
}
+Button::PaintState Button::GetPaintState()
+{
+ return mPaintState;
+}
+
+void Button::InsertChild( unsigned int index, Actor& actor )
+{
+ if( actor )
+ {
+ Self().Insert( index, actor);
+ }
+}
+
+void Button::RemoveChild( Actor& actor )
+{
+ if( actor && actor.GetParent() )
+ {
+ Self().Remove( 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::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
{
Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
Actor GetLabel() const;
/**
+ * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
+ */
+ void SetButtonImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::PushButton::GetButtonImage()
*/
Actor GetButtonImage() const;
Actor& GetButtonImage();
/**
+ * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
+ */
+ void SetSelectedImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
*/
Actor GetSelectedImage() const;
Actor& GetSelectedImage();
/**
+ * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
+ */
+ void SetBackgroundImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
*/
Actor GetBackgroundImage() const;
Actor& GetBackgroundImage();
/**
+ * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage( Actor image )
+ */
+ void SetSelectedBackgroundImage( Actor image );
+
+ /**
+ * @copydoc Dali::Toolkit::PushButton::GetSelectedBackgroundImage()
+ */
+ Actor GetSelectedBackgroundImage() const;
+
+ /**
+ * Internal use only.
+ * @return A reference to the selected background image.
+ */
+ Actor& GetSelectedBackgroundImage();
+
+ /**
+ * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
+ */
+ void SetDisabledImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
*/
Actor GetDisabledImage() const;
Actor& GetDisabledImage();
/**
+ * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
+ */
+ void SetDisabledSelectedImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
*/
Actor GetDisabledSelectedImage() const;
Actor& GetDisabledSelectedImage();
/**
+ * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
+ */
+ void SetDisabledBackgroundImage( Actor image );
+
+ /**
* @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
*/
Actor GetDisabledBackgroundImage() const;
*/
static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes );
+protected:
+
/**
- * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
+ * @return A reference to the label actor.
*/
- virtual void SetButtonImage( Actor image ) {}
+ Actor& GetLabel();
/**
- * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
+ * It changes the transition state of the push button.
*/
- virtual void SetSelectedImage( Actor image ) {}
+ void UpdatePaintTransitionState();
+
+private:
/**
- * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
+ * Perform the click action to click the button.
+ * @param[in] attributes The attributes to perfrom this action.
*/
- virtual void SetBackgroundImage( Actor image ) {}
+ void DoClickAction( const PropertyValueContainer& attributes );
/**
- * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
+ * This method is called after the button initialization.
+ * Could be reimplemented in subclasses to provide specific behaviour.
*/
- virtual void SetDisabledImage( Actor image ) {}
+ virtual void OnButtonInitialize() { }
/**
- * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
+ * This method is called when the label is set.
*/
- virtual void SetDisabledSelectedImage( Actor image ) {}
+ virtual void OnLabelSet() {}
/**
- * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
+ * This method is called when the button image is set
*/
- virtual void SetDisabledBackgroundImage( Actor image ) {}
+ virtual void OnButtonImageSet() {}
-protected:
+ /**
+ * This method is called when the selected image is set
+ */
+ virtual void OnSelectedImageSet() {}
/**
- * Internal use only.
- * @return A reference to the label actor.
+ * This method is called when the background image is set
*/
- Actor& GetLabel();
+ virtual void OnBackgroundImageSet() {}
-private:
+ /**
+ * This method is called when the selected background image is set
+ */
+ virtual void OnSelectedBackgroundImageSet() {}
/**
- * Perform the click action to click the button.
- * @param[in] attributes The attributes to perfrom this action.
+ * This method is called when the disabled button image is set
*/
- void DoClickAction( const PropertyValueContainer& attributes );
+ virtual void OnDisabledImageSet() {}
/**
- * This method is called after the button initialization.
- * Could be reimplemented in subclasses to provide specific behaviour.
+ * This method is called when the disabled selected image is set
*/
- virtual void OnButtonInitialize() { }
+ virtual void OnDisabledSelectedImageSet() {}
+
+ /**
+ * This method is called when the disabled background image is set
+ */
+ virtual void OnDisabledBackgroundImageSet() {}
/**
* This method is called from the OnTouchEvent method when the button is down.
virtual void OnButtonStageDisconnection();
/**
- * This method is called when the label is set.
- */
- virtual void OnLabelSet() {}
-
- /**
* This method is called when the \e selected property is changed.
+ * @return true if the transition animation is started.
*/
- virtual void OnSelected( bool selected ) {}
+ virtual bool OnSelected() { return false; }
/**
* This method is called when the \e disabled property is changed.
+ * @return true if the transition animation is started.
*/
- virtual void OnDisabled( bool disabled ) {}
+ virtual bool OnDisabled() { return false; }
/**
* This method is called when the button is pressed.
+ * @return true if the transition animation is started.
*/
- virtual void OnPressed() {}
+ virtual bool OnPressed() { return false; }
/**
* This method is called when the button is released.
+ * @return true if the transition animation is started.
*/
- virtual void OnReleased() {}
+ virtual bool OnReleased() { return false; }
/**
- * This method is called when the button is clicked
+ * This method stops all animations
*/
- virtual void OnClicked() {}
+ virtual void StopAllAnimations() {}
public:
*/
bool AutoRepeatingSlot();
+ /**
+ * Sets the button as selected or unselected.
+ * @param[in] selected \e selected property value.
+ * @param[in] emitSignal Emit a signal if this value is \e true.
+ */
+ void SetSelected( bool selected, bool emitSignal );
+
+ /**
+ * This method is called when the button is pressed.
+ */
+ void Pressed();
+
+ /**
+ * This method is called when the button is released.
+ */
+ void Released();
+
protected:
enum ButtonState
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.
+ SelectedUnselectedTransition, ///< The 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.
};
ButtonState GetState();
+ PaintState GetPaintState();
+
+ /**
+ * Inserts the actor to the button.
+ */
+ void InsertChild( unsigned int index, Actor& actor );
+
+ /**
+ * Removes the actor from the button.
+ */
+ void RemoveChild( Actor& actor );
+
+ /**
+ * Finds the index of the actor.
+ * If the actor doesn't exist, return the last index + 1.
+ */
+ unsigned int FindChildIndex( Actor& actor );
private:
Actor mButtonContent; ///< Stores the unselected content.
Actor mSelectedContent; ///< Stores the selected content.
Actor mBackgroundContent; ///< Stores the background content.
+ Actor mSelectedBackgroundContent; ///< Stores the selected background content.
Actor mDisabledContent; ///< Stores the disabled content.
Actor mDisabledSelectedContent; ///< Stores the disabled selected content.
Actor mDisabledBackgroundContent; ///< Stores the disabled background content.
bool mClickActionPerforming;
ButtonState mState; ///< Stores the button state.
+ PaintState mPaintState; ///< Stores the paint state.
};
} // namespace Internal
namespace
{
-const float FOREGROUND_DEPTH( 0.5f );
-const float BACKGROUND_DEPTH( 0.25f );
-
+const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f );
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();
}
CheckBoxButton::CheckBoxButton()
-: Button(),
- mPaintState( UnselectedState )
+: Button()
{
SetTogglableButton( true );
CheckBoxButton::~CheckBoxButton()
{
- if( mCheckInAnimation )
+ if( mTransitionAnimation )
{
- mCheckInAnimation.Clear();
+ mTransitionAnimation.Clear();
}
}
Self().SetResizePolicy( FIT_TO_CHILDREN, ALL_DIMENSIONS );
}
-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.SetParentOrigin( ParentOrigin::CENTER_LEFT );
label.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
- label.TranslateBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
if( IsDisabled() && GetDisabledBackgroundImage() )
{
- GetDisabledBackgroundImage().Add( label );
+ label.SetX( GetDisabledBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
else if ( GetBackgroundImage() )
{
- GetBackgroundImage().Add( label );
+ label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
else
{
- Self().Add( label );
+ label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
}
}
-void CheckBoxButton::OnSelected( bool selected )
+bool CheckBoxButton::OnSelected()
{
Actor& selectedImage = GetSelectedImage();
- switch( mPaintState )
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
case UnselectedState:
{
- AddChild( selectedImage );
- StartCheckInAnimation( selectedImage ); // Animate in the check actor
-
- mPaintState = UnselectedSelectedTransition;
+ StartTransitionAnimation( selectedImage );
break;
}
case SelectedState:
{
RemoveChild( selectedImage );
-
- mPaintState = UnselectedState;
break;
}
case UnselectedSelectedTransition:
{
- StopCheckInAnimation();
+ StopTransitionAnimation( false );
RemoveChild( selectedImage );
-
- mPaintState = UnselectedState;
break;
}
default:
+ {
break;
+ }
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
-void CheckBoxButton::OnDisabled( bool disabled )
+bool CheckBoxButton::OnDisabled()
{
Actor& backgroundImage = GetBackgroundImage();
Actor& selectedImage = GetSelectedImage();
Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
Actor& disabledSelectedImage = GetDisabledSelectedImage();
- switch( mPaintState )
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
case UnselectedState:
{
- if( disabled )
- {
- RemoveChild( backgroundImage );
- AddChild( disabledBackgroundImage );
- mPaintState = DisabledUnselectedState;
- }
+ RemoveChild( backgroundImage );
break;
}
case SelectedState:
{
- if( disabled )
- {
- RemoveChild( backgroundImage );
- RemoveChild( selectedImage );
- AddChild( disabledBackgroundImage );
- AddChild( disabledSelectedImage );
-
- mPaintState = DisabledSelectedState;
- }
+ RemoveChild( backgroundImage );
+ RemoveChild( selectedImage );
break;
}
case DisabledUnselectedState:
{
- if( !disabled )
- {
- RemoveChild( disabledBackgroundImage );
- AddChild( backgroundImage );
-
- mPaintState = UnselectedState;
- }
+ RemoveChild( disabledBackgroundImage );
break;
}
case DisabledSelectedState:
{
- if( !disabled )
- {
- RemoveChild( disabledBackgroundImage );
- RemoveChild( disabledSelectedImage );
- AddChild( backgroundImage );
- AddChild( selectedImage );
-
- mPaintState = SelectedState;
- }
+ RemoveChild( disabledBackgroundImage );
+ RemoveChild( disabledSelectedImage );
break;
}
case UnselectedSelectedTransition:
{
- if( disabled )
- {
- StopCheckInAnimation();
-
- RemoveChild( backgroundImage );
- RemoveChild( selectedImage );
- AddChild( disabledBackgroundImage );
- AddChild( disabledSelectedImage );
+ StopTransitionAnimation();
- mPaintState = DisabledSelectedState;
- }
+ RemoveChild( backgroundImage );
+ RemoveChild( selectedImage );
break;
}
default:
+ {
break;
+ }
}
Actor& label = GetLabel();
if( label )
{
- if( label.GetParent() )
+ if( IsDisabled() && disabledBackgroundImage)
{
- label.GetParent().Remove( label );
+ label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
-
- if( disabled && disabledBackgroundImage)
+ else if( backgroundImage )
{
- disabledBackgroundImage.Add( label );
+ label.SetX( backgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- else if( backgroundImage )
+ else
{
- backgroundImage.Add( label );
+ label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
}
-}
-void CheckBoxButton::AddChild( Actor& actor )
-{
- if( actor )
+ if( mTransitionAnimation )
{
- Self().Add( actor);
+ return true;
}
+
+ return false;
}
-void CheckBoxButton::RemoveChild( Actor& actor )
+void CheckBoxButton::StopAllAnimations()
{
- if( actor )
- {
- Self().Remove( actor );
- }
+ StopTransitionAnimation();
}
-void CheckBoxButton::StartCheckInAnimation( Actor& actor )
+void CheckBoxButton::StartTransitionAnimation( Actor& actor )
{
if( actor )
{
mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) );
- if( !mCheckInAnimation )
+ if( !mTransitionAnimation )
{
- mCheckInAnimation = Dali::Animation::New( GetAnimationTime() );
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
}
// UV anim
- mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
+ mTransitionAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
// Actor size anim
- mCheckInAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f );
+ mTransitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f );
- mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButton::CheckInAnimationFinished );
- mCheckInAnimation.Play();
+ mTransitionAnimation.FinishedSignal().Connect( this, &CheckBoxButton::TransitionAnimationFinished );
+ mTransitionAnimation.Play();
}
}
-void CheckBoxButton::StopCheckInAnimation()
+void CheckBoxButton::StopTransitionAnimation( bool remove )
{
- if( mCheckInAnimation )
+ if( mTransitionAnimation )
{
- mCheckInAnimation.Clear();
- mCheckInAnimation.Reset();
+ mTransitionAnimation.Clear();
+ mTransitionAnimation.Reset();
}
-}
-void CheckBoxButton::CheckInAnimationFinished( Dali::Animation& source )
-{
- switch( mPaintState )
+ if( remove )
{
- case UnselectedSelectedTransition:
- {
- mPaintState = SelectedState;
- break;
- }
- default:
- {
- break;
- }
+ UpdatePaintTransitionState();
}
+}
- StopCheckInAnimation();
+void CheckBoxButton::TransitionAnimationFinished( Dali::Animation& source )
+{
+ StopTransitionAnimation();
}
} // namespace Internal
*/
static Dali::Toolkit::CheckBoxButton New();
-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 );
+private:
/**
- * @copydoc Toolkit::Internal::Button::SetDisabledSelectedImage( Actor image )
+ * Construct a new CheckBoxButton.
*/
- virtual void SetDisabledSelectedImage( Actor image );
+ CheckBoxButton();
/**
- * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image )
+ * A reference counted object may only be deleted by calling Unreference()
*/
- virtual void SetDisabledBackgroundImage( Actor image );
+ virtual ~CheckBoxButton();
private: // From Button
/**
* @copydoc Toolkit::Internal::Button::OnSelected()
*/
- virtual void OnSelected( bool selected );
+ virtual bool OnSelected();
/**
- * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled )
+ * @copydoc Toolkit::Internal::Button::OnDisabled()
*/
- virtual void OnDisabled( bool disabled );
-
-private:
+ virtual bool OnDisabled();
/**
- * Construct a new CheckBoxButton.
+ * @copydoc Toolkit::Internal::Button::StopAllAnimations()
*/
- CheckBoxButton();
-
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~CheckBoxButton();
+ virtual void StopAllAnimations();
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.
+ * Adds the actor to the transition animation.
+ * It creates a transition animation if needed and starts the animation.
* @param[in] actor The actor.
*/
- void StartCheckInAnimation( Actor& actor );
+ void StartTransitionAnimation( Actor& actor );
/**
- * Stops the check in animation.
+ * Stops the transition animation.
+ * @param[in] remove If true, removes the fadeout actor from root.
*/
- void StopCheckInAnimation();
+ void StopTransitionAnimation( bool remove = true );
// slots
/**
- * Called when the check in animation finishes.
- * It changes the check button paint state.
+ * Called when the transition animation finishes.
*/
- void CheckInAnimationFinished( Dali::Animation& source );
+ void TransitionAnimationFinished( Dali::Animation& source );
private:
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.
+ Animation mTransitionAnimation; ///< Animation used in the state transitions.
+ ImageRegionEffect mTickUVEffect; ///< ImageRegionEffect to expand the tick across
};
} // namespace Internal
{
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()
PushButton::PushButton()
: Button(),
- mSize(),
- mPaintState( UnselectedState )
+ mSize()
{
SetAnimationTime( ANIMATION_TIME );
}
{
}
-void PushButton::SetButtonImage( Actor image )
+void PushButton::OnButtonInitialize()
{
- Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
-
- switch( mPaintState )
- {
- case UnselectedState:
- {
- if( buttonImage && buttonImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
-
- buttonImage = image;
-
- FadeInImage( buttonImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- buttonImage = image;
- Self().Insert( 0, buttonImage );
- }
- break;
- }
- case UnselectedSelectedTransition: // FALLTHROUGH
- case UnselectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutButtonImage )
- {
- opacity = fadeOutButtonImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- buttonImage = image;
-
- Self().Insert( 0, buttonImage );
- FadeOutImage( Foreground, buttonImage, opacity );
+ // Push button requires the Leave event.
+ Actor self = Self();
+ self.SetLeaveRequired( true );
- StartFadeOutAnimation();
- break;
- }
- case SelectedUnselectedTransition: // FALLTHROUGH
- case DisabledUnselectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( buttonImage );
+ // Set resize policy to natural size so that buttons will resize to background images
+ self.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
+}
- buttonImage = image;
+void PushButton::OnLabelSet()
+{
+ Actor& label = GetLabel();
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeInAnimation();
- break;
- }
- default:
- buttonImage = image;
- break;
+ if( label )
+ {
+ label.SetAnchorPoint( AnchorPoint::CENTER );
+ label.SetParentOrigin( ParentOrigin::CENTER );
+ label.SetSize( mSize );
}
+}
+
+void PushButton::OnButtonImageSet()
+{
+ Actor& buttonImage = GetButtonImage();
- buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- buttonImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
- buttonImage.SetName( "BUTTON_IMAGE" );
}
-void PushButton::SetSelectedImage( Actor image )
+void PushButton::OnSelectedImageSet()
{
Actor& selectedImage = GetSelectedImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
-
- switch( mPaintState )
- {
- case SelectedState:
- {
- if( selectedImage && selectedImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
-
- selectedImage = image;
-
- FadeInImage( selectedImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- selectedImage = image;
- Self().Insert( 0, selectedImage );
- }
- break;
- }
- case SelectedUnselectedTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutButtonImage )
- {
- opacity = fadeOutButtonImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- selectedImage = image;
-
- Self().Insert( 0, selectedImage );
- FadeOutImage( Foreground, selectedImage, opacity );
-
- StartFadeOutAnimation();
- break;
- }
- case UnselectedSelectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( selectedImage );
-
- selectedImage = image;
- FadeInImage( selectedImage, 0.0f, 0 );
- 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.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
}
-void PushButton::SetBackgroundImage( Actor image )
+void PushButton::OnBackgroundImageSet()
{
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, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- backgroundImage = image;
- Self().Insert( 0, backgroundImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- float opacity = 1.f;
- if( fadeOutBackgroundImage )
- {
- opacity = fadeOutBackgroundImage.GetCurrentOpacity();
- }
- StopFadeOutAnimation();
-
- // Replaces the button image.
- backgroundImage = image;
-
- Self().Insert( 0, backgroundImage );
- FadeOutImage( Background, backgroundImage, opacity );
-
- StartFadeOutAnimation();
- break;
- }
- case DisabledUnselectedTransition: // FALLTHROUGH
- case DisabledSelectedTransition:
- {
- StopFadeInAnimation();
- Self().Remove( backgroundImage );
-
- backgroundImage = image;
-
- FadeInImage( backgroundImage, 0.0f, 0 );
- 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.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
}
-void PushButton::SetDisabledImage( Actor image )
+void PushButton::OnSelectedBackgroundImageSet()
{
- Actor& disabledImage = GetDisabledImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
- switch( mPaintState )
- {
- case DisabledUnselectedState: // FALLTHROUGH
- case DisabledSelectedState:
- {
- if( disabledImage && disabledImage.GetParent() )
- {
- StopFadeOutAnimation();
- FadeOutImage( Foreground, disabledImage );
-
- disabledImage = image;
-
- FadeInImage( disabledImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- disabledImage = image;
- Self().Add( disabledImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- StopFadeInAnimation();
- Self().Remove( disabledImage );
-
- disabledImage = image;
-
- FadeInImage( disabledImage, 0.0f, 0 );
- 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 );
+ selectedBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+}
- StartFadeOutAnimation();
- break;
- }
- default:
- disabledImage = image;
- break;
- }
+void PushButton::OnDisabledImageSet()
+{
+ Actor& disabledImage = GetDisabledImage();
- disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
- disabledImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH );
disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
}
-void PushButton::SetDisabledBackgroundImage( Actor image )
+void PushButton::OnDisabledBackgroundImageSet()
{
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, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- }
- else
- {
- disabledBackgroundImage = image;
- Self().Add( disabledBackgroundImage );
- }
- break;
- }
- case UnselectedDisabledTransition: // FALLTHROUGH
- case SelectedDisabledTransition:
- {
- StopFadeInAnimation();
- Self().Remove( disabledBackgroundImage );
-
- disabledBackgroundImage = image;
-
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- 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.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
}
-void PushButton::OnButtonInitialize()
+bool PushButton::OnSelected()
{
- // Push button requires the Leave event.
- Actor root = Self();
- root.SetLeaveRequired( true );
-
- // Set resize policy to natural size so that buttons will resize to background images
- root.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
-}
-
-void PushButton::OnLabelSet()
-{
- 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 );
- }
-}
-
-void PushButton::OnSelected( bool selected )
-{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
+
+ PaintState paintState = GetPaintState();
- switch( mPaintState )
+ switch( paintState )
{
case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
break;
}
case SelectedUnselectedTransition:
{
float opacity = 0.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = 1.f - fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( buttonImage, 1.f - opacity );
+ FadeInImage( selectedBackgroundImage, opacity );
+ FadeInImage( selectedImage, opacity );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledUnselectedTransition:
+ {
+ StopTransitionAnimation();
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ StopTransitionAnimation();
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
-void PushButton::OnDisabled( bool disabled )
+bool PushButton::OnDisabled()
{
Actor& buttonImage = GetButtonImage();
Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
Actor& backgroundImage = GetBackgroundImage();
Actor& disabledImage = GetDisabledImage();
+ Actor& disabledSelectedImage = GetDisabledSelectedImage();
Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
- switch( mPaintState )
- {
- case UnselectedState:
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
- if( disabled )
+ case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, backgroundImage );
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- FadeInImage( disabledImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ FadeOutImage( backgroundImage );
+ FadeOutImage( buttonImage );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedState:
- {
- if( disabled )
+ case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, backgroundImage );
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
- FadeInImage( disabledImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ FadeOutImage( backgroundImage );
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledSelectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledUnselectedState:
- {
- if( !disabled )
+ case DisabledUnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, disabledBackgroundImage );
- FadeOutImage( Foreground, disabledImage );
- FadeInImage( backgroundImage, 0.0f, 0 );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( disabledBackgroundImage );
+ FadeOutImage( disabledImage );
+ FadeInImage( backgroundImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledSelectedState:
- {
- if( !disabled )
+ case DisabledSelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Background, disabledBackgroundImage );
- FadeOutImage( Foreground, disabledImage );
- FadeInImage( backgroundImage, 0.0f, 0 );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( disabledBackgroundImage );
+ FadeOutImage( disabledSelectedImage );
+ FadeInImage( backgroundImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case UnselectedSelectedTransition:
- {
- if( disabled )
+ case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation();
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage );
- FadeInImage( disabledImage, 0.0f, 0 );
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( backgroundImage );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledSelectedImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedUnselectedTransition:
- {
- if( disabled )
+ case SelectedUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation();
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage );
- FadeInImage( disabledImage, 0.0f, 0);
- FadeInImage( disabledBackgroundImage, 0.0f, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( backgroundImage );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( disabledBackgroundImage );
+ FadeInImage( disabledImage );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case UnselectedDisabledTransition:
- {
- if( !disabled )
+ case UnselectedDisabledTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( disabledImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = disabledImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, disabledImage, 1.f - opacity );
- FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
- FadeInImage( backgroundImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( disabledBackgroundImage, opacity );
+ FadeOutImage( disabledImage, opacity );
+ FadeInImage( backgroundImage, 1.f - opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledUnselectedTransition:
- {
- if( disabled )
+ case DisabledUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage, 1.f - opacity );
- FadeInImage( disabledImage, opacity, 0 );
- FadeInImage( disabledBackgroundImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
- if( buttonImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = UnselectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledUnselectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( backgroundImage, opacity );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( disabledBackgroundImage, 1.f - opacity );
+ FadeInImage( disabledImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case SelectedDisabledTransition:
- {
- if( !disabled )
+ case SelectedDisabledTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( disabledSelectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = disabledSelectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
- FadeOutImage( Foreground, disabledImage, 1.f - opacity );
- FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
- FadeInImage( backgroundImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = DisabledSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( disabledBackgroundImage, opacity );
+ FadeOutImage( disabledSelectedImage, opacity );
+ FadeInImage( backgroundImage, 1.f - opacity );
+ FadeInImage( selectedBackgroundImage, 1.f - opacity );
+ FadeInImage( selectedImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
- }
- case DisabledSelectedTransition:
- {
- if( disabled )
+ case DisabledSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
-
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeOutImage( Background, backgroundImage, 1.f - opacity );
- FadeInImage( disabledImage, opacity, 0 );
- FadeInImage( disabledBackgroundImage, opacity, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( selectedImage || disabledImage || backgroundImage || disabledBackgroundImage )
- {
- mPaintState = SelectedDisabledTransition;
- }
- else
- {
- mPaintState = DisabledSelectedState;
- }
+ StopTransitionAnimation( false );
+ FadeOutImage( backgroundImage, opacity );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( disabledBackgroundImage, 1.f - opacity );
+ FadeInImage( disabledSelectedImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
}
- break;
}
- default:
- break;
+
+ if( mTransitionAnimation )
+ {
+ return true;
}
+
+ return false;
}
-void PushButton::OnPressed()
+bool PushButton::OnPressed()
{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
- switch( mPaintState )
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
case UnselectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, buttonImage );
- FadeInImage( selectedImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ FadeOutImage( buttonImage );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
- case UnselectedSelectedTransition:
+ case SelectedUnselectedTransition:
{
- if( !IsAutoRepeating() )
+ float opacity = 1.f;
+ if( buttonImage )
{
- mPaintState = SelectedUnselectedTransition;
+ opacity = buttonImage.GetCurrentOpacity();
}
+
+ StopTransitionAnimation( false );
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( selectedBackgroundImage, 1.f - opacity );
+ FadeInImage( selectedImage, 1.f - opacity );
+ StartTransitionAnimation();
break;
}
- case SelectedUnselectedTransition:
+ case DisabledUnselectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( buttonImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = buttonImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
- FadeOutImage( Foreground, buttonImage, 1.f - opacity );
- FadeInImage( selectedImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = UnselectedSelectedTransition;
- }
- else
- {
- mPaintState = SelectedState;
- }
+ StopTransitionAnimation();
+ FadeOutImage( buttonImage, opacity );
+ FadeInImage( selectedBackgroundImage );
+ FadeInImage( selectedImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
-void PushButton::OnReleased()
+bool PushButton::OnReleased()
{
- Actor& selectedImage = GetSelectedImage();
Actor& buttonImage = GetButtonImage();
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& selectedBackgroundImage = GetSelectedBackgroundImage();
+
+ PaintState paintState = GetPaintState();
- switch( mPaintState )
+ switch( paintState )
{
case SelectedState:
{
- StopFadeOutAnimation();
- FadeOutImage( Foreground, selectedImage );
- FadeInImage( buttonImage, 0.0f, 0 );
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
- {
- mPaintState = UnselectedState;
- }
+ FadeOutImage( selectedBackgroundImage );
+ FadeOutImage( selectedImage );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
case UnselectedSelectedTransition:
{
float opacity = 1.f;
- if( fadeOutButtonImage )
+ if( selectedImage )
{
- opacity = fadeOutButtonImage.GetCurrentOpacity();
+ opacity = selectedImage.GetCurrentOpacity();
}
- StopFadeOutAnimation( false );
- StopFadeInAnimation();
- FadeOutImage( Foreground, selectedImage, 1.f - opacity );
- FadeInImage( buttonImage, opacity, 0 );
-
- StartFadeOutAnimation();
- StartFadeInAnimation();
-
- if( buttonImage || selectedImage )
- {
- mPaintState = SelectedUnselectedTransition;
- }
- else
+ StopTransitionAnimation( false );
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage, 1.f - opacity );
+ StartTransitionAnimation();
+ break;
+ }
+ case DisabledSelectedTransition:
+ {
+ float opacity = 1.f;
+ if( selectedImage )
{
- mPaintState = UnselectedState;
+ opacity = selectedImage.GetCurrentOpacity();
}
+
+ StopTransitionAnimation();
+ FadeOutImage( selectedBackgroundImage, opacity );
+ FadeOutImage( selectedImage, opacity );
+ FadeInImage( buttonImage );
+ StartTransitionAnimation();
break;
}
default:
break;
}
}
+
+ if( mTransitionAnimation )
+ {
+ return true;
+ }
+
+ return false;
}
-void PushButton::OnClicked()
+void PushButton::StopAllAnimations()
{
- OnReleased();
+ StopTransitionAnimation();
}
void PushButton::OnControlSizeSet( const Vector3& targetSize )
return size;
}
-Actor& PushButton::GetFadeOutButtonImage()
-{
- return mFadeOutButtonContent;
-}
-
-Actor& PushButton::GetFadeOutBackgroundImage()
-{
- return mFadeOutBackgroundContent;
-}
-
-void PushButton::AddToFadeInAnimation( Actor& actor )
-{
- if( !mFadeInAnimation )
- {
- mFadeInAnimation = Dali::Animation::New( GetAnimationTime() );
- }
-
- mFadeInAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), 1.f );
-}
-
-void PushButton::StartFadeInAnimation()
-{
- if( mFadeInAnimation )
- {
- mFadeInAnimation.FinishedSignal().Connect( this, &PushButton::FadeInAnimationFinished );
- mFadeInAnimation.Play();
- }
-}
-
-void PushButton::StopFadeInAnimation()
+void PushButton::StartTransitionAnimation()
{
- if( mFadeInAnimation )
+ if( mTransitionAnimation )
{
- mFadeInAnimation.Clear();
- mFadeInAnimation.Reset();
+ mTransitionAnimation.FinishedSignal().Connect( this, &PushButton::TransitionAnimationFinished );
+ mTransitionAnimation.Play();
}
}
-void PushButton::AddToFadeOutAnimation( Actor& actor )
+void PushButton::StopTransitionAnimation( bool remove )
{
- if( !mFadeOutAnimation )
+ if( mTransitionAnimation )
{
- mFadeOutAnimation = Dali::Animation::New( GetAnimationTime() );
- }
-
- mFadeOutAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), 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();
+ mTransitionAnimation.Clear();
+ mTransitionAnimation.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();
+ UpdatePaintTransitionState();
}
}
-void PushButton::FadeInImage( Actor& image, float opacity, int priority )
+void PushButton::FadeInImage( Actor& image, float opacity, Vector3 scale )
{
if( image )
{
image.SetOpacity( opacity );
- if( !image.GetParent() )
+ image.SetScale( scale );
+
+ if( !mTransitionAnimation )
{
- if( priority > -1 )
- {
- Self().Insert( priority, image );
- }
- else
- {
- Self().Add( image );
- }
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
}
- AddToFadeInAnimation( image );
+ mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 1.f );
}
}
-void PushButton::FadeOutImage( ImageLayer layer, Actor& image, float opacity )
+void PushButton::FadeOutImage( Actor& image, float opacity, Vector3 scale )
{
if( image )
{
- Actor& fadeOutButtonImage = GetFadeOutButtonImage();
- Actor& fadeOutBackgroundImage = GetFadeOutBackgroundImage();
-
- Actor& actorLayer = ( ( Background == layer ) ? fadeOutBackgroundImage : fadeOutButtonImage );
-
- actorLayer = image;
- actorLayer.SetOpacity( opacity );
-
- AddToFadeOutAnimation( actorLayer );
- }
-}
+ image.SetOpacity( opacity );
+ image.SetScale( scale );
-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:
+ if( !mTransitionAnimation )
{
- mPaintState = SelectedState;
- break;
+ mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
}
- default:
- {
- break;
- }
- }
- StopFadeOutAnimation();
+ mTransitionAnimation.AnimateTo( Property( image, Actor::Property::COLOR_ALPHA ), 0.f );
+ }
}
-void PushButton::FadeInAnimationFinished( Dali::Animation& source )
+void PushButton::TransitionAnimationFinished( 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();
+ StopTransitionAnimation();
}
} // namespace Internal
*/
virtual ~PushButton();
-public: // From Button
+private: // From Button
/**
- * @copydoc Toolkit::Internal::Button::SetButtonImage( Actor image )
+ * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
*/
- virtual void SetButtonImage( Actor image );
+ virtual void OnButtonInitialize();
/**
- * @copydoc Toolkit::Internal::Button::SetSelectedImage( Actor image )
+ * @copydoc Toolkit::Internal::Button::OnLabelSet()
*/
- virtual void SetSelectedImage( Actor image );
+ virtual void OnLabelSet();
/**
- * @copydoc Toolkit::Internal::Button::SetBackgroundImage( Actor image )
+ * @copydoc Toolkit::Internal::Button::OnButtonImageSet()
*/
- virtual void SetBackgroundImage( Actor image );
+ virtual void OnButtonImageSet();
/**
- * @copydoc Toolkit::Internal::Button::SetDisabledImage( Actor image )
+ * @copydoc Toolkit::Internal::Button::OnSelectedImageSet()
*/
- virtual void SetDisabledImage( Actor image );
+ virtual void OnSelectedImageSet();
/**
- * @copydoc Toolkit::Internal::Button::SetDisabledBackgroundImage( Actor image )
+ * @copydoc Toolkit::Internal::Button::OnBackgroundImage()
*/
- virtual void SetDisabledBackgroundImage( Actor image );
+ virtual void OnBackgroundImageSet();
-private: // From Button
+ /**
+ * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet()
+ */
+ virtual void OnSelectedBackgroundImageSet();
/**
- * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
+ * @copydoc Toolkit::Internal::Button::OnDisabledImageSet()
*/
- virtual void OnButtonInitialize();
+ virtual void OnDisabledImageSet();
/**
- * @copydoc Toolkit::Internal::Button::OnLabelSet()
+ * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet()
*/
- virtual void OnLabelSet();
+ virtual void OnDisabledBackgroundImageSet();
/**
* @copydoc Toolkit::Internal::Button::OnSelected()
*/
- virtual void OnSelected( bool selected );
+ virtual bool OnSelected();
/**
- * @copydoc Toolkit::Internal::Button::OnDisabled( bool disabled )
+ * @copydoc Toolkit::Internal::Button::OnDisabled()
*/
- virtual void OnDisabled( bool disabled );
+ virtual bool OnDisabled();
/**
* @copydoc Toolkit::Internal::Button::OnPressed()
*/
- virtual void OnPressed();
+ virtual bool OnPressed();
/**
* @copydoc Toolkit::Internal::Button::OnReleased()
*/
- virtual void OnReleased();
+ virtual bool OnReleased();
/**
- * @copydoc Toolkit::Internal::Button::OnClicked()
+ * @copydoc Toolkit::Internal::Button::StopAllAnimations()
*/
- virtual void OnClicked();
+ virtual void StopAllAnimations();
private: // From Control
private:
/**
- * Used in the FadeOut functions.
- */
- enum ImageLayer
- {
- Background, ///< Fade out the background.
- Foreground ///< Fade out the foreground.
- };
-
- /**
- * Gets the button image that is fading out.
- * @return A reference to the button image that is fading out.
+ * Starts the transition animation.
+ * PushButton::TransitionAnimationFinished slot is called when the animation finishes.
*/
- Actor& GetFadeOutButtonImage();
+ void StartTransitionAnimation();
/**
- * 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( 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( 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.
+ * Stops the transition animation.
* @param[in] remove If true, removes the fadeout actor from root.
*/
- void StopFadeOutAnimation( bool remove = true );
+ void StopTransitionAnimation( 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.
+ * @param[in] scale The initial scale.
*/
- void FadeInImage( Actor& image, float opacity = 0.f, int priority = -1 );
+ void FadeInImage( Actor& image, float opacity = 0.f, Vector3 scale = Vector3( 1.f, 1.f, 1.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.
+ * @param[in] scale The initial scale.
*/
- void FadeOutImage( ImageLayer layer, Actor& image, float opacity = 1.f );
+ void FadeOutImage( Actor& image, float opacity = 1.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) );
// slots
/**
- * Called when the fade out animation finishes.
- * It changes the check button paint state and removes actors from the root.
+ * Called when the transition animation finishes.
*/
- void FadeOutAnimationFinished( Dali::Animation& source );
-
- /**
- * Called when the fade in animation finishes.
- * It changes the check button paint state.
- */
- void FadeInAnimationFinished( Dali::Animation& source );
+ void TransitionAnimationFinished( Dali::Animation& source );
private:
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.
-
+ Animation mTransitionAnimation; ///< Animation used in the state transitions.
Vector3 mSize; ///< The button's size.
-
- PaintState mPaintState; ///< The paint state.
};
} // namespace Internal
const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected.png";
const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected.png";
-const float DISTANCE_BETWEEN_IMAGE_AND_LABEL = 5.0f;
+const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f );
}
Dali::Toolkit::RadioButton RadioButton::New()
{
}
-void RadioButton::SetImage( Actor image )
-{
- mLayoutContainer.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
- mLayoutContainer.AddChild( image, Toolkit::TableView::CellPosition( 0, 0 ) );
-
- RelayoutRequest();
-}
-
-void RadioButton::SetButtonImage( Actor image )
-{
- Actor& buttonImage = GetButtonImage();
- buttonImage = image;
-}
-
-void RadioButton::SetSelectedImage( Actor image )
-{
- Actor& selectedImage = GetSelectedImage();
- selectedImage = image;
-}
-
void RadioButton::OnButtonInitialize()
{
Actor self = Self();
// Wrap size of radio button around all its children
self.SetResizePolicy( FIT_TO_CHILDREN, ALL_DIMENSIONS );
- // Create the layout container empty at first
- mLayoutContainer = Toolkit::TableView::New( 0, 0 );
- mLayoutContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mLayoutContainer.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mLayoutContainer.SetResizePolicy( FIT_TO_CHILDREN, ALL_DIMENSIONS );
- self.Add( mLayoutContainer );
-
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 ) );
- SetImage( GetButtonImage() );
-
RelayoutRequest();
}
if( label )
{
- // Add padding to the left of the label to create distance from the image
- label.SetPadding( Padding( DISTANCE_BETWEEN_IMAGE_AND_LABEL, 0.0f, 0.0f, 0.0f ) );
+ label.SetParentOrigin( ParentOrigin::CENTER_LEFT );
+ label.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
- mLayoutContainer.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 1 ) );
- mLayoutContainer.AddChild( label, Toolkit::TableView::CellPosition( 0, 1 ) );
+ if( IsSelected() )
+ {
+ label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ }
+ else
+ {
+ label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ }
}
}
-void RadioButton::OnSelected( bool selected )
+bool RadioButton::OnSelected()
{
- if( selected )
+ Actor& buttonImage = GetButtonImage();
+ Actor& selectedImage = GetSelectedImage();
+ Actor& label = GetLabel();
+
+ PaintState paintState = GetPaintState();
+
+ switch( paintState )
{
- Actor parent = Self().GetParent();
- if( parent )
+ case UnselectedState:
{
- for( unsigned int i = 0; i < parent.GetChildCount(); ++i )
+ Actor parent = Self().GetParent();
+ if( parent )
{
- Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) );
- if( radioButtonChild )
+ for( unsigned int i = 0; i < parent.GetChildCount(); ++i )
{
- radioButtonChild.SetSelected( false );
+ Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) );
+ if( radioButtonChild && radioButtonChild != Self() )
+ {
+ radioButtonChild.SetSelected( false );
+ }
}
}
+
+ RemoveChild( buttonImage );
+
+ if( label )
+ {
+ label.SetX( selectedImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ }
+ break;
}
+ case SelectedState:
+ {
+ RemoveChild( selectedImage );
- SetImage( GetSelectedImage() );
- }
- else
- {
- SetImage( GetButtonImage() );
+ if( label )
+ {
+ label.SetX( buttonImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
}
+
+ // there is no animation
+ return false;
}
} // namespace Internal
/**
* Create a new RadioButton.
*
- * @return A smart-pointer to the newly allocated PushButton.
+ * @return A smart-pointer to the newly allocated RadioButton.
*/
static Dali::Toolkit::RadioButton New();
- /**
- * Construct a new PushButton.
- */
- RadioButton();
-
- /**
- * Construct a new PushButton with label.
- */
- RadioButton( const std::string& label );
+private:
/**
- * Construct a new PushButton with label.
+ * Construct a new RadioButton.
*/
- RadioButton( Actor label );
+ RadioButton();
/**
* A reference counted object may only be deleted by calling Unreference()
*/
virtual ~RadioButton();
-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 );
-
private: // From Button
/**
/**
* @copydoc Toolkit::Internal::Button::OnSelected()
*/
- virtual void OnSelected( bool selected );
+ virtual bool OnSelected();
/**
* @copydoc Toolkit::Internal::Button::OnLabelSet()
private:
- /**
- * @brief Set the image to display
- *
- * @param[in] image The image to set
- */
- void SetImage( Actor image );
-
-private:
-
// Undefined
RadioButton( const RadioButton& origin );
// Undefined
RadioButton& operator=( const RadioButton& origin );
-
-private:
-
- Toolkit::TableView mLayoutContainer; ///< Container to position button images and labels
-
};
} // namespace Internal
* limitations under the License.
*
*/
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/base-object.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/scripting/script.h>
return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage();
}
+void PushButton::SetSelectedBackgroundImage( Image image )
+{
+ Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( ImageActor::New( image ) );
+}
+
+void PushButton::SetSelectedBackgroundImage( Actor image )
+{
+ Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( image );
+}
+
+Actor PushButton::GetSelectedBackgroundImage() const
+{
+ return Dali::Toolkit::GetImplementation( *this ).GetSelectedBackgroundImage();
+}
+
void PushButton::SetDisabledBackgroundImage( Image image )
{
Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( ImageActor::New( image ) );
Actor GetSelectedImage() const;
/**
+ * @brief Sets the selected background image.
+ *
+ * @param[in] image The selected background image.
+ */
+ void SetSelectedBackgroundImage( Image image );
+
+ /**
+ * @copydoc SetSelectedBackgroundImage( Image image )
+ */
+ void SetSelectedBackgroundImage( Actor image );
+
+ /**
+ * @brief Gets the selected background image.
+ *
+ * @return An actor with the selected background image.
+ */
+ Actor GetSelectedBackgroundImage() const;
+
+ /**
* @brief Sets the disabled background image.
*
* @param[in] image The disabled background image.
*
*/
-// INTERNAL INCLUDES
+// EXTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
-#include <dali.h>
+#include <dali/public-api/object/base-handle.h>
namespace Dali
{