Class ShadowOptions
The light and colors of DrawShadow(Path, ShadowOptions?), after Skia's shadow model (the Material Design one): a shape lifted Elevation above the canvas casts an ambient shadow, blurred by its height, and a spot shadow from a round light at LightPosition, moved away from the light and blurred by the light's size.
public sealed record ShadowOptions : IEquatable<ShadowOptions>
- Inheritance
-
ShadowOptions
- Implements
- Inherited Members
Examples
using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
// A card floating 12 pixels up: its ambient and spot shadows, then the card itself.
RoundRect card = new(new RectF(60, 40, 180, 110), 10);
canvas.DrawShadow(Path.RoundRect(card), new ShadowOptions { Elevation = 12 });
canvas.FillRoundRect(card, Rgba8.White);
// A whole group's drop shadow: a layer with a drop shadow filter that keeps the layer's size.
canvas.SaveLayer(new LayerOptions { Filter = ops => ops.DropShadow(3, 4, 3, new Rgba8(0, 0, 0, 90), new DropShadowOptions { Expand = false }) });
canvas.FillCircle(new Vector2(110, 95), 20, new Rgba8(230, 80, 40, 255));
canvas.FillRect(new RectF(140, 80, 60, 30), new Rgba8(40, 120, 220, 255));
canvas.Restore();
}
Properties
AmbientColor
Gets the ambient shadow's color. Defaults to black at 3.9%, Material Design's ambient opacity.
public RgbaF32 AmbientColor { get; init; }
Property Value
Elevation
Gets how high above the canvas the shape is, in device pixels, from 0 to 10000. Defaults to 8.
public float Elevation { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 10000.
LightPosition
Gets the light's position in device pixels, z above the canvas, or null (the default) for a light above the canvas's top center at height 600, as Material Design places it.
public Vector3? LightPosition { get; init; }
Property Value
Exceptions
- ArgumentException
A coordinate is not finite, or z is not positive.
LightRadius
Gets the light's radius in device pixels: a larger light softens the spot shadow. Defaults to 800.
public float LightRadius { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not finite.
SpotColor
Gets the spot shadow's color. Defaults to black at 19%, Material Design's spot opacity.
public RgbaF32 SpotColor { get; init; }
Property Value
Transparent
Gets a value indicating whether the shape is see-through, so the shadow under it is drawn too; when false (the default) the shadow is left out where the shape covers it, as Skia does for an opaque occluder.
public bool Transparent { get; init; }