- 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::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;
- }