Documentation
¶
Overview ¶
Package canvas2d plays NSGo's drawings into a canvas's 2D context over syscall/js: a browser's <canvas> on the web, and a WeChat mini program's offscreen canvas, which has the same context.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadTexture ¶
func ReadTexture(canvas, img js.Value, density float64) (tex canvasmesh.Texture)
ReadTexture snapshots a native image's premultiplied pixels. Canvas security rules may prevent reading an image loaded from another origin.
Types ¶
type Player ¶
type Player struct {
Ctx js.Value
Drawing *driver.Drawing
// Ratio is the canvas's pixels per point, and Size its diagonal in
// points, which repeating gradients cover.
Ratio, Size float64
// OriginX and OriginY shift the drawing space when the <canvas> holds only a visible sub-rectangle of a larger canvas.
OriginX, OriginY float64
// Font is the context's font shorthand of a font.
Font func(driver.Font) string
// Image returns the loaded image an op draws and its pixels per
// point; false while it loads, when the op draws nothing.
Image func(driver.ImageSource, bool) (img js.Value, density float64, ok bool)
// NewCanvas creates a scratch canvas for tinting.
NewCanvas func(width, height int) js.Value
// Texture supplies a mesh's loaded pixels. MeshCanvas supplies a
// scratch canvas for native 2D composition.
Texture func(driver.ImageSource) canvasmesh.Texture
MeshCanvas func() js.Value
// Shade draws an op that shades with a program, a DrawShader or an
// image op under SetShader, reporting whether it did; nil, or a false
// report, leaves a DrawShader out and draws an image op plain.
Shade func(op *driver.DrawOp) bool
// contains filtered or unexported fields
}
Player plays a drawing into a 2D context, which draws as NSGo's: the context already does what the ops say, so most map one to one.
func NewPlayer ¶
NewPlayer returns a player into ctx, whose canvas has ratio pixels per point and a diagonal of size points.