X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fborder%2Fborder-visual.cpp;h=03412bf67e75077558d58bec05e73dd21030533e;hp=32867121fd19b607cabca03fee3584b54d1b45e3;hb=54342c70a267a34b3345b24c404f1064fed99338;hpb=afa6a15b3ae8deb2e8cdf4f1262fd0d2d08d2eac diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index 3286712..03412bf 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-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. @@ -23,7 +23,7 @@ // INTERNAL INCLUDES #include -#include +#include #include #include #include @@ -40,10 +40,6 @@ namespace Internal namespace { -const char * const COLOR_NAME("borderColor"); -const char * const SIZE_NAME("borderSize"); -const char * const ANTI_ALIASING("antiAliasing"); - const char * const POSITION_ATTRIBUTE_NAME("aPosition"); const char * const DRIFT_ATTRIBUTE_NAME("aDrift"); const char * const INDEX_NAME("indices"); @@ -52,14 +48,14 @@ const char * const INDEX_NAME("indices"); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aDrift;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n + uniform highp mat4 uMvpMatrix;\n + uniform highp vec3 uSize;\n uniform mediump float borderSize;\n \n //Visual size and offset uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n + uniform highp vec2 size;\n uniform mediump vec4 offsetSizeMode;\n uniform mediump vec2 origin;\n uniform mediump vec2 anchorPoint;\n @@ -81,18 +77,19 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( uniform lowp vec4 uColor;\n uniform lowp vec4 borderColor;\n + uniform lowp vec3 mixColor;\n \n void main()\n {\n - gl_FragColor = borderColor*uColor;\n + gl_FragColor = vec4(mixColor, 1.0)*borderColor*uColor;\n }\n ); const char* VERTEX_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aDrift;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n + uniform highp mat4 uMvpMatrix;\n + uniform highp vec3 uSize;\n uniform mediump float borderSize;\n varying mediump float vAlpha;\n \n @@ -107,24 +104,27 @@ const char* VERTEX_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( const char* FRAGMENT_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( uniform lowp vec4 uColor;\n uniform lowp vec4 borderColor;\n + uniform lowp vec3 mixColor;\n uniform mediump float borderSize;\n varying mediump float vAlpha;\n \n void main()\n {\n - gl_FragColor = borderColor*uColor;\n + gl_FragColor = vec4(mixColor, 1.0)*borderColor*uColor;\n gl_FragColor.a *= smoothstep(0.0, 1.5, vAlpha)*smoothstep( borderSize+1.5, borderSize, vAlpha );\n }\n ); } -BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache ) +BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) { - return new BorderVisual( factoryCache ); + BorderVisualPtr borderVisualPtr( new BorderVisual( factoryCache ) ); + borderVisualPtr->SetProperties( properties ); + return borderVisualPtr; } BorderVisual::BorderVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), +: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::BORDER ), mBorderColor( Color::TRANSPARENT ), mBorderSize( 0.f ), mBorderColorIndex( Property::INVALID_INDEX ), @@ -139,57 +139,92 @@ BorderVisual::~BorderVisual() void BorderVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* color = propertyMap.Find( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME ); - if( !( color && color->Get(mBorderColor) ) ) - { - DALI_LOG_ERROR( "Fail to provide a border color to the BorderVisual object\n" ); - } - - Property::Value* size = propertyMap.Find( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME ); - if( !( size && size->Get(mBorderSize) ) ) + for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter ) { - DALI_LOG_ERROR( "Fail to provide a border size to the BorderVisual object\n" ); + KeyValuePair keyValue = propertyMap.GetKeyValue( iter ); + if( keyValue.first.type == Property::Key::INDEX ) + { + DoSetProperty( keyValue.first.indexKey, keyValue.second ); + } + else + { + if( keyValue.first == COLOR_NAME ) + { + DoSetProperty( Toolkit::BorderVisual::Property::COLOR, keyValue.second ); + } + else if( keyValue.first == SIZE_NAME ) + { + DoSetProperty( Toolkit::BorderVisual::Property::SIZE, keyValue.second ); + } + else if( keyValue.first == ANTI_ALIASING ) + { + DoSetProperty( Toolkit::BorderVisual::Property::ANTI_ALIASING, keyValue.second ); + } + } } +} - Property::Value* antiAliasing = propertyMap.Find( Toolkit::BorderVisual::Property::ANTI_ALIASING, ANTI_ALIASING ); - if( antiAliasing ) +void BorderVisual::DoSetProperty( Dali::Property::Index index, + const Dali::Property::Value& value ) +{ + switch( index ) { - antiAliasing->Get( mAntiAliasing ); + case Toolkit::BorderVisual::Property::COLOR: + { + if( !value.Get( mBorderColor ) ) + { + DALI_LOG_ERROR("BorderVisual: borderColor property has incorrect type\n"); + } + break; + } + case Toolkit::BorderVisual::Property::SIZE: + { + if( !value.Get( mBorderSize ) ) + { + DALI_LOG_ERROR("BorderVisual: borderSize property has incorrect type\n"); + } + break; + } + case Toolkit::BorderVisual::Property::ANTI_ALIASING: + { + if( !value.Get( mAntiAliasing ) ) + { + DALI_LOG_ERROR("BorderVisual: antiAliasing property has incorrect type\n"); + } + break; + } } } -void BorderVisual::DoSetOnStage( Actor& actor ) +void BorderVisual::DoSetOnScene( Actor& actor ) { InitializeRenderer(); - mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME, mBorderColor ); + mBorderColorIndex = mImpl->mRenderer.RegisterProperty( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME, mBorderColor ); if( mBorderColor.a < 1.f || mAntiAliasing) { mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); } - mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME, mBorderSize ); + mBorderSizeIndex = mImpl->mRenderer.RegisterProperty( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME, mBorderSize ); actor.AddRenderer( mImpl->mRenderer ); + + // Border Visual Generated and ready to display + ResourceReady( Toolkit::Visual::ResourceStatus::READY ); } void BorderVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); - map.Insert( VisualProperty::TYPE, Toolkit::Visual::BORDER ); + map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::BORDER ); map.Insert( Toolkit::BorderVisual::Property::COLOR, mBorderColor ); map.Insert( Toolkit::BorderVisual::Property::SIZE, mBorderSize ); map.Insert( Toolkit::BorderVisual::Property::ANTI_ALIASING, mAntiAliasing ); } -void BorderVisual::DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ) +void BorderVisual::DoCreateInstancePropertyMap( Property::Map& map ) const { - // TODO -} - -Dali::Property::Value BorderVisual::DoGetProperty( Dali::Property::Index index ) -{ - // TODO - return Dali::Property::Value(); + // Do nothing } void BorderVisual::OnSetTransform() @@ -209,54 +244,11 @@ void BorderVisual::InitializeRenderer() mFactoryCache.SaveGeometry( VisualFactoryCache::BORDER_GEOMETRY, geometry ); } - Shader shader = GetBorderShader(); mImpl->mRenderer = Renderer::New( geometry, shader ); //Register transform properties mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT ); - -} - -void BorderVisual::SetBorderColor(const Vector4& color) -{ - mBorderColor = color; - - if( mImpl->mRenderer ) - { - (mImpl->mRenderer).SetProperty( mBorderColorIndex, color ); - if( color.a < 1.f ) - { - mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - } - } -} - -void BorderVisual::SetBorderSize( float size ) -{ - mBorderSize = size; - - if( mImpl->mRenderer ) - { - (mImpl->mRenderer).SetProperty( mBorderSizeIndex, size ); - } -} - -void BorderVisual::RequireAntiAliasing( bool antiAliasing ) -{ - if( mAntiAliasing != antiAliasing ) - { - mAntiAliasing = antiAliasing; - if( mImpl->mRenderer ) - { - Shader borderShader( GetBorderShader() ); - mImpl->mRenderer.SetShader( borderShader ); - if( mAntiAliasing ) - { - mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - } - } - } } Shader BorderVisual::GetBorderShader() @@ -331,7 +323,7 @@ Geometry BorderVisual::CreateBorderGeometry() Property::Map borderVertexFormat; borderVertexFormat[POSITION_ATTRIBUTE_NAME] = Property::VECTOR2; borderVertexFormat[DRIFT_ATTRIBUTE_NAME] = Property::VECTOR2; - PropertyBuffer borderVertices = PropertyBuffer::New( borderVertexFormat ); + VertexBuffer borderVertices = VertexBuffer::New( borderVertexFormat ); borderVertices.SetData( borderVertexData, 16 ); // Create indices