2 * Copyright (c) 2021 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.
19 #include <dali-toolkit/internal/transition/fade-transition-impl.h>
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>
35 FadeTransitionPtr FadeTransition::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
37 float delaySeconds = timePeriod.delaySeconds;
38 if(delaySeconds < 0.0f)
40 DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
44 float durationSeconds = timePeriod.durationSeconds;
45 if(durationSeconds < 0.0f)
47 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
48 durationSeconds = 0.0f;
51 FadeTransitionPtr fadeTransition = new FadeTransition(control, Dali::Clamp(opacity, 0.0f, 1.0f), TimePeriod(delaySeconds, durationSeconds));
53 // Second-phase construction
54 fadeTransition->Initialize();
56 return fadeTransition;
59 FadeTransition::FadeTransition(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
61 mTargetControl(control),
65 SetTimePeriod(timePeriod);
68 FadeTransition::~FadeTransition()
72 void FadeTransition::OnPlay()
74 Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
75 if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
77 DALI_LOG_ERROR("The Control is not added on the window\n");
81 Property::Map startPropertyMap;
82 Property::Map finishPropertyMap;
84 float targetOpacity = targetControl[Dali::Actor::Property::OPACITY];
85 if(IsAppearingTransition())
87 startPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
88 finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
92 startPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetOpacity);
93 finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity * targetOpacity);
96 SetStartPropertyMap(startPropertyMap);
97 SetFinishPropertyMap(finishPropertyMap);
100 } // namespace Internal
102 } // namespace Toolkit