Commit 68db592bf9ddb45bc541e8ff4b137f3521019dd2

Authored by Nick Holland
1 parent 0a75ccea

Create ImageView with shader and Image at the same time

Change-Id: If22c12af7072927646e60ee320bd4e58f0702cb7
demo/dali-table-view.cpp
... ... @@ -108,7 +108,6 @@ const float BUBBLE_MAX_Z = 0.0f;
108 108 // The shader uses the tiles position within the scroll-view page and the scroll-views rotation position to create a parallax effect.
109 109 const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
110 110 varying mediump vec2 vTexCoord;
111   - varying mediump vec3 vIllumination;
112 111 uniform lowp vec4 uColor;
113 112 uniform sampler2D sTexture;
114 113 uniform mediump vec3 uCustomPosition;
... ... @@ -266,7 +265,7 @@ void DaliTableView::Initialize( Application& application )
266 265 Stage::GetCurrent().Add( mRootActor );
267 266  
268 267 // Add logo
269   - ImageView logo = CreateLogo( LOGO_PATH );
  268 + ImageView logo = ImageView::New( LOGO_PATH );
270 269 logo.SetName( "LOGO_IMAGE" );
271 270 logo.SetAnchorPoint( AnchorPoint::TOP_CENTER );
272 271 logo.SetParentOrigin( Vector3( 0.5f, 0.1f, 0.5f ) );
... ... @@ -517,18 +516,20 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
517 516 tileContent.SetAnchorPoint( AnchorPoint::CENTER );
518 517 tileContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
519 518  
520   - // Add the image via the property first.
521   - tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, TILE_BACKGROUND_ALPHA );
522   - // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
  519 + // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
523 520 Property::Value value = Vector3( 0.0f, 0.0f, 0.0f );
524 521 Property::Index propertyIndex = tileContent.RegisterProperty( "uCustomPosition", value );
525 522  
526 523 // Add a shader to the image (details in shader source).
527   - Property::Map map;
528 524 Property::Map customShader;
529 525 customShader[ Visual::Shader::Property::FRAGMENT_SHADER ] = FRAGMENT_SHADER_TEXTURED;
530   - map[ Visual::Property::SHADER ] = customShader;
531   - tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
  526 +
  527 + // Set the Image URL and the custom shader
  528 + Property::Map imageMap;
  529 + imageMap.Add( ImageVisual::Property::URL, TILE_BACKGROUND_ALPHA );
  530 + imageMap.Add( Visual::Property::SHADER, customShader );
  531 + tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
  532 +
532 533 tileContent.SetColor( TILE_COLOR );
533 534  
534 535 // 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 )
782 783 {
783 784 float randSize = Random::Range( 10.0f, 400.0f );
784 785 int shapeType = static_cast<int>( Random::Range( 0.0f, NUMBER_OF_SHAPE_IMAGES - 1 ) + 0.5f );
785   - ImageView dfActor = ImageView::New( SHAPE_IMAGE_TABLE[ shapeType ] );
  786 +
  787 + ImageView dfActor = ImageView::New();
786 788 dfActor.SetSize( Vector2( randSize, randSize ) );
787 789 dfActor.SetParentOrigin( ParentOrigin::CENTER );
788 790  
  791 + // Set the Image URL and the custom shader at the same time
789 792 Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
790   - dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, effect );
  793 + Property::Map imageMap;
  794 + imageMap.Add( ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[ shapeType ] );
  795 + imageMap.Add( Visual::Property::SHADER, effect );
  796 + dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
  797 +
791 798 dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );
792 799  
793 800 layer.Add( dfActor );
... ... @@ -797,16 +804,6 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count )
797 804 layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors );
798 805 }
799 806  
800   -ImageView DaliTableView::CreateLogo( std::string imagePath )
801   -{
802   - ImageView logo = ImageView::New( imagePath );
803   -
804   - logo.SetAnchorPoint( AnchorPoint::CENTER );
805   - logo.SetParentOrigin( ParentOrigin::CENTER );
806   -
807   - return logo;
808   -}
809   -
810 807 bool DaliTableView::PauseBackgroundAnimation()
811 808 {
812 809 PauseAnimation();
... ...
demo/dali-table-view.h
... ... @@ -266,15 +266,6 @@ private: // Application callbacks &amp; implementation
266 266 void AddBackgroundActors( Dali::Actor layer, int count );
267 267  
268 268 /**
269   - * Creates the logo.
270   - *
271   - * @param[in] imagePath The path to the image file to load
272   - *
273   - * @return The created image actor
274   - */
275   - Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
276   -
277   - /**
278 269 * Timer handler for ending background animation
279 270 *
280 271 * @return Return value for timer handler
... ...