From 535870c8f9a4033ea411b89d30f2ddc1342ac7ee Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 5 Jun 2017 13:34:35 +0100 Subject: [PATCH] (Visuals) If depth index not specified, then visual depth indices are set in order they are registered Change-Id: I720bbee7cd9588332b759621d204fa7cd20224ff --- .../src/dali-toolkit/utc-Dali-ControlWrapper.cpp | 82 ++++++++++++++++++- .../src/dali-toolkit/utc-Dali-Visual.cpp | 95 ++++++++++++++++++++++ dali-toolkit/devel-api/controls/control-devel.cpp | 12 +++ dali-toolkit/devel-api/controls/control-devel.h | 46 +++++++++-- .../devel-api/controls/control-wrapper-impl.cpp | 10 +++ .../devel-api/controls/control-wrapper-impl.h | 10 +++ .../internal/controls/buttons/button-impl.cpp | 3 +- .../controls/control/control-data-impl.cpp | 67 +++++++++++++-- .../internal/controls/control/control-data-impl.h | 48 +++++++++++ .../controls/effects-view/effects-view-impl.cpp | 3 +- .../controls/progress-bar/progress-bar-impl.cpp | 5 +- .../super-blur-view/super-blur-view-impl.cpp | 6 +- .../text-controls/text-selection-popup-impl.cpp | 3 +- dali-toolkit/public-api/controls/control-impl.cpp | 6 +- 14 files changed, 365 insertions(+), 31 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlWrapper.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlWrapper.cpp index 8caf518..93e47ff 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlWrapper.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlWrapper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -405,6 +405,43 @@ int UtcDaliControlWrapperRegisterVisualToSelf(void) END_TEST; } +int UtcDaliControlWrapperRegisterVisualWithDepthIndexToSelf(void) +{ + ToolkitTestApplication application; + + Test::ObjectDestructionTracker objectDestructionTracker; + + { + Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT ); + ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl ); + + objectDestructionTracker.Start( controlWrapper ); + + Property::Index index = 1; + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK( visual ); + + // Register to self + controlWrapperImpl->RegisterVisual( index, visual, 4.0f ); + + DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), false, TEST_LOCATION ); // Control not destroyed yet + DALI_TEST_EQUALS( controlWrapperImpl->GetVisual( index ), visual, TEST_LOCATION ); + DALI_TEST_EQUALS( visual.GetDepthIndex(), 4.0f, TEST_LOCATION ); + } + + DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), true, TEST_LOCATION ); // Should be destroyed + + END_TEST; +} + int UtcDaliControlWrapperRegisterDisabledVisual(void) { ToolkitTestApplication application; @@ -447,6 +484,49 @@ int UtcDaliControlWrapperRegisterDisabledVisual(void) END_TEST; } +int UtcDaliControlWrapperRegisterDisabledVisualWithDepthIndex(void) +{ + ToolkitTestApplication application; + + Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT ); + ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl ); + + Property::Index TEST_PROPERTY = 1; + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // Register index with a color visual + controlWrapperImpl->RegisterVisual( TEST_PROPERTY, visual, false, 10.0f ); + + DALI_TEST_EQUALS( controlWrapperImpl->GetVisual( TEST_PROPERTY ), visual, TEST_LOCATION ); + DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( visual.GetDepthIndex(), 10.0f, TEST_LOCATION ); + + Stage::GetCurrent().Add( controlWrapper ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION ); + + DALI_TEST_EQUALS( controlWrapper.OnStage(), true, TEST_LOCATION ); + + controlWrapperImpl->EnableVisual( TEST_PROPERTY, true ); + + DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), true, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliControlWrapperRegisterUnregisterVisual(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 1222bd5..c121a53 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -2080,3 +2081,97 @@ int UtcDaliVisualPremultipliedAlpha(void) END_TEST; } + +int UtcDaliRegisterVisualOrder(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register Visual Order" ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + tet_infoline( "Register visual, should have depth index of 0.0f" ); + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, testVisual ); + DALI_TEST_EQUALS( testVisual.GetDepthIndex(), 0.0f, TEST_LOCATION ); + + tet_infoline( "Register more visuals, each added one should have a depth index greater than previous" ); + + Visual::Base testVisual2 = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, testVisual2 ); + DALI_TEST_CHECK( testVisual2.GetDepthIndex() > testVisual.GetDepthIndex() ); + + Visual::Base foregroundVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::FOREGROUND_VISUAL, foregroundVisual ); + DALI_TEST_CHECK( foregroundVisual.GetDepthIndex() > testVisual2.GetDepthIndex() ); + + Visual::Base focusVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::FOCUS_VISUAL, focusVisual ); + DALI_TEST_CHECK( focusVisual.GetDepthIndex() > foregroundVisual.GetDepthIndex() ); + + tet_infoline( "Set depth index on a new visual before registering, the depth index should not have been changed" ); + Visual::Base labelVisual = factory.CreateVisual( propertyMap ); + labelVisual.SetDepthIndex( -2000.0f ); + dummyImpl.RegisterVisual( DummyControl::Property::LABEL_VISUAL, labelVisual ); + DALI_TEST_EQUALS( labelVisual.GetDepthIndex(), -2000.0f, TEST_LOCATION ); + + tet_infoline( "Replace visual, the depth index should be the same as what was previously set" ); + const float testVisual2DepthIndex = testVisual2.GetDepthIndex(); + Visual::Base testVisual2Replacement = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( testVisual2Replacement.GetDepthIndex() != testVisual2DepthIndex ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, testVisual2Replacement ); + DALI_TEST_EQUALS( testVisual2Replacement.GetDepthIndex(), testVisual2DepthIndex, TEST_LOCATION ); + + tet_infoline( "Replace visual and set a depth index on the replacement, the depth index of the replacement should be honoured" ); + Visual::Base anotherTestVisual2Replacement = factory.CreateVisual( propertyMap ); + anotherTestVisual2Replacement.SetDepthIndex( 2000.0f ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, anotherTestVisual2Replacement ); + DALI_TEST_EQUALS( anotherTestVisual2Replacement.GetDepthIndex(), 2000.0f, TEST_LOCATION ); + + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + END_TEST; +} + +int UtcDaliRegisterVisualWithDepthIndex(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register a Visual With Depth Index" ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + tet_infoline( "Register a visual with a depth index, it should be enabled by default too" ); + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, testVisual, 203.0f ); + DALI_TEST_EQUALS( testVisual.GetDepthIndex(), 203.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL ), true, TEST_LOCATION ); + + tet_infoline( "Register another visual with a depth index and it disabled" ); + Visual::Base testVisual2 = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, testVisual2, false, 450.0f ); + DALI_TEST_EQUALS( testVisual2.GetDepthIndex(), 450.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL2 ), false, TEST_LOCATION ); + + tet_infoline( "Register another visual with a depth index and it enabled using the enabled API" ); + Visual::Base testVisual3 = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, testVisual3, true, 300.0f ); + DALI_TEST_EQUALS( testVisual3.GetDepthIndex(), 300.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL2 ), true, TEST_LOCATION ); + + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/control-devel.cpp b/dali-toolkit/devel-api/controls/control-devel.cpp index 77b2368..ba249a9 100644 --- a/dali-toolkit/devel-api/controls/control-devel.cpp +++ b/dali-toolkit/devel-api/controls/control-devel.cpp @@ -57,12 +57,24 @@ void RegisterVisual( Internal::Control& control, Dali::Property::Index index, To controlImpl.RegisterVisual( index, visual ); } +void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ) +{ + Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( control ); + controlImpl.RegisterVisual( index, visual, depthIndex ); +} + void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled ) { Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( control ); controlImpl.RegisterVisual( index, visual, enabled ); } +void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ) +{ + Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( control ); + controlImpl.RegisterVisual( index, visual, enabled, depthIndex ); +} + void UnregisterVisual( Internal::Control& control, Dali::Property::Index index ) { Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( control ); diff --git a/dali-toolkit/devel-api/controls/control-devel.h b/dali-toolkit/devel-api/controls/control-devel.h index 7795df1..f6d5b38 100644 --- a/dali-toolkit/devel-api/controls/control-devel.h +++ b/dali-toolkit/devel-api/controls/control-devel.h @@ -139,34 +139,66 @@ DALI_IMPORT_API ResourceReadySignalType& ResourceReadySignal( Control& control ) DALI_IMPORT_API bool IsResourceReady( const Control& control ); /** - * @brief Register a visual by Property Index, linking an Actor to visual when required. - * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle. - * No parenting is done during registration, this should be done by derived class. + * @brief Register a visual by Property Index. * * @param[in] control The control * @param[in] index The Property index of the visual, used to reference visual * @param[in] visual The visual to register + * * @note Derived class should not call visual.SetOnStage(actor). It is the responsibility of the base class to connect/disconnect registered visual to stage. * Use below API with enabled set to false if derived class wishes to control when visual is staged. + * @note If the depth-index is not set on the visual, then it is set to be above the currently registered visuals. + * @note If replacing a visual, then the depth-index of the visual being replaced is used for the visual. */ DALI_IMPORT_API void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual ); /** - * @brief Register a visual by Property Index, linking an Actor to visual when required. + * @brief Register a visual by Property Index with a depth index. + * + * @param[in] control The control + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] visual The visual to register + * @param[in] depthIndex The visual's depth-index is set to this * - * In the case of the visual being an actor or control deeming visual not required then visual should be an empty handle. - * If enabled is false then the visual is not set on stage until enabled by the derived class. - * @see EnableVisual + * @note Derived class should not call visual.SetOnStage(actor). It is the responsibility of the base class to connect/disconnect registered visual to stage. + * Use below API with enabled set to false if derived class wishes to control when visual is staged. + * + * @see Visual::Base::GetDepthIndex() + * @see Visual::Base::SetDepthIndex() + */ +DALI_IMPORT_API void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ); + +/** + * @brief Register a visual by Property Index with the option of enabling/disabling it. * * @param[in] control The control * @param[in] index The Property index of the visual, used to reference visual * @param[in] visual The visual to register * @param[in] enabled false if derived class wants to control when visual is set on stage. * + * @note If the depth-index is not set on the visual, then it is set to be above the currently registered visuals. + * @note If replacing a visual, then the depth-index of the visual being replaced is used for the visual. + * + * @see EnableVisual() */ DALI_IMPORT_API void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled ); /** + * @brief Register a visual by Property Index with a depth index with the option of enabling/disabling it. + * + * @param[in] control The control + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] visual The visual to register + * @param[in] enabled false if derived class wants to control when visual is set on stage. + * @param[in] depthIndex The visual's depth-index is set to this + * + * @see EnableVisual() + * @see Visual::Base::GetDepthIndex() + * @see Visual::Base::SetDepthIndex() + */ +DALI_IMPORT_API void RegisterVisual( Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ); + +/** * @brief Erase the entry matching the given index from the list of registered visuals * * @param[in] control The control diff --git a/dali-toolkit/devel-api/controls/control-wrapper-impl.cpp b/dali-toolkit/devel-api/controls/control-wrapper-impl.cpp index fbbfa2e..8c7a76e 100755 --- a/dali-toolkit/devel-api/controls/control-wrapper-impl.cpp +++ b/dali-toolkit/devel-api/controls/control-wrapper-impl.cpp @@ -125,11 +125,21 @@ void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Bas DevelControl::RegisterVisual( *this, index, visual ); } +void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ) +{ + DevelControl::RegisterVisual( *this, index, visual, depthIndex ); +} + void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled ) { DevelControl::RegisterVisual( *this, index, visual, enabled ); } +void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ) +{ + DevelControl::RegisterVisual( *this, index, visual, enabled, depthIndex ); +} + void ControlWrapper::UnregisterVisual( Property::Index index ) { DevelControl::UnregisterVisual( *this, index ); diff --git a/dali-toolkit/devel-api/controls/control-wrapper-impl.h b/dali-toolkit/devel-api/controls/control-wrapper-impl.h index 85bc26c..8a35ee9 100755 --- a/dali-toolkit/devel-api/controls/control-wrapper-impl.h +++ b/dali-toolkit/devel-api/controls/control-wrapper-impl.h @@ -118,9 +118,19 @@ public: // From Control /** * @ref Dali::Toolkit::DevelControl::RegisterVisual() */ + void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ); + + /** + * @ref Dali::Toolkit::DevelControl::RegisterVisual() + */ void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled ); /** + * @ref Dali::Toolkit::DevelControl::RegisterVisual() + */ + void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ); + + /** * @ref Dali::Toolkit::DevelControl::UnregisterVisual() */ void UnregisterVisual( Property::Index index ); diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index b52e46c..e8378cb 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -453,8 +453,7 @@ void Button::CreateVisualsForComponent( Property::Index index, const Property::V { DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent RegisterVisual index(%d) enabled(%s)\n", index, DevelControl::IsVisualEnabled( *this, index )?"true":"false" ); - buttonVisual.SetDepthIndex( visualDepth ); - DevelControl::RegisterVisual( *this, index, buttonVisual, DevelControl::IsVisualEnabled( *this, index ) ); + DevelControl::RegisterVisual( *this, index, buttonVisual, DevelControl::IsVisualEnabled( *this, index ), visualDepth ); } else { diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index f20e489..b04aa2a 100644 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -383,11 +384,26 @@ bool Control::Impl::IsResourceReady() const void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual ) { - RegisterVisual( index, visual, true ); + RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET ); +} + +void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ) +{ + RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex ); } void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled ) { + RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET ); +} + +void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ) +{ + RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex ); +} + +void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, float depthIndex ) +{ bool visualReplaced ( false ); Actor self = mControlImpl.Self(); @@ -402,10 +418,19 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base Toolkit::GetImplementation((*iter)->visual).SetOffStage( self ); } + // If we've not set the depth-index value and the new visual does not have a depth index applied to it, then use the previously set depth-index for this index + if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) && + EqualsZero( visual.GetDepthIndex() ) ) + { + const float currentDepthIndex = (*iter)->visual.GetDepthIndex(); + visual.SetDepthIndex( currentDepthIndex ); + } + StopObservingVisual( (*iter)->visual ); StartObservingVisual( visual ); (*iter)->visual = visual; + (*iter)->enabled = ( enabled == VisualState::ENABLED ) ? true : false; visualReplaced = true; } } @@ -433,16 +458,47 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base if( !visualReplaced ) // New registration entry { - mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) ); + mVisuals.PushBack( new RegisteredVisual( index, visual, ( enabled == VisualState::ENABLED ? true : false ) ) ); // monitor when the visuals resources are ready StartObservingVisual( visual ); + // If we've not set the depth-index value, we have more than one visual and the visual does not have a depth index, then set it to be the highest + if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) && + ( mVisuals.Size() > 1 ) && + EqualsZero( visual.GetDepthIndex() ) ) + { + float maxDepthIndex = std::numeric_limits< float >::min(); + + RegisteredVisualContainer::ConstIterator iter; + const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End(); + for ( iter = mVisuals.Begin(); iter != endIter; iter++ ) + { + const float visualDepthIndex = (*iter)->visual.GetDepthIndex(); + if ( visualDepthIndex > maxDepthIndex ) + { + maxDepthIndex = visualDepthIndex; + } + } + + ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top + visual.SetDepthIndex( maxDepthIndex ); + } } - if( visual && self.OnStage() && enabled ) + if( visual ) { - Toolkit::GetImplementation(visual).SetOnStage( self ); + // If the caller has set the depth-index, then set it here + if( depthIndexValueSet == DepthIndexValue::SET ) + { + visual.SetDepthIndex( depthIndex ); + } + + // Put on stage if enabled and the control is already on the stage + if( ( enabled == VisualState::ENABLED ) && self.OnStage() ) + { + Toolkit::GetImplementation(visual).SetOnStage( self ); + } } DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" ); @@ -737,8 +793,7 @@ void Control::Impl::SetProperty( BaseObject* object, Property::Index index, cons Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() ); if( visual ) { - controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual ); - visual.SetDepthIndex( DepthIndex::BACKGROUND ); + controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, float( DepthIndex::BACKGROUND ) ); } } else if( value.Get( color ) ) diff --git a/dali-toolkit/internal/controls/control/control-data-impl.h b/dali-toolkit/internal/controls/control/control-data-impl.h index 2ee216f..5a0a351 100644 --- a/dali-toolkit/internal/controls/control/control-data-impl.h +++ b/dali-toolkit/internal/controls/control/control-data-impl.h @@ -133,9 +133,19 @@ public: /** * @copydoc Dali::Toolkit::DevelControl::RegisterVisual() */ + void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex ); + + /** + * @copydoc Dali::Toolkit::DevelControl::RegisterVisual() + */ void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled ); /** + * @copydoc Dali::Toolkit::DevelControl::RegisterVisual() + */ + void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex ); + + /** * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual() */ void UnregisterVisual( Property::Index index ); @@ -249,6 +259,44 @@ public: */ bool IsResourceReady() const; +private: + + /** + * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled. + */ + struct VisualState + { + enum Type + { + DISABLED = 0, ///< Visual disabled. + ENABLED = 1 ///< Visual enabled. + }; + }; + + /** + * Used as an alternative to boolean so that it is obvious whether a visual's depth value has been set or not by the caller. + */ + struct DepthIndexValue + { + enum Type + { + NOT_SET = 0, ///< Visual depth value not set by caller. + SET = 1 ///< Visual depth value set by caller. + }; + }; + + /** + * @brief Adds the visual to the list of registered visuals. + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] visual The visual to register + * @param[in] enabled false if derived class wants to control when visual is set on stage + * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually + * @param[in] depthIndex The visual's depth-index is set to this + */ + void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, float depthIndex = 0.0f ); + +public: + Control& mControlImpl; DevelControl::State mState; std::string mSubStateName; diff --git a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp index db76861..4285524 100644 --- a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp +++ b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp @@ -428,8 +428,7 @@ void EffectsView::AllocateResources() mImageForChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat ); Internal::InitializeVisual( self, mVisualForChildren, mImageForChildren ); - DevelControl::RegisterVisual( *this, CHILD_VISUAL, mVisualForChildren ); - mVisualForChildren.SetDepthIndex( DepthIndex::CONTENT+1 ); + DevelControl::RegisterVisual( *this, CHILD_VISUAL, mVisualForChildren, float( DepthIndex::CONTENT + 1 ) ); mImagePostFilter = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat ); TextureSet textureSet = TextureSet::New(); diff --git a/dali-toolkit/internal/controls/progress-bar/progress-bar-impl.cpp b/dali-toolkit/internal/controls/progress-bar/progress-bar-impl.cpp index 24b1aa4..d591c5a 100755 --- a/dali-toolkit/internal/controls/progress-bar/progress-bar-impl.cpp +++ b/dali-toolkit/internal/controls/progress-bar/progress-bar-impl.cpp @@ -375,14 +375,13 @@ void ProgressBar::CreateVisualsForComponent( Property::Index index, const Proper if ( progressVisual ) { - progressVisual.SetDepthIndex( visualDepth ); if( index == Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL ) { - DevelControl::RegisterVisual( *this, index, progressVisual, mIndeterminate ); + DevelControl::RegisterVisual( *this, index, progressVisual, mIndeterminate, visualDepth ); } else { - DevelControl::RegisterVisual( *this, index, progressVisual, true ); + DevelControl::RegisterVisual( *this, index, progressVisual, true, visualDepth ); } } else diff --git a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp index 581b87e..7aa46b8 100644 --- a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp @@ -174,8 +174,7 @@ void SuperBlurView::SetImage(Image inputImage) Actor self( Self() ); mVisuals[0] = Toolkit::VisualFactory::Get().CreateVisual( mInputImage ); - DevelControl::RegisterVisual( *this, 0, mVisuals[0] ); // Will clean up previously registered visuals for this index. - mVisuals[0].SetDepthIndex(0); + DevelControl::RegisterVisual( *this, 0, mVisuals[0], 0.0f ); // Will clean up previously registered visuals for this index. // custom shader is not applied on the original image. BlurImage( 0, inputImage); @@ -283,8 +282,7 @@ void SuperBlurView::OnSizeSet( const Vector3& targetSize ) GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT ); mVisuals[i] = Toolkit::VisualFactory::Get().CreateVisual( mBlurredImage[i - 1] ); - DevelControl::RegisterVisual( *this, i, mVisuals[i] ); // Will clean up existing visual with same index. - mVisuals[i].SetDepthIndex( i ); + DevelControl::RegisterVisual( *this, i, mVisuals[i], float( i ) ); // Will clean up existing visual with same index. SetShaderEffect( mVisuals[i] ); } diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 597fee1..3486aab 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -850,8 +850,7 @@ void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap ) if( visual ) { - DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual ); - visual.SetDepthIndex( DepthIndex::CONTENT ); + DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, float( DepthIndex::CONTENT ) ); } } } diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index a41a6f3..aa0ef0b 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -124,8 +124,7 @@ void Control::SetBackground( const Property::Map& map ) Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map ); if( visual ) { - mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual ); - visual.SetDepthIndex( DepthIndex::BACKGROUND ); + mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, float( DepthIndex::BACKGROUND ) ); // Trigger a size negotiation request that may be needed by the new visual to relayout its contents. RelayoutRequest(); @@ -137,8 +136,7 @@ void Control::SetBackgroundImage( Image image ) Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image ); if( visual ) { - mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual ); - visual.SetDepthIndex( DepthIndex::BACKGROUND ); + mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, float( DepthIndex::BACKGROUND ) ); } } -- 2.7.4