71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package canvas
|
|
|
|
import "image"
|
|
import "image/draw"
|
|
import "image/color"
|
|
|
|
// Cap represents a stroke cap type.
|
|
type Cap int; const (
|
|
CapButt Cap = iota
|
|
CapRound
|
|
CapSquare
|
|
)
|
|
|
|
// Joint represents a stroke joint type.
|
|
type Joint int; const (
|
|
JointRount Joint = iota
|
|
JointSharp
|
|
JointMiter
|
|
)
|
|
|
|
// StrokeAlign determines whether a stroke is drawn inside, outside, or on a
|
|
// path.
|
|
type StrokeAlign int; const (
|
|
StrokeAlignCenter StrokeAlign = iota
|
|
StrokeAlignInner
|
|
StrokeAlignOuter
|
|
)
|
|
|
|
// 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 {
|
|
// Draw draws a path
|
|
Draw (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
|
|
|
|
// set the stroke/fill to a solid color
|
|
Stroke (color.Color)
|
|
Fill (color.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 (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)
|
|
}
|