2 * Copyright (c) 2014 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.
20 #include <dali/public-api/common/constants.h>
21 #include <dali/public-api/math/math-utils.h>
22 #include <dali/public-api/object/property-input.h>
23 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
33 Vector3 MoveActorConstraint(const Vector3& current,
34 const PropertyInput& scrollPositionProperty)
36 return current + scrollPositionProperty.GetVector3();
39 Vector3 MoveScaledActorConstraint(const Vector3& current,
40 const PropertyInput& scrollPositionProperty,
41 const PropertyInput& scrollScaleProperty)
43 return scrollScaleProperty.GetVector3() * (current + scrollPositionProperty.GetVector3());
46 Vector3 ScaleActorConstraint(const Vector3& current,
47 const PropertyInput& scrollScaleProperty)
49 return current * scrollScaleProperty.GetVector3();
52 Vector3 WrapActorConstraint(const Vector3& current,
53 const PropertyInput& actorScaleProperty,
54 const PropertyInput& actorAnchorPointProperty,
55 const PropertyInput& actorSizeProperty,
56 const PropertyInput& scrollPositionMin,
57 const PropertyInput& scrollPositionMax,
58 const PropertyInput& scrollWrap)
60 Vector3 position = current;
61 bool wrap = scrollWrap.GetBoolean();
65 const Vector3& min = scrollPositionMin.GetVector3();
66 const Vector3& max = scrollPositionMax.GetVector3();
68 const Vector3& anchor = actorAnchorPointProperty.GetVector3();
69 const Vector3 scale = actorScaleProperty.GetVector3();
70 const Vector3 size = actorSizeProperty.GetVector3();
72 if(fabsf(min.x - max.x) > Math::MACHINE_EPSILON_1)
74 // WRAP X (based on the position of the right side)
75 float offsetX = (1.0f - anchor.x) * size.x * scale.x;
76 position.x = WrapInDomain(position.x + offsetX, min.x, max.x) - offsetX;
79 if(fabsf(min.y - max.y) > Math::MACHINE_EPSILON_1)
81 // WRAP Y (based on the position of the bottom side)
82 float offsetY = (1.0f - anchor.y) * size.y * scale.y;
83 position.y = WrapInDomain(position.y + offsetY, min.y, max.y) - offsetY;
90 } // namespace Toolkit