Merge "TextSelectionToolbar and Style Properties added" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / shear-effect.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 #include <dali-toolkit/devel-api/shader-effects/shear-effect.h>
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace
27 {
28
29 const std::string CENTER_PROPERTY_NAME( "uCenter" );
30 const std::string ANGLE_X_AXIS_PROPERTY_NAME( "uAngleXAxis" );
31 const std::string ANGLE_Y_AXIS_PROPERTY_NAME( "uAngleYAxis" );
32
33 } // namespace
34
35 ShearEffect::ShearEffect()
36 {
37 }
38
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 ShearEffect::ShearEffect(ShaderEffect handle)
41 :ShaderEffect(handle)
42 {
43 }
44
45 ShearEffect::~ShearEffect()
46 {
47 }
48
49
50 ShearEffect ShearEffect::New()
51 {
52   // append the default version
53   std::string vertexShader(
54               "uniform mediump  vec2  uCenter;\n"
55               "uniform mediump  float uAngleXAxis;\n"
56               "uniform mediump  float uAngleYAxis;\n"
57               "\n"
58               "void main()\n"
59               "{\n"
60                   "mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
61                   "\n"
62                   "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
63                   "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
64                   "\n"
65                   "gl_Position = uProjection * world;\n"
66                   "\n"
67                   "vTexCoord = aTexCoord;\n"
68               "}" );
69
70   // Create the implementation, temporarily owned on stack,
71   ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
72       vertexShader,
73       "",
74       GeometryType( GEOMETRY_TYPE_IMAGE ),
75       GeometryHints( HINT_GRID ));
76
77   // Pass ownership to ShearEffect through overloaded constructor, So that it now has access to the
78   // Dali::ShaderEffect implementation
79   Dali::Toolkit::ShearEffect handle( shaderEffectCustom );
80
81   handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.0f, 0.0f), COORDINATE_TYPE_VIEWPORT_POSITION );
82   handle.SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, 0.0f);
83   handle.SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, 0.0f);
84
85   return handle;
86 }
87
88 void ShearEffect::SetCenter( const Vector2& center )
89 {
90   SetUniform( CENTER_PROPERTY_NAME, center, COORDINATE_TYPE_VIEWPORT_POSITION );
91 }
92
93 void ShearEffect::SetAngleXAxis( float angle )
94 {
95   SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, angle );
96 };
97
98 void ShearEffect::SetAngleYAxis( float angle )
99 {
100   SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, angle );
101 };
102
103 const std::string& ShearEffect::GetCenterPropertyName() const
104 {
105   return CENTER_PROPERTY_NAME;
106 }
107
108 const std::string& ShearEffect::GetAngleXAxisPropertyName() const
109 {
110   return ANGLE_X_AXIS_PROPERTY_NAME;
111 }
112
113 const std::string& ShearEffect::GetAngleYAxisPropertyName() const
114 {
115   return ANGLE_Y_AXIS_PROPERTY_NAME;
116 }
117
118 } // namespace Toolkit
119
120 } // namespace Dali