Canvas

A 2D Canvas able to render complex pathes into an ImageRef!RGBA buffer. Canvas tries to follow loosely the HTML 5 Canvas API.

struct Canvas {}

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

getTransform
alias getTransform = currentTransform
Undocumented in source.

Functions

arc
void arc(float x, float y, float radius, float startAngle, float endAngle, bool anticlockwise)
void arc(vec2f center, float radius, float startAngle, float endAngle, bool anticlockwise)

Adds an arc to the current path (used to create circles, or parts of circles).

beginPath
void beginPath()

Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.

bezierCurveTo
void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)
void bezierCurveTo(vec2f controlPoint1, vec2f controlPoint2, vec2f dest)

Adds a cubic Bezier curve to the current path.

closePath
void closePath()

Adds a straight line to the path, going to the start of the current sub-path.

createCircularGradient
CanvasGradient createCircularGradient(float centerX, float centerY, float endRadius)
CanvasGradient createCircularGradient(vec2f center, float endRadius)

Creates a circular gradient, centered in (x, y) and going from 0 to endRadius.

createEllipticalGradient
CanvasGradient createEllipticalGradient(float x0, float y0, float x1, float y1, float r2)
CanvasGradient createEllipticalGradient(vec2f pt0, vec2f pt1, float r2)

Creates an elliptical gradient. First radius is given by (x1, y1), second radius with a radius at 90° with the first one).

createLinearGradient
CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1)
CanvasGradient createLinearGradient(vec2f pt0, vec2f pt1)

Creates a linear gradient along the line given by the coordinates represented by the parameters.

currentTransform
Transform2D currentTransform()

Retrieves the current transformation matrix.

fill
void fill()

Fills all subpaths of the current path using the current fillStyle. Open subpaths are implicitly closed when being filled.

fillCircle
void fillCircle(float x, float y, float radius)
void fillCircle(vec2f center, float radius)

Fill a disc using the current fillStyle. Note: affects the current path.

fillRect
void fillRect(float x, float y, float width, float height)
void fillRect(vec2f topLeft, vec2f dimension)
void fillRect(box2f rect)
void fillRect(box2i rect)

Fill a rectangle using the current fillStyle. Note: affects the current path.

fillRule
void fillRule(FillRule rule)

Set current fill rule.

fillRule
FillRule fillRule()

Get current fill rule.

fillStyle
void fillStyle(RGBA color)
void fillStyle(Color col)
void fillStyle(const(char)[] htmlColorString)
void fillStyle(CanvasGradient gradient)

Set the fill style. The fill style can be a plain color fill, a CanvasGradient, or an HTML-compatible text string.

globalCompositeOperation
void globalCompositeOperation(CompositeOperation op)

Set global composite operation.

globalCompositeOperation
CompositeOperation globalCompositeOperation()

Get global composite operation.

initialize
void initialize(ImageRef!RGBA imageDest)

Initialize the Canvas object with this target.

lineTo
void lineTo(float x, float y)
void lineTo(vec2f point)
void lineTo(vec2f[] points)

Connects the last point in the current sub-path to the specified (x, y) coordinates with a straight line. If several points are provided, it is equivalent to consecutive single-point lineTo calls.

moveTo
void moveTo(float x, float y)
void moveTo(vec2f point)

Moves the starting point of a new sub-path to the (x, y) coordinates.

quadraticCurveTo
void quadraticCurveTo(float cpx, float cpy, float x, float y)
void quadraticCurveTo(vec2f controlPoint, vec2f dest)

Adds a quadratic Bézier curve to the current path.

rect
void rect(float x, float y, float width, float height)
void rect(vec2f topLeftPoint, vec2f dimension)
void rect(box2f rectangle)
void rect(box2i rectangle)

Add a rect to the current path.

resetTransform
void resetTransform()

Changes the current transformation matrix to the identity matrix.

restore
void restore()

Restores state corresponding to save().

rotate
void rotate(float angle)

Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.

save
void save()

Save: - current transform

scale
void scale(float x, float y)
void scale(vec2f xy)
void scale(float xy)

Adds a scaling transformation to the canvas units by x horizontally and by y vertically.

setTransform
void setTransform(float a, float b, float c, float d, float e, float f)
Undocumented in source. Be warned that the author may not have intended to support it.
setTransform
void setTransform(Transform2D transform)

Multiplies the current transformation matrix with the matrix described by its arguments.

transform
void transform(float a, float b, float c, float d, float e, float f)

Multiplies the current transformation matrix with the matrix described by its arguments.

translate
void translate(float x, float y)
void translate(vec2f position)

Adds a translation transformation by moving the canvas and its origin x horizontally and y vertically on the grid.

See Also

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement

Important: * Only works on RGBA output. * There need at least 12 extra bytes between lines (trailingSamples = 3 in OwnedImage). You can use OwnedImage to have that guarantee. See https://github.com/AuburnSounds/Dplug/issues/563 For now, avoid full-UI controls that use a Canvas.

Meta