ac29e53578c4190cbac1f03e9e44a715e99f66ae
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / scrollable / scroll-view / scroll-view-constraints.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // INTERNAL INCLUDES
18
19 #include <dali/public-api/common/constants.h>
20 #include <dali/public-api/math/math-utils.h>
21 #include <dali/public-api/object/property-input.h>
22 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
23
24 using namespace Dali;
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 Vector3 MoveActorConstraint(const Vector3&    current,
33                             const PropertyInput& scrollPositionProperty)
34 {
35   return current + scrollPositionProperty.GetVector3();
36 }
37
38 Vector3 MoveScaledActorConstraint(const Vector3&    current,
39                                   const PropertyInput& scrollPositionProperty,
40                                   const PropertyInput& scrollScaleProperty)
41 {
42   return scrollScaleProperty.GetVector3() * (current + scrollPositionProperty.GetVector3());
43 }
44
45 Vector3 ScaleActorConstraint(const Vector3&    current,
46                              const PropertyInput& scrollScaleProperty)
47 {
48  return current * scrollScaleProperty.GetVector3();
49 }
50
51 Vector3 WrapActorConstraint(const Vector3&    current,
52                             const PropertyInput& actorScaleProperty,
53                             const PropertyInput& actorAnchorPointProperty,
54                             const PropertyInput& actorSizeProperty,
55                             const PropertyInput& scrollPositionMin,
56                             const PropertyInput& scrollPositionMax,
57                             const PropertyInput& scrollWrap)
58 {
59   Vector3 position = current;
60   bool wrap = scrollWrap.GetBoolean();
61
62   if(wrap)
63   {
64     const Vector3& min = scrollPositionMin.GetVector3();
65     const Vector3& max = scrollPositionMax.GetVector3();
66
67     const Vector3& anchor = actorAnchorPointProperty.GetVector3();
68     const Vector3 scale = actorScaleProperty.GetVector3();
69     const Vector3 size = actorSizeProperty.GetVector3();
70
71     if(fabsf(min.x - max.x) > Math::MACHINE_EPSILON_1)
72     {
73       // WRAP X (based on the position of the right side)
74       float offsetX = (1.0f - anchor.x) * size.x * scale.x;
75       position.x = WrapInDomain(position.x + offsetX, min.x, max.x) - offsetX;
76     }
77
78     if(fabsf(min.y - max.y) > Math::MACHINE_EPSILON_1)
79     {
80       // WRAP Y (based on the position of the bottom side)
81       float offsetY = (1.0f - anchor.y) * size.y * scale.y;
82       position.y = WrapInDomain(position.y + offsetY, min.y, max.y) - offsetY;
83     }
84   }
85
86   return position;
87 }
88
89 } // namespace Toolkit
90
91 } // namespace Dali
92