Merge "(Vector) Replace std::chrono::system_clock with chrono::steady_clock" into...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / fade-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-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 namespace
35 {
36 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
37
38 } // anonymous namespace
39
40 FadePtr Fade::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
41 {
42   float delaySeconds = timePeriod.delaySeconds;
43   if(delaySeconds < 0.0f)
44   {
45     DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
46     delaySeconds = 0.0f;
47   }
48
49   float durationSeconds = timePeriod.durationSeconds;
50   if(durationSeconds < 0.0f)
51   {
52     DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
53     durationSeconds = 0.0f;
54   }
55
56   FadePtr fade = new Fade(control, Dali::Clamp(opacity, 0.0f, 1.0f), TimePeriod(delaySeconds, durationSeconds));
57
58   // Second-phase construction
59   fade->Initialize();
60
61   return fade;
62 }
63
64 Fade::Fade(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
65 : TransitionBase(),
66   mTargetControl(control),
67   mOpacity(opacity)
68 {
69   SetTarget(control);
70   SetTimePeriod(timePeriod);
71 }
72
73 Fade::~Fade()
74 {
75 }
76
77 void Fade::OnPlay()
78 {
79   Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
80   if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
81   {
82     DALI_LOG_ERROR("The Control is not added on the window\n");
83     return;
84   }
85
86   Property::Map initialPropertyMap;
87   Property::Map startPropertyMap;
88   Property::Map finishPropertyMap;
89
90   float targetOpacity                              = GetWorldColor(targetControl).a;
91   targetControl[Dali::Actor::Property::COLOR_MODE] = Dali::ColorMode::USE_OWN_COLOR;
92
93   if(IsAppearingTransition())
94   {
95     initialPropertyMap.Insert(Dali::Actor::Property::OPACITY, 0.0f);
96     startPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
97     finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
98   }
99   else
100   {
101     initialPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
102     startPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
103     finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
104   }
105
106   SetInitialPropertyMap(initialPropertyMap);
107   SetStartPropertyMap(startPropertyMap);
108   SetFinishPropertyMap(finishPropertyMap);
109 }
110
111 } // namespace Internal
112
113 } // namespace Toolkit
114
115 } // namespace Dali