#ifndef __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__
#define __DALI_INTERNAL_ACTIVE_CONSTRAINT_BASE_H__
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * 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 <dali/internal/common/owner-pointer.h>
#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/animation/time-period.h>
#include <dali/public-api/common/dali-common.h>
+#include <dali/internal/event/animation/constraint-source-impl.h>
namespace Dali
{
{
class EventToUpdate;
-class ProxyObject;
+typedef Dali::Vector<ProxyObject*> ProxyObjectContainer;
+typedef ProxyObjectContainer::Iterator ProxyObjectIter;
namespace SceneGraph
{
/**
* An abstract base class for active constraints.
*/
-class ActiveConstraintBase : public ProxyObject
+class ActiveConstraintBase : public ProxyObject, public ProxyObject::Observer
{
public:
* 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( EventToUpdate& messageController, Property::Index targetPropertyIndex );
+ ActiveConstraintBase( EventToUpdate& messageController, Property::Index targetPropertyIndex, SourceContainer& sources, unsigned int sourceCount );
/**
* Virtual destructor.
void BeginRemove();
/**
- * Query whether the constraint is being removed.
- * This is only possible if mRemoveTime.durationSeconds is non-zero.
- * @return True if constraint is being removed.
+ * Called when the target object is destroyed.
*/
- bool IsRemoving();
+ 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.
ActiveConstraintSignalV2& AppliedSignal();
/**
- * @copydoc Dali::Constraint::SetRemoveTime()
- */
- void SetRemoveTime( TimePeriod timePeriod );
-
- /**
- * @copydoc Dali::Constraint::GetRemoveTime()
- */
- TimePeriod GetRemoveTime() const;
-
- /**
* @copydoc Dali::Constraint::SetAlphaFunction()
*/
void SetAlphaFunction(AlphaFunction func);
*/
unsigned int GetTag() const;
-
-
/**
* Connects a callback function with the object's signals.
* @param[in] object The object providing the signal.
*/
virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
-private:
+public: // ProxyObject::Observer methods
/**
- * Helper called after the first apply animation.
- * @param [in] object The active constraint.
+ * @copydoc ProxyObject::Observer::SceneObjectAdded()
*/
- static void FirstApplyFinished( Object* object );
+ virtual void SceneObjectAdded( ProxyObject& proxy );
/**
- * Helper called after the remove animation.
- * @param [in] object The active constraint.
+ * @copydoc ProxyObject::Observer::SceneObjectRemoved()
*/
- static void OnRemoveFinished( Object* object );
+ virtual void SceneObjectRemoved( ProxyObject& proxy );
- // To be implemented in derived classes
+ /**
+ * @copydoc ProxyObject::Observer::ProxyDestroyed()
+ */
+ virtual void ProxyDestroyed( ProxyObject& proxy );
+
+private:
/**
- * Used to observe the lifetime of an object with custom "weight" property
- * @param [in] weightObject The object.
+ * Helper to observe a proxy, if not already observing it
*/
- virtual void OnCustomWeightSet( ProxyObject& weightObject ) = 0;
+ void ObserveProxy( ProxyObject& proxy );
/**
- * Set the parent of the active-constraint; called during OnFirstApply().
- * @param [in] parent The parent object.
+ * Helper to stop observing proxies
*/
- virtual void OnFirstApply( ProxyObject& parent ) = 0;
+ void StopObservation();
/**
- * Notification for the derived class, when BeginRemove() is called.
+ * Helper called after the first apply animation.
+ * @param [in] object The active constraint.
*/
- virtual void OnBeginRemove() = 0;
+ 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:
EventToUpdate& mEventToUpdate;
Property::Index mTargetPropertyIndex;
+ SourceContainer mSources;
+ const unsigned int mSourceCount;
ProxyObject* mTargetProxy; ///< The proxy-object owns the active-constraint.
+ ProxyObjectContainer mObservedProxies; // We don't observe the same object twice
const SceneGraph::ConstraintBase* mSceneGraphConstraint;
float mOffstageWeight;
- TimePeriod mRemoveTime;
-
AlphaFunction mAlphaFunction;
RemoveAction mRemoveAction;
ActiveConstraintSignalV2 mAppliedSignal;
Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f
- Dali::Animation mRemoveAnimation; ///< Used to automatically animate weight back to 0.0f
-
};