X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fcolor%2Fcolor-visual.cpp;h=0ac80d61a62cbb19937b39374f0f5dc583bef275;hp=b6d5c6cf2fbd17a903cc182bd673fb2cc653ea84;hb=5a2a5883422f4d114902ac57d57d7d1e973fbb2e;hpb=9217ec0c1d483607ed6c8f08a1d9c238657ba5d6 diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index b6d5c6c..0ac80d6 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include //INTERNAL INCLUDES #include @@ -40,7 +41,6 @@ namespace Internal namespace { -const char * const COLOR_NAME("mixColor"); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n @@ -70,23 +70,25 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( uniform lowp vec4 uColor;\n - uniform lowp vec4 mixColor;\n + uniform lowp vec3 mixColor;\n + uniform lowp float opacity;\n \n void main()\n {\n - gl_FragColor = mixColor*uColor;\n + gl_FragColor = vec4(mixColor, opacity)*uColor;\n }\n ); } -ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache ) +ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) { - return new ColorVisual( factoryCache ); + ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) ); + colorVisualPtr->SetProperties( properties ); + return colorVisualPtr; } ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mMixColorIndex( Property::INVALID_INDEX ) +: Visual::Base( factoryCache ) { } @@ -96,10 +98,29 @@ ColorVisual::~ColorVisual() void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* color = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, COLOR_NAME ); - if( !( color && color->Get(mMixColor) ) ) + // By virtue of DoSetProperties being called last, this will override + // anything set by DevelVisual::Property::MIX_COLOR + Property::Value* colorValue = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR ); + if( colorValue ) { - DALI_LOG_ERROR( "Fail to provide a color to the ColorVisual object\n" ); + Vector4 color; + if( colorValue->Get( color ) ) + { + Property::Type type = colorValue->GetType(); + if( type == Property::VECTOR4 ) + { + SetMixColor( color ); + } + else if( type == Property::VECTOR3 ) + { + Vector3 color3(color); + SetMixColor( color3 ); + } + } + else + { + DALI_LOG_ERROR("ColorVisual: mixColor property has incorrect type\n"); + } } } @@ -114,7 +135,7 @@ void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::Visual::COLOR ); - map.Insert( Toolkit::ColorVisual::Property::MIX_COLOR, mMixColor ); + map.Insert( Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor ); } void ColorVisual::OnSetTransform() @@ -128,11 +149,6 @@ void ColorVisual::OnSetTransform() void ColorVisual::InitializeRenderer() { Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); - if( !geometry ) - { - geometry = VisualFactoryCache::CreateQuadGeometry(); - mFactoryCache.SaveGeometry( VisualFactoryCache::QUAD_GEOMETRY, geometry ); - } Shader shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER ); if( !shader ) @@ -143,30 +159,20 @@ void ColorVisual::InitializeRenderer() mImpl->mRenderer = Renderer::New( geometry, shader ); - mMixColorIndex = mImpl->mRenderer.RegisterProperty( Toolkit::ColorVisual::Property::MIX_COLOR, COLOR_NAME, mMixColor ); - if( mMixColor.a < 1.f ) + // ColorVisual has it's own index key for mix color - use this instead + // of using the new base index to avoid changing existing applications + // String keys will get to this property. + mImpl->mMixColorIndex = DevelHandle::RegisterProperty( mImpl->mRenderer, Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor) ); + + if( mImpl->mMixColor.a < 1.f ) { mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); } - //Register transform properties + // Register transform properties mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT ); } -void ColorVisual::SetColor(const Vector4& color) -{ - mMixColor = color; - - if( mImpl->mRenderer ) - { - (mImpl->mRenderer).SetProperty( mMixColorIndex, color ); - if( color.a < 1.f ) - { - mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - } - } -} - } // namespace Internal } // namespace Toolkit