2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali-toolkit/internal/controls/selectors/rotating-selector-impl.h>
20 #include "dali-toolkit/public-api/controls/selectors/rotating-selector.h"
26 const float TOUCH_OPACITY_THRESHOLD = 0.1f;
42 // empty handle, as RotatingSelector takes children during construction
43 return Toolkit::RotatingSelector();
45 TypeRegistration mType( typeid(Toolkit::RotatingSelector), typeid(Toolkit::Control), Create );
47 const Quaternion ROTATION_ANGLE(0.0f, Vector3(1.0f, 0.0f, 0.0f));
50 Dali::Toolkit::RotatingSelector RotatingSelector::New(Actor& unSelectedActor, Actor& selectedActor)
52 // Create the implementation, temporarily owned on stack
53 IntrusivePtr< RotatingSelector > customCheckActor = new RotatingSelector;
55 // Pass ownership to CustomActor
56 Dali::Toolkit::RotatingSelector handle( *customCheckActor );
58 // Second-phase init of the implementation
59 // This can only be done after the CustomActor connection has been made...
60 customCheckActor->Initialize();
62 customCheckActor->SetSelectedActor(selectedActor);
63 customCheckActor->SetUnSelectedActor(unSelectedActor);
68 void RotatingSelector::OnInitialize()
70 mContainer = Actor::New();
71 mContainer.SetName("Selector Container");
72 mUnSelectedActor = Actor::New();
73 mSelectedActor = Actor::New();
75 mRotateAnimation = Animation::New(0.5f);
76 mRotateAnimation.FinishedSignal().Connect(this, &RotatingSelector::AnimationCompleted);
78 mUnSelectedActor.SetParentOrigin(ParentOrigin::CENTER);
79 mUnSelectedActor.SetAnchorPoint(AnchorPoint::CENTER);
81 mSelectedActor.SetParentOrigin(ParentOrigin::CENTER);
82 mSelectedActor.SetAnchorPoint(AnchorPoint::CENTER);
84 mContainer.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
86 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
87 mSelectedActor.ApplyConstraint(constraint);
88 mUnSelectedActor.ApplyConstraint(constraint);
89 mContainer.ApplyConstraint(constraint);
91 mContainer.Add(mUnSelectedActor);
92 mSelectedActor.SetRotation(Radian(Math::PI), Vector3::XAXIS );
94 mUnSelectedActor.SetName("RotatingSelector : UnSelectedActor");
95 mSelectedActor.SetName("RotatingSelector : SelectedActor");
97 Self().Add(mContainer);
98 Self().SetLeaveRequired(true);
100 mRotateAnimation.RotateBy(mContainer, Radian(Math::PI), Vector3(1.0f, 0.0f, 0.0f));
103 RotatingSelector::RotatingSelector()
104 : Control( REQUIRES_TOUCH_EVENTS ),
111 RotatingSelector::~RotatingSelector()
113 mRotateAnimation.Reset();
116 void RotatingSelector::SetSelected( bool toggle )
118 if(toggle != mSelected)
122 ToggleAndAnimateSelection();
127 void RotatingSelector::SetSelectedActor( Actor& selectedActor )
129 unsigned int numChildren = mSelectedActor.GetChildCount();
130 for( unsigned int i=0; i<numChildren; ++i )
132 Actor actor = mSelectedActor.GetChildAt(i);
133 mSelectedActor.Remove(actor);
136 mSelectedActor.Add(selectedActor);
139 Actor RotatingSelector::GetSelectedActor()
141 return mSelectedActor.GetChildAt(0);
144 void RotatingSelector::SetUnSelectedActor( Actor& unSelectedActor )
146 unsigned int numChildren = mUnSelectedActor.GetChildCount();
148 for(unsigned int i=0; i<numChildren; ++i)
150 mUnSelectedActor.Remove(mUnSelectedActor.GetChildAt(0));
153 mUnSelectedActor.Add(unSelectedActor);
156 Actor RotatingSelector::GetUnSelectedActor()
158 return mUnSelectedActor.GetChildAt(0);
161 void RotatingSelector::SetSelectable( bool selectable )
163 mSelectable = selectable;
166 Toolkit::RotatingSelector::SelectedSignalV2& RotatingSelector::SelectedSignal()
168 return mCheckedSignalV2;
171 bool RotatingSelector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
173 Dali::BaseHandle handle( object );
175 bool connected( true );
176 Toolkit::RotatingSelector selector = Toolkit::RotatingSelector::DownCast(handle);
178 if( Toolkit::RotatingSelector::SIGNAL_CHECKED == signalName )
180 selector.SelectedSignal().Connect( tracker, functor );
184 // signalName does not match any signal
191 bool RotatingSelector::OnTouchEvent(const TouchEvent& event)
193 if( 1 == event.GetPointCount() )
195 switch( event.GetPoint(0).state )
197 case TouchPoint::Down:
198 if(Self().GetCurrentOpacity() > TOUCH_OPACITY_THRESHOLD)
203 case TouchPoint::Leave:
208 if(mSelectable && mPressed)
210 ToggleAndAnimateSelection();
220 return false; // dont consume
223 void RotatingSelector::ToggleAndAnimateSelection()
227 mSelected = !mSelected;
230 //The checked image (i.e mSelectedActor should be in front)
231 mSelectedActor.SetPosition(0.0f, 0.0f, -1.0f);
232 mContainer.Add(mSelectedActor);
236 //The un checked image (i.e mUnSelectedActor should be in front)
237 mUnSelectedActor.SetPosition(0.0f, 0.0f, 1.0f);
238 mContainer.Add(mUnSelectedActor);
242 mRotateAnimation.Play();
246 void RotatingSelector::AnimationCompleted( Animation& animation )
250 //The checked image (i.e mSelectedActor should be in front)
251 mSelectedActor.SetPosition(0.0f, 0.0f, 0.0f);
252 mContainer.Remove(mUnSelectedActor);
257 //The un checked image (i.e mUnSelectedActor should be in front)
258 mContainer.Remove(mSelectedActor);
259 mUnSelectedActor.SetPosition(0.0f, 0.0f, 0.0f);
262 mIsAnimating = false;
265 Dali::Toolkit::RotatingSelector handle( GetOwner() );
266 mCheckedSignalV2.Emit( handle, mSelected );
269 } // namespace Internal
271 } // namespace Toolkit