2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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
8 // http://floralicense.org/license/
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.
17 #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
28 const std::string TOP_LEFT_PROPERTY_NAME( "uTopLeft" );
29 const std::string BOTTOM_RIGHT_PROPERTY_NAME( "uBottomRight" );
33 ImageRegionEffect::ImageRegionEffect()
37 //Call the Parent copy constructor to add reference to the implementation for this object
38 ImageRegionEffect::ImageRegionEffect(ShaderEffect handle)
43 ImageRegionEffect::~ImageRegionEffect()
48 ImageRegionEffect ImageRegionEffect::New()
50 std::string vertexShader(
51 "uniform vec2 uTopLeft;\n"
52 "uniform vec2 uBottomRight;\n"
55 " vec4 position = vec4(aPosition,1.0);\n"
56 " gl_Position = uMvpMatrix * position;\n"
57 // The line below is doing the same as the following commented lines:
58 //" vec2 imageSize = sTextureRect.zw - sTextureRect.xy;\n"
59 //" vec2 topLeft = sTextureRect.xy + uTopLeft * imageSize;\n"
60 //" vec2 bottomRight = sTextureRect.xy + uBottomRight * imageSize;\n"
61 //" vec2 texCoord = (aTexCoord - sTextureRect.xy) / imageSize;\n"
62 //" vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
63 " vTexCoord = sTextureRect.xy + uTopLeft * ( sTextureRect.zw - sTextureRect.xy ) + ( aTexCoord - sTextureRect.xy ) * ( uBottomRight - uTopLeft );\n"
67 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New( vertexShader, "" );
69 Dali::Toolkit::ImageRegionEffect handle( shaderEffectCustom );
71 handle.SetUniform( TOP_LEFT_PROPERTY_NAME, Vector2( 0.f, 0.f ) );
72 handle.SetUniform( BOTTOM_RIGHT_PROPERTY_NAME, Vector2( 1.f, 1.f ) );
77 void ImageRegionEffect::SetTopLeft(const Vector2& point)
79 SetUniform( TOP_LEFT_PROPERTY_NAME, point );
82 void ImageRegionEffect::SetBottomRight(const Vector2& point)
84 SetUniform( BOTTOM_RIGHT_PROPERTY_NAME, point );
87 const std::string& ImageRegionEffect::GetTopLeftPropertyName() const
89 return TOP_LEFT_PROPERTY_NAME;
92 const std::string& ImageRegionEffect::GetBottomRightPropertyName() const
94 return BOTTOM_RIGHT_PROPERTY_NAME;
97 } // namespace Toolkit