2 * Copyright (c) 2022 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/slide-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/devel-api/adaptor-framework/window-devel.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/math-utils.h>
28 #include <dali/public-api/object/type-registry.h>
37 SlideTransitionPtr SlideTransition::New(Dali::Toolkit::Control control, const Vector2& direction, TimePeriod timePeriod)
39 float delaySeconds = timePeriod.delaySeconds;
40 if(delaySeconds < 0.0f)
42 DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
46 float durationSeconds = timePeriod.durationSeconds;
47 if(durationSeconds < 0.0f)
49 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
50 durationSeconds = 0.0f;
53 SlideTransitionPtr slideTransition = new SlideTransition(control, direction, TimePeriod(delaySeconds, durationSeconds));
55 // Second-phase construction
56 slideTransition->Initialize();
58 return slideTransition;
61 SlideTransition::SlideTransition(Dali::Toolkit::Control control, const Vector2& direction, TimePeriod timePeriod)
63 mTargetControl(control),
67 SetTimePeriod(timePeriod);
70 SlideTransition::~SlideTransition()
74 void SlideTransition::SetDirection(const Vector2& direction)
76 mDirection = direction;
77 mDirection.Normalize();
80 Vector2 SlideTransition::GetDirection() const
85 void SlideTransition::OnPlay()
87 Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
88 if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
90 DALI_LOG_ERROR("The Control is not added on the window\n");
94 Property::Map startPropertyMap;
95 Property::Map finishPropertyMap;
97 Vector3 currentPosition = targetControl[Dali::Actor::Property::POSITION];
98 Vector3 currentScale = targetControl[Dali::Actor::Property::SCALE];
100 Vector3 size = targetControl[Dali::Actor::Property::SIZE];
101 size *= currentScale;
103 Vector2 windowSize = DevelWindow::Get(targetControl).GetSize();
104 // This checkPosition go outside of window(by following the direction), this targetControl will be out of window.
105 Vector2 checkPosition = windowSize / 2.0f +
106 Vector2(currentPosition.x + ((mDirection.x < 0.0f) ? size.x / 2.0f : -size.x / 2.0f),
107 currentPosition.y + ((mDirection.y < 0.0f) ? size.y / 2.0f : -size.y / 2.0f));
109 float xScale = (Dali::EqualsZero(mDirection.x)) ? std::numeric_limits<float>::max()
110 : ((mDirection.x < 0.0f) ? checkPosition.x : windowSize.x - checkPosition.x) / std::abs(mDirection.x);
111 float yScale = (Dali::EqualsZero(mDirection.y)) ? std::numeric_limits<float>::max()
112 : ((mDirection.y < 0.0f) ? checkPosition.y : windowSize.y - checkPosition.y) / std::abs(mDirection.y);
114 Vector2 displacement = mDirection * std::min(xScale, yScale);
116 Vector3 startPosition;
117 Vector3 finishPosition;
118 if(IsAppearingTransition())
120 startPosition = currentPosition + Vector3(displacement);
121 finishPosition = currentPosition;
125 startPosition = currentPosition;
126 finishPosition = currentPosition + Vector3(displacement);
129 startPropertyMap.Insert(Dali::Actor::Property::POSITION, startPosition);
130 finishPropertyMap.Insert(Dali::Actor::Property::POSITION, finishPosition);
132 SetStartPropertyMap(startPropertyMap);
133 SetFinishPropertyMap(finishPropertyMap);
136 } // namespace Internal
138 } // namespace Toolkit