Revert "Remove dali-core dependency of GLES version."
[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
21 using namespace Dali;
22 using namespace Dali::Toolkit;
23
24 namespace
25 {
26 Property::Value ConvertAnimationMap( const Test::TestAnimationData& animationMap )
27 {
28   // We have a data structure. Now convert it back into an array:
29   Property::Array animators;
30   for( unsigned int i=0; i<animationMap.Size(); ++i )
31   {
32     Property::Map animator;
33     animator.Insert( "target", Property::Value(animationMap.mAnimationDataList[i]->target ));
34     animator.Insert( "property", Property::Value(animationMap.mAnimationDataList[i]->property ));
35     animator.Insert( "value", Property::Value(animationMap.mAnimationDataList[i]->value ));
36     animator.Insert( "alphaFunction", Property::Value(animationMap.mAnimationDataList[i]->alphaFunction ));
37     animator.Insert( "timePeriodDelay", Property::Value(animationMap.mAnimationDataList[i]->timePeriodDelay ));
38     animator.Insert( "timePeriodDuration", Property::Value(animationMap.mAnimationDataList[i]->timePeriodDuration ));
39     animators.PushBack( animator );
40   }
41   Property::Value animation( animators );
42   return animation;
43 }
44 }
45
46 namespace Test
47 {
48 namespace Impl
49 {
50
51 Test::TestButton TestButton::New()
52 {
53   IntrusivePtr<TestButton> internalTestButton = new TestButton();
54   Test::TestButton button( *internalTestButton );
55   internalTestButton->Initialize();
56   return button;
57 }
58
59 TestButton::TestButton()
60 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS|REQUIRES_STYLE_CHANGE_SIGNALS ) )
61 {
62 }
63
64 TestButton::~TestButton()
65 {
66 }
67
68 void TestButton::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
69 {
70   Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
71
72   if ( button )
73   {
74     TestButton& buttonImpl = GetImpl(button);
75     switch ( index )
76     {
77       case Test::TestButton::Property::PRESS_TRANSITION:
78       {
79         if( value.GetType() == Property::MAP )
80         {
81           Property::Map* valueMap = value.GetMap();
82           buttonImpl.mPressTransitionData.Clear();
83           NewAnimation( *valueMap, buttonImpl.mPressTransitionData );
84         }
85         else if( value.GetType() == Property::ARRAY )
86         {
87           Property::Array* valueArray = value.GetArray();
88           buttonImpl.mPressTransitionData.Clear();
89           NewAnimation( *valueArray, buttonImpl.mPressTransitionData );
90         }
91         break;
92       }
93       case Test::TestButton::Property::BACKGROUND_COLOR:
94       {
95         buttonImpl.mBackgroundColor = value.Get<Vector4>();
96         break;
97       }
98
99       case Test::TestButton::Property::FOREGROUND_COLOR:
100       {
101         buttonImpl.mForegroundColor = value.Get<Vector4>();
102         break;
103       }
104     }
105   }
106 }
107
108 Property::Value TestButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
109 {
110   Test::TestButton button = Test::TestButton::DownCast( Dali::BaseHandle( object ) );
111
112   Property::Value value;
113
114   if ( button )
115   {
116     TestButton& buttonImpl = GetImpl(button);
117     switch ( propertyIndex )
118     {
119       case Test::TestButton::Property::PRESS_TRANSITION:
120       {
121         return ConvertAnimationMap(buttonImpl.mPressTransitionData);
122       }
123       case Test::TestButton::Property::RELEASE_TRANSITION:
124       {
125         return ConvertAnimationMap(buttonImpl.mReleaseTransitionData);
126       }
127       case Test::TestButton::Property::DISABLED_TRANSITION:
128       {
129         return ConvertAnimationMap(buttonImpl.mDisabledTransitionData);
130       }
131       case Test::TestButton::Property::ENABLED_TRANSITION:
132       {
133         return ConvertAnimationMap(buttonImpl.mEnabledTransitionData);
134       }
135       case Test::TestButton::Property::BACKGROUND_COLOR:
136       {
137         return Property::Value(buttonImpl.mBackgroundColor);
138       }
139       case Test::TestButton::Property::FOREGROUND_COLOR:
140       {
141         return Property::Value(buttonImpl.mForegroundColor);
142       }
143     }
144   }
145   return Property::Value();
146 }
147
148 BaseHandle Create()
149 {
150   return TestButton::New();
151 }
152
153 // Generates typeRegistration static variable.
154 DALI_TYPE_REGISTRATION_BEGIN( Test::TestButton, Dali::Toolkit::Control, Create )
155
156 DALI_PROPERTY_REGISTRATION( Test, TestButton, "pressTransition", ARRAY, PRESS_TRANSITION )
157 DALI_PROPERTY_REGISTRATION( Test, TestButton, "releaseTransition", ARRAY, RELEASE_TRANSITION)
158 DALI_PROPERTY_REGISTRATION( Test, TestButton, "disabledTransition", ARRAY, DISABLED_TRANSITION )
159 DALI_PROPERTY_REGISTRATION( Test, TestButton, "enabledTransition", ARRAY, ENABLED_TRANSITION )
160 DALI_PROPERTY_REGISTRATION( Test, TestButton, "backgroundColor", VECTOR4, BACKGROUND_COLOR )
161 DALI_PROPERTY_REGISTRATION( Test, TestButton, "foregroundColor", VECTOR4, FOREGROUND_COLOR )
162
163 DALI_TYPE_REGISTRATION_END()
164
165 } // Impl Namespace
166
167 TestButton::TestButton()
168 : Control()
169 {
170 }
171
172 TestButton::TestButton(const TestButton& button)
173 : Control( button )
174 {
175 }
176
177 TestButton::TestButton(Impl::TestButton& impl)
178 : Control(impl)
179 {
180 }
181
182 TestButton::TestButton(Dali::Internal::CustomActor* internal)
183 : Control(internal)
184 {
185   VerifyCustomActorPointer<Impl::TestButton>(internal);
186 }
187
188 TestButton& TestButton::operator=( const TestButton& button)
189 {
190   if(&button != this)
191   {
192     Control::operator=(button);
193   }
194   return *this;
195 }
196
197 TestButton::~TestButton()
198 {
199 }
200
201 TestButton TestButton::New()
202 {
203   return Impl::TestButton::New();
204 }
205
206 TestButton TestButton::DownCast( BaseHandle handle )
207 {
208   return Control::DownCast<TestButton,Impl::TestButton>(handle);
209 }
210
211 } // namespace Test