New Popup implementation
[platform/core/uifw/dali-demo.git] / demo / dali-table-view.cpp
index 392e582..990a787 100644 (file)
@@ -23,6 +23,8 @@
 #include <sstream>
 #include <unistd.h>
 #include <dali/devel-api/images/distance-field.h>
+#include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
+#include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
 
 // INTERNAL INCLUDES
 #include "shared/view.h"
@@ -86,10 +88,10 @@ const float BUBBLE_MAX_Z = 0.0f;
 /**
  * Creates the background image
  */
-ImageActor CreateBackground( std::string imagePath )
+ImageView CreateBackground( std::string imagePath )
 {
   Image image = ResourceImage::New( imagePath );
-  ImageActor background = ImageActor::New( image );
+  ImageView background = ImageView::New( image );
   background.SetName( "BACKGROUND" );
   background.SetAnchorPoint( AnchorPoint::CENTER );
   background.SetParentOrigin( ParentOrigin::CENTER );
@@ -151,7 +153,6 @@ DaliTableView::DaliTableView( Application& application )
   mBackgroundLayer(),
   mRootActor(),
   mRotateAnimation(),
-  mBackground(),
   mPressedAnimation(),
   mScrollViewLayer(),
   mScrollView(),
@@ -174,8 +175,7 @@ DaliTableView::DaliTableView( Application& application )
   mTotalPages(),
   mScrolling( false ),
   mSortAlphabetically( false ),
-  mBackgroundAnimsPlaying( false ),
-  mVersionPopupShown( false )
+  mBackgroundAnimsPlaying( false )
 {
   application.InitSignal().Connect( this, &DaliTableView::Initialize );
 }
@@ -202,14 +202,12 @@ void DaliTableView::SortAlphabetically( bool sortAlphabetically )
 
 void DaliTableView::Initialize( Application& application )
 {
-  DemoHelper::RequestThemeChange();
-
   Stage::GetCurrent().KeyEventSignal().Connect( this, &DaliTableView::OnKeyEvent );
 
   const Vector2 stageSize = Stage::GetCurrent().GetSize();
 
   // Background
-  Actor background = CreateBackground( mBackgroundImagePath );
+  ImageView background = CreateBackground( mBackgroundImagePath );
   Stage::GetCurrent().Add( background );
 
   // Render entire content as overlays, as is all on same 2D plane.
@@ -230,7 +228,7 @@ void DaliTableView::Initialize( Application& application )
   mRootActor.SetFitHeight( 0 );
 
   // Add logo
-  Dali::ImageActor logo = CreateLogo( LOGO_PATH );
+  ImageView logo = CreateLogo( LOGO_PATH );
   logo.SetName( "LOGO_IMAGE" );
   logo.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
   const float paddingHeight = ( ( 1.f-TABLE_RELATIVE_SIZE.y ) * stageSize.y );
@@ -268,9 +266,11 @@ void DaliTableView::Initialize( Application& application )
   mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched );
 
   mScrollViewLayer = Layer::New();
+
+  // Disable the depth test for performance
+  mScrollViewLayer.SetDepthTestDisabled( true );
   mScrollViewLayer.SetAnchorPoint( AnchorPoint::CENTER );
   mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER );
-  mScrollViewLayer.SetDrawMode( DrawMode::OVERLAY );
   mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
   // Create solid background colour.
@@ -279,7 +279,9 @@ void DaliTableView::Initialize( Application& application )
   backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER );
   backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
   backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) );
-  backgroundColourActor.SetZ( BACKGROUND_Z );
+
+  // Force the filled background right to the back
+  backgroundColourActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX );
   mScrollViewLayer.Add( backgroundColourActor );
 
   // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show
@@ -317,12 +319,10 @@ void DaliTableView::Initialize( Application& application )
   winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
 
   // Set initial orientation
-  Dali::Orientation orientation = winHandle.GetOrientation();
-
-  unsigned int degrees = winHandle.GetOrientation().GetDegrees();
+  unsigned int degrees = 0;
   Rotate( degrees );
 
-  orientation.ChangedSignal().Connect( this, &DaliTableView::OrientationChanged );
+  //orientation.ChangedSignal().Connect( this, &DaliTableView::OrientationChanged );
 
   winHandle.ShowIndicator( Dali::Window::INVISIBLE );
 
@@ -333,7 +333,8 @@ void DaliTableView::Initialize( Application& application )
   mBackgroundAnimsPlaying = true;
 
   KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
-  KeyboardFocusManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
+  KeyboardFocusManager::Get().FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
+  AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
 }
 
 void DaliTableView::ApplyCubeEffectToPages()
@@ -389,12 +390,12 @@ void DaliTableView::Populate()
           const Example& example = ( *iter );
 
           Actor tile = CreateTile( example.name, example.title, Vector3( tileParentMultiplier, tileParentMultiplier, 1.0f ), true );
-          FocusManager focusManager = FocusManager::Get();
-          focusManager.SetFocusOrder( tile, ++exampleCount );
-          focusManager.SetAccessibilityAttribute( tile, Dali::Toolkit::FocusManager::ACCESSIBILITY_LABEL,
+          AccessibilityManager accessibilityManager = AccessibilityManager::Get();
+          accessibilityManager.SetFocusOrder( tile, ++exampleCount );
+          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL,
                                                   example.title );
-          focusManager.SetAccessibilityAttribute( tile, Dali::Toolkit::FocusManager::ACCESSIBILITY_TRAIT, "Tile" );
-          focusManager.SetAccessibilityAttribute( tile, Dali::Toolkit::FocusManager::ACCESSIBILITY_HINT,
+          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile" );
+          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT,
                                                   "You can run this example" );
 
           tile.SetPadding( Padding( margin, margin, margin, margin ) );
@@ -553,7 +554,7 @@ bool DaliTableView::OnTilePressed( Actor actor, const TouchEvent& event )
     std::string name = actor.GetName();
     ExampleMapConstIter iter = mExampleMap.find( name );
 
-    FocusManager focusManager = FocusManager::Get();
+    AccessibilityManager accessibilityManager = AccessibilityManager::Get();
 
     if( iter != mExampleMap.end() )
     {
@@ -596,11 +597,11 @@ void DaliTableView::OnPressedAnimationFinished( Dali::Animation& source )
       if( name == BUTTON_QUIT )
       {
         // Move focus to the OK button
-        FocusManager focusManager = FocusManager::Get();
+        AccessibilityManager accessibilityManager = AccessibilityManager::Get();
 
         // Enable the group mode and wrap mode
-        focusManager.SetGroupMode( true );
-        focusManager.SetWrapMode( true );
+        accessibilityManager.SetGroupMode( true );
+        accessibilityManager.SetWrapMode( true );
       }
     }
     else
@@ -632,8 +633,8 @@ void DaliTableView::OnScrollComplete( const Dali::Vector2& position )
   mScrolling = false;
 
   // move focus to 1st item of new page
-  FocusManager focusManager = FocusManager::Get();
-  focusManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) );
+  AccessibilityManager accessibilityManager = AccessibilityManager::Get();
+  accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) );
 }
 
 bool DaliTableView::OnScrollTouched( Actor actor, const TouchEvent& event )
@@ -695,9 +696,11 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event )
   {
     if ( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
     {
-      if ( mVersionPopup && mVersionPopupShown )
+      // If there's a Popup, Hide it if it's contributing to the display in any way (EG. transitioning in or out).
+      // Otherwise quit.
+      if ( mVersionPopup && ( mVersionPopup.GetDisplayState() != Toolkit::Popup::HIDDEN ) )
       {
-        HideVersionPopup();
+        mVersionPopup.SetDisplayState( Popup::HIDDEN );
       }
       else
       {
@@ -766,6 +769,9 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis
     dfActor.SetSize( Vector2( randSize, randSize ) );
     dfActor.SetParentOrigin( ParentOrigin::CENTER );
 
+    // Force the bubbles just in front of the solid background
+    dfActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX + 1 );
+
     ShaderEffect effect = Toolkit::CreateDistanceFieldEffect();
     dfActor.SetShaderEffect( effect );
     dfActor.SetColor( randColour );
@@ -842,10 +848,10 @@ void DaliTableView::GenerateCircle( const Size& size, std::vector< unsigned char
   }
 }
 
-ImageActor DaliTableView::CreateLogo( std::string imagePath )
+ImageView DaliTableView::CreateLogo( std::string imagePath )
 {
   Image image = ResourceImage::New( imagePath );
-  ImageActor logo = ImageActor::New( image );
+  ImageView logo = ImageView::New( image );
 
   logo.SetAnchorPoint( AnchorPoint::CENTER );
   logo.SetParentOrigin( ParentOrigin::CENTER );
@@ -892,7 +898,7 @@ void DaliTableView::PlayAnimation()
   mAnimationTimer.SetInterval( BACKGROUND_ANIMATION_DURATION );
 }
 
-Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction )
+Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction )
 {
   Actor nextFocusActor = proposed;
 
@@ -907,22 +913,22 @@ Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::
     // in the given direction. We should work out which page to scroll to next.
     int currentPage = mScrollView.GetCurrentPage();
     int newPage = currentPage;
-    if( direction == Dali::Toolkit::Control::Left )
+    if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT )
     {
       newPage--;
     }
-    else if( direction == Dali::Toolkit::Control::Right )
+    else if( direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT )
     {
       newPage++;
     }
 
-    newPage = std::max(0, std::min(static_cast<int>(mScrollRulerX->GetTotalPages() - 1), newPage));
+    newPage = std::max(0, std::min(mTotalPages - 1, newPage));
     if( newPage == currentPage )
     {
-      if( direction == Dali::Toolkit::Control::Left )
+      if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT )
       {
-        newPage = mScrollRulerX->GetTotalPages() - 1;
-      } else if( direction == Dali::Toolkit::Control::Right )
+        newPage = mTotalPages - 1;
+      } else if( direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT )
       {
         newPage = 0;
       }
@@ -931,7 +937,7 @@ Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::
     // Scroll to the page in the given direction
     mScrollView.ScrollTo(newPage);
 
-    if( direction == Dali::Toolkit::Control::Left )
+    if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT )
     {
       // Work out the cell position for the last tile
       int remainingExamples = mExampleList.size() - newPage * EXAMPLES_PER_PAGE;
@@ -939,7 +945,7 @@ Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::
       int colPos = remainingExamples >= EXAMPLES_PER_PAGE ? EXAMPLES_PER_ROW - 1 : ( remainingExamples % EXAMPLES_PER_PAGE - rowPos * EXAMPLES_PER_ROW - 1 );
 
       // Move the focus to the last tile in the new page.
-      nextFocusActor = mPages[newPage].GetChildAt(colPos * EXAMPLES_PER_ROW + rowPos);
+      nextFocusActor = mPages[newPage].GetChildAt(rowPos * EXAMPLES_PER_ROW + colPos);
     }
     else
     {
@@ -972,44 +978,48 @@ bool DaliTableView::OnTileHovered( Actor actor, const HoverEvent& event )
 
 void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap )
 {
-  if ( !mVersionPopupShown )
+  // Only show if currently fully hidden. If transitioning-out, the transition will not be interrupted.
+  if ( !mVersionPopup || ( mVersionPopup.GetDisplayState() == Toolkit::Popup::HIDDEN ) )
   {
     if ( !mVersionPopup )
     {
       std::ostringstream stream;
-      stream << "DALi Core: "    << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")" << std::endl << std::endl;
-      stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")" << std::endl << std::endl;
-      stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")";
+      stream << "DALi Core: "    << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")\n";
+      stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")\n";
+      stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")\n";
 
       mVersionPopup = Dali::Toolkit::Popup::New();
-      mVersionPopup.SetParentOrigin( ParentOrigin::CENTER );
-      mVersionPopup.SetAnchorPoint( AnchorPoint::CENTER );
+
+      Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Version information" );
+      titleActor.SetName( "title-actor" );
+      titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+
+      Toolkit::TextLabel contentActor = Toolkit::TextLabel::New( stream.str() );
+      contentActor.SetName( "content-actor" );
+      contentActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+      contentActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+      contentActor.SetPadding( Padding( 0.0f, 0.0f, 20.0f, 0.0f ) );
+
+      mVersionPopup.SetTitle( titleActor );
+      mVersionPopup.SetContent( contentActor );
+
       mVersionPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
       mVersionPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
       mVersionPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
-      mVersionPopup.SetTitle( stream.str() );
-      mVersionPopup.HideTail();
+
       mVersionPopup.OutsideTouchedSignal().Connect( this, &DaliTableView::HideVersionPopup );
-      mVersionPopup.HiddenSignal().Connect( this, &DaliTableView::PopupHidden );
+      Stage::GetCurrent().Add( mVersionPopup );
     }
 
-    mVersionPopup.Show();
-    mVersionPopupShown = true;
+    mVersionPopup.SetDisplayState( Popup::SHOWN );
   }
 }
 
 void DaliTableView::HideVersionPopup()
 {
-  if ( mVersionPopup )
-  {
-    mVersionPopup.Hide();
-  }
-}
-
-void DaliTableView::PopupHidden()
-{
-  if ( mVersionPopup )
+  // Only hide if currently fully shown. If transitioning-in, the transition will not be interrupted.
+  if ( mVersionPopup && ( mVersionPopup.GetDisplayState() == Toolkit::Popup::SHOWN ) )
   {
-    mVersionPopupShown = false;
+    mVersionPopup.SetDisplayState( Popup::HIDDEN );
   }
 }