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=8228550c943c5ca5d3507f2a1fe410adc6db689d;hp=5bc3c6ec8c428d71b6203eefab1fea526c928a9d;hb=a0a28eb90260b017d231b0a2ff993825405fd058;hpb=dc256c60aaab03a8d7319b9257549d32f6a5b22d diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 5bc3c6e..8228550 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -24,7 +24,8 @@ //INTERNAL INCLUDES #include -#include +#include +#include #include #include #include @@ -41,7 +42,6 @@ namespace Internal namespace { -const char * const COLOR_NAME("mixColor"); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n @@ -71,11 +71,12 @@ 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 ); } @@ -88,8 +89,8 @@ ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Propert } ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mMixColorIndex( Property::INVALID_INDEX ) +: Visual::Base( factoryCache, Visual::FittingMode::FILL ), + mRenderIfTransparent( false ) { } @@ -99,10 +100,38 @@ 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 Toolkit::Visual::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"); + } + } + + Property::Value* renderIfTransparentValue = propertyMap.Find( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, RENDER_IF_TRANSPARENT_NAME ); + if( renderIfTransparentValue ) + { + if( ! renderIfTransparentValue->Get( mRenderIfTransparent ) ) + { + DALI_LOG_ERROR( "ColorVisual: renderIfTransparent property has incorrect type: %d\n", renderIfTransparentValue->GetType() ); + } } } @@ -110,16 +139,31 @@ void ColorVisual::DoSetOnStage( Actor& actor ) { InitializeRenderer(); - actor.AddRenderer( mImpl->mRenderer ); + // Only add the renderer if it's not fully transparent + // We cannot avoid creating a renderer as it's used in the base class + if( mRenderIfTransparent || mImpl->mMixColor.a > 0.0f ) + { + actor.AddRenderer( mImpl->mRenderer ); + } + + // Color Visual generated and ready to display + ResourceReady( Toolkit::Visual::ResourceStatus::READY ); } 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::Visual::Property::TYPE, Toolkit::Visual::COLOR ); + map.Insert( Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor ); + map.Insert( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, mRenderIfTransparent ); +} + +void ColorVisual::DoCreateInstancePropertyMap( Property::Map& map ) const +{ + // Do nothing } + void ColorVisual::OnSetTransform() { if( mImpl->mRenderer ) @@ -141,30 +185,20 @@ void ColorVisual::InitializeRenderer() mImpl->mRenderer = Renderer::New( geometry, shader ); - mMixColorIndex = DevelHandle::RegisterProperty( mImpl->mRenderer, 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