Added a Max Core Property Index so that a range can be defined in toolkit
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture-detector-impl.cpp
index 5c9ea9e..c819a82 100644 (file)
@@ -18,6 +18,9 @@
 // CLASS HEADER
 #include <dali/internal/event/events/pan-gesture-detector-impl.h>
 
+// EXTERNAL INCLUDES
+#include <cstring> // for strcmp
+
 // INTERNAL INCLUDES
 #include <dali/public-api/events/pan-gesture.h>
 #include <dali/public-api/object/type-registry.h>
@@ -25,7 +28,7 @@
 #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/property-helper.h>
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/events/gesture-event-processor.h>
 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
 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::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
 {
 
@@ -49,21 +44,20 @@ namespace
 
 // Properties
 
-PropertyDetails DEFAULT_PROPERTIES[] =
-{
-  { "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] );
+//              Name                  Type   writable animatable constraint-input  enum for index-checking
+DALI_PROPERTY_TABLE_BEGIN
+DALI_PROPERTY( "screenPosition",      VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::SCREEN_POSITION     )
+DALI_PROPERTY( "screenDisplacement",  VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::SCREEN_DISPLACEMENT )
+DALI_PROPERTY( "screenVelocity",      VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::SCREEN_VELOCITY     )
+DALI_PROPERTY( "localPosition",       VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::LOCAL_POSITION      )
+DALI_PROPERTY( "localDisplacement",   VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::LOCAL_DISPLACEMENT  )
+DALI_PROPERTY( "localVelocity",       VECTOR2, false, false, true,   Dali::PanGestureDetector::Property::LOCAL_VELOCITY      )
+DALI_PROPERTY( "panning",             BOOLEAN, false, false, true,   Dali::PanGestureDetector::Property::PANNING             )
+DALI_PROPERTY_TABLE_END( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX )
 
 // Signals
 
-const char* const SIGNAL_PAN_DETECTED = "pan-detected";
+const char* const SIGNAL_PAN_DETECTED = "panDetected";
 
 BaseHandle Create()
 {
@@ -76,15 +70,6 @@ SignalConnectorType signalConnector1( mType, SIGNAL_PAN_DETECTED, &PanGestureDet
 
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_PAN_GESTURE_DETECTOR");
-
-/**
- * When debugging, helper for converting radians to degrees.
- */
-inline float RadiansToDegrees( float radian )
-{
-  return radian * 180.0f / Math::PI;
-}
-
 #endif
 
 /**
@@ -186,7 +171,7 @@ void PanGestureDetector::AddAngle( Radian angle, Radian threshold )
 
   angle = WrapInDomain( angle, -Math::PI, Math::PI );
 
-  DALI_LOG_INFO( gLogFilter, Debug::Concise, "Angle Added: %.2f, Threshold: %.2f\n", RadiansToDegrees(angle), RadiansToDegrees(threshold) );
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "Angle Added: %.2f, Threshold: %.2f\n", Degree(angle), Degree(threshold) );
 
   AngleThresholdPair pair( angle, threshold );
   mAngleContainer.push_back( pair );
@@ -202,11 +187,24 @@ void PanGestureDetector::AddDirection( Radian direction, Radian threshold )
   AddAngle( direction, threshold );
 }
 
-const PanGestureDetector::AngleContainer& PanGestureDetector::GetAngles() const
+size_t PanGestureDetector::GetAngleCount() const
+{
+  return mAngleContainer.size();
+}
+
+PanGestureDetector::AngleThresholdPair PanGestureDetector::GetAngle(size_t index) const
 {
-  return mAngleContainer;
+  PanGestureDetector::AngleThresholdPair ret( Radian(0),Radian(0) );
+
+  if( index < mAngleContainer.size() )
+  {
+    ret = mAngleContainer[index];
+  }
+
+  return ret;
 }
 
+
 void PanGestureDetector::ClearAngles()
 {
   mAngleContainer.clear();
@@ -258,7 +256,7 @@ bool PanGestureDetector::CheckAngleAllowed( Radian angle ) const
 
       DALI_LOG_INFO( gLogFilter, Debug::General,
                      "AngleToCheck: %.2f, CompareWith: %.2f, Threshold: %.2f\n",
-                     RadiansToDegrees(angle), RadiansToDegrees(angleAllowed), RadiansToDegrees(threshold) );
+                     Degree(angle), Degree(angleAllowed), Degree(threshold) );
 
       float relativeAngle( fabsf( WrapInDomain( angle - angleAllowed, -Math::PI, Math::PI ) ) );
       if ( relativeAngle <= threshold )
@@ -335,26 +333,24 @@ unsigned int PanGestureDetector::GetDefaultPropertyCount() const
 
 void PanGestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
 {
-  indices.reserve( DEFAULT_PROPERTY_COUNT );
+  indices.Reserve( DEFAULT_PROPERTY_COUNT );
 
-  int index = DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
+  int index = DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX;
   for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
   {
-    indices.push_back( index );
+    indices.PushBack( index );
   }
 }
 
 const char* PanGestureDetector::GetDefaultPropertyName( Property::Index index ) const
 {
-  index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
+  index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX;
   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
   {
-    return DEFAULT_PROPERTIES[ index ].name;
-  }
-  else
-  {
-    return NULL;
+    return DEFAULT_PROPERTY_DETAILS[ index ].name;
   }
+
+  return NULL;
 }
 
 Property::Index PanGestureDetector::GetDefaultPropertyIndex(const std::string& name) const
@@ -364,10 +360,10 @@ Property::Index PanGestureDetector::GetDefaultPropertyIndex(const std::string& n
   // Look for name in default properties
   for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
-    const Internal::PropertyDetails* property = &DEFAULT_PROPERTIES[ i ];
+    const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
     if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
     {
-      index = i;
+      index = DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX + i;
       break;
     }
   }
@@ -377,27 +373,27 @@ Property::Index PanGestureDetector::GetDefaultPropertyIndex(const std::string& n
 bool PanGestureDetector::IsDefaultPropertyWritable(Property::Index index) const
 {
   // None of our properties should be writable through the Public API
-  return false;
+  return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ].writable;
 }
 
 bool PanGestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
 {
   // None of our properties are animatable
-  return false;
+  return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ].animatable;
 }
 
 bool PanGestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
 {
   // All our properties can be used as an input to a constraint.
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ].constraintInput;
 }
 
 Property::Type PanGestureDetector::GetDefaultPropertyType(Property::Index index) const
 {
-  index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
+  index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX;
   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
   {
-    return DEFAULT_PROPERTIES[ index ].type;
+    return DEFAULT_PROPERTY_DETAILS[ index ].type;
   }
   else
   {
@@ -417,7 +413,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
 
   switch ( index )
   {
-    case Dali::PanGestureDetector::SCREEN_POSITION:
+    case Dali::PanGestureDetector::Property::SCREEN_POSITION:
     {
       if(mSceneObject)
       {
@@ -430,7 +426,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::SCREEN_DISPLACEMENT:
+    case Dali::PanGestureDetector::Property::SCREEN_DISPLACEMENT:
     {
       if(mSceneObject)
       {
@@ -443,7 +439,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::SCREEN_VELOCITY:
+    case Dali::PanGestureDetector::Property::SCREEN_VELOCITY:
     {
       if(mSceneObject)
       {
@@ -456,7 +452,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::LOCAL_POSITION:
+    case Dali::PanGestureDetector::Property::LOCAL_POSITION:
     {
       if(mSceneObject)
       {
@@ -469,7 +465,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::LOCAL_DISPLACEMENT:
+    case Dali::PanGestureDetector::Property::LOCAL_DISPLACEMENT:
     {
       if(mSceneObject)
       {
@@ -482,7 +478,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::LOCAL_VELOCITY:
+    case Dali::PanGestureDetector::Property::LOCAL_VELOCITY:
     {
       if(mSceneObject)
       {
@@ -495,7 +491,7 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co
       break;
     }
 
-    case Dali::PanGestureDetector::PANNING:
+    case Dali::PanGestureDetector::Property::PANNING:
     {
       if(mSceneObject)
       {
@@ -542,9 +538,10 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper
     return property;
   }
 
-  if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
+  if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && // Child properties are also stored as custom properties
+       ( index <= PROPERTY_CUSTOM_MAX_INDEX ) )
   {
-    CustomProperty* custom = FindCustomProperty( index );
+    CustomPropertyMetadata* custom = FindCustomProperty( index );
     DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
     property = custom->GetSceneGraphProperty();
   }
@@ -552,43 +549,43 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper
   {
     switch ( index )
     {
-      case Dali::PanGestureDetector::SCREEN_POSITION:
+      case Dali::PanGestureDetector::Property::SCREEN_POSITION:
       {
         property = &mSceneObject->GetScreenPositionProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::SCREEN_DISPLACEMENT:
+      case Dali::PanGestureDetector::Property::SCREEN_DISPLACEMENT:
       {
         property = &mSceneObject->GetScreenDisplacementProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::SCREEN_VELOCITY:
+      case Dali::PanGestureDetector::Property::SCREEN_VELOCITY:
       {
         property = &mSceneObject->GetScreenVelocityProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::LOCAL_POSITION:
+      case Dali::PanGestureDetector::Property::LOCAL_POSITION:
       {
         property = &mSceneObject->GetLocalPositionProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::LOCAL_DISPLACEMENT:
+      case Dali::PanGestureDetector::Property::LOCAL_DISPLACEMENT:
       {
         property = &mSceneObject->GetLocalDisplacementProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::LOCAL_VELOCITY:
+      case Dali::PanGestureDetector::Property::LOCAL_VELOCITY:
       {
         property = &mSceneObject->GetLocalVelocityProperty();
         break;
       }
 
-      case Dali::PanGestureDetector::PANNING:
+      case Dali::PanGestureDetector::Property::PANNING:
       {
         property = &mSceneObject->GetPanningProperty();
         break;