/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
#include "npatch-visual.h"
// EXTERNAL INCLUDES
-#include <dali/integration-api/platform-abstraction.h>
#include <dali/public-api/images/buffer-image.h>
#include <dali/public-api/images/resource-image.h>
#include <dali/devel-api/images/texture-set-image.h>
+#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
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;\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
/////////////////NPatchVisual////////////////
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties )
+NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
nPatchVisual->mImageUrl = imageUrl;
return nPatchVisual;
}
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl )
+NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
nPatchVisual->mImageUrl = imageUrl;
NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
- nPatchVisual->mImageUrl = image.GetUrl();
-
+ VisualUrl visualUrl( image.GetUrl() );
+ nPatchVisual->mImageUrl = visualUrl;
return nPatchVisual;
}
{
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, mBorder );
+ mId = mLoader.Load( mImageUrl.GetUrl(), mBorder );
}
const NPatchLoader::Data* data;
if( mLoader.GetNPatchData( mId, data ) )
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, mBorder );
+ mId = mLoader.Load( mImageUrl.GetUrl(), mBorder );
}
Geometry geometry = CreateGeometry();
ApplyTextureAndUniforms();
actor.AddRenderer( mImpl->mRenderer );
+
+ // npatch loaded and ready to display
+ ResourceReady();
}
void NPatchVisual::DoSetOffStage( Actor& actor )
{
map.Clear();
map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::N_PATCH );
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
map.Insert( Toolkit::ImageVisual::Property::BORDER_ONLY, mBorderOnly );
map.Insert( Toolkit::DevelImageVisual::Property::BORDER, mBorder );
}
}
hints = mImpl->mCustomShader->mHints;
+ /* Apply Custom Vertex Shader only if image is 9-patch */
if( ( xStretchCount == 1 && yStretchCount == 1 ) ||
( xStretchCount == 0 && yStretchCount == 0 ) )
{
- shader = Shader::New( VERTEX_SHADER_3X3, fragmentShader, hints );
+ const char* vertexShader = VERTEX_SHADER_3X3;
+
+ if( !mImpl->mCustomShader->mVertexShader.empty() )
+ {
+ vertexShader = mImpl->mCustomShader->mVertexShader.c_str();
+ }
+ shader = Shader::New( vertexShader, fragmentShader, hints );
}
else if( xStretchCount > 0 || yStretchCount > 0)
{
}
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();