From 326af23a9e20230797d542054b7e586b0d69c034 Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 21 Aug 2020 14:37:29 +0100 Subject: [PATCH] Migrating Handle devel-api to public-api Change-Id: If2e537646fbcb60149eaa3213e061d836a70e448 Signed-off-by: David Steele --- automated-tests/src/dali/utc-Dali-Handle.cpp | 95 +++++++++---- dali/devel-api/object/handle-devel.cpp | 37 +---- dali/devel-api/object/handle-devel.h | 129 +----------------- dali/internal/event/common/object-impl.cpp | 68 ++------- dali/internal/event/common/object-impl.h | 16 +-- .../event/common/type-registry-impl.cpp | 29 ++-- dali/public-api/common/dali-common.h | 3 + dali/public-api/object/handle.cpp | 32 ++++- dali/public-api/object/handle.h | 115 +++++++++++++++- dali/public-api/object/property.cpp | 2 +- 10 files changed, 245 insertions(+), 281 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index f406fd4ab..24a40008b 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -263,17 +263,17 @@ int UtcDaliHandleGetPropertyIndex02(void) const float withFlake(99.f); Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); - Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); + Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor); Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE ); - Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake ); Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE ); application.SendNotification(); application.Render(); // Test that we can get the property index from the integer key - Property::Index testIndex1 = DevelHandle::GetPropertyIndex( actor, key1 ); - Property::Index testIndex2 = DevelHandle::GetPropertyIndex( actor, key2 ); + Property::Index testIndex1 = actor.GetPropertyIndex( key1 ); + Property::Index testIndex2 = actor.GetPropertyIndex( key2 ); DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION ); @@ -303,15 +303,15 @@ int UtcDaliHandleGetPropertyIndex03(void) std::string myName("croydon"); Property::Index intKey = CORE_PROPERTY_MAX_INDEX+1; Property::Value value( Color::GREEN ); - Property::Index myIndex = DevelHandle::RegisterProperty( actor, intKey, myName, value ); + Property::Index myIndex = actor.RegisterProperty( intKey, myName, value ); - DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, intKey ), TEST_LOCATION ); + DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( intKey ), TEST_LOCATION ); Property::Key key1(myName); Property::Key key2(intKey); - DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key1 ), TEST_LOCATION ); - DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key2 ), TEST_LOCATION ); + DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( key1 ), TEST_LOCATION ); + DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( key2 ), TEST_LOCATION ); END_TEST; } @@ -750,8 +750,8 @@ int UtcDaliHandleRegisterProperty02(void) const float withFlake(99.f); Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); - Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); - Property::Index index3 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor); + Property::Index index3 = actor.RegisterProperty( key2, "iceCream", withFlake ); application.SendNotification(); application.Render(); @@ -852,9 +852,9 @@ int UtcDaliHandleGetPropertyIndices(void) Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2; actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); - DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); + actor.RegisterProperty( key1, "sideColor", testColor); actor.RegisterProperty( "MyPropertyTwo", 1234 ); - Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake ); actor.RegisterProperty( "MyPropertyThree", Vector2(.2f,.7f) ); actor.GetPropertyIndices( indices ); @@ -1501,7 +1501,7 @@ int UtcDaliHandleDoesCustomPropertyExistP1(void) Actor actor = Actor::New(); auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.DoesCustomPropertyExist( propertyIndex ), true, TEST_LOCATION ); END_TEST; } @@ -1514,7 +1514,7 @@ int UtcDaliHandleDoesCustomPropertyExistN1(void) Actor actor = Actor::New(); auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex+1 ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.DoesCustomPropertyExist( propertyIndex+1 ), false, TEST_LOCATION ); END_TEST; } @@ -1525,7 +1525,7 @@ int UtcDaliHandleDoesCustomPropertyExistN2(void) tet_infoline( "Test that a default property does not show as a custom property on object" ); Actor actor = Actor::New(); - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, Actor::Property::POSITION ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.DoesCustomPropertyExist( Actor::Property::POSITION ), false, TEST_LOCATION ); END_TEST; } @@ -1548,7 +1548,7 @@ int UtcDaliHandleDoesCustomPropertyExistN3(void) auto child = Actor::New(); container.Add( child ); // Resolve child properties (if any) - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( child.DoesCustomPropertyExist( CHILD_PROPERTY ), false, TEST_LOCATION ); END_TEST; } @@ -1572,7 +1572,7 @@ int UtcDaliHandleDoesCustomPropertyExistP2(void) container.Add( child ); // Resolve child properties (if any) child.SetProperty( CHILD_PROPERTY, 2 ); - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.DoesCustomPropertyExist( CHILD_PROPERTY ), true, TEST_LOCATION ); DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 2, TEST_LOCATION ); END_TEST; } @@ -1597,7 +1597,7 @@ int UtcDaliHandleDoesCustomPropertyExistP3(void) child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); container.Add( child ); // Resolve child properties (if any) - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.DoesCustomPropertyExist( CHILD_PROPERTY ), true, TEST_LOCATION ); DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); END_TEST; } @@ -1654,7 +1654,7 @@ int UtcDaliHandlePropertySetSignal01(void) tet_infoline( "Test that setting a default property triggers a signal" ); auto actor = Actor::New(); - DevelHandle::PropertySetSignal(actor).Connect(&application, propertySetCheck); + actor.PropertySetSignal().Connect(&application, propertySetCheck); actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS ); propertySetCheck.CheckSignalReceived(); @@ -1674,7 +1674,7 @@ int UtcDaliHandlePropertySetSignal02(void) tet_infoline( "Test that setting a custom property triggers a signal" ); auto actor = Actor::New(); - DevelHandle::PropertySetSignal(actor).Connect(&application, propertySetCheck); + actor.PropertySetSignal().Connect(&application, propertySetCheck); auto propertyIndex = actor.RegisterProperty("propName", 3.0f); actor.SetProperty( propertyIndex, 5.0f ); @@ -1706,10 +1706,10 @@ int UtcDaliHandlePropertySetSignal03(void) application.GetScene().Add( container ); auto child = Actor::New(); child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); - DevelHandle::PropertySetSignal(child).Connect(&application, propertySetCheck); + child.PropertySetSignal().Connect(&application, propertySetCheck); container.Add( child ); // Resolve child properties (if any) - DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.DoesCustomPropertyExist( CHILD_PROPERTY ), true, TEST_LOCATION ); DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); child.SetProperty( CHILD_PROPERTY, 29 ); @@ -1718,6 +1718,43 @@ int UtcDaliHandlePropertySetSignal03(void) END_TEST; } + + +int UtcDaliHandlePropertySetSignal04(void) +{ + TestApplication application; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a property on a vanilla Object triggers a signal" ); + + constexpr Property::Index TEST_PROPERTY_KEY_INDEX = 1; + const std::string TEST_PROPERTY_KEY_NAME = "testProperty"; + + Handle vanillaObject = Handle::New(); + auto propertyIndex = vanillaObject.RegisterProperty( + TEST_PROPERTY_KEY_INDEX, + TEST_PROPERTY_KEY_NAME, + Color::WHITE ); + + vanillaObject.PropertySetSignal().Connect(&application, propertySetCheck); + + DALI_TEST_EQUALS( vanillaObject.DoesCustomPropertyExist( propertyIndex ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( vanillaObject.GetProperty( propertyIndex ), Color::WHITE, 0.001f, TEST_LOCATION ); + + vanillaObject[TEST_PROPERTY_KEY_NAME] = Color::RED; + + propertySetCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( Color::RED ), 0.001f, TEST_LOCATION ); + DALI_TEST_VALUE_EQUALS( vanillaObject[propertyIndex], Property::Value( Color::RED), 0.001f, TEST_LOCATION ); + + END_TEST; +} + + int UtcDaliHandlePropertySetProperties(void) { TestApplication application; @@ -1726,8 +1763,7 @@ int UtcDaliHandlePropertySetProperties(void) const Vector4 color( 0.1f, 0.2, 0.3f, 0.4f ); Handle handle = Actor::New(); - DevelHandle::SetProperties( - handle, + handle.SetProperties( Property::Map { { Actor::Property::SIZE, actorSize }, @@ -1743,14 +1779,14 @@ int UtcDaliHandlePropertySetProperties(void) END_TEST; } -int UtcDaliHandleTemplateNew(void) +int UtcDaliHandleTemplateNew01(void) { TestApplication application; const Vector3 actorSize( 10.0f, 20.0f, 30.0f ); const Vector3 anchorPoint( 1.0f, 0.5f, 0.0f ); const Vector4 color( 0.1f, 0.2, 0.3f, 0.4f ); - Handle handle = DevelHandle::New< Actor >( + Handle handle = Handle::New< Actor >( Property::Map { { Actor::Property::SIZE, actorSize }, @@ -1772,8 +1808,7 @@ int UtcDaliHandleGetProperties(void) TestApplication application; Handle handle = Actor::New(); - DevelHandle::SetProperties( - handle, + handle.SetProperties( Property::Map { { Actor::Property::SIZE, Vector3( 400.0f, 200.0f, 100.0f ) }, @@ -1786,7 +1821,7 @@ int UtcDaliHandleGetProperties(void) ); Property::Map map; - DevelHandle::GetProperties( handle, map ); + handle.GetProperties( map ); // Get all the properties and ensure they match @@ -1822,7 +1857,7 @@ int UtcDaliHandleGetProperties(void) // Add a custom property and ensure the count goes up by one. const auto countBefore = map.Count(); handle.RegisterProperty( "tempProperty", Color::GREEN ); - DevelHandle::GetProperties( handle, map ); + handle.GetProperties( map ); DALI_TEST_EQUALS( countBefore + 1, map.Count(), TEST_LOCATION ); END_TEST; diff --git a/dali/devel-api/object/handle-devel.cpp b/dali/devel-api/object/handle-devel.cpp index 6a01e45be..d062531ed 100644 --- a/dali/devel-api/object/handle-devel.cpp +++ b/dali/devel-api/object/handle-devel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -29,46 +29,11 @@ namespace Dali namespace DevelHandle { -Property::Index GetPropertyIndex( const Handle& handle, Property::Index key ) -{ - return GetImplementation( handle ).GetPropertyIndex( key ); -} - -Property::Index GetPropertyIndex( const Handle& handle, Property::Key key ) -{ - return GetImplementation( handle ).GetPropertyIndex( key ); -} - -Property::Index RegisterProperty( Handle handle, Property::Index key, const std::string& name, const Property::Value& propertyValue ) -{ - return GetImplementation( handle ).RegisterProperty( name, key, propertyValue ); -} - -void SetProperties( Handle handle, const Property::Map& properties ) -{ - GetImplementation( handle ).SetProperties( properties ); -} - -void GetProperties( Handle handle, Property::Map& properties ) -{ - GetImplementation( handle ).GetProperties( properties ); -} - void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo ) { GetImplementation( handle ).SetTypeInfo( &GetImplementation( typeInfo ) ); } -bool DoesCustomPropertyExist( Handle& handle, Property::Index index ) -{ - return GetImplementation( handle ).DoesCustomPropertyExist( index ); -} - -PropertySetSignalType& PropertySetSignal( Handle handle ) -{ - return GetImplementation( handle ).PropertySetSignal(); -} - } // namespace DevelHandle } // namespace Dali diff --git a/dali/devel-api/object/handle-devel.h b/dali/devel-api/object/handle-devel.h index df6a4d670..d6b65306e 100644 --- a/dali/devel-api/object/handle-devel.h +++ b/dali/devel-api/object/handle-devel.h @@ -2,7 +2,7 @@ #define DALI_HANDLE_DEVEL_H /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -27,95 +27,6 @@ namespace Dali namespace DevelHandle { -/** - * @brief Query the index of a custom property matching the given key. - * - * Returns the first custom property that matches the given integer key. This is - * useful for other classes that know the key but not the name. Requires the property - * to have been registered with the associated key. - * - * @note This key is not the same as the Property enum found in - * objects such as Actor (which is a preset index). - * - * @param[in] handle The handle from where to retrieve the property index. - * @param[in] key The integer key of the property - * - * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given key. - * - * @note The key is not the same as the returned index, though it has the same type. - */ -DALI_CORE_API Property::Index GetPropertyIndex( const Handle& handle, Property::Index key ); - -/** - * @brief Query the index of a property using the given key from a Property::Map - * - * @param[in] handle The handle from where to retrieve the property index. - * @param[in] key The key of the property to search for. - * - * @return the matching property index of either the string key or the matching - * custom property index of the index key, or Property::INVALID_INDEX if no - * property matches the given key. - * - * @note See also, GetPropertyIndex(Property::Index) and GetPropertyIndex(const std::string&) - */ -DALI_CORE_API Property::Index GetPropertyIndex( const Handle& handle, Property::Key key ); - -/** - * @brief Register a new animatable property with an integer key. - * - * @param[in] handle The handle where to register the property. - * @param[in] key The integer key of the property. - * @param[in] name The text key of the property. - * @param[in] propertyValue The new value of the property. - * - * @return The index of the property or Property::INVALID_INDEX if registration failed - * - * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true. - * Property names and keys are expected to be unique, but this is not enforced. - * Property indices are unique to each registered custom property in a given object. - * - * @note Returns Property::INVALID_INDEX if registration failed. This can happen if you try to register - * animatable property on an object that does not have scene graph object. - * - * @note The returned property index is not the same as the integer key (though it shares a type) - * - * This version of RegisterProperty associates both an integer key - * and the text key with the property, allowing for lookup of the - * property index by either key or name ( which is useful when other - * classes know the key but not the name ) - * - * @note Only the following types can be animated: - * - Property::BOOLEAN - * - Property::FLOAT - * - Property::INTEGER - * - Property::VECTOR2 - * - Property::VECTOR3 - * - Property::VECTOR4 - * - Property::MATRIX3 - * - Property::MATRIX - * - Property::ROTATION - * @note If a property with the desired name already exists, then the value given is just set. - */ -DALI_CORE_API Property::Index RegisterProperty( Handle handle, Property::Index key, const std::string& name, const Property::Value& propertyValue ); - -/** - * @brief Sets all the properties in the given property map. - * - * @param[in] handle The handle to set the properties on - * @param[in] properties The properties to set - */ -DALI_CORE_API void SetProperties( Handle handle, const Property::Map& properties ); - -/** - * @brief Retrieves all the properties and the values for a handle. - * - * @param[in] handle The handle to retrieve properties from - * @param[out] properties A map which is populated with the index-value pairs - * - * @note The properties map will be cleared by this method first. - */ -DALI_CORE_API void GetProperties( Handle handle, Property::Map& properties ); - /** * @brief Set the type-info that the object is created by. * @@ -126,44 +37,6 @@ DALI_CORE_API void GetProperties( Handle handle, Property::Map& properties ); */ DALI_CORE_API void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo ); - -/** - * @brief Determine if the custom property index exists on this object without throwing a Dali::Exception. - * - * @note This does not check default properties. - * @param[in] handle The handle to check - * @param[in] index The index of the property to test for - */ -DALI_CORE_API bool DoesCustomPropertyExist( Handle& handle, Property::Index index ); - -/** - * @brief PropertySetSignal function prototype for signal handler. Called when a property is set on this object. - */ -using PropertySetSignalType = Signal< void( Handle& handle, Property::Index index, Property::Value value ) >; - -/** - * @brief Get a signal when a property is set on this object through the API (i.e. not when animating) - * - * @param[in] handle The handle of the object to listen to. - * @return The signal to attach a connection to. - */ -DALI_CORE_API PropertySetSignalType& PropertySetSignal( Handle handle ); - -/** - * @brief Template to create a derived handle and set properties on it. - * - * @tparam T The derived class to create - * - * @param[in] properties The properties to set - */ -template< typename T > -DALI_INTERNAL T New( const Property::Map& properties ) -{ - T handle = T::New(); - SetProperties( handle, properties ); - return handle; -} - } // namespace DevelHandle } // namespace Dali diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index bf521bbc2..e65d1f32f 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -136,55 +136,31 @@ std::string Object::GetPropertyName( Property::Index index ) const return std::string(); } -Property::Index Object::GetPropertyIndex( const std::string& name ) const +Property::Index Object::GetPropertyIndex( Property::Key key ) const { Property::Index index = Property::INVALID_INDEX; - const TypeInfo* typeInfo( GetTypeInfo() ); - if ( typeInfo ) - { - index = typeInfo->GetPropertyIndex( name ); - } - if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) ) + if( key.type == Property::Key::STRING ) { - Property::Index count = PROPERTY_CUSTOM_START_INDEX; - const auto end = mCustomProperties.End(); - for( auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count ) + const TypeInfo* typeInfo( GetTypeInfo() ); + if ( typeInfo ) { - CustomPropertyMetadata* custom = static_cast(*iter); - if ( custom->name == name ) - { - if ( custom->childPropertyIndex != Property::INVALID_INDEX ) - { - // If it is a child property, return the child property index - index = custom->childPropertyIndex; - } - else - { - index = count; - } - break; - } + index = typeInfo->GetPropertyIndex( key.stringKey ); } } - return index; -} - -Property::Index Object::GetPropertyIndex( Property::Index key ) const -{ - Property::Index index = Property::INVALID_INDEX; - - if( mCustomProperties.Count() > 0 ) + if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) ) { Property::Index count = PROPERTY_CUSTOM_START_INDEX; const auto end = mCustomProperties.End(); for( auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count ) { CustomPropertyMetadata* custom = static_cast(*iter); - if( custom->key == key ) + + if( ( key.type == Property::Key::STRING && custom->name == key.stringKey) || + ( key.type == Property::Key::INDEX && custom->key == key.indexKey ) ) { - if( custom->childPropertyIndex != Property::INVALID_INDEX ) + if ( custom->childPropertyIndex != Property::INVALID_INDEX ) { // If it is a child property, return the child property index index = custom->childPropertyIndex; @@ -201,20 +177,6 @@ Property::Index Object::GetPropertyIndex( Property::Index key ) const return index; } -Property::Index Object::GetPropertyIndex( Property::Key key ) const -{ - Property::Index index = Property::INVALID_INDEX; - if( key.type == Property::Key::INDEX ) - { - index = GetPropertyIndex( key.indexKey ); - } - else - { - index = GetPropertyIndex( key.stringKey ); - } - return index; -} - bool Object::IsPropertyWritable( Property::Index index ) const { DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds"); @@ -453,7 +415,7 @@ Property::Value Object::GetProperty( Property::Index index ) const else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - // this is needed because property value may have been set as full property and get as a property component + // this is needed because property value may have been set as full property and get as a property component AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr ); if( animatableProperty ) { @@ -507,7 +469,7 @@ Property::Value Object::GetCurrentProperty( Property::Index index ) const else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - // this is needed because property value may have been set as full property and get as a property component + // this is needed because property value may have been set as full property and get as a property component AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr ); if( animatableProperty ) { @@ -590,7 +552,7 @@ void Object::SetProperties( const Property::Map& properties ) // Iterating twice to get the value we want should still be fairly quick in a Property::Map. const auto& key = properties.GetKeyAt( position ); - const auto propertyIndex = ( key.type == Property::Key::INDEX ) ? key.indexKey : GetPropertyIndex( key.stringKey ); + const auto propertyIndex = ( key.type == Property::Key::INDEX ) ? key.indexKey : GetPropertyIndex( key ); if( propertyIndex != Property::INVALID_INDEX ) { @@ -974,7 +936,7 @@ int32_t Object::GetPropertyComponentIndex( Property::Index index ) const return componentIndex; } -DevelHandle::PropertySetSignalType& Object::PropertySetSignal() +Handle::PropertySetSignalType& Object::PropertySetSignal() { return mPropertySetSignal; } diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index c9c1c0032..8bdc264da 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_OBJECT_H /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -147,16 +147,6 @@ public: */ std::string GetPropertyName( Property::Index index ) const; - /** - * @copydoc Dali::Handle::GetPropertyIndex() - */ - Property::Index GetPropertyIndex( const std::string& name ) const; - - /** - * @copydoc Dali::Handle::GetPropertyIndex() - */ - Property::Index GetPropertyIndex( Property::Index key ) const; - /** * @copydoc Dali::Handle::GetPropertyIndex() */ @@ -361,7 +351,7 @@ public: /** * @copydoc Dali::Handle::PropertySetSignal() */ - DevelHandle::PropertySetSignalType& PropertySetSignal(); + Handle::PropertySetSignalType& PropertySetSignal(); protected: @@ -571,8 +561,8 @@ private: using PropertyNotificationContainer = std::vector< Dali::PropertyNotification >; PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications. - DevelHandle::PropertySetSignalType mPropertySetSignal; + Handle::PropertySetSignalType mPropertySetSignal; }; } // namespace Internal diff --git a/dali/internal/event/common/type-registry-impl.cpp b/dali/internal/event/common/type-registry-impl.cpp index 99c333782..ca86f6e68 100644 --- a/dali/internal/event/common/type-registry-impl.cpp +++ b/dali/internal/event/common/type-registry-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -99,26 +99,34 @@ std::string TypeRegistry::GetTypeName( uint32_t index ) const return name; } -std::string TypeRegistry::Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, - Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit ) +std::string TypeRegistry::Register( const std::type_info& theTypeInfo, + const std::type_info& baseTypeInfo, + Dali::TypeInfo::CreateFunction createInstance, + bool callCreateOnInit ) { std::string uniqueTypeName = DemangleClassName( theTypeInfo.name() ); return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit ); } -std::string TypeRegistry::Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, - Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit, - const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount ) +std::string TypeRegistry::Register( const std::type_info& theTypeInfo, + const std::type_info& baseTypeInfo, + Dali::TypeInfo::CreateFunction createInstance, + bool callCreateOnInit, + const Dali::PropertyDetails* defaultProperties, + Property::Index defaultPropertyCount ) { std::string uniqueTypeName = DemangleClassName( theTypeInfo.name() ); return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit, defaultProperties, defaultPropertyCount ); } -std::string TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo, - Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit, - const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount ) +std::string TypeRegistry::Register( const std::string& uniqueTypeName, + const std::type_info& baseTypeInfo, + Dali::TypeInfo::CreateFunction createInstance, + bool callCreateOnInit, + const Dali::PropertyDetails* defaultProperties, + Property::Index defaultPropertyCount ) { std::string baseTypeName = DemangleClassName( baseTypeInfo.name() ); @@ -133,7 +141,8 @@ std::string TypeRegistry::Register( const std::string& uniqueTypeName, const std } } - mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) ); + mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( + new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) ); DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str() ); if( callCreateOnInit ) diff --git a/dali/public-api/common/dali-common.h b/dali/public-api/common/dali-common.h index 5b668f578..c858328ea 100755 --- a/dali/public-api/common/dali-common.h +++ b/dali/public-api/common/dali-common.h @@ -33,11 +33,13 @@ #if __GNUC__ >= 4 # ifndef HIDE_DALI_INTERNALS # define DALI_EXPORT_API +# define DALI_NO_EXPORT_API # define DALI_IMPORT_API # define DALI_CORE_API # define DALI_INTERNAL # else # define DALI_EXPORT_API __attribute__ ((visibility ("default"))) +# define DALI_NO_EXPORT_API __attribute__ ((visibility ("hidden"))) # define DALI_IMPORT_API __attribute__ ((visibility ("default"))) # define DALI_CORE_API __attribute__ ((visibility ("default"))) # define DALI_INTERNAL __attribute__ ((visibility ("hidden"))) @@ -65,6 +67,7 @@ #endif /** Visibility attribute to hide declarations */ # define DALI_INTERNAL +# define DALI_NO_EXPORT_API #endif #ifdef DEPRECATION_WARNING diff --git a/dali/public-api/object/handle.cpp b/dali/public-api/object/handle.cpp index a067aee92..c28330cc8 100644 --- a/dali/public-api/object/handle.cpp +++ b/dali/public-api/object/handle.cpp @@ -29,12 +29,12 @@ namespace Dali { + Handle::Handle( Dali::Internal::Object* handle ) : BaseHandle(handle) { } - Handle::Handle() { } @@ -76,9 +76,9 @@ std::string Handle::GetPropertyName( Property::Index index ) const return GetImplementation(*this).GetPropertyName( index ); } -Property::Index Handle::GetPropertyIndex( const std::string& name ) const +Property::Index Handle::GetPropertyIndex( Property::Key key ) const { - return GetImplementation(*this).GetPropertyIndex( name ); + return GetImplementation( *this ).GetPropertyIndex( key ); } bool Handle::IsPropertyWritable( Property::Index index ) const @@ -111,6 +111,11 @@ Property::Index Handle::RegisterProperty( const std::string& name, const Propert return GetImplementation(*this).RegisterProperty( name, propertyValue ); } +Property::Index Handle::RegisterProperty( Property::Index key, const std::string& name, const Property::Value& propertyValue ) +{ + return GetImplementation( *this ).RegisterProperty( name, key, propertyValue ); +} + Property::Index Handle::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode ) { return GetImplementation(*this).RegisterProperty( name, propertyValue, accessMode ); @@ -126,11 +131,26 @@ Property::Value Handle::GetCurrentProperty( Property::Index index ) const return GetImplementation(*this).GetCurrentProperty( index ); } +void Handle::SetProperties( const Property::Map& properties ) +{ + GetImplementation( *this ).SetProperties( properties ); +} + +void Handle::GetProperties( Property::Map& properties ) +{ + GetImplementation( *this ).GetProperties( properties ); +} + void Handle::GetPropertyIndices( Property::IndexContainer& indices ) const { GetImplementation(*this).GetPropertyIndices( indices ); } +bool Handle::DoesCustomPropertyExist( Property::Index index ) +{ + return GetImplementation( *this ).DoesCustomPropertyExist( index ); +} + Dali::PropertyNotification Handle::AddPropertyNotification( Property::Index index, const PropertyCondition& condition ) { @@ -176,6 +196,12 @@ IndirectValue Handle::operator[]( const std::string& name ) return IndirectValue(*this, GetPropertyIndex(name)); } +Handle::PropertySetSignalType& Handle::PropertySetSignal() +{ + return GetImplementation( *this ).PropertySetSignal(); +} + + namespace WeightObject { diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index 540a04e46..b5f0ecbe8 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include namespace Dali @@ -71,6 +73,11 @@ public: DYNAMIC_PROPERTIES = 0x01, }; + /** + * @brief PropertySetSignal function prototype for signal handler. Called when a property is set on this object. + */ + using PropertySetSignalType = Signal< void( Handle& handle, Property::Index index, Property::Value value ) >; + public: /** @@ -105,6 +112,22 @@ public: */ static Handle New(); + /** + * @brief Template to create a derived handle and set properties on it. + * + * Marked as DALI_NO_EXPORT_API to prevent internal usage exporting symbols. + * @SINCE_1_9.27 + * @tparam T The derived class to create + * @param[in] properties The properties to set + */ + template< typename Type > + static DALI_NO_EXPORT_API Type New( const Property::Map& properties ) + { + Type handle = Type::New(); + handle.SetProperties( properties ); + return handle; + } + /** * @brief Dali::Handle is intended as a base class. * @@ -187,15 +210,15 @@ public: std::string GetPropertyName( Property::Index index ) const; /** - * @brief Queries the index of a property. - * - * Returns the first property index that matches the given name exactly. + * @brief Query the index of a property using the given key. * - * @SINCE_1_0.0 - * @param[in] name The name of the property - * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name + * @SINCE_1_9.27 + * @param[in] key The key of the property to search for. (The name or integer key provided to + * RegisterProperty()). + * @return the matching property index of the key, or Property::INVALID_INDEX if no + * property matches the given key. */ - Property::Index GetPropertyIndex( const std::string& name ) const; + Property::Index GetPropertyIndex( Property::Key key ) const; /** * @brief Queries whether a property can be set using SetProperty(). @@ -271,6 +294,48 @@ public: */ Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue ); + /** + * @brief Register a new animatable property with an integer key. + * + * @SINCE_1_9.27 + * @param[in] key The integer key of the property. + * @param[in] name The text key of the property. + * @param[in] propertyValue The new value of the property. + * + * @return The index of the property or Property::INVALID_INDEX if registration failed + * + * @pre The object supports dynamic properties + * i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true. Property names and keys + * are expected to be unique, but this is not enforced. Property indices are unique + * to each registered custom property in a given object. + * + * @note Returns Property::INVALID_INDEX if registration failed. This can happen if + * you try to register animatable property on an object that does not have scene graph + * object. + * + * @note The returned property index is not the same as the integer key (though it + * shares a type) + * + * This version of RegisterProperty associates both an integer key and the text key + * with the property, allowing for lookup of the property index by either key or name + * ( which is useful when other classes know the key but not the name ) + * + * @note Only the following types can be animated: + * - Property::BOOLEAN + * - Property::FLOAT + * - Property::INTEGER + * - Property::VECTOR2 + * - Property::VECTOR3 + * - Property::VECTOR4 + * - Property::MATRIX3 + * - Property::MATRIX + * - Property::ROTATION + * @note If a property with the desired name already exists, then the value given is just set. + */ + Property::Index RegisterProperty( Property::Index key, + const std::string& name, + const Property::Value& propertyValue ); + /** * @brief Registers a new property. * @@ -346,6 +411,24 @@ public: return T( value.Get() ); } + /** + * @brief Sets all the properties in the given property map. + * + * @SINCE_1_9.27 + * @param[in] properties The properties to set + */ + void SetProperties( const Property::Map& properties ); + + /** + * @brief Retrieves all the properties and the values for this object + * + * @SINCE_1_9.27 + * @param[out] properties A map which is populated with the index-value pairs + * + * @note The properties map will be cleared by this method first. + */ + void GetProperties( Property::Map& properties ); + /** * @brief Retrieves all the property indices for this object (including custom properties). * @@ -355,6 +438,15 @@ public: */ void GetPropertyIndices( Property::IndexContainer& indices ) const; + /** + * @brief Determine if the custom property index exists on this object without throwing a Dali::Exception. + * + * @SINCE_1_9.27 + * @note This does not check default properties. + * @param[in] index The index of the property to test for + */ + bool DoesCustomPropertyExist( Property::Index index ); + /** * @brief Adds a property notification to this object. * @@ -433,6 +525,15 @@ public: * @return indirect value. Should have shorter scope than the handle */ IndirectValue operator[]( const std::string& name ); + +public: // Signals + /** + * @brief Get a signal when a property is set on this object through the API (i.e. not when animating) + * + * @SINCE_1_9.27 + * @return The signal to attach a connection to. + */ + PropertySetSignalType& PropertySetSignal(); }; /** diff --git a/dali/public-api/object/property.cpp b/dali/public-api/object/property.cpp index 1ac845347..ce2b458bf 100644 --- a/dali/public-api/object/property.cpp +++ b/dali/public-api/object/property.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. -- 2.34.1