-/**
- * Structure which holds information about the background of a control
- */
-struct Background
-{
- Actor actor; ///< Background actor
- Vector4 color; ///< The color of the actor.
-
- /**
- * Constructor
- */
- Background()
- : actor(),
- color( Color::WHITE )
- {
- }
-};
-
-unsigned int gQuadIndex[6] = { 0, 2, 1, 1, 2, 3 };
-
-Vector2 gQuad[] = {
- Vector2( -0.5f, -0.5f ),
- Vector2( 0.5f, -0.5f ),
- Vector2( -0.5f, 0.5f ),
- Vector2( 0.5f, 0.5f )
-};
-
-
-const char* VERTEX_SHADER_COLOR = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- uniform mediump mat4 uMvpMatrix;\n
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4( aPosition, 0.0, 1.0 );\n
- }\n
-);
-
-const char* FRAGMENT_SHADER_COLOR = DALI_COMPOSE_SHADER(
- uniform lowp vec4 uBackgroundColor;\n
- uniform lowp vec4 uColor;\n
- void main()\n
- {\n
- gl_FragColor = uBackgroundColor * uColor;\n
- }\n
-);
-
-
-/**
- * @brief Create the background actor for the control.
- *
- * @param[in] actor The parent actor of the background
- * @param[in] color The background color
- * @param[in] image If a valid image is supplied this will be the texture used by the background
- *
- * @return An actor which will render the background
- *
- */
-Actor CreateBackground( Actor parent, const Vector4& color, Image image = Image() )
-{
- if( !image )
- {
- PropertyBuffer vertexBuffer;
- Shader shader;
- Material material;
-
- Property::Map vertexFormat;
- vertexFormat["aPosition"] = Property::VECTOR2;
-
- //Create a vertex buffer for vertex positions
- vertexBuffer = PropertyBuffer::New( vertexFormat, 4u );
- vertexBuffer.SetData( gQuad );
-
- shader = Shader::New( VERTEX_SHADER_COLOR, FRAGMENT_SHADER_COLOR );
- material = Material::New( shader );
-
- //Create the index buffer
- Property::Map indexFormat;
- indexFormat["indices"] = Property::UNSIGNED_INTEGER;
- PropertyBuffer indexBuffer = PropertyBuffer::New( indexFormat, 6u );
- indexBuffer.SetData(gQuadIndex);
-
- //Create the geometry
- Geometry mesh = Geometry::New();
- mesh.AddVertexBuffer( vertexBuffer );
- mesh.SetIndexBuffer( indexBuffer );
-
- //Add uniforms to the shader
- shader.RegisterProperty( "uBackgroundColor", color );
-
- //Create the renderer
- Renderer renderer = Renderer::New( mesh, material );
- renderer.SetDepthIndex( parent.GetHierarchyDepth() + BACKGROUND_DEPTH_INDEX );
-
- //Create the actor
- Actor meshActor = Actor::New();
- meshActor.SetSize( Vector3::ONE );
- meshActor.AddRenderer( renderer );
- meshActor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
- meshActor.SetColorMode( USE_PARENT_COLOR );
-
- //Constraint scale of the mesh actor to the size of the control
- Constraint constraint = Constraint::New<Vector3>( meshActor,
- Actor::Property::SCALE,
- EqualToConstraint() );
- constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
- constraint.Apply();
-
- return meshActor;
- }
- else
- {
- ImageActor imageActor = ImageActor::New( image );
- imageActor.SetColor( color );
- imageActor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
- imageActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
- imageActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- imageActor.SetSortModifier( parent.GetHierarchyDepth() + BACKGROUND_DEPTH_INDEX );
-
- return imageActor;
- }
-
-}