Merge "Remove obsolete and non functional SizeChanged signal from actor" into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / shader-effects / carousel-effect.cpp
1 /*
2  * Copyright (c) 2014 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 #include <dali-toolkit/public-api/shader-effects/carousel-effect.h>
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace
27 {
28
29 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
30 const std::string ANGLE_PER_UNIT_PROPERTY_NAME( "uAnglePerUnit" );
31 const std::string CENTER_PROPERTY_NAME( "uCenter" );
32
33 } // namespace
34
35 CarouselEffect::CarouselEffect()
36 {
37 }
38
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 CarouselEffect::CarouselEffect(ShaderEffect handle)
41 :ShaderEffect(handle)
42 {
43 }
44
45 CarouselEffect::~CarouselEffect()
46 {
47 }
48
49
50 CarouselEffect CarouselEffect::New()
51 {
52   // append the default version
53   std::string vertexShader(
54               "uniform float uRadius;\n"
55               "uniform mediump vec2 uCenter;\n"
56               "uniform mediump vec2 uAnglePerUnit;\n"
57               "\n"
58               "void main()\n"
59               "{\n"
60               "    mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
61               "    mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
62               "    mediump float a = length(d);\n"
63               "    mediump float cs = cos(radians(a));\n"
64               "    world.z -= cs * uRadius;\n"
65               "    gl_Position = uProjection * world;\n"
66               "    \n"
67               "    vTexCoord = aTexCoord;\n"
68               "}\n");
69
70   ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader,
71           "",
72           GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
73           ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
74
75   // Pass ownership to CarouselEffect through overloaded constructor, So that it now has access to the
76   // Dali::ShaderEffect implementation
77   CarouselEffect handle( shaderEffectCustom );
78
79   handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
80   handle.SetUniform( CENTER_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
81   handle.SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
82
83   return handle;
84 }
85
86 void CarouselEffect::SetRadius( float radius)
87 {
88   SetUniform( RADIUS_PROPERTY_NAME, radius );
89 }
90
91 void CarouselEffect::SetCenter( const Vector2& center )
92 {
93   SetUniform( CENTER_PROPERTY_NAME, center );
94 }
95
96 void CarouselEffect::SetAnglePerUnit( const Vector2& angle )
97 {
98   SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, angle );
99 }
100
101 const std::string& CarouselEffect::GetRadiusPropertyName() const
102 {
103   return RADIUS_PROPERTY_NAME;
104 }
105
106 const std::string& CarouselEffect::GetCenterPropertyName() const
107 {
108   return CENTER_PROPERTY_NAME;
109 }
110
111 const std::string& CarouselEffect::GetAnglePerUnitPropertyName() const
112 {
113   return ANGLE_PER_UNIT_PROPERTY_NAME;
114 }
115
116 } // namespace Toolkit
117
118 } // namespace Dali