From f468c03113e03c0d23564032fd5e39d82947f18a Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Wed, 11 Mar 2015 14:13:57 +0000 Subject: [PATCH] New Constraints BEFORE: struct MyObject { MyObject( Vector3 input ) : mInput( input ) { } Vector3 operator()( const Vector3& current, const PropertyInput& parentSize ) { return current * parentSize.GetVector3() * mInput; } Vector3 mInput; }; ... Actor actor = Actor::New(); Constraint constraint = Constraint::New< Vector3 >( Actor::Property::POSITION, ParentSource( Actor::Property::SIZE ), MyObject( Vector::ONE ) ); actor.ApplyConstraint( constraint ); NOW: struct MyObject { MyObject( Vector3 input ) : mInput( input ) { } void operator()( Vector3& current, const PropertyInputContainer& inputs ) { current *= inputs[0]->GetVector3() * mInput; } Vector3 mInput; }; ... Actor actor = Actor::New(); Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, MyObject( Vector::ONE ) ); constraint.AddSource( ParentSource( Actor::Property::SIZE ) ); constraint.Apply(); DESCRIPTION OF CHANGES: - Constraints take a handle as parameter - AddSource to add a source - Constraints no longer copied unless absolutely required - Constraints can be cloned for another object - Replaced the New methods in Dali::Constraint - Use one constraint function - Inputs are passed in via Dali::Vector< PropertyInput* > - Only one PropertyConstraint class being used now - Constraint function has no return - Remove PropertyInputComponentAccessor and moved its functionality into PropertyInputAccessor for the time being - Currently using std::vector internally as Dali::Vector cannot support non-trivial types - Updated Path Constraints to use new constraints - Replace boost::function usage in Constraints - Remove weight property from constraints - Constraint is no longer an Object, it is a base-object - Remove duplicated data from Internal::Constraint - Combine Constraint & ActiveConstraint Change-Id: I210afffae45820e17ecd901a4106b5f735b2b1a8 --- automated-tests/src/dali-internal/CMakeLists.txt | 1 - automated-tests/src/dali/CMakeLists.txt | 2 - .../dali-test-suite-utils.cpp | 2 +- .../dali-test-suite-utils/dali-test-suite-utils.h | 2 +- automated-tests/src/dali/utc-Dali-Actor.cpp | 345 +------ automated-tests/src/dali/utc-Dali-Animation.cpp | 7 +- automated-tests/src/dali/utc-Dali-CameraActor.cpp | 38 +- .../src/dali/utc-Dali-PanGestureDetector.cpp | 112 +-- automated-tests/src/dali/utc-Dali-ShaderEffect.cpp | 125 +-- dali/integration-api/profiling.cpp | 6 +- .../event/animation/active-constraint-base.cpp | 520 ---------- .../event/animation/active-constraint-base.h | 352 ------- .../event/animation/active-constraint-impl.h | 599 ----------- dali/internal/event/animation/constraint-base.cpp | 245 +++++ dali/internal/event/animation/constraint-base.h | 238 +++++ dali/internal/event/animation/constraint-impl.cpp | 289 ------ dali/internal/event/animation/constraint-impl.h | 554 +++++++++-- .../event/animation/path-constraint-impl.cpp | 19 +- .../event/animation/path-constraint-impl.h | 25 +- .../event/animation/property-constraint-ptr.h | 2 +- .../internal/event/animation/property-constraint.h | 1038 ++------------------ .../event/animation/property-input-accessor.h | 177 +--- .../event/animation/property-input-indexer.h | 29 +- dali/internal/event/common/object-impl.cpp | 145 +-- dali/internal/event/common/object-impl.h | 42 +- dali/internal/file.list | 4 +- .../update/animation/interpolator-functions.cpp | 174 ---- .../update/animation/interpolator-functions.h | 51 - .../animation/scene-graph-constraint-base.cpp | 7 +- .../update/animation/scene-graph-constraint-base.h | 45 - .../update/animation/scene-graph-constraint.h | 53 +- dali/internal/update/common/property-owner.cpp | 8 - .../common/scene-graph-property-notification.cpp | 4 +- dali/internal/update/manager/update-algorithms.cpp | 19 +- dali/internal/update/manager/update-algorithms.h | 8 +- dali/internal/update/manager/update-manager.cpp | 19 +- dali/public-api/actors/actor.h | 1 - .../animation/active-constraint-declarations.h | 39 - dali/public-api/animation/active-constraint.cpp | 79 -- dali/public-api/animation/active-constraint.h | 142 --- dali/public-api/animation/constraint-functions.h | 194 ---- dali/public-api/animation/constraint.cpp | 296 +++--- dali/public-api/animation/constraint.h | 660 +++++++------ dali/public-api/animation/constraints.h | 201 +--- dali/public-api/dali-core.h | 3 - dali/public-api/file.list | 4 - dali/public-api/object/handle.cpp | 16 - dali/public-api/object/handle.h | 34 +- dali/public-api/shader-effects/shader-effect.h | 2 - 49 files changed, 1816 insertions(+), 5161 deletions(-) delete mode 100644 dali/internal/event/animation/active-constraint-base.cpp delete mode 100644 dali/internal/event/animation/active-constraint-base.h delete mode 100644 dali/internal/event/animation/active-constraint-impl.h create mode 100644 dali/internal/event/animation/constraint-base.cpp create mode 100644 dali/internal/event/animation/constraint-base.h delete mode 100644 dali/internal/event/animation/constraint-impl.cpp delete mode 100644 dali/internal/update/animation/interpolator-functions.cpp delete mode 100644 dali/internal/update/animation/interpolator-functions.h delete mode 100644 dali/public-api/animation/active-constraint-declarations.h delete mode 100644 dali/public-api/animation/active-constraint.cpp delete mode 100644 dali/public-api/animation/active-constraint.h delete mode 100644 dali/public-api/animation/constraint-functions.h diff --git a/automated-tests/src/dali-internal/CMakeLists.txt b/automated-tests/src/dali-internal/CMakeLists.txt index 5eb1e41..f67751a 100644 --- a/automated-tests/src/dali-internal/CMakeLists.txt +++ b/automated-tests/src/dali-internal/CMakeLists.txt @@ -15,7 +15,6 @@ SET(TC_SOURCES utc-Dali-Internal-ResourceClient.cpp utc-Dali-Internal-Image-Culling.cpp utc-Dali-Internal-Text-Culling.cpp - utc-Dali-Internal-Constraint.cpp utc-Dali-Internal-FixedSizeMemoryPool.cpp utc-Dali-Internal-MemoryPoolObjectAllocator.cpp utc-Dali-Internal-RelayoutController.cpp diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index 2feca62..7d53326 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -6,7 +6,6 @@ SET(RPM_NAME "core-${PKG_NAME}-tests") SET(CAPI_LIB "dali") SET(TC_SOURCES - utc-Dali-ActiveConstraint.cpp utc-Dali-Actor.cpp utc-Dali-AlphaFunctions.cpp utc-Dali-AngleAxis.cpp @@ -18,7 +17,6 @@ SET(TC_SOURCES utc-Dali-BufferImage.cpp utc-Dali-CameraActor.cpp utc-Dali-Character.cpp - utc-Dali-Constraint.cpp utc-Dali-Context.cpp utc-Dali-CustomActor.cpp utc-Dali-Degree.cpp diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp index bd801db..ee46961 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp @@ -271,7 +271,7 @@ ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived ) { } -void ConstraintAppliedCheck::operator()( ActiveConstraint& constraint ) +void ConstraintAppliedCheck::operator()( Constraint& constraint ) { mSignalReceived = true; } diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h index edd5560..5ba835f 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h @@ -372,7 +372,7 @@ inline void DALI_TEST_PRINT_ASSERT( DaliException& e ) struct ConstraintAppliedCheck { ConstraintAppliedCheck( bool& signalReceived ); - void operator()( ActiveConstraint& constraint ); + void operator()( Constraint& constraint ); void Reset(); void CheckSignalReceived(); void CheckSignalNotReceived(); diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index e4408f4..295965e 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -76,10 +76,9 @@ static bool gTestConstraintCalled; struct TestConstraint { - Vector4 operator()(const Vector4& color) + void operator()( Vector4& color, const PropertyInputContainer& /* inputs */ ) { gTestConstraintCalled = true; - return Vector4(color.x, color.y, color.z, 0.1f); } }; @@ -97,34 +96,15 @@ struct TestConstraintRef { } - T operator()(const T& current) + void operator()( T& current, const PropertyInputContainer& /* inputs */ ) { mResultRef = mValue; - return current; } unsigned int& mResultRef; unsigned int mValue; }; -bool wasConstraintCallbackCalled1 = false; -void TestConstraintCallback1( ActiveConstraint& constraint ) -{ - wasConstraintCallbackCalled1 = true; -} - -bool wasConstraintCallbackCalled2 = false; -void TestConstraintCallback2( ActiveConstraint& constraint ) -{ - wasConstraintCallbackCalled2 = true; -} - -bool wasConstraintCallbackCalled3 = false; -void TestConstraintCallback3( ActiveConstraint& constraint ) -{ - wasConstraintCallbackCalled3 = true; -} - static bool TestCallback(Actor actor, const TouchEvent& event) { gTouchCallBackCalled = true; @@ -174,14 +154,12 @@ struct PositionComponentConstraint { PositionComponentConstraint(){} - Vector3 operator()(const Vector3& current, const PropertyInput& property) + void operator()( Vector3& pos, const PropertyInputContainer& inputs ) { - const Matrix& m = property.GetMatrix(); - Vector3 pos; + const Matrix& m = inputs[0]->GetMatrix(); Vector3 scale; Quaternion rot; m.GetTransformComponents(pos, rot, scale); - return pos; } }; @@ -1830,225 +1808,6 @@ int UtcDaliActorIsKeyboardFocusable(void) END_TEST; } - -int UtcDaliActorApplyConstraint(void) -{ - TestApplication application; - - gTestConstraintCalled = false; - - Actor actor = Actor::New(); - - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestConstraint() ); - actor.ApplyConstraint(constraint); - - DALI_TEST_CHECK( gTestConstraintCalled == false ); - // add to stage - Stage::GetCurrent().Add( actor ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( gTestConstraintCalled == true ); - END_TEST; -} - - -int UtcDaliActorApplyConstraintAppliedCallback(void) -{ - TestApplication application; - - // Build a reusable constraint - - Actor parent = Actor::New(); - Vector3 parentSize( 100.0f, 100.0f, 100.0f ); - parent.SetSize( parentSize ); - Stage::GetCurrent().Add( parent ); - - Constraint constraint = Constraint::New( Actor::Property::SIZE, - Source( parent, Actor::Property::SIZE ), - EqualToConstraint() ); - - // Create some child actors - - Actor child1 = Actor::New(); - parent.Add( child1 ); - - Actor child2 = Actor::New(); - parent.Add( child2 ); - - Actor child3 = Actor::New(); - parent.Add( child3 ); - - // Apply constraint with different timings - everything should be finished after 10 seconds - - wasConstraintCallbackCalled1 = false; - wasConstraintCallbackCalled2 = false; - wasConstraintCallbackCalled3 = false; - - constraint.SetApplyTime( 5.0f ); - ActiveConstraint activeConstraint1 = child1.ApplyConstraint( constraint ); - activeConstraint1.AppliedSignal().Connect( TestConstraintCallback1 ); - - constraint.SetApplyTime( 10.0f ); - ActiveConstraint activeConstraint2 = child2.ApplyConstraint( constraint ); - activeConstraint2.AppliedSignal().Connect( TestConstraintCallback2 ); - - constraint.SetApplyTime( TimePeriod( 2.0f/*delay*/, 5.0f/*duration*/ ) ); - ActiveConstraint activeConstraint3 = child3.ApplyConstraint( constraint ); - activeConstraint3.AppliedSignal().Connect( TestConstraintCallback3 ); - - // Check event-side size - DALI_TEST_EQUALS( child1.GetTargetSize(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( child2.GetTargetSize(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( child3.GetTargetSize(), Vector3::ZERO, TEST_LOCATION ); - - DALI_TEST_EQUALS( child1.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( child2.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( child3.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - application.SendNotification(); - - application.Render(static_cast(1000.0f)); // 1 elapsed second - - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // 1 / 5 * 100 = 20% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.10f, TEST_LOCATION ); // 1 / 10 * 100 = 10% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.00f, TEST_LOCATION ); // 0% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 2 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // 2 / 5 * 100 = 40% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // 2 / 10 * 100 = 20% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.00f, TEST_LOCATION ); // 0% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 3 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // 3 / 5 * 100 = 60% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.30f, TEST_LOCATION ); // 3 / 10 * 100 = 30% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // (3 - 2) / 5 * 100 = 20% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 4 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // 4 / 5 * 100 = 80% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // 4 / 10 * 100 = 40% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // (4 - 2) / 5 * 100 = 40% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 5 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // 5 / 5 * 100 = 100% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.50f, TEST_LOCATION ); // 5 / 10 * 100 = 50% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // (5 - 2) / 5 * 100 = 60% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 6 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 1 should fire) - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // 6 / 10 * 100 = 60% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // (6 - 2) / 5 * 100 = 80% - - // 1st signal should have fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, true, TEST_LOCATION ); - wasConstraintCallbackCalled1 = false; - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 7 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.70f, TEST_LOCATION ); // 7 / 10 * 100 = 70% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // (7 - 2) / 5 * 100 = 100% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f)); // 8 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // 8 / 10 * 100 = 80% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 3 should fire) - - // 3rd signal should have fired - application.SendNotification(); - - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, true, TEST_LOCATION ); - wasConstraintCallbackCalled3 = false; - - application.Render(static_cast(1000.0f)); // 9 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.90f, TEST_LOCATION ); // 9 / 10 * 100 = 90% - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - - // Check signals have not fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(static_cast(1000.0f + 1.0f)); // over 10 elapsed seconds - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 2 should fire) - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% - - // 2nd signal should have fired - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, true, TEST_LOCATION ); - wasConstraintCallbackCalled2 = false; - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - - application.Render(0); - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); - - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - - application.Render(0); - DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); - - application.SendNotification(); - DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION ); - DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION ); - END_TEST; -} - int UtcDaliActorRemoveConstraints(void) { tet_infoline(" UtcDaliActorRemoveConstraints"); @@ -2058,14 +1817,14 @@ int UtcDaliActorRemoveConstraints(void) Actor actor = Actor::New(); - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestConstraint() ); - actor.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( actor, Actor::Property::COLOR, TestConstraint() ); + constraint.Apply(); actor.RemoveConstraints(); DALI_TEST_CHECK( gTestConstraintCalled == false ); Stage::GetCurrent().Add( actor ); - actor.ApplyConstraint(constraint); + constraint.Apply(); // flush the queue and render once application.SendNotification(); @@ -2077,81 +1836,6 @@ int UtcDaliActorRemoveConstraints(void) END_TEST; } -int UtcDaliActorRemoveConstraint(void) -{ - tet_infoline(" UtcDaliActorRemoveConstraint"); - TestApplication application; - - Actor actor = Actor::New(); - - // 1. Apply Constraint1 and Constraint2, and test... - unsigned int result1 = 0u; - unsigned int result2 = 0u; - ActiveConstraint activeConstraint1 = actor.ApplyConstraint( Constraint::New( Actor::Property::COLOR, TestConstraintRef(result1, 1) ) ); - ActiveConstraint activeConstraint2 = actor.ApplyConstraint( Constraint::New( Actor::Property::COLOR, TestConstraintRef(result2, 2) ) ); - - Stage::GetCurrent().Add( actor ); - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); - - // 2. Remove Constraint1 and test... - result1 = 0; - result2 = 0; - actor.RemoveConstraint(activeConstraint1); - // make color property dirty, which will trigger constraints to be reapplied. - actor.SetColor( Color::WHITE ); - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now. - DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); - - // 3. Re-Apply Constraint1 and test... - result1 = 0; - result2 = 0; - activeConstraint1 = actor.ApplyConstraint( Constraint::New( Actor::Property::COLOR, TestConstraintRef(result1, 1) ) ); - // make color property dirty, which will trigger constraints to be reapplied. - actor.SetColor( Color::WHITE ); - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); - - // 2. Remove Constraint2 and test... - result1 = 0; - result2 = 0; - actor.RemoveConstraint(activeConstraint2); - // make color property dirty, which will trigger constraints to be reapplied. - actor.SetColor( Color::WHITE ); - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now. - - // 2. Remove Constraint1 as well and test... - result1 = 0; - result2 = 0; - actor.RemoveConstraint(activeConstraint1); - // make color property dirty, which will trigger constraints to be reapplied. - actor.SetColor( Color::WHITE ); - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now. - DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now. - END_TEST; -} - int UtcDaliActorRemoveConstraintTag(void) { tet_infoline(" UtcDaliActorRemoveConstraintTag"); @@ -2164,14 +1848,14 @@ int UtcDaliActorRemoveConstraintTag(void) unsigned int result2 = 0u; unsigned constraint1Tag = 1u; - Constraint constraint1 = Constraint::New( Actor::Property::COLOR, TestConstraintRef(result1, 1) ); + Constraint constraint1 = Constraint::New( actor, Actor::Property::COLOR, TestConstraintRef(result1, 1) ); constraint1.SetTag( constraint1Tag ); - actor.ApplyConstraint( constraint1 ); + constraint1.Apply(); unsigned constraint2Tag = 2u; - Constraint constraint2 = Constraint::New( Actor::Property::COLOR, TestConstraintRef(result2, 2) ); + Constraint constraint2 = Constraint::New( actor, Actor::Property::COLOR, TestConstraintRef(result2, 2) ); constraint2.SetTag( constraint2Tag ); - actor.ApplyConstraint( constraint2 ); + constraint2.Apply(); Stage::GetCurrent().Add( actor ); // flush the queue and render once @@ -2197,7 +1881,7 @@ int UtcDaliActorRemoveConstraintTag(void) // 3. Re-Apply Constraint1 and test... result1 = 0; result2 = 0; - actor.ApplyConstraint( constraint1 ); + constraint1.Apply(); // make color property dirty, which will trigger constraints to be reapplied. actor.SetColor( Color::WHITE ); // flush the queue and render once @@ -2765,8 +2449,9 @@ int UtcDaliActorConstrainedToWorldMatrix(void) Actor child = Actor::New(); child.SetParentOrigin(ParentOrigin::CENTER); - Constraint posConstraint = Constraint::New( Actor::Property::POSITION, Source( parent, Actor::Property::WORLD_MATRIX), PositionComponentConstraint() ); - child.ApplyConstraint(posConstraint); + Constraint posConstraint = Constraint::New( child, Actor::Property::POSITION, PositionComponentConstraint() ); + posConstraint.AddSource( Source( parent, Actor::Property::WORLD_MATRIX ) ); + posConstraint.Apply(); Stage::GetCurrent().Add( child ); diff --git a/automated-tests/src/dali/utc-Dali-Animation.cpp b/automated-tests/src/dali/utc-Dali-Animation.cpp index 25a0961..58b6460 100644 --- a/automated-tests/src/dali/utc-Dali-Animation.cpp +++ b/automated-tests/src/dali/utc-Dali-Animation.cpp @@ -8843,10 +8843,9 @@ struct UpdateManagerTestConstraint { } - Vector3 operator()(const Vector3& current) + void operator()( Vector3& current, const PropertyInputContainer& /* inputs */) { mApplication.SendNotification(); // Process events - return current; } TestApplication& mApplication; @@ -8868,8 +8867,8 @@ int UtcDaliAnimationUpdateManager(void) Vector3 startValue(1.0f, 1.0f, 1.0f); Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Constraint constraint = Constraint::New( index, UpdateManagerTestConstraint( application ) ); - actor.ApplyConstraint( constraint ); + Constraint constraint = Constraint::New( actor, index, UpdateManagerTestConstraint( application ) ); + constraint.Apply(); // Apply animation to actor animation.AnimateTo( Property(actor, Actor::Property::POSITION), Vector3( 100.f, 90.f, 80.f ), AlphaFunctions::Linear ); diff --git a/automated-tests/src/dali/utc-Dali-CameraActor.cpp b/automated-tests/src/dali/utc-Dali-CameraActor.cpp index 6d5cdc7..86b421f 100644 --- a/automated-tests/src/dali/utc-Dali-CameraActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CameraActor.cpp @@ -754,11 +754,13 @@ int UtcDaliCameraActorReadProjectionMatrix(void) Property::Index projectionMatrixPropertyIndex = shaderEffect.GetPropertyIndex(SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME); Property::Index viewMatrixPropertyIndex = shaderEffect.GetPropertyIndex(SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME); - Constraint projectionMatrixConstraint = Constraint::New( projectionMatrixPropertyIndex, Source( camera, CameraActor::Property::PROJECTION_MATRIX ), EqualToConstraint()); - Constraint viewMatrixConstraint = Constraint::New( viewMatrixPropertyIndex, Source( camera, CameraActor::Property::VIEW_MATRIX ), EqualToConstraint()); + Constraint projectionMatrixConstraint = Constraint::New( shaderEffect, projectionMatrixPropertyIndex, EqualToConstraint() ); + projectionMatrixConstraint.AddSource( Source( camera, CameraActor::Property::PROJECTION_MATRIX ) ); + Constraint viewMatrixConstraint = Constraint::New( shaderEffect, viewMatrixPropertyIndex, EqualToConstraint()); + viewMatrixConstraint.AddSource( Source( camera, CameraActor::Property::VIEW_MATRIX ) ); - shaderEffect.ApplyConstraint(projectionMatrixConstraint); - shaderEffect.ApplyConstraint(viewMatrixConstraint); + projectionMatrixConstraint.Apply(); + viewMatrixConstraint.Apply(); application.SendNotification(); application.Render(); @@ -780,7 +782,9 @@ int UtcDaliCameraActorAnimatedProperties(void) actor.SetSize(100.0f, 100.0f); Stage::GetCurrent().Add(actor); - actor.ApplyConstraint(Constraint::New( Actor::Property::POSITION, Source( camera, Actor::Property::POSITION), EqualToConstraint())); + Constraint constraint = Constraint::New( actor, Actor::Property::POSITION, EqualToConstraint()); + constraint.AddSource( Source( camera, Actor::Property::POSITION) ); + constraint.Apply(); camera.SetPosition(100.0f, 200.0f, 300.0f); application.SendNotification(); @@ -818,13 +822,11 @@ int UtcDaliCameraActorCheckLookAtAndFreeLookViews01(void) target.SetParentOrigin(ParentOrigin::CENTER); target.SetPosition(targetPosition); - Constraint cameraOrientationConstraint = - Constraint::New ( Actor::Property::ORIENTATION, - Source( target, Actor::Property::WORLD_POSITION ), - Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ), - Source( target, Actor::Property::WORLD_ORIENTATION ), - &LookAt ); - freeLookCameraActor.ApplyConstraint( cameraOrientationConstraint ); + Constraint cameraOrientationConstraint = Constraint::New ( freeLookCameraActor, Actor::Property::ORIENTATION, &LookAt ); + cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_ORIENTATION ) ); + cameraOrientationConstraint.Apply(); CameraActor lookAtCameraActor = CameraActor::New(stageSize); lookAtCameraActor.SetType(Camera::LOOK_AT_TARGET); @@ -880,13 +882,11 @@ int UtcDaliCameraActorCheckLookAtAndFreeLookViews02(void) target.SetParentOrigin(ParentOrigin::CENTER); target.SetPosition(targetPosition); - Constraint cameraOrientationConstraint = - Constraint::New ( Actor::Property::ORIENTATION, - Source( target, Actor::Property::WORLD_POSITION ), - Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ), - Source( target, Actor::Property::WORLD_ORIENTATION ), - &LookAt ); - freeLookCameraActor.ApplyConstraint( cameraOrientationConstraint ); + Constraint cameraOrientationConstraint = Constraint::New ( freeLookCameraActor, Actor::Property::ORIENTATION, &LookAt ); + cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( freeLookCameraActor, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( target, Actor::Property::WORLD_ORIENTATION ) ); + cameraOrientationConstraint.Apply(); CameraActor lookAtCameraActor = CameraActor::New(stageSize); lookAtCameraActor.SetType(Camera::LOOK_AT_TARGET); diff --git a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp index 57d0651..b0a7ef3 100644 --- a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp @@ -157,22 +157,16 @@ struct PanConstraint { PanConstraint( ConstraintData& data ) : constraintData(data) { } - Vector3 operator()(const Vector3& current, - const PropertyInput& screenPositionProperty, - const PropertyInput& screenDisplacementProperty, - const PropertyInput& screenVelocityProperty, - const PropertyInput& localPositionProperty, - const PropertyInput& localDisplacementProperty, - const PropertyInput& localVelocityProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - constraintData.screenPosition = screenPositionProperty.GetVector2(); - constraintData.screenDisplacement = screenDisplacementProperty.GetVector2(); - constraintData.screenVelocity = screenVelocityProperty.GetVector2(); - constraintData.localPosition = localPositionProperty.GetVector2(); - constraintData.localDisplacement = localDisplacementProperty.GetVector2(); - constraintData.localVelocity = localVelocityProperty.GetVector2(); + constraintData.screenPosition = inputs[0]->GetVector2(); + constraintData.screenDisplacement = inputs[1]->GetVector2(); + constraintData.screenVelocity = inputs[2]->GetVector2(); + constraintData.localPosition = inputs[3]->GetVector2(); + constraintData.localDisplacement = inputs[4]->GetVector2(); + constraintData.localVelocity = inputs[5]->GetVector2(); constraintData.called = true; - return Vector3::ZERO; + current = Vector3::ZERO; } ConstraintData& constraintData; @@ -2085,13 +2079,14 @@ int UtcDaliPanGestureNoPredictionNoSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2130,13 +2125,14 @@ int UtcDaliPanGestureNoPredictionSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2176,13 +2172,14 @@ int UtcDaliPanGesturePredictionNoSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2222,13 +2219,14 @@ int UtcDaliPanGesturePredictionSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2269,13 +2267,14 @@ int UtcDaliPanGestureSetProperties(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2329,13 +2328,14 @@ int UtcDaliPanGestureSetPropertiesAlreadyPanning(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::Property::SCREEN_POSITION ), - Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::Property::LOCAL_POSITION ), - Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.Apply(); // Render and notify application.SendNotification(); diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index d03cb79..30a04ae 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -58,9 +58,9 @@ struct TestConstraintToVector3 { } - Vector3 operator()(const Vector3& current) + void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ ) { - return mTarget; + current = mTarget; } Vector3 mTarget; @@ -72,10 +72,9 @@ struct TestConstraintFromPositionToVector3 { } - Vector3 operator()(const Vector3& current, const PropertyInput& position) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - - return position.GetVector3(); + current = inputs[0]->GetVector3(); } }; @@ -86,9 +85,9 @@ struct TestConstraintToVector3Double { } - Vector3 operator()(const Vector3& current) + void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ ) { - return mTarget * 2.0f; + current = mTarget * 2.0f; } Vector3 mTarget; @@ -642,10 +641,8 @@ int UtcDaliShaderEffectMethodApplyConstraint(void) application.GetGlAbstraction().CheckUniformValue( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - Constraint constraint = Constraint::New( uVecProperty, - TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - - effect.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); + constraint.Apply(); application.SendNotification(); application.Render(); @@ -681,11 +678,9 @@ int UtcDaliShaderEffectMethodApplyConstraintFromActor(void) Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - Constraint constraint = Constraint::New( uVecProperty, - Source(actor, Actor::Property::POSITION), - TestConstraintFromPositionToVector3() ); - - effect.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintFromPositionToVector3() ); + constraint.AddSource( Source( actor, Actor::Property::POSITION ) ); + constraint.Apply(); application.SendNotification(); application.Render(); @@ -721,16 +716,12 @@ int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void) Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - Constraint shaderConstraint = Constraint::New( uVecProperty, - Source(actor, Actor::Property::POSITION), - TestConstraintFromPositionToVector3() ); - - effect.ApplyConstraint(shaderConstraint); + Constraint shaderConstraint = Constraint::New( effect, uVecProperty, TestConstraintFromPositionToVector3() ); + shaderConstraint.AddSource( Source(actor, Actor::Property::POSITION) ); + shaderConstraint.Apply(); - Constraint actorConstraint = Constraint::New( Actor::Property::POSITION, - TestConstraintToVector3Double(targetPosition) ); - - actor.ApplyConstraint(actorConstraint); + Constraint actorConstraint = Constraint::New( actor, Actor::Property::POSITION, TestConstraintToVector3Double(targetPosition) ); + actorConstraint.Apply(); application.SendNotification(); application.Render(); @@ -742,78 +733,6 @@ int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void) END_TEST; } -int UtcDaliShaderEffectMethodApplyConstraintCallback(void) -{ - // Test whether Shader's uniform can be constrained to a stationary constraint. - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - application.SendNotification(); - application.Render(); - - // Test effects of SetUniform... - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - - Constraint constraint = Constraint::New( uVecProperty, - TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - - constraint.SetApplyTime( 10.0f ); - - bool constraintCheck( false ); - ConstraintAppliedCheck appliedCheck( constraintCheck ); - - // We should receive the "Applied" signal after 10 seconds - ActiveConstraint active = effect.ApplyConstraint(constraint); - active.AppliedSignal().Connect( &application, appliedCheck ); - - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 1 elapsed second - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(4000.0f)); // 5 elapsed seconds - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(5000.0f - 1.0f)); // <10 elapsed seconds - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(2.0f)); // >10 elapsed seconds - - // Signal should have fired - application.SendNotification(); - appliedCheck.CheckSignalReceived(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) ); - END_TEST; -} - int UtcDaliShaderEffectMethodRemoveConstraints(void) { // Test if constrains can be removed before they are ever applyed. @@ -842,10 +761,8 @@ int UtcDaliShaderEffectMethodRemoveConstraints(void) application.GetGlAbstraction().CheckUniformValue( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - Constraint constraint = Constraint::New( uVecProperty, - TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - - effect.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); + constraint.Apply(); // Remove the constraints effect.RemoveConstraints(); @@ -888,10 +805,8 @@ int UtcDaliShaderEffectMethodRemoveConstraints2(void) application.GetGlAbstraction().CheckUniformValue( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - Constraint constraint = Constraint::New( uVecProperty, - TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - - effect.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); + constraint.Apply(); application.SendNotification(); application.Render(); diff --git a/dali/integration-api/profiling.cpp b/dali/integration-api/profiling.cpp index 4343fe5..ec65a61 100644 --- a/dali/integration-api/profiling.cpp +++ b/dali/integration-api/profiling.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -113,9 +112,8 @@ const int ANIMATION_MEMORY_SIZE( sizeof( Internal::AnimatorConnector ) + sizeof( Internal::SceneGraph::Animation ) ); const int CONSTRAINT_MEMORY_SIZE( - sizeof( Internal::Constraint ) + - sizeof( Internal::SceneGraph::Constraint > ) + - sizeof( Internal::ActiveConstraint ) ); + sizeof( Internal::Constraint ) + + sizeof( Internal::SceneGraph::Constraint > ) ); const int ACTOR_MEMORY_SIZE( sizeof( Internal::Actor ) + sizeof( Internal::ActorAttachment ) + diff --git a/dali/internal/event/animation/active-constraint-base.cpp b/dali/internal/event/animation/active-constraint-base.cpp deleted file mode 100644 index 730d0fe..0000000 --- a/dali/internal/event/animation/active-constraint-base.cpp +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using Dali::Internal::SceneGraph::AnimatableProperty; - -namespace Dali -{ - -namespace Internal -{ - -namespace // unnamed namespace -{ - -// Properties - -// Name Type writable animatable constraint-input enum for index-checking -DALI_PROPERTY_TABLE_BEGIN -DALI_PROPERTY( "weight", FLOAT, true, true, true, Dali::ActiveConstraint::Property::WEIGHT ) -DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX ) - -// Signals - -const char* const SIGNAL_APPLIED = "applied"; - -BaseHandle Create() -{ - // not directly creatable - return BaseHandle(); -} - -TypeRegistration mType( typeid(Dali::ActiveConstraint), typeid(Dali::Handle), Create ); - -SignalConnectorType signalConnector1( mType, SIGNAL_APPLIED, &ActiveConstraintBase::DoConnectSignal ); - -} // unnamed namespace - -ActiveConstraintBase::ActiveConstraintBase( Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount ) -: mTargetPropertyIndex( targetPropertyIndex ), - mSources( sources ), - mSourceCount( sourceCount ), - mTargetObject( NULL ), - mObservedObjects(), - mSceneGraphConstraint( NULL ), - mCustomWeight( NULL ), - mOffstageWeight( Dali::ActiveConstraint::DEFAULT_WEIGHT ), - mAlphaFunction( Dali::Constraint::DEFAULT_ALPHA_FUNCTION ), - mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ), - mTag(0), - mApplyAnimation() -{ - // Skip init when any of the objects have been destroyed - if ( mSources.size() != mSourceCount ) - { - // Discard all object pointers - mTargetObject = NULL; - mSources.clear(); - } - - // Observe the objects providing properties - for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) - { - if ( OBJECT_PROPERTY == iter->sourceType ) - { - DALI_ASSERT_ALWAYS( NULL != iter->object && "ActiveConstraint source object not found" ); - - ObserveObject( *(iter->object) ); - } - } -} - -ActiveConstraintBase::~ActiveConstraintBase() -{ - StopObservation(); - - // Disconnect from internal animation signals - if ( mApplyAnimation ) - { - GetImplementation(mApplyAnimation).SetFinishedCallback( NULL, NULL ); - } -} - -void ActiveConstraintBase::SetCustomWeightObject( Object& weightObject, Property::Index weightIndex ) -{ - const SceneGraph::PropertyBase* base = weightObject.GetSceneObjectAnimatableProperty( weightIndex ); - const SceneGraph::AnimatableProperty* sceneProperty = dynamic_cast< const SceneGraph::AnimatableProperty* >( base ); - - if( sceneProperty ) - { - mCustomWeight = sceneProperty; - - ObserveObject( weightObject ); - } -} - -void ActiveConstraintBase::FirstApply( Object& parent, TimePeriod applyTime ) -{ - DALI_ASSERT_ALWAYS( NULL == mTargetObject && "Parent of ActiveConstraint already set" ); - - // No need to do anything, if the source objects are gone - if( mSources.size() == mSourceCount ) - { - mTargetObject = &parent; - - ConnectConstraint(); - } - - if ( applyTime.durationSeconds > 0.0f ) - { - DALI_ASSERT_DEBUG( !mApplyAnimation ); - - // Set start weight - SetWeight( 0.0f ); - - // Automatically animate (increase) the weight, until the constraint is fully applied - mApplyAnimation = Dali::Animation::New( applyTime.delaySeconds + applyTime.durationSeconds ); - Dali::ActiveConstraint self( this ); - mApplyAnimation.AnimateTo( Property( self, Dali::ActiveConstraint::Property::WEIGHT ), Dali::ActiveConstraint::FINAL_WEIGHT, mAlphaFunction, applyTime ); - mApplyAnimation.Play(); - - // Chain "Finish" to "Applied" signal - GetImplementation(mApplyAnimation).SetFinishedCallback( &ActiveConstraintBase::FirstApplyFinished, this ); - } -} - -void ActiveConstraintBase::OnParentDestroyed() -{ - // Stop observing the remaining objects - StopObservation(); - - // Discard all object pointers - mTargetObject = NULL; - mSources.clear(); -} - -void ActiveConstraintBase::OnParentSceneObjectAdded() -{ - if ( NULL == mSceneGraphConstraint && - mTargetObject ) - { - ConnectConstraint(); - } -} - -void ActiveConstraintBase::OnParentSceneObjectRemoved() -{ - if ( mSceneGraphConstraint ) - { - // Notify base class that the scene-graph constraint is being removed - OnSceneObjectRemove(); - - // mSceneGraphConstraint will be deleted in update-thread, remove dangling pointer - mSceneGraphConstraint = NULL; - } -} - -void ActiveConstraintBase::BeginRemove() -{ - // Stop observing the remaining objects - StopObservation(); - - // Discard all object pointers - mSources.clear(); - - const SceneGraph::PropertyOwner* propertyOwner = mTargetObject ? mTargetObject->GetSceneObject() : NULL; - - if ( propertyOwner && - mSceneGraphConstraint ) - { - // Notify base class that the scene-graph constraint is being removed - OnSceneObjectRemove(); - - // Remove from scene-graph - RemoveConstraintMessage( GetEventThreadServices(), *propertyOwner, *(mSceneGraphConstraint) ); - - // mSceneGraphConstraint will be deleted in update-thread, remove dangling pointer - mSceneGraphConstraint = NULL; - } -} - -Object* ActiveConstraintBase::GetParent() -{ - return mTargetObject; -} - -bool ActiveConstraintBase::Supports( Capability capability ) const -{ - return false; // switch-off support for dynamic properties -} - -Dali::Handle ActiveConstraintBase::GetTargetObject() -{ - return Dali::Handle( mTargetObject ); -} - -Property::Index ActiveConstraintBase::GetTargetProperty() -{ - return mTargetPropertyIndex; -} - -void ActiveConstraintBase::SetWeight( float weight ) -{ - if ( mSceneGraphConstraint ) - { - BakeWeightMessage( GetEventThreadServices(), *mSceneGraphConstraint, weight ); - } - else - { - mOffstageWeight = weight; - } -} - -float ActiveConstraintBase::GetCurrentWeight() const -{ - float currentWeight( mOffstageWeight ); - - if ( mSceneGraphConstraint ) - { - currentWeight = mSceneGraphConstraint->GetWeight( GetEventThreadServices().GetEventBufferIndex() ); - } - - return currentWeight; -} - -ActiveConstraintSignalType& ActiveConstraintBase::AppliedSignal() -{ - return mAppliedSignal; -} - -bool ActiveConstraintBase::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) -{ - bool connected( true ); - ActiveConstraintBase* constraint = dynamic_cast(object); - - if ( 0 == strcmp( signalName.c_str(), SIGNAL_APPLIED ) ) - { - constraint->AppliedSignal().Connect( tracker, functor ); - } - else - { - // signalName does not match any signal - connected = false; - } - - return connected; -} - -void ActiveConstraintBase::SetAlphaFunction( AlphaFunction alphaFunc ) -{ - mAlphaFunction = alphaFunc; -} - -AlphaFunction ActiveConstraintBase::GetAlphaFunction() const -{ - return mAlphaFunction; -} - -void ActiveConstraintBase::SetRemoveAction( ActiveConstraintBase::RemoveAction action ) -{ - mRemoveAction = action; -} - -ActiveConstraintBase::RemoveAction ActiveConstraintBase::GetRemoveAction() const -{ - return mRemoveAction; -} - -void ActiveConstraintBase::SetTag(const unsigned int tag) -{ - mTag = tag; -} - -unsigned int ActiveConstraintBase::GetTag() const -{ - return mTag; -} - -unsigned int ActiveConstraintBase::GetDefaultPropertyCount() const -{ - return DEFAULT_PROPERTY_COUNT; -} - -void ActiveConstraintBase::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const -{ - indices.reserve( DEFAULT_PROPERTY_COUNT ); - - for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i ) - { - indices.push_back( i ); - } -} - -const char* ActiveConstraintBase::GetDefaultPropertyName( Property::Index index ) const -{ - if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) ) - { - return DEFAULT_PROPERTY_DETAILS[index].name; - } - else - { - return NULL; - } -} - -Property::Index ActiveConstraintBase::GetDefaultPropertyIndex( const std::string& name ) const -{ - Property::Index index = Property::INVALID_INDEX; - - // Only one name to compare with... - if( 0 == strcmp( name.c_str(), DEFAULT_PROPERTY_DETAILS[0].name ) ) // Don't want to convert rhs to string - { - index = 0; - } - - return index; -} - -bool ActiveConstraintBase::IsDefaultPropertyWritable( Property::Index index ) const -{ - return DEFAULT_PROPERTY_DETAILS[ index ].writable; -} - -bool ActiveConstraintBase::IsDefaultPropertyAnimatable( Property::Index index ) const -{ - return DEFAULT_PROPERTY_DETAILS[ index ].animatable; -} - -bool ActiveConstraintBase::IsDefaultPropertyAConstraintInput( Property::Index index ) const -{ - return DEFAULT_PROPERTY_DETAILS[ index ].constraintInput; -} - -Property::Type ActiveConstraintBase::GetDefaultPropertyType( Property::Index index ) const -{ - if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) ) - { - return DEFAULT_PROPERTY_DETAILS[index].type; - } - - // Index out-of-range - return Property::NONE; -} - -void ActiveConstraintBase::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) -{ - if( Dali::ActiveConstraint::Property::WEIGHT == index ) - { - SetWeight( propertyValue.Get() ); - } -} - -Property::Value ActiveConstraintBase::GetDefaultProperty( Property::Index index ) const -{ - Property::Value value; - - if( Dali::ActiveConstraint::Property::WEIGHT == index ) - { - value = GetCurrentWeight(); - } - - return value; -} - -const SceneGraph::PropertyOwner* ActiveConstraintBase::GetSceneObject() const -{ - return mSceneGraphConstraint; -} - -const SceneGraph::PropertyBase* ActiveConstraintBase::GetSceneObjectAnimatableProperty( Property::Index index ) const -{ - DALI_ASSERT_DEBUG( 0 == index ); // only 1 property supported - - // This method should only return a property which is part of the scene-graph - if ( !mSceneGraphConstraint ) - { - return NULL; - } - - return &mSceneGraphConstraint->mWeight; -} - -const PropertyInputImpl* ActiveConstraintBase::GetSceneObjectInputProperty( Property::Index index ) const -{ - DALI_ASSERT_DEBUG( 0 == index ); // only 1 property supported - - // This method should only return a property which is part of the scene-graph - if ( !mSceneGraphConstraint ) - { - return NULL; - } - - return &mSceneGraphConstraint->mWeight; -} - -void ActiveConstraintBase::SceneObjectAdded( Object& object ) -{ - // Should not be getting callbacks when mSources has been cleared - DALI_ASSERT_DEBUG( mSources.size() == mSourceCount ); - - if ( NULL == mSceneGraphConstraint && - mTargetObject ) - { - ConnectConstraint(); - } -} - -void ActiveConstraintBase::SceneObjectRemoved( Object& object ) -{ - // Notify base class that the scene-graph constraint is being removed - OnSceneObjectRemove(); - - if ( mSceneGraphConstraint ) - { - // Preserve the previous weight - mOffstageWeight = mSceneGraphConstraint->GetWeight( GetEventThreadServices().GetEventBufferIndex() ); - - const SceneGraph::PropertyOwner* propertyOwner = mTargetObject ? mTargetObject->GetSceneObject() : NULL; - - if( propertyOwner ) - { - // Remove from scene-graph - RemoveConstraintMessage( GetEventThreadServices(), *propertyOwner, *(mSceneGraphConstraint) ); - } - - // mSceneGraphConstraint will be deleted in update-thread, remove dangling pointer - mSceneGraphConstraint = NULL; - } -} - -void ActiveConstraintBase::ObjectDestroyed( Object& object ) -{ - // Remove object pointer from observation set - ObjectIter iter = std::find( mObservedObjects.Begin(), mObservedObjects.End(), &object ); - DALI_ASSERT_DEBUG( mObservedObjects.End() != iter ); - mObservedObjects.Erase( iter ); - - // Stop observing the remaining objects - StopObservation(); - - // Discard all object & scene-graph pointers - mSceneGraphConstraint = NULL; - mTargetObject = NULL; - mSources.clear(); -} - -void ActiveConstraintBase::ObserveObject( Object& object ) -{ - ObjectIter iter = std::find( mObservedObjects.Begin(), mObservedObjects.End(), &object ); - if ( mObservedObjects.End() == iter ) - { - object.AddObserver( *this ); - mObservedObjects.PushBack( &object ); - } -} - -void ActiveConstraintBase::StopObservation() -{ - const ObjectIter end = mObservedObjects.End(); - for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter ) - { - (*iter)->RemoveObserver( *this ); - } - - mObservedObjects.Clear(); -} - -void ActiveConstraintBase::FirstApplyFinished( Object* object ) -{ - // trust the object is correct as its set in FirstApply (in this same file) - ActiveConstraintBase* self = static_cast( object ); - - // This is necessary when the constraint was not added to scene-graph during the animation - self->SetWeight( Dali::ActiveConstraint::FINAL_WEIGHT ); - - // The animation is no longer needed - GetImplementation(self->mApplyAnimation).SetFinishedCallback( NULL, NULL ); - self->mApplyAnimation.Reset(); - - // Chain "Finish" to "Applied" signal - - if ( !self->mAppliedSignal.Empty() ) - { - Dali::ActiveConstraint handle( self ); - self->mAppliedSignal.Emit( handle ); - } - - // WARNING - this constraint may now have been deleted; don't do anything else here -} - -} // namespace Internal - -} // namespace Dali diff --git a/dali/internal/event/animation/active-constraint-base.h b/dali/internal/event/animation/active-constraint-base.h deleted file mode 100644 index 680c6e4..0000000 --- a/dali/internal/event/animation/active-constraint-base.h +++ /dev/null @@ -1,352 +0,0 @@ -#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ -#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -class EventThreadServices; -typedef Dali::Vector ObjectContainer; -typedef ObjectContainer::Iterator ObjectIter; - -namespace SceneGraph -{ -class ConstraintBase; - -template -class AnimatableProperty; -} - -/** - * An abstract base class for active constraints. - */ -class ActiveConstraintBase : public Object, public Object::Observer -{ -public: - - typedef Dali::Constraint::RemoveAction RemoveAction; - typedef Any AnyFunction; - - /** - * Constructor. - * @param[in] messageController Used to send messages to the update-thread. - * @param[in] targetPropertyIndex The index of the property being constrained. - * @param[in] sources The sources of the input properties. - * @param[in] sourceCount The original number of sources; this may not match sources.size() if objects have died. - */ - ActiveConstraintBase( Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount ); - - /** - * Virtual destructor. - */ - virtual ~ActiveConstraintBase(); - - /** - * Clone an active-constraint. - * @return A new active-constraint. - */ - virtual ActiveConstraintBase* Clone() = 0; - - /** - * Set a custom "weight" property. - * @param[in] weightObject An object with a "weight" float property. - * @param[in] weightIndex The index of the weight property. - */ - void SetCustomWeightObject( Object& weightObject, Property::Index weightIndex ); - - /** - * Called when the ActiveConstraint is first applied. - * @pre The active-constraint does not already have a parent. - * @param[in] parent The parent object. - * @param[in] applyTime The apply-time for this constraint. - */ - void FirstApply( Object& parent, TimePeriod applyTime ); - - /** - * Called when the ActiveConstraint is removed. - */ - void BeginRemove(); - - /** - * Called when the target object is destroyed. - */ - void OnParentDestroyed(); - - /** - * Called when the target object is connected to the scene-graph - */ - void OnParentSceneObjectAdded(); - - /** - * Called when the target object is disconnected from the scene-graph - */ - void OnParentSceneObjectRemoved(); - - /** - * Retrieve the parent of the active-constraint. - * @return The parent object, or NULL. - */ - Object* GetParent(); - - /** - * @copydoc Dali::Internal::Object::Supports() - */ - virtual bool Supports( Object::Capability capability ) const; - - /** - * @copydoc Dali::ActiveConstraint::GetTargetObject() - */ - Dali::Handle GetTargetObject(); - - /** - * @copydoc Dali::ActiveConstraint::GetTargetProperty() - */ - Property::Index GetTargetProperty(); - - /** - * @copydoc Dali::ActiveConstraint::SetWeight() - */ - void SetWeight( float weight ); - - /** - * @copydoc Dali::ActiveConstraint::GetCurrentWeight() - */ - float GetCurrentWeight() const; - - /** - * @copydoc Dali::ActiveConstraint::AppliedSignal() - */ - ActiveConstraintSignalType& AppliedSignal(); - - /** - * @copydoc Dali::Constraint::SetAlphaFunction() - */ - void SetAlphaFunction(AlphaFunction func); - - /** - * @copydoc Dali::Constraint::GetAlphaFunction() - */ - AlphaFunction GetAlphaFunction() const; - - /** - * @copydoc Dali::Constraint::SetRemoveAction() - */ - void SetRemoveAction(RemoveAction action); - - /** - * @copydoc Dali::Constraint::GetRemoveAction() - */ - RemoveAction GetRemoveAction() const; - - /** - * @copydoc Dali::Constraint::SetTag() - */ - void SetTag(const unsigned int tag); - - /** - * @copydoc Dali::Constraint::GetTag() - */ - unsigned int GetTag() const; - - /** - * Connects a callback function with the object's signals. - * @param[in] object The object providing the signal. - * @param[in] tracker Used to disconnect the signal. - * @param[in] signalName The signal to connect to. - * @param[in] functor A newly allocated FunctorDelegate. - * @return True if the signal was connected. - * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor. - */ - static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ); - -public: // Default property extensions from Object - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyCount() - */ - virtual unsigned int GetDefaultPropertyCount() const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices() - */ - virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyName() - */ - virtual const char* GetDefaultPropertyName( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex() - */ - virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable() - */ - virtual bool IsDefaultPropertyWritable( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable() - */ - virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput() - */ - virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyType() - */ - virtual Property::Type GetDefaultPropertyType( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::SetDefaultProperty() - */ - virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ); - - /** - * @copydoc Dali::Internal::Object::GetDefaultProperty() - */ - virtual Property::Value GetDefaultProperty( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObject() - */ - virtual const SceneGraph::PropertyOwner* GetSceneObject() const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty() - */ - virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty() - */ - virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const; - -public: // Object::Observer methods - - /** - * @copydoc Object::Observer::SceneObjectAdded() - */ - virtual void SceneObjectAdded( Object& object ); - - /** - * @copydoc Object::Observer::SceneObjectRemoved() - */ - virtual void SceneObjectRemoved( Object& object ); - - /** - * @copydoc Object::Observer::ObjectDestroyed() - */ - virtual void ObjectDestroyed( Object& object ); - -private: - - /** - * Helper to observe an object, if not already observing it - */ - void ObserveObject( Object& object ); - - /** - * Helper to stop observing objects - */ - void StopObservation(); - - /** - * Helper called after the first apply animation. - * @param [in] object The active constraint. - */ - static void FirstApplyFinished( Object* object ); - - // To be implemented in derived classes - - /** - * Create and connect a constraint for a scene-object. - */ - virtual void ConnectConstraint() = 0; - -protected: - Property::Index mTargetPropertyIndex; - SourceContainer mSources; - const unsigned int mSourceCount; - - Object* mTargetObject; ///< The object owns the active-constraint. - ObjectContainer mObservedObjects; // We don't observe the same object twice - - const SceneGraph::ConstraintBase* mSceneGraphConstraint; - - const SceneGraph::AnimatableProperty* mCustomWeight; - - float mOffstageWeight; - - AlphaFunction mAlphaFunction; - - RemoveAction mRemoveAction; - unsigned int mTag; - -private: - - ActiveConstraintSignalType mAppliedSignal; - - Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f - -}; - -} // namespace Internal - -// Helpers for public-api forwarding methods - -inline Internal::ActiveConstraintBase& GetImplementation(Dali::ActiveConstraint& constraint) -{ - DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" ); - - BaseObject& handle = constraint.GetBaseObject(); - - return static_cast(handle); -} - -inline const Internal::ActiveConstraintBase& GetImplementation(const Dali::ActiveConstraint& constraint) -{ - DALI_ASSERT_ALWAYS( constraint && "ActiveConstraint handle is empty" ); - - const BaseObject& handle = constraint.GetBaseObject(); - - return static_cast(handle); -} - -} // namespace Dali - -#endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ diff --git a/dali/internal/event/animation/active-constraint-impl.h b/dali/internal/event/animation/active-constraint-impl.h deleted file mode 100644 index 4ad167a..0000000 --- a/dali/internal/event/animation/active-constraint-impl.h +++ /dev/null @@ -1,599 +0,0 @@ -#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ -#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -/** - * Helper to add only unique entries to the propertyOwner container - * @param propertyOwners to add the entries to - * @param object to add - */ -inline void AddUnique( SceneGraph::PropertyOwnerContainer& propertyOwners, SceneGraph::PropertyOwner* object ) -{ - const SceneGraph::PropertyOwnerIter iter = std::find( propertyOwners.Begin(), propertyOwners.End(), object ); - if( iter == propertyOwners.End() ) - { - // each owner should only be added once - propertyOwners.PushBack( object ); - } -} - -/** - * Connects a constraint which takes another property as an input. - */ -template < typename PropertyType > -class ActiveConstraint : public ActiveConstraintBase -{ -public: - - typedef SceneGraph::Constraint< PropertyType, PropertyAccessor > SceneGraphConstraint; - typedef const SceneGraph::AnimatableProperty* ScenePropertyPtr; - typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; - - /** - * Construct a new active-constraint. - * @param[in] targetIndex The index of the property to constrain. - * @param[in] sources The sources of the input properties passed to func. - * @param[in] func The constraint function. - * @return A newly allocated active-constraint. - */ - static ActiveConstraintBase* New( Property::Index targetIndex, - SourceContainer& sources, - ConstraintFunctionPtr func ) - { - return new ActiveConstraint< PropertyType >( targetIndex, sources, sources.size(), func ); - } - - /** - * Virtual destructor. - */ - virtual ~ActiveConstraint() - { - // This is not responsible for removing constraints. - } - - /** - * @copydoc ActiveConstraintBase::Clone() - */ - virtual ActiveConstraintBase* Clone() - { - ActiveConstraintBase* clone( NULL ); - - ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); - - clone = new ActiveConstraint< PropertyType >( mTargetIndex, - mSources, - mSourceCount, - funcPtr ); - - clone->SetAlphaFunction(mAlphaFunction); - clone->SetRemoveAction(mRemoveAction); - clone->SetTag( mTag ); - - return clone; - } - -private: - - /** - * Private constructor; see also ActiveConstraint::New(). - */ - ActiveConstraint( Property::Index targetIndex, - SourceContainer& sources, - unsigned int sourceCount, - ConstraintFunctionPtr& func ) - : ActiveConstraintBase( targetIndex, sources, sourceCount ), - mTargetIndex( targetIndex ), - mUserFunction( func ) - { - } - - // Undefined - ActiveConstraint( const ActiveConstraint& ); - - // Undefined - ActiveConstraint& operator=( const ActiveConstraint& rhs ); - - /** - * Create and connect a constraint for a scene-object. - */ - void ConnectConstraint() - { - // Should not come here any objects have been destroyed - DALI_ASSERT_DEBUG( NULL != mTargetObject ); - DALI_ASSERT_DEBUG( mSources.size() == mSourceCount ); - - // Guard against double connections - DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); - - // Short-circuit until the target scene-object exists - SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); - if ( NULL == targetObject ) - { - return; - } - - // Build a container of property-owners, providing the scene-graph properties - SceneGraph::PropertyOwnerContainer propertyOwners; - propertyOwners.PushBack( targetObject ); - - // Build the constraint function; this requires a scene-graph property from each source - ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); - - if ( func ) - { - // Create the SceneGraphConstraint, and connect to the scene-graph - - const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); - - // The targetProperty should exist, when targetObject exists - DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); - - // Connect the constraint - SceneGraph::ConstraintBase* sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, - propertyOwners, - func, - mCustomWeight ); - DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); - sceneGraphConstraint->SetInitialWeight( mOffstageWeight ); - sceneGraphConstraint->SetRemoveAction( mRemoveAction ); - - // object is being used in a separate thread; queue a message to apply the constraint - ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); - - // Keep a raw-pointer to the scene-graph constraint - mSceneGraphConstraint = sceneGraphConstraint; - - // Notify Object base-class that the scene-graph constraint has been added - OnSceneObjectAdd(); - } - } - - /** - * Helper for ConnectConstraint. Creates a connected constraint-function. - * Also populates the property-owner container, for each input connected to the constraint-function. - * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. - * @return A connected constraint-function, or NULL if the scene-graph properties are not available. - */ - PropertyConstraintBase* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) - { - PropertyConstraintBase* func = mUserFunction->Clone(); - bool usingComponentFunc( false ); - - for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) - { - Source& source = *iter; - - PropertyInputImpl* inputProperty( NULL ); - int componentIndex( Property::INVALID_COMPONENT_INDEX ); - - if ( OBJECT_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); - - // The property owner will not exist, if the target object is off-stage - if( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - else if ( LOCAL_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); - - inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); - - // The target scene-object should provide this property - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - else - { - DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); - - Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); - - // This will not exist, if the target object is off-stage - if ( NULL != objectParent ) - { - DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); - - // The property owner will not exist, if the parent object is off-stage - if ( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - } - - if ( NULL == inputProperty ) - { - delete func; - func = NULL; - - // Exit if a scene-graph object is not available from one of the sources - break; - } - else if ( Property::INVALID_COMPONENT_INDEX != componentIndex ) - { - // Special case where component indices are required - if ( !usingComponentFunc ) - { - PropertyConstraintBase* componentFunc = func->CloneComponentFunc(); - usingComponentFunc = true; - - // Switch to function supporting component indices - delete func; - func = componentFunc; - } - } - - func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); - } - - return func; - } - -protected: - - Property::Index mTargetIndex; - - ConstraintFunctionPtr mUserFunction; -}; - -/** - * Variant which allows float components to be animated individually. - */ -template <> -class ActiveConstraint : public ActiveConstraintBase -{ -public: - - typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; - - /** - * Construct a new active-constraint. - * @param[in] targetIndex The index of the property to constrain. - * @param[in] sources The sources of the input properties passed to func. - * @param[in] func The constraint function. - * @return A newly allocated active-constraint. - */ - static ActiveConstraintBase* New( Property::Index targetIndex, - SourceContainer& sources, - ConstraintFunctionPtr func ) - { - return new ActiveConstraint< float >( targetIndex, sources, sources.size(), func ); - } - - /** - * Virtual destructor. - */ - virtual ~ActiveConstraint() - { - // This is not responsible for removing constraints. - } - - /** - * @copydoc ActiveConstraintBase::Clone() - */ - virtual ActiveConstraintBase* Clone() - { - ActiveConstraintBase* clone( NULL ); - - ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); - - clone = new ActiveConstraint< float >( mTargetIndex, - mSources, - mSourceCount, - funcPtr ); - - clone->SetAlphaFunction(mAlphaFunction); - clone->SetRemoveAction(mRemoveAction); - clone->SetTag( mTag ); - - return clone; - } - -private: - - /** - * Private constructor; see also ActiveConstraint::New(). - */ - ActiveConstraint( Property::Index targetIndex, - SourceContainer& sources, - unsigned int sourceCount, - ConstraintFunctionPtr& func ) - : ActiveConstraintBase( targetIndex, sources, sourceCount ), - mTargetIndex( targetIndex ), - mUserFunction( func ) - { - } - - // Undefined - ActiveConstraint( const ActiveConstraint& ); - - // Undefined - ActiveConstraint& operator=( const ActiveConstraint& rhs ); - - /** - * Create and connect a constraint for a scene-object. - */ - void ConnectConstraint() - { - // Should not come here any objects have been destroyed - DALI_ASSERT_DEBUG( NULL != mTargetObject ); - DALI_ASSERT_DEBUG( mSources.size() == mSourceCount ); - - // Guard against double connections - DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); - - // Short-circuit until the target scene-object exists - SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); - if ( NULL == targetObject ) - { - return; - } - - // Build a container of property-owners, providing the scene-graph properties - SceneGraph::PropertyOwnerContainer propertyOwners; - propertyOwners.PushBack( targetObject ); - - // Build the constraint function; this requires a scene-graph property from each source - ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); - - if ( func ) - { - // Create the SceneGraphConstraint, and connect to the scene-graph - - const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); - - // The targetProperty should exist, when targetObject exists - DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); - - const int componentIndex = mTargetObject->GetPropertyComponentIndex( mTargetIndex ); - - SceneGraph::ConstraintBase* sceneGraphConstraint( NULL ); - - if ( Property::INVALID_COMPONENT_INDEX == componentIndex ) - { - // Not a Vector3 or Vector4 component, expecting float type - DALI_ASSERT_DEBUG( PropertyTypes::Get< float >() == targetProperty->GetType() ); - - typedef SceneGraph::Constraint< float, PropertyAccessor > SceneGraphConstraint; - - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, - propertyOwners, - func, - mCustomWeight ); - } - else - { - // Expecting Vector3 or Vector4 type - - if ( PropertyTypes::Get< Vector3 >() == targetProperty->GetType() ) - { - // Constrain float component of Vector3 property - - if ( 0 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - else if ( 1 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - else if ( 2 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - } - else if ( PropertyTypes::Get< Vector4 >() == targetProperty->GetType() ) - { - // Constrain float component of Vector4 property - - if ( 0 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - else if ( 1 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - else if ( 2 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - else if ( 3 == componentIndex ) - { - typedef SceneGraph::Constraint< float, PropertyComponentAccessorW > SceneGraphConstraint; - sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func, mCustomWeight ); - } - } - } - - DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); - sceneGraphConstraint->SetInitialWeight( mOffstageWeight ); - sceneGraphConstraint->SetRemoveAction( mRemoveAction ); - - // object is being used in a separate thread; queue a message to apply the constraint - ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); - - // Keep a raw-pointer to the scene-graph constraint - mSceneGraphConstraint = sceneGraphConstraint; - - // Notify Object base-class that the scene-graph constraint has been added - OnSceneObjectAdd(); - } - } - - /** - * Helper for ConnectConstraint. Creates a connected constraint-function. - * Also populates the property-owner container, for each input connected to the constraint-function. - * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. - * @return A connected constraint-function, or NULL if the scene-graph properties are not available. - */ - PropertyConstraintBase* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) - { - PropertyConstraintBase* func = mUserFunction->Clone(); - bool usingComponentFunc( false ); - - for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) - { - Source& source = *iter; - - PropertyInputImpl* inputProperty( NULL ); - int componentIndex( Property::INVALID_COMPONENT_INDEX ); - - if ( OBJECT_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); - - // The property owner will not exist, if the target object is off-stage - if( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - else if ( LOCAL_PROPERTY == source.sourceType ) - { - DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); - - inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); - - // The target scene-object should provide this property - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - else - { - DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); - - Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); - - // This will not exist, if the target object is off-stage - if ( NULL != objectParent ) - { - DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); - - SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); - - // The property owner will not exist, if the parent object is off-stage - if ( NULL != owner ) - { - AddUnique( propertyOwners, owner ); - inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); - componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); - - // The scene-object property should exist, when the property owner exists - DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); - } - } - } - - if ( NULL == inputProperty ) - { - delete func; - func = NULL; - - // Exit if a scene-graph object is not available from one of the sources - break; - } - else if ( Property::INVALID_COMPONENT_INDEX != componentIndex ) - { - // Special case where component indices are required - if ( !usingComponentFunc ) - { - PropertyConstraintBase* componentFunc = func->CloneComponentFunc(); - usingComponentFunc = true; - - // Switch to function supporting component indices - delete func; - func = componentFunc; - } - } - - func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); - } - - return func; - } - -protected: - - Property::Index mTargetIndex; - - ConstraintFunctionPtr mUserFunction; -}; - -} // namespace Internal - -} // namespace Dali - -#endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ diff --git a/dali/internal/event/animation/constraint-base.cpp b/dali/internal/event/animation/constraint-base.cpp new file mode 100644 index 0000000..24e41b0 --- /dev/null +++ b/dali/internal/event/animation/constraint-base.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include + +using Dali::Internal::SceneGraph::AnimatableProperty; + +namespace Dali +{ + +namespace Internal +{ + +ConstraintBase::ConstraintBase( Object& object, Property::Index targetPropertyIndex, SourceContainer& sources ) +: mEventThreadServices( *Stage::GetCurrent() ), + mTargetObject( &object ), + mSceneGraphConstraint( NULL ), + mSources( sources ), + mObservedObjects(), + mTargetPropertyIndex( targetPropertyIndex ), + mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ), + mTag( 0 ), + mApplied( false ), + mSourceDestroyed( false ) +{ + ObserveObject( object ); +} + +ConstraintBase::~ConstraintBase() +{ + StopObservation(); + + RemoveInternal(); +} + +void ConstraintBase::AddSource( Source source ) +{ + mSources.push_back( source ); + + // Observe the object providing this property + if ( OBJECT_PROPERTY == source.sourceType ) + { + if ( source.object != NULL ) + { + ObserveObject( *source.object ); + } + else + { + DALI_LOG_ERROR( "Constraint source object not found" ); + } + } +} + +void ConstraintBase::Apply() +{ + if ( mTargetObject && !mApplied && !mSourceDestroyed ) + { + mApplied = true; + ConnectConstraint(); + + mTargetObject->ApplyConstraint( *this ); + } +} + +void ConstraintBase::Remove() +{ + RemoveInternal(); + + if( mTargetObject ) + { + mTargetObject->RemoveConstraint( *this ); + } +} + +void ConstraintBase::RemoveInternal() +{ + if ( mApplied ) + { + mApplied = false; + + // Guard against constraint sending messages during core destruction + if( Stage::IsInstalled() ) + { + const SceneGraph::PropertyOwner* propertyOwner = mTargetObject ? mTargetObject->GetSceneObject() : NULL; + + if ( propertyOwner && + mSceneGraphConstraint ) + { + // Remove from scene-graph + RemoveConstraintMessage( GetEventThreadServices(), *propertyOwner, *(mSceneGraphConstraint) ); + + // mSceneGraphConstraint will be deleted in update-thread, remove dangling pointer + mSceneGraphConstraint = NULL; + } + } + } +} + +Object* ConstraintBase::GetParent() +{ + return mTargetObject; +} + +Dali::Handle ConstraintBase::GetTargetObject() +{ + return Dali::Handle( mTargetObject ); +} + +Property::Index ConstraintBase::GetTargetProperty() +{ + return mTargetPropertyIndex; +} + +void ConstraintBase::SetRemoveAction( ConstraintBase::RemoveAction action ) +{ + mRemoveAction = action; +} + +ConstraintBase::RemoveAction ConstraintBase::GetRemoveAction() const +{ + return mRemoveAction; +} + +void ConstraintBase::SetTag(const unsigned int tag) +{ + mTag = tag; +} + +unsigned int ConstraintBase::GetTag() const +{ + return mTag; +} + +void ConstraintBase::SceneObjectAdded( Object& object ) +{ + if ( mApplied && + ( NULL == mSceneGraphConstraint ) && + mTargetObject ) + { + ConnectConstraint(); + } +} + +void ConstraintBase::SceneObjectRemoved( Object& object ) +{ + if ( mSceneGraphConstraint ) + { + // An input property owning source has been deleted, need to tell the scene-graph-constraint owner to remove it + if ( &object != mTargetObject ) + { + const SceneGraph::PropertyOwner* propertyOwner = mTargetObject ? mTargetObject->GetSceneObject() : NULL; + + if( propertyOwner ) + { + // Remove from scene-graph + RemoveConstraintMessage( GetEventThreadServices(), *propertyOwner, *(mSceneGraphConstraint) ); + } + } + + // mSceneGraphConstraint will be deleted in update-thread, remove dangling pointer + mSceneGraphConstraint = NULL; + } +} + +void ConstraintBase::ObjectDestroyed( Object& object ) +{ + // Remove object pointer from observation set + ObjectIter iter = std::find( mObservedObjects.Begin(), mObservedObjects.End(), &object ); + DALI_ASSERT_DEBUG( mObservedObjects.End() != iter ); + mObservedObjects.Erase( iter ); + + if ( &object != mTargetObject ) + { + // Constraint is not useful anymore as an input-source has been destroyed + mSourceDestroyed = true; + + // Stop observing the remaining objects + StopObservation(); + + // Clear our sources as well + mSources.clear(); + + // We should remove ourselves from the target-object's constraints as well + if ( mTargetObject ) + { + mTargetObject->RemoveConstraint( *this ); + } + } + + // NOTE: We do not clear our sources if our target-object is destroyed because we may want to clone this constraint for another target + + // Discard all object & scene-graph pointers + mSceneGraphConstraint = NULL; + mTargetObject = NULL; +} + +void ConstraintBase::ObserveObject( Object& object ) +{ + ObjectIter iter = std::find( mObservedObjects.Begin(), mObservedObjects.End(), &object ); + if ( mObservedObjects.End() == iter ) + { + object.AddObserver( *this ); + mObservedObjects.PushBack( &object ); + } +} + +void ConstraintBase::StopObservation() +{ + const ObjectIter end = mObservedObjects.End(); + for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter ) + { + (*iter)->RemoveObserver( *this ); + } + + mObservedObjects.Clear(); +} + +} // namespace Internal + +} // namespace Dali diff --git a/dali/internal/event/animation/constraint-base.h b/dali/internal/event/animation/constraint-base.h new file mode 100644 index 0000000..5b006ed --- /dev/null +++ b/dali/internal/event/animation/constraint-base.h @@ -0,0 +1,238 @@ +#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ +#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ + +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include + +namespace Dali +{ + +namespace Internal +{ + +class EventThreadServices; +class Object; +typedef Dali::Vector ObjectContainer; +typedef ObjectContainer::Iterator ObjectIter; + +namespace SceneGraph +{ +class ConstraintBase; + +template +class AnimatableProperty; +} + +/** + * An abstract base class for active constraints. + */ +class ConstraintBase : public BaseObject, public Object::Observer +{ +public: + + typedef Dali::Constraint::RemoveAction RemoveAction; + + /** + * Constructor. + * @param[in] object The property owning object. + * @param[in] messageController Used to send messages to the update-thread. + * @param[in] targetPropertyIndex The index of the property being constrained. + * @param[in] sources The sources of the input properties. + */ + ConstraintBase( Object& object, Property::Index targetPropertyIndex, SourceContainer& sources ); + + /** + * Clone this constraint for another object. + * @param[in] object The object to clone this constraint for + * @return A new constraint. + */ + virtual ConstraintBase* Clone( Object& object ) = 0; + + /** + * Virtual destructor. + */ + virtual ~ConstraintBase(); + + /** + * Adds a constraint source to the constraint + * + * @param[in] source The constraint source input to add + */ + void AddSource( Source source ); + + /** + * @copydoc Dali::Constraint::Apply() + */ + void Apply(); + + /** + * @copydoc Dali::Constraint::Remove() + */ + void Remove(); + + /** + * Called when the Constraint is removed. + * + * @note This removes the scene-object as well but then does not call back into the target-object. + */ + void RemoveInternal(); + + /** + * Retrieve the parent of the constraint. + * @return The parent object, or NULL. + */ + Object* GetParent(); + + /** + * @copydoc Dali::Constraint::GetTargetObject() + */ + Dali::Handle GetTargetObject(); + + /** + * @copydoc Dali::Constraint::GetTargetProperty() + */ + Property::Index GetTargetProperty(); + + /** + * @copydoc Dali::Constraint::SetRemoveAction() + */ + void SetRemoveAction(RemoveAction action); + + /** + * @copydoc Dali::Constraint::GetRemoveAction() + */ + RemoveAction GetRemoveAction() const; + + /** + * @copydoc Dali::Constraint::SetTag() + */ + void SetTag(const unsigned int tag); + + /** + * @copydoc Dali::Constraint::GetTag() + */ + unsigned int GetTag() const; + +private: // Object::Observer methods + + /** + * @copydoc Object::Observer::SceneObjectAdded() + */ + virtual void SceneObjectAdded( Object& object ); + + /** + * @copydoc Object::Observer::SceneObjectRemoved() + */ + virtual void SceneObjectRemoved( Object& object ); + + /** + * @copydoc Object::Observer::ObjectDestroyed() + */ + virtual void ObjectDestroyed( Object& object ); + +private: + + /** + * Helper to observe an object, if not already observing it + */ + void ObserveObject( Object& object ); + + /** + * Helper to stop observing objects + */ + void StopObservation(); + + // To be implemented in derived classes + + /** + * Create and connect a constraint for a scene-object. + */ + virtual void ConnectConstraint() = 0; + +protected: + + /** + * Get the event thread services object - used for sending messages to the scene graph + * Assert if called from the wrong thread. + * This is intentionally inline for performance reasons. + * + * @return The event thread services object + */ + inline EventThreadServices& GetEventThreadServices() + { + DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() ); + return mEventThreadServices; + } + + /** + * Get the event thread services object - used for sending messages to the scene graph + * Assert if called from the wrong thread + * This is intentionally inline for performance reasons. + * + * @return The event thread services object + */ + inline const EventThreadServices& GetEventThreadServices() const + { + DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() ); + return mEventThreadServices; + } + +protected: + EventThreadServices& mEventThreadServices; + Object* mTargetObject; ///< The object owns the constraint. + const SceneGraph::ConstraintBase* mSceneGraphConstraint; + SourceContainer mSources; + ObjectContainer mObservedObjects; // We don't observe the same object twice + Property::Index mTargetPropertyIndex; + RemoveAction mRemoveAction; + unsigned int mTag; + bool mApplied:1; ///< Whether the constraint has been applied + bool mSourceDestroyed:1; ///< Is set to true if any of our input source objects are destroyed +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::ConstraintBase& GetImplementation(Dali::Constraint& constraint) +{ + DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" ); + + BaseObject& handle = constraint.GetBaseObject(); + + return static_cast(handle); +} + +inline const Internal::ConstraintBase& GetImplementation(const Dali::Constraint& constraint) +{ + DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" ); + + const BaseObject& handle = constraint.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Dali + +#endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__ diff --git a/dali/internal/event/animation/constraint-impl.cpp b/dali/internal/event/animation/constraint-impl.cpp deleted file mode 100644 index ece2366..0000000 --- a/dali/internal/event/animation/constraint-impl.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// EXTERNAL INCLUDES -#include - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -namespace // unnamed namespace -{ - -template -PropertyConstraintBase

* CreatePropertyConstraint( Constraint::AnyFunction& func, unsigned int sourceCount ) -{ - PropertyConstraintBase

* propertyConstraint( NULL ); - - switch ( sourceCount ) - { - case 0u: - { - propertyConstraint = new PropertyConstraint0

( AnyCast >( func ) ); - break; - } - - case 1u: - { - propertyConstraint = new PropertyConstraint1( AnyCast< boost::function

>( func ) ); - break; - } - - case 2u: - { - propertyConstraint = new PropertyConstraint2( AnyCast< boost::function

>( func ) ); - break; - } - - case 3u: - { - propertyConstraint = new PropertyConstraint3( AnyCast< boost::function

>( func ) ); - break; - } - - case 4u: - { - propertyConstraint = new PropertyConstraint4( AnyCast< boost::function

>( func ) ); - break; - } - - case 5u: - { - propertyConstraint = new PropertyConstraint5( AnyCast< boost::function

>( func ) ); - break; - } - - case 6u: - { - propertyConstraint = new PropertyConstraint6( AnyCast< boost::function

>( func ) ); - break; - } - - - default: - { - // should never come here - DALI_ASSERT_ALWAYS( false && "Cannot have more than 6 property constraints" ); - break; - } - } - - return propertyConstraint; -} - -} // unnamed namespace - -Constraint::Constraint( Property::Index targetIndex, - Property::Type targetType, - SourceContainer& sources, - AnyFunction& func ) -: mApplyTime( 0.0f ) -{ - switch ( targetType ) - { - case Property::BOOLEAN: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::FLOAT: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::INTEGER: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::VECTOR2: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::VECTOR3: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::VECTOR4: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::ROTATION: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::MATRIX: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - case Property::MATRIX3: - { - PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( func, sources.size() ) ); - - mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint::New( targetIndex, - sources, - funcPtr ) ); - break; - } - - default: - { - DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here - break; - } - } -} - -ActiveConstraintBase* Constraint::CreateActiveConstraint() -{ - return GetImplementation( mActiveConstraintTemplate ).Clone(); -} - -void Constraint::SetApplyTime( TimePeriod timePeriod ) -{ - mApplyTime = timePeriod; -} - -TimePeriod Constraint::GetApplyTime() const -{ - return mApplyTime; -} - -void Constraint::SetAlphaFunction( Dali::AlphaFunction func ) -{ - GetImplementation( mActiveConstraintTemplate ).SetAlphaFunction( func ); -} - -Dali::AlphaFunction Constraint::GetAlphaFunction() const -{ - return GetImplementation( mActiveConstraintTemplate ).GetAlphaFunction(); -} - -void Constraint::SetRemoveAction( Dali::Constraint::RemoveAction action ) -{ - GetImplementation( mActiveConstraintTemplate ).SetRemoveAction( action ); -} - -Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const -{ - return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction(); -} - - -void Constraint::SetTag(unsigned int tag) -{ - GetImplementation( mActiveConstraintTemplate ).SetTag(tag); -} - -unsigned int Constraint::GetTag() const -{ - return GetImplementation( mActiveConstraintTemplate ).GetTag(); -} - - - -Constraint::~Constraint() -{ -} - -} // namespace Internal - -} // namespace Dali diff --git a/dali/internal/event/animation/constraint-impl.h b/dali/internal/event/animation/constraint-impl.h index d9b2d30..bffc047 100644 --- a/dali/internal/event/animation/constraint-impl.h +++ b/dali/internal/event/animation/constraint-impl.h @@ -1,5 +1,5 @@ -#ifndef __DALI_INTERNAL_CONSTRAINT_H__ -#define __DALI_INTERNAL_CONSTRAINT_H__ +#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ +#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ /* * Copyright (c) 2014 Samsung Electronics Co., Ltd. @@ -19,12 +19,20 @@ */ // INTERNAL INCLUDES -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include namespace Dali { @@ -32,124 +40,524 @@ namespace Dali namespace Internal { -class ActiveConstraintBase; -class Object; +/** + * Helper to add only unique entries to the propertyOwner container + * @param propertyOwners to add the entries to + * @param object to add + */ +inline void AddUnique( SceneGraph::PropertyOwnerContainer& propertyOwners, SceneGraph::PropertyOwner* object ) +{ + const SceneGraph::PropertyOwnerIter iter = std::find( propertyOwners.Begin(), propertyOwners.End(), object ); + if( iter == propertyOwners.End() ) + { + // each owner should only be added once + propertyOwners.PushBack( object ); + } +} /** - * Constraints are used to constrain a property of an object, after animations have been applied. + * Connects a constraint which takes another property as an input. */ -class Constraint : public BaseObject +template < typename PropertyType > +class Constraint : public ConstraintBase { public: - typedef Any AnyFunction; + typedef SceneGraph::Constraint< PropertyType, PropertyAccessor > SceneGraphConstraint; + typedef const SceneGraph::AnimatableProperty* ScenePropertyPtr; + typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; /** - * Construct a new constraint which targets a property. - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] sources The objects which provide parameters for func. - * @param [in] func The constraint function. + * Construct a new constraint. + * @param[in] object The property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] sources The sources of the input properties passed to func. + * @param[in] func The constraint function. + * @return A newly allocated active-constraint. */ - Constraint( Property::Index target, - Property::Type targetType, - SourceContainer& sources, - AnyFunction& func ); + static ConstraintBase* New( Object& object, + Property::Index targetIndex, + SourceContainer& sources, + ConstraintFunctionPtr func ) + { + return new Constraint< PropertyType >( object, targetIndex, sources, func ); + } /** - * @copydoc Dali::Constraint::SetApplyTime() + * @copydoc ConstraintBase::Clone() */ - void SetApplyTime( TimePeriod timePeriod ); + virtual ConstraintBase* Clone( Object& object ) + { + DALI_ASSERT_ALWAYS( !mSourceDestroyed && "An input source object has been destroyed" ); + + ConstraintBase* clone( NULL ); + + ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); + + clone = new Constraint< PropertyType >( object, + mTargetIndex, + mSources, + funcPtr ); + + clone->SetRemoveAction(mRemoveAction); + clone->SetTag( mTag ); + + return clone; + } - /** - * @copydoc Dali::Constraint::GetApplyTime() - */ - TimePeriod GetApplyTime() const; /** - * @copydoc Dali::Constraint::SetAlphaFunction( AlphaFunction func ) + * Virtual destructor. */ - void SetAlphaFunction( AlphaFunction func ); + virtual ~Constraint() + { + // This is not responsible for removing constraints. + } + +private: /** - * @copydoc Dali::Constraint::GetAlphaFunction() + * Private constructor; see also Constraint::New(). */ - AlphaFunction GetAlphaFunction() const; + Constraint( Object& object, + Property::Index targetIndex, + SourceContainer& sources, + ConstraintFunctionPtr& func ) + : ConstraintBase( object, targetIndex, sources ), + mTargetIndex( targetIndex ), + mUserFunction( func ) + { + } + + // Undefined + Constraint( const Constraint& ); + + // Undefined + Constraint& operator=( const Constraint& rhs ); /** - * @copydoc Dali::Constraint::SetRemoveAction() + * Create and connect a constraint for a scene-object. */ - void SetRemoveAction(Dali::Constraint::RemoveAction action); + void ConnectConstraint() + { + // Should not come here if target-object has been destroyed + DALI_ASSERT_DEBUG( NULL != mTargetObject ); + + // Guard against double connections + DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); + + // Short-circuit until the target scene-object exists + SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); + if ( NULL == targetObject ) + { + return; + } + + // Build a container of property-owners, providing the scene-graph properties + SceneGraph::PropertyOwnerContainer propertyOwners; + propertyOwners.PushBack( targetObject ); + + // Build the constraint function; this requires a scene-graph property from each source + ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); + + if ( func ) + { + // Create the SceneGraphConstraint, and connect to the scene-graph + + const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); + + // The targetProperty should exist, when targetObject exists + DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); + + // Connect the constraint + SceneGraph::ConstraintBase* sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, + propertyOwners, + func ); + DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); + sceneGraphConstraint->SetRemoveAction( mRemoveAction ); + + // object is being used in a separate thread; queue a message to apply the constraint + ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); + + // Keep a raw-pointer to the scene-graph constraint + mSceneGraphConstraint = sceneGraphConstraint; + } + } /** - * @copydoc Dali::Constraint::GetRemoveAction() + * Helper for ConnectConstraint. Creates a connected constraint-function. + * Also populates the property-owner container, for each input connected to the constraint-function. + * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. + * @return A connected constraint-function, or NULL if the scene-graph properties are not available. */ - Dali::Constraint::RemoveAction GetRemoveAction() const; + PropertyConstraint* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) + { + PropertyConstraint* func = mUserFunction->Clone(); + + for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) + { + Source& source = *iter; + + PropertyInputImpl* inputProperty( NULL ); + int componentIndex( Property::INVALID_COMPONENT_INDEX ); + + if ( OBJECT_PROPERTY == source.sourceType ) + { + DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); + + SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); + + // The property owner will not exist, if the target object is off-stage + if( NULL != owner ) + { + AddUnique( propertyOwners, owner ); + inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); + + // The scene-object property should exist, when the property owner exists + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + } + else if ( LOCAL_PROPERTY == source.sourceType ) + { + DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); + + inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); + + // The target scene-object should provide this property + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + else + { + DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); + + Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); + + // This will not exist, if the target object is off-stage + if ( NULL != objectParent ) + { + DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); + + SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); + + // The property owner will not exist, if the parent object is off-stage + if ( NULL != owner ) + { + AddUnique( propertyOwners, owner ); + inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); + + // The scene-object property should exist, when the property owner exists + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + } + } + + if ( NULL == inputProperty ) + { + delete func; + func = NULL; + + // Exit if a scene-graph object is not available from one of the sources + break; + } + + func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); + } + + return func; + } + +protected: + + Property::Index mTargetIndex; + + ConstraintFunctionPtr mUserFunction; +}; + +/** + * Variant which allows float components to be animated individually. + */ +template <> +class Constraint : public ConstraintBase +{ +public: + + typedef typename PropertyConstraintPtr::Type ConstraintFunctionPtr; /** - * @copydoc Dali::Constraint::SetTag() + * Construct a new constraint. + * @param[in] object The property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] sources The sources of the input properties passed to func. + * @param[in] func The constraint function. + * @return A newly allocated constraint. */ - void SetTag( const unsigned int tag); + static ConstraintBase* New( Object& object, + Property::Index targetIndex, + SourceContainer& sources, + ConstraintFunctionPtr func ) + { + return new Constraint< float >( object, targetIndex, sources, func ); + } /** - * @copydoc Dali::Constraint::GetTag() + * @copydoc ConstraintBase::Clone() */ - unsigned int GetTag() const; + virtual ConstraintBase* Clone( Object& object ) + { + DALI_ASSERT_ALWAYS( !mSourceDestroyed && "An input source object has been destroyed" ); + ConstraintBase* clone( NULL ); + ConstraintFunctionPtr funcPtr( mUserFunction->Clone() ); + clone = new Constraint< float >( object, + mTargetIndex, + mSources, + funcPtr ); - /** - * Create an active constraint. - * An active constraint is created each time the constraint is applied to an object. - * @return A newly allocated active-constraint. - */ - ActiveConstraintBase* CreateActiveConstraint(); + clone->SetRemoveAction(mRemoveAction); + clone->SetTag( mTag ); -protected: + return clone; + } /** - * A reference counted object may only be deleted by calling Unreference() + * Virtual destructor. */ - virtual ~Constraint(); + virtual ~Constraint() + { + // This is not responsible for removing constraints. + } private: + /** + * Private constructor; see also Constraint::New(). + */ + Constraint( Object& object, + Property::Index targetIndex, + SourceContainer& sources, + ConstraintFunctionPtr& func ) + : ConstraintBase( object, targetIndex, sources ), + mTargetIndex( targetIndex ), + mUserFunction( func ) + { + } + // Undefined - Constraint(const Constraint&); + Constraint( const Constraint& ); // Undefined - Constraint& operator=(const Constraint& rhs); + Constraint& operator=( const Constraint& rhs ); + + /** + * Create and connect a constraint for a scene-object. + */ + void ConnectConstraint() + { + // Should not come here if target-object has been destroyed + DALI_ASSERT_DEBUG( NULL != mTargetObject ); + + // Guard against double connections + DALI_ASSERT_DEBUG( NULL == mSceneGraphConstraint ); + + // Short-circuit until the target scene-object exists + SceneGraph::PropertyOwner* targetObject = const_cast< SceneGraph::PropertyOwner* >( mTargetObject->GetSceneObject() ); + if ( NULL == targetObject ) + { + return; + } + + // Build a container of property-owners, providing the scene-graph properties + SceneGraph::PropertyOwnerContainer propertyOwners; + propertyOwners.PushBack( targetObject ); + + // Build the constraint function; this requires a scene-graph property from each source + ConstraintFunctionPtr func( ConnectConstraintFunction( propertyOwners ) ); + + if ( func ) + { + // Create the SceneGraphConstraint, and connect to the scene-graph + + const SceneGraph::PropertyBase* targetProperty = mTargetObject->GetSceneObjectAnimatableProperty( mTargetIndex ); + + // The targetProperty should exist, when targetObject exists + DALI_ASSERT_ALWAYS( NULL != targetProperty && "Constraint target property does not exist" ); + + const int componentIndex = mTargetObject->GetPropertyComponentIndex( mTargetIndex ); + + SceneGraph::ConstraintBase* sceneGraphConstraint( NULL ); + + if ( Property::INVALID_COMPONENT_INDEX == componentIndex ) + { + // Not a Vector3 or Vector4 component, expecting float type + DALI_ASSERT_DEBUG( PropertyTypes::Get< float >() == targetProperty->GetType() ); + + typedef SceneGraph::Constraint< float, PropertyAccessor > SceneGraphConstraint; + + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, + propertyOwners, + func ); + } + else + { + // Expecting Vector3 or Vector4 type + + if ( PropertyTypes::Get< Vector3 >() == targetProperty->GetType() ) + { + // Constrain float component of Vector3 property + + if ( 0 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + else if ( 1 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + else if ( 2 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + } + else if ( PropertyTypes::Get< Vector4 >() == targetProperty->GetType() ) + { + // Constrain float component of Vector4 property + + if ( 0 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorX > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + else if ( 1 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorY > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + else if ( 2 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorZ > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + else if ( 3 == componentIndex ) + { + typedef SceneGraph::Constraint< float, PropertyComponentAccessorW > SceneGraphConstraint; + sceneGraphConstraint = SceneGraphConstraint::New( *targetProperty, propertyOwners, func ); + } + } + } + + DALI_ASSERT_DEBUG( NULL != sceneGraphConstraint ); + sceneGraphConstraint->SetRemoveAction( mRemoveAction ); + + // object is being used in a separate thread; queue a message to apply the constraint + ApplyConstraintMessage( GetEventThreadServices(), *targetObject, *sceneGraphConstraint ); + + // Keep a raw-pointer to the scene-graph constraint + mSceneGraphConstraint = sceneGraphConstraint; + } + } + + /** + * Helper for ConnectConstraint. Creates a connected constraint-function. + * Also populates the property-owner container, for each input connected to the constraint-function. + * @param[out] propertyOwners The container of property-owners providing the scene-graph properties. + * @return A connected constraint-function, or NULL if the scene-graph properties are not available. + */ + PropertyConstraint* ConnectConstraintFunction( SceneGraph::PropertyOwnerContainer& propertyOwners ) + { + PropertyConstraint* func = mUserFunction->Clone(); + + for ( SourceIter iter = mSources.begin(); mSources.end() != iter; ++iter ) + { + Source& source = *iter; + + PropertyInputImpl* inputProperty( NULL ); + int componentIndex( Property::INVALID_COMPONENT_INDEX ); + + if ( OBJECT_PROPERTY == source.sourceType ) + { + DALI_ASSERT_ALWAYS( source.object->IsPropertyAConstraintInput( source.propertyIndex ) ); + + SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( source.object->GetSceneObject() ); + + // The property owner will not exist, if the target object is off-stage + if( NULL != owner ) + { + AddUnique( propertyOwners, owner ); + inputProperty = const_cast< PropertyInputImpl* >( source.object->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = source.object->GetPropertyComponentIndex( source.propertyIndex ); + + // The scene-object property should exist, when the property owner exists + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + } + else if ( LOCAL_PROPERTY == source.sourceType ) + { + DALI_ASSERT_ALWAYS( mTargetObject->IsPropertyAConstraintInput( source.propertyIndex ) ); + + inputProperty = const_cast< PropertyInputImpl* >( mTargetObject->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = mTargetObject->GetPropertyComponentIndex( source.propertyIndex ); + + // The target scene-object should provide this property + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + else + { + DALI_ASSERT_ALWAYS( PARENT_PROPERTY == source.sourceType && "Constraint source property type is invalid" ); + + Object* objectParent = dynamic_cast< Actor& >( *mTargetObject ).GetParent(); + + // This will not exist, if the target object is off-stage + if ( NULL != objectParent ) + { + DALI_ASSERT_ALWAYS( objectParent->IsPropertyAConstraintInput( source.propertyIndex ) ); + + SceneGraph::PropertyOwner* owner = const_cast< SceneGraph::PropertyOwner* >( objectParent->GetSceneObject() ); + + // The property owner will not exist, if the parent object is off-stage + if ( NULL != owner ) + { + AddUnique( propertyOwners, owner ); + inputProperty = const_cast< PropertyInputImpl* >( objectParent->GetSceneObjectInputProperty( source.propertyIndex ) ); + componentIndex = objectParent->GetPropertyComponentIndex( source.propertyIndex ); + + // The scene-object property should exist, when the property owner exists + DALI_ASSERT_ALWAYS( NULL != inputProperty && "Constraint source property does not exist" ); + } + } + } + + if ( NULL == inputProperty ) + { + delete func; + func = NULL; + + // Exit if a scene-graph object is not available from one of the sources + break; + } + + func->SetInput( ( iter - mSources.begin() ), componentIndex, *inputProperty ); + } + + return func; + } protected: - Dali::ActiveConstraint mActiveConstraintTemplate; ///< Used to create active constraints + Property::Index mTargetIndex; - TimePeriod mApplyTime; + ConstraintFunctionPtr mUserFunction; }; } // namespace Internal -// Helpers for public-api forwarding methods - -inline Internal::Constraint& GetImplementation(Dali::Constraint& constraint) -{ - DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" ); - - BaseObject& handle = constraint.GetBaseObject(); - - return static_cast(handle); -} - -inline const Internal::Constraint& GetImplementation(const Dali::Constraint& constraint) -{ - DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" ); - - const BaseObject& handle = constraint.GetBaseObject(); - - return static_cast(handle); -} - } // namespace Dali -#endif // __DALI_INTERNAL_CONSTRAINT_H__ +#endif // __DALI_INTERNAL_ACTIVE_CONSTRAINT_H__ diff --git a/dali/internal/event/animation/path-constraint-impl.cpp b/dali/internal/event/animation/path-constraint-impl.cpp index 3e0a74b..d9e8e2e 100644 --- a/dali/internal/event/animation/path-constraint-impl.cpp +++ b/dali/internal/event/animation/path-constraint-impl.cpp @@ -192,26 +192,23 @@ void PathConstraint::Apply( Property source, Property target, const Vector3& for if( propertyType == Dali::Property::VECTOR3) { - //If property is Vector3, contraint its value to the position of the path - - Dali::Constraint constraint = Dali::Constraint::New( target.propertyIndex, - Source(source.object, source.propertyIndex ), - PathConstraintFunctor( mPath, mRange ) ); + // If property is Vector3, constrain its value to the position of the path + Dali::Constraint constraint = Dali::Constraint::New( target.object, target.propertyIndex, PathConstraintFunctor( mPath, mRange ) ); + constraint.AddSource( Source(source.object, source.propertyIndex ) ); constraint.SetTag( reinterpret_cast( this ) ); constraint.SetRemoveAction( Dali::Constraint::Discard ); - target.object.ApplyConstraint(constraint); + constraint.Apply(); } else if( propertyType == Dali::Property::ROTATION ) { - //If property is Rotation, constraint its value to align the forward vector to the tangent of the path - Dali::Constraint constraint = Dali::Constraint::New( target.propertyIndex, - Source(source.object, source.propertyIndex ), - PathConstraintFunctor( mPath, mRange,forward) ); + // If property is Rotation, constrain its value to align the forward vector to the tangent of the path + Dali::Constraint constraint = Dali::Constraint::New( target.object, target.propertyIndex, PathConstraintFunctor( mPath, mRange,forward) ); + constraint.AddSource( Source(source.object, source.propertyIndex ) ); constraint.SetTag( reinterpret_cast( this ) ); constraint.SetRemoveAction( Dali::Constraint::Discard ); - target.object.ApplyConstraint(constraint); + constraint.Apply(); } //Add the object to the list of observed objects if it is not there already diff --git a/dali/internal/event/animation/path-constraint-impl.h b/dali/internal/event/animation/path-constraint-impl.h index abebe16..714e0f9 100644 --- a/dali/internal/event/animation/path-constraint-impl.h +++ b/dali/internal/event/animation/path-constraint-impl.h @@ -63,35 +63,34 @@ struct PathConstraintFunctor /** * @brief Functor operator for Vector3 properties * - * @param[in] current Current value of the property - * @param[in] property The input property used as the parameter for the path + * @param[in,out] position Current value of the property + * @param[in] inputs Contains the input property used as the parameter for the path * * @return The position of the path at the given parameter. */ - Vector3 operator()(const Vector3& current, - const PropertyInput& property) + void operator()( Vector3& position, + const PropertyInputContainer& inputs) { - float t = ( property.GetFloat() - mRange.x ) / (mRange.y-mRange.x); - Vector3 position, tangent; + float t = ( inputs[0]->GetFloat() - mRange.x ) / ( mRange.y-mRange.x ); + Vector3 tangent; mPath->Sample( t, position, tangent ); - return position; } /** * @brief Functor operator for Quaternion properties * - * @param[in] current Current value of the property - * @param[in] property The input property used as the parameter for the path + * @param[in,out] current Current value of the property + * @param[in] inputs Contains the input property used as the parameter for the path * * @return The rotation which will align the forward vector and the tangent of the path at the given parameter. */ - Quaternion operator()( const Quaternion& current, - const PropertyInput& property) + void operator()( Quaternion& current, + const PropertyInputContainer& inputs) { - float t = ( property.GetFloat() - mRange.x ) / (mRange.y-mRange.x); + float t = ( inputs[0]->GetFloat() - mRange.x ) / (mRange.y-mRange.x); Vector3 position, tangent; mPath->Sample( t, position, tangent ); - return Quaternion( mForward, tangent ); + current = Quaternion( mForward, tangent ); } PathPtr mPath; ///< The path used diff --git a/dali/internal/event/animation/property-constraint-ptr.h b/dali/internal/event/animation/property-constraint-ptr.h index 85a6c75..495607a 100644 --- a/dali/internal/event/animation/property-constraint-ptr.h +++ b/dali/internal/event/animation/property-constraint-ptr.h @@ -31,7 +31,7 @@ namespace Internal template struct PropertyConstraintPtr { - typedef OwnerPointer< PropertyConstraintBase

> Type; + typedef OwnerPointer< PropertyConstraint

> Type; }; } // namespace Internal diff --git a/dali/internal/event/animation/property-constraint.h b/dali/internal/event/animation/property-constraint.h index 0779f45..196c229 100644 --- a/dali/internal/event/animation/property-constraint.h +++ b/dali/internal/event/animation/property-constraint.h @@ -19,6 +19,9 @@ */ // INTERNAL INCLUDES +#include +#include +#include #include #include #include @@ -30,51 +33,95 @@ namespace Internal { /** - * A base class for connecting properties to a constraint function. + * A class for connecting properties to a constraint function. */ template < typename PropertyType > -class PropertyConstraintBase +class PropertyConstraint { public: + typedef std::vector < PropertyInputAccessor > InputContainer; + typedef typename InputContainer::iterator InputContainerIter; + typedef typename InputContainer::const_iterator InputContainerConstIter; + + typedef std::vector< PropertyInputIndexer< PropertyInputAccessor > > InputIndexerContainer; + + typedef Dali::Constraint::Function< PropertyType > ConstraintFunction; + /** * Create a property constraint. + * + * @param[in] func A constraint function. Ownership of this callback-function is passed to this object. */ - PropertyConstraintBase() - : mInputsInitialized( false ) + PropertyConstraint( Dali::Constraint::Function< PropertyType >* func ) + : mInputsInitialized( false ), + mFunction( func ), + mInputs() { } /** - * Virtual destructor. + * Constructor. + * @param [in] func A constraint function. Ownership of this callback-function is passed to this object. + * @param [in] inputs Property inputs. */ - virtual ~PropertyConstraintBase() + PropertyConstraint( Dali::Constraint::Function< PropertyType >* func, + const InputContainer& inputs ) + : mInputsInitialized( false ), + mFunction( func ), + mInputs( inputs ) { } /** - * Clone a property constraint. + * Non virtual destructor. */ - virtual PropertyConstraintBase< PropertyType >* Clone() = 0; + ~PropertyConstraint() + { + delete mFunction; + } /** - * Clone a property constraint supporting component indices. + * Clone a property constraint. + * + * @return The clone of the property-constraint. + * + * @note This function will create a copy of the stored constraint function for the clone. */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() = 0; + PropertyConstraint< PropertyType >* Clone() + { + return new PropertyConstraint< PropertyType >( reinterpret_cast< ConstraintFunction* >( mFunction->Clone() ), mInputs ); + } /** * Set the input for one of the property constraint parameters. * @param [in] index The parameter index. * @param [in] input The interface for receiving a property value. */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) = 0; + void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) + { + if ( index >= mInputs.size() ) + { + mInputs.push_back( PropertyInputAccessor() ); + } + + mInputs[ index ].SetInput( input, componentIndex ); + } /** * Retrieve the input for one of the property constraint parameters. * @param [in] index The parameter index. * @return The property input, or NULL if no input exists with this index. */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const = 0; + const PropertyInputImpl* GetInput( unsigned int index ) const + { + if ( index < mInputs.size() ) + { + return mInputs[ index ].GetInput(); + } + + return NULL; + } /** * Query whether all of the inputs have been initialized. @@ -127,973 +174,44 @@ public: /** * Apply the constraint. * @param [in] bufferIndex The current update buffer index. - * @param [in] current The current property value. - * @return The constrained property value. - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) = 0; - -private: - - bool mInputsInitialized; -}; - -/** - * Connects a constraint function with a target property & zero input properties. - */ -template < typename PropertyType > -class PropertyConstraint0 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&)> ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint0( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint0() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint0< PropertyType >( mFunction ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - DALI_ASSERT_ALWAYS( false && "PropertyConstraint0 does not support (property component) inputs" ); - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( false && "PropertyConstraintBase::SetInput() needs overriding" ); // No additional inputs - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - return NULL; // No additional inputs - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - return mFunction( current ); - } - -private: - - // Undefined - PropertyConstraint0(const PropertyConstraint0&); - - // Undefined - PropertyConstraint0& operator=(const PropertyConstraint0& rhs); - -private: - - ConstraintFunction mFunction; -}; - -/** - * Connects a constraint function with a target property & 1 input property. - */ -template < typename PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint1 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&) > ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint1( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - */ - PropertyConstraint1( const ConstraintFunction& func, - const PropertyInputAccessorType& input1 ) - : mFunction( func ), - mInput1( input1 ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint1() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint1< PropertyType, PropertyInputAccessorType >( mFunction, mInput1 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint1< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( 0u == index && "Constraint only has one input property" ); - - mInput1.SetInput( input, componentIndex ); - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - - return mFunction( current, input1 ); - } - -private: - - // Undefined - PropertyConstraint1(const PropertyConstraint1&); - - // Undefined - PropertyConstraint1& operator=(const PropertyConstraint1& rhs); - -private: - - ConstraintFunction mFunction; - - PropertyInputAccessorType mInput1; -}; - -/** - * Connects a constraint function with a target property & 2 input properties. - */ -template < typename PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint2 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&) > ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint2( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - * @param [in] input2 A 2nd property input. - */ - PropertyConstraint2( const ConstraintFunction& func, - const PropertyInputAccessorType& input1, - const PropertyInputAccessorType& input2 ) - : mFunction( func ), - mInput1( input1 ), - mInput2( input2 ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint2() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint2< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint2< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() + * @param [in,out] current The current property value, will be set to the constrained value upon return. */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) + void Apply( BufferIndex bufferIndex, PropertyType& current ) { - DALI_ASSERT_ALWAYS( 2u > index && "Constraint only has 2 properties" ); + InputIndexerContainer mInputIndices; + PropertyInputContainer mIndices; + const unsigned int noOfInputs = mInputs.size(); - if ( 0u == index ) - { - mInput1.SetInput( input, componentIndex ); - } - else - { - mInput2.SetInput( input, componentIndex ); - } - } + mInputIndices.reserve( noOfInputs ); + mIndices.Reserve( noOfInputs ); - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - else if ( 1u == index ) + const InputContainerConstIter endIter = mInputs.end(); + unsigned int index = 0; + for ( InputContainerConstIter iter = mInputs.begin(); iter != endIter; ++iter, ++index ) { - return mInput2.GetInput(); + DALI_ASSERT_DEBUG( NULL != iter->GetInput() ); + mInputIndices.push_back( PropertyInputIndexer< PropertyInputAccessor >( bufferIndex, &*iter ) ); + mIndices.PushBack( &mInputIndices[ index ] ); } - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 ); - - return mFunction( current, - input1, - input2 ); + CallbackBase::Execute< PropertyType&, const PropertyInputContainer& >( *mFunction, current, mIndices ); } private: // Undefined - PropertyConstraint2(const PropertyConstraint2&); + PropertyConstraint( const PropertyConstraint& ); // Undefined - PropertyConstraint2& operator=(const PropertyConstraint2& rhs); + PropertyConstraint& operator=( const PropertyConstraint& rhs ); private: - ConstraintFunction mFunction; - - PropertyInputAccessorType mInput1; - PropertyInputAccessorType mInput2; -}; - -/** - * Connects a constraint function with a target property & 3 input properties. - */ -template < class PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint3 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&)> ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint3( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - * @param [in] input2 A 2nd property input. - * @param [in] input3 A 3rd property input. - */ - PropertyConstraint3( const ConstraintFunction& func, - const PropertyInputAccessorType& input1, - const PropertyInputAccessorType& input2, - const PropertyInputAccessorType& input3 ) - : mFunction( func ), - mInput1( input1 ), - mInput2( input2 ), - mInput3( input3 ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint3() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint3< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint3< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( 3u > index && "Constraint only has 3 properties" ); - - if ( 0u == index ) - { - mInput1.SetInput( input, componentIndex ); - } - else if ( 1u == index ) - { - mInput2.SetInput( input, componentIndex ); - } - else - { - mInput3.SetInput( input, componentIndex ); - } - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - else if ( 1u == index ) - { - return mInput2.GetInput(); - } - else if ( 2u == index ) - { - return mInput3.GetInput(); - } - - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 ); - const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 ); - - return mFunction( current, - input1, - input2, - input3 ); - } - -private: - - // Undefined - PropertyConstraint3(const PropertyConstraint3&); - - // Undefined - PropertyConstraint3& operator=(const PropertyConstraint3& rhs); - -private: - - ConstraintFunction mFunction; - - PropertyInputAccessorType mInput1; - PropertyInputAccessorType mInput2; - PropertyInputAccessorType mInput3; -}; - -/** - * Connects a constraint function with a target property & 4 input properties. - */ -template < class PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint4 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&) > ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint4( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - * @param [in] input2 A 2nd property input. - * @param [in] input3 A 3rd property input. - * @param [in] input4 A 4th property input. - */ - PropertyConstraint4( const ConstraintFunction& func, - const PropertyInputAccessorType& input1, - const PropertyInputAccessorType& input2, - const PropertyInputAccessorType& input3, - const PropertyInputAccessorType& input4 ) - : mFunction( func ), - mInput1( input1 ), - mInput2( input2 ), - mInput3( input3 ), - mInput4( input4 ) - { - } - - /** - * Create a PropertyConstraint4 instance. - * @param [in] func A constraint function. - * @return A newly heap-allocated object. - */ - static PropertyConstraintBase< PropertyType >* New( ConstraintFunction func ) - { - return new PropertyConstraint4< PropertyType, PropertyInputAccessorType >( func ); - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint4() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint4< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint4< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( 4u > index && "Constraint only has 4 properties" ); - - if ( 0u == index ) - { - mInput1.SetInput( input, componentIndex ); - } - else if ( 1u == index ) - { - mInput2.SetInput( input, componentIndex ); - } - else if ( 2u == index ) - { - mInput3.SetInput( input, componentIndex ); - } - else - { - mInput4.SetInput( input, componentIndex ); - } - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - else if ( 1u == index ) - { - return mInput2.GetInput(); - } - else if ( 2u == index ) - { - return mInput3.GetInput(); - } - else if ( 3u == index ) - { - return mInput4.GetInput(); - } - - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 ); - const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 ); - const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 ); - - return mFunction( current, - input1, - input2, - input3, - input4 ); - } - -private: - - // Undefined - PropertyConstraint4(const PropertyConstraint4&); - - // Undefined - PropertyConstraint4& operator=(const PropertyConstraint4& rhs); - -private: - - ConstraintFunction mFunction; - - PropertyInputAccessorType mInput1; - PropertyInputAccessorType mInput2; - PropertyInputAccessorType mInput3; - PropertyInputAccessorType mInput4; -}; - -/** - * Connects a constraint function with a target property & 5 input properties. - */ -template < class PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint5 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&) > ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint5( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - * @param [in] input2 A 2nd property input. - * @param [in] input3 A 3rd property input. - * @param [in] input4 A 4th property input. - * @param [in] input5 A 5th property input. - */ - PropertyConstraint5( const ConstraintFunction& func, - const PropertyInputAccessorType& input1, - const PropertyInputAccessorType& input2, - const PropertyInputAccessorType& input3, - const PropertyInputAccessorType& input4, - const PropertyInputAccessorType& input5 ) - : mFunction( func ), - mInput1( input1 ), - mInput2( input2 ), - mInput3( input3 ), - mInput4( input4 ), - mInput5( input5 ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint5() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint5< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint5< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( 5u > index && "Constraint only has 5 properties"); - - if ( 0u == index ) - { - mInput1.SetInput( input, componentIndex ); - } - else if ( 1u == index ) - { - mInput2.SetInput( input, componentIndex ); - } - else if ( 2u == index ) - { - mInput3.SetInput( input, componentIndex ); - } - else if ( 3u == index ) - { - mInput4.SetInput( input, componentIndex ); - } - else - { - mInput5.SetInput( input, componentIndex ); - } - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - else if ( 1u == index ) - { - return mInput2.GetInput(); - } - else if ( 2u == index ) - { - return mInput3.GetInput(); - } - else if ( 3u == index ) - { - return mInput4.GetInput(); - } - else if ( 4u == index ) - { - return mInput5.GetInput(); - } - - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput5.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 ); - const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 ); - const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 ); - const PropertyInputIndexer< PropertyInputAccessorType > input5( bufferIndex, &mInput5 ); - - return mFunction( current, - input1, - input2, - input3, - input4, - input5 ); - } - -private: - - // Undefined - PropertyConstraint5(const PropertyConstraint5&); - - // Undefined - PropertyConstraint5& operator=(const PropertyConstraint5& rhs); - -private: - - ConstraintFunction mFunction; - - PropertyInputAccessorType mInput1; - PropertyInputAccessorType mInput2; - PropertyInputAccessorType mInput3; - PropertyInputAccessorType mInput4; - PropertyInputAccessorType mInput5; -}; - -/** - * Connects a constraint function with a target property & 6 input properties. - */ -template < class PropertyType, typename PropertyInputAccessorType > -class PropertyConstraint6 : public PropertyConstraintBase< PropertyType > -{ -public: - - typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&)> ConstraintFunction; - - /** - * Constructor. - * @param [in] func A constraint function. - */ - PropertyConstraint6( const ConstraintFunction& func ) - : mFunction( func ) - { - } - - /** - * Constructor. - * @param [in] func A constraint function. - * @param [in] input1 A property input. - * @param [in] input2 A 2nd property input. - * @param [in] input3 A 3rd property input. - * @param [in] input4 A 4th property input. - * @param [in] input5 A 5th property input. - * @param [in] input6 A 6th property input. - */ - PropertyConstraint6( const ConstraintFunction& func, - const PropertyInputAccessorType& input1, - const PropertyInputAccessorType& input2, - const PropertyInputAccessorType& input3, - const PropertyInputAccessorType& input4, - const PropertyInputAccessorType& input5, - const PropertyInputAccessorType& input6 ) - : mFunction( func ), - mInput1( input1 ), - mInput2( input2 ), - mInput3( input3 ), - mInput4( input4 ), - mInput5( input5 ), - mInput6( input6 ) - { - } - - /** - * Virtual destructor. - */ - virtual ~PropertyConstraint6() - { - } - - /** - * @copydoc PropertyConstraintBase::Clone() - */ - virtual PropertyConstraintBase< PropertyType >* Clone() - { - return new PropertyConstraint6< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5, mInput6 ); - } - - /** - * @copydoc PropertyConstraintBase::CloneComponentFunc() - */ - virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() - { - return new PropertyConstraint6< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5, mInput6 ); - } - - /** - * @copydoc PropertyConstraintBase::SetInput() - */ - virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) - { - DALI_ASSERT_ALWAYS( 6u > index && "Constraint only has 6 properties" ); - - if ( 0u == index ) - { - mInput1.SetInput( input, componentIndex ); - } - else if ( 1u == index ) - { - mInput2.SetInput( input, componentIndex ); - } - else if ( 2u == index ) - { - mInput3.SetInput( input, componentIndex ); - } - else if ( 3u == index ) - { - mInput4.SetInput( input, componentIndex ); - } - else if ( 4u == index ) - { - mInput5.SetInput( input, componentIndex ); - } - else - { - mInput6.SetInput( input, componentIndex ); - } - } - - /** - * @copydoc PropertyConstraintBase::GetInput() - */ - virtual const PropertyInputImpl* GetInput( unsigned int index ) const - { - if ( 0u == index ) - { - return mInput1.GetInput(); - } - else if ( 1u == index ) - { - return mInput2.GetInput(); - } - else if ( 2u == index ) - { - return mInput3.GetInput(); - } - else if ( 3u == index ) - { - return mInput4.GetInput(); - } - else if ( 4u == index ) - { - return mInput5.GetInput(); - } - else if ( 5u == index ) - { - return mInput6.GetInput(); - } - - return NULL; - } - - /** - * @copydoc PropertyConstraintBase::Apply() - */ - virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) - { - DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput5.GetInput() ); - DALI_ASSERT_DEBUG( NULL != mInput6.GetInput() ); - - const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 ); - const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 ); - const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 ); - const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 ); - const PropertyInputIndexer< PropertyInputAccessorType > input5( bufferIndex, &mInput5 ); - const PropertyInputIndexer< PropertyInputAccessorType > input6( bufferIndex, &mInput6 ); - - return mFunction( current, - input1, - input2, - input3, - input4, - input5, - input6 ); - } - -private: - - // Undefined - PropertyConstraint6(const PropertyConstraint6&); - - // Undefined - PropertyConstraint6& operator=(const PropertyConstraint6& rhs); - -private: + bool mInputsInitialized; - ConstraintFunction mFunction; + ConstraintFunction* mFunction; - PropertyInputAccessorType mInput1; - PropertyInputAccessorType mInput2; - PropertyInputAccessorType mInput3; - PropertyInputAccessorType mInput4; - PropertyInputAccessorType mInput5; - PropertyInputAccessorType mInput6; + InputContainer mInputs; }; } // namespace Internal diff --git a/dali/internal/event/animation/property-input-accessor.h b/dali/internal/event/animation/property-input-accessor.h index 5caf4a8..8c37e0a 100644 --- a/dali/internal/event/animation/property-input-accessor.h +++ b/dali/internal/event/animation/property-input-accessor.h @@ -36,155 +36,15 @@ public: * Create the PropertyInputAccessor. */ PropertyInputAccessor() - : mInput( NULL ) - { - } - - /** - * Create the PropertyInputAccessor. - */ - PropertyInputAccessor( const PropertyInputImpl* input, int /*componentIndex*/ ) - : mInput( input ) - { - } - - /** - * Copy from a PropertyInputAccessor - */ - PropertyInputAccessor( const PropertyInputAccessor& accessor ) - : mInput( accessor.mInput ) - { - } - - /** - * Copy from a PropertyInputAccessor - */ - PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor) - { - mInput = accessor.mInput; - - return *this; - } - - /** - * Set the property input. - */ - void SetInput( const PropertyInputImpl& input, int componentIndex ) - { - DALI_ASSERT_DEBUG( componentIndex < 0 && "Did not expect a valid component index" ); - mInput = &input; - } - - /** - * Retrieve the property input. - */ - const PropertyInputImpl* GetInput() const - { - return mInput; - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetType() - */ - Property::Type GetType() const - { - return mInput->GetType(); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean() - */ - const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputBoolean( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat() - */ - const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputFloat( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputInteger() const - */ - const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputInteger( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2() - */ - const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputVector2( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3() - */ - const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputVector3( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4() - */ - const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputVector4( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion() - */ - const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputQuaternion( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3() - */ - const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputMatrix3( updateBufferIndex ); - } - - /** - * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix() - */ - const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const - { - return mInput->GetConstraintInputMatrix( updateBufferIndex ); - } - -public: - - const PropertyInputImpl* mInput; -}; - -class PropertyInputComponentAccessor -{ -public: - - /** - * Create the PropertyInputComponentAccessor. - */ - PropertyInputComponentAccessor() : mInput( NULL ), - mComponentIndex( 0 ) + mComponentIndex( -1 ) { } /** - * Create the PropertyInputComponentAccessor. + * Create the PropertyInputAccessor. */ - PropertyInputComponentAccessor( const PropertyInputImpl* input, int componentIndex ) + PropertyInputAccessor( const PropertyInputImpl* input, int componentIndex ) : mInput( input ), mComponentIndex( componentIndex ) { @@ -193,25 +53,16 @@ public: /** * Copy from a PropertyInputAccessor */ - PropertyInputComponentAccessor( const PropertyInputAccessor& accessor ) - : mInput( accessor.mInput ), - mComponentIndex( -1 ) - { - } - - /** - * Copy from a PropertyInputComponentAccessor - */ - PropertyInputComponentAccessor( const PropertyInputComponentAccessor& accessor ) + PropertyInputAccessor( const PropertyInputAccessor& accessor ) : mInput( accessor.mInput ), mComponentIndex( accessor.mComponentIndex ) { } /** - * Assign from a PropertyInputComponentAccessor + * Copy from a PropertyInputAccessor */ - PropertyInputComponentAccessor& operator=(const PropertyInputComponentAccessor& accessor) + PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor) { mInput = accessor.mInput; mComponentIndex = accessor.mComponentIndex; @@ -248,8 +99,6 @@ public: */ const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputBoolean( updateBufferIndex ); } @@ -302,8 +151,6 @@ public: */ const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputInteger( updateBufferIndex ); } @@ -312,8 +159,6 @@ public: */ const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputVector2( updateBufferIndex ); } @@ -322,8 +167,6 @@ public: */ const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputVector3( updateBufferIndex ); } @@ -332,8 +175,6 @@ public: */ const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputVector4( updateBufferIndex ); } @@ -342,8 +183,6 @@ public: */ const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputQuaternion( updateBufferIndex ); } @@ -352,8 +191,6 @@ public: */ const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputMatrix3( updateBufferIndex ); } @@ -362,8 +199,6 @@ public: */ const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const { - DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" ); - return mInput->GetConstraintInputMatrix( updateBufferIndex ); } diff --git a/dali/internal/event/animation/property-input-indexer.h b/dali/internal/event/animation/property-input-indexer.h index 7856acb..3d95edf 100644 --- a/dali/internal/event/animation/property-input-indexer.h +++ b/dali/internal/event/animation/property-input-indexer.h @@ -48,6 +48,33 @@ public: } /** + * Copy constructor + */ + PropertyInputIndexer( const PropertyInputIndexer& other ) + : mBufferIndex( other.mBufferIndex ), + mInput( other.mInput ) + { + } + + /** + * Assignment operator + */ + PropertyInputIndexer& operator=( const PropertyInputIndexer& other ) + { + mBufferIndex = other.mBufferIndex; + mInput = other.mInput; + + return *this; + } + + /** + * Virtual Destructor + */ + virtual ~PropertyInputIndexer() + { + } + + /** * @copydoc Dali::Internal::PropertyInput::GetType() */ virtual Property::Type GetType() const @@ -127,7 +154,7 @@ public: return mInput->GetConstraintInputQuaternion( mBufferIndex ); } -private: +public: unsigned int mBufferIndex; const AccessorType* mInput; diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index e5568c1..e63c857 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -86,17 +85,6 @@ void Object::RemoveObserver(Observer& observer) void Object::OnSceneObjectAdd() { - // Notification for this object's constraints - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentSceneObjectAdded(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter) { @@ -109,17 +97,6 @@ void Object::OnSceneObjectAdd() void Object::OnSceneObjectRemove() { - // Notification for this object's constraints - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentSceneObjectRemoved(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter ) { @@ -787,45 +764,6 @@ void Object::DisablePropertyNotifications() } } -Dali::ActiveConstraint Object::ApplyConstraint( Constraint& constraint ) -{ - return Dali::ActiveConstraint( DoApplyConstraint( constraint, Dali::Handle() ) ); -} - -Dali::ActiveConstraint Object::ApplyConstraint( Constraint& constraint, Dali::Handle weightObject ) -{ - return Dali::ActiveConstraint( DoApplyConstraint( constraint, weightObject ) ); -} - -ActiveConstraintBase* Object::DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject ) -{ - ActiveConstraintBase* activeConstraintImpl = constraint.CreateActiveConstraint(); - DALI_ASSERT_DEBUG( NULL != activeConstraintImpl ); - - Dali::ActiveConstraint activeConstraint( activeConstraintImpl ); - - if( weightObject ) - { - Object& weightObjectImpl = GetImplementation( weightObject ); - Property::Index weightIndex = weightObjectImpl.GetPropertyIndex( "weight" ); - - if( Property::INVALID_INDEX != weightIndex ) - { - activeConstraintImpl->SetCustomWeightObject( weightObjectImpl, weightIndex ); - } - } - - if( !mConstraints ) - { - mConstraints = new ActiveConstraintContainer; - } - mConstraints->push_back( activeConstraint ); - - activeConstraintImpl->FirstApply( *this, constraint.GetApplyTime() ); - - return activeConstraintImpl; -} - Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const { Property::Value value; @@ -1052,32 +990,44 @@ const TypeInfo* Object::GetTypeInfo() const return mTypeInfo; } -void Object::RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ) +void Object::ApplyConstraint( ConstraintBase& constraint ) { - // guard against constraint sending messages during core destruction - if ( Stage::IsInstalled() ) + if( !mConstraints ) { - if( isInScenegraph ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( constraint ); - baseConstraint.BeginRemove(); - } + mConstraints = new ConstraintContainer; } + mConstraints->push_back( Dali::Constraint( &constraint ) ); } -void Object::RemoveConstraint( Dali::ActiveConstraint activeConstraint ) +void Object::RemoveConstraint( ConstraintBase& constraint ) +{ + DALI_ASSERT_DEBUG( mConstraints ); + + ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) ); + if( it != mConstraints->end() ) + { + mConstraints->erase( it ); + } +} + +void Object::RemoveConstraints() { // guard against constraint sending messages during core destruction if( mConstraints && Stage::IsInstalled() ) { - bool isInSceneGraph( NULL != GetSceneObject() ); - - ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) ); - if( it != mConstraints->end() ) + // If we have nothing in the scene-graph, just clear constraint containers + const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); + if ( NULL != propertyOwner ) { - RemoveConstraint( *it, isInSceneGraph ); - mConstraints->erase( it ); + const ConstraintConstIter endIter = mConstraints->end(); + for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) + { + GetImplementation( *iter ).RemoveInternal(); + } } + + delete mConstraints; + mConstraints = NULL; } } @@ -1086,15 +1036,13 @@ void Object::RemoveConstraints( unsigned int tag ) // guard against constraint sending messages during core destruction if( mConstraints && Stage::IsInstalled() ) { - bool isInSceneGraph( NULL != GetSceneObject() ); - - ActiveConstraintIter iter( mConstraints->begin() ); + ConstraintIter iter( mConstraints->begin() ); while(iter != mConstraints->end() ) { - ActiveConstraintBase& constraint = GetImplementation( *iter ); + ConstraintBase& constraint = GetImplementation( *iter ); if( constraint.GetTag() == tag ) { - RemoveConstraint( *iter, isInSceneGraph ); + GetImplementation( *iter ).RemoveInternal(); iter = mConstraints->erase( iter ); } else @@ -1102,27 +1050,12 @@ void Object::RemoveConstraints( unsigned int tag ) ++iter; } } - } -} -void Object::RemoveConstraints() -{ - // guard against constraint sending messages during core destruction - if( mConstraints && Stage::IsInstalled() ) - { - // If we have nothing in the scene-graph, just clear constraint containers - const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); - if ( NULL != propertyOwner ) + if ( mConstraints->empty() ) { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - RemoveConstraint( *iter, true ); - } + delete mConstraints; + mConstraints = NULL; } - - delete mConstraints; - mConstraints = NULL; } } @@ -1133,18 +1066,6 @@ void Object::SetTypeInfo( const TypeInfo* typeInfo ) Object::~Object() { - // Notification for this object's constraints - // (note that the ActiveConstraint handles may outlive the Object) - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentDestroyed(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter) { diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index 3133135..be66703 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -19,13 +19,13 @@ */ // INTERNAL INCLUDES -#include #include #include #include #include #include #include +#include #include #include #include @@ -41,7 +41,7 @@ class PropertyNotification; namespace Internal { -class Constraint; +class ConstraintBase; class EventThreadServices; class Handle; class PropertyCondition; @@ -55,9 +55,9 @@ class PropertyBase; class PropertyOwner; } -typedef std::vector< Dali::ActiveConstraint > ActiveConstraintContainer; -typedef ActiveConstraintContainer::iterator ActiveConstraintIter; -typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter; +typedef std::vector< Dali::Constraint > ConstraintContainer; +typedef ConstraintContainer::iterator ConstraintIter; +typedef ConstraintContainer::const_iterator ConstraintConstIter; /** * A base class for objects which optionally provide properties. @@ -214,23 +214,16 @@ public: // Constraints /** - * Apply a constraint to a Object. + * Apply a constraint to an Object. * @param[in] constraint The constraint to apply. */ - Dali::ActiveConstraint ApplyConstraint( Constraint& constraint ); + void ApplyConstraint( ConstraintBase& constraint ); /** - * Apply a constraint to a Object. - * @param[in] constraint The constraint to apply. - * @param[in] weightObject An object with a "weight" float property. - */ - Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Handle weightObject ); - - /** - * Remove one constraint from a Object. - * @param[in] activeConstraint The active constraint to remove. + * Remove one constraint from an Object. + * @param[in] constraint The constraint to remove. */ - void RemoveConstraint( Dali::ActiveConstraint activeConstraint ); + void RemoveConstraint( ConstraintBase& constraint ); /** * Remove all constraints from a Object. @@ -456,19 +449,6 @@ private: void DisablePropertyNotifications(); /** - * Helper for ApplyConstraint overloads. - * @param[in] constraint The constraint to apply. - * @param[in] weightObject An object with a "weight" float property, or an empty handle. - * @return The new active-constraint which is owned by Object. - */ - ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject ); - - /** - * Helper to remove active constraints - */ - void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ); - - /** * Get the value of the property. * @param [in] entry An entry from the property lookup container. * @return The new value of the property. @@ -522,7 +502,7 @@ private: Dali::Vector mObservers; - ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints. + ConstraintContainer* mConstraints; ///< Container of owned -constraints. typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer; typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter; diff --git a/dali/internal/file.list b/dali/internal/file.list index 8204242..2463c68 100644 --- a/dali/internal/file.list +++ b/dali/internal/file.list @@ -25,10 +25,9 @@ internal_src_files = \ $(internal_src_dir)/event/actors/mesh-actor-impl.cpp \ $(internal_src_dir)/event/actors/camera-actor-impl.cpp \ $(internal_src_dir)/event/actors/renderable-actor-impl.cpp \ - $(internal_src_dir)/event/animation/active-constraint-base.cpp \ $(internal_src_dir)/event/animation/animation-impl.cpp \ $(internal_src_dir)/event/animation/animation-playlist.cpp \ - $(internal_src_dir)/event/animation/constraint-impl.cpp \ + $(internal_src_dir)/event/animation/constraint-base.cpp \ $(internal_src_dir)/event/animation/key-frames-impl.cpp \ $(internal_src_dir)/event/animation/path-impl.cpp \ $(internal_src_dir)/event/animation/path-constraint-impl.cpp \ @@ -155,7 +154,6 @@ internal_src_files = \ $(internal_src_dir)/render/shaders/program-controller.cpp \ $(internal_src_dir)/render/shaders/shader.cpp \ \ - $(internal_src_dir)/update/animation/interpolator-functions.cpp \ $(internal_src_dir)/update/animation/scene-graph-animation.cpp \ $(internal_src_dir)/update/animation/scene-graph-constraint-base.cpp \ $(internal_src_dir)/update/common/discard-queue.cpp \ diff --git a/dali/internal/update/animation/interpolator-functions.cpp b/dali/internal/update/animation/interpolator-functions.cpp deleted file mode 100644 index de8e8b7..0000000 --- a/dali/internal/update/animation/interpolator-functions.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include - - -namespace -{ - -bool LerpBoolean( const bool& current, const bool& target, float progress ) -{ - // Not particularly useful for boolean values - if (progress >= 1.0f) - { - return target; - } - - return current; -} - -float LerpFloat( const float& current, const float& target, float progress ) -{ - return current + ((target - current) * progress); -} - -int LerpInteger( const int& current, const int& target, float progress ) -{ - return static_cast( current + ( (target - current) * progress ) + 0.5f ); -} - -Dali::Vector2 LerpVector2( const Dali::Vector2& current, const Dali::Vector2& target, float progress ) -{ - return current + ((target - current) * progress); -} - -Dali::Vector3 LerpVector3( const Dali::Vector3& current, const Dali::Vector3& target, float progress ) -{ - return current + ((target - current) * progress); -} - -Dali::Vector4 LerpVector4( const Dali::Vector4& current, const Dali::Vector4& target, float progress ) -{ - return current + ((target - current) * progress); -} - -Dali::Quaternion SlerpQuaternion( const Dali::Quaternion& current, const Dali::Quaternion& target, float progress ) -{ - return Dali::Quaternion::Slerp(current, target, progress); -} - -Dali::Matrix LerpMatrix( const Dali::Matrix& current, const Dali::Matrix& target, float progress ) -{ - if (progress > 0.5f) - { - return target; - } - - return current; -} - -Dali::Matrix3 LerpMatrix3( const Dali::Matrix3& current, const Dali::Matrix3& target, float progress ) -{ - if (progress > 0.5f) - { - return target; - } - - return current; -} - -} // unnamed namespace - -namespace Dali -{ - -namespace Internal -{ - -namespace SceneGraph -{ - -CallbackBase* GetDefaultInterpolator( Property::Type type ) -{ - CallbackBase* function = NULL; - - switch ( type ) - { - case Property::BOOLEAN: - { - function = MakeCallback( LerpBoolean ); - break; - } - - case Property::FLOAT: - { - function = MakeCallback( LerpFloat ); - break; - } - - case Property::INTEGER: - { - function = MakeCallback( LerpInteger ); - break; - } - - case Property::VECTOR2: - { - function = MakeCallback( LerpVector2 ); - break; - } - - case Property::VECTOR3: - { - function = MakeCallback( LerpVector3 ); - break; - } - - case Property::VECTOR4: - { - function = MakeCallback( LerpVector4 ); - break; - } - - case Property::ROTATION: - { - function = MakeCallback( SlerpQuaternion ); - break; - } - - case Property::MATRIX3: - { - function = MakeCallback( LerpMatrix3 ); - break; - } - - case Property::MATRIX: - { - function = MakeCallback( LerpMatrix ); - break; - } - - default: - break; - } - - return function; -} - -} // namespace SceneGraph - -} // namespace Internal - -} // namespace Dali diff --git a/dali/internal/update/animation/interpolator-functions.h b/dali/internal/update/animation/interpolator-functions.h deleted file mode 100644 index ba664cb..0000000 --- a/dali/internal/update/animation/interpolator-functions.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __DALI_INTERPOLATOR_FUNCTIONS_H__ -#define __DALI_INTERPOLATOR_FUNCTIONS_H__ - -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -namespace SceneGraph -{ - -/** - * @brief Retrieve an interpolator function for a property. - * - * @param[in] type The property type for which to get an interpolator - * @return The interpolator function. - * - * @note This returns dynamically allocated memory. The caller is responsible for deleting it. - */ -CallbackBase* GetDefaultInterpolator( Property::Type type ); - -} // namespace Internal - -} //namespace SceneGraph - -} // namespace Dali - -#endif // __DALI_INTERPOLATOR_FUNCTIONS_H__ diff --git a/dali/internal/update/animation/scene-graph-constraint-base.cpp b/dali/internal/update/animation/scene-graph-constraint-base.cpp index 017942b..85bf625 100644 --- a/dali/internal/update/animation/scene-graph-constraint-base.cpp +++ b/dali/internal/update/animation/scene-graph-constraint-base.cpp @@ -18,9 +18,6 @@ // CLASS HEADER #include -// INTERNAL INCLUDES -#include - namespace Dali { @@ -36,8 +33,7 @@ namespace SceneGraph #endif ConstraintBase::ConstraintBase( PropertyOwnerContainer& ownerSet ) -: mWeight( Dali::ActiveConstraint::DEFAULT_WEIGHT ), - mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ), +: mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ), mFirstApply( true ), mDisconnected( true ), mObservedOwners( ownerSet ) @@ -62,7 +58,6 @@ ConstraintBase::~ConstraintBase() void ConstraintBase::ResetDefaultProperties( BufferIndex updateBufferIndex ) { - // Not used, since the weight property is reset by PropertyOwner DALI_ASSERT_DEBUG( false ); } diff --git a/dali/internal/update/animation/scene-graph-constraint-base.h b/dali/internal/update/animation/scene-graph-constraint-base.h index 67db5f3..1df4546 100644 --- a/dali/internal/update/animation/scene-graph-constraint-base.h +++ b/dali/internal/update/animation/scene-graph-constraint-base.h @@ -92,36 +92,6 @@ public: } /** - * Bake the weight property. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] weight The new weight. - */ - void BakeWeight( BufferIndex updateBufferIndex, float weight ) - { - mWeight.Bake( updateBufferIndex, weight ); - } - - /** - * Set the initial weight. - * @pre The constraint has not been connected to the scene-graph. - * @param[in] weight The new weight. - */ - void SetInitialWeight( float weight ) - { - mWeight.SetInitial( weight ); - } - - /** - * Retrieve the weight property. - * @param[in] bufferIndex The buffer index to read from. - * @return The current weight. - */ - float GetWeight( BufferIndex bufferIndex ) const - { - return mWeight[ bufferIndex ]; - } - - /** * Constrain the associated scene object. * @param[in] updateBufferIndex The current update buffer index. */ @@ -227,10 +197,6 @@ private: */ virtual void OnDisconnect() = 0; -public: - - AnimatableProperty mWeight; ///< The constraint is "fully-applied" when weight = 1 - protected: RemoveAction mRemoveAction; @@ -250,17 +216,6 @@ private: // Messages for ConstraintBase -inline void BakeWeightMessage( EventThreadServices& eventThreadServices, const ConstraintBase& constraint, float weight ) -{ - typedef MessageDoubleBuffered1< ConstraintBase, float > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &constraint, &ConstraintBase::BakeWeight, weight ); -} - inline void SetRemoveActionMessage( EventThreadServices& eventThreadServices, const ConstraintBase& constraint, Dali::Constraint::RemoveAction removeAction ) { typedef MessageValue1< ConstraintBase, Dali::Constraint::RemoveAction > LocalType; diff --git a/dali/internal/update/animation/scene-graph-constraint.h b/dali/internal/update/animation/scene-graph-constraint.h index d8fa34b..14b83b8 100644 --- a/dali/internal/update/animation/scene-graph-constraint.h +++ b/dali/internal/update/animation/scene-graph-constraint.h @@ -18,18 +18,13 @@ * */ -// EXTERNAL INCLUDES -#include - // INTERNAL INCLUDES -#include #include #include #include #include #include #include -#include #include #include @@ -52,28 +47,24 @@ class Constraint : public ConstraintBase public: typedef typename PropertyConstraintPtr< PropertyType >::Type ConstraintFunctionPtr; - typedef boost::function< PropertyType (const PropertyType&, const PropertyType&, float progress) > InterpolatorFunc; /** * Create a new scene-graph constraint. * @param[in] targetProperty The target property. * @param[in] ownerSet A set of property owners; func is connected to the properties provided by these objects. * @param[in] func The function to calculate the final constrained value. - * @param[in] customWeight A custom weight property, or NULL if the constraint is using its own. * @return A smart-pointer to a newly allocated constraint. */ static ConstraintBase* New( const PropertyBase& targetProperty, PropertyOwnerContainer& ownerContainer, - ConstraintFunctionPtr func, - const AnimatableProperty* customWeight ) + ConstraintFunctionPtr func ) { // Scene-graph thread can edit these objects PropertyBase& property = const_cast< PropertyBase& >( targetProperty ); return new Constraint< PropertyType, PropertyAccessorType >( property, ownerContainer, - func, - customWeight ); + func ); } /** @@ -81,7 +72,6 @@ public: */ virtual ~Constraint() { - delete mInterpolator; } /** @@ -97,8 +87,7 @@ public: } if ( ! mTargetProperty.IsClean() || - mFunc->InputsChanged() || - ! mWeightInput->IsClean() ) + mFunc->InputsChanged() ) { return true; } @@ -117,33 +106,20 @@ public: return; // Early-out when property owners have been disconnected } - bool firstApply( mFirstApply ); - if ( mFunc->InputsInitialized() && ApplyNeeded() ) { - const PropertyType& current = mTargetProperty.Get( updateBufferIndex ); + PropertyType current = mTargetProperty.Get( updateBufferIndex ); + mFunc->Apply( updateBufferIndex, current ); - // FINAL_WEIGHT means the constraint is fully-applied, unless weight is still being animated - if ( ( ! firstApply && ! mWeightInput->IsClean() ) || // We should not rely on the flag state of weight-input on first apply - ! Equals( Dali::ActiveConstraint::FINAL_WEIGHT, (*mWeightInput)[updateBufferIndex] ) ) + // Optionally bake the final value + if ( Dali::Constraint::Bake == mRemoveAction ) { - // Constraint is not fully-applied; interpolation between start & final values - mTargetProperty.Set( - updateBufferIndex, - CallbackBase::ExecuteReturn< PropertyType, const PropertyType&, const PropertyType&, float >( *mInterpolator, current, mFunc->Apply( updateBufferIndex, current ), (*mWeightInput)[updateBufferIndex] )); + mTargetProperty.Bake( updateBufferIndex, current ); } else { - // Constraint is fully-applied; optionally bake the final value - if ( Dali::Constraint::Bake == mRemoveAction ) - { - mTargetProperty.Bake( updateBufferIndex, mFunc->Apply( updateBufferIndex, current ) ); - } - else - { - mTargetProperty.Set( updateBufferIndex, mFunc->Apply( updateBufferIndex, current ) ); - } + mTargetProperty.Set( updateBufferIndex, current ); } INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED); @@ -161,13 +137,10 @@ private: */ Constraint( PropertyBase& targetProperty, PropertyOwnerContainer& ownerContainer, - ConstraintFunctionPtr func, - const AnimatableProperty* customWeight ) + ConstraintFunctionPtr func ) : ConstraintBase( ownerContainer ), mTargetProperty( &targetProperty ), - mFunc( func ), - mInterpolator( GetDefaultInterpolator( PropertyTypes::Get< PropertyType >() ) ), - mWeightInput( customWeight ? customWeight : &mWeight) + mFunc( func ) { } @@ -192,10 +165,6 @@ protected: PropertyAccessorType mTargetProperty; ///< Raw-pointer to the target property. Not owned. ConstraintFunctionPtr mFunc; - - CallbackBase* mInterpolator; - - const AnimatableProperty* mWeightInput; }; } // namespace SceneGraph diff --git a/dali/internal/update/common/property-owner.cpp b/dali/internal/update/common/property-owner.cpp index e6cfa77..e231f0a 100644 --- a/dali/internal/update/common/property-owner.cpp +++ b/dali/internal/update/common/property-owner.cpp @@ -126,13 +126,6 @@ void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex ) (*iter)->ResetToBaseValue( updateBufferIndex ); } - // Reset constraint weights - const ConstraintIter constraintEndIter = mConstraints.End(); - for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter ) - { - (*iter)->mWeight.ResetToBaseValue( updateBufferIndex ); - } - // Notification for derived classes, to reset default properties ResetDefaultProperties( updateBufferIndex ); } @@ -151,7 +144,6 @@ void PropertyOwner::ApplyConstraint( ConstraintBase* constraint ) void PropertyOwner::RemoveConstraint( ConstraintBase* constraint ) { - // Reset constraint weights const ConstraintIter constraintEndIter = mConstraints.End(); for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter ) { diff --git a/dali/internal/update/common/scene-graph-property-notification.cpp b/dali/internal/update/common/scene-graph-property-notification.cpp index ed33b3c..012b537 100644 --- a/dali/internal/update/common/scene-graph-property-notification.cpp +++ b/dali/internal/update/common/scene-graph-property-notification.cpp @@ -134,8 +134,8 @@ bool PropertyNotification::Check( BufferIndex bufferIndex ) if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex ) { // Evaluate Condition - const PropertyInputComponentAccessor component( mProperty, mComponentIndex ); - const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component ); + const PropertyInputAccessor component( mProperty, mComponentIndex ); + const PropertyInputIndexer< PropertyInputAccessor > input( bufferIndex, &component ); currentValid = mConditionFunction(input, mArguments); } else diff --git a/dali/internal/update/manager/update-algorithms.cpp b/dali/internal/update/manager/update-algorithms.cpp index 7d35f54..7c33f04 100644 --- a/dali/internal/update/manager/update-algorithms.cpp +++ b/dali/internal/update/manager/update-algorithms.cpp @@ -59,10 +59,8 @@ Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UP * @param updateBufferIndex buffer index to use * @return The number of constraints that are still being applied */ -unsigned int ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex ) +void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex ) { - unsigned int activeCount = 0; - ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints(); const ConstraintIter endIter = constraints.End(); @@ -70,15 +68,7 @@ unsigned int ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex u { ConstraintBase& constraint = **iter; constraint.Apply( updateBufferIndex ); - - if( constraint.mWeight[updateBufferIndex] < 1.0f ) - { - // this constraint is still being applied - ++activeCount; - } } - - return activeCount; } /** @@ -87,9 +77,9 @@ unsigned int ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex u * @param updateBufferIndex buffer index to use * @return number of active constraints */ -unsigned int ConstrainNodes( Node& node, BufferIndex updateBufferIndex ) +void ConstrainNodes( Node& node, BufferIndex updateBufferIndex ) { - unsigned int activeCount = ConstrainPropertyOwner( node, updateBufferIndex ); + ConstrainPropertyOwner( node, updateBufferIndex ); /** * Constrain the children next @@ -99,9 +89,8 @@ unsigned int ConstrainNodes( Node& node, BufferIndex updateBufferIndex ) for ( NodeIter iter = children.Begin(); iter != endIter; ++iter ) { Node& child = **iter; - activeCount += ConstrainNodes( child, updateBufferIndex ); + ConstrainNodes( child, updateBufferIndex ); } - return activeCount; } /****************************************************************************** diff --git a/dali/internal/update/manager/update-algorithms.h b/dali/internal/update/manager/update-algorithms.h index 239d415..118b264 100644 --- a/dali/internal/update/manager/update-algorithms.h +++ b/dali/internal/update/manager/update-algorithms.h @@ -41,17 +41,15 @@ class RenderQueue; * Recursively apply the constraints on the nodes. * @param[in] node to constraint. * @param[in] updateBufferIndex The current update buffer index. - * @return number of active constraints. - */ -unsigned int ConstrainNodes( Node& node, BufferIndex updateBufferIndex ); + */ +void ConstrainNodes( Node& node, BufferIndex updateBufferIndex ); /** * Constrain the local properties of the PropertyOwner. * @param[in] propertyOwner The PropertyOwner to constrain * @param[in] updateBufferIndex The current update buffer index. - * @return The number of active constraints. */ -unsigned int ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex ); +void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex ); /** * Update a tree of nodes, and attached objects. diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index 5c94fe5..d3a6872 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -179,7 +179,6 @@ struct UpdateManager::Impl dynamicsChanged( false ), keepRenderingSeconds( 0.0f ), animationFinishedDuringUpdate( false ), - activeConstraints( 0 ), nodeDirtyFlags( TransformFlag ), // set to TransformFlag to ensure full update the first time through Update() previousUpdateScene( false ), frameCounter( 0 ), @@ -278,7 +277,6 @@ struct UpdateManager::Impl float keepRenderingSeconds; ///< Set via Dali::Stage::KeepRendering bool animationFinishedDuringUpdate; ///< Flag whether any animations finished during the Update() - unsigned int activeConstraints; ///< number of active constraints from previous frame int nodeDirtyFlags; ///< cumulative node dirty flags from previous frame bool previousUpdateScene; ///< True if the scene was updated in the previous frame (otherwise it was optimized out) @@ -847,8 +845,6 @@ void UpdateManager::ApplyConstraints() { PERF_MONITOR_START(PerformanceMonitor::APPLY_CONSTRAINTS); - mImpl->activeConstraints = 0; - // constrain custom objects... (in construction order) OwnerContainer< PropertyOwner* >& customObjects = mImpl->customObjects; @@ -856,18 +852,18 @@ void UpdateManager::ApplyConstraints() for ( OwnerContainer< PropertyOwner* >::Iterator iter = customObjects.Begin(); endIter != iter; ++iter ) { PropertyOwner& object = **iter; - mImpl->activeConstraints += ConstrainPropertyOwner( object, mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainPropertyOwner( object, mSceneGraphBuffers.GetUpdateBufferIndex() ); } // constrain nodes... (in Depth First traversal order) if ( mImpl->root ) { - mImpl->activeConstraints += ConstrainNodes( *(mImpl->root), mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainNodes( *(mImpl->root), mSceneGraphBuffers.GetUpdateBufferIndex() ); } if ( mImpl->systemLevelRoot ) { - mImpl->activeConstraints += ConstrainNodes( *(mImpl->systemLevelRoot), mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainNodes( *(mImpl->systemLevelRoot), mSceneGraphBuffers.GetUpdateBufferIndex() ); } // constrain other property-owners after nodes as they are more likely to depend on a node's @@ -885,7 +881,7 @@ void UpdateManager::ApplyConstraints() for ( RenderTaskList::RenderTaskContainer::ConstIterator iter = systemLevelTasks.Begin(); iter != systemLevelTasks.End(); ++iter ) { RenderTask& task = **iter; - mImpl->activeConstraints += ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() ); } // Constrain render-tasks @@ -894,7 +890,7 @@ void UpdateManager::ApplyConstraints() for ( RenderTaskList::RenderTaskContainer::ConstIterator iter = tasks.Begin(); iter != tasks.End(); ++iter ) { RenderTask& task = **iter; - mImpl->activeConstraints += ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() ); } // constrain meshes (in construction order) @@ -902,7 +898,7 @@ void UpdateManager::ApplyConstraints() for ( AnimatableMeshIter iter = meshes.Begin(); iter != meshes.End(); ++iter ) { AnimatableMesh& mesh = **iter; - mImpl->activeConstraints += ConstrainPropertyOwner( mesh, mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainPropertyOwner( mesh, mSceneGraphBuffers.GetUpdateBufferIndex() ); } // constrain shaders... (in construction order) @@ -911,7 +907,7 @@ void UpdateManager::ApplyConstraints() for ( ShaderIter iter = shaders.Begin(); iter != shaders.End(); ++iter ) { Shader& shader = **iter; - mImpl->activeConstraints += ConstrainPropertyOwner( shader, mSceneGraphBuffers.GetUpdateBufferIndex() ); + ConstrainPropertyOwner( shader, mSceneGraphBuffers.GetUpdateBufferIndex() ); } PERF_MONITOR_END(PerformanceMonitor::APPLY_CONSTRAINTS); @@ -1017,7 +1013,6 @@ unsigned int UpdateManager::Update( float elapsedSeconds, const bool gestureUpdated = ProcessGestures( lastVSyncTimeMilliseconds, nextVSyncTimeMilliseconds ); const bool updateScene = // The scene-graph requires an update if.. - mImpl->activeConstraints != 0 || // ..constraints were active in previous frame OR (mImpl->nodeDirtyFlags & RenderableUpdateFlags) || // ..nodes were dirty in previous frame OR IsAnimationRunning() || // ..at least one animation is running OR mImpl->dynamicsChanged || // ..there was a change in the dynamics simulation OR diff --git a/dali/public-api/actors/actor.h b/dali/public-api/actors/actor.h index 019014e..2045436 100644 --- a/dali/public-api/actors/actor.h +++ b/dali/public-api/actors/actor.h @@ -23,7 +23,6 @@ // INTERNAL INCLUDES #include -#include #include #include #include diff --git a/dali/public-api/animation/active-constraint-declarations.h b/dali/public-api/animation/active-constraint-declarations.h deleted file mode 100644 index 3e22804..0000000 --- a/dali/public-api/animation/active-constraint-declarations.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __DALI_ACTIVE_CONSTRAINT_DECLARATIONS_H__ -#define __DALI_ACTIVE_CONSTRAINT_DECLARATIONS_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include - -// INTERNAL INCLUDES -#include -#include - -namespace Dali -{ - -class ActiveConstraint; - -typedef Signal< void (ActiveConstraint& constraint) > ActiveConstraintSignalType; - -typedef boost::function ActiveConstraintCallbackType; - -} // namespace Dali - -#endif // __DALI_ACTIVE_CONSTRAINT_DECLARATIONS_H__ diff --git a/dali/public-api/animation/active-constraint.cpp b/dali/public-api/animation/active-constraint.cpp deleted file mode 100644 index 5ee5f48..0000000 --- a/dali/public-api/animation/active-constraint.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include - -namespace Dali -{ - -const float ActiveConstraint::FINAL_WEIGHT = 1.0f; -const float ActiveConstraint::DEFAULT_WEIGHT = 1.0f; - -ActiveConstraint::ActiveConstraint() -{ -} - -ActiveConstraint::ActiveConstraint( Internal::ActiveConstraintBase* constraint ) -: Handle( constraint ) -{ -} - -ActiveConstraint::~ActiveConstraint() -{ -} - -ActiveConstraint::ActiveConstraint(const ActiveConstraint& handle) -: Handle( handle ) -{ -} - -ActiveConstraint& ActiveConstraint::operator=(const ActiveConstraint& rhs) -{ - BaseHandle::operator=(rhs); - return *this; -} - -Handle ActiveConstraint::GetTargetObject() -{ - return GetImplementation(*this).GetTargetObject(); -} - -Property::Index ActiveConstraint::GetTargetProperty() -{ - return GetImplementation(*this).GetTargetProperty(); -} - -void ActiveConstraint::SetWeight( float weight ) -{ - GetImplementation(*this).SetWeight( weight ); -} - -float ActiveConstraint::GetCurrentWeight() const -{ - return GetImplementation(*this).GetCurrentWeight(); -} - -ActiveConstraintSignalType& ActiveConstraint::AppliedSignal() -{ - return GetImplementation(*this).AppliedSignal(); -} - -} // namespace Dali diff --git a/dali/public-api/animation/active-constraint.h b/dali/public-api/animation/active-constraint.h deleted file mode 100644 index e930f2e..0000000 --- a/dali/public-api/animation/active-constraint.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef __DALI_ACTIVE_CONSTRAINT_H__ -#define __DALI_ACTIVE_CONSTRAINT_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal DALI_INTERNAL -{ -class ActiveConstraintBase; -} - -/** - * @brief A constraint which is being applied to an object. - * - * Signals - * | %Signal Name | Method | - * |--------------|-----------------------| - * | applied | @ref AppliedSignal() | - */ -class DALI_IMPORT_API ActiveConstraint : public Handle -{ -public: - - /** - * @brief An enumeration of properties belonging to the ActiveConstraint class. - */ - struct Property - { - enum - { - WEIGHT = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "weight", type float - }; - }; - - static const float FINAL_WEIGHT; ///< 1.0f means the constraint is fully-applied, unless weight is still being animated - static const float DEFAULT_WEIGHT; ///< 1.0f - - /** - * @brief Create an uninitialized Constraint; this can be initialized with Constraint::New(). - * - * Calling member functions with an uninitialized Dali::Object is not allowed. - */ - ActiveConstraint(); - - /** - * @brief Dali::ActiveConstraint is intended as a base class - * - * This is non-virtual since derived Handle types must not contain data or virtual methods. - */ - ~ActiveConstraint(); - - /** - * @brief This copy constructor is required for (smart) pointer semantics. - * - * @param [in] handle A reference to the copied handle - */ - ActiveConstraint(const ActiveConstraint& handle); - - /** - * @brief This assignment operator is required for (smart) pointer semantics. - * - * @param [in] rhs A reference to the copied handle - * @return A reference to this - */ - ActiveConstraint& operator=(const ActiveConstraint& rhs); - - /** - * @brief Retrieve the object which this constraint is targeting. - * - * @return The target object. - */ - Handle GetTargetObject(); - - /** - * @brief Retrieve the property which this constraint is targeting. - * - * @return The target property. - */ - Dali::Property::Index GetTargetProperty(); - - /** - * @brief Set the weight of the constraint; this is a value clamped between 0. - * 0f and 1.0f. - * The default is 1.0f. - * 0.0f means the constraint has no effect, and 1.0f means the constraint is fully-applied. - * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentWeight(). - * @param [in] weight The weight. - */ - void SetWeight( float weight ); - - /** - * @brief Retrieve the current weight of the constraint. - * - * @return The current weight. - */ - float GetCurrentWeight() const; - - /** - * @brief This signal is emitted after the apply-time of the constraint has expired. - * - * @note A non-zero apply-time must have been set using Constraint::SetApplyTime(). - * @return A signal object to Connect() with. - */ - ActiveConstraintSignalType& AppliedSignal(); - -public: // Not intended for use by Application developers - - /** - * @brief This constructor is used by Dali New() methods. - * - * @param [in] constraint A pointer to a newly allocated Dali resource - */ - explicit DALI_INTERNAL ActiveConstraint( Internal::ActiveConstraintBase* constraint ); -}; - -} // namespace Dali - -#endif // __DALI_ACTIVE_CONSTRAINT_H__ diff --git a/dali/public-api/animation/constraint-functions.h b/dali/public-api/animation/constraint-functions.h deleted file mode 100644 index 1abc9d3..0000000 --- a/dali/public-api/animation/constraint-functions.h +++ /dev/null @@ -1,194 +0,0 @@ -#ifndef __DALI_CONSTRAINT_FUNCTIONS_H__ -#define __DALI_CONSTRAINT_FUNCTIONS_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include - -namespace Dali -{ - -struct Vector3; -struct Vector4; -class Quaternion; - -/** - * @brief Constraints can be used to adjust an Actor property, after animations have been applied. - * - * A local-constraint function is based on local properties of the Actor. - */ -namespace LocalConstraint -{ - -/** - * @brief A function which constrains a Vector3 property, based on the local properties of an Actor. - * - * @param[in] size The actor's current size. - * @param[in] position The actor's current position. - * @param[in] orientation The actor's current orientation. - * @param[in] scale The actor's current scale. - * @param[in] color The actor's current color. - * @return The constrained property value. - */ -typedef boost::function Vector3Function; - -/** - * @brief A function which constrains a Vector4 property, based on the local properties of an Actor. - * - * @param[in] size The actor's current size. - * @param[in] position The actor's current position. - * @param[in] orientation The actor's current orientation. - * @param[in] scale The actor's current scale. - * @param[in] color The actor's current color. - * @return The constrained property value. - */ -typedef boost::function Vector4Function; - -/** - * @brief A function which constrains a Quaternion property, based on the local properties of an Actor. - * - * @param[in] size The actor's current size. - * @param[in] position The actor's current position. - * @param[in] orientation The actor's current orientation. - * @param[in] scale The actor's current scale. - * @param[in] color The actor's current color. - * @return The constrained property value. - */ -typedef boost::function QuaternionFunction; - -/** - * @brief A function which constrains a boolean property, based on the local properties of an Actor. - * - * @param[in] size The actor's current size. - * @param[in] position The actor's current position. - * @param[in] orientation The actor's current orientation. - * @param[in] scale The actor's current scale. - * @param[in] color The actor's current color. - * @return The constrained property value. - */ -typedef boost::function BoolFunction; - -} // LocalConstraint - -/** - * @brief A parent-constraint function is based on properties related to the Actor's parent. - */ -namespace ParentConstraint -{ - -/** - * @brief A function which constrains a Vector3 property, based on properties related to the Actor's parent. - * - * @param[in] current The current value of the property to be constrained. - * @param[in] parentOrigin The actor's current parent-origin. - * @param[in] anchorPoint The actor's current anchor-point. - * @param[in] parentSize The parent's current size. - * @param[in] parentPosition The parent's current position. - * @param[in] parentOrientation The parent's current orientation. - * @param[in] parentScale The parent's current scale. - * @return The constrained property value. - */ -typedef boost::function Vector3Function; - -/** - * @brief A function which constrains a Vector4 property, based on properties related to the Actor's parent. - * - * @param[in] current The current value of the property to be constrained. - * @param[in] parentOrigin The actor's current parent-origin. - * @param[in] anchorPoint The actor's current anchor-point. - * @param[in] parentSize The parent's current size. - * @param[in] parentPosition The parent's current position. - * @param[in] parentOrientation The parent's current orientation. - * @param[in] parentScale The parent's current scale. - * @return The constrained property value. - */ -typedef boost::function Vector4Function; - -/** - * @brief A function which constrains a Quaternion property, based on properties related to the Actor's parent. - * - * @param[in] parentOrigin The actor's current parent-origin. - * @param[in] anchorPoint The actor's current anchor-point. - * @param[in] parentSize The parent's current size. - * @param[in] parentPosition The parent's current position. - * @param[in] parentOrientation The parent's current orientation. - * @param[in] parentScale The parent's current scale. - * @return The constrained property value. - */ -typedef boost::function QuaternionFunction; - -/** - * @brief A function which constrains a boolean property, based on properties related to the Actor's parent. - * - * @param[in] progress A progress value in the range 0->1, where 1 means that the constraint is fully applied. - * @param[in] parentOrigin The actor's current parent-origin. - * @param[in] anchorPoint The actor's current anchor-point. - * @param[in] parentSize The parent's current size. - * @param[in] parentPosition The parent's current position. - * @param[in] parentOrientation The parent's current orientation. - * @param[in] parentScale The parent's current scale. - * @return The constrained property value. - */ -typedef boost::function BoolFunction; - -} // ParentConstraint - -} // namespace Dali - -#endif // __DALI_CONSTRAINT_FUNCTIONS_H__ diff --git a/dali/public-api/animation/constraint.cpp b/dali/public-api/animation/constraint.cpp index 2174d6f..9d80836 100644 --- a/dali/public-api/animation/constraint.cpp +++ b/dali/public-api/animation/constraint.cpp @@ -19,58 +19,79 @@ #include // INTERNAL INCLUDES -#include #include #include +#include +#include namespace Dali { -const AlphaFunction Constraint::DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Linear; +namespace // unnamed namespace +{ + +template < class P > +Internal::PropertyConstraint< P >* CreatePropertyConstraint( CallbackBase* func ) +{ + return new Internal::PropertyConstraint< P >( reinterpret_cast< Dali::Constraint::Function< P >* >( func ) ); +} + +} // unnamed namespace + const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::Bake; Constraint::Constraint() { } -Constraint::Constraint(Internal::Constraint* constraint) -: BaseHandle(constraint) +Constraint Constraint::Clone( Handle object ) { + return Constraint( GetImplementation( *this ).Clone( GetImplementation( object ) ) ); } Constraint::~Constraint() { } -Constraint::Constraint(const Constraint& handle) -: BaseHandle(handle) +Constraint::Constraint( const Constraint& constraint ) +: BaseHandle( constraint ) { } -Constraint& Constraint::operator=(const Constraint& rhs) +Constraint& Constraint::operator=( const Constraint& rhs ) { - BaseHandle::operator=(rhs); + BaseHandle::operator=( rhs ); return *this; } -void Constraint::SetApplyTime( TimePeriod timePeriod ) +Constraint Constraint::DownCast( BaseHandle baseHandle ) +{ + return Constraint( dynamic_cast< Dali::Internal::ConstraintBase* >( baseHandle.GetObjectPtr() ) ); +} + +void Constraint::AddSource( ConstraintSource source ) +{ + GetImplementation( *this ).AddSource( Internal::Source( source ) ); +} + +void Constraint::Apply() { - GetImplementation(*this).SetApplyTime( timePeriod ); + GetImplementation( *this ).Apply(); } -TimePeriod Constraint::GetApplyTime() const +void Constraint::Remove() { - return GetImplementation(*this).GetApplyTime(); + GetImplementation( *this ).Remove(); } -void Constraint::SetAlphaFunction( AlphaFunction func ) +Handle Constraint::GetTargetObject() { - GetImplementation(*this).SetAlphaFunction( func ); + return GetImplementation(*this).GetTargetObject(); } -AlphaFunction Constraint::GetAlphaFunction() +Property::Index Constraint::GetTargetProperty() { - return GetImplementation(*this).GetAlphaFunction(); + return GetImplementation(*this).GetTargetProperty(); } void Constraint::SetRemoveAction(Constraint::RemoveAction action) @@ -93,139 +114,126 @@ unsigned int Constraint::GetTag() const return GetImplementation(*this).GetTag(); } - - - - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - AnyFunction func ) -{ - Internal::SourceContainer sources; // empty - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - AnyFunction func ) +Constraint::Constraint( Internal::ConstraintBase* constraint ) +: BaseHandle( constraint ) { - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - AnyFunction func ) -{ - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - sources.push_back( Internal::Source( source2 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - AnyFunction func ) -{ - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - sources.push_back( Internal::Source( source2 ) ); - sources.push_back( Internal::Source( source3 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); } -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - AnyFunction func ) -{ - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - sources.push_back( Internal::Source( source2 ) ); - sources.push_back( Internal::Source( source3 ) ); - sources.push_back( Internal::Source( source4 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - AnyFunction func ) -{ - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - sources.push_back( Internal::Source( source2 ) ); - sources.push_back( Internal::Source( source3 ) ); - sources.push_back( Internal::Source( source4 ) ); - sources.push_back( Internal::Source( source5 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - ConstraintSource source6, - AnyFunction func ) +Constraint Constraint::New( Handle handle, Property::Index targetIndex, Property::Type targetType, CallbackBase* function ) { + Constraint constraint; Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - sources.push_back( Internal::Source( source2 ) ); - sources.push_back( Internal::Source( source3 ) ); - sources.push_back( Internal::Source( source4 ) ); - sources.push_back( Internal::Source( source5 ) ); - sources.push_back( Internal::Source( source6 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func ) ); -} - -Constraint Constraint::DownCast( BaseHandle handle ) -{ - return Constraint( dynamic_cast(handle.GetObjectPtr()) ); + Internal::Object& object = GetImplementation( handle ); + + switch ( targetType ) + { + case Property::BOOLEAN: + { + Internal::PropertyConstraintPtr< bool >::Type funcPtr( CreatePropertyConstraint< bool >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< bool >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::FLOAT: + { + Internal::PropertyConstraintPtr< float >::Type funcPtr( CreatePropertyConstraint< float >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< float >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::INTEGER: + { + Internal::PropertyConstraintPtr< int >::Type funcPtr( CreatePropertyConstraint< int >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< int >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::VECTOR2: + { + Internal::PropertyConstraintPtr< Vector2 >::Type funcPtr( CreatePropertyConstraint< Vector2 >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Vector2 >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::VECTOR3: + { + Internal::PropertyConstraintPtr< Vector3 >::Type funcPtr( CreatePropertyConstraint< Vector3 >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Vector3 >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::VECTOR4: + { + Internal::PropertyConstraintPtr< Vector4 >::Type funcPtr( CreatePropertyConstraint< Vector4 >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Vector4 >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::ROTATION: + { + Internal::PropertyConstraintPtr< Quaternion >::Type funcPtr( CreatePropertyConstraint< Quaternion >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Quaternion >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::MATRIX: + { + Internal::PropertyConstraintPtr< Matrix >::Type funcPtr( CreatePropertyConstraint< Matrix >( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Matrix >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + case Property::MATRIX3: + { + Internal::PropertyConstraintPtr::Type funcPtr( CreatePropertyConstraint( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Matrix3 >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + default: + { + DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here + break; + } + } + + return constraint; } } // namespace Dali diff --git a/dali/public-api/animation/constraint.h b/dali/public-api/animation/constraint.h index e849cd8..1ff3b4f 100644 --- a/dali/public-api/animation/constraint.h +++ b/dali/public-api/animation/constraint.h @@ -18,45 +18,249 @@ * */ -// EXTERNAL INCLUDES -#include - // INTERNAL INCLUDES -#include #include -#include -#include +#include +#include #include #include +#include namespace Dali { -struct TimePeriod; + +class Handle; namespace Internal DALI_INTERNAL { -class Constraint; +class ConstraintBase; } +typedef Vector< PropertyInput* > PropertyInputContainer; + /** * @brief An abstract base class for Constraints. - * This can be used to constrain a property of an actor, after animations have been applied. + * + * This can be used to constrain a property of an object, after animations have been applied. * Constraints are applied in the following order: * - Constraints are applied to on-stage actors in a depth-first traversal. - * - For each actor, the constraints are applied in the same order as the calls to Actor::ApplyConstraint(). + * - For each actor, the constraints are applied in the same order as the calls to Apply(). * - Constraints are not applied to off-stage actors. + * + * Create a constraint using one of the New methods depending on the type of callback function used. + * Try to use a C function unless some data needs to be stored, otherwise functors and class methods + * are also supported. + * + * A constraint can be applied to an object in the following manner: + * + * @code + * Handle handle = CreateMyObject(); + * Constraint constraint = Constraint::New< Vector3 >( handle, CONSTRAINING_PROPERTY_INDEX, &MyFunction ); + * constraint.AddSource( LocalSource( INPUT_PROPERTY_INDEX ) ); + * constraint.Apply(); + * @endcode */ class DALI_IMPORT_API Constraint : public BaseHandle { public: - typedef Any AnyFunction; ///< Generic function pointer for constraint + /** + * @brief Template for the Function that is called by the Constraint system. + * + * Supports: + * - C style functions + * - Static member methods of an object + * - Member functions of a particular class + * - Functors of a particular class + * - If a functor or method is provided, then a copy of the object is made. + * + * The expected signature of the callback should be: + * @code + * void Function( P&, const PropertyInputContainer& ); + * @endcode + * + * The P& parameter is an in,out parameter which stores the current value of the property. The callback + * should change this value to the desired one. The PropertyInputContainer is a const reference to the property inputs + * added to the Constraint in the order they were added via AddSource(). + * + * @tparam P The property type to constrain. + */ + template< typename P > + class Function : public CallbackBase + { + public: + + /** + * @brief Constructor which connects to the provided C function (or a static member function). + * + * The expected signature of the function is: + * @code + * void MyFunction( P&, const PropertyInputContainer& ); + * @endcode + * + * @param[in] function The function to call. + */ + Function( void( *function )( P&, const PropertyInputContainer& ) ) + : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) ), + mCopyConstructorDispatcher( NULL ) + { + } + + /** + * @brief Constructor which copies a function object and connects to the functor of that object. + * + * The function object should have a functor with the following signature: + * @code + * void operator()( P&, const PropertyInputContainer& ); + * @endcode + * + * @param[in] object The object to copy. + * + * @tparam T The type of the object. + */ + template< class T > + Function( const T& object ) + : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object + NULL, // uses operator() instead of member function + reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcher2< T, P&, const PropertyInputContainer& >::Dispatch ), + reinterpret_cast< CallbackBase::Destructor >( &Destroyer< T >::Delete ) ), + mCopyConstructorDispatcher( reinterpret_cast< CopyConstructorDispatcher >( &ObjectCopyConstructorDispatcher< T >::Copy ) ) + { + } + + /** + * @brief Constructor which copies a function object and allows a connection to a member method. + * + * The object should have a method with the signature: + * @code + * void MyObject::MyMethod( P&, const PropertyInputContainer& ); + * @endcode + * + * @param[in] object The object to copy. + * @param[in] memberFunction The member function to call. This has to be a member of the same class. + * + * @tparam T The type of the object. + */ + template< class T > + Function( const T& object, void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) ) + : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object + reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ), + reinterpret_cast< CallbackBase::Dispatcher >( &Dispatcher2< T, P&, const PropertyInputContainer& >::Dispatch ), + reinterpret_cast< CallbackBase::Destructor >( &Destroyer< T >::Delete ) ), + mCopyConstructorDispatcher( reinterpret_cast< CopyConstructorDispatcher >( &ObjectCopyConstructorDispatcher< T >::Copy ) ) + { + } + + /** + * @brief Clones the Function object. + * + * The object, if held by this object, is also copied. + * + * @return A pointer to a newly-allocation Function. + */ + CallbackBase* Clone() + { + CallbackBase* callback = NULL; + if ( mImpl && mImpl->mObjectPointer && mCopyConstructorDispatcher ) + { + callback = new Function( mCopyConstructorDispatcher( reinterpret_cast< UndefinedClass* >( mImpl->mObjectPointer ) ) /* Copy the object */, + mMemberFunction, + mImpl->mMemberFunctionDispatcher, + mImpl->mDestructorDispatcher, + mCopyConstructorDispatcher ); + } + else + { + callback = new Function( mFunction ); + } + return callback; + } + + private: + + /** + * @brief Must not be declared. + * + * This is used so that no optimisations are done by the compiler when using void*. + */ + class UndefinedClass; + + /** + * @brief Used to call the function to copy the stored object + */ + typedef UndefinedClass* (*CopyConstructorDispatcher) ( UndefinedClass* object ); + + /** + * @brief Copies the actual object in Constraint::Function. + * + * @tparam T The type of the object. + */ + template< class T > + struct ObjectCopyConstructorDispatcher + { + /** + * @brief Copy the object stored in Constraint::Function. + * + * @param[in] object The object to copy. + * + * @return Newly allocated clone of the object. + */ + static UndefinedClass* Copy( const UndefinedClass* object ) + { + T* copy = new T( *( reinterpret_cast< const T* >( object ) ) ); + return reinterpret_cast< UndefinedClass* >( copy ); + } + }; + + /** + * @brief Undefined copy constructor + */ + Function( const Function& ); + + /** + * @brief Undefined assignment operator + */ + Function& operator=( const Function& ); + + /** + * @brief Constructor used when copying the stored object. + * + * @param[in] object A newly copied object + * @param[in] memberFunction The member function of the object. + * @param[in] dispatcher Used to call the actual object. + * @param[in] destructor Used to delete the owned object. + * @param[in] copyConstructorDispatcher Used to create a copy of the owned object. + */ + Function( void* object, + CallbackBase::MemberFunction memberFunction, + CallbackBase::Dispatcher dispatcher, + CallbackBase::Destructor destructor, + CopyConstructorDispatcher copyConstructorDispatcher ) + : CallbackBase( object, memberFunction, dispatcher, destructor ), + mCopyConstructorDispatcher( copyConstructorDispatcher ) + { + } + + /** + * @brief Constructor used when copying a simple stored function. + * + * @param[in] function The function to call. + */ + Function( CallbackBase::Function function ) + : CallbackBase( function ), + mCopyConstructorDispatcher( NULL ) + { + } + + // Data + + CopyConstructorDispatcher mCopyConstructorDispatcher; ///< Function to call to copy the stored object + }; /** * @brief The action that will happen when the constraint is removed. * - * Constraints can be applied gradually; see SetApplyTime() for more details. - * When a constraint is fully-applied the final value may be "baked" i.e. saved permanently. + * The final value may be "baked" i.e. saved permanently. * Alternatively the constrained value may be discarded when the constraint is removed. */ enum RemoveAction @@ -65,7 +269,6 @@ public: Discard ///< When the constraint is removed, the constrained value is discarded. }; - static const AlphaFunction DEFAULT_ALPHA_FUNCTION; ///< AlphaFunctions::Linear static const RemoveAction DEFAULT_REMOVE_ACTION; ///< Bake /** @@ -76,262 +279,170 @@ public: Constraint(); /** - * @brief Create a constraint which targets a property. + * @brief Create a constraint which targets a property using a function or a static class member. + * + * The expected signature, for a Vector3 type for example, of the function is: + * @code + * void MyFunction( Vector3&, const PropertyInputContainer& ); + * @endcode * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] func A function which returns the constrained property value. + * Create the constraint with this function as follows: + * @code + * Constraint constraint = Constraint::New< Vector3 >( handle, CONSTRAINING_PROPERTY_INDEX, &MyFunction ); + * @endcode + * + * @param[in] handle The handle to the property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] function The function to call to set the constrained property value. * @return The new constraint. + * + * @tparam P The type of the property to constrain. */ - template - static Constraint New( Property::Index target, - boost::function

func ) + template< class P > + static Constraint New( Handle handle, Property::Index targetIndex, void( *function )( P&, const PropertyInputContainer& ) ) { - return New( target, - PropertyTypes::Get

(), - func ); + CallbackBase* callback = new Constraint::Function< P >( function ); + return New( handle, targetIndex, PropertyTypes::Get< P >(), callback ); } /** - * @brief Create a constraint which targets a property. + * @brief Create a constraint which targets a property using a functor object. + * + * The expected structure, for a Vector3 type for example, of the functor object is: + * @code + * struct MyObject + * { + * void operator() ( Vector3&, const PropertyInputContainer& ); + * }; + * @endcode * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] func A function which returns the constrained property value. + * Create the constraint with this object as follows: + * @code + * Constraint constraint = Constraint::New< Vector3 >( handle, CONSTRAINING_PROPERTY_INDEX, MyObject() ); + * @endcode + * + * @param[in] handle The handle to the property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] object The functor object whose functor is called to set the constrained property value. * @return The new constraint. + * + * @tparam P The type of the property to constrain. + * @tparam T The type of the object. */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - boost::function

func ) + template< class P, class T > + static Constraint New( Handle handle, Property::Index targetIndex, const T& object ) { - return New( target, - PropertyTypes::Get

(), - source1, - func ); + CallbackBase* function = new Constraint::Function< P >( object ); + return New( handle, targetIndex, PropertyTypes::Get< P >(), function ); } /** - * @brief Create a constraint which targets a property. + * @brief Create a constraint which targets a property using an object method. + * + * The expected structure, for a Vector3 type for example, of the object is: + * @code + * struct MyObject + * { + * void MyMethod( Vector3&, const PropertyInputContainer& ); + * }; + * @endcode * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] func A function which returns the constrained property value. + * Create the constraint with this object as follows: + * @code + * Constraint constraint = Constraint::New< Vector3 >( handle, CONSTRAINING_PROPERTY_INDEX, MyObject(), &MyObject::MyMethod ); + * @endcode + * + * @param[in] handle The handle to the property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] object The object whose member function is called to set the constrained property value. + * @param[in] memberFunction The member function to call to set the constrained property value. * @return The new constraint. + * + * @tparam P The type of the property to constrain. + * @tparam T The type of the object. */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - ConstraintSource source2, - boost::function

func ) + template< class P, class T > + static Constraint New( Handle handle, Property::Index targetIndex, const T& object, void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) ) { - return New( target, - PropertyTypes::Get

(), - source1, - source2, - func ); + CallbackBase* function = new Constraint::Function< P >( object, memberFunction ); + return New( handle, targetIndex, PropertyTypes::Get< P >(), function ); } /** - * @brief Create a constraint which targets a property. - * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] func A function which returns the constrained property value. + * @brief Creates a clones of this constraint for another object. + * + * @param[in] handle The handle to the property-owning object this constraint is to be cloned for. + * * @return The new constraint. */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - boost::function

func ) - { - return New( target, - PropertyTypes::Get

(), - source1, - source2, - source3, - func ); - } + Constraint Clone( Handle handle ); /** - * @brief Create a constraint which targets a property. - * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] func A function which returns the constrained property value. - * @return The new constraint. + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - boost::function

func ) - { - return New( target, - PropertyTypes::Get

(), - source1, - source2, - source3, - source4, - func ); - } + ~Constraint(); /** - * @brief Create a constraint which targets a property. - * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] source5 The source of a property; the current value will be passed as the 6th parameter of func. - * @param [in] func A function which returns the constrained property value. - * @return The new constraint. + * @brief This copy constructor is required for (smart) pointer semantics. + * + * @param [in] constraint A reference to the copied handle */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - boost::function

func ) - { - return New( target, - PropertyTypes::Get

(), - source1, - source2, - source3, - source4, - source5, - func ); - } + Constraint( const Constraint& constraint ); /** - * @brief Create a constraint which targets a property. - * - * The templated parameter P, is the type of the property to constrain. - * @param [in] target The index of the property to constrain. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] source5 The source of a property; the current value will be passed as the 6th parameter of func. - * @param [in] source6 The source of a property; the current value will be passed as the 7th parameter of func. - * @param [in] func A function which returns the constrained property value. - * @return The new constraint. + * @brief This assignment operator is required for (smart) pointer semantics. + * + * @param [in] rhs A reference to the copied handle + * @return A reference to this */ - template - static Constraint New( Property::Index target, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - ConstraintSource source6, - boost::function

func ) - { - return New( target, - PropertyTypes::Get

(), - source1, - source2, - source3, - source4, - source5, - source6, - func ); - } + Constraint& operator=( const Constraint& rhs ); /** * @brief Downcast an Object handle to Constraint handle. * * If handle points to a Constraint object the * downcast produces valid handle. If not the returned handle is left uninitialized. - * @param[in] handle to An object + * @param[in] baseHandle to An object * @return handle to a Constraint object or an uninitialized handle */ - static Constraint DownCast( BaseHandle handle ); + static Constraint DownCast( BaseHandle baseHandle ); /** - * @brief Destructor + * @brief Adds a constraint source to the constraint * - * This is non-virtual since derived Handle types must not contain data or virtual methods. + * @param[in] source The constraint source input to add */ - ~Constraint(); + void AddSource( ConstraintSource source ); /** - * @brief This copy constructor is required for (smart) pointer semantics. + * @brief Applies this constraint. * - * @param [in] handle A reference to the copied handle + * @pre The constraint must be initialized + * @pre The target object must still be alive + * @pre The source inputs should not have been destroyed */ - Constraint(const Constraint& handle); + void Apply(); /** - * @brief This assignment operator is required for (smart) pointer semantics. - * - * @param [in] rhs A reference to the copied handle - * @return A reference to this - */ - Constraint& operator=(const Constraint& rhs); - - /** - * @brief Set the time taken for the constraint to be fully applied. - * - * The default is zero, meaning that the constraint is applied immediately. - * @param [in] timePeriod The constraint will be applied during this time period. - */ - void SetApplyTime( TimePeriod timePeriod ); - - /** - * @brief Retrieve the time taken for the constraint to be fully applied. - * - * @return The apply time. + * @brief Removes this constraint. */ - TimePeriod GetApplyTime() const; + void Remove(); /** - * @brief Set the alpha function for a constraint; the default is AlphaFunctions::Linear. + * @brief Retrieve the object which this constraint is targeting. * - * @param [in] func The alpha function to use when applying/removing the constraint. + * @return The target object. */ - void SetAlphaFunction( AlphaFunction func ); + Handle GetTargetObject(); /** - * @brief Retrieve the alpha function of a constraint. + * @brief Retrieve the property which this constraint is targeting. * - * @return The function. + * @return The target property. */ - AlphaFunction GetAlphaFunction(); + Dali::Property::Index GetTargetProperty(); /** * @brief Set whether the constraint will "bake" a value when fully-applied. @@ -370,135 +481,20 @@ public: // Not intended for use by Application developers * @brief This constructor is used by Dali New() methods * @param [in] constraint A pointer to a newly allocated Dali resource */ - explicit DALI_INTERNAL Constraint( Internal::Constraint* constraint ); + explicit DALI_INTERNAL Constraint( Internal::ConstraintBase* constraint ); private: // Not intended for use by Application developers /** * @brief Construct a new constraint which targets a property. * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] source5 The source of a property; the current value will be passed as the 6th parameter of func. - * @param [in] func The constraint function. - * @return The new constraint. - */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - AnyFunction func ); - - /** - * @brief Construct a new constraint which targets a property. - * - * @param [in] target The index of the property to constrain. - * @param [in] targetType The type of the constrained property. - * @param [in] source1 The source of a property; the current value will be passed as the 2nd parameter of func. - * @param [in] source2 The source of a property; the current value will be passed as the 3rd parameter of func. - * @param [in] source3 The source of a property; the current value will be passed as the 4th parameter of func. - * @param [in] source4 The source of a property; the current value will be passed as the 5th parameter of func. - * @param [in] source5 The source of a property; the current value will be passed as the 6th parameter of func. - * @param [in] source6 The source of a property; the current value will be passed as the 7th parameter of func. - * @param [in] func The constraint function. + * @param[in] handle The handle to the property-owning object. + * @param[in] targetIndex The index of the property to constrain. + * @param[in] targetType Type The type of the constrained property. + * @param[in] function The constraint function. * @return The new constraint. */ - static Constraint New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - ConstraintSource source6, - AnyFunction func ); + static Constraint New( Handle handle, Property::Index targetIndex, Property::Type targetType, CallbackBase* function ); }; } // namespace Dali diff --git a/dali/public-api/animation/constraints.h b/dali/public-api/animation/constraints.h index 7efc7a4..d9e0400 100644 --- a/dali/public-api/animation/constraints.h +++ b/dali/public-api/animation/constraints.h @@ -19,6 +19,7 @@ */ // INTERNAL INCLUDES +#include #include #include #include @@ -30,181 +31,100 @@ namespace Dali { /** - * @brief Scale To Fit constraint. - * - * Scales an Actor, such that it fits within it's Parent's Size. - * f(current, size, parentSize) = parentSize / size - */ -struct ScaleToFitConstraint -{ - /** - * @brief Constructor. - */ - ScaleToFitConstraint() - { } - - /** - * @brief Functor operator - * - * @param[in] current The actor's current scale - * @param[in] sizeProperty The actor's current size - * @param[in] parentSizeProperty The parent's current size. - * @return The actor's new scale - */ - Vector3 operator()(const Vector3& current, - const PropertyInput& sizeProperty, - const PropertyInput& parentSizeProperty) - { - const Vector3 size = sizeProperty.GetVector3(); - const Vector3 parentSize = parentSizeProperty.GetVector3(); - - return Vector3( fabsf(size.x) > Math::MACHINE_EPSILON_1 ? (parentSize.x / size.x) : 0.0f, - fabsf(size.y) > Math::MACHINE_EPSILON_1 ? (parentSize.y / size.y) : 0.0f, - fabsf(size.z) > Math::MACHINE_EPSILON_1 ? (parentSize.z / size.z) : 0.0f ); - } -}; - -/** - * @brief Scale To Fit Keep Aspect Ratio constraint. + * @brief EqualToConstraint * - * Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio. - * f(current, size, parentSize) = Vector3( min( parentSizeX / sizeX, min( parentSizeY / sizeY, parentSizeZ / sizeZ ) ) + * f(current, property) = property */ -struct ScaleToFitKeepAspectRatioConstraint +struct EqualToConstraint { /** * @brief Constructor. */ - ScaleToFitKeepAspectRatioConstraint() + EqualToConstraint() { } /** - * @brief Functor operator + * @brief override functor for float properties * - * @param[in] current The actor's current scale - * @param[in] sizeProperty The actor's current size - * @param[in] parentSizeProperty The parent's current size. - * @return The actor's new scale - */ - Vector3 operator()(const Vector3& current, - const PropertyInput& sizeProperty, - const PropertyInput& parentSizeProperty) - { - return FitKeepAspectRatio( parentSizeProperty.GetVector3(), sizeProperty.GetVector3() ); - } -}; - -/** - * @brief Scale To Fill XY Keep Aspect Ratio constraint. - * - * Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio. - * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) ) - */ -struct ScaleToFillXYKeepAspectRatioConstraint -{ - /** - * @brief Constructor. - */ - ScaleToFillXYKeepAspectRatioConstraint() - { } - - /** - * @param[in] current The actor's current scale - * @param[in] sizeProperty The actor's current size - * @param[in] parentSizeProperty The parent's current size. - * @return The actor's new scale + * @param[in, out] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy + * @return The copy of the input property */ - Vector3 operator()(const Vector3& current, - const PropertyInput& sizeProperty, - const PropertyInput& parentSizeProperty) + void operator()( float& current, const PropertyInputContainer& inputs ) { - return FillXYKeepAspectRatio( parentSizeProperty.GetVector3(), sizeProperty.GetVector3() ); + current = inputs[0]->GetFloat(); } -}; - -/** - * @brief EqualToConstraint - * - * f(current, property) = property - */ -struct EqualToConstraint -{ - /** - * @brief Constructor. - */ - EqualToConstraint() - { } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - float operator()(const float current, const PropertyInput& property) + void operator()( Vector2& current, const PropertyInputContainer& inputs ) { - return property.GetFloat(); + current = inputs[0]->GetVector2(); } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in,out] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - Vector3 operator()(const Vector3& current, const PropertyInput& property) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - return property.GetVector3(); + current = inputs[0]->GetVector3(); } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in,out] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - Vector4 operator()(const Vector4& current, const PropertyInput& property) + void operator()( Vector4& current, const PropertyInputContainer& inputs ) { - return property.GetVector4(); + current = inputs[0]->GetVector4(); } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in,out] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - Quaternion operator()(const Quaternion& current, const PropertyInput& property) + void operator()( Quaternion& current, const PropertyInputContainer& inputs ) { - return property.GetQuaternion(); + current = inputs[0]->GetQuaternion(); } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in,out] current The current property value + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - Matrix3 operator()(const Matrix3& current, const PropertyInput& property) + void operator()( Matrix3& current, const PropertyInputContainer& inputs ) { - return property.GetMatrix3(); + current = inputs[0]->GetMatrix3(); } /** * @brief override functor for float properties * - * @param[in] current The current property value - * @param[in] property The property to copy + * @param[in,out] current The current property value, the constrained value is set + * @param[in] inputs Contains the property to copy * @return The copy of the input property */ - Matrix operator()(const Matrix& current, const PropertyInput& property) + void operator()( Matrix& current, const PropertyInputContainer& inputs ) { - return property.GetMatrix(); + current = inputs[0]->GetMatrix(); } }; @@ -212,7 +132,7 @@ struct EqualToConstraint /** * @brief RelativeToConstraint for Vector3 properties * - * f(current, property, scale) = property * scale + * current = property * scale */ struct RelativeToConstraint { @@ -231,9 +151,9 @@ struct RelativeToConstraint /** * @brief Functor. */ - Vector3 operator()(const Vector3& current, const PropertyInput& property) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - return property.GetVector3() * mScale; + current = inputs[0]->GetVector3() * mScale; } Vector3 mScale; ///< Component-wise scale factor @@ -253,39 +173,15 @@ struct RelativeToConstraintFloat /** * @brief Functor. */ - float operator()(const float current, const PropertyInput& property) + void operator()( float& current, const PropertyInputContainer& inputs ) { - return property.GetFloat() * mScale; + current = inputs[0]->GetFloat() * mScale; } float mScale; ///< Scale factor }; /** - * @brief Constraint which sets width to be another actor's width, - * and the height to a fixed height. - */ -struct SourceWidthFixedHeight -{ - /** - * @brief Constructor. - */ - SourceWidthFixedHeight( float height ) - : mFixedHeight( height ) { } - - /** - * @brief Functor. - */ - Vector3 operator()(const Vector3& current, - const PropertyInput& sourceSize) - { - return Vector3( sourceSize.GetVector3().width, mFixedHeight, current.depth ); - } - - float mFixedHeight; ///< the fixed height -}; - -/** * @brief Constraint function to aim a camera at a target. * * Constraint which sets camera's orientation given camera world position @@ -293,17 +189,16 @@ struct SourceWidthFixedHeight * constrained actor along the vector between camera position and * target position. * - * @param[in] current The current orientation property value - * @param[in] targetPosition World position of target - * @param[in] cameraPosition World position of camera - * @param[in] targetOrientation World orientation of the target + * @param[in,out] current The current orientation property value, the constrained value is set. + * @param[in] inputs Contains the World position of the target, the World position of the camera, and the world orientation of the target * @return The orientation of the camera */ -inline Quaternion LookAt( const Quaternion& current, - const PropertyInput& targetPosition, - const PropertyInput& cameraPosition, - const PropertyInput& targetOrientation ) +inline void LookAt( Quaternion& current, const PropertyInputContainer& inputs ) { + const PropertyInput& targetPosition( *inputs[0] ); + const PropertyInput& cameraPosition( *inputs[1] ); + const PropertyInput& targetOrientation( *inputs[2] ); + Vector3 vForward = targetPosition.GetVector3() - cameraPosition.GetVector3(); vForward.Normalize(); @@ -320,7 +215,7 @@ inline Quaternion LookAt( const Quaternion& current, Vector3 vY = vForward.Cross(vX); vY.Normalize(); - return Quaternion( vX, vY, vForward ); + current = Quaternion( vX, vY, vForward ); } } // namespace Dali diff --git a/dali/public-api/dali-core.h b/dali/public-api/dali-core.h index 032e4bc..2bb3151 100644 --- a/dali/public-api/dali-core.h +++ b/dali/public-api/dali-core.h @@ -32,11 +32,8 @@ #include #include -#include -#include #include #include -#include #include #include #include diff --git a/dali/public-api/file.list b/dali/public-api/file.list index d7a7721..2009651 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -11,7 +11,6 @@ public_api_src_files = \ $(public_api_src_dir)/actors/mesh-actor.cpp \ $(public_api_src_dir)/actors/text-actor.cpp \ $(public_api_src_dir)/actors/renderable-actor.cpp \ - $(public_api_src_dir)/animation/active-constraint.cpp \ $(public_api_src_dir)/animation/animation.cpp \ $(public_api_src_dir)/animation/alpha-functions.cpp \ $(public_api_src_dir)/animation/constraint.cpp \ @@ -135,13 +134,10 @@ public_api_core_actors_header_files = \ $(public_api_src_dir)/actors/sampling.h public_api_core_animation_header_files = \ - $(public_api_src_dir)/animation/active-constraint.h \ - $(public_api_src_dir)/animation/active-constraint-declarations.h \ $(public_api_src_dir)/animation/alpha-functions.h \ $(public_api_src_dir)/animation/animation.h \ $(public_api_src_dir)/animation/constraint.h \ $(public_api_src_dir)/animation/constraints.h \ - $(public_api_src_dir)/animation/constraint-functions.h \ $(public_api_src_dir)/animation/constraint-source.h \ $(public_api_src_dir)/animation/key-frames.h \ $(public_api_src_dir)/animation/path.h \ diff --git a/dali/public-api/object/handle.cpp b/dali/public-api/object/handle.cpp index 01065b5..1772dd0 100644 --- a/dali/public-api/object/handle.cpp +++ b/dali/public-api/object/handle.cpp @@ -19,7 +19,6 @@ #include // INTERNAL INCLUDES -#include #include #include #include @@ -159,21 +158,6 @@ void Handle::RemovePropertyNotifications() GetImplementation(*this).RemovePropertyNotifications(); } -ActiveConstraint Handle::ApplyConstraint( Constraint constraint ) -{ - return GetImplementation(*this).ApplyConstraint( GetImplementation( constraint ) ); -} - -ActiveConstraint Handle::ApplyConstraint( Constraint constraint, Handle weightObject ) -{ - return GetImplementation(*this).ApplyConstraint( GetImplementation( constraint ), weightObject ); -} - -void Handle::RemoveConstraint(ActiveConstraint activeConstraint) -{ - GetImplementation(*this).RemoveConstraint( activeConstraint ); -} - void Handle::RemoveConstraints() { GetImplementation(*this).RemoveConstraints(); diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index 0dd7eb3..6a7963a 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -32,7 +32,6 @@ namespace Dali { -class ActiveConstraint; class Constraint; class PropertyNotification; class PropertyCondition; @@ -319,37 +318,6 @@ public: // Constraints /** - * @brief Constrain one of the properties of an Actor. - * - * @note The constraint will be copied by the Actor. This means that modifying the apply-time etc. - * of the constraint, will not affect actors which are already being constrained. - * @pre The Actor has been initialized. - * @param[in] constraint The constraint to apply. - * @return The active-constraint being applied to the actor. - */ - ActiveConstraint ApplyConstraint( Constraint constraint ); - - /** - * @brief Constrain one of the properties of an Actor, using a custom weight property. - * - * This overload is intended to allow a single weight property to be shared by many constraints - * e.g. call WeightObject::New() once, and pass the return value into every call to ApplyConstraint(). - * @pre The Actor has been initialized. - * @param[in] constraint The constraint to apply. - * @param[in] weightObject An object which is expected to have a float property named "weight". - * @return The active-constraint being applied to the actor. - */ - ActiveConstraint ApplyConstraint( Constraint constraint, Handle weightObject ); - - /** - * @brief Remove one constraint from an Object. - * - * @pre The Object has been initialized. - * @param[in] activeConstraint The active-constraint to remove. - */ - void RemoveConstraint( ActiveConstraint activeConstraint ); - - /** * @brief Remove all constraints from an Object. * * @pre The object has been initialized. @@ -359,7 +327,7 @@ public: /** * @brief Remove all the constraint from the Object with a matching tag. * - * @pre The Object has been intialized. + * @pre The Object has been initialized. * @param[in] tag The tag of the constraints which will be removed */ void RemoveConstraints( unsigned int tag ); diff --git a/dali/public-api/shader-effects/shader-effect.h b/dali/public-api/shader-effects/shader-effect.h index 1778968..e9a8502 100644 --- a/dali/public-api/shader-effects/shader-effect.h +++ b/dali/public-api/shader-effects/shader-effect.h @@ -19,7 +19,6 @@ */ // INTERNAL INCLUDES -#include #include #include @@ -51,7 +50,6 @@ namespace Dali */ #define DALI_COMPOSE_SHADER(STR) #STR -class Constraint; class Image; struct Vector2; struct Vector3; -- 2.7.4