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/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/object/type-registry.h>
36 SlideTransitionPtr SlideTransition::New(Dali::Toolkit::Control control, const Vector2& direction, TimePeriod timePeriod)
38 float delaySeconds = timePeriod.delaySeconds;
39 if(delaySeconds < 0.0f)
41 DALI_LOG_WARNING("delay should be greater than 0.0f.\n");
45 float durationSeconds = timePeriod.durationSeconds;
46 if(durationSeconds < 0.0f)
48 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
49 durationSeconds = 0.0f;
52 SlideTransitionPtr slideTransition = new SlideTransition(control, direction, TimePeriod(delaySeconds, durationSeconds));
54 // Second-phase construction
55 slideTransition->Initialize();
57 return slideTransition;
60 SlideTransition::SlideTransition(Dali::Toolkit::Control control, const Vector2& direction, TimePeriod timePeriod)
62 mTargetControl(control),
66 SetTimePeriod(timePeriod);
69 SlideTransition::~SlideTransition()
73 void SlideTransition::SetDirection(const Vector2& direction)
75 mDirection = direction;
76 mDirection.Normalize();
79 Vector2 SlideTransition::GetDirection() const
84 void SlideTransition::OnPlay()
86 Dali::Toolkit::Control targetControl = mTargetControl.GetHandle();
87 if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE])
89 DALI_LOG_ERROR("The Control is not added on the window\n");
93 Property::Map startPropertyMap;
94 Property::Map finishPropertyMap;
96 Vector3 currentPosition = targetControl[Dali::Actor::Property::POSITION];
97 Vector3 currentScale = targetControl[Dali::Actor::Property::SCALE];
99 Vector3 size = targetControl[Dali::Actor::Property::SIZE];
100 size *= currentScale;
102 Vector2 windowSize = DevelWindow::Get(targetControl).GetSize();
103 // This checkPosition go outside of window(by following the direction), this targetControl will be out of window.
104 Vector2 checkPosition = windowSize / 2.0f +
105 Vector2(currentPosition.x + ((mDirection.x < 0.0f) ? size.x / 2.0f : -size.x / 2.0f),
106 currentPosition.y + ((mDirection.y < 0.0f) ? size.y / 2.0f : -size.y / 2.0f));
108 float xScale = (mDirection.x == 0.0f) ? std::numeric_limits<float>::max()
109 : ((mDirection.x < 0.0f) ? checkPosition.x : windowSize.x - checkPosition.x) / std::abs(mDirection.x);
110 float yScale = (mDirection.y == 0.0f) ? std::numeric_limits<float>::max()
111 : ((mDirection.y < 0.0f) ? checkPosition.y : windowSize.y - checkPosition.y) / std::abs(mDirection.y);
113 Vector2 displacement = mDirection * std::min(xScale, yScale);
115 Vector3 startPosition;
116 Vector3 finishPosition;
117 if(IsAppearingTransition())
119 startPosition = currentPosition + Vector3(displacement);
120 finishPosition = currentPosition;
124 startPosition = currentPosition;
125 finishPosition = currentPosition + Vector3(displacement);
128 startPropertyMap.Insert(Dali::Actor::Property::POSITION, startPosition);
129 finishPropertyMap.Insert(Dali::Actor::Property::POSITION, finishPosition);
131 SetStartPropertyMap(startPropertyMap);
132 SetFinishPropertyMap(finishPropertyMap);
135 } // namespace Internal
137 } // namespace Toolkit