X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fcolor%2Fcolor-visual.cpp;h=fdc48356ac03486e6dc95d5e5dcba9718251d4c0;hb=refs%2Fchanges%2F91%2F170491%2F7;hp=6313211433f7e53ba82a308673e06f812470b4cc;hpb=45fc50ae7d1c0b9d33d47da82e2ac8e928e992f9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 6313211..fdc4835 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 @@ -70,11 +71,11 @@ 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 \n void main()\n {\n - gl_FragColor = mixColor*uColor;\n + gl_FragColor = vec4(mixColor, 1.0)*uColor;\n }\n ); } @@ -87,7 +88,8 @@ ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Propert } ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ) +: Visual::Base( factoryCache, Visual::FittingMode::FILL ), + mRenderIfTransparent( false ) { } @@ -98,36 +100,69 @@ ColorVisual::~ColorVisual() void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) { // By virtue of DoSetProperties being called last, this will override - // anything set by DevelVisual::Property::MIX_COLOR + // anything set by Toolkit::Visual::Property::MIX_COLOR Property::Value* colorValue = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR ); if( colorValue ) { Vector4 color; if( colorValue->Get( color ) ) { - SetMixColor( 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() ); + } + } } 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::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 ) @@ -152,7 +187,8 @@ void ColorVisual::InitializeRenderer() // 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, mImpl->mMixColor ); + 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 );