Merge "Follow the include-order coding conventions" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-impl.cpp
index 1aed323..f83d627 100644 (file)
@@ -35,36 +35,36 @@ const Property::Index Layer::CLIPPING_BOX    = Internal::DEFAULT_ACTOR_PROPERTY_
 
 namespace Internal
 {
-bool Layer::mFirstInstance = true;
-Actor::DefaultPropertyLookup* Layer::mDefaultLayerPropertyLookup = NULL;
 
 namespace
 {
 
+// Actions
+
+const char* const ACTION_RAISE =           "raise";
+const char* const ACTION_LOWER =           "lower";
+const char* const ACTION_RAISE_TO_TOP =    "raise-to-top";
+const char* const ACTION_LOWER_TO_BOTTOM = "lower-to-bottom";
+
 BaseHandle Create()
 {
   return Dali::Layer::New();
 }
 
-TypeRegistration mType( typeid(Dali::Layer), typeid(Dali::Actor), Create );
+TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create );
 
-TypeAction a1(mType, Dali::Layer::ACTION_RAISE, &Layer::DoAction);
-TypeAction a2(mType, Dali::Layer::ACTION_LOWER, &Layer::DoAction);
-TypeAction a3(mType, Dali::Layer::ACTION_RAISE_TO_TOP, &Layer::DoAction);
-TypeAction a4(mType, Dali::Layer::ACTION_LOWER_TO_BOTTOM, &Layer::DoAction);
+TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction );
+TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction );
+TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction );
+TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
 
-const std::string DEFAULT_LAYER_PROPERTY_NAMES[] =
+const PropertyDetails DEFAULT_PROPERTY_DETAILS[] =
 {
-  "clipping-enable",
-  "clipping-box"
-};
-const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_LAYER_PROPERTY_NAMES ) / sizeof( std::string );
-
-const Property::Type DEFAULT_LAYER_PROPERTY_TYPES[DEFAULT_LAYER_PROPERTY_COUNT] =
-{
-  Property::BOOLEAN,    // "clipping-enable",
-  Property::RECTANGLE,  // "clipping-box",
+ // Name                     Type              writable animatable constraint-input
+ { "clipping-enable",     Property::BOOLEAN,    true,    false,   true  },  // CLIPPING_ENABLE
+ { "clipping-box",        Property::RECTANGLE,  true,    false,   true  },  // CLIPPING_BOX
 };
+const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( DEFAULT_PROPERTY_DETAILS[0] );
 
 } // unnamed namespace
 
@@ -111,22 +111,14 @@ Layer::Layer( Actor::DerivedType type )
   mClippingBox(0,0,0,0),
   mSortFunction(Dali::Layer::ZValue),
   mIsClipping(false),
-  mDepthTestDisabled(false)
+  mDepthTestDisabled(false),
+  mTouchConsumed(false),
+  mHoverConsumed(false)
 {
 }
 
 void Layer::OnInitialize()
 {
-  if(Layer::mFirstInstance)
-  {
-    mDefaultLayerPropertyLookup = new DefaultPropertyLookup();
-    const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
-    for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
-    {
-      (*mDefaultLayerPropertyLookup)[DEFAULT_LAYER_PROPERTY_NAMES[i]] = i + start;
-    }
-    Layer::mFirstInstance = false;
-  }
 }
 
 Layer::~Layer()
@@ -237,8 +229,12 @@ void Layer::SetClippingBox(int x, int y, int width, int height)
     // Clipping box is not animatable; this is the most up-to-date value
     mClippingBox.Set(x, y, width, height);
 
+    // Convert mClippingBox to GL based coordinates (from bottom-left)
+    ClippingBox clippingBox( mClippingBox );
+    clippingBox.y = mStage->GetSize().height - clippingBox.y - clippingBox.height;
+
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mClippingBox );
+    SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), clippingBox );
   }
 }
 
@@ -270,6 +266,26 @@ void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
   }
 }
 
+void Layer::SetTouchConsumed( bool consume )
+{
+  mTouchConsumed = consume;
+}
+
+bool Layer::IsTouchConsumed() const
+{
+  return mTouchConsumed;
+}
+
+void Layer::SetHoverConsumed( bool consume )
+{
+  mHoverConsumed = consume;
+}
+
+bool Layer::IsHoverConsumed() const
+{
+  return mHoverConsumed;
+}
+
 SceneGraph::Node* Layer::CreateNode() const
 {
   return SceneGraph::Layer::New();
@@ -336,7 +352,7 @@ bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
   }
   else
   {
-    return true;
+    return true; // all properties writable, no need to lookup the table
   }
 }
 
@@ -348,7 +364,7 @@ bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
   }
   else
   {
-    return false;
+    return false; // all properties non animateable, no need to lookup the table
   }
 }
 
@@ -358,7 +374,7 @@ bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
   {
     return Actor::IsDefaultPropertyAConstraintInput(index);
   }
-  return true; // our properties can be used as an input to a constraint
+  return true; // our properties can be used as an input to a constraint, no need to lookup the table
 }
 
 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
@@ -373,7 +389,7 @@ Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
 
     if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
     {
-      return DEFAULT_LAYER_PROPERTY_TYPES[index];
+      return DEFAULT_PROPERTY_DETAILS[index].type;
     }
     else
     {
@@ -383,8 +399,7 @@ Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
   }
 }
 
-
-const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
+const char* Layer::GetDefaultPropertyName( Property::Index index ) const
 {
   if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
   {
@@ -396,13 +411,11 @@ const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
 
     if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
     {
-      return DEFAULT_LAYER_PROPERTY_NAMES[index];
+      return DEFAULT_PROPERTY_DETAILS[index].name;
     }
     else
     {
-      // index out-of-bounds
-      static const std::string INVALID_PROPERTY_NAME;
-      return INVALID_PROPERTY_NAME;
+      return NULL;
     }
   }
 }
@@ -411,15 +424,17 @@ Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  DALI_ASSERT_DEBUG( NULL != mDefaultLayerPropertyLookup );
-
   // Look for name in current class' default properties
-  DefaultPropertyLookup::const_iterator result = mDefaultLayerPropertyLookup->find( name );
-  if ( mDefaultLayerPropertyLookup->end() != result )
+  for( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
   {
-    index = result->second;
+    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 + DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
+      break;
+    }
   }
-  else
+  if( Property::INVALID_INDEX == index )
   {
     // If not found, check in base class
     index = Actor::GetDefaultPropertyIndex( name );
@@ -440,12 +455,13 @@ void Layer::SetDefaultProperty( Property::Index index, const Property::Value& pr
     {
       case Dali::Layer::CLIPPING_ENABLE:
       {
-        mIsClipping = propertyValue.Get<bool>();
+        SetClipping( propertyValue.Get<bool>() );
         break;
       }
       case Dali::Layer::CLIPPING_BOX:
       {
-        mClippingBox = propertyValue.Get<Rect<int> >();
+        Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
+        SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
         break;
       }
       default:
@@ -490,29 +506,29 @@ Property::Value Layer::GetDefaultProperty( Property::Index index ) const
   return ret;
 }
 
-bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
+bool Layer::DoAction( BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes )
 {
   bool done = false;
-  Layer* layer = dynamic_cast<Layer*>(object);
+  Layer* layer = dynamic_cast<Layer*>( object );
 
-  if(layer)
+  if( layer )
   {
-    if(Dali::Layer::ACTION_RAISE == actionName)
+    if( 0 == strcmp( actionName.c_str(), ACTION_RAISE ) )
     {
       layer->Raise();
       done = true;
     }
-    else if(Dali::Layer::ACTION_LOWER == actionName)
+    else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER ) )
     {
       layer->Lower();
       done = true;
     }
-    else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
+    else if( 0 == strcmp( actionName.c_str(), ACTION_RAISE_TO_TOP ) )
     {
       layer->RaiseToTop();
       done = true;
     }
-    else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
+    else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER_TO_BOTTOM ) )
     {
       layer->LowerToBottom();
       done = true;