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=13b8633a5cb3db83d6b8c2e38c9083454fdc130a;hp=3cb168850bd436b8412353afca9c295238782b03;hb=5a2a5883422f4d114902ac57d57d7d1e973fbb2e;hpb=257a9991486e4e05335212b21ecc1f5a0aacbc63 diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index 3cb1688..13b8633 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) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -20,12 +20,15 @@ // EXTERNAL INCLUDES #include +#include -//INTERNAL INCLUDES +// INTERNAL INCLUDES +#include +#include #include #include #include -#include +#include namespace Dali { @@ -54,9 +57,24 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( uniform mediump vec3 uSize;\n uniform mediump float borderSize;\n \n + + //Visual size and offset + uniform mediump vec2 offset;\n + uniform mediump vec2 size;\n + uniform mediump vec4 offsetSizeMode;\n + uniform mediump vec2 origin;\n + uniform mediump vec2 anchorPoint;\n + + vec2 ComputeVertexPosition()\n + {\n + vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n + vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n + return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;\n + }\n + void main()\n {\n - vec2 position = aPosition*uSize.xy + aDrift*borderSize;\n + vec2 position = ComputeVertexPosition() + aDrift*borderSize;\n gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n }\n ); @@ -64,10 +82,12 @@ 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 + uniform lowp float opacity;\n \n void main()\n {\n - gl_FragColor = borderColor*uColor;\n + gl_FragColor = vec4(mixColor, opacity)*borderColor*uColor;\n }\n ); @@ -90,19 +110,28 @@ 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 lowp float opacity;\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, opacity)*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, const Property::Map& properties ) +{ + BorderVisualPtr borderVisualPtr( new BorderVisual( factoryCache ) ); + borderVisualPtr->SetProperties( properties ); + return borderVisualPtr; +} + BorderVisual::BorderVisual( VisualFactoryCache& factoryCache ) -: Visual( factoryCache ), +: Visual::Base( factoryCache ), mBorderColor( Color::TRANSPARENT ), mBorderSize( 0.f ), mBorderColorIndex( Property::INVALID_INDEX ), @@ -115,52 +144,94 @@ BorderVisual::~BorderVisual() { } -void BorderVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) +void BorderVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* color = propertyMap.Find( COLOR_NAME ); - if( !( color && color->Get(mBorderColor) ) ) - { - DALI_LOG_ERROR( "Fail to provide a border color to the BorderVisual object" ); - } - - Property::Value* size = propertyMap.Find( SIZE_NAME ); - if( !( size && size->Get(mBorderSize) ) ) - { - DALI_LOG_ERROR( "Fail to provide a border size to the BorderVisual object" ); - } - - Property::Value* antiAliasing = propertyMap.Find( ANTI_ALIASING ); - if( antiAliasing ) + for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter ) { - antiAliasing->Get( mAntiAliasing ); + 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 ); + } + } } } -void BorderVisual::SetClipRect( const Rect& clipRect ) +void BorderVisual::DoSetProperty( Dali::Property::Index index, + const Dali::Property::Value& value ) { - Visual::SetClipRect( clipRect ); - - //ToDo: renderer responds to the clipRect change + switch( index ) + { + 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 ) { InitializeRenderer(); - mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_NAME, mBorderColor ); + mBorderColorIndex = DevelHandle::RegisterProperty( mImpl->mRenderer, 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( SIZE_NAME, mBorderSize ); + mBorderSizeIndex = DevelHandle::RegisterProperty( mImpl->mRenderer, Toolkit::BorderVisual::Property::SIZE, SIZE_NAME, mBorderSize ); + + actor.AddRenderer( mImpl->mRenderer ); } void BorderVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); - map.Insert( RENDERER_TYPE, BORDER_RENDERER ); - map.Insert( COLOR_NAME, mBorderColor ); - map.Insert( SIZE_NAME, mBorderSize ); + map.Insert( Toolkit::DevelVisual::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::OnSetTransform() +{ + if( mImpl->mRenderer ) + { + mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT ); + } } void BorderVisual::InitializeRenderer() @@ -172,10 +243,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) @@ -301,7 +373,7 @@ Geometry BorderVisual::CreateBorderGeometry() Geometry geometry = Geometry::New(); geometry.AddVertexBuffer( borderVertices ); geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); - geometry.SetGeometryType( Geometry::TRIANGLE_STRIP ); + geometry.SetType( Geometry::TRIANGLE_STRIP ); return geometry; }