89268b3caeddce82c5697b3b2a07bf31df2543b7
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-page-path-effect-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-page-path-effect-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/property-array.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 ScrollViewPagePathEffect::ScrollViewPagePathEffect(Path path, const Vector3& forward, Dali::Property::Index inputPropertyIndex, const Vector3& pageSize, unsigned int pageCount)
37 :mPageSize(pageSize),
38  mInputPropertyIndex(inputPropertyIndex),
39  mPageCount(pageCount)
40 {
41   //Create path constrainer
42   mPathConstrainer = Dali::PathConstrainer::New();
43   mPathConstrainer.SetProperty( PathConstrainer::Property::FORWARD, forward );
44
45   Dali::Property::Value pointsProperty = path.GetProperty(Path::Property::POINTS);
46   mPathConstrainer.SetProperty( PathConstrainer::Property::POINTS, pointsProperty );
47
48   pointsProperty = path.GetProperty(Path::Property::CONTROL_POINTS);
49   mPathConstrainer.SetProperty( PathConstrainer::Property::CONTROL_POINTS, pointsProperty );
50
51   //Create linear constrainer
52   pointsProperty = Property::Value(Property::ARRAY);
53   Property::Array* array = pointsProperty.GetArray();
54
55   if( array )
56   {
57     array->PushBack(0.0f);
58     array->PushBack(1.0f);
59     array->PushBack(0.0f);
60   }
61   mLinearConstrainer = Dali::LinearConstrainer::New();
62   mLinearConstrainer.SetProperty( LinearConstrainer::Property::VALUE, pointsProperty );
63 }
64
65 ScrollViewPagePathEffect::~ScrollViewPagePathEffect()
66 {
67 }
68
69 void ScrollViewPagePathEffect::ApplyToPage( Actor page, unsigned int pageOrder )
70 {
71   float pageHalfSize = mPageSize.x * 0.5f;
72   Vector2 range = Vector2( pageHalfSize - (pageHalfSize*pageOrder),  -pageHalfSize - (pageHalfSize*pageOrder) );
73   Vector2 wrap  = Vector2( range.x, -pageHalfSize*(mPageCount-2) + range.y);
74
75   Toolkit::ScrollView scrollView = GetScrollView();
76
77   //Position
78   mPathConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::POSITION ),
79                           Dali::Property( scrollView, mInputPropertyIndex),
80                           range, wrap
81                         );
82
83   //Rotation
84   mPathConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::ORIENTATION ),
85                           Dali::Property( scrollView, mInputPropertyIndex ),
86                           range, wrap
87                         );
88
89   //Alpha
90   mLinearConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::COLOR_ALPHA ),
91                             Dali::Property( scrollView, mInputPropertyIndex ),
92                             range, wrap
93                           );
94
95 }
96
97 void ScrollViewPagePathEffect::OnAttach(Toolkit::ScrollView& scrollView)
98 {
99 }
100
101 void ScrollViewPagePathEffect::OnDetach(Toolkit::ScrollView& scrollView)
102 {
103 }
104
105 } // namespace Internal
106
107 } // namespace Toolkit
108
109 } // namespace Dali