Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture-detector-impl.cpp
index 3aa90ca..77bb5bb 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/public-api/math/radian.h>
 #include <dali/public-api/math/degree.h>
 #include <dali/integration-api/debug.h>
+#include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/common/property-index-ranges.h>
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/events/gesture-event-processor.h>
@@ -34,8 +35,11 @@ namespace Dali
 
 const Property::Index PanGestureDetector::SCREEN_POSITION      = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
 const Property::Index PanGestureDetector::SCREEN_DISPLACEMENT  = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 1;
-const Property::Index PanGestureDetector::LOCAL_POSITION       = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2;
-const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT   = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3;
+const Property::Index PanGestureDetector::SCREEN_VELOCITY      = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2;
+const Property::Index PanGestureDetector::LOCAL_POSITION       = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3;
+const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT   = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 4;
+const Property::Index PanGestureDetector::LOCAL_VELOCITY       = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 5;
+const Property::Index PanGestureDetector::PANNING              = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 6;
 
 namespace Internal
 {
@@ -45,22 +49,17 @@ namespace
 
 // Properties
 
-const std::string DEFAULT_PROPERTY_NAMES[] =
+PropertyDetails DEFAULT_PROPERTIES[] =
 {
-  "screen-position",
-  "screen-displacement",
-  "local-position",
-  "local-displacement",
-};
-const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_NAMES ) / sizeof( std::string );
-
-const Property::Type DEFAULT_PROPERTY_TYPES[DEFAULT_PROPERTY_COUNT] =
-{
-  Property::VECTOR2,  // SCREEN_POSITION
-  Property::VECTOR2,  // SCREEN_DISPLACEMENT
-  Property::VECTOR2,  // LOCAL_POSITION
-  Property::VECTOR2,  // LOCAL_DISPLACEMENT
+  { "screen-position",     Property::VECTOR2, false, false, true },
+  { "screen-displacement", Property::VECTOR2, false, false, true },
+  { "screen-velocity",     Property::VECTOR2, false, false, true },
+  { "local-position",      Property::VECTOR2, false, false, true },
+  { "local-displacement",  Property::VECTOR2, false, false, true },
+  { "local-velocity",      Property::VECTOR2, false, false, true },
+  { "panning",             Property::BOOLEAN, false, false, true },
 };
+const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTIES ) / sizeof( DEFAULT_PROPERTIES[0] );
 
 BaseHandle Create()
 {
@@ -104,8 +103,6 @@ float GetOppositeAngle( float angle )
 
 } // unnamed namespace
 
-PanGestureDetector::DefaultPropertyLookup* PanGestureDetector::mDefaultPropertyLookup = NULL;
-
 PanGestureDetectorPtr PanGestureDetector::New()
 {
   return new PanGestureDetector;
@@ -117,15 +114,6 @@ PanGestureDetector::PanGestureDetector()
   mMaximumTouches(1),
   mSceneObject(NULL)
 {
-  if( !mDefaultPropertyLookup )
-  {
-    mDefaultPropertyLookup = new DefaultPropertyLookup();
-    const int start = DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
-    for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
-    {
-      ( *mDefaultPropertyLookup )[ DEFAULT_PROPERTY_NAMES[i] ] = i + start;
-    }
-  }
 }
 
 PanGestureDetector::~PanGestureDetector()
@@ -336,11 +324,6 @@ void PanGestureDetector::OnActorDestroyed(Object& object)
   // Do nothing
 }
 
-bool PanGestureDetector::IsSceneObjectRemovable() const
-{
-  return false;
-}
-
 unsigned int PanGestureDetector::GetDefaultPropertyCount() const
 {
   return DEFAULT_PROPERTY_COUNT;
@@ -357,18 +340,16 @@ void PanGestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& in
   }
 }
 
-const std::string& PanGestureDetector::GetDefaultPropertyName( Property::Index index ) const
+const char* PanGestureDetector::GetDefaultPropertyName( Property::Index index ) const
 {
   index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
   {
-    return DEFAULT_PROPERTY_NAMES[ index ];
+    return DEFAULT_PROPERTIES[ index ].name;
   }
   else
   {
-    // Index out-of-range... return empty string.
-    static const std::string INVALID_PROPERTY_NAME;
-    return INVALID_PROPERTY_NAME;
+    return NULL;
   }
 }
 
@@ -376,15 +357,16 @@ Property::Index PanGestureDetector::GetDefaultPropertyIndex(const std::string& n
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  DALI_ASSERT_DEBUG( NULL != mDefaultPropertyLookup );
-
   // Look for name in default properties
-  DefaultPropertyLookup::const_iterator result = mDefaultPropertyLookup->find( name );
-  if ( mDefaultPropertyLookup->end() != result )
+  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
-    index = result->second;
+    const Internal::PropertyDetails* property = &DEFAULT_PROPERTIES[ i ];
+    if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
+    {
+      index = i;
+      break;
+    }
   }
-
   return index;
 }
 
@@ -411,7 +393,7 @@ Property::Type PanGestureDetector::GetDefaultPropertyType(Property::Index index)
   index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
   {
-    return DEFAULT_PROPERTY_TYPES[ index ];
+    return DEFAULT_PROPERTIES[ index ].type;
   }
   else
   {
@@ -425,11 +407,6 @@ void PanGestureDetector::SetDefaultProperty( Property::Index index, const Proper
   // None of our properties should be settable from Public API
 }
 
-void PanGestureDetector::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
-{
-  // None of our properties should be settable from Public API
-}
-
 Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) const
 {
   Property::Value value;
@@ -462,6 +439,19 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
+    case Dali::PanGestureDetector::SCREEN_VELOCITY:
+    {
+      if(mSceneObject)
+      {
+        value = mSceneObject->GetScreenVelocityProperty().Get();
+      }
+      else
+      {
+        value = Vector2();
+      }
+      break;
+    }
+
     case Dali::PanGestureDetector::LOCAL_POSITION:
     {
       if(mSceneObject)
@@ -488,6 +478,32 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
+    case Dali::PanGestureDetector::LOCAL_VELOCITY:
+    {
+      if(mSceneObject)
+      {
+        value = mSceneObject->GetLocalVelocityProperty().Get();
+      }
+      else
+      {
+        value = Vector2();
+      }
+      break;
+    }
+
+    case Dali::PanGestureDetector::PANNING:
+    {
+      if(mSceneObject)
+      {
+        value = mSceneObject->GetPanningProperty().Get();
+      }
+      else
+      {
+        value = false;
+      }
+      break;
+    }
+
     default:
     {
       DALI_ASSERT_ALWAYS(false && "PanGestureDetector Property index invalid" ); // should not come here
@@ -498,12 +514,6 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
   return value;
 }
 
-void PanGestureDetector::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
-{
-  // We do not want the user to install custom properties
-  DALI_ASSERT_ALWAYS(false && "PanGestureDetector does not allow custom properties" );
-}
-
 const SceneGraph::PropertyOwner* PanGestureDetector::GetSceneObject() const
 {
   // This method should only return an object connected to the scene-graph
@@ -530,11 +540,9 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper
 
   if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
   {
-    CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index );
-
-    DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "property index is invalid" );
-
-    property = entry->second.GetSceneGraphProperty();
+    CustomProperty* custom = FindCustomProperty( index );
+    DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
+    property = custom->GetSceneGraphProperty();
   }
   else
   {
@@ -552,6 +560,12 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper
         break;
       }
 
+      case Dali::PanGestureDetector::SCREEN_VELOCITY:
+      {
+        property = &mSceneObject->GetScreenVelocityProperty();
+        break;
+      }
+
       case Dali::PanGestureDetector::LOCAL_POSITION:
       {
         property = &mSceneObject->GetLocalPositionProperty();
@@ -564,6 +578,18 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper
         break;
       }
 
+      case Dali::PanGestureDetector::LOCAL_VELOCITY:
+      {
+        property = &mSceneObject->GetLocalVelocityProperty();
+        break;
+      }
+
+      case Dali::PanGestureDetector::PANNING:
+      {
+        property = &mSceneObject->GetPanningProperty();
+        break;
+      }
+
       default:
         break;
     }