From: Agnelo Vaz Date: Thu, 7 Jul 2016 14:20:12 +0000 (+0100) Subject: Adding RegisterVisual API to Control base class X-Git-Tag: dali_1.2.0~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F78983%2F12;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Adding RegisterVisual API to Control base class Visuals are stored in Control after being registered through the new API via the derived control Change-Id: If94c43f148994434c9f7c409fadef5ebd590e66c --- 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 1a3490b..fcf6825 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 @@ -18,6 +18,7 @@ #include "dummy-control.h" #include +#include namespace Dali { @@ -74,6 +75,16 @@ DummyControlImpl::~DummyControlImpl() { } +void DummyControlImpl::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ) +{ + Control::RegisterVisual( index, placementActor, visual ); +} + +void DummyControlImpl::UnregisterVisual( Property::Index index ) +{ + Control::UnregisterVisual( index ); +} + 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 496786e..897fc17 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,7 +28,7 @@ namespace Toolkit { class DummyControlImpl; - +class ControlRenderer; /** * Control does not have a New method so use this dummy class for the handle. */ @@ -71,6 +71,9 @@ public: inline TapGestureDetector GetTapGestureDetector() const { return Internal::Control::GetTapGestureDetector(); } inline LongPressGestureDetector GetLongPressGestureDetector() const { return Internal::Control::GetLongPressGestureDetector(); } + void RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual); + void UnregisterVisual( Property::Index index ); + // Used to test signal connections void CustomSlot1( Actor actor ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index 5aff146..ead898d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -972,3 +972,38 @@ int UtcDaliButtonSetUnSelectedColorP(void) END_TEST; } +int UtcDaliButtonResetSelectedColorP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetSelectedColorP"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + application.SendNotification(); + application.Render(); + + const Vector4 FIRST_COLOR = Color::BLUE; + const Vector4 SECOND_COLOR = Color::BLUE; + + pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); + pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR ); + + application.SendNotification(); + application.Render(); + + Vector4 color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION ); + + pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR ); + + application.SendNotification(); + application.Render(); + + color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp index 12ce913..07c6fe4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -944,3 +945,174 @@ int UtcDaliControlImplGetNextKeyboardFocusableActorP(void) END_TEST; } + +int UtcDaliControlImplRegisterThenReRegisterVisual(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + 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 + dummyImpl.RegisterVisual( index, placementActor, visual ); + + + Property::Map newMap; + newMap[Visual::Property::TYPE] = Visual::COLOR; + newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE; + + visual = visualFactory.CreateVisual( newMap ); + DALI_TEST_CHECK(visual); + + // ReRegister with altered color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterVisaulThenReRegisterToSelf(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + 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 + dummyImpl.RegisterVisual( index, placementActor, visual ); + + // ReRegister to self + dummyImpl.RegisterVisual( index, dummy, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterVisualToSelf(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + 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); + + // ReRegister to self + dummyImpl.RegisterVisual( index, dummy, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + + +int UtcDaliControlImplRegisterTwoVisuals(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Property::Index index2 =2; + Actor secondPlacementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + Toolkit::Visual::Base secondVisual; + + 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 + dummyImpl.RegisterVisual( index, placementActor, visual ); + + Property::Map newMap; + newMap[Visual::Property::TYPE] = Visual::COLOR; + newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE; + + secondVisual = visualFactory.CreateVisual( newMap ); + + // ReRegister with altered color visual + dummyImpl.RegisterVisual( index2, secondPlacementActor, secondVisual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterUnregisterVisual(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + 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 + dummyImpl.RegisterVisual( index, placementActor, visual ); + + // Unregister visual + dummyImpl.UnregisterVisual( index ); + + tet_result(TET_PASS); + + END_TEST; +} diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 5fc7a89..53ccf41 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -539,6 +539,7 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) { Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this. bool imageFileExists = false; + Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE; if ( selectedState == SelectedState || selectedState == DisabledSelectedState ) { @@ -551,6 +552,7 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) mUnselectedColor = color; contentActor = &mUnselectedContent; imageFileExists = !GetUnselectedImageFilename().empty(); + visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE; } if ( contentActor ) @@ -564,15 +566,17 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) { // If there is no existing content, create a new actor to use for flat color. Actor placementActor = Actor::New(); - Toolkit::VisualFactory rendererFactory = Toolkit::VisualFactory::Get(); - Toolkit::Visual::Base colorRenderer; + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; Property::Map map; map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - colorRenderer = rendererFactory.CreateVisual( map ); - colorRenderer.SetOnStage( placementActor ); + visual = visualFactory.CreateVisual( map ); + + RegisterVisual( visualIndex, placementActor, visual ); + visual.SetOnStage( placementActor ); SetupContent( *contentActor, placementActor ); // contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index d19cb14..6eec362 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -52,6 +52,33 @@ namespace { /** + * Struct used to store Visual within the control, index is a unique key for each visual. + */ +struct RegisteredVisual +{ + Property::Index index; + Toolkit::Visual::Base visual; + Actor placementActor; + + RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {} +}; + +/** + * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter + */ +bool FindVisual( Property::Index targetIndex, std::vector& visuals, std::vector::iterator& iter ) +{ + for ( iter = visuals.begin(); iter != visuals.end(); iter++ ) + { + if ( (*iter).index == targetIndex ) + { + return true; + } + } + return false; +} + +/** * Creates control through type registry */ BaseHandle Create() @@ -367,6 +394,7 @@ public: // Data Control& mControlImpl; + std::vector mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used. std::string mStyleName; Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background Vector4 mBackgroundColor; ///< The color of the background visual @@ -624,6 +652,44 @@ void Control::KeyboardEnter() OnKeyboardEnter(); } +void Control::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ) +{ + bool visualReplaced ( false ); + Actor actorToRegister; // Null actor, replaced if placement actor not Self + + if ( placementActor != Self() ) // Prevent increasing ref count if actor self + { + actorToRegister = placementActor; + } + + if ( !mImpl->mVisuals.empty() ) + { + std::vector::iterator iter; + // Check if visual (index) is already registered. Replace if so. + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + (*iter).visual = visual; + (*iter).placementActor = actorToRegister; + visualReplaced = true; + } + } + + if ( !visualReplaced ) // New registration entry + { + RegisteredVisual newVisual = RegisteredVisual( index, visual, actorToRegister ); + mImpl->mVisuals.push_back( newVisual ); + } +} + +void Control::UnregisterVisual( Property::Index index ) +{ + std::vector< RegisteredVisual >::iterator iter; + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + mImpl->mVisuals.erase( iter ); + } +} + bool Control::OnAccessibilityActivated() { return false; // Accessibility activation is not handled by default diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index 2353cea..e3d0676 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -42,6 +42,10 @@ namespace Toolkit class StyleManager; +namespace Visual +{ +class Base; +} namespace Internal { /** @@ -288,6 +292,27 @@ public: protected: // For derived classes to call /** + * @brief Register a visual by Property Index, linking an Actor to controlRenderer when required. + * In the case of the visual being an actor or control deeming controlRenderer not required then controlRenderer should be an empty handle. + * No parenting is done during registration, this should be done by derived class. + * + * @SINCE_1_1.46 + * + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] placementActor The actor used to by the visual. + * @param[in] visual The visual to register + */ + void RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ); + + /** + * @brief Erase the entry matching the given index from the list of registered visuals + * @param[in] index The Property index of the visual, used to reference visual + * + * @SINCE_1_1.46 + */ + void UnregisterVisual( Property::Index index ); + + /** * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal * * Should be called last by the control after it acts on the Input Focus change.