tomo/canvas/canvas.go

77 lines
2.2 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 (
CapButt Cap = iota // Square cap that ends at the point
CapRound // Round cap that surrounds the point
CapSquare // square cap that surrounds 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
// context.
type Pen interface {
// Rectangle draws a rectangle
Rectangle (image.Rectangle)
// Path draws a path
Path (points ...image.Point)
Closed (bool) // if the path is closed
Cap (Cap) // line cap stype
Joint (Joint) // line joint style
StrokeWeight (int) // how thick the stroke is
StrokeAlign (StrokeAlign) // where the stroke is drawn
Stroke (color.Color) // Sets the stroke to a solid color
Fill (color.Color) // Sets the fill to a solid color
Texture (Texture) // Overlaps a texture onto the fill color
}
// Canvas is an image that supports drawing paths.
type Canvas interface {
draw.Image
// Pen returns a new pen for this canvas.
Pen () Pen
// Clip returns a new canvas that points to a specific area of this one.
Clip (image.Rectangle) Canvas
}
// Drawer is an object that 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)
}