From fcc666716f42510adc17d894e443a86148c0f412 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 2 Nov 2016 19:33:03 +0000 Subject: [PATCH] Updated control transitions to work with visual transform Modified Transform::SetPropertyMap() to handle string keys ( for styled transitions that set initial values ) Added GetRenderer to Internal::Visual::Base (not public) ( To allow control to access renderer's registered properties ) Changed Control::Impl::GetVisualProperty to ignore actor properties and instead only use renderer properties. ( Allows transform::size to be accessed ) Ensured RegisterVisual automatically names un-named visuals to match the name of the property they are associated with. (This makes it easy to wire up styled transitions to visuals). Added a new method AddTransitions() to Internal::Control. This enables the styled transition framework to add multiple animators to a single animation. (slightly controversial - this is a new public API, which should be a Devel API, but is really hard to implement - an alternative approach is currently being looked at, on which this may have to be rebased. Change-Id: Ia3a1365594a1367fec9af09b9481f8696aef1d76 Signed-off-by: David Steele --- .../dali-toolkit-test-utils/dummy-control.cpp | 16 +++ .../dali-toolkit-test-utils/dummy-control.h | 19 +++- .../src/dali-toolkit/utc-Dali-TransitionData.cpp | 109 ++++++++++++--------- .../src/dali-toolkit/utc-Dali-Visual.cpp | 25 ++++- .../devel-api/visual-factory/visual-base.cpp | 3 + .../internal/visuals/visual-base-data-impl.cpp | 76 ++++++++++---- dali-toolkit/internal/visuals/visual-base-impl.cpp | 20 ++++ dali-toolkit/internal/visuals/visual-base-impl.h | 6 ++ dali-toolkit/public-api/controls/control-impl.cpp | 63 ++++++------ 9 files changed, 235 insertions(+), 102 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp index f44fa71..e8c266d 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp @@ -67,6 +67,10 @@ BaseHandle Create() DALI_TYPE_REGISTRATION_BEGIN( Toolkit::DummyControl, Toolkit::Control, Create ); DALI_TYPE_REGISTRATION_END() + +Dali::PropertyRegistration dummyControlVisualProperty( + typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty ); + } DummyControl DummyControlImpl::New() @@ -135,6 +139,18 @@ Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& tra return Control::CreateTransition( transition ); } +void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ) +{ +} + +Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex ) +{ + Dali::Property::Value value; + return value; +} + + + DummyControl DummyControlImplOverride::New() { IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h index 95b4126..a425330 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h @@ -28,13 +28,26 @@ namespace Toolkit { class DummyControlImpl; -class ControlRenderer; + /** * Control does not have a New method so use this dummy class for the handle. */ class DummyControl : public Control { public: + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0 + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property index + }; + + struct Property + { + enum Type + { + TEST_VISUAL = PROPERTY_START_INDEX + }; + }; DummyControl(); DummyControl(const DummyControl& control); @@ -80,6 +93,10 @@ public: Toolkit::Visual::Base GetVisual( Property::Index index ); Animation CreateTransition( const Toolkit::TransitionData& transition ); + static void SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + + static Property::Value GetProperty( BaseObject* object, Dali::Property::Index propertyIndex ); + // Used to test signal connections void CustomSlot1( Actor actor ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp index c0f7982..58559d5 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp @@ -338,22 +338,21 @@ int UtcDaliTransitionDataMap2P(void) END_TEST; } - int UtcDaliTransitionDataMap3P(void) { TestApplication application; - tet_printf("Testing animation of a visual's placement actor property\n"); + tet_printf("Testing animation of an actor's position property using bezier curve\n"); Property::Map map; - map["target"] = "visual1"; - map["property"] = "color"; - map["initialValue"] = Color::MAGENTA; - map["targetValue"] = Color::RED; + map["target"] = "Actor1"; + map["property"] = "position"; + map["initialValue"] = Vector3(0, 0, 0); + map["targetValue"] = Vector3(100, 100, 0); map["animator"] = Property::Map() - .Add("alphaFunction", "EASE_IN_OUT") + .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) ) .Add("timePeriod", Property::Map() - .Add("delay", 0.5f) + .Add("delay", 0.0f) .Add("duration", 1.0f)); Dali::Toolkit::TransitionData transition = TransitionData::New( map ); @@ -361,39 +360,36 @@ int UtcDaliTransitionDataMap3P(void) DummyControl actor = DummyControl::New(); actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); actor.SetName("Actor1"); - actor.SetColor(Color::CYAN); Stage::GetCurrent().Add(actor); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - - Property::Map visualMap; - visualMap[Visual::Property::TYPE] = Visual::COLOR; - visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; - Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); - visual.SetName( "visual1" ); - - Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1; - dummyImpl.RegisterVisual( visualIndex, visual ); - Animation anim = dummyImpl.CreateTransition( transition ); DALI_TEST_CHECK( anim ); application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION); anim.Play(); application.SendNotification(); application.Render(0); - application.Render(500); - application.Render(500); // Halfway thru map1 anim + + application.Render(250); // 25% application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(-10,-10,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% - application.Render(500); // End of map1 anim + application.Render(250); // Halfway thru map1 anim application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(24,24,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% + + application.Render(250); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve + + application.Render(250); // End of map1 anim + application.SendNotification(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION ); END_TEST; } @@ -402,20 +398,31 @@ int UtcDaliTransitionDataMap4P(void) { TestApplication application; - tet_printf("Testing animation of a visual's placement actor property using bezier curve\n"); + tet_printf("Testing animation of a visual's transform property using programmatic maps\n"); - Property::Map map; - map["target"] = "Actor1"; - map["property"] = "position"; - map["initialValue"] = Vector3(0, 0, 0); - map["targetValue"] = Vector3(100, 100, 0); - map["animator"] = Property::Map() - .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) ) + Property::Map map1; + map1["target"] = "testVisual"; + map1["property"] = "offset"; + map1["initialValue"] = Vector2(0.0f, 0.0f); + map1["targetValue"] = Vector2(100.0f, 100.0f); + map1["animator"] = Property::Map() + .Add("alphaFunction", "LINEAR") .Add("timePeriod", Property::Map() - .Add("delay", 0.0f) + .Add("delay", 0.5f) .Add("duration", 1.0f)); - Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + Property::Map map2; + map2["target"] = "testVisual"; + map2["property"] = "size"; + map2["initialValue"] = Vector2(10.0f, 10.0f); + map2["targetValue"] = Vector2(110.0f, 110.0f); + map2["animator"] = Property::Map() + .Add("alphaFunction", "LINEAR") + .Add("timePeriod", Property::Map() + .Add("delay", 0.5f) + .Add("duration", 1.0f)); + + Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) ); DummyControl actor = DummyControl::New(); actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); @@ -423,36 +430,42 @@ int UtcDaliTransitionDataMap4P(void) Stage::GetCurrent().Add(actor); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + + Property::Map visualMap; + visualMap[Visual::Property::TYPE] = Visual::COLOR; + visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA; + Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap ); + + visual.SetName( "testVisual" ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + Animation anim = dummyImpl.CreateTransition( transition ); DALI_TEST_CHECK( anim ); + Renderer renderer = actor.GetRendererAt(0); + Property::Index sizeIndex = renderer.GetPropertyIndex( "size" ); application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION); + + DALI_TEST_EQUALS( renderer.GetProperty(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION); anim.Play(); application.SendNotification(); application.Render(0); - - application.Render(250); // 25% - application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(-10,-10,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% - - application.Render(250); // Halfway thru map1 anim + application.Render(500); // Start animation + application.Render(500); // Halfway thru anim application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(24,24,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50% + DALI_TEST_EQUALS( renderer.GetProperty(sizeIndex), Vector2(60.0f, 60.0f), TEST_LOCATION); - application.Render(250); // End of map1 anim + application.Render(500); // End of anim application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve + DALI_TEST_EQUALS( renderer.GetProperty(sizeIndex), Vector2(110.0f, 110.0f), TEST_LOCATION ); - application.Render(250); // End of map1 anim - application.SendNotification(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION ); END_TEST; } + int UtcDaliTransitionDataMap1N(void) { TestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 563c593..fae713a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -1532,6 +1532,15 @@ int UtcDaliNPatchVisualCustomShader(void) Property::Map shader; const std::string fragmentShader = "Foobar"; shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader; + + Property::Map transformMap; + transformMap["size"] = Vector2( 0.5f, 0.5f ) ; + transformMap["offset"] = Vector2( 20.0f, 0.0f ) ; + transformMap["offsetSizeMode"] = Vector4( 1.0f, 1.0f, 0.0f, 0.0f ); + transformMap["anchorPoint"] = Align::CENTER; + transformMap["origin"] = Align::CENTER; + properties[DevelVisual::Property::TRANSFORM] = transformMap; + properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; properties[Dali::Toolkit::Visual::Property::SHADER]=shader; properties[Dali::Toolkit::ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME; @@ -1545,6 +1554,7 @@ int UtcDaliNPatchVisualCustomShader(void) dummy.SetSize(2000, 2000); dummy.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(dummy); + application.SendNotification(); Renderer renderer = dummy.GetRendererAt( 0 ); Shader shader2 = renderer.GetShader(); @@ -1552,6 +1562,9 @@ int UtcDaliNPatchVisualCustomShader(void) Property::Map* map = value.GetMap(); DALI_TEST_CHECK( map ); + Property::Index index = renderer.GetPropertyIndex("size"); + DALI_TEST_EQUALS( renderer.GetProperty( index ), Property::Value(Vector2(0.5, 0.5)), 0.001, TEST_LOCATION ); + Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp // *map["vertex"]; is default here so not verifying it @@ -1677,6 +1690,7 @@ int UtcDaliVisualTextVisualRender(void) DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 0, TEST_LOCATION ); dummyControl.SetSize(200.f, 200.f); + dummyControl.SetParentOrigin( ParentOrigin::CENTER ); Stage::GetCurrent().Add( dummyControl ); application.SendNotification(); @@ -1691,7 +1705,7 @@ int UtcDaliVisualTextVisualRender(void) propertyMap.Insert( TextVisual::Property::MULTI_LINE, true ); Property::Map transformMap; - transformMap.Insert( DevelVisual::Transform::Property::SIZE, Vector2( 720.f, 640.f ) ); + transformMap.Insert( "size", Vector2( 0.5f, 0.5f ) ); propertyMap.Insert( DevelVisual::Property::TRANSFORM, transformMap ); textVisual = factory.CreateVisual( propertyMap ); @@ -1700,9 +1714,16 @@ int UtcDaliVisualTextVisualRender(void) dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, textVisual ); dummyControl.SetSize( 720.f, 640.f ); - application.SendNotification(); + application.SendNotification(); // force process events to ensure text visual + // adds renderer to the dummy control in OnRelayout application.Render(); + Renderer renderer = dummyControl.GetRendererAt(0u); + Property::Index index = renderer.GetPropertyIndex("size"); + + tet_infoline( "Test that the TextVisual overrides anything set by developer" ); + DALI_TEST_EQUALS( renderer.GetProperty(index), Vector2( 1.0, 1.0 ), 0.001f, TEST_LOCATION ); + END_TEST; } diff --git a/dali-toolkit/devel-api/visual-factory/visual-base.cpp b/dali-toolkit/devel-api/visual-factory/visual-base.cpp index eea2b44..6a19c9b 100644 --- a/dali-toolkit/devel-api/visual-factory/visual-base.cpp +++ b/dali-toolkit/devel-api/visual-factory/visual-base.cpp @@ -96,6 +96,9 @@ void Visual::Base::CreatePropertyMap( Property::Map& map ) const GetImplementation( *this ).CreatePropertyMap( map ); } + + + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp index 489dfb6..f8d3e5f 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp @@ -208,7 +208,7 @@ Internal::Visual::Base::Impl::Transform::Transform() void Internal::Visual::Base::Impl::Transform::SetPropertyMap( const Property::Map& map ) { - //Set default values + // Set default values mOffset = Vector2( 0.0f,0.0f ); mSize = Vector2( 1.0f,1.0f ); mOffsetSizeMode = Vector4( 0.0f,0.0f,0.0f,0.0f ); @@ -218,33 +218,67 @@ void Internal::Visual::Base::Impl::Transform::SetPropertyMap( const Property::Ma for( Property::Map::SizeType i(0); i( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, align ) ) + switch( keyValue.first.indexKey ) { - mOrigin = align; + case Toolkit::DevelVisual::Transform::Property::OFFSET: + { + keyValue.second.Get( mOffset ); + break; + } + case Toolkit::DevelVisual::Transform::Property::SIZE: + { + keyValue.second.Get( mSize ); + break; + } + case Toolkit::DevelVisual::Transform::Property::ORIGIN: + { + Scripting::GetEnumerationProperty< Toolkit::Align::Type >( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, mOrigin ); + break; + } + case Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT: + { + Scripting::GetEnumerationProperty< Toolkit::Align::Type >( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, mAnchorPoint ); + break; + } + case Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE: + { + keyValue.second.Get( mOffsetSizeMode ); + break; + } } } - else if( keyValue.first == Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT ) + else // Key type is STRING { - Toolkit::Align::Type align(Toolkit::Align::CENTER); - if( Scripting::GetEnumerationProperty< Toolkit::Align::Type >( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, align ) ) + if( keyValue.first == "offset" ) { - mAnchorPoint = align; + keyValue.second.Get( mOffset ); + } + else if( keyValue.first == "size" ) + { + keyValue.second.Get( mSize ); + } + else if( keyValue.first == "origin" ) + { + Toolkit::Align::Type align(Toolkit::Align::CENTER); + if( Scripting::GetEnumerationProperty< Toolkit::Align::Type >( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, align ) ) + { + mOrigin = align; + } + } + else if( keyValue.first == "anchorPoint" ) + { + Toolkit::Align::Type align(Toolkit::Align::CENTER); + if( Scripting::GetEnumerationProperty< Toolkit::Align::Type >( keyValue.second, ALIGN_TABLE, ALIGN_TABLE_COUNT, align ) ) + { + mAnchorPoint = align; + } + } + else if( keyValue.first == "offsetSizeMode" ) + { + keyValue.second.Get( mOffsetSizeMode ); } - } - else if( keyValue.first == Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE ) - { - keyValue.second.Get( mOffsetSizeMode ); } } } diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 0958afa..5815c4a 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -27,6 +27,13 @@ #include #include +namespace +{ +#if defined(DEBUG_ENABLED) +Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VISUAL_BASE" ); +#endif +} + namespace Dali { @@ -107,6 +114,14 @@ void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size con { mImpl->mControlSize = controlSize; mImpl->mTransform.SetPropertyMap( transform ); + +#if defined(DEBUG_ENABLED) + std::ostringstream oss; + oss << transform; + DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s controlSize: (%3.1f, %3.1f)]\e[0m\n", + GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y ); +#endif + OnSetTransform(); } @@ -245,6 +260,11 @@ bool Visual::Base::IsFromCache() const return mImpl->mFlags & Impl::IS_FROM_CACHE; } +Renderer Visual::Base::GetRenderer() +{ + return mImpl->mRenderer; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 1a84b2d..f496467 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -22,6 +22,7 @@ #include #include #include +#include #include // INTERNAL INCLUDES @@ -157,6 +158,11 @@ public: */ Dali::Property::Value GetProperty( Dali::Property::Index index ); + /** + * Gets currently staged renderer, or an empty handle if not staged + */ + Renderer GetRenderer(); + protected: /** diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 2ac22fa..71398c8 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -22,6 +22,7 @@ #include // for strcmp #include #include +#include #include #include #include @@ -57,7 +58,7 @@ namespace { #if defined(DEBUG_ENABLED) -Debug::Filter* gLogFilter = Debug::Filter::New( Debug::General, false, "LOG_CONTROL_VISUALS"); +Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS"); #endif /** @@ -117,7 +118,7 @@ HandleIndex GetVisualProperty( { #if defined(DEBUG_ENABLED) std::ostringstream oss; - oss << "Control::GetHandleIndex(" << visualName << ", " << propertyKey << ")" << std::endl; + oss << "Control::GetVisualProperty(" << visualName << ", " << propertyKey << ")" << std::endl; DALI_LOG_INFO( gLogFilter, Debug::General, oss.str().c_str() ); #endif @@ -125,44 +126,25 @@ HandleIndex GetVisualProperty( RegisteredVisualContainer::Iterator iter; for ( iter = visuals.Begin(); iter != visuals.End(); iter++ ) { - if ( (*iter)->visual.GetName() == visualName ) + Toolkit::Visual::Base visual = (*iter)->visual; + if( visual && visual.GetName() == visualName ) { - break; - } - } - - // Does it's renderer have an associated property? - if( iter != visuals.End() ) - { - Actor self = controlImpl.Self(); - Property::Index index = DevelHandle::GetPropertyIndex( self, propertyKey ); - if( index != Property::INVALID_INDEX ) - { - // It's an actor property: - return HandleIndex( self, index ); - } - else - { - // Check if it is a renderer property: - if( self.GetRendererCount() > 0 ) + Internal::Visual::Base& visualImpl = GetImplementation(visual); + Renderer renderer = visualImpl.GetRenderer(); + if( renderer ) { - // @todo Need to use correct renderer index - Renderer renderer = self.GetRendererAt(0); Property::Index index = DevelHandle::GetPropertyIndex( renderer, propertyKey ); if( index != Property::INVALID_INDEX ) { - // It's a renderer property: return HandleIndex( renderer, index ); } } - else - { - std::ostringstream oss; - oss << propertyKey; - DALI_LOG_WARNING( "Control::GetHandleIndex(%s, %s) No renderers\n", visualName.c_str(), oss.str().c_str() ); - } } } + + std::ostringstream noRenderers; + noRenderers << propertyKey; + DALI_LOG_WARNING( "Control::GetVisualProperty(%s, %s) No renderers\n", visualName.c_str(), noRenderers.str().c_str() ); Handle handle; return HandleIndex( handle, Property::INVALID_INDEX ); } @@ -785,6 +767,27 @@ void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visu } } + // If not set, set the name of the visual to the same name as the control's property. + // ( If the control has been type registered ) + if( visual.GetName().empty() ) + { + // Check if the control has been type registered: + TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) ); + if( typeInfo ) + { + // Check if the property index has been registered: + Property::IndexContainer indices; + typeInfo.GetPropertyIndices( indices ); + Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index ); + if( iter != indices.End() ) + { + // If it has, then get it's name and use that for the visual + std::string visualName = typeInfo.GetPropertyName( index ); + visual.SetName( visualName ); + } + } + } + if( !visualReplaced ) // New registration entry { mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) ); -- 2.7.4