Revert "[Tizen] Initialize 'mDepthTreeDirty' member in stage-impl.cpp"
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.cpp
index 2358018..905cfba 100644 (file)
 #include <dali/internal/event/common/object-registry-impl.h>
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/public-api/common/constants.h>
+#include <dali/public-api/events/touch-data.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 
 using Dali::Internal::SceneGraph::Node;
 
+namespace
+{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DEPTH_TIMER" );
+#endif
+}
+
 namespace Dali
 {
 
@@ -55,8 +63,10 @@ const float DEFAULT_STEREO_BASE( 65.0f );
 // Signals
 
 const char* const SIGNAL_KEY_EVENT =                 "keyEvent";
+const char* const SIGNAL_KEY_EVENT_GENERATED =       "keyEventGenerated";
 const char* const SIGNAL_EVENT_PROCESSING_FINISHED = "eventProcessingFinished";
 const char* const SIGNAL_TOUCHED =                   "touched";
+const char* const SIGNAL_TOUCH =                     "touch";
 const char* const SIGNAL_WHEEL_EVENT =               "wheelEvent";
 const char* const SIGNAL_CONTEXT_LOST =              "contextLost";
 const char* const SIGNAL_CONTEXT_REGAINED =          "contextRegained";
@@ -71,6 +81,8 @@ SignalConnectorType signalConnector4( mType, SIGNAL_WHEEL_EVENT,               &
 SignalConnectorType signalConnector5( mType, SIGNAL_CONTEXT_LOST,              &Stage::DoConnectSignal );
 SignalConnectorType signalConnector6( mType, SIGNAL_CONTEXT_REGAINED,          &Stage::DoConnectSignal );
 SignalConnectorType signalConnector7( mType, SIGNAL_SCENE_CREATED,             &Stage::DoConnectSignal );
+SignalConnectorType signalConnector8( mType, SIGNAL_KEY_EVENT_GENERATED,       &Stage::DoConnectSignal );
+SignalConnectorType signalConnector9( mType, SIGNAL_TOUCH,                     &Stage::DoConnectSignal );
 
 } // unnamed namespace
 
@@ -185,22 +197,29 @@ void Stage::Remove( Actor& actor )
   mRootLayer->Remove( actor );
 }
 
-void Stage::SetSize(float width, float height)
+void Stage::SurfaceResized(float width, float height)
 {
+  mSurfaceSize.width = width;
+  mSurfaceSize.height = height;
+
   // Internally we want to report the actual size of the stage.
-  mSize.width  = width;
-  mSize.height = height;
+  mSize.width = width;
+  mSize.height = height - mTopMargin;
 
   // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
-  mDefaultCamera->SetPerspectiveProjection( mSize );
+  mDefaultCamera->SetPerspectiveProjection( mSurfaceSize );
+
+  // Adjust the camera height to allow for top-margin
+  SetDefaultCameraPosition();
 
-  // The depth of the stage gets set to the maximun of these values
-  mRootLayer->SetSize( mSize );
+  mRootLayer->SetSize( mSize.width, mSize.height );
 
   // Repeat for SystemOverlay actors
   if( mSystemOverlay )
   {
-    mSystemOverlay->GetImpl()->SetSize( mSize.width, mSize.height );
+    // Note that the SystemOverlay has a separate camera, configured for the full surface-size.
+    // This will remain unaffected by changes in SetDefaultCameraPosition()
+    mSystemOverlay->GetImpl()->SetSize( width, height );
   }
 
   SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, width, height ) );
@@ -223,6 +242,23 @@ Vector2 Stage::GetSize() const
   return mSize;
 }
 
+void Stage::SetTopMargin( unsigned int margin )
+{
+  if (mTopMargin == margin)
+  {
+    return;
+  }
+  mTopMargin = margin;
+
+  mSize.width = mSurfaceSize.width;
+  mSize.height = mSurfaceSize.height - mTopMargin;
+
+  // Adjust the camera height to allow for top-margin
+  SetDefaultCameraPosition();
+
+  mRootLayer->SetSize( mSize.width, mSize.height );
+}
+
 RenderTaskList& Stage::GetRenderTaskList() const
 {
   return *mRenderTaskList;
@@ -238,6 +274,11 @@ void Stage::CreateDefaultCameraActor()
   Add(*(mDefaultCamera.Get()));
 }
 
+void Stage::SetDefaultCameraPosition()
+{
+  mDefaultCamera->SetY( -(static_cast<float>(mTopMargin) * 0.5f) );
+}
+
 Actor& Stage::GetDefaultRootActor()
 {
   return *mRootLayer;
@@ -411,7 +452,7 @@ void Stage::SetStereoBase( float stereoBase )
 {
   if( ! Equals( mStereoBase, stereoBase ) )
   {
-    DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)", mStereoBase, stereoBase );
+    DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)\n", mStereoBase, stereoBase );
     mStereoBase = stereoBase;
 
     switch( mViewMode  )
@@ -490,12 +531,16 @@ void Stage::KeepRendering( float durationSeconds )
 bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   bool connected( true );
-  Stage* stage = dynamic_cast<Stage*>(object);
+  Stage* stage = static_cast< Stage* >(object); // TypeRegistry guarantees that this is the correct type.
 
   if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
   {
     stage->KeyEventSignal().Connect( tracker, functor );
   }
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT_GENERATED ) )
+  {
+    stage->KeyEventGeneratedSignal().Connect( tracker, functor );
+  }
   else if( 0 == strcmp( signalName.c_str(), SIGNAL_EVENT_PROCESSING_FINISHED ) )
   {
     stage->EventProcessingFinishedSignal().Connect( tracker, functor );
@@ -504,6 +549,10 @@ bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra
   {
     stage->TouchedSignal().Connect( tracker, functor );
   }
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCH ) )
+  {
+    stage->TouchSignal().Connect( tracker, functor );
+  }
   else if( 0 == strcmp( signalName.c_str(), SIGNAL_WHEEL_EVENT ) )
   {
     stage->WheelEventSignal().Connect( tracker, functor );
@@ -536,14 +585,22 @@ void Stage::EmitKeyEventSignal(const KeyEvent& event)
   mKeyEventSignal.Emit( event );
 }
 
+bool Stage::EmitKeyEventGeneratedSignal(const KeyEvent& event)
+{
+  // Emit the KeyEventGenerated signal when KeyEvent is generated
+
+  return mKeyEventGeneratedSignal.Emit( event );
+}
+
 void Stage::EmitEventProcessingFinishedSignal()
 {
    mEventProcessingFinishedSignal.Emit();
 }
 
-void Stage::EmitTouchedSignal( const TouchEvent& touch )
+void Stage::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch )
 {
-  mTouchedSignal.Emit( touch );
+  mTouchedSignal.Emit( touchEvent );
+  mTouchSignal.Emit( touch );
 }
 
 void Stage::EmitWheelEventSignal(const WheelEvent& event)
@@ -563,6 +620,11 @@ Dali::Stage::KeyEventSignalType& Stage::KeyEventSignal()
   return mKeyEventSignal;
 }
 
+Dali::DevelStage::KeyEventGeneratedSignalType& Stage::KeyEventGeneratedSignal()
+{
+  return mKeyEventGeneratedSignal;
+}
+
 Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSignal()
 {
   return mEventProcessingFinishedSignal;
@@ -570,9 +632,15 @@ Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSi
 
 Dali::Stage::TouchedSignalType& Stage::TouchedSignal()
 {
+  DALI_LOG_WARNING( "Deprecated. Use TouchSignal() instead.\n" );
   return mTouchedSignal;
 }
 
+Dali::Stage::TouchSignalType& Stage::TouchSignal()
+{
+  return mTouchSignal;
+}
+
 Dali::Stage::WheelEventSignalType& Stage::WheelEventSignal()
 {
   return mWheelEventSignal;
@@ -603,6 +671,27 @@ void Stage::NotifyContextRegained()
   mContextRegainedSignal.Emit();
 }
 
+
+void Stage::RequestRebuildDepthTree()
+{
+  DALI_LOG_INFO(gLogFilter, Debug::General, "RequestRebuildDepthTree()\n");
+  mDepthTreeDirty = true;
+}
+
+void Stage::RebuildDepthTree()
+{
+  // If the depth tree needs rebuilding, do it in this frame only.
+  if( mDepthTreeDirty )
+  {
+    DALI_LOG_INFO(gLogFilter, Debug::Concise, "RebuildDepthTree() dirty:T\n");
+
+    ActorPtr actor( mRootLayer.Get() );
+    actor->RebuildDepthTree();
+    mDepthTreeDirty = false;
+  }
+}
+
+
 Stage::Stage( AnimationPlaylist& playlist,
               PropertyNotificationManager& propertyNotificationManager,
               SceneGraph::UpdateManager& updateManager,
@@ -615,6 +704,7 @@ Stage::Stage( AnimationPlaylist& playlist,
   mBackgroundColor(Dali::Stage::DEFAULT_BACKGROUND_COLOR),
   mViewMode( MONO ),
   mStereoBase( DEFAULT_STEREO_BASE ),
+  mTopMargin( 0 ),
   mSystemOverlay(NULL)
 {
 }