Documentation ¶
Overview ¶
Package canvas provides an API that tries to closely mirror that of the HTML5 canvas API, using OpenGL to do the rendering.
Index ¶
- Constants
- Variables
- type Canvas
- func (cv *Canvas) Arc(x, y, radius, startAngle, endAngle float64, anticlockwise bool)
- func (cv *Canvas) ArcTo(x1, y1, x2, y2, radius float64)
- func (cv *Canvas) BeginPath()
- func (cv *Canvas) BezierCurveTo(x1, y1, x2, y2, x3, y3 float64)
- func (cv *Canvas) ClearRect(x, y, w, h float64)
- func (cv *Canvas) Clip()
- func (cv *Canvas) ClosePath()
- func (cv *Canvas) CreateLinearGradient(x0, y0, x1, y1 float64) *LinearGradient
- func (cv *Canvas) CreatePattern(src interface{}, repeat imagePatternRepeat) *ImagePattern
- func (cv *Canvas) CreateRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient
- func (cv *Canvas) DrawImage(image interface{}, coords ...float64)
- func (cv *Canvas) Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, ...)
- func (cv *Canvas) Fill()
- func (cv *Canvas) FillPath(path *Path2D)
- func (cv *Canvas) FillRect(x, y, w, h float64)
- func (cv *Canvas) FillText(str string, x, y float64)
- func (cv *Canvas) GetImageData(x, y, w, h int) *image.RGBA
- func (cv *Canvas) GetLineDash() []float64
- func (cv *Canvas) Height() int
- func (cv *Canvas) IsPointInPath(x, y float64, rule pathRule) bool
- func (cv *Canvas) IsPointInStroke(x, y float64) bool
- func (cv *Canvas) LineTo(x, y float64)
- func (cv *Canvas) LoadFont(src interface{}) (*Font, error)
- func (cv *Canvas) LoadImage(src interface{}) (*Image, error)
- func (cv *Canvas) MeasureText(str string) TextMetrics
- func (cv *Canvas) MoveTo(x, y float64)
- func (cv *Canvas) NewPath2D() *Path2D
- func (cv *Canvas) PutImageData(img *image.RGBA, x, y int)
- func (cv *Canvas) QuadraticCurveTo(x1, y1, x2, y2 float64)
- func (cv *Canvas) Rect(x, y, w, h float64)
- func (cv *Canvas) Restore()
- func (cv *Canvas) Rotate(angle float64)
- func (cv *Canvas) Save()
- func (cv *Canvas) Scale(x, y float64)
- func (cv *Canvas) SetFillStyle(value ...interface{})
- func (cv *Canvas) SetFont(src interface{}, size float64)
- func (cv *Canvas) SetGlobalAlpha(alpha float64)
- func (cv *Canvas) SetLineCap(cap lineCap)
- func (cv *Canvas) SetLineDash(dash []float64)
- func (cv *Canvas) SetLineDashOffset(offset float64)
- func (cv *Canvas) SetLineJoin(join lineJoin)
- func (cv *Canvas) SetLineWidth(width float64)
- func (cv *Canvas) SetMiterLimit(limit float64)
- func (cv *Canvas) SetShadowBlur(r float64)
- func (cv *Canvas) SetShadowColor(color ...interface{})
- func (cv *Canvas) SetShadowOffset(x, y float64)
- func (cv *Canvas) SetShadowOffsetX(offset float64)
- func (cv *Canvas) SetShadowOffsetY(offset float64)
- func (cv *Canvas) SetStrokeStyle(value ...interface{})
- func (cv *Canvas) SetTextAlign(align textAlign)
- func (cv *Canvas) SetTextBaseline(baseline textBaseline)
- func (cv *Canvas) SetTransform(a, b, c, d, e, f float64)
- func (cv *Canvas) Size() (int, int)
- func (cv *Canvas) Stroke()
- func (cv *Canvas) StrokePath(path *Path2D)
- func (cv *Canvas) StrokeRect(x, y, w, h float64)
- func (cv *Canvas) StrokeText(str string, x, y float64)
- func (cv *Canvas) Transform(a, b, c, d, e, f float64)
- func (cv *Canvas) Translate(x, y float64)
- func (cv *Canvas) Width() int
- type Font
- type Image
- type ImagePattern
- type LinearGradient
- type Path2D
- func (p *Path2D) Arc(x, y, radius, startAngle, endAngle float64, anticlockwise bool)
- func (p *Path2D) ArcTo(x1, y1, x2, y2, radius float64)
- func (p *Path2D) BezierCurveTo(x1, y1, x2, y2, x3, y3 float64)
- func (p *Path2D) ClosePath()
- func (p *Path2D) Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, ...)
- func (p *Path2D) IsPointInPath(x, y float64, rule pathRule) bool
- func (p *Path2D) IsPointInStroke(x, y float64) bool
- func (p *Path2D) LineTo(x, y float64)
- func (p *Path2D) MoveTo(x, y float64)
- func (p *Path2D) QuadraticCurveTo(x1, y1, x2, y2 float64)
- func (p *Path2D) Rect(x, y, w, h float64)
- type RadialGradient
- type TextMetrics
Constants ¶
const ( Miter = iota Bevel Round Square Butt )
Line join and end constants for SetLineJoin and SetLineCap
const ( Left = iota Center Right Start End )
Text alignment constants for SetTextAlign
const ( Alphabetic = iota Top Hanging Middle Ideographic Bottom )
Text baseline constants for SetTextBaseline
const ( Repeat imagePatternRepeat = imagePatternRepeat(backendbase.Repeat) RepeatX = imagePatternRepeat(backendbase.RepeatX) RepeatY = imagePatternRepeat(backendbase.RepeatY) NoRepeat = imagePatternRepeat(backendbase.NoRepeat) )
Image pattern repeat constants
const ( NonZero pathRule = iota EvenOdd )
Path rule constants. See https://en.wikipedia.org/wiki/Nonzero-rule and https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
Variables ¶
var Performance = struct { IgnoreSelfIntersections bool AssumeConvex bool // CacheSize is only approximate CacheSize int }{ CacheSize: 128_000_000, }
Performance is a nonstandard setting to improve the performance of the rendering in some circumstances. Disabling self intersections will lead to incorrect rendering of self intersecting polygons, but will yield better performance when not using the polygons are not self intersecting. Assuming convex polygons will break concave polygons, but improve performance even further
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas represents an area on the viewport on which to draw using a set of functions very similar to the HTML5 canvas
func New ¶
func New(backend backendbase.Backend) *Canvas
New creates a new canvas with the given viewport coordinates. While all functions on the canvas use the top left point as the origin, since GL uses the bottom left coordinate, the coordinates given here also use the bottom left as origin
func (*Canvas) Arc ¶
Arc adds a circle segment to the end of the path. x/y is the center, radius is the radius, startAngle and endAngle are angles in radians, anticlockwise means that the line is added anticlockwise
func (*Canvas) ArcTo ¶
ArcTo adds to the current path by drawing a line toward x1/y1 and a circle segment of a radius given by the radius parameter. The circle touches the lines from the end of the path to x1/y1, and from x1/y1 to x2/y2. The line will only go to where the circle segment would touch the latter line
func (*Canvas) BeginPath ¶
func (cv *Canvas) BeginPath()
BeginPath clears the current path and starts a new one
func (*Canvas) BezierCurveTo ¶
BezierCurveTo adds a bezier curve to the path. It uses the current end point of the path, x1/y1 and x2/y2 define the curve, and x3/y3 is the end point
func (*Canvas) Clip ¶
func (cv *Canvas) Clip()
Clip uses the current path to clip any further drawing. Use Save/Restore to remove the clipping again
func (*Canvas) ClosePath ¶
func (cv *Canvas) ClosePath()
ClosePath closes the path to the beginning of the path or the last point from a MoveTo call
func (*Canvas) CreateLinearGradient ¶
func (cv *Canvas) CreateLinearGradient(x0, y0, x1, y1 float64) *LinearGradient
CreateLinearGradient creates a new linear gradient with the coordinates from where to where the gradient will apply on the canvas
func (*Canvas) CreatePattern ¶
func (cv *Canvas) CreatePattern(src interface{}, repeat imagePatternRepeat) *ImagePattern
CreatePattern creates a new image pattern with the specified image and repetition
func (*Canvas) CreateRadialGradient ¶
func (cv *Canvas) CreateRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient
CreateRadialGradient creates a new radial gradient with the coordinates and the radii for two circles. The gradient will apply from the first to the second circle
func (*Canvas) DrawImage ¶
DrawImage draws the given image to the given coordinates. The image parameter can be an Image loaded by LoadImage, a file name string that will be loaded and cached, or a name string that corresponds to a previously loaded image with the same name parameter.
The coordinates must be one of the following:
DrawImage("image", dx, dy) DrawImage("image", dx, dy, dw, dh) DrawImage("image", sx, sy, sw, sh, dx, dy, dw, dh)
Where dx/dy/dw/dh are the destination coordinates and sx/sy/sw/sh are the source coordinates
func (*Canvas) Ellipse ¶
func (cv *Canvas) Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, anticlockwise bool)
Ellipse adds an ellipse segment to the end of the path. x/y is the center, radiusX is the major axis radius, radiusY is the minor axis radius, rotation is the rotation of the ellipse in radians, startAngle and endAngle are angles in radians, and anticlockwise means that the line is added anticlockwise
func (*Canvas) Fill ¶
func (cv *Canvas) Fill()
Fill fills the current path with the current FillStyle
func (*Canvas) FillText ¶
FillText draws the given string at the given coordinates using the currently set font and font height
func (*Canvas) GetImageData ¶
GetImageData returns an RGBA image of the current image
func (*Canvas) GetLineDash ¶
GetLineDash gets the line dash style
func (*Canvas) IsPointInPath ¶
IsPointInPath returns true if the point is in the current path according to the given rule
func (*Canvas) IsPointInStroke ¶
IsPointInStroke returns true if the point is in the current path stroke
func (*Canvas) LoadFont ¶
LoadFont loads a font and returns the result. The font can be a file name or a byte slice in TTF format
func (*Canvas) LoadImage ¶
LoadImage loads an image. The src parameter can be either an image from the standard image package, a byte slice that will be loaded, or a file name string. If you want the canvas package to load the image, make sure you import the required format packages
func (*Canvas) MeasureText ¶
func (cv *Canvas) MeasureText(str string) TextMetrics
MeasureText measures the given string using the current font and font height
func (*Canvas) PutImageData ¶
PutImageData puts the given image at the given x/y coordinates
func (*Canvas) QuadraticCurveTo ¶
QuadraticCurveTo adds a quadratic curve to the path. It uses the current end point of the path, x1/y1 defines the curve, and x2/y2 is the end point
func (*Canvas) Restore ¶
func (cv *Canvas) Restore()
Restore restores the last draw state from the stack if available
func (*Canvas) Rotate ¶
Rotate updates the current transformation with a rotation by the given angle
func (*Canvas) SetFillStyle ¶
func (cv *Canvas) SetFillStyle(value ...interface{})
SetFillStyle sets the color, gradient, or image for any fill calls. To set a color, there are several acceptable formats: 3 or 4 int values for RGB(A) in the range 0-255, 3 or 4 float values for RGB(A) in the range 0-1, hex strings in the format "#AABBCC", "#AABBCCDD", "#ABC", or "#ABCD"
func (*Canvas) SetFont ¶
SetFont sets the font and font size. The font parameter can be a font loaded with the LoadFont function, a filename for a font to load (which will be cached), or nil, in which case the first loaded font will be used
func (*Canvas) SetGlobalAlpha ¶
SetGlobalAlpha sets the global alpha value
func (*Canvas) SetLineCap ¶
func (cv *Canvas) SetLineCap(cap lineCap)
SetLineCap sets the style of line endings for rendering a path with Stroke The value can be Butt, Square, or Round
func (*Canvas) SetLineDash ¶
SetLineDash sets the line dash style
func (*Canvas) SetLineDashOffset ¶
SetLineDashOffset sets the line dash offset
func (*Canvas) SetLineJoin ¶
func (cv *Canvas) SetLineJoin(join lineJoin)
SetLineJoin sets the style of line joints for rendering a path with Stroke. The value can be Miter, Bevel, or Round
func (*Canvas) SetLineWidth ¶
SetLineWidth sets the line width for any line drawing calls
func (*Canvas) SetMiterLimit ¶
SetMiterLimit sets the limit for how far a miter line join can be extend. The fallback is a bevel join
func (*Canvas) SetShadowBlur ¶
SetShadowBlur sets the gaussian blur radius of the shadow (0 for no blur)
func (*Canvas) SetShadowColor ¶
func (cv *Canvas) SetShadowColor(color ...interface{})
SetShadowColor sets the color of the shadow. If it is fully transparent (default) then no shadow is drawn
func (*Canvas) SetShadowOffset ¶
SetShadowOffset sets the offset of the shadow
func (*Canvas) SetShadowOffsetX ¶
SetShadowOffsetX sets the x offset of the shadow
func (*Canvas) SetShadowOffsetY ¶
SetShadowOffsetY sets the y offset of the shadow
func (*Canvas) SetStrokeStyle ¶
func (cv *Canvas) SetStrokeStyle(value ...interface{})
SetStrokeStyle sets the color, gradient, or image for any line drawing calls. To set a color, there are several acceptable formats: 3 or 4 int values for RGB(A) in the range 0-255, 3 or 4 float values for RGB(A) in the range 0-1, hex strings in the format "#AABBCC", "#AABBCCDD", "#ABC", or "#ABCD"
func (*Canvas) SetTextAlign ¶
func (cv *Canvas) SetTextAlign(align textAlign)
SetTextAlign sets the text align for any text drawing calls. The value can be Left, Center, Right, Start, or End
func (*Canvas) SetTextBaseline ¶
func (cv *Canvas) SetTextBaseline(baseline textBaseline)
SetTextBaseline sets the text baseline for any text drawing calls. The value can be Alphabetic (default), Top, Hanging, Middle, Ideographic, or Bottom
func (*Canvas) SetTransform ¶
SetTransform replaces the current transformation with the given matrix
func (*Canvas) Stroke ¶
func (cv *Canvas) Stroke()
Stroke uses the current StrokeStyle to draw the current path
func (*Canvas) StrokePath ¶
StrokePath uses the current StrokeStyle to draw the given path
func (*Canvas) StrokeRect ¶
StrokeRect draws a rectangle using the current stroke style
func (*Canvas) StrokeText ¶
StrokeText draws the given string at the given coordinates using the currently set font and font height and using the current stroke style
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
Font is a loaded font that can be passed to the SetFont method
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is a type holding information on an image loaded with the LoadImage function
type ImagePattern ¶
type ImagePattern struct {
// contains filtered or unexported fields
}
ImagePattern is an image pattern that can be used for any fill call
func (*ImagePattern) SetTransform ¶
func (ip *ImagePattern) SetTransform(tf [6]float64)
SetTransform changes the transformation of the image pattern to the given matrix. The matrix is a 3x3 matrix, but three of the values are always identity values
type LinearGradient ¶
type LinearGradient struct {
// contains filtered or unexported fields
}
LinearGradient is a gradient with any number of stops and any number of colors. The gradient will be drawn such that each point on the gradient will correspond to a straight line
func (*LinearGradient) AddColorStop ¶
func (lg *LinearGradient) AddColorStop(pos float64, stopColor ...interface{})
AddColorStop adds a color stop to the gradient. The stops don't have to be added in order, they are sorted into the right place
type Path2D ¶
type Path2D struct {
// contains filtered or unexported fields
}
Path2D is a type that holds a predefined path which can be drawn with a single call
func (*Path2D) BezierCurveTo ¶
BezierCurveTo (see equivalent function on canvas type)
func (*Path2D) ClosePath ¶
func (p *Path2D) ClosePath()
ClosePath (see equivalent function on canvas type)
func (*Path2D) Ellipse ¶
func (p *Path2D) Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, anticlockwise bool)
Ellipse (see equivalent function on canvas type)
func (*Path2D) IsPointInPath ¶
IsPointInPath returns true if the point is in the path according to the given rule
func (*Path2D) IsPointInStroke ¶
IsPointInStroke returns true if the point is in the stroke
func (*Path2D) QuadraticCurveTo ¶
QuadraticCurveTo (see equivalent function on canvas type)
type RadialGradient ¶
type RadialGradient struct {
// contains filtered or unexported fields
}
RadialGradient is a gradient with any number of stops and any number of colors. The gradient will be drawn such that each point on the gradient will correspond to a circle
func (*RadialGradient) AddColorStop ¶
func (rg *RadialGradient) AddColorStop(pos float64, stopColor ...interface{})
AddColorStop adds a color stop to the gradient. The stops don't have to be added in order, they are sorted into the right place
type TextMetrics ¶
type TextMetrics struct { Width float64 ActualBoundingBoxAscent float64 ActualBoundingBoxDescent float64 }
TextMetrics is the result of a MeasureText call
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
backend
|
|
goglbackend/gl
Package gl implements Go bindings to OpenGL.
|
Package gl implements Go bindings to OpenGL. |
examples
|
|