- // create background image
- if( addBackground )
- {
- 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 );
-
- content.Add( image );
-
- // Add stencil
- Toolkit::ImageView stencil = NewStencilImage();
- stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- image.Add( stencil );
- }
+ Toolkit::ImageView tileContent = ImageView::New();
+ tileContent.SetParentOrigin( ParentOrigin::CENTER );
+ 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.
+ 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 );
+ tileContent.SetColor( TILE_COLOR );
+
+ // We create a constraint to perform a precalculation on the scroll-view X offset
+ // and pass it to the shader uniform, along with the tile's position.
+ Constraint shaderPosition = Constraint::New < Vector3 > ( tileContent, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) );
+ shaderPosition.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) );
+ shaderPosition.SetRemoveAction( Constraint::Discard );
+ shaderPosition.Apply();
+ content.Add( tileContent );
+
+ // Create an ImageView for the 9-patch border around the tile.
+ ImageView image = ImageView::New( TILE_BACKGROUND );
+ image.SetAnchorPoint( AnchorPoint::CENTER );
+ image.SetParentOrigin( ParentOrigin::CENTER );
+ image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ image.SetOpacity( 0.8f );
+ tileContent.Add( image );