[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / fade-transition-impl.cpp
1 /*
2  * Copyright (c) 2021 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
18 // CLASS HEADER
19 #include <dali-toolkit/internal/transition/fade-transition-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali/devel-api/actors/actor-devel.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/type-registry.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34
35 FadeTransitionPtr FadeTransition::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
36 {
37   float delaySeconds = timePeriod.delaySeconds;
38   if(delaySeconds < 0.0f)
39   {
40     DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
41     delaySeconds = 0.0f;
42   }
43
44   float durationSeconds = timePeriod.durationSeconds;
45   if(durationSeconds < 0.0f)
46   {
47     DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
48     durationSeconds = 0.0f;
49   }
50
51   FadeTransitionPtr fadeTransition = new FadeTransition(control, Dali::Clamp(opacity, 0.0f, 1.0f), TimePeriod(delaySeconds, durationSeconds));
52
53   // Second-phase construction
54   fadeTransition->Initialize();
55
56   return fadeTransition;
57 }
58
59 FadeTransition::FadeTransition(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
60 : TransitionBase(),
61   mTargetControl(control),
62   mOpacity(opacity)
63 {
64   SetTarget(control);
65   SetTimePeriod(timePeriod);
66 }
67
68 FadeTransition::~FadeTransition()
69 {
70 }
71
72 void FadeTransition::OnPlay()
73 {
74   Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
75   if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
76   {
77     DALI_LOG_ERROR("The Control is not added on the window\n");
78     return;
79   }
80
81   Property::Map startPropertyMap;
82   Property::Map finishPropertyMap;
83
84   float targetOpacity = targetControl[Dali::Actor::Property::OPACITY];
85   if(IsAppearingTransition())
86   {
87     startPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
88     finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
89   }
90   else
91   {
92     startPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
93     finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
94   }
95
96   SetStartPropertyMap(startPropertyMap);
97   SetFinishPropertyMap(finishPropertyMap);
98 }
99
100 } // namespace Internal
101
102 } // namespace Toolkit
103
104 } // namespace Dali