2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
29 const std::string TOP_LEFT_PROPERTY_NAME( "uTopLeft" );
30 const std::string BOTTOM_RIGHT_PROPERTY_NAME( "uBottomRight" );
34 ImageRegionEffect::ImageRegionEffect()
38 //Call the Parent copy constructor to add reference to the implementation for this object
39 ImageRegionEffect::ImageRegionEffect(ShaderEffect handle)
44 ImageRegionEffect::~ImageRegionEffect()
49 ImageRegionEffect ImageRegionEffect::New()
51 std::string vertexShader(
52 "uniform vec2 uTopLeft;\n"
53 "uniform vec2 uBottomRight;\n"
56 " vec4 position = vec4(aPosition,1.0);\n"
57 " gl_Position = uMvpMatrix * position;\n"
58 // The line below is doing the same as the following commented lines:
59 //" vec2 imageSize = sTextureRect.zw - sTextureRect.xy;\n"
60 //" vec2 topLeft = sTextureRect.xy + uTopLeft * imageSize;\n"
61 //" vec2 bottomRight = sTextureRect.xy + uBottomRight * imageSize;\n"
62 //" vec2 texCoord = (aTexCoord - sTextureRect.xy) / imageSize;\n"
63 //" vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
64 " vTexCoord = sTextureRect.xy + uTopLeft * ( sTextureRect.zw - sTextureRect.xy ) + ( aTexCoord - sTextureRect.xy ) * ( uBottomRight - uTopLeft );\n"
68 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New( vertexShader, "" );
70 Dali::Toolkit::ImageRegionEffect handle( shaderEffectCustom );
72 handle.SetUniform( TOP_LEFT_PROPERTY_NAME, Vector2( 0.f, 0.f ) );
73 handle.SetUniform( BOTTOM_RIGHT_PROPERTY_NAME, Vector2( 1.f, 1.f ) );
78 void ImageRegionEffect::SetTopLeft(const Vector2& point)
80 SetUniform( TOP_LEFT_PROPERTY_NAME, point );
83 void ImageRegionEffect::SetBottomRight(const Vector2& point)
85 SetUniform( BOTTOM_RIGHT_PROPERTY_NAME, point );
88 const std::string& ImageRegionEffect::GetTopLeftPropertyName() const
90 return TOP_LEFT_PROPERTY_NAME;
93 const std::string& ImageRegionEffect::GetBottomRightPropertyName() const
95 return BOTTOM_RIGHT_PROPERTY_NAME;
98 } // namespace Toolkit