draw_shadowed
Mojo function 🡭
draw_shadowed
fn def draw_shadowed(mut dst: Canvas, layer: Canvas, x: Int, y: Int, shadow_color: Color, blur_radius: Float64, offset_x: Int, offset_y: Int)Composite layer onto dst at (x, y) with a blurred, tinted, offset copy of it underneath – a drop shadow, or (with offset_x = offset_y = 0) a soft glow.
Since a Mojo closure cannot capture a generic “draw my shape” call,
the caller renders their shape into layer themselves, onto a
transparent background, before calling this. draw_shadowed then:
- builds a shadow layer the same size as
layerplus padding (see_shadow_pad),layer’s alpha tinted toshadow_color(color replaced, alpha multiplied byshadow_color’s own alpha); - blurs the shadow layer by
blur_radius; - composites it onto
dstat(x + offset_x, y + offset_y), shifted back by the padding; - composites
layeritself ontodstat (x, y), unchanged, on top.
Both composites go through _composite_onto, so dst’s active
clip and blend mode apply to the shadow and the shape alike.
Args:
- dst (
Canvas): Canvas composited onto. - layer (
Canvas): The shape, already rendered onto a transparent background. Unchanged. - x (
Int): Destination column forlayer’s left edge. - y (
Int): Destination row forlayer’s top edge. - shadow_color (
Color): Color of the shadow/glow. - blur_radius (
Float64):blur()radius applied to the shadow layer. - offset_x (
Int): Horizontal shift of the shadow from the shape. - offset_y (
Int): Vertical shift of the shadow from the shape.
Raises:
Error: layer’s dimensions are negative once padded (does not
happen for a layer that was itself validly constructed).