The fill_premul
function fills the current shape in the Sdf2d
drawing context with a pre-multiplied RGBA color. It blends the provided color with the existing content and resets the internal shape and clipping parameters, preparing the context for subsequent drawing operations.
Sdf2d
instance where the fill operation is performed. The function modifies the result
, shape
, old_shape
, clip
, and has_clip
fields of self
in place.vec4
): A pre-multiplied RGBA color used to fill the shape.result
color after the fill operation, reflecting the blended color of the input and the existing content. The shape and clipping parameters are reset after this operation.In this example:
Sdf2d
context using the current position (self.pos
) scaled by self.rect_size
, which represents the size of the viewport.sdf.box
to draw a rectangle starting at position (10.0, 10.0)
with a width and height of 80.0
units and corner radius of 5.0
.fill_premul
to fill the rectangle with a semi-transparent red color. Since fill_premul
expects a pre-multiplied color, we multiply each RGB component by the alpha (0.5
), resulting in vec4(0.5, 0.0, 0.0, 0.5)
.fill_premul
, the shape and clipping parameters are reset, allowing you to start drawing new shapes without manually resetting the state.PI * 0.25
radians) around the point (50.0, 50.0)
, which is the center of the rectangle.sdf.result
, which contains the final rendered color after all drawing operations.fill_premul
is pre-multiplied, meaning each RGB component is multiplied by the alpha component. This is crucial for correct blending and transparency effects.fill_keep_premul
, the fill_premul
function resets the internal shape and clipping state after execution. This means you can define new shapes immediately after calling fill_premul
without manual resets.fill_premul
when you want to fill a shape and prepare the context for new drawing operations without preserving the current shape and clipping settings.rotate
, translate
, or scale
to manipulate the drawing context as needed. In this example, rotate
is used to rotate the entire drawing.fill_premul
resets the shape and clipping state, any shapes drawn before calling it will not affect subsequent drawing operations. Plan your drawing sequence accordingly.