canvas

package
v0.48.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: GPL-3.0 Imports: 4 Imported by: 7

Documentation

Overview

Canvas defines a standard interface for images that support drawing primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shatter added in v0.8.0

func Shatter(
	glass image.Rectangle,
	rocks ...image.Rectangle,
) (
	tiles []image.Rectangle,
)

Shatter takes in a bounding rectangle, and several image.Rectangles to be subtracted from it. It returns a slice of rectangles that tile together to make up the difference between them. This is intended to be used for figuring out which areas of a container box's background are covered by other boxes so it doesn't waste CPU cycles drawing to those areas.

Types

type Canvas

type Canvas interface {
	draw.Image

	// Pen returns a new pen for this Canvas.
	Pen() Pen

	// SubCanvas returns a returns a Canvas representing the portion of this
	// Canvas visible and drawable through a rectangle. The returned value
	// shares pixels with the original Canvas.
	SubCanvas(image.Rectangle) Canvas
}

Canvas is an image that supports drawing paths.

type CanvasCloser added in v0.35.0

type CanvasCloser interface {
	Canvas
	io.Closer
}

CanvasCloser is a canvas that can be closed. Anything that receives a CanvasCloser must close it after use.

type Cap

type Cap int

Cap represents a stroke cap type.

const (
	CapRound  Cap = iota // Round cap that surrounds the point
	CapSquare            // Square cap that surrounds the point
	CapButt              // Square cap that ends at the point
)

type Drawer

type Drawer interface {
	// Draw draws to the given Canvas.
	Draw(Canvas)
}

Drawer can draw to a canvas.

type Joint

type Joint int

Joint represents a stroke joint type.

const (
	JointRount Joint = iota // Rounded joint
	JointSharp              // Sharp joint
	JointMiter              // Clipped/beveled joint
)

type Pen

type Pen interface {
	// Rectangle draws an image.Rectangle.
	Rectangle(image.Rectangle)

	// Path draws a path, which is a series of connected points.
	Path(points ...image.Point)

	// StrokeWeight sets how thick the stroke is. The default value is zero.
	StrokeWeight(int)
	// SetClosed sets whether the path is a closed shape, or has an open
	// side. This only applies if the stroke weight is greater than zero.
	Closed(bool)
	// Cap sets how the ends of the stroke look. This only applies if the
	// stroke weight is greater than zero, and if the path is not closed.
	// The default value is CapRound.
	Cap(Cap)
	// Joint sets how bend points in the stroke look. This only applies if
	// the stroke weight is greater than zero. The default value is
	// JointRound.
	Joint(Joint)
	// StrokeAlign sets where the stroke is drawn in relation to the path.
	// This only applies if the stroke weight is greater than zero. The
	// default value is StrokeAlignCenter.
	StrokeAlign(StrokeAlign)

	// Stroke sets the stroke to a solid color.
	Stroke(color.Color)
	// Fill sets the fill to a solid color.
	Fill(color.Color)
	// Texture overlaps a texture onto the fill color.
	Texture(Texture)
}

Pen represents a drawing context that is linked to a canvas. Each canvas can have multiple pens associated with it, each maintaining their own drawing state.

type PushCanvas

type PushCanvas interface {
	Canvas

	// Push pushes a specified region to the screen.
	Push(image.Rectangle)
}

PushCanvas is a Canvas that can push a region of itself to the screen (or some other destination).

type StrokeAlign

type StrokeAlign int

StrokeAlign determines whether a stroke is drawn inside, outside, or on a path.

const (
	StrokeAlignCenter StrokeAlign = iota // Centered on the path
	StrokeAlignInner                     // Inset into the path
	StrokeAlignOuter                     // Outset around the path
)

type Texture added in v0.26.0

type Texture interface {
	image.Image

	// SubTexture returns a returns a Texture representing the portion of
	// this Texture visible through a rectangle. The returned value shares
	// pixels with the original Texture.
	SubTexture(image.Rectangle) Texture
}

Texture is a handle that points to a 2D raster image.

type TextureCloser added in v0.28.0

type TextureCloser interface {
	Texture
	io.Closer
}

TextureCloser is a Texture that can be closed. Anything that receives a TextureCloser must close it after use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL