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 AddButtonImage( mBackgroundContent );
147 TransitionButtonImage( mDisabledBackgroundContent );
148 AddButtonImage( mUnselectedContent );
149 TransitionButtonImage( mDisabledContent );
152 TransitionOut( mUnselectedContent );
153 TransitionOut( mSelectedContent );
154 TransitionOut( mBackgroundContent );
155 TransitionOut( mSelectedBackgroundContent );
156 TransitionOut( mDisabledSelectedContent );
158 mPaintState = DisabledUnselectedState;
164 //(5) mDisabledSelectedContent (Inserted)
165 //(4) mSelectedContent
166 //(3) mDisabledBackgroundContent (Inserted)
167 //(2) mSelectedBackgroundContent
168 //(1) mBackgroundContent
170 AddButtonImage( mBackgroundContent );
171 AddButtonImage( mSelectedBackgroundContent );
172 TransitionButtonImage( mDisabledBackgroundContent );
173 AddButtonImage( mSelectedContent );
174 TransitionButtonImage( mDisabledSelectedContent );
177 TransitionOut( mUnselectedContent );
178 TransitionOut( mSelectedContent );
179 TransitionOut( mBackgroundContent );
180 TransitionOut( mSelectedBackgroundContent );
181 TransitionOut( mDisabledContent );
183 mPaintState = DisabledSelectedState;
186 case DisabledUnselectedState:
189 //(3) mUnselectedContent (Inserted)
190 //(4) mDisabledContent
191 //(2) mBackgroundContent (Inserted)
192 //(1) mDisabledBackgroundContent
194 AddButtonImage( mDisabledBackgroundContent );
195 TransitionButtonImage( mBackgroundContent );
196 AddButtonImage( mDisabledContent );
197 TransitionButtonImage( mUnselectedContent );
200 TransitionOut( mSelectedContent );
201 TransitionOut( mSelectedBackgroundContent );
202 TransitionOut( mDisabledContent );
203 TransitionOut( mDisabledSelectedContent );
204 TransitionOut( mDisabledBackgroundContent );
206 mPaintState = UnselectedState;
209 case DisabledSelectedState:
212 //(4) mSelectedContent (Inserted)
213 //(5) mDisabledSelectedContent
214 //(3) mSelectedBackgroundContent (Inserted)
215 //(2) mBackgroundContent (Inserted)
216 //(1) mDisabledBackgroundContent
218 AddButtonImage( mDisabledBackgroundContent );
219 TransitionButtonImage( mBackgroundContent );
220 TransitionButtonImage( mSelectedBackgroundContent );
221 AddButtonImage( mDisabledSelectedContent );
222 TransitionButtonImage( mSelectedContent );
225 TransitionOut( mUnselectedContent );
226 TransitionOut( mDisabledContent );
227 TransitionOut( mDisabledSelectedContent );
228 TransitionOut( mDisabledBackgroundContent );
230 mPaintState = SelectedState;
235 StartTransitionAnimation();
238 bool Button::IsDisabled() const
243 void Button::SetAutoRepeating( bool autoRepeating )
245 mAutoRepeating = autoRepeating;
247 // An autorepeating button can't be a togglable button.
250 mTogglableButton = false;
254 // Emit a signal is not wanted, only change the appearance.
255 SetSelected( false, false );
260 bool Button::IsAutoRepeating() const
262 return mAutoRepeating;
265 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
267 DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
268 mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
271 float Button::GetInitialAutoRepeatingDelay() const
273 return mInitialAutoRepeatingDelay;
276 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
278 DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
279 mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
282 float Button::GetNextAutoRepeatingDelay() const
284 return mNextAutoRepeatingDelay;
287 void Button::SetTogglableButton( bool togglable )
289 mTogglableButton = togglable;
291 // A togglable button can't be an autorepeating button.
294 mAutoRepeating = false;
298 bool Button::IsTogglableButton() const
300 return mTogglableButton;
303 void Button::SetSelected( bool selected )
305 if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
307 SetSelected( selected, true );
311 void Button::SetSelected( bool selected, bool emitSignal )
313 StopTransitionAnimation();
315 mSelected = selected;
317 // Notifies the derived class the button has been selected.
320 switch( mPaintState )
322 case UnselectedState:
325 //(3) mSelectedContent (Inserted)
326 //(4) mUnselectedContent
327 //(2) mSelectedBackgroundContent (Inserted)
328 //(1) mBackgroundContent
330 AddButtonImage( mBackgroundContent );
331 TransitionButtonImage( mSelectedBackgroundContent );
332 AddButtonImage( mUnselectedContent );
333 TransitionButtonImage( mSelectedContent );
336 TransitionOut( mUnselectedContent );
337 TransitionOut( mDisabledContent );
338 TransitionOut( mDisabledSelectedContent );
339 TransitionOut( mDisabledBackgroundContent );
341 mPaintState = SelectedState;
347 //(3) mUnselectedContent (Inserted)
348 //(2) mSelectedContent
349 //(1) mBackgroundContent
351 AddButtonImage( mBackgroundContent );
352 AddButtonImage( mSelectedContent );
353 TransitionButtonImage( mUnselectedContent );
356 TransitionOut( mSelectedContent );
357 TransitionOut( mSelectedBackgroundContent );
358 TransitionOut( mDisabledContent );
359 TransitionOut( mDisabledSelectedContent );
360 TransitionOut( mDisabledBackgroundContent );
362 mPaintState = UnselectedState;
365 case DisabledUnselectedState:
366 case DisabledSelectedState:
368 DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
373 StartTransitionAnimation();
377 Toolkit::Button handle( GetOwner() );
380 mStateChangedSignal.Emit( handle );
386 bool Button::IsSelected() const
388 return mTogglableButton && mSelected;
391 void Button::SetAnimationTime( float animationTime )
393 mAnimationTime = animationTime;
396 float Button::GetAnimationTime() const
398 return mAnimationTime;
401 void Button::SetLabel( const std::string& label )
403 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
404 SetLabel( textLabel );
407 void Button::SetLabel( Actor label )
409 if( mLabel != label )
411 if( mLabel && mLabel.GetParent() )
413 mLabel.GetParent().Remove( mLabel );
417 mLabel.SetPosition( 0.f, 0.f );
419 // label should be the top of the button
420 Self().Add( mLabel );
428 Actor Button::GetLabel() const
433 Actor& Button::GetLabel()
438 void Button::SetButtonImage( Actor image )
440 StopTransitionAnimation();
442 if( mUnselectedContent && mUnselectedContent.GetParent() )
444 Self().Remove( mUnselectedContent );
447 mUnselectedContent = image;
448 if( mUnselectedContent )
450 mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
451 mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
452 mUnselectedContent.SetPosition( 0.f, 0.f );
460 Actor Button::GetButtonImage() const
462 return mUnselectedContent;
465 Actor& Button::GetButtonImage()
467 return mUnselectedContent;
470 void Button::SetSelectedImage( Actor image )
472 StopTransitionAnimation();
474 if( mSelectedContent && mSelectedContent.GetParent() )
476 Self().Remove( mSelectedContent );
479 mSelectedContent = image;
480 if( mSelectedContent )
482 mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
483 mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
484 mSelectedContent.SetPosition( 0.f, 0.f );
487 OnSelectedImageSet();
492 Actor Button::GetSelectedImage() const
494 return mSelectedContent;
497 Actor& Button::GetSelectedImage()
499 return mSelectedContent;
502 void Button::SetBackgroundImage( Actor image )
504 StopTransitionAnimation();
506 if( mBackgroundContent && mBackgroundContent.GetParent() )
508 Self().Remove( mBackgroundContent );
511 mBackgroundContent = image;
512 if( mBackgroundContent )
514 mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
515 mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
516 mBackgroundContent.SetPosition( 0.f, 0.f );
519 OnBackgroundImageSet();
524 Actor Button::GetBackgroundImage() const
526 return mBackgroundContent;
529 Actor& Button::GetBackgroundImage()
531 return mBackgroundContent;
534 void Button::SetSelectedBackgroundImage( Actor image )
536 StopTransitionAnimation();
538 if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
540 Self().Remove( mSelectedBackgroundContent );
543 mSelectedBackgroundContent = image;
544 if( mSelectedBackgroundContent )
546 mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
547 mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
548 mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
551 OnSelectedBackgroundImageSet();
556 Actor Button::GetSelectedBackgroundImage() const
558 return mSelectedBackgroundContent;
561 Actor& Button::GetSelectedBackgroundImage()
563 return mSelectedBackgroundContent;
566 void Button::SetDisabledImage( Actor image )
568 StopTransitionAnimation();
570 if( mDisabledContent && mDisabledContent.GetParent() )
572 Self().Remove( mDisabledContent );
575 mDisabledContent = image;
576 if( mDisabledContent )
578 mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
579 mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
580 mDisabledContent.SetPosition( 0.f, 0.f );
584 OnDisabledImageSet();
587 Actor Button::GetDisabledImage() const
589 return mDisabledContent;
592 Actor& Button::GetDisabledImage()
594 return mDisabledContent;
597 void Button::SetDisabledSelectedImage( Actor image )
599 StopTransitionAnimation();
601 if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
603 Self().Remove( mDisabledSelectedContent );
606 mDisabledSelectedContent = image;
607 if( mDisabledSelectedContent )
609 mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
610 mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
611 mDisabledSelectedContent.SetPosition( 0.f, 0.f );
615 OnDisabledSelectedImageSet();
618 Actor Button::GetDisabledSelectedImage() const
620 return mDisabledSelectedContent;
623 Actor& Button::GetDisabledSelectedImage()
625 return mDisabledSelectedContent;
628 void Button::SetDisabledBackgroundImage( Actor image )
630 StopTransitionAnimation();
632 if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
634 Self().Remove( mDisabledBackgroundContent );
637 mDisabledBackgroundContent = image;
638 if( mDisabledBackgroundContent )
640 mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
641 mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
642 mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
645 OnDisabledBackgroundImageSet();
648 Actor Button::GetDisabledBackgroundImage() const
650 return mDisabledBackgroundContent;
653 Actor& Button::GetDisabledBackgroundImage()
655 return mDisabledBackgroundContent;
658 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
662 Dali::BaseHandle handle( object );
664 Toolkit::Button button = Toolkit::Button::DownCast( handle );
666 DALI_ASSERT_ALWAYS( button );
668 if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
670 ret = GetImplementation( button ).DoClickAction( attributes );
676 bool Button::DoClickAction( const Property::Map& attributes )
678 // Prevents the button signals from doing a recursive loop by sending an action
679 // and re-emitting the signals.
680 if( !mClickActionPerforming )
682 mClickActionPerforming = true;
686 mClickActionPerforming = false;
694 void Button::OnButtonStageDisconnection()
696 if( ButtonDown == mState )
698 if( !mTogglableButton )
704 mAutoRepeatingTimer.Reset();
710 void Button::OnButtonDown()
712 if( !mTogglableButton )
718 SetUpTimer( mInitialAutoRepeatingDelay );
722 // The pressed signal should be emitted regardless of toggle mode.
723 Toolkit::Button handle( GetOwner() );
724 mPressedSignal.Emit( handle );
727 void Button::OnButtonUp()
729 if( ButtonDown == mState )
731 if( mTogglableButton )
733 SetSelected( !mSelected );
741 mAutoRepeatingTimer.Reset();
745 // The clicked and released signals should be emitted regardless of toggle mode.
746 Toolkit::Button handle( GetOwner() );
747 mReleasedSignal.Emit( handle );
748 mClickedSignal.Emit( handle );
752 void Button::OnTouchPointLeave()
754 if( ButtonDown == mState )
756 if( !mTogglableButton )
762 mAutoRepeatingTimer.Reset();
766 // The released signal should be emitted regardless of toggle mode.
767 Toolkit::Button handle( GetOwner() );
768 mReleasedSignal.Emit( handle );
772 void Button::OnTouchPointInterrupted()
777 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
779 return mPressedSignal;
782 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
784 return mReleasedSignal;
787 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
789 return mClickedSignal;
792 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
794 return mStateChangedSignal;
797 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
799 Dali::BaseHandle handle( object );
801 bool connected( true );
802 Toolkit::Button button = Toolkit::Button::DownCast( handle );
804 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
806 button.PressedSignal().Connect( tracker, functor );
808 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
810 button.ReleasedSignal().Connect( tracker, functor );
812 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
814 button.ClickedSignal().Connect( tracker, functor );
816 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
818 button.StateChangedSignal().Connect( tracker, functor );
822 // signalName does not match any signal
829 bool Button::OnTouchEvent(const TouchEvent& event)
831 // Only events are processed when the button is not disabled and the touch event has only
833 if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
835 switch( event.GetPoint(0).state )
837 case TouchPoint::Down:
839 OnButtonDown(); // Notification for derived classes.
841 // Sets the button state to ButtonDown.
847 OnButtonUp(); // Notification for derived classes.
849 // Sets the button state to ButtonUp.
853 case TouchPoint::Interrupted:
855 OnTouchPointInterrupted(); // Notification for derived classes.
857 // Sets the button state to the default (ButtonUp).
861 case TouchPoint::Leave:
863 OnTouchPointLeave(); // Notification for derived classes.
865 // Sets the button state to the default (ButtonUp).
869 case TouchPoint::Motion:
870 case TouchPoint::Stationary: // FALLTHROUGH
877 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
882 else if( 1 < event.GetPointCount() )
884 OnTouchPointLeave(); // Notification for derived classes.
886 // Sets the button state to the default (ButtonUp).
893 void Button::OnInitialize()
897 mTapDetector = TapGestureDetector::New();
898 mTapDetector.Attach( self );
899 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
901 OnButtonInitialize();
903 self.SetKeyboardFocusable( true );
906 bool Button::OnAccessibilityActivated()
908 return OnKeyboardEnter();
911 bool Button::OnKeyboardEnter()
913 // When the enter key is pressed, or button is activated, the click action is performed.
914 Property::Map attributes;
915 bool ret = DoClickAction( attributes );
920 void Button::OnControlStageDisconnection()
922 OnButtonStageDisconnection(); // Notification for derived classes.
926 void Button::OnTap(Actor actor, const TapGesture& tap)
931 void Button::SetUpTimer( float delay )
933 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
934 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
935 mAutoRepeatingTimer.Start();
938 bool Button::AutoRepeatingSlot()
940 bool consumed = false;
943 // Restart the autorepeat timer.
944 SetUpTimer( mNextAutoRepeatingDelay );
948 Toolkit::Button handle( GetOwner() );
951 consumed = mReleasedSignal.Emit( handle );
952 consumed |= mClickedSignal.Emit( handle );
953 consumed |= mPressedSignal.Emit( handle );
959 void Button::Pressed()
961 if( mPaintState == UnselectedState )
963 StopTransitionAnimation();
965 // Notifies the derived class the button has been pressed.
969 //(4) mSelectedContent (Inserted)
970 //(3) mUnselectedContent
971 //(2) mSelectedBackgroundContent (Inserted)
972 //(1) mBackgroundContent
974 AddButtonImage( mBackgroundContent );
975 TransitionButtonImage( mSelectedBackgroundContent );
976 AddButtonImage( mUnselectedContent );
977 TransitionButtonImage( mSelectedContent );
980 TransitionOut( mUnselectedContent );
981 TransitionOut( mDisabledContent );
982 TransitionOut( mDisabledSelectedContent );
983 TransitionOut( mDisabledBackgroundContent );
985 mPaintState = SelectedState;
987 StartTransitionAnimation();
991 void Button::Released()
993 if( mPaintState == SelectedState )
995 StopTransitionAnimation();
997 // Notifies the derived class the button has been released.
1001 //(3) mUnselectedContent (Inserted)
1002 //(2) mSelectedContent
1003 //(1) mBackgroundContent
1005 AddButtonImage( mBackgroundContent );
1006 AddButtonImage( mSelectedContent );
1007 TransitionButtonImage( mUnselectedContent );
1010 TransitionOut( mSelectedContent );
1011 TransitionOut( mSelectedBackgroundContent );
1012 TransitionOut( mDisabledContent );
1013 TransitionOut( mDisabledSelectedContent );
1014 TransitionOut( mDisabledBackgroundContent );
1016 mPaintState = UnselectedState;
1018 StartTransitionAnimation();
1022 Button::ButtonState Button::GetState()
1027 Button::PaintState Button::GetPaintState()
1032 void Button::PrepareAddButtonImage( Actor& actor )
1037 Self().Add( actor );
1038 PrepareForTranstionOut( actor );
1042 void Button::TransitionButtonImage( Actor& actor )
1046 if( !actor.GetParent() )
1048 Self().Add( actor );
1051 OnTransitionIn( actor );
1055 void Button::AddButtonImage( Actor& actor )
1059 Self().Add( actor );
1063 void Button::ReAddLabel()
1068 Self().Add( mLabel );
1072 void Button::RemoveButtonImage( Actor& actor )
1076 if( actor.GetParent() )
1078 Self().Remove( actor );
1080 PrepareForTranstionIn( actor );
1084 unsigned int Button::FindChildIndex( Actor& actor )
1086 Actor self = Self();
1087 unsigned int childrenNum = self.GetChildCount();
1089 for( unsigned int i = 0; i < childrenNum; i++ )
1091 Actor child = self.GetChildAt( i );
1092 if( child == actor )
1101 void Button::TransitionOut( Actor actor )
1103 OnTransitionOut( actor );
1106 void Button::ResetImageLayers()
1108 // Ensure that all layers are in the correct order and state according to the paint state
1110 switch( mPaintState )
1112 case UnselectedState:
1115 //(2) mUnselectedContent
1116 //(1) mBackgroundContent
1118 RemoveButtonImage( mSelectedContent );
1119 RemoveButtonImage( mSelectedBackgroundContent );
1120 RemoveButtonImage( mDisabledContent );
1121 RemoveButtonImage( mDisabledSelectedContent );
1122 RemoveButtonImage( mDisabledBackgroundContent );
1124 PrepareAddButtonImage( mBackgroundContent );
1125 PrepareAddButtonImage( mUnselectedContent );
1131 //(3) mSelectedContent
1132 //(2) mSelectedBackgroundContent
1133 //(1) mBackgroundContent
1135 RemoveButtonImage( mUnselectedContent );
1136 RemoveButtonImage( mDisabledContent );
1137 RemoveButtonImage( mDisabledSelectedContent );
1138 RemoveButtonImage( mDisabledBackgroundContent );
1140 PrepareAddButtonImage( mBackgroundContent );
1141 PrepareAddButtonImage( mSelectedBackgroundContent );
1142 PrepareAddButtonImage( mSelectedContent );
1146 case DisabledUnselectedState:
1149 //(2) mDisabledContent
1150 //(1) mDisabledBackgroundContent
1152 RemoveButtonImage( mUnselectedContent );
1153 RemoveButtonImage( mBackgroundContent );
1154 RemoveButtonImage( mSelectedContent );
1155 RemoveButtonImage( mDisabledSelectedContent );
1156 RemoveButtonImage( mSelectedBackgroundContent );
1158 PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
1159 PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
1163 case DisabledSelectedState:
1166 // (2) mDisabledSelectedContent
1167 // (1) mDisabledBackgroundContent
1169 RemoveButtonImage( mUnselectedContent );
1170 RemoveButtonImage( mSelectedContent );
1171 RemoveButtonImage( mBackgroundContent );
1172 RemoveButtonImage( mSelectedBackgroundContent );
1173 RemoveButtonImage( mDisabledContent );
1175 if( mDisabledBackgroundContent )
1177 PrepareAddButtonImage( mDisabledBackgroundContent );
1181 PrepareAddButtonImage( mBackgroundContent );
1182 PrepareAddButtonImage( mSelectedBackgroundContent );
1185 PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
1192 void Button::StartTransitionAnimation()
1194 if( mTransitionAnimation )
1196 mTransitionAnimation.Play();
1204 void Button::StopTransitionAnimation()
1206 if( mTransitionAnimation )
1208 mTransitionAnimation.Clear();
1209 mTransitionAnimation.Reset();
1213 Dali::Animation Button::GetTransitionAnimation()
1215 if( !mTransitionAnimation )
1217 mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
1218 mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
1221 return mTransitionAnimation;
1224 void Button::TransitionAnimationFinished( Dali::Animation& source )
1226 StopTransitionAnimation();
1230 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1232 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1238 case Toolkit::Button::Property::DISABLED:
1240 GetImplementation( button ).SetDisabled( value.Get< bool >() );
1244 case Toolkit::Button::Property::AUTO_REPEATING:
1246 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1250 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1252 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1256 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1258 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1262 case Toolkit::Button::Property::TOGGLABLE:
1264 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1268 case Toolkit::Button::Property::SELECTED:
1270 GetImplementation( button ).SetSelected( value.Get< bool >() );
1274 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1276 GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1280 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1282 GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1286 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1288 GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1292 case Toolkit::Button::Property::LABEL_ACTOR:
1294 GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
1301 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1303 Property::Value value;
1305 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1309 switch ( propertyIndex )
1311 case Toolkit::Button::Property::DISABLED:
1313 value = GetImplementation( button ).mDisabled;
1317 case Toolkit::Button::Property::AUTO_REPEATING:
1319 value = GetImplementation( button ).mAutoRepeating;
1323 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1325 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1329 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1331 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1335 case Toolkit::Button::Property::TOGGLABLE:
1337 value = GetImplementation( button ).mTogglableButton;
1341 case Toolkit::Button::Property::SELECTED:
1343 value = GetImplementation( button ).mSelected;
1347 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1350 Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map );
1355 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1358 Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
1363 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1366 Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
1371 case Toolkit::Button::Property::LABEL_ACTOR:
1374 Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
1384 } // namespace Internal
1386 } // namespace Toolkit