[dali_1.1.32] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-button.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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>
21
22 using namespace Dali;
23 using namespace Dali::Toolkit;
24
25 namespace
26 {
27 Property::Value ConvertAnimationMap( const Test::TestAnimationData& animationMap )
28 {
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 )
32   {
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 );
41   }
42   Property::Value animation( animators );
43   return animation;
44 }
45 }
46
47 namespace Test
48 {
49 namespace Impl
50 {
51
52 Test::TestButton TestButton::New()
53 {
54   IntrusivePtr<TestButton> internalTestButton = new TestButton();
55   Test::TestButton button( *internalTestButton );
56   internalTestButton->Initialize();
57   return button;
58 }
59
60 TestButton::TestButton()
61 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS|REQUIRES_STYLE_CHANGE_SIGNALS ) )
62 {
63 }
64
65 TestButton::~TestButton()
66 {
67 }
68
69 void TestButton::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
70 {
71   Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
72
73   if ( button )
74   {
75     TestButton& buttonImpl = GetImpl(button);
76     switch ( index )
77     {
78       case Test::TestButton::Property::PRESS_TRANSITION:
79       {
80         if( value.GetType() == Property::MAP )
81         {
82           Property::Map* valueMap = value.GetMap();
83           buttonImpl.mPressTransitionData.Clear();
84           NewAnimation( *valueMap, buttonImpl.mPressTransitionData );
85         }
86         else if( value.GetType() == Property::ARRAY )
87         {
88           Property::Array* valueArray = value.GetArray();
89           buttonImpl.mPressTransitionData.Clear();
90           NewAnimation( *valueArray, buttonImpl.mPressTransitionData );
91         }
92         break;
93       }
94       case Test::TestButton::Property::BACKGROUND_COLOR:
95       {
96         buttonImpl.mBackgroundColor = value.Get<Vector4>();
97         break;
98       }
99
100       case Test::TestButton::Property::FOREGROUND_COLOR:
101       {
102         buttonImpl.mForegroundColor = value.Get<Vector4>();
103         break;
104       }
105     }
106   }
107 }
108
109 Property::Value TestButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
110 {
111   Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
112
113   Property::Value value;
114
115   if ( button )
116   {
117     TestButton& buttonImpl = GetImpl(button);
118     switch ( propertyIndex )
119     {
120       case Test::TestButton::Property::PRESS_TRANSITION:
121       {
122         return ConvertAnimationMap(buttonImpl.mPressTransitionData);
123       }
124       case Test::TestButton::Property::RELEASE_TRANSITION:
125       {
126         return ConvertAnimationMap(buttonImpl.mReleaseTransitionData);
127       }
128       case Test::TestButton::Property::DISABLED_TRANSITION:
129       {
130         return ConvertAnimationMap(buttonImpl.mDisabledTransitionData);
131       }
132       case Test::TestButton::Property::ENABLED_TRANSITION:
133       {
134         return ConvertAnimationMap(buttonImpl.mEnabledTransitionData);
135       }
136       case Test::TestButton::Property::BACKGROUND_COLOR:
137       {
138         return Property::Value(buttonImpl.mBackgroundColor);
139       }
140       case Test::TestButton::Property::FOREGROUND_COLOR:
141       {
142         return Property::Value(buttonImpl.mForegroundColor);
143       }
144     }
145   }
146   return Property::Value();
147 }
148
149 BaseHandle Create()
150 {
151   return TestButton::New();
152 }
153
154 // Generates typeRegistration static variable.
155 DALI_TYPE_REGISTRATION_BEGIN( Test::TestButton, Dali::Toolkit::Control, Create )
156
157 DALI_PROPERTY_REGISTRATION( Test, TestButton, "pressTransition", ARRAY, PRESS_TRANSITION )
158 DALI_PROPERTY_REGISTRATION( Test, TestButton, "releaseTransition", ARRAY, RELEASE_TRANSITION)
159 DALI_PROPERTY_REGISTRATION( Test, TestButton, "disabledTransition", ARRAY, DISABLED_TRANSITION )
160 DALI_PROPERTY_REGISTRATION( Test, TestButton, "enabledTransition", ARRAY, ENABLED_TRANSITION )
161 DALI_PROPERTY_REGISTRATION( Test, TestButton, "backgroundColor", VECTOR4, BACKGROUND_COLOR )
162 DALI_PROPERTY_REGISTRATION( Test, TestButton, "foregroundColor", VECTOR4, FOREGROUND_COLOR )
163
164 DALI_TYPE_REGISTRATION_END()
165
166 } // Impl Namespace
167
168 TestButton::TestButton()
169 : Control()
170 {
171 }
172
173 TestButton::TestButton(const TestButton& button)
174 : Control( button )
175 {
176 }
177
178 TestButton::TestButton(Impl::TestButton& impl)
179 : Control(impl)
180 {
181 }
182
183 TestButton::TestButton(Dali::Internal::CustomActor* internal)
184 : Control(internal)
185 {
186   VerifyCustomActorPointer<Impl::TestButton>(internal);
187 }
188
189 TestButton& TestButton::operator=( const TestButton& button)
190 {
191   if(&button != this)
192   {
193     Control::operator=(button);
194   }
195   return *this;
196 }
197
198 TestButton::~TestButton()
199 {
200 }
201
202 TestButton TestButton::New()
203 {
204   return Impl::TestButton::New();
205 }
206
207 TestButton TestButton::DownCast( BaseHandle handle )
208 {
209   return Control::DownCast<TestButton,Impl::TestButton>(handle);
210 }
211
212 } // namespace Test