/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <cstring> // for strcmp
-#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/object/type-registry-helper.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+
/**
* Button states and contents
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating", BOOLEAN, AUTO_REPEATING )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
+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, "normal-state-actor", MAP, NORMAL_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor", MAP, LABEL_ACTOR )
+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 )
+// 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, "state-changed", SIGNAL_STATE_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED )
-DALI_ACTION_REGISTRATION( Toolkit, Button, "button-click", ACTION_BUTTON_CLICK )
+// Actions:
+DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK )
DALI_TYPE_REGISTRATION_END()
} // unnamed namespace
Button::Button()
-: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
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 ),
TransitionButtonImage( mDisabledBackgroundContent );
AddButtonImage( mUnselectedContent );
TransitionButtonImage( mDisabledContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
TransitionOut( mBackgroundContent );
TransitionButtonImage( mDisabledBackgroundContent );
AddButtonImage( mSelectedContent );
TransitionButtonImage( mDisabledSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
TransitionOut( mBackgroundContent );
TransitionButtonImage( mBackgroundContent );
AddButtonImage( mDisabledContent );
TransitionButtonImage( mUnselectedContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
TransitionOut( mSelectedContent );
TransitionOut( mSelectedBackgroundContent );
TransitionOut( mDisabledContent );
TransitionButtonImage( mSelectedBackgroundContent );
AddButtonImage( mDisabledSelectedContent );
TransitionButtonImage( mSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mDisabledContent );
TransitionOut( mDisabledSelectedContent );
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 );
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 );
return mAnimationTime;
}
-void Button::SetLabel( const std::string& label )
+void Button::SetLabelText( const std::string& label )
{
- Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
- SetLabel( textLabel );
+ Property::Map labelProperty;
+ labelProperty.Insert( "text", label );
+ ModifyLabel( labelProperty );
}
-void Button::SetLabel( Actor label )
+std::string Button::GetLabelText() const
{
- if( mLabel != label )
+ Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
+ if( label )
{
- if( mLabel && mLabel.GetParent() )
- {
- mLabel.GetParent().Remove( mLabel );
- }
-
- mLabel = label;
- mLabel.SetPosition( 0.f, 0.f );
+ return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
+ }
+ return std::string();
+}
+void Button::ModifyLabel( const Property::Map& properties )
+{
+ // If we don't have a label yet, create one.
+ if( !mLabel )
+ {
+ // If we don't have a label, create one and set it up.
+ // Note: The label text is set from the passed in property map after creation.
+ mLabel = Toolkit::TextLabel::New();
+ mLabel.SetPosition( 0.0f, 0.0f );
// label should be the top of the button
Self().Add( mLabel );
+ }
- OnLabelSet();
+ // 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 ) );
- RelayoutRequest();
+ // 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 );
+ }
}
-}
-Actor Button::GetLabel() const
-{
- return mLabel;
+ // Notify derived button classes of the change.
+ OnLabelSet( false );
+
+ RelayoutRequest();
}
-Actor& Button::GetLabel()
+Actor& Button::GetLabelActor()
{
return mLabel;
}
-void Button::SetButtonImage( Actor image )
+void Button::SetDecoration( DecorationState state, Actor actor )
{
- StopTransitionAnimation();
-
- if( mUnselectedContent && mUnselectedContent.GetParent() )
+ if( mDecoration[ state ] && mDecoration[ state ].GetParent() )
{
- Self().Remove( mUnselectedContent );
+ mDecoration[ state ].Unparent();
}
- mUnselectedContent = image;
- if( mUnselectedContent )
- {
- mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mUnselectedContent.SetPosition( 0.f, 0.f );
- }
- ResetImageLayers();
- OnButtonImageSet();
+ mDecoration[ state ] = actor;
+ mDecoration[ state ].SetColorMode( USE_OWN_COLOR );
+ ResetImageLayers();
RelayoutRequest();
}
-Actor Button::GetButtonImage() const
+Actor& Button::GetDecoration( DecorationState state )
{
- return mUnselectedContent;
+ return mDecoration[ state ];
}
-Actor& Button::GetButtonImage()
+void Button::SetupContent( Actor& actorToModify, Actor newActor )
{
- return mUnselectedContent;
+ if( newActor )
+ {
+ StopTransitionAnimation();
+
+ if( actorToModify && actorToModify.GetParent() )
+ {
+ actorToModify.Unparent();
+ }
+
+ actorToModify = newActor;
+
+ if( actorToModify )
+ {
+ actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ actorToModify.SetPosition( 0.f, 0.f );
+ }
+
+ ResetImageLayers();
+ }
}
-void Button::SetSelectedImage( Actor image )
+const Vector4 Button::GetUnselectedColor() const
{
- StopTransitionAnimation();
+ return mUnselectedColor;
+}
+
+void Button::SetColor( const Vector4& color, Button::PaintState selectedState )
+{
+ Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this.
+ bool imageFileExists = false;
+ Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE;
- if( mSelectedContent && mSelectedContent.GetParent() )
+ if ( selectedState == SelectedState || selectedState == DisabledSelectedState )
{
- Self().Remove( mSelectedContent );
+ mSelectedColor = color;
+ contentActor = &mSelectedContent;
+ imageFileExists = !GetSelectedImageFilename().empty();
}
-
- mSelectedContent = image;
- if( mSelectedContent )
+ else
{
- mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mSelectedContent.SetPosition( 0.f, 0.f );
+ mUnselectedColor = color;
+ contentActor = &mUnselectedContent;
+ imageFileExists = !GetUnselectedImageFilename().empty();
+ visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE;
}
- ResetImageLayers();
- OnSelectedImageSet();
- RelayoutRequest();
+ if ( contentActor )
+ {
+ if( imageFileExists )
+ {
+ // If there is existing unselected content, change the color on it directly.
+ contentActor->SetColor( color );
+ }
+ else
+ {
+ // If there is no existing content, create a new actor to use for flat color.
+ Actor placementActor = Actor::New();
+ Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
+ Toolkit::Visual::Base visual;
+
+ Property::Map map;
+ map[ Toolkit::VisualProperty::TYPE ] = Toolkit::Visual::COLOR;
+ map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
+
+ visual = visualFactory.CreateVisual( map );
+
+ RegisterVisual( visualIndex, placementActor, visual );
+
+ SetupContent( *contentActor, placementActor ); //
+ contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ }
+ }
}
-Actor Button::GetSelectedImage() const
+const Vector4 Button::GetSelectedColor() const
{
- return mSelectedContent;
+ return mSelectedColor;
}
-Actor& Button::GetSelectedImage()
+void Button::SetUnselectedImage( const std::string& filename )
{
- return mSelectedContent;
+ Toolkit::ImageView newContent;
+ if( !filename.empty() )
+ {
+ newContent = Toolkit::ImageView::New( filename );
+ }
+ else
+ {
+ newContent = Toolkit::ImageView::New();
+ }
+
+ if( newContent )
+ {
+ SetupContent( mUnselectedContent, newContent );
+
+ mUnselectedContent.SetColor( mUnselectedColor );
+
+ OnUnselectedImageSet();
+ RelayoutRequest();
+ }
}
-void Button::SetBackgroundImage( Actor image )
+Actor& Button::GetUnselectedImage()
{
- StopTransitionAnimation();
+ return mUnselectedContent;
+}
- if( mBackgroundContent && mBackgroundContent.GetParent() )
+void Button::SetSelectedImage( const std::string& filename )
+{
+ Toolkit::ImageView newContent;
+ if( !filename.empty() )
+ {
+ newContent = Toolkit::ImageView::New( filename );
+ }
+ else
{
- Self().Remove( mBackgroundContent );
+ newContent = Toolkit::ImageView::New();
}
- mBackgroundContent = image;
- if( mBackgroundContent )
+ if( newContent )
{
- mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mBackgroundContent.SetPosition( 0.f, 0.f );
+ SetupContent( mSelectedContent, newContent );
+
+ mSelectedContent.SetColor( mSelectedColor );
+
+ OnSelectedImageSet();
+ RelayoutRequest();
}
- ResetImageLayers();
- OnBackgroundImageSet();
+}
- RelayoutRequest();
+Actor& Button::GetSelectedImage()
+{
+ return mSelectedContent;
}
-Actor Button::GetBackgroundImage() const
+void Button::SetBackgroundImage( const std::string& filename )
{
- return mBackgroundContent;
+ SetupContent( mBackgroundContent, Toolkit::ImageView::New( filename ) );
+
+ OnBackgroundImageSet();
+ RelayoutRequest();
}
Actor& Button::GetBackgroundImage()
return mBackgroundContent;
}
-void Button::SetSelectedBackgroundImage( Actor image )
+void Button::SetSelectedBackgroundImage( const std::string& filename )
{
- StopTransitionAnimation();
-
- if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
- {
- Self().Remove( mSelectedBackgroundContent );
- }
+ SetupContent( mSelectedBackgroundContent, Toolkit::ImageView::New( filename ) );
- mSelectedBackgroundContent = image;
- if( mSelectedBackgroundContent )
- {
- mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
- }
- ResetImageLayers();
OnSelectedBackgroundImageSet();
-
RelayoutRequest();
}
-Actor Button::GetSelectedBackgroundImage() const
-{
- return mSelectedBackgroundContent;
-}
-
Actor& Button::GetSelectedBackgroundImage()
{
return mSelectedBackgroundContent;
}
-void Button::SetDisabledImage( Actor image )
+void Button::SetDisabledImage( const std::string& filename )
{
- StopTransitionAnimation();
+ SetupContent( mDisabledContent, Toolkit::ImageView::New( filename ) );
- if( mDisabledContent && mDisabledContent.GetParent() )
- {
- Self().Remove( mDisabledContent );
- }
-
- mDisabledContent = image;
- if( mDisabledContent )
- {
- mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledContent.SetPosition( 0.f, 0.f );
- }
-
- ResetImageLayers();
OnDisabledImageSet();
-}
-
-Actor Button::GetDisabledImage() const
-{
- return mDisabledContent;
+ RelayoutRequest();
}
Actor& Button::GetDisabledImage()
return mDisabledContent;
}
-void Button::SetDisabledSelectedImage( Actor image )
+void Button::SetDisabledSelectedImage( const std::string& filename )
{
- StopTransitionAnimation();
+ SetupContent( mDisabledSelectedContent, Toolkit::ImageView::New( filename ) );
- if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
- {
- Self().Remove( mDisabledSelectedContent );
- }
-
- mDisabledSelectedContent = image;
- if( mDisabledSelectedContent )
- {
- mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledSelectedContent.SetPosition( 0.f, 0.f );
- }
-
- ResetImageLayers();
OnDisabledSelectedImageSet();
+ RelayoutRequest();
}
-Actor Button::GetDisabledSelectedImage() const
+Actor& Button::GetDisabledSelectedImage()
{
return mDisabledSelectedContent;
}
-Actor& Button::GetDisabledSelectedImage()
+void Button::SetDisabledBackgroundImage( const std::string& filename )
{
- return mDisabledSelectedContent;
+ SetupContent( mDisabledBackgroundContent, Toolkit::ImageView::New( filename ) );
+
+ OnDisabledBackgroundImageSet();
+ RelayoutRequest();
}
-void Button::SetDisabledBackgroundImage( Actor image )
+Actor& Button::GetDisabledBackgroundImage()
{
- StopTransitionAnimation();
-
- if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
- {
- Self().Remove( mDisabledBackgroundContent );
- }
+ return mDisabledBackgroundContent;
+}
- mDisabledBackgroundContent = image;
- if( mDisabledBackgroundContent )
+std::string Button::GetUnselectedImageFilename() const
+{
+ if( mUnselectedContent )
{
- mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+ ResourceImage image = ResourceImage::DownCast( mUnselectedContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
}
- ResetImageLayers();
- OnDisabledBackgroundImageSet();
+ return std::string();
}
-Actor Button::GetDisabledBackgroundImage() const
+std::string Button::GetSelectedImageFilename() const
{
- return mDisabledBackgroundContent;
+ if( mSelectedContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mSelectedContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
-Actor& Button::GetDisabledBackgroundImage()
+std::string Button::GetDisabledImageFilename() const
{
- return mDisabledBackgroundContent;
+ if( mDisabledContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mDisabledContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
return false;
}
-void Button::OnButtonStageDisconnection()
-{
- if( ButtonDown == mState )
- {
- if( !mTogglableButton )
- {
- Released();
-
- if( mAutoRepeating )
- {
- mAutoRepeatingTimer.Reset();
- }
- }
- }
-}
-
void Button::OnButtonDown()
{
if( !mTogglableButton )
return connected;
}
-bool Button::OnTouchEvent(const TouchEvent& event)
+void Button::OnInitialize()
+{
+ Actor self = Self();
+
+ mTapDetector = TapGestureDetector::New();
+ mTapDetector.Attach( self );
+ mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
+
+ self.SetKeyboardFocusable( true );
+
+ self.TouchSignal().Connect( this, &Button::OnTouch );
+}
+
+bool Button::OnAccessibilityActivated()
+{
+ return OnKeyboardEnter();
+}
+
+bool Button::OnKeyboardEnter()
+{
+ // 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::OnStageDisconnection()
+{
+ if( ButtonDown == mState )
+ {
+ if( !mTogglableButton )
+ {
+ Released();
+
+ if( mAutoRepeating )
+ {
+ mAutoRepeatingTimer.Reset();
+ }
+ }
+ }
+
+ mState = ButtonUp;
+
+ Control::OnStageDisconnection();
+}
+
+bool Button::OnTouch( Actor actor, const TouchData& touch )
{
// Only events are processed when the button is not disabled and the touch event has only
// one touch point.
- if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
+ if( ( !mDisabled ) && ( 1 == touch.GetPointCount() ) )
{
- switch( event.GetPoint(0).state )
+ switch( touch.GetState( 0 ) )
{
- case TouchPoint::Down:
+ case PointState::DOWN:
{
OnButtonDown(); // Notification for derived classes.
mState = ButtonDown;
break;
}
- case TouchPoint::Up:
+ case PointState::UP:
{
OnButtonUp(); // Notification for derived classes.
mState = ButtonUp;
break;
}
- case TouchPoint::Interrupted:
+ case PointState::INTERRUPTED:
{
OnTouchPointInterrupted(); // Notification for derived classes.
mState = ButtonUp;
break;
}
- case TouchPoint::Leave:
+ case PointState::LEAVE:
{
OnTouchPointLeave(); // Notification for derived classes.
mState = ButtonUp;
break;
}
- case TouchPoint::Motion:
- case TouchPoint::Stationary: // FALLTHROUGH
+ case PointState::MOTION:
+ case PointState::STATIONARY: // FALLTHROUGH
{
// Nothing to do
break;
}
- default:
- {
- DALI_ASSERT_ALWAYS( !"Point status unhandled." );
- break;
- }
}
}
- else if( 1 < event.GetPointCount() )
+ else if( 1 < touch.GetPointCount() )
{
OnTouchPointLeave(); // Notification for derived classes.
return false;
}
-void Button::OnInitialize()
-{
- Actor self = Self();
-
- mTapDetector = TapGestureDetector::New();
- mTapDetector.Attach( self );
- mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
-
- OnButtonInitialize();
-
- self.SetKeyboardFocusable( true );
-}
-
-bool Button::OnAccessibilityActivated()
-{
- return OnKeyboardEnter();
-}
-
-bool Button::OnKeyboardEnter()
-{
- // 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)
{
// Do nothing.
StopTransitionAnimation();
// Notifies the derived class the button has been pressed.
- OnPressed();
+ OnPressed();
- //Layer Order
+ //Layer Order
//(4) mSelectedContent (Inserted)
//(3) mUnselectedContent
//(2) mSelectedBackgroundContent (Inserted)
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 );
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 );
{
if( actor )
{
- actor.Unparent();
Self().Add( actor );
PrepareForTranstionOut( actor );
}
//(2) mUnselectedContent
//(1) mBackgroundContent
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
RemoveButtonImage( mSelectedContent );
RemoveButtonImage( mSelectedBackgroundContent );
RemoveButtonImage( mDisabledContent );
PrepareAddButtonImage( mBackgroundContent );
PrepareAddButtonImage( mUnselectedContent );
+
+ PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
break;
}
case SelectedState:
//(2) mSelectedBackgroundContent
//(1) mBackgroundContent
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
RemoveButtonImage( mUnselectedContent );
RemoveButtonImage( mDisabledContent );
RemoveButtonImage( mDisabledSelectedContent );
PrepareAddButtonImage( mBackgroundContent );
PrepareAddButtonImage( mSelectedBackgroundContent );
PrepareAddButtonImage( mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
break;
}
//(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;
}
// (2) mDisabledSelectedContent
// (1) mDisabledBackgroundContent
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
RemoveButtonImage( mSelectedContent );
RemoveButtonImage( mBackgroundContent );
RemoveButtonImage( mSelectedBackgroundContent );
}
PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
break;
}
break;
}
- case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
{
- GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() );
break;
}
- case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
+ case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
{
- GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetSelectedImage( value.Get< std::string >() );
break;
}
- case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
+ case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
{
- GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetDisabledImage( value.Get< std::string >() );
break;
}
- case Toolkit::Button::Property::LABEL_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_COLOR:
{
- GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), UnselectedState );
break;
}
+
+ case Toolkit::Button::Property::SELECTED_COLOR:
+ {
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), SelectedState );
+ 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;
}
}
}
break;
}
- case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
+ {
+ value = GetImplementation( button ).GetUnselectedImageFilename();
+ break;
+ }
+
+ case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
+ {
+ value = GetImplementation( button ).GetSelectedImageFilename();
+ break;
+ }
+
+ case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
+ {
+ value = GetImplementation( button ).GetDisabledImageFilename();
+ break;
+ }
+
+ case Toolkit::Button::Property::UNSELECTED_COLOR:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map );
- value = map;
+ value = GetImplementation( button ).GetUnselectedColor();
break;
}
- case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
+ case Toolkit::Button::Property::SELECTED_COLOR:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
- value = map;
+ value = GetImplementation( button ).GetSelectedColor();
break;
}
- case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
+ case Toolkit::Button::Property::LABEL_TEXT:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
- value = map;
+ value = GetImplementation( button ).GetLabelText();
break;
}
- case Toolkit::Button::Property::LABEL_ACTOR:
+ case Toolkit::Button::Property::LABEL:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
- value = map;
+ Property::Map emptyMap;
+ value = emptyMap;
break;
}
}
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