X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch%2Fnpatch-visual.cpp;h=36700fe24db01df9377dc48524c388307b5c1057;hp=8751c3e11084b02fbba0d154210a572964919957;hb=8cfc7965881ba756bca7bdde98b548200a649bd4;hpb=9217ec0c1d483607ed6c8f08a1d9c238657ba5d6 diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 8751c3e..36700fe 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -27,6 +27,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -46,7 +47,8 @@ namespace Internal namespace { -const char * const BORDER_ONLY("borderOnly"); +const char * const BORDER_ONLY( "borderOnly" ); +const char * const BORDER( "border" ); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n @@ -110,7 +112,7 @@ const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER( vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n mediump vec2 scale = vec2( length( uModelMatrix[ 0 ].xyz ), length( uModelMatrix[ 1 ].xyz ) );\n - mediump vec2 size = visualSize.xy * scale;\n + mediump vec2 size = visualSize.xy;\n \n mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );\n mediump vec2 stretch = floor( aPosition * 0.5 );\n @@ -118,7 +120,7 @@ const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER( \n mediump vec4 vertexPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 ); vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n - vertexPosition.xy = vertexPosition.xy / scale + anchorPoint*size + (visualOffset + origin)*uSize.xy;\ + vertexPosition.xy = vertexPosition.xy + anchorPoint*size + (visualOffset + origin)*uSize.xy;\ \n vertexPosition = uMvpMatrix * vertexPosition;\n \n @@ -132,10 +134,16 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n uniform sampler2D sTexture;\n uniform lowp vec4 uColor;\n - \n + uniform lowp vec3 mixColor;\n + uniform lowp float opacity;\n + uniform lowp float preMultipliedAlpha;\n + lowp vec4 visualMixColor()\n + {\n + return vec4( mixColor * mix( 1.0, opacity, preMultipliedAlpha ), opacity );\n + }\n void main()\n {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * visualMixColor();\n }\n ); @@ -226,30 +234,40 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) { - NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache ); + NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); nPatchVisual->mImageUrl = imageUrl; + nPatchVisual->SetProperties( properties ); return nPatchVisual; } -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) { - NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache ); - nPatchVisual->mImageUrl = image.GetUrl(); + NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); + nPatchVisual->mImageUrl = imageUrl; return nPatchVisual; } +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image ) +{ + NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); + VisualUrl visualUrl( image.GetUrl() ); + nPatchVisual->mImageUrl = visualUrl; + return nPatchVisual; +} + void NPatchVisual::GetNaturalSize( Vector2& naturalSize ) { naturalSize.x = 0u; naturalSize.y = 0u; + // load now if not already loaded - if( NPatchLoader::UNINITIALIZED_ID == mId ) + if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() ) { - mId = mLoader.Load( mImageUrl ); + mId = mLoader.Load( mImageUrl.GetUrl(), mBorder ); } const NPatchLoader::Data* data; if( mLoader.GetNPatchData( mId, data ) ) @@ -268,14 +286,28 @@ void NPatchVisual::DoSetProperties( const Property::Map& propertyMap ) { borderOnlyValue->Get( mBorderOnly ); } + + Property::Value* borderValue = propertyMap.Find( Toolkit::DevelImageVisual::Property::BORDER, BORDER ); + if( borderValue && ! borderValue->Get( mBorder ) ) // If value exists and is rect, just set mBorder + { + // Not a rect so try vector4 + Vector4 border; + if( borderValue->Get( border ) ) + { + mBorder.left = static_cast< int >( border.x ); + mBorder.right = static_cast< int >( border.y ); + mBorder.bottom = static_cast< int >( border.z ); + mBorder.top = static_cast< int >( border.w ); + } + } } void NPatchVisual::DoSetOnStage( Actor& actor ) { // load when first go on stage - if( NPatchLoader::UNINITIALIZED_ID == mId ) + if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() ) { - mId = mLoader.Load( mImageUrl ); + mId = mLoader.Load( mImageUrl.GetUrl(), mBorder ); } Geometry geometry = CreateGeometry(); @@ -304,9 +336,15 @@ void NPatchVisual::OnSetTransform() void NPatchVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); - map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::Visual::IMAGE ); - map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl ); + map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::N_PATCH ); + map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); map.Insert( Toolkit::ImageVisual::Property::BORDER_ONLY, mBorderOnly ); + map.Insert( Toolkit::DevelImageVisual::Property::BORDER, mBorder ); +} + +void NPatchVisual::DoCreateInstancePropertyMap( Property::Map& map ) const +{ + // Do nothing } NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) @@ -314,7 +352,8 @@ NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) mLoader( factoryCache.GetNPatchLoader() ), mImageUrl(), mId( NPatchLoader::UNINITIALIZED_ID ), - mBorderOnly( false ) + mBorderOnly( false ), + mBorder() { } @@ -453,7 +492,7 @@ void NPatchVisual::ApplyTextureAndUniforms() } else { - DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.c_str() ); + DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str() ); TextureSet textureSet = TextureSet::New(); mImpl->mRenderer.SetTextures( textureSet ); Image croppedImage = VisualFactoryCache::GetBrokenVisualImage();