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-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>
36 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
38 } // anonymous namespace
40 FadePtr Fade::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
42 float delaySeconds = timePeriod.delaySeconds;
43 if(delaySeconds < 0.0f)
45 DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
49 float durationSeconds = timePeriod.durationSeconds;
50 if(durationSeconds < 0.0f)
52 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
53 durationSeconds = 0.0f;
56 FadePtr fade = new Fade(control, Dali::Clamp(opacity, 0.0f, 1.0f), TimePeriod(delaySeconds, durationSeconds));
58 // Second-phase construction
64 Fade::Fade(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod)
66 mTargetControl(control),
70 SetTimePeriod(timePeriod);
79 Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
80 if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
82 DALI_LOG_ERROR("The Control is not added on the window\n");
86 Property::Map initialPropertyMap;
87 Property::Map startPropertyMap;
88 Property::Map finishPropertyMap;
90 float targetOpacity = GetWorldColor(targetControl).a;
91 targetControl[Dali::Actor::Property::COLOR_MODE] = Dali::ColorMode::USE_OWN_COLOR;
93 if(IsAppearingTransition())
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);
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);
106 SetInitialPropertyMap(initialPropertyMap);
107 SetStartPropertyMap(startPropertyMap);
108 SetFinishPropertyMap(finishPropertyMap);
111 } // namespace Internal
113 } // namespace Toolkit