2 * Copyright (c) 2016 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.
17 #include <dali/dali.h>
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <test-button.h>
20 #include <dali/devel-api/object/type-registry-helper.h>
23 using namespace Dali::Toolkit;
27 Property::Value ConvertAnimationMap( const Test::TestAnimationData& animationMap )
29 // We have a data structure. Now convert it back into an array:
30 Property::Array animators;
31 for( unsigned int i=0; i<animationMap.Size(); ++i )
33 Property::Map animator;
34 animator.Insert( "target", Property::Value(animationMap.mAnimationDataList[i]->target ));
35 animator.Insert( "property", Property::Value(animationMap.mAnimationDataList[i]->property ));
36 animator.Insert( "value", Property::Value(animationMap.mAnimationDataList[i]->value ));
37 animator.Insert( "alphaFunction", Property::Value(animationMap.mAnimationDataList[i]->alphaFunction ));
38 animator.Insert( "timePeriodDelay", Property::Value(animationMap.mAnimationDataList[i]->timePeriodDelay ));
39 animator.Insert( "timePeriodDuration", Property::Value(animationMap.mAnimationDataList[i]->timePeriodDuration ));
40 animators.PushBack( animator );
42 Property::Value animation( animators );
52 Test::TestButton TestButton::New()
54 IntrusivePtr<TestButton> internalTestButton = new TestButton();
55 Test::TestButton button( *internalTestButton );
56 internalTestButton->Initialize();
60 TestButton::TestButton()
61 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS|REQUIRES_STYLE_CHANGE_SIGNALS ) )
65 TestButton::~TestButton()
69 void TestButton::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
71 Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
77 case Test::TestButton::Property::PRESS_TRANSITION:
79 if( value.GetType() == Property::MAP )
81 Property::Map* valueMap = value.GetMap();
82 TestButton& buttonImpl = GetImpl(button);
83 buttonImpl.mPressTransitionData.Clear();
84 NewAnimation( *valueMap, buttonImpl.mPressTransitionData );
86 else if( value.GetType() == Property::ARRAY )
88 Property::Array* valueArray = value.GetArray();
89 TestButton& buttonImpl = GetImpl(button);
90 buttonImpl.mPressTransitionData.Clear();
91 NewAnimation( *valueArray, buttonImpl.mPressTransitionData );
99 Property::Value TestButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
101 Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
105 TestButton& buttonImpl = GetImpl(button);
106 switch ( propertyIndex )
108 case Test::TestButton::Property::PRESS_TRANSITION:
110 return ConvertAnimationMap(buttonImpl.mPressTransitionData);
113 case Test::TestButton::Property::RELEASE_TRANSITION:
115 return ConvertAnimationMap(buttonImpl.mReleaseTransitionData);
118 case Test::TestButton::Property::DISABLED_TRANSITION:
120 return ConvertAnimationMap(buttonImpl.mDisabledTransitionData);
123 case Test::TestButton::Property::ENABLED_TRANSITION:
125 return ConvertAnimationMap(buttonImpl.mEnabledTransitionData);
130 return Property::Value();
135 return TestButton::New();
138 // Generates typeRegistration static variable.
139 DALI_TYPE_REGISTRATION_BEGIN( Test::TestButton, Dali::Toolkit::Control, Create )
141 DALI_PROPERTY_REGISTRATION( Test, TestButton, "pressTransition", ARRAY, PRESS_TRANSITION )
142 DALI_PROPERTY_REGISTRATION( Test, TestButton, "releaseTransition", ARRAY, RELEASE_TRANSITION)
143 DALI_PROPERTY_REGISTRATION( Test, TestButton, "disabledTransition", ARRAY, DISABLED_TRANSITION )
144 DALI_PROPERTY_REGISTRATION( Test, TestButton, "enabledTransition", ARRAY, ENABLED_TRANSITION )
146 DALI_TYPE_REGISTRATION_END()
150 TestButton::TestButton()
155 TestButton::TestButton(const TestButton& button)
160 TestButton::TestButton(Impl::TestButton& impl)
165 TestButton::TestButton(Dali::Internal::CustomActor* internal)
168 VerifyCustomActorPointer<Impl::TestButton>(internal);
171 TestButton& TestButton::operator=( const TestButton& button)
175 Control::operator=(button);
180 TestButton::~TestButton()
184 TestButton TestButton::New()
186 return Impl::TestButton::New();
189 TestButton TestButton::DownCast( BaseHandle handle )
191 return Control::DownCast<TestButton,Impl::TestButton>(handle);