remove (dead) ImageView UI control
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / shader-effects / iris-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/iris-effect.h>
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace
26 {
27 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
28 const std::string CENTER_PROPERTY_NAME( "uCenter" );
29 const std::string BLEND_FACTOR_PROPERTY_NAME( "uBlendFactor" );
30 } // namespace
31
32 IrisEffect::IrisEffect()
33 {
34 }
35
36 //Call the Parent copy constructor to add reference to the implementation for this object
37 IrisEffect::IrisEffect(ShaderEffect handle)
38 :ShaderEffect(handle)
39 {
40 }
41
42 IrisEffect::~IrisEffect()
43 {
44 }
45
46 IrisEffect IrisEffect::New()
47 {
48   // append the default version
49   std::string vertexShader(
50               "uniform mediump vec2 uCenter;\n"
51               "varying mediump vec2 vRelativePosition;\n"
52               "\n"
53               "void main()\n"
54               "{\n"
55               "    mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
56               "    gl_Position = uProjection * world;\n"
57               "    \n"
58               "    vTexCoord = aTexCoord;\n"
59               "    vRelativePosition = aTexCoord - uCenter;\n"
60               "}\n");
61
62   std::string fragmentShader(
63               "uniform mediump float uRadius;                                                           \n"
64               "uniform mediump float uBlendFactor;                                                      \n"
65               "varying mediump vec2 vRelativePosition;                                                  \n"
66               "void main()                                                                      \n"
67               "{                                                                                \n"
68               "   mediump float delta = (length(vRelativePosition) - uRadius);                          \n"
69               "   delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0);                          \n"
70               "   gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;                       \n"
71               "   gl_FragColor.a *= delta;                                                      \n"
72               "}                                                                                \n"
73               );
74
75   Dali::ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
76       vertexShader,
77       fragmentShader,
78       GeometryType( GEOMETRY_TYPE_IMAGE ),
79       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
80
81   Dali::Toolkit::IrisEffect handle( shaderEffectCustom );
82   handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
83   handle.SetUniform( BLEND_FACTOR_PROPERTY_NAME, 100.0f );
84   handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.5f, 0.5f) );
85   return handle;
86 }
87
88 void IrisEffect::SetRadius( float radius )
89 {
90   SetUniform( RADIUS_PROPERTY_NAME, radius );
91 }
92
93 void IrisEffect::SetBlendFactor(float value )
94 {
95   SetUniform( BLEND_FACTOR_PROPERTY_NAME, value );
96 }
97
98 void IrisEffect::SetCenter( const Vector2& center )
99 {
100   SetUniform( CENTER_PROPERTY_NAME, center );
101 }
102
103 const std::string& IrisEffect::GetRadiusPropertyName() const
104 {
105   return RADIUS_PROPERTY_NAME;
106 }
107
108 const std::string& IrisEffect::GetBlendFactorPropertyName() const
109 {
110   return BLEND_FACTOR_PROPERTY_NAME;
111 }
112
113 const std::string& IrisEffect::GetCenterPropertyName() const
114 {
115   return CENTER_PROPERTY_NAME;
116 }
117
118
119 }
120 }