use modern construct 'nullptr' instead of 'NULL' or '0'
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
index 6c49499..ecc6ab9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -15,7 +15,7 @@
  *
  */
 
-#include <dali/internal/event/common/proxy-object.h>
+#include <dali/internal/event/common/object-impl.h>
 #include <dali/internal/event/animation/property-constraint.h>
 #include <dali/internal/event/animation/property-input-accessor.h>
 #include <dali/internal/event/animation/property-input-indexer.h>
@@ -24,8 +24,6 @@
 #include <dali/internal/update/common/scene-graph-property-notification.h>
 #include <dali/internal/update/common/property-condition-functions.h>
 
-using namespace std;
-
 namespace Dali
 {
 
@@ -35,33 +33,37 @@ namespace Internal
 namespace SceneGraph
 {
 
-PropertyNotification* PropertyNotification::New(ProxyObject& proxy,
+PropertyNotification* PropertyNotification::New(Object& object,
                                                 Property::Index propertyIndex,
                                                 Property::Type propertyType,
                                                 int componentIndex,
                                                 ConditionType condition,
                                                 RawArgumentContainer& arguments,
-                                                NotifyMode notifyMode)
+                                                NotifyMode notifyMode,
+                                                bool compare)
 {
-  return new PropertyNotification( proxy, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode );
+  return new PropertyNotification( object, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare );
 }
 
 
-PropertyNotification::PropertyNotification(ProxyObject& proxy,
+PropertyNotification::PropertyNotification(Object& object,
                                            Property::Index propertyIndex,
                                            Property::Type propertyType,
                                            int componentIndex,
                                            ConditionType condition,
                                            RawArgumentContainer& arguments,
-                                           NotifyMode notifyMode)
-: mProxy(&proxy),
+                                           NotifyMode notifyMode,
+                                           bool compare)
+: mObject(&object),
   mPropertyIndex(propertyIndex),
   mPropertyType(propertyType),
-  mProperty(NULL),
+  mProperty(nullptr),
   mComponentIndex(componentIndex),
   mConditionType(condition),
   mArguments(arguments),
-  mValid(false)
+  mValid(false),
+  mNotifyMode( Dali::PropertyNotification::DISABLED ),
+  mConditionFunction(nullptr)
 {
   SetNotifyMode(notifyMode);
 
@@ -89,7 +91,14 @@ PropertyNotification::PropertyNotification(ProxyObject& proxy,
     }
     case PropertyCondition::Step:
     {
-      mConditionFunction = Step::GetFunction(mPropertyType);
+      if( compare == true )
+      {
+        mConditionFunction = Step::GetCompareFunction(mPropertyType);
+      }
+      else
+      {
+        mConditionFunction = Step::GetFunction(mPropertyType);
+      }
       break;
     }
     case PropertyCondition::VariableStep:
@@ -104,8 +113,8 @@ PropertyNotification::PropertyNotification(ProxyObject& proxy,
     }
   }
 
-  mProperty = mProxy->GetSceneObjectInputProperty( mPropertyIndex );
-  int internalComponentIndex = mProxy->GetPropertyComponentIndex(mPropertyIndex);
+  mProperty = mObject->GetSceneObjectInputProperty( mPropertyIndex );
+  int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
   {
     // override the one passed in
@@ -124,33 +133,7 @@ bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgum
 
 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
 {
-  switch(notifyMode)
-  {
-    case Dali::PropertyNotification::Disabled:
-    {
-      mNotifyValidity[0] = false;
-      mNotifyValidity[1] = false;
-      break;
-    }
-    case Dali::PropertyNotification::NotifyOnTrue:
-    {
-      mNotifyValidity[0] = false;
-      mNotifyValidity[1] = true;
-      break;
-    }
-    case Dali::PropertyNotification::NotifyOnFalse:
-    {
-      mNotifyValidity[0] = true;
-      mNotifyValidity[1] = false;
-      break;
-    }
-    case Dali::PropertyNotification::NotifyOnChanged:
-    {
-      mNotifyValidity[0] = true;
-      mNotifyValidity[1] = true;
-      break;
-    }
-  }
+  mNotifyMode = notifyMode;
 }
 
 bool PropertyNotification::Check( BufferIndex bufferIndex )
@@ -161,8 +144,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
@@ -173,11 +156,34 @@ bool PropertyNotification::Check( BufferIndex bufferIndex )
   }
 
   if( mValid != currentValid
-      || (currentValid && ((mConditionType == PropertyCondition::Step)
-                        || (mConditionType == PropertyCondition::VariableStep))) )
+      || ( currentValid && ( ( mConditionType == PropertyCondition::Step )
+                        || ( mConditionType == PropertyCondition::VariableStep ) ) ) )
   {
     mValid = currentValid;
-    notifyRequired = mNotifyValidity[currentValid];
+    //  means don't notify so notifyRequired stays false
+    switch( mNotifyMode )
+    {
+      case Dali::PropertyNotification::DISABLED:
+      {
+        // notify never, already initialized to false
+        break;
+      }
+      case Dali::PropertyNotification::NOTIFY_ON_TRUE:
+      {
+        notifyRequired = mValid; // notify if value is true
+        break;
+      }
+      case Dali::PropertyNotification::NOTIFY_ON_FALSE:
+      {
+        notifyRequired = !mValid; // notify when its false
+        break;
+      }
+      case Dali::PropertyNotification::NOTIFY_ON_CHANGED:
+      {
+        notifyRequired = true; // notify whenever changed
+        break;
+      }
+    }
   }
 
   return notifyRequired;