[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.19.8 Gradient object

The Gradient object lets you make some fairly sophisticated gradients. These can then be used to texture a widget, or a part of a widget using masking. There are currently only five different kinds of gradients supported. Also, it should be realized that using a gradient is more of an art than a science. Things can get complex in a hurry.

The basic pattern behind using a gradient is to create a new Gradient object, and then add colors to it.

 
gr = new Gradient();
    			
gr.AddColor(new Color(1,1,1,1), 0.0);	
gr.AddColor(new Color(1,1,1,1), 0.1);	
gr.AddColor(new Color(0.6,0.6,0.6,1), 0.5);					
gr.AddColor(new Color(0.4,0.4,0.4,1), 0.51);				
gr.AddColor(new Color(0.7, 0.7, 0.7, 1), 0.9);
gr.AddColor(new Color(0.0, 0.0, 0.0, 1), 1.0);

Once you are done creating your gradient, it has to be rendered into a texture to actually be useful.

 
gr.Render(tex, Gradient.VERTICAL);

For horizontal and vertical gradients, it's best to create a texture that is 1 pixel wide and N pixels high, or vice versa, and then using that to texture your shape. Other gradients require you to create a full width and height texture.

The following table lists all possible gradient types:

HORIZONTAL

The gradient starts at the left and runs to the right.

VERTICAL

The gradient starts at the top and runs to the bottom.

RADIAL

The gradient starts in the center and runs to the edges in all directions.

LDIAG

The gradient starts in the upper left corner and runs to the bottom right corner.

RDIAG

The gradient starts in the upper right corner and runs to the bottom left corner.

The following methods are supported:

AddColor(color_object, position)

Adds the given color at the given position. The position must be between 0.0 and 1.0. Colors will be sorted automatically, so they don't have to be added in order.

Render(texture, gradient_constant)

Renders the gradient to the given Texture object. Whatever was in the texture is overwritten.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.