94 lines
2.9 KiB
Go
94 lines
2.9 KiB
Go
// Canvas defines a standard interface for images that support drawing
|
|
// primitives.
|
|
package canvas
|
|
|
|
import "image"
|
|
import "image/draw"
|
|
import "image/color"
|
|
|
|
// Cap represents a stroke cap type.
|
|
type Cap int; 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
|
|
)
|
|
|
|
// Joint represents a stroke joint type.
|
|
type Joint int; const (
|
|
JointRount Joint = iota // Rounded joint
|
|
JointSharp // Sharp joint
|
|
JointMiter // Clipped/beveled joint
|
|
)
|
|
|
|
// StrokeAlign determines whether a stroke is drawn inside, outside, or on a
|
|
// path.
|
|
type StrokeAlign int; const (
|
|
StrokeAlignCenter StrokeAlign = iota // Centered on the path
|
|
StrokeAlignInner // Inset into the path
|
|
StrokeAlignOuter // Outset around the path
|
|
)
|
|
|
|
// 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 Pen interface {
|
|
// Rectangle draws a 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)
|
|
}
|
|
|
|
// Canvas is an image that supports drawing paths.
|
|
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
|
|
}
|
|
|
|
// Drawer can draw to a canvas.
|
|
type Drawer interface {
|
|
// Draw draws to the given canvas.
|
|
Draw (Canvas)
|
|
}
|
|
|
|
// PushCanvas is a canvas that can push a region of itself to the screen (or
|
|
// some other destination).
|
|
type PushCanvas interface {
|
|
Canvas
|
|
|
|
// Push pushes a specified region to the screen.
|
|
Push (image.Rectangle)
|
|
}
|