-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include <dali-toolkit/public-api/shader-effects/nine-patch-mask-effect.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/object/property-input.h>
+#include <dali/public-api/shader-effects/shader-effect.h>
+#include <dali/public-api/images/resource-image.h>
+
namespace Dali
{
namespace NinePatchMaskEffect
{
-struct NinePatchMaskEffectSizeConstraint
+namespace
+{
+
+void NinePatchMaskEffectSizeConstraint( Vector2& current, const PropertyInputContainer& inputs )
{
- Vector2 operator()( const Vector2& current, const PropertyInput& property )
- {
- const Vector3& actorSize = property.GetVector3();
- return Vector2( actorSize.x, actorSize.y );
- }
-};
+ const Vector3& actorSize = inputs[0]->GetVector3();
+ current.x = actorSize.x;
+ current.y = actorSize.y;
+}
+
+} // unnamed namespace
static void DoApply( ImageActor actor, const std::string& maskImage, const Vector2& maskSize, Vector4 maskBorder )
{
const char* ALPHA_MASK_VERTEX_SHADER_SOURCE =
+ "precision mediump float;\n"
"uniform vec2 uImageSize; \n"
"uniform vec2 uMaskSize; \n"
"varying vec2 vMaskTexCoord; \n"
"} \n";
const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE =
- "varying vec2 vMaskTexCoord; \n"
+ "varying mediump vec2 vMaskTexCoord; \n"
" \n"
"void main() \n"
"{ \n"
" gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n"
"} \n";
- ShaderEffect maskEffect = ShaderEffect::New( ALPHA_MASK_VERTEX_SHADER_SOURCE,
- ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
- GeometryType( GEOMETRY_TYPE_IMAGE ),
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
+ ShaderEffect maskEffect = ShaderEffect::New(
+ ALPHA_MASK_VERTEX_SHADER_SOURCE,
+ ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
+ GeometryType( GEOMETRY_TYPE_IMAGE ),
+ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
- maskEffect.SetEffectImage( Image::New( maskImage ) );
+ maskEffect.SetEffectImage( ResourceImage::New( maskImage ) );
maskEffect.SetUniform( "uImageSize", Vector2(0,0) /*Constrained to actor size*/ );
- maskEffect.ApplyConstraint( Constraint::New<Vector2>( maskEffect.GetPropertyIndex("uImageSize"),
- Source(actor, Actor::SIZE),
- NinePatchMaskEffectSizeConstraint() ) );
+
+ Constraint constraint = Constraint::New<Vector2>( maskEffect, maskEffect.GetPropertyIndex("uImageSize"), NinePatchMaskEffectSizeConstraint );
+ constraint.AddSource( Source(actor, Actor::Property::SIZE) );
+ constraint.Apply();
maskEffect.SetUniform( "uMaskSize", maskSize );
void Apply( ImageActor actor, const std::string& maskImage )
{
- Vector2 maskSize = Image::GetImageSize( maskImage );
+ const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage );
- const float leftRight = (maskSize.width - 1.0f) * 0.5f;
- const float topBottom = (maskSize.height - 1.0f) * 0.5f;
+ const float leftRight = (maskSize.GetWidth() - 1.0f) * 0.5f;
+ const float topBottom = (maskSize.GetHeight() - 1.0f) * 0.5f;
- DoApply( actor, maskImage, maskSize, Vector4( leftRight, topBottom, leftRight, topBottom ) );
+ DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), Vector4( leftRight, topBottom, leftRight, topBottom ) );
}
void Apply( ImageActor actor, const std::string& maskImage, const Vector4& maskBorder )
{
- Vector2 maskSize = Image::GetImageSize( maskImage );
+ const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage );
- DoApply( actor, maskImage, maskSize, maskBorder );
+ DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), maskBorder );
}
} // namespace NinePatchMaskEffect