Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / common / animatable-property.h
index 1165f8f..a05d545 100644 (file)
@@ -1,21 +1,22 @@
 #ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H__
 #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_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) 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.
+ *
+ */
 
 // EXTERNAL INCLUDES
 #include <limits>
@@ -26,7 +27,7 @@
 #include <dali/public-api/object/property-input.h>
 #include <dali/public-api/object/property-types.h>
 #include <dali/internal/common/message.h>
-#include <dali/internal/common/event-to-update.h>
+#include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/common/property-input-impl.h>
 #include <dali/internal/update/common/double-buffered.h>
 #include <dali/internal/update/common/property-base.h>
@@ -253,11 +254,11 @@ public:
    */
   void Bake(BufferIndex bufferIndex, bool value)
   {
-    // check if the value actually changed to avoid dirtying nodes unnecessarily
-    if( mValue[bufferIndex] != value )
+    // bake has to check the base value as current buffer value can be correct by constraint or something else
+    if( mBaseValue != value )
     {
-      mValue[bufferIndex] = value;
       mBaseValue = value;
+      mValue[bufferIndex] = value;
 
       OnBake();
     }
@@ -291,6 +292,187 @@ private:
 
 };
 
+
+/**
+ * An integer animatable property of a scene-graph object.
+ */
+template <>
+class AnimatableProperty<int> : public AnimatablePropertyBase
+{
+public:
+
+  /**
+   * Create an animatable property.
+   * @param [in] initialValue The initial value of the property.
+   */
+  AnimatableProperty( int initialValue )
+  : mValue( initialValue ),
+    mBaseValue( initialValue )
+  {
+  }
+
+  /**
+   * Virtual destructor.
+   */
+  virtual ~AnimatableProperty()
+  {
+  }
+
+  /**
+   * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
+   */
+  virtual Dali::Property::Type GetType() const
+  {
+    return Dali::PropertyTypes::Get<int>();
+  }
+
+  /**
+   * @copydoc Dali::Internal::SceneGraph::PropertyBase::ResetToBaseValue()
+   */
+  virtual void ResetToBaseValue(BufferIndex updateBufferIndex)
+  {
+    if (CLEAN_FLAG != mDirtyFlags)
+    {
+      mValue[updateBufferIndex] = mBaseValue;
+
+      mDirtyFlags = ( mDirtyFlags >> 1 );
+    }
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetInteger()
+   */
+  virtual const int& GetInteger( BufferIndex bufferIndex ) const
+  {
+    return mValue[ bufferIndex ];
+  }
+
+  /**
+   * Set the property value. This will only persist for the current frame; the property
+   * will be reset with the base value, at the beginning of the next frame.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] value The new property value.
+   */
+  void Set(BufferIndex bufferIndex, int value)
+  {
+    mValue[bufferIndex] = value;
+
+    OnSet();
+  }
+
+  /**
+   * Change the property value by a relative amount.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] delta The property will change by this amount.
+   */
+  void SetRelative(BufferIndex bufferIndex, int delta)
+  {
+    mValue[bufferIndex] = mValue[bufferIndex] + delta;
+
+    OnSet();
+  }
+
+  /**
+   * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
+   */
+  int& Get(size_t bufferIndex)
+  {
+    return mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
+   */
+  const int& Get(size_t bufferIndex) const
+  {
+    return mValue[bufferIndex];
+  }
+
+  /**
+   * Retrieve the property value.
+   * @param[in] bufferIndex The buffer to read.
+   * @return The property value.
+   */
+  int& operator[](size_t bufferIndex)
+  {
+    return mValue[bufferIndex];
+  }
+
+  /**
+   * Retrieve the property value.
+   * @param[in] bufferIndex The buffer to read.
+   * @return The property value.
+   */
+  const int& operator[](size_t bufferIndex) const
+  {
+    return mValue[bufferIndex];
+  }
+
+  /**
+   * Set both the property value & base value.
+   * @param[in] bufferIndex The buffer to write for the property value.
+   * @param[in] value The new property value.
+   */
+  void Bake(BufferIndex bufferIndex, int value)
+  {
+    mValue[bufferIndex] = value;
+    mBaseValue = mValue[bufferIndex];
+
+    OnBake();
+  }
+
+  /**
+   * Change the property value & base value by a relative amount.
+   * @param[in] bufferIndex The buffer to write for the local property value.
+   * @param[in] delta The property will change by this amount.
+   */
+  void BakeRelative(BufferIndex bufferIndex, int delta)
+  {
+    mValue[bufferIndex] = mValue[bufferIndex] + delta;
+    mBaseValue = mValue[bufferIndex];
+
+    OnBake();
+  }
+
+  /**
+   * Sets both double-buffered values & the base value.
+   * This should only be used when the owning object has not been connected to the scene-graph.
+   * @param[in] value The new property value.
+   */
+  void SetInitial(const int& value)
+  {
+    mValue[0]  = value;
+    mValue[1]  = mValue[0];
+    mBaseValue = mValue[0];
+  }
+
+  /**
+   * Change both double-buffered values & the base value by a relative amount.
+   * This should only be used when the owning object has not been connected to the scene-graph.
+   * @param[in] delta The property will change by this amount.
+   */
+  void SetInitialRelative(const int& delta)
+  {
+    mValue[0] = mValue[0] + delta;
+    mValue[1] = mValue[0];
+    mBaseValue = mValue[0];
+  }
+
+private:
+
+  // Undefined
+  AnimatableProperty(const AnimatableProperty& property);
+
+  // Undefined
+  AnimatableProperty& operator=(const AnimatableProperty& rhs);
+
+private:
+
+  DoubleBuffered<int> mValue; ///< The double-buffered property value
+  int mBaseValue;             ///< Reset to this base value at the beginning of each frame
+
+};
+
 /**
  * An float animatable property of a scene-graph object.
  */
@@ -468,7 +650,6 @@ private:
 
   DoubleBuffered<float> mValue; ///< The double-buffered property value
   float mBaseValue;             ///< Reset to this base value at the beginning of each frame
-
 };
 
 /**
@@ -539,6 +720,32 @@ public:
   }
 
   /**
+   * Set the property value. This will only persist for the current frame; the property
+   * will be reset with the base value, at the beginning of the next frame.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] value The new X value.
+   */
+  void SetX(BufferIndex bufferIndex, float value)
+  {
+    mValue[bufferIndex].x = value;
+
+    OnSet();
+  }
+
+  /**
+   * Set the property value. This will only persist for the current frame; the property
+   * will be reset with the base value, at the beginning of the next frame.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] value The new Y value.
+   */
+  void SetY(BufferIndex bufferIndex, float value)
+  {
+    mValue[bufferIndex].y = value;
+
+    OnSet();
+  }
+
+  /**
    * Change the property value by a relative amount.
    * @param[in] bufferIndex The buffer to write.
    * @param[in] delta The property will change by this amount.
@@ -551,6 +758,30 @@ public:
   }
 
   /**
+   * Change the X value by a relative amount.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] delta The X value will change by this amount.
+   */
+  void SetXRelative(BufferIndex bufferIndex, float delta)
+  {
+    mValue[bufferIndex].x += delta;
+
+    OnSet();
+  }
+
+  /**
+   * Change the Y value by a relative amount.
+   * @param[in] bufferIndex The buffer to write.
+   * @param[in] delta The Y value will change by this amount.
+   */
+  void SetYRelative(BufferIndex bufferIndex, float delta)
+  {
+    mValue[bufferIndex].y += delta;
+
+    OnSet();
+  }
+
+  /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
   Vector2& Get(size_t bufferIndex)
@@ -600,6 +831,32 @@ public:
   }
 
   /**
+   * Set both the X value & base X value.
+   * @param[in] bufferIndex The buffer to write for the property value.
+   * @param[in] value The new property value.
+   */
+  void BakeX(BufferIndex bufferIndex, float value)
+  {
+    mValue[bufferIndex].x = value;
+    mBaseValue.x = value;
+
+    OnBake();
+  }
+
+  /**
+   * Set both the Y value & base Y value.
+   * @param[in] bufferIndex The buffer to write for the property value.
+   * @param[in] value The new property value.
+   */
+  void BakeY(BufferIndex bufferIndex, float value)
+  {
+    mValue[bufferIndex].y = value;
+    mBaseValue.y = value;
+
+    OnBake();
+  }
+
+  /**
    * Change the property value & base value by a relative amount.
    * @param[in] bufferIndex The buffer to write for the local property value.
    * @param[in] delta The property will change by this amount.
@@ -612,6 +869,32 @@ public:
     OnBake();
   }
 
+  /**
+   * Change the X value & base X value by a relative amount.
+   * @param[in] bufferIndex The buffer to write for the local property value.
+   * @param[in] delta The X value will change by this amount.
+   */
+  void BakeXRelative(BufferIndex bufferIndex, float delta)
+  {
+    mValue[bufferIndex].x += delta;
+    mBaseValue.x = mValue[bufferIndex].x;
+
+    OnBake();
+  }
+
+  /**
+   * Change the Y value & base Y value by a relative amount.
+   * @param[in] bufferIndex The buffer to write for the local property value.
+   * @param[in] delta The Y value will change by this amount.
+   */
+  void BakeYRelative(BufferIndex bufferIndex, float delta)
+  {
+    mValue[bufferIndex].y += delta;
+    mBaseValue.y = mValue[bufferIndex].y;
+
+    OnBake();
+  }
+
 private:
 
   // Undefined
@@ -637,6 +920,15 @@ public:
 
   /**
    * Create an animatable property.
+   */
+  AnimatableProperty()
+  : mValue(),
+    mBaseValue()
+  {
+  }
+
+  /**
+   * Create an animatable property.
    * @param [in] initialValue The initial value of the property.
    */
   AnimatableProperty( const Vector3& initialValue )
@@ -1330,6 +1622,15 @@ public:
 
   /**
    * Create an animatable property.
+   */
+  AnimatableProperty()
+  : mValue(),
+    mBaseValue()
+  {
+  }
+
+  /**
+   * Create an animatable property.
    * @param [in] initialValue The initial value of the property.
    */
   AnimatableProperty( const Quaternion& initialValue )
@@ -1799,14 +2100,14 @@ private:
 // Messages for AnimatableProperty<T>
 
 template <class T>
-void BakeMessage( EventToUpdate& eventToUpdate,
+void BakeMessage( EventThreadServices& eventThreadServices,
                   const SceneGraph::AnimatableProperty<T>& property,
                   typename ParameterType< T >::PassingType newValue )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, T > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,
@@ -1815,14 +2116,14 @@ void BakeMessage( EventToUpdate& eventToUpdate,
 }
 
 template <class T>
-void BakeRelativeMessage( EventToUpdate& eventToUpdate,
+void BakeRelativeMessage( EventThreadServices& eventThreadServices,
                           const SceneGraph::AnimatableProperty<T>& property,
                           const T& delta )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, const T& > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,
@@ -1831,14 +2132,14 @@ void BakeRelativeMessage( EventToUpdate& eventToUpdate,
 }
 
 template <class T>
-void SetXComponentMessage( EventToUpdate& eventToUpdate,
+void SetXComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,
@@ -1847,14 +2148,14 @@ void SetXComponentMessage( EventToUpdate& eventToUpdate,
 }
 
 template <class T>
-void SetYComponentMessage( EventToUpdate& eventToUpdate,
+void SetYComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,
@@ -1863,14 +2164,14 @@ void SetYComponentMessage( EventToUpdate& eventToUpdate,
 }
 
 template <class T>
-void SetZComponentMessage( EventToUpdate& eventToUpdate,
+void SetZComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,
@@ -1879,14 +2180,14 @@ void SetZComponentMessage( EventToUpdate& eventToUpdate,
 }
 
 template <class T>
-void SetWComponentMessage( EventToUpdate& eventToUpdate,
+void SetWComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
   typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  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( &property,