2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "button-impl.h"
22 #include <cstring> // for strcmp
23 #include <dali/public-api/events/touch-event.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/devel-api/object/type-registry-helper.h>
26 #include <dali/public-api/actors/image-actor.h>
27 #include <dali/devel-api/scripting/scripting.h>
30 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
33 * Button states and contents
34 * (3) mSelectedContent
35 * (2) mUnselectedContent (2) mSelectedBackgroundContent
36 * (1) mBackgroundContent (1) mBackgroundContent
37 * < unselected > ----------------------- < selected >
39 * | OnDisabled() | OnDisabled()
41 * < disabled > < disabled-selected >
42 * (2) mDisabledContent (2) mDisabledSelectedContent
43 * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent
45 * The drawing order of child actors is as follows.
48 * | mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
49 * | mSelectedBackgroundContent
50 * Bottom mBackgroundContent / mDisabledBackgroundContent
52 * Some of contents may be missed.
53 * 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.
70 // empty handle as we cannot create button (but type registered for clicked signal)
74 // Setup properties, signals and actions using the type-registry.
75 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
77 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
78 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating", BOOLEAN, AUTO_REPEATING )
79 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
80 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
81 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
82 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
83 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "normal-state-actor", MAP, NORMAL_STATE_ACTOR )
84 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR )
85 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR )
86 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor", MAP, LABEL_ACTOR )
88 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
89 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
90 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
91 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "state-changed", SIGNAL_STATE_CHANGED )
93 DALI_ACTION_REGISTRATION( Toolkit, Button, "button-click", ACTION_BUTTON_CLICK )
95 DALI_TYPE_REGISTRATION_END()
97 const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
98 const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
100 } // unnamed namespace
103 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
104 mAutoRepeatingTimer(),
106 mAutoRepeating( false ),
107 mTogglableButton( false ),
109 mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
110 mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
111 mAnimationTime( 0.0f ),
112 mClickActionPerforming( false ),
114 mPaintState( UnselectedState )
122 void Button::SetDisabled( bool disabled )
124 if( disabled == mDisabled )
129 StopTransitionAnimation();
131 mDisabled = disabled;
133 // Notifies the derived class the button has been disabled.
136 switch( mPaintState )
138 case UnselectedState:
141 //(3) mDisabledContent (Inserted)
142 //(4) mUnselectedContent
143 //(2) mDisabledBackgroundContent (Inserted)
144 //(1) mBackgroundContent
146 TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent );
147 TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent );
149 TransitionOut( mUnselectedContent );
150 TransitionOut( mSelectedContent );
151 TransitionOut( mBackgroundContent );
152 TransitionOut( mSelectedBackgroundContent );
153 TransitionOut( mDisabledSelectedContent );
155 mPaintState = DisabledUnselectedState;
161 //(5) mDisabledSelectedContent (Inserted)
162 //(4) mSelectedContent
163 //(3) mDisabledBackgroundContent (Inserted)
164 //(2) mSelectedBackgroundContent
165 //(1) mBackgroundContent
167 TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent );
168 TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent );
170 TransitionOut( mUnselectedContent );
171 TransitionOut( mSelectedContent );
172 TransitionOut( mBackgroundContent );
173 TransitionOut( mSelectedBackgroundContent );
174 TransitionOut( mDisabledContent );
176 mPaintState = DisabledSelectedState;
179 case DisabledUnselectedState:
182 //(3) mUnselectedContent (Inserted)
183 //(4) mDisabledContent
184 //(2) mBackgroundContent (Inserted)
185 //(1) mDisabledBackgroundContent
187 TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent );
188 TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
190 TransitionOut( mSelectedContent );
191 TransitionOut( mSelectedBackgroundContent );
192 TransitionOut( mDisabledContent );
193 TransitionOut( mDisabledSelectedContent );
194 TransitionOut( mDisabledBackgroundContent );
196 mPaintState = UnselectedState;
199 case DisabledSelectedState:
202 //(4) mSelectedContent (Inserted)
203 //(5) mDisabledSelectedContent
204 //(3) mSelectedBackgroundContent (Inserted)
205 //(2) mBackgroundContent (Inserted)
206 //(1) mDisabledBackgroundContent
208 TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent );
209 TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent );
210 TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
212 TransitionOut( mUnselectedContent );
213 TransitionOut( mDisabledContent );
214 TransitionOut( mDisabledSelectedContent );
215 TransitionOut( mDisabledBackgroundContent );
217 mPaintState = SelectedState;
222 StartTransitionAnimation();
225 bool Button::IsDisabled() const
230 void Button::SetAutoRepeating( bool autoRepeating )
232 mAutoRepeating = autoRepeating;
234 // An autorepeating button can't be a togglable button.
237 mTogglableButton = false;
241 // Emit a signal is not wanted, only change the appearance.
242 SetSelected( false, false );
247 bool Button::IsAutoRepeating() const
249 return mAutoRepeating;
252 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
254 DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
255 mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
258 float Button::GetInitialAutoRepeatingDelay() const
260 return mInitialAutoRepeatingDelay;
263 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
265 DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
266 mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
269 float Button::GetNextAutoRepeatingDelay() const
271 return mNextAutoRepeatingDelay;
274 void Button::SetTogglableButton( bool togglable )
276 mTogglableButton = togglable;
278 // A togglable button can't be an autorepeating button.
281 mAutoRepeating = false;
285 bool Button::IsTogglableButton() const
287 return mTogglableButton;
290 void Button::SetSelected( bool selected )
292 if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
294 SetSelected( selected, true );
298 void Button::SetSelected( bool selected, bool emitSignal )
300 StopTransitionAnimation();
302 mSelected = selected;
304 // Notifies the derived class the button has been selected.
307 switch( mPaintState )
309 case UnselectedState:
312 //(3) mSelectedContent (Inserted)
313 //(4) mUnselectedContent
314 //(2) mSelectedBackgroundContent (Inserted)
315 //(1) mBackgroundContent
317 TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
318 TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
319 TransitionInAtIndex( 0, mBackgroundContent );
321 TransitionOut( mUnselectedContent );
322 TransitionOut( mDisabledContent );
323 TransitionOut( mDisabledSelectedContent );
324 TransitionOut( mDisabledBackgroundContent );
326 mPaintState = SelectedState;
332 //(3) mUnselectedContent (Inserted)
333 //(2) mSelectedContent
334 //(1) mBackgroundContent
336 TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
337 TransitionInAtIndex( 0, mBackgroundContent );
339 TransitionOut( mSelectedContent );
340 TransitionOut( mSelectedBackgroundContent );
341 TransitionOut( mDisabledContent );
342 TransitionOut( mDisabledSelectedContent );
343 TransitionOut( mDisabledBackgroundContent );
345 mPaintState = UnselectedState;
348 case DisabledUnselectedState:
349 case DisabledSelectedState:
351 DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
356 StartTransitionAnimation();
360 Toolkit::Button handle( GetOwner() );
363 mStateChangedSignal.Emit( handle );
369 bool Button::IsSelected() const
371 return mTogglableButton && mSelected;
374 void Button::SetAnimationTime( float animationTime )
376 mAnimationTime = animationTime;
379 float Button::GetAnimationTime() const
381 return mAnimationTime;
384 void Button::SetLabel( const std::string& label )
386 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
387 SetLabel( textLabel );
390 void Button::SetLabel( Actor label )
392 if( mLabel != label )
394 if( mLabel && mLabel.GetParent() )
396 mLabel.GetParent().Remove( mLabel );
400 mLabel.SetPosition( 0.f, 0.f );
402 // label should be the top of the button
403 Self().Add( mLabel );
411 Actor Button::GetLabel() const
416 Actor& Button::GetLabel()
421 void Button::SetButtonImage( Actor image )
423 StopTransitionAnimation();
425 if( mUnselectedContent && mUnselectedContent.GetParent() )
427 Self().Remove( mUnselectedContent );
430 mUnselectedContent = image;
431 if( mUnselectedContent )
433 mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
434 mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
435 mUnselectedContent.SetPosition( 0.f, 0.f );
443 Actor Button::GetButtonImage() const
445 return mUnselectedContent;
448 Actor& Button::GetButtonImage()
450 return mUnselectedContent;
453 void Button::SetSelectedImage( Actor image )
455 StopTransitionAnimation();
457 if( mSelectedContent && mSelectedContent.GetParent() )
459 Self().Remove( mSelectedContent );
462 mSelectedContent = image;
463 if( mSelectedContent )
465 mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
466 mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
467 mSelectedContent.SetPosition( 0.f, 0.f );
470 OnSelectedImageSet();
475 Actor Button::GetSelectedImage() const
477 return mSelectedContent;
480 Actor& Button::GetSelectedImage()
482 return mSelectedContent;
485 void Button::SetBackgroundImage( Actor image )
487 StopTransitionAnimation();
489 if( mBackgroundContent && mBackgroundContent.GetParent() )
491 Self().Remove( mBackgroundContent );
494 mBackgroundContent = image;
495 if( mBackgroundContent )
497 mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
498 mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
499 mBackgroundContent.SetPosition( 0.f, 0.f );
502 OnBackgroundImageSet();
507 Actor Button::GetBackgroundImage() const
509 return mBackgroundContent;
512 Actor& Button::GetBackgroundImage()
514 return mBackgroundContent;
517 void Button::SetSelectedBackgroundImage( Actor image )
519 StopTransitionAnimation();
521 if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
523 Self().Remove( mSelectedBackgroundContent );
526 mSelectedBackgroundContent = image;
527 if( mSelectedBackgroundContent )
529 mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
530 mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
531 mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
534 OnSelectedBackgroundImageSet();
539 Actor Button::GetSelectedBackgroundImage() const
541 return mSelectedBackgroundContent;
544 Actor& Button::GetSelectedBackgroundImage()
546 return mSelectedBackgroundContent;
549 void Button::SetDisabledImage( Actor image )
551 StopTransitionAnimation();
553 if( mDisabledContent && mDisabledContent.GetParent() )
555 Self().Remove( mDisabledContent );
558 mDisabledContent = image;
559 if( mDisabledContent )
561 mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
562 mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
563 mDisabledContent.SetPosition( 0.f, 0.f );
567 OnDisabledImageSet();
570 Actor Button::GetDisabledImage() const
572 return mDisabledContent;
575 Actor& Button::GetDisabledImage()
577 return mDisabledContent;
580 void Button::SetDisabledSelectedImage( Actor image )
582 StopTransitionAnimation();
584 if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
586 Self().Remove( mDisabledSelectedContent );
589 mDisabledSelectedContent = image;
590 if( mDisabledSelectedContent )
592 mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
593 mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
594 mDisabledSelectedContent.SetPosition( 0.f, 0.f );
598 OnDisabledSelectedImageSet();
601 Actor Button::GetDisabledSelectedImage() const
603 return mDisabledSelectedContent;
606 Actor& Button::GetDisabledSelectedImage()
608 return mDisabledSelectedContent;
611 void Button::SetDisabledBackgroundImage( Actor image )
613 StopTransitionAnimation();
615 if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
617 Self().Remove( mDisabledBackgroundContent );
620 mDisabledBackgroundContent = image;
621 if( mDisabledBackgroundContent )
623 mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
624 mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
625 mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
628 OnDisabledBackgroundImageSet();
631 Actor Button::GetDisabledBackgroundImage() const
633 return mDisabledBackgroundContent;
636 Actor& Button::GetDisabledBackgroundImage()
638 return mDisabledBackgroundContent;
641 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
645 Dali::BaseHandle handle( object );
647 Toolkit::Button button = Toolkit::Button::DownCast( handle );
649 DALI_ASSERT_ALWAYS( button );
651 if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
653 ret = GetImplementation( button ).DoClickAction( attributes );
659 bool Button::DoClickAction( const Property::Map& attributes )
661 // Prevents the button signals from doing a recursive loop by sending an action
662 // and re-emitting the signals.
663 if( !mClickActionPerforming )
665 mClickActionPerforming = true;
669 mClickActionPerforming = false;
677 void Button::OnButtonStageDisconnection()
679 if( ButtonDown == mState )
681 if( !mTogglableButton )
687 mAutoRepeatingTimer.Reset();
693 void Button::OnButtonDown()
695 if( !mTogglableButton )
697 Toolkit::Button handle( GetOwner() );
703 SetUpTimer( mInitialAutoRepeatingDelay );
707 mPressedSignal.Emit( handle );
711 void Button::OnButtonUp()
713 if( ButtonDown == mState )
715 if( mTogglableButton )
717 SetSelected( !mSelected );
725 mAutoRepeatingTimer.Reset();
728 Toolkit::Button handle( GetOwner() );
731 mReleasedSignal.Emit( handle );
732 mClickedSignal.Emit( handle );
737 void Button::OnTouchPointLeave()
739 if( ButtonDown == mState )
741 if( !mTogglableButton )
743 Toolkit::Button handle( GetOwner() );
749 mAutoRepeatingTimer.Reset();
753 mReleasedSignal.Emit( handle );
758 void Button::OnTouchPointInterrupted()
763 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
765 return mPressedSignal;
768 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
770 return mReleasedSignal;
773 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
775 return mClickedSignal;
778 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
780 return mStateChangedSignal;
783 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
785 Dali::BaseHandle handle( object );
787 bool connected( true );
788 Toolkit::Button button = Toolkit::Button::DownCast( handle );
790 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
792 button.PressedSignal().Connect( tracker, functor );
794 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
796 button.ReleasedSignal().Connect( tracker, functor );
798 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
800 button.ClickedSignal().Connect( tracker, functor );
802 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
804 button.StateChangedSignal().Connect( tracker, functor );
808 // signalName does not match any signal
815 bool Button::OnTouchEvent(const TouchEvent& event)
817 // Only events are processed when the button is not disabled and the touch event has only
819 if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
821 switch( event.GetPoint(0).state )
823 case TouchPoint::Down:
825 OnButtonDown(); // Notification for derived classes.
827 // Sets the button state to ButtonDown.
833 OnButtonUp(); // Notification for derived classes.
835 // Sets the button state to ButtonUp.
839 case TouchPoint::Interrupted:
841 OnTouchPointInterrupted(); // Notification for derived classes.
843 // Sets the button state to the default (ButtonUp).
847 case TouchPoint::Leave:
849 OnTouchPointLeave(); // Notification for derived classes.
851 // Sets the button state to the default (ButtonUp).
855 case TouchPoint::Motion:
856 case TouchPoint::Stationary: // FALLTHROUGH
863 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
868 else if( 1 < event.GetPointCount() )
870 OnTouchPointLeave(); // Notification for derived classes.
872 // Sets the button state to the default (ButtonUp).
879 void Button::OnInitialize()
883 mTapDetector = TapGestureDetector::New();
884 mTapDetector.Attach( self );
885 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
887 OnButtonInitialize();
889 self.SetKeyboardFocusable( true );
892 bool Button::OnAccessibilityActivated()
894 return OnKeyboardEnter();
897 bool Button::OnKeyboardEnter()
899 // When the enter key is pressed, or button is activated, the click action is performed.
900 Property::Map attributes;
901 bool ret = DoClickAction( attributes );
906 void Button::OnControlStageDisconnection()
908 OnButtonStageDisconnection(); // Notification for derived classes.
912 void Button::OnTap(Actor actor, const TapGesture& tap)
917 void Button::SetUpTimer( float delay )
919 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
920 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
921 mAutoRepeatingTimer.Start();
924 bool Button::AutoRepeatingSlot()
926 bool consumed = false;
929 // Restart the autorepeat timer.
930 SetUpTimer( mNextAutoRepeatingDelay );
934 Toolkit::Button handle( GetOwner() );
937 consumed = mReleasedSignal.Emit( handle );
938 consumed |= mClickedSignal.Emit( handle );
939 consumed |= mPressedSignal.Emit( handle );
945 void Button::Pressed()
947 if( mPaintState == UnselectedState )
949 StopTransitionAnimation();
951 // Notifies the derived class the button has been pressed.
955 //(4) mSelectedContent (Inserted)
956 //(3) mUnselectedContent
957 //(2) mSelectedBackgroundContent (Inserted)
958 //(1) mBackgroundContent
960 TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
961 TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
962 TransitionInAtIndex( 0, mBackgroundContent );
964 TransitionOut( mUnselectedContent );
965 TransitionOut( mDisabledContent );
966 TransitionOut( mDisabledSelectedContent );
967 TransitionOut( mDisabledBackgroundContent );
969 mPaintState = SelectedState;
971 StartTransitionAnimation();
975 void Button::Released()
977 if( mPaintState == SelectedState )
979 StopTransitionAnimation();
981 // Notifies the derived class the button has been released.
985 //(3) mUnselectedContent (Inserted)
986 //(2) mSelectedContent
987 //(1) mBackgroundContent
989 TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
990 TransitionInAtIndex( 0, mBackgroundContent );
992 TransitionOut( mSelectedContent );
993 TransitionOut( mSelectedBackgroundContent );
994 TransitionOut( mDisabledContent );
995 TransitionOut( mDisabledSelectedContent );
996 TransitionOut( mDisabledBackgroundContent );
998 mPaintState = UnselectedState;
1000 StartTransitionAnimation();
1004 Button::ButtonState Button::GetState()
1009 Button::PaintState Button::GetPaintState()
1014 bool Button::InsertButtonImage( unsigned int index, Actor& actor )
1018 Self().Insert( index, actor );
1019 PrepareForTranstionOut( actor );
1026 void Button::RemoveButtonImage( Actor& actor )
1030 if( actor.GetParent() )
1032 Self().Remove( actor );
1034 PrepareForTranstionIn( actor );
1038 unsigned int Button::FindChildIndex( Actor& actor )
1040 Actor self = Self();
1041 unsigned int childrenNum = self.GetChildCount();
1043 for( unsigned int i = 0; i < childrenNum; i++ )
1045 Actor child = self.GetChildAt( i );
1046 if( child == actor )
1055 void Button::TransitionInBetween( Actor childLower, Actor childUpper, Actor actor )
1057 unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper );
1058 TransitionInAtIndex( index, actor );
1061 void Button::TransitionInAbove( Actor child, Actor actor )
1063 unsigned int index = child ? FindChildIndex( child ) + 1 : 0;
1064 TransitionInAtIndex( index, actor );
1067 void Button::TransitionInAtIndex( unsigned int index, Actor actor )
1071 if( !actor.GetParent() )
1073 Self().Insert( index, actor );
1076 OnTransitionIn( actor );
1080 void Button::TransitionOut( Actor actor )
1082 OnTransitionOut( actor );
1085 void Button::ResetImageLayers()
1087 //ensure that all layers are in the correct order and state according to the paint state
1090 switch( mPaintState )
1092 case UnselectedState:
1095 //(2) mUnselectedContent
1096 //(1) mBackgroundContent
1098 RemoveButtonImage( mSelectedContent );
1099 RemoveButtonImage( mSelectedBackgroundContent );
1100 RemoveButtonImage( mDisabledContent );
1101 RemoveButtonImage( mDisabledSelectedContent );
1102 RemoveButtonImage( mDisabledBackgroundContent );
1104 if( InsertButtonImage( index, mBackgroundContent ) )
1108 if( InsertButtonImage( index, mUnselectedContent ) )
1117 //(3) mSelectedContent
1118 //(2) mSelectedBackgroundContent
1119 //(1) mBackgroundContent
1121 RemoveButtonImage( mUnselectedContent );
1122 RemoveButtonImage( mDisabledContent );
1123 RemoveButtonImage( mDisabledSelectedContent );
1124 RemoveButtonImage( mDisabledBackgroundContent );
1126 if( InsertButtonImage( index, mBackgroundContent ) )
1130 if( InsertButtonImage( index, mSelectedBackgroundContent ) )
1134 if( InsertButtonImage( index, mSelectedContent ) )
1140 case DisabledUnselectedState:
1143 //(2) mDisabledContent
1144 //(1) mDisabledBackgroundContent
1146 RemoveButtonImage( mUnselectedContent );
1147 RemoveButtonImage( mBackgroundContent );
1148 RemoveButtonImage( mSelectedContent );
1149 RemoveButtonImage( mDisabledSelectedContent );
1150 RemoveButtonImage( mSelectedBackgroundContent );
1152 if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) )
1156 if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) )
1162 case DisabledSelectedState:
1165 // (2) mDisabledSelectedContent
1166 // (1) mDisabledBackgroundContent
1168 RemoveButtonImage( mUnselectedContent );
1169 RemoveButtonImage( mSelectedContent );
1170 RemoveButtonImage( mBackgroundContent );
1171 RemoveButtonImage( mSelectedBackgroundContent );
1172 RemoveButtonImage( mDisabledContent );
1174 if( mDisabledBackgroundContent )
1176 if( InsertButtonImage( index, mDisabledBackgroundContent) )
1183 if( InsertButtonImage( index, mBackgroundContent ) )
1187 if( InsertButtonImage( index, mSelectedBackgroundContent ) )
1193 if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) )
1202 void Button::StartTransitionAnimation()
1204 if( mTransitionAnimation )
1206 mTransitionAnimation.Play();
1214 void Button::StopTransitionAnimation()
1216 if( mTransitionAnimation )
1218 mTransitionAnimation.Clear();
1219 mTransitionAnimation.Reset();
1223 Dali::Animation Button::GetTransitionAnimation()
1225 if( !mTransitionAnimation )
1227 mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
1228 mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
1231 return mTransitionAnimation;
1234 void Button::TransitionAnimationFinished( Dali::Animation& source )
1236 StopTransitionAnimation();
1240 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1242 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1248 case Toolkit::Button::Property::DISABLED:
1250 GetImplementation( button ).SetDisabled( value.Get< bool >() );
1254 case Toolkit::Button::Property::AUTO_REPEATING:
1256 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1260 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1262 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1266 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1268 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1272 case Toolkit::Button::Property::TOGGLABLE:
1274 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1278 case Toolkit::Button::Property::SELECTED:
1280 GetImplementation( button ).SetSelected( value.Get< bool >() );
1284 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1286 GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1290 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1292 GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1296 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1298 GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1302 case Toolkit::Button::Property::LABEL_ACTOR:
1304 GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
1311 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1313 Property::Value value;
1315 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1319 switch ( propertyIndex )
1321 case Toolkit::Button::Property::DISABLED:
1323 value = GetImplementation( button ).mDisabled;
1327 case Toolkit::Button::Property::AUTO_REPEATING:
1329 value = GetImplementation( button ).mAutoRepeating;
1333 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1335 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1339 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1341 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1345 case Toolkit::Button::Property::TOGGLABLE:
1347 value = GetImplementation( button ).mTogglableButton;
1351 case Toolkit::Button::Property::SELECTED:
1353 value = GetImplementation( button ).mSelected;
1357 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1360 Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map );
1365 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1368 Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
1373 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1376 Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
1381 case Toolkit::Button::Property::LABEL_ACTOR:
1384 Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
1394 } // namespace Internal
1396 } // namespace Toolkit