X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Frenderers%2Fgradient%2Fgradient-renderer.cpp;h=f1838ae5435e98f9e6ffcfdbedc3587b83260331;hp=6dc25cadfaa758258807ee2679ca4bfe9087f566;hb=a2de9cf491172cd5da9dc9ed60b17683dab6d7bc;hpb=6861f629112d44d4de1a8a7c70591e2279b951b2;ds=sidebyside diff --git a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp index 6dc25ca..f1838ae 100644 --- a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp @@ -43,33 +43,36 @@ namespace Internal namespace { -const char * const RENDERER_TYPE("renderer-type"); -const char * const RENDERER_TYPE_VALUE("gradient-renderer"); +const char * const RENDERER_TYPE("rendererType"); +const char * const RENDERER_TYPE_VALUE("gradient"); // properties: linear gradient -const char * const GRADIENT_START_POSITION_NAME("gradient-start-position"); // Property::VECTOR2 -const char * const GRADIENT_END_POSITION_NAME("gradient-end-position"); // Property::VECTOR2 +const char * const START_POSITION_NAME("startPosition"); // Property::VECTOR2 +const char * const END_POSITION_NAME("endPosition"); // Property::VECTOR2 // properties: radial gradient -const char * const GRADIENT_CENTER_NAME("gradient-center"); // Property::VECTOR2 -const char * const GRADIENT_RADIUS_NAME("gradient-radius"); // Property::FLOAT +const char * const CENTER_NAME("center"); // Property::VECTOR2 +const char * const RADIUS_NAME("radius"); // Property::FLOAT // properties: linear&radial gradient -const char * const GRADIENT_STOP_OFFSET_NAME("gradient-stop-offset"); // Property::Array FLOAT -const char * const GRADIENT_STOP_COLOR_NAME("gradient-stop-color"); // Property::Array VECTOR4 -const char * const GRADIENT_UNITS_NAME("gradient-units"); // Property::String "userSpaceOnUse | objectBoundingBox" -const char * const GRADIENT_SPREAD_METHOD_NAME("gradient-spread-method"); // Property::String "pad | reflect | repeat" +const char * const STOP_OFFSET_NAME("stopOffset"); // Property::Array FLOAT +const char * const STOP_COLOR_NAME("stopColor"); // Property::Array VECTOR4 +const char * const UNITS_NAME("units"); // Property::String "userSpaceOnUse | objectBoundingBox" +const char * const SPREAD_METHOD_NAME("spreadMethod"); // Property::String "pad | reflect | repeat" // string values -const char * const UNIT_USER_SPACE("user-space"); -const char * const UNIT_BOUNDING_BOX("object-bounding-box"); +const char * const UNIT_USER_SPACE("userSpace"); +const char * const UNIT_BOUNDING_BOX("objectBoundingBox"); const char * const SPREAD_PAD("pad"); const char * const SPREAD_REFLECT("reflect"); const char * const SPREAD_REPEAT("repeat"); // uniform names const char * const UNIFORM_ALIGNMENT_MATRIX_NAME( "uAlignmentMatrix" ); -const char * const UNIFORM_TEXTULRE_NAME("sTexture"); + +// default offset value +const unsigned int DEFAULT_OFFSET_MINIMUM = 0.0f; +const unsigned int DEFAULT_OFFSET_MAXIMUM = 1.0f; RendererFactoryCache::ShaderType GetShaderType( GradientRenderer::Type type, Gradient::GradientUnits units) { @@ -188,10 +191,10 @@ GradientRenderer::~GradientRenderer() { } -void GradientRenderer::DoInitialize( const Property::Map& propertyMap ) +void GradientRenderer::DoInitialize( Actor& actor, const Property::Map& propertyMap ) { Gradient::GradientUnits gradientUnits = Gradient::OBJECT_BOUNDING_BOX; - Property::Value* unitsValue = propertyMap.Find( GRADIENT_UNITS_NAME ); + Property::Value* unitsValue = propertyMap.Find( UNITS_NAME ); std::string units; // The default unit is OBJECT_BOUNDING_BOX. // Only need to set new units if 'user-space' @@ -201,7 +204,7 @@ void GradientRenderer::DoInitialize( const Property::Map& propertyMap ) } mGradientType = LINEAR; - if( propertyMap.Find( GRADIENT_RADIUS_NAME )) + if( propertyMap.Find( RADIUS_NAME )) { mGradientType = RADIAL; } @@ -234,6 +237,11 @@ void GradientRenderer::SetOffset( const Vector2& offset ) //ToDo: renderer applies the offset } +void GradientRenderer::DoSetOnStage( Actor& actor ) +{ + InitializeRenderer(); +} + void GradientRenderer::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); @@ -242,25 +250,25 @@ void GradientRenderer::DoCreatePropertyMap( Property::Map& map ) const Gradient::GradientUnits units = mGradient->GetGradientUnits(); if( units == Gradient::USER_SPACE_ON_USE ) { - map.Insert( GRADIENT_UNITS_NAME, UNIT_USER_SPACE ); + map.Insert( UNITS_NAME, UNIT_USER_SPACE ); } else // if( units == Gradient::OBJECT_BOUNDING_BOX ) { - map.Insert( GRADIENT_UNITS_NAME, UNIT_BOUNDING_BOX ); + map.Insert( UNITS_NAME, UNIT_BOUNDING_BOX ); } Gradient::SpreadMethod spread = mGradient->GetSpreadMethod(); if( spread == Gradient::PAD ) { - map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_PAD ); + map.Insert( SPREAD_METHOD_NAME, SPREAD_PAD ); } else if( spread == Gradient::REFLECT ) { - map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REFLECT ); + map.Insert( SPREAD_METHOD_NAME, SPREAD_REFLECT ); } else // if( units == Gradient::REPEAT ) { - map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REPEAT ); + map.Insert( SPREAD_METHOD_NAME, SPREAD_REPEAT ); } const Vector& stops( mGradient->GetStops() ); @@ -272,24 +280,24 @@ void GradientRenderer::DoCreatePropertyMap( Property::Map& map ) const colors.PushBack( stops[i].mStopColor ); } - map.Insert( GRADIENT_STOP_OFFSET_NAME, offsets ); - map.Insert( GRADIENT_STOP_COLOR_NAME, colors ); + map.Insert( STOP_OFFSET_NAME, offsets ); + map.Insert( STOP_COLOR_NAME, colors ); if( &typeid( *mGradient ) == &typeid(LinearGradient) ) { LinearGradient* gradient = static_cast( mGradient.Get() ); - map.Insert( GRADIENT_START_POSITION_NAME, gradient->GetStartPosition() ); - map.Insert( GRADIENT_END_POSITION_NAME, gradient->GetEndPosition() ); + map.Insert( START_POSITION_NAME, gradient->GetStartPosition() ); + map.Insert( END_POSITION_NAME, gradient->GetEndPosition() ); } else // if( &typeid( *mGradient ) == &typeid(RadialGradient) ) { RadialGradient* gradient = static_cast( mGradient.Get() ); - map.Insert( GRADIENT_CENTER_NAME, gradient->GetCenter() ); - map.Insert( GRADIENT_RADIUS_NAME, gradient->GetRadius() ); + map.Insert( CENTER_NAME, gradient->GetCenter() ); + map.Insert( RADIUS_NAME, gradient->GetRadius() ); } } -void GradientRenderer::InitializeRenderer( Dali::Renderer& renderer ) +void GradientRenderer::InitializeRenderer() { Geometry geometry = mFactoryCache.GetGeometry( RendererFactoryCache::QUAD_GEOMETRY ); if( !geometry ) @@ -307,38 +315,27 @@ void GradientRenderer::InitializeRenderer( Dali::Renderer& renderer ) mFactoryCache.SaveShader( shaderType, shader ); } - Material material; - if( !renderer ) - { - material = Material::New( shader ); - renderer = Renderer::New( geometry, material ); - } - else - { - mImpl->mRenderer.SetGeometry( geometry ); - material = mImpl->mRenderer.GetMaterial(); - if( material ) - { - material.SetShader( shader ); - } - } - + //Set up the texture set + TextureSet textureSet = TextureSet::New(); Dali::BufferImage lookupTexture = mGradient->GenerateLookupTexture(); - Sampler sampler = Sampler::New(); + textureSet.SetImage( 0u, lookupTexture ); Dali::WrapMode::Type wrap = GetWrapMode( mGradient->GetSpreadMethod() ); + Sampler sampler = Sampler::New(); sampler.SetWrapMode( wrap, wrap ); + textureSet.SetSampler( 0u, sampler ); - material.AddTexture( lookupTexture, UNIFORM_TEXTULRE_NAME, sampler ); + mImpl->mRenderer = Renderer::New( geometry, shader ); + mImpl->mRenderer.SetTextures( textureSet ); - renderer.RegisterProperty( UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform ); + mImpl->mRenderer.RegisterProperty( UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform ); } bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& propertyMap) { if( gradientType==LINEAR ) { - Property::Value* startPositionValue = propertyMap.Find( GRADIENT_START_POSITION_NAME ); - Property::Value* endPositionValue = propertyMap.Find( GRADIENT_END_POSITION_NAME ); + Property::Value* startPositionValue = propertyMap.Find( START_POSITION_NAME ); + Property::Value* endPositionValue = propertyMap.Find( END_POSITION_NAME ); Vector2 startPosition; Vector2 endPosition; @@ -354,8 +351,8 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope } else // type==RADIAL { - Property::Value* centerValue = propertyMap.Find( GRADIENT_CENTER_NAME ); - Property::Value* radiusValue = propertyMap.Find( GRADIENT_RADIUS_NAME ); + Property::Value* centerValue = propertyMap.Find( CENTER_NAME ); + Property::Value* radiusValue = propertyMap.Find( RADIUS_NAME ); Vector2 center; float radius; if( centerValue && centerValue->Get(center) @@ -370,14 +367,15 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope } unsigned int numValidStop = 0u; - Property::Value* stopOffsetValue = propertyMap.Find( GRADIENT_STOP_OFFSET_NAME ); - Property::Value* stopColorValue = propertyMap.Find( GRADIENT_STOP_COLOR_NAME ); - if( stopOffsetValue && stopColorValue ) + Property::Value* stopOffsetValue = propertyMap.Find( STOP_OFFSET_NAME ); + Property::Value* stopColorValue = propertyMap.Find( STOP_COLOR_NAME ); + if( stopColorValue ) { Vector offsetArray; Property::Array* colorArray = stopColorValue->GetArray(); - if( colorArray && GetStopOffsets( stopOffsetValue, offsetArray )) + if( colorArray ) { + GetStopOffsets( stopOffsetValue, offsetArray ); unsigned int numStop = offsetArray.Count() < colorArray->Count() ? offsetArray.Count() : colorArray->Count(); Vector4 color; @@ -397,7 +395,7 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope return false; } - Property::Value* spread = propertyMap.Find( GRADIENT_SPREAD_METHOD_NAME ); + Property::Value* spread = propertyMap.Find( SPREAD_METHOD_NAME ); std::string stringValue ; // The default spread method is PAD. // Only need to set new spread if 'reflect' or 'repeat" @@ -416,51 +414,68 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope return true; } -bool GradientRenderer::GetStopOffsets(const Property::Value* value, Vector& stopOffsets) +void GradientRenderer::GetStopOffsets(const Property::Value* value, Vector& stopOffsets) { - Vector2 offset2; - if( value->Get( offset2 ) ) - { - stopOffsets.PushBack( offset2.x ); - stopOffsets.PushBack( offset2.y ); - return true; - } - - Vector3 offset3; - if( value->Get( offset3 ) ) - { - stopOffsets.PushBack( offset3.x ); - stopOffsets.PushBack( offset3.y ); - stopOffsets.PushBack( offset3.z ); - return true; - } - - Vector4 offset4; - if( value->Get( offset4 ) ) - { - stopOffsets.PushBack( offset4.x ); - stopOffsets.PushBack( offset4.y ); - stopOffsets.PushBack( offset4.z ); - stopOffsets.PushBack( offset4.w ); - return true; - } - Property::Array* offsetArray = value->GetArray(); - if( offsetArray ) + if ( value ) // Only check valve type if a valid Property has been passed in { - unsigned int numStop = offsetArray->Count(); - float offset; - for( unsigned int i=0; iGetType() ) { - if( offsetArray->GetElementAt(i).Get(offset) ) + case Property::VECTOR2: + { + Vector2 offset2; + value->Get( offset2 ); + stopOffsets.PushBack( offset2.x ); + stopOffsets.PushBack( offset2.y ); + break; + } + case Property::VECTOR3: + { + Vector3 offset3; + value->Get( offset3 ); + stopOffsets.PushBack( offset3.x ); + stopOffsets.PushBack( offset3.y ); + stopOffsets.PushBack( offset3.z ); + break; + } + case Property::VECTOR4: { - stopOffsets.PushBack( offset ); + Vector4 offset4; + value->Get( offset4 ); + stopOffsets.PushBack( offset4.x ); + stopOffsets.PushBack( offset4.y ); + stopOffsets.PushBack( offset4.z ); + stopOffsets.PushBack( offset4.w ); + break; + } + case Property::ARRAY: + { + Property::Array* offsetArray = value->GetArray(); + unsigned int numStop = offsetArray->Count(); + float offset; + for( unsigned int i=0; iGetElementAt(i).Get(offset) ) + { + stopOffsets.PushBack( offset ); + } + } + break; + } + default: + { + DALI_LOG_WARNING("GetStopOffsets passed unsupported Property Map\n"); + // Unsupported Type } } - return true; } - return false; + if ( stopOffsets.Empty() ) + { + // Set default offset if none set by Property system, need a minimum and maximum + stopOffsets.PushBack( DEFAULT_OFFSET_MINIMUM ); + stopOffsets.PushBack( DEFAULT_OFFSET_MAXIMUM ); + } } } // namespace Internal