Create ImageView with shader and Image at the same time 61/113461/2
authorNick Holland <nick.holland@partner.samsung.com>
Tue, 7 Feb 2017 16:08:45 +0000 (16:08 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Tue, 7 Feb 2017 16:13:26 +0000 (08:13 -0800)
Change-Id: If22c12af7072927646e60ee320bd4e58f0702cb7

demo/dali-table-view.cpp
demo/dali-table-view.h

index 67b9232..6791aaa 100644 (file)
@@ -108,7 +108,6 @@ const float BUBBLE_MAX_Z = 0.0f;
 // The shader uses the tiles position within the scroll-view page and the scroll-views rotation position to create a parallax effect.
 const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
   varying mediump vec2  vTexCoord;
-  varying mediump vec3  vIllumination;
   uniform lowp    vec4  uColor;
   uniform sampler2D     sTexture;
   uniform mediump vec3  uCustomPosition;
@@ -266,7 +265,7 @@ void DaliTableView::Initialize( Application& application )
   Stage::GetCurrent().Add( mRootActor );
 
   // Add logo
-  ImageView logo = CreateLogo( LOGO_PATH );
+  ImageView logo = ImageView::New( LOGO_PATH );
   logo.SetName( "LOGO_IMAGE" );
   logo.SetAnchorPoint( AnchorPoint::TOP_CENTER );
   logo.SetParentOrigin( Vector3( 0.5f, 0.1f, 0.5f ) );
@@ -517,18 +516,20 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
   tileContent.SetAnchorPoint( AnchorPoint::CENTER );
   tileContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
-  // Add the image via the property first.
-  tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, TILE_BACKGROUND_ALPHA );
-  // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
+ // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
   Property::Value value = Vector3( 0.0f, 0.0f, 0.0f );
   Property::Index propertyIndex = tileContent.RegisterProperty( "uCustomPosition", value );
 
   // Add a shader to the image (details in shader source).
-  Property::Map map;
   Property::Map customShader;
   customShader[ Visual::Shader::Property::FRAGMENT_SHADER ] = FRAGMENT_SHADER_TEXTURED;
-  map[ Visual::Property::SHADER ] = customShader;
-  tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
+
+  // Set the Image URL and the custom shader
+  Property::Map imageMap;
+  imageMap.Add( ImageVisual::Property::URL, TILE_BACKGROUND_ALPHA );
+  imageMap.Add( Visual::Property::SHADER, customShader );
+  tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
+
   tileContent.SetColor( TILE_COLOR );
 
   // We create a constraint to perform a precalculation on the scroll-view X offset
@@ -782,12 +783,18 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count )
   {
     float randSize = Random::Range( 10.0f, 400.0f );
     int shapeType = static_cast<int>( Random::Range( 0.0f, NUMBER_OF_SHAPE_IMAGES - 1 ) + 0.5f );
-    ImageView dfActor = ImageView::New( SHAPE_IMAGE_TABLE[ shapeType ] );
+
+    ImageView dfActor = ImageView::New();
     dfActor.SetSize( Vector2( randSize, randSize ) );
     dfActor.SetParentOrigin( ParentOrigin::CENTER );
 
+    // Set the Image URL and the custom shader at the same time
     Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
-    dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, effect );
+    Property::Map imageMap;
+    imageMap.Add( ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[ shapeType ] );
+    imageMap.Add( Visual::Property::SHADER, effect );
+    dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
+
     dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );
 
     layer.Add( dfActor );
@@ -797,16 +804,6 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count )
   layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors );
 }
 
-ImageView DaliTableView::CreateLogo( std::string imagePath )
-{
-  ImageView logo = ImageView::New( imagePath );
-
-  logo.SetAnchorPoint( AnchorPoint::CENTER );
-  logo.SetParentOrigin( ParentOrigin::CENTER );
-
-  return logo;
-}
-
 bool DaliTableView::PauseBackgroundAnimation()
 {
   PauseAnimation();
index c7cf0ab..099636c 100644 (file)
@@ -266,15 +266,6 @@ private: // Application callbacks & implementation
   void AddBackgroundActors( Dali::Actor layer, int count );
 
   /**
-   * Creates the logo.
-   *
-   * @param[in] imagePath The path to the image file to load
-   *
-   * @return The created image actor
-   */
-  Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
-
-  /**
    * Timer handler for ending background animation
    *
    * @return Return value for timer handler