50d57a1fad1532255a07c855b33a88931d13eac2
[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 //INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32
33 ScrollViewPagePathEffect::ScrollViewPagePathEffect(Path path, const Vector3& forward, Dali::Property::Index inputPropertyIndex, const Vector3& pageSize, unsigned int pageCount)
34 :mPageSize(pageSize),
35  mInputPropertyIndex(inputPropertyIndex),
36  mPageCount(pageCount)
37 {
38   //Create path constrainer
39   mPathConstrainer = Dali::PathConstrainer::New();
40   mPathConstrainer.SetProperty( PathConstrainer::Property::FORWARD, forward );
41
42   Dali::Property::Value pointsProperty = path.GetProperty(Path::Property::POINTS);
43   Property::Array points;
44   pointsProperty.Get(points);
45   mPathConstrainer.SetProperty( PathConstrainer::Property::POINTS, points );
46
47   pointsProperty = path.GetProperty(Path::Property::CONTROL_POINTS);
48   pointsProperty.Get(points);
49   mPathConstrainer.SetProperty( PathConstrainer::Property::CONTROL_POINTS, points );
50
51   //Create linear constrainer
52   Property::Array pointsLinearConstrainer;
53   pointsProperty = Property::Value(pointsLinearConstrainer);
54   pointsProperty.AppendItem(0.0f);
55   pointsProperty.AppendItem(1.0f);
56   pointsProperty.AppendItem(0.0f);
57   mLinearConstrainer = Dali::LinearConstrainer::New();
58   mLinearConstrainer.SetProperty( LinearConstrainer::Property::VALUE, pointsProperty );
59 }
60
61 ScrollViewPagePathEffect::~ScrollViewPagePathEffect()
62 {
63 }
64
65 void ScrollViewPagePathEffect::ApplyToPage( Actor page, unsigned int pageOrder )
66 {
67   float pageHalfSize = mPageSize.x * 0.5f;
68   Vector2 range = Vector2( pageHalfSize - (pageHalfSize*pageOrder),  -pageHalfSize - (pageHalfSize*pageOrder) );
69   Vector2 wrap  = Vector2( range.x, -pageHalfSize*(mPageCount-2) + range.y);
70
71   Toolkit::ScrollView scrollView = GetScrollView();
72
73   //Position
74   mPathConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::POSITION ),
75                           Dali::Property( scrollView, mInputPropertyIndex),
76                           range, wrap
77                         );
78
79   //Rotation
80   mPathConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::ORIENTATION ),
81                           Dali::Property( scrollView, mInputPropertyIndex ),
82                           range, wrap
83                         );
84
85   //Alpha
86   mLinearConstrainer.Apply( Dali::Property( page, Dali::Actor::Property::COLOR_ALPHA ),
87                             Dali::Property( scrollView, mInputPropertyIndex ),
88                             range, wrap
89                           );
90
91 }
92
93 void ScrollViewPagePathEffect::OnAttach(Toolkit::ScrollView& scrollView)
94 {
95 }
96
97 void ScrollViewPagePathEffect::OnDetach(Toolkit::ScrollView& scrollView)
98 {
99 }
100
101 } // namespace Internal
102
103 } // namespace Toolkit
104
105 } // namespace Dali