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 <dali-toolkit/internal/controls/selectors/rotating-selector-impl.h>
21 #include "dali-toolkit/public-api/controls/selectors/rotating-selector.h"
27 const float TOUCH_OPACITY_THRESHOLD = 0.1f;
43 // empty handle, as RotatingSelector takes children during construction
44 return Toolkit::RotatingSelector();
46 TypeRegistration mType( typeid(Toolkit::RotatingSelector), typeid(Toolkit::Control), Create );
48 const Quaternion ROTATION_ANGLE(0.0f, Vector3(1.0f, 0.0f, 0.0f));
51 Dali::Toolkit::RotatingSelector RotatingSelector::New(Actor& unSelectedActor, Actor& selectedActor)
53 // Create the implementation, temporarily owned on stack
54 IntrusivePtr< RotatingSelector > customCheckActor = new RotatingSelector;
56 // Pass ownership to CustomActor
57 Dali::Toolkit::RotatingSelector handle( *customCheckActor );
59 // Second-phase init of the implementation
60 // This can only be done after the CustomActor connection has been made...
61 customCheckActor->Initialize();
63 customCheckActor->SetSelectedActor(selectedActor);
64 customCheckActor->SetUnSelectedActor(unSelectedActor);
69 void RotatingSelector::OnInitialize()
71 mContainer = Actor::New();
72 mContainer.SetName("Selector Container");
73 mUnSelectedActor = Actor::New();
74 mSelectedActor = Actor::New();
76 mRotateAnimation = Animation::New(0.5f);
77 mRotateAnimation.FinishedSignal().Connect(this, &RotatingSelector::AnimationCompleted);
79 mUnSelectedActor.SetParentOrigin(ParentOrigin::CENTER);
80 mUnSelectedActor.SetAnchorPoint(AnchorPoint::CENTER);
82 mSelectedActor.SetParentOrigin(ParentOrigin::CENTER);
83 mSelectedActor.SetAnchorPoint(AnchorPoint::CENTER);
85 mContainer.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
87 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
88 mSelectedActor.ApplyConstraint(constraint);
89 mUnSelectedActor.ApplyConstraint(constraint);
90 mContainer.ApplyConstraint(constraint);
92 mContainer.Add(mUnSelectedActor);
93 mSelectedActor.SetRotation(Radian(Math::PI), Vector3::XAXIS );
95 mUnSelectedActor.SetName("RotatingSelector : UnSelectedActor");
96 mSelectedActor.SetName("RotatingSelector : SelectedActor");
98 Self().Add(mContainer);
99 Self().SetLeaveRequired(true);
101 mRotateAnimation.RotateBy(mContainer, Radian(Math::PI), Vector3(1.0f, 0.0f, 0.0f));
104 RotatingSelector::RotatingSelector()
105 : Control( REQUIRES_TOUCH_EVENTS ),
112 RotatingSelector::~RotatingSelector()
114 mRotateAnimation.Reset();
117 void RotatingSelector::SetSelected( bool toggle )
119 if(toggle != mSelected)
123 ToggleAndAnimateSelection();
128 void RotatingSelector::SetSelectedActor( Actor& selectedActor )
130 unsigned int numChildren = mSelectedActor.GetChildCount();
131 for( unsigned int i=0; i<numChildren; ++i )
133 Actor actor = mSelectedActor.GetChildAt(i);
134 mSelectedActor.Remove(actor);
137 mSelectedActor.Add(selectedActor);
140 Actor RotatingSelector::GetSelectedActor()
142 return mSelectedActor.GetChildAt(0);
145 void RotatingSelector::SetUnSelectedActor( Actor& unSelectedActor )
147 unsigned int numChildren = mUnSelectedActor.GetChildCount();
149 for(unsigned int i=0; i<numChildren; ++i)
151 mUnSelectedActor.Remove(mUnSelectedActor.GetChildAt(0));
154 mUnSelectedActor.Add(unSelectedActor);
157 Actor RotatingSelector::GetUnSelectedActor()
159 return mUnSelectedActor.GetChildAt(0);
162 void RotatingSelector::SetSelectable( bool selectable )
164 mSelectable = selectable;
167 Toolkit::RotatingSelector::SelectedSignalV2& RotatingSelector::SelectedSignal()
169 return mCheckedSignalV2;
172 bool RotatingSelector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
174 Dali::BaseHandle handle( object );
176 bool connected( true );
177 Toolkit::RotatingSelector selector = Toolkit::RotatingSelector::DownCast(handle);
179 if( Toolkit::RotatingSelector::SIGNAL_CHECKED == signalName )
181 selector.SelectedSignal().Connect( tracker, functor );
185 // signalName does not match any signal
192 bool RotatingSelector::OnTouchEvent(const TouchEvent& event)
194 if( 1 == event.GetPointCount() )
196 switch( event.GetPoint(0).state )
198 case TouchPoint::Down:
199 if(Self().GetCurrentOpacity() > TOUCH_OPACITY_THRESHOLD)
204 case TouchPoint::Leave:
209 if(mSelectable && mPressed)
211 ToggleAndAnimateSelection();
221 return false; // dont consume
224 void RotatingSelector::ToggleAndAnimateSelection()
228 mSelected = !mSelected;
231 //The checked image (i.e mSelectedActor should be in front)
232 mSelectedActor.SetPosition(0.0f, 0.0f, -1.0f);
233 mContainer.Add(mSelectedActor);
237 //The un checked image (i.e mUnSelectedActor should be in front)
238 mUnSelectedActor.SetPosition(0.0f, 0.0f, 1.0f);
239 mContainer.Add(mUnSelectedActor);
243 mRotateAnimation.Play();
247 void RotatingSelector::AnimationCompleted( Animation& animation )
251 //The checked image (i.e mSelectedActor should be in front)
252 mSelectedActor.SetPosition(0.0f, 0.0f, 0.0f);
253 mContainer.Remove(mUnSelectedActor);
258 //The un checked image (i.e mUnSelectedActor should be in front)
259 mContainer.Remove(mSelectedActor);
260 mUnSelectedActor.SetPosition(0.0f, 0.0f, 0.0f);
263 mIsAnimating = false;
266 Dali::Toolkit::RotatingSelector handle( GetOwner() );
267 mCheckedSignalV2.Emit( handle, mSelected );
270 } // namespace Internal
272 } // namespace Toolkit