Implemented a mesh renderer to display 3D objects from files.
[platform/core/uifw/dali-demo.git] / demo / dali-table-view.cpp
index 92f75e9..04cfaa3 100644 (file)
@@ -37,10 +37,10 @@ using namespace Dali::Toolkit;
 namespace
 {
 
-const std::string LOGO_PATH( DALI_IMAGE_DIR "Logo-for-demo.png" );
-const std::string DEFAULT_TOOLBAR_IMAGE_PATH( DALI_IMAGE_DIR "top-bar.png" );
-const std::string TILE_BACKGROUND(DALI_IMAGE_DIR "item-background.png");
-const std::string TILE_BACKGROUND_ALPHA(DALI_IMAGE_DIR "item-background-alpha.png");
+const std::string LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" );
+const std::string DEFAULT_TOOLBAR_IMAGE_PATH( DEMO_IMAGE_DIR "top-bar.png" );
+const std::string TILE_BACKGROUND(DEMO_IMAGE_DIR "item-background.9.png");
+const std::string TILE_BACKGROUND_ALPHA(DEMO_IMAGE_DIR "item-background-alpha.9.png");
 
 const char * const DEFAULT_TOOLBAR_TEXT( "TOUCH TO LAUNCH EXAMPLE" );
 
@@ -78,7 +78,6 @@ const float SCALE_SPEED_SIN = 0.1f;
 
 const unsigned int BACKGROUND_ANIMATION_DURATION = 15000; // 15 secs
 
-const float BACKGROUND_Z = -1.0f;
 const Vector4 BACKGROUND_COLOR( 0.3569f, 0.5451f, 0.7294f, 1.0f );
 
 const float BUBBLE_MIN_Z = -1.0;
@@ -100,12 +99,6 @@ Control CreateBackground( std::string stylename )
   return background;
 }
 
-// These values depend on the tile image
-const float IMAGE_BORDER_LEFT = 11.0f;
-const float IMAGE_BORDER_RIGHT = IMAGE_BORDER_LEFT;
-const float IMAGE_BORDER_TOP = IMAGE_BORDER_LEFT;
-const float IMAGE_BORDER_BOTTOM = IMAGE_BORDER_LEFT;
-
 /**
  * Constraint to return a position for a bubble based on the scroll value and vertical wrapping
  */
@@ -113,8 +106,8 @@ struct AnimateBubbleConstraint
 {
 public:
   AnimateBubbleConstraint( const Vector3& initialPos, float scale )
-      : mInitialX( initialPos.x ),
-        mScale( scale )
+  : mInitialX( initialPos.x ),
+    mScale( scale )
   {
   }
 
@@ -123,11 +116,10 @@ public:
     const Vector3& parentSize = inputs[1]->GetVector3();
     const Vector3& childSize = inputs[2]->GetVector3();
 
-    // Wrap bubbles verically.
-    if( position.y + childSize.y * 0.5f < -parentSize.y * 0.5f )
-    {
-      position.y = parentSize.y * 0.5f + childSize.y * 0.5f;
-    }
+    // Wrap bubbles vertically.
+    float range = parentSize.y + childSize.y;
+    // This performs a float mod (we don't use fmod as we want the arithmetic modulus as opposed to the remainder).
+    position.y -= range * ( floor( position.y / range ) + 0.5f );
 
     // Bubbles X position moves parallax to horizontal
     // panning by a scale factor unique to each bubble.
@@ -137,7 +129,6 @@ public:
 private:
   float mInitialX;
   float mScale;
-  float mShapeSize;
 };
 
 bool CompareByTitle( const Example& lhs, const Example& rhs )
@@ -250,7 +241,7 @@ void DaliTableView::Initialize( Application& application )
   mScrollView.SetAxisAutoLock( true );
   mScrollView.ScrollCompletedSignal().Connect( this, &DaliTableView::OnScrollComplete );
   mScrollView.ScrollStartedSignal().Connect( this, &DaliTableView::OnScrollStart );
-  mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched );
+  mScrollView.TouchSignal().Connect( this, &DaliTableView::OnScrollTouched );
 
   mScrollViewLayer = Layer::New();
 
@@ -261,14 +252,13 @@ void DaliTableView::Initialize( Application& application )
   mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
   // Create solid background colour.
-  ImageActor backgroundColourActor = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR );
+  Control backgroundColourActor = Control::New();
+  backgroundColourActor.SetBackgroundColor( BACKGROUND_COLOR );
   backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER );
   backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER );
   backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
   backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) );
 
-  // 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
@@ -276,7 +266,7 @@ void DaliTableView::Initialize( Application& application )
   bubbleContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   bubbleContainer.SetAnchorPoint( AnchorPoint::CENTER );
   bubbleContainer.SetParentOrigin( ParentOrigin::CENTER );
-  mScrollViewLayer.Add( bubbleContainer );
+  backgroundColourActor.Add( bubbleContainer );
 
   SetupBackground( bubbleContainer );
 
@@ -309,8 +299,6 @@ void DaliTableView::Initialize( Application& application )
   unsigned int degrees = 0;
   Rotate( degrees );
 
-  //orientation.ChangedSignal().Connect( this, &DaliTableView::OrientationChanged );
-
   winHandle.ShowIndicator( Dali::Window::INVISIBLE );
 
   // Background animation
@@ -425,11 +413,6 @@ void DaliTableView::Populate()
   mScrollView.SetRulerY( mScrollRulerY );
 }
 
-void DaliTableView::OrientationChanged( Orientation orientation )
-{
-  // TODO: Implement if orientation change required
-}
-
 void DaliTableView::Rotate( unsigned int degrees )
 {
   // Resize the root actor
@@ -465,21 +448,16 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
   // create background image
   if( addBackground )
   {
-    Image bg = ResourceImage::New( TILE_BACKGROUND );
-    ImageActor image = ImageActor::New( bg );
+    ImageView image = ImageView::New( TILE_BACKGROUND );
     image.SetAnchorPoint( AnchorPoint::CENTER );
     image.SetParentOrigin( ParentOrigin::CENTER );
     // make the image 100% of tile
     image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
-    // move image back to get text appear in front
-    image.SetZ( -1 );
-    image.SetStyle( ImageActor::STYLE_NINE_PATCH );
-    image.SetNinePatchBorder( Vector4( IMAGE_BORDER_LEFT, IMAGE_BORDER_TOP, IMAGE_BORDER_RIGHT, IMAGE_BORDER_BOTTOM ) );
     content.Add( image );
 
     // Add stencil
-    ImageActor stencil = NewStencilImage();
+    Toolkit::ImageView stencil = NewStencilImage();
     stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
     image.Add( stencil );
   }
@@ -498,36 +476,36 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
   content.SetKeyboardFocusable(true);
 
   // connect to the touch events
-  content.TouchedSignal().Connect( this, &DaliTableView::OnTilePressed );
+  content.TouchSignal().Connect( this, &DaliTableView::OnTilePressed );
   content.HoveredSignal().Connect( this, &DaliTableView::OnTileHovered );
 
   return content;
 }
 
-ImageActor DaliTableView::NewStencilImage()
+Toolkit::ImageView DaliTableView::NewStencilImage()
 {
-  Image alpha = ResourceImage::New( TILE_BACKGROUND_ALPHA );
+  Toolkit::ImageView stencil = ImageView::New( TILE_BACKGROUND_ALPHA );
 
-  ImageActor stencilActor = ImageActor::New( alpha );
-  stencilActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
-  stencilActor.SetNinePatchBorder( Vector4( IMAGE_BORDER_LEFT, IMAGE_BORDER_TOP, IMAGE_BORDER_RIGHT, IMAGE_BORDER_BOTTOM ) );
+  stencil.SetParentOrigin( ParentOrigin::CENTER );
+  stencil.SetAnchorPoint( AnchorPoint::CENTER );
+  stencil.SetDrawMode( DrawMode::STENCIL );
 
-  stencilActor.SetParentOrigin( ParentOrigin::CENTER );
-  stencilActor.SetAnchorPoint( AnchorPoint::CENTER );
-  stencilActor.SetDrawMode( DrawMode::STENCIL );
+  Property::Map shaderEffect = CreateAlphaDiscardEffect();
+  stencil.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderEffect );
 
-  Dali::ShaderEffect shaderEffect = CreateAlphaDiscardEffect();
-  stencilActor.SetShaderEffect( shaderEffect );
+  return stencil;
+}
 
-  return stencilActor;
+bool DaliTableView::OnTilePressed( Actor actor, const TouchData& event )
+{
+  return DoTilePress( actor, event.GetState( 0 ) );
 }
 
-bool DaliTableView::OnTilePressed( Actor actor, const TouchEvent& event )
+bool DaliTableView::DoTilePress( Actor actor, PointState::Type pointState )
 {
   bool consumed = false;
 
-  const TouchPoint& point = event.GetPoint( 0 );
-  if( TouchPoint::Down == point.state )
+  if( PointState::DOWN == pointState )
   {
     mPressedActor = actor;
     consumed = true;
@@ -535,7 +513,7 @@ bool DaliTableView::OnTilePressed( Actor actor, const TouchEvent& event )
 
   // A button press is only valid if the Down & Up events
   // both occurred within the button.
-  if( ( TouchPoint::Up == point.state ) &&
+  if( ( PointState::UP == pointState ) &&
       ( mPressedActor == actor ) )
   {
     // ignore Example button presses when scrolling or button animating.
@@ -580,7 +558,7 @@ void DaliTableView::OnPressedAnimationFinished( Dali::Animation& source )
     std::string name = mPressedActor.GetName();
 
     std::stringstream stream;
-    stream << DALI_EXAMPLE_BIN << name.c_str();
+    stream << DEMO_EXAMPLE_BIN << name.c_str();
     pid_t pid = fork();
     if( pid == 0)
     {
@@ -607,10 +585,9 @@ void DaliTableView::OnScrollComplete( const Dali::Vector2& position )
   accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) );
 }
 
-bool DaliTableView::OnScrollTouched( Actor actor, const TouchEvent& event )
+bool DaliTableView::OnScrollTouched( Actor actor, const TouchData& event )
 {
-  const TouchPoint& point = event.GetPoint( 0 );
-  if( TouchPoint::Down == point.state )
+  if( PointState::DOWN == event.GetState( 0 ) )
   {
     mPressedActor = actor;
   }
@@ -716,11 +693,12 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor )
     animConstraint.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) );
     animConstraint.AddSource( Dali::ParentSource( Dali::Actor::Property::SIZE ) );
     animConstraint.AddSource( Dali::LocalSource( Dali::Actor::Property::SIZE ) );
+    animConstraint.SetRemoveAction( Constraint::Discard );
     animConstraint.Apply();
 
     // Kickoff animation
-    Animation animation = Animation::New( Random::Range( 40.0f, 80.0f ) );
-    animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -1.0f, 0.0f ), AlphaFunction::LINEAR );
+    Animation animation = Animation::New( Random::Range( 30.0f, 160.0f ) );
+    animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -2000.0f, 0.0f ), AlphaFunction::LINEAR );
     animation.SetLooping( true );
     animation.Play();
     mBackgroundAnimations.push_back( animation );
@@ -732,18 +710,13 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis
   for( int i = 0; i < count; ++i )
   {
     float randSize = Random::Range( 10.0f, 400.0f );
-    ImageActor dfActor = ImageActor::New( distanceField );
+    ImageView dfActor = ImageView::New( distanceField );
     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 );
+    Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
+    dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, effect );
     dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );
-    effect.SetUniform("uOutlineParams", Vector2( 0.55f, 0.00f ) );
-    effect.SetUniform("uSmoothing", 0.5f );
     layer.Add( dfActor );
   }
 
@@ -931,9 +904,7 @@ void DaliTableView::OnFocusedActorActivated( Dali::Actor activatedActor )
     mPressedActor = activatedActor;
 
     // Activate the current focused actor;
-    TouchEvent touchEventUp;
-    touchEventUp.points.push_back( TouchPoint ( 0, TouchPoint::Up, 0.0f, 0.0f ) );
-    OnTilePressed(mPressedActor, touchEventUp);
+    DoTilePress( mPressedActor, PointState::UP );
   }
 }
 
@@ -958,11 +929,11 @@ void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap
       mVersionPopup = Dali::Toolkit::Popup::New();
 
       Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Version information" );
-      titleActor.SetName( "title-actor" );
+      titleActor.SetName( "titleActor" );
       titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
 
       Toolkit::TextLabel contentActor = Toolkit::TextLabel::New( stream.str() );
-      contentActor.SetName( "content-actor" );
+      contentActor.SetName( "contentActor" );
       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 ) );