Using brushes
Brushes are graphics objects that describe how 2D content is drawn. For example, with brushes you can define the color of text in a Text Block 2D node, fill a background of a 2D node with an image pattern, or apply a material effect of 2D content.
Usually 2D components have a foreground and a background. With brushes you can change the appearance of both. In Kanzi you can use these brushes:
Kanzi Studio stores brushes in the Library > Materials and Textures > Brushes.
Creating color brushes
Use a Color Brush to fill 2D content with a solid color.
To create and use a color brush:
- In the Library press Alt and right-click Materials and Textures and select Color Brush.

- In the Properties set the Brush Color property to the color you want to use to paint the background of a 2D node.

- In the Project select the 2D node the background of which you want to paint with that brush, in the Properties add the Background Brush property, and select the brush you created in the first step. See Adjusting the appearance of 2D nodes with a solid color.
Tip To quickly edit a brush, in the Properties next to the Background Brush or Foreground Brush property click
and edit the brush.

Creating texture brushes
Use a Texture Brush to fill a 2D area with a texture.
To create and use a texture brush:
- In the Library press Alt and right-click Materials and Textures and select Texture Brush.

- In the Properties set the Brush Texture property to the texture you want to use to paint the background of a 2D node.

- In the Project select the 2D node the background of which you want to paint with that brush, in the Properties add the Background Brush property, and select the brush you created in the first step. See Adjusting the appearance of 2D nodes with a texture.
Tip To quickly edit a brush, in the Properties next to the Background Brush or Foreground Brush property click
and edit the brush.

Creating material brushes
Use a Material Brush to apply a material to 2D content.
To create and use a material brush:
- In the Library press Alt and right-click Materials and Textures and select Material Brush.

- In the Properties set the Material property to the material you want to use to paint the background of a 2D node.
If you do not have any materials in your project, create a material. See Using materials.

- In the Project select the 2D node the background of which you want to paint with that brush, in the Properties add the Background Brush property, and select the brush you created in the first step. See Applying custom rendering to 2D nodes.
Tip To quickly edit a brush, in the Properties next to the Background Brush or Foreground Brush property click
and edit the brush.

Setting the color of text in a Text Block 2D node
To set the color of text in a Text Block 2D node:
- In the Project create or select a Text Block 2D node.

- In the Properties add the Foreground Brush property.

- Set the Foreground Brush property to an existing Color Brush or select + Color Brush, click
next to the property, and set the color of the Color Brush you created.

Adjusting the appearance of 2D nodes with a solid color
Use a Color Brush to fill 2D content with a solid color.
To adjust the appearance of 2D nodes with a solid color:
- In the Project window select or create the 2D node the appearance of which you want to adjust.
For example, in the Project window press Alt and right-click the Viewport 2D node and create a Text Block 2D node.

- In the Properties add the Background Brush property.
You adjust the look and behavior of nodes in your project with properties. See Property system.

- In the Properties open the Background Brush property dropdown menu and select + Color Brush.

- In the Properties next to the Background Brush property click
and set the color of the color brush you created in the previous step.
In the Properties click
next to a property to access and edit the resource to which the property points without moving away from the currently selected node.
In the Preview window you can see that the Color Brush you created paints the background of the node for which you set the Background Brush property.

Adjusting the appearance of 2D nodes with a texture
Use a Texture Brush to fill a 2D area with a texture.
To adjust the appearance of 2D nodes with a texture:
- In the Library window press Alt and right-clickMaterials and Textures and select Texture Brush.
The Library window shows all resources, such as animations, materials, textures, brushes, and fonts. Here you can create, import, and edit resources in your project.

- In the Project select the 2D node the appearance of which you want to adjust, in the Properties add the Background Brush property, and select the brush you created in the first step.
For example, create a Text Block 2D node, in the Properties add the Background Brush property and set it to the brush you created in the first step.
- In the Properties window click
next to the Background Brush property to go the brush used by that property, set the texture you want this texture brush to use, and adjust how the Texture Brush uses that texture:- Brush Modulate Color sets the modulation color for the brush.
- Brush Horizontal Tiling affects the scale of the texture coordinates to set the horizontal tiling of the texture.
- Brush Vertical Tiling affects the scale of the texture coordinates to set the vertical tiling of the texture.
- Brush Texture sets the texture for the brush.

Applying custom rendering to 2D nodes
To apply custom rendering to a 2D node:
- Create a Material Type that defines the material with which you want to apply to a material. For example, to create a Material Type that converts color to grayscale:
- In the Library press Alt and right-click Materials and Textures and select Material Type.

- In the Library > Materials and Textures expand the material type you created, open the Vertex Shader, replace the existing shader code with this code, and save the shader.
attribute vec3 kzPosition;
attribute vec2 kzTextureCoordinate0;
uniform highp mat4 kzProjectionCameraWorldMatrix;
varying mediump vec2 vTexCoord;
void main()
{
precision mediump float;
vTexCoord = kzTextureCoordinate0;
gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
} - Open the Fragment Shader, replace the existing shader code with this code, and save the shader.
uniform sampler2D ContentTexture;
varying mediump vec2 vTexCoord;
void main()
{
precision mediump float;
// Use this algorithm to convert the colors in the texture used by
// the Image node to grayscale.
float grayscale = dot(texture2D(ContentTexture, vTexCoord).rgb, vec3(0.21, 0.72, 0.07));
gl_FragColor = vec4(grayscale, grayscale, grayscale, 1.0);
}
- Create a material and set it to use the material type you created in the previous step:
- In the Library press Alt and right-click Materials and Textures and select Material.

- In the Properties set the Material Type property to the material type you created in the previous step.

- In the Library press Alt and right-click Materials and Textures, select Material Brush, and set it to use the material you created in the previous step.

- In the Project create or select the 2D node to which you want to apply the material you created.
For example, create an Image node and set it to display an image.

- In the Properties add and set the Foreground Brush property of the node to the material brush that uses the material you want to apply to that node.

Setting the background of a 2D node
Use brushes to set the background of 2D nodes. In Kanzi all 2D nodes by default have transparent background.
To set the background:
- Create a Color Brush, a Texture Brush, or a Material Brush. See Using brushes.

- In the Project select the 2D node the background of which you want to paint.
Note that you can set only the background of 2D nodes.
- In the Properties add the Background Brush property and select the brush you created in the first step.

See also
Textures
Material types and materials
Open topic with navigation