Table of Contents

Class DrawingExtensions

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

Ways into a canvas from Egami's rasters and operation chains.

public static class DrawingExtensions
Inheritance
DrawingExtensions
Inherited Members

Examples

// Draw as a step in an operation chain: inside Within the canvas covers the area, with its origin at the area's corner.
raster.Apply(ops => ops
    .Draw(canvas => canvas.FillRect(new RectF(0, 0, 300, 200), new Rgba8(240, 240, 255, 255)))
    .Within(new Rect(100, 50, 100, 100), area => area.Draw(canvas => canvas.FillCircle(new Vector2(50, 50), 40, Rgba8.Red))),
    Ct);

// On an animation the step runs once per frame, and can be told which.
raster.Apply(ops => ops.Draw((canvas, frame) => canvas.FillCircle(new Vector2(20 + (frame * 4), 20), 10, Rgba8.Black)), Ct);

Methods

CreateCanvas<TPixel>(Raster<TPixel>, CanvasOptions?)

Creates a canvas that draws on a raster's first frame. Dispose it when done.

public static RasterCanvas<TPixel> CreateCanvas<TPixel>(this Raster<TPixel> raster, CanvasOptions? options = null) where TPixel : unmanaged, IPixelType<TPixel>

Parameters

raster Raster<TPixel>

The raster.

options CanvasOptions

The settings, or null for the defaults.

Returns

RasterCanvas<TPixel>

The canvas.

Type Parameters

TPixel

The raster's pixel type.

Examples

// A canvas draws onto a raster. Calls draw when they are made; dispose the canvas when done.
using Raster<Rgba8> raster = Raster.Create(400, 300, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
    canvas.FillRect(new RectF(20, 20, 160, 100), new Rgba8(30, 90, 200, 255));

    // Save and Restore bracket transform and clip changes.
    canvas.Save();
    canvas.Translate(260, 150);
    canvas.Rotate(30);
    canvas.FillRect(new RectF(-50, -30, 100, 60), new Rgba8(200, 60, 30, 200));
    canvas.Restore();

    canvas.FillCircle(new Vector2(100, 220), 50, Rgba8.Black);
}

// Blend edges in linear light, which keeps thin lines and translucent colors from darkening.
using RasterCanvas<Rgba8> linear = raster.CreateCanvas(new CanvasOptions { ColorSpace = ColorSpace.Linear });

Draw(RasterOps, Action<Canvas, int>, CanvasOptions?)

Adds a step that draws on each frame, passing the frame's index, for animations.

public static RasterOps Draw(this RasterOps operations, Action<Canvas, int> draw, CanvasOptions? options = null)

Parameters

operations RasterOps

The chain.

draw Action<Canvas, int>

The drawing, called once per frame with its index.

options CanvasOptions

The canvas settings, or null for the defaults.

Returns

RasterOps

The chain.

Examples

// Draw as a step in an operation chain: inside Within the canvas covers the area, with its origin at the area's corner.
raster.Apply(ops => ops
    .Draw(canvas => canvas.FillRect(new RectF(0, 0, 300, 200), new Rgba8(240, 240, 255, 255)))
    .Within(new Rect(100, 50, 100, 100), area => area.Draw(canvas => canvas.FillCircle(new Vector2(50, 50), 40, Rgba8.Red))),
    Ct);

// On an animation the step runs once per frame, and can be told which.
raster.Apply(ops => ops.Draw((canvas, frame) => canvas.FillCircle(new Vector2(20 + (frame * 4), 20), 10, Rgba8.Black)), Ct);

Draw(RasterOps, Action<Canvas>, CanvasOptions?)

Adds a step that draws on each frame with a canvas over the step's pixels. It keeps the image's size, so it composes with Within (the canvas then covers the area, with its origin at the area's corner), channel scopes and animations.

public static RasterOps Draw(this RasterOps operations, Action<Canvas> draw, CanvasOptions? options = null)

Parameters

operations RasterOps

The chain.

draw Action<Canvas>

The drawing, called once per frame.

options CanvasOptions

The canvas settings, or null for the defaults.

Returns

RasterOps

The chain.

Examples

// Draw as a step in an operation chain: inside Within the canvas covers the area, with its origin at the area's corner.
raster.Apply(ops => ops
    .Draw(canvas => canvas.FillRect(new RectF(0, 0, 300, 200), new Rgba8(240, 240, 255, 255)))
    .Within(new Rect(100, 50, 100, 100), area => area.Draw(canvas => canvas.FillCircle(new Vector2(50, 50), 40, Rgba8.Red))),
    Ct);

// On an animation the step runs once per frame, and can be told which.
raster.Apply(ops => ops.Draw((canvas, frame) => canvas.FillCircle(new Vector2(20 + (frame * 4), 20), 10, Rgba8.Black)), Ct);