Documentation ¶
Index ¶
- Constants
- Variables
- func AlignPosition(align Align, bounds image.Rectangle, sizeX int, sizeY int) (image.Rectangle, error)
- func DrawDiamond(canvas draw.Image, start image.Point, width int, height int, ...)
- func DrawDownTriangle(canvas draw.Image, start image.Point, width int, height int, ...)
- func DrawImage(canvas draw.Image, bounds image.Rectangle, img image.Image) error
- func DrawImageAligned(canvas draw.Image, bounds image.Rectangle, img *image.RGBA, align Align) error
- func DrawRectangle(canvas draw.Image, startX int, startY int, sizeX int, sizeY int, ...) error
- func DrawSquare(canvas draw.Image, start image.Point, width int, outlineClr color.Color, ...)
- func DrawUpTriangle(canvas draw.Image, start image.Point, width int, height int, ...)
- func DrawVerticalLine(canvas draw.Image, start image.Point, end image.Point, clr color.Color)
- func FitImage(img image.Image, bounds image.Rectangle, zoom float64) image.Image
- func GetFont(name string) (*truetype.Font, error)
- func GradientXRectangle(bounds image.Rectangle, fillPercentage float64, baseColor color.Color, ...) image.Image
- func HexToRGB(hexClr string) (uint8, uint8, uint8, error)
- func PlayGIF(ctx context.Context, canvas board.Canvas, gif *gif.GIF) error
- func PlayImages(ctx context.Context, canvas board.Canvas, images []image.Image, ...) error
- func ResizeGIF(ctx context.Context, g *gif.GIF, bounds image.Rectangle, zoom float64) error
- func ResizeImage(img image.Image, bounds image.Rectangle, zoom float64) image.Image
- func SaveGif(img *gif.GIF, fileName string) error
- func SavePng(img image.Image, fileName string) error
- func SetImageAlign(canvas *cnvs.Canvas, align Align, img image.Image) (image.Image, error)
- func ShiftedSize(xStart int, yStart int, bounds image.Rectangle) image.Rectangle
- func ZeroedBounds(bounds image.Rectangle) image.Rectangle
- func ZeroedXBounds(bounds image.Rectangle) image.Rectangle
- func ZeroedYBounds(bounds image.Rectangle) image.Rectangle
- func ZoomImageSize(img image.Image, zoom float64) (int, int)
- type Align
- type Cell
- type ColorChar
- type ColorCharLine
- type Draw
- type Grid
- func (g *Grid) Cell(index int) (*Cell, error)
- func (g *Grid) Cells() []*Cell
- func (g *Grid) Clear() error
- func (g *Grid) DrawToBase(base board.Canvas) error
- func (g *Grid) FillPadded(canvas board.Canvas, clr color.Color)
- func (g *Grid) GetCol(col int) []*Cell
- func (g *Grid) GetRow(row int) []*Cell
- func (g *Grid) NumCols() int
- func (g *Grid) NumRows() int
- type GridOption
- func WithCellColRatios(colRatios []float64) GridOption
- func WithCellRatios(colRatios []float64, rowRatios []float64) GridOption
- func WithCellRowRatios(rowRatios []float64) GridOption
- func WithPadding(pad float64) GridOption
- func WithUniformCells() GridOption
- func WithUniformCols() GridOption
- func WithUniformRows() GridOption
- type Layer
- type LayerDrawer
- type Prepare
- type TextLayer
- type TextPrepare
- type TextWriter
- func (t *TextWriter) BreakText(canvas draw.Image, maxPixWidth int, text string) ([]string, error)
- func (t *TextWriter) MaxChars(canvas draw.Image, pixWidth int) (int, error)
- func (t *TextWriter) MeasureStrings(canvas draw.Image, str []string) ([]int, error)
- func (t *TextWriter) Write(canvas draw.Image, bounds image.Rectangle, str []string, clr color.Color) error
- func (t *TextWriter) WriteAligned(align Align, canvas draw.Image, bounds image.Rectangle, str []string, ...) error
- func (t *TextWriter) WriteAlignedBoxed(align Align, canvas draw.Image, bounds image.Rectangle, str []string, ...) error
- func (t *TextWriter) WriteAlignedColorCodes(align Align, canvas draw.Image, bounds image.Rectangle, colorChars *ColorChar) error
- func (t *TextWriter) WriteColorCodes(canvas draw.Image, bounds image.Rectangle, colorChars *ColorChar) error
- type Write
Constants ¶
const ( // BackgroundPriority sets a layer's priority to the rearmost layer BackgroundPriority = 0 // ForegroundPriority sets a layer's priority to the frontmost layer ForegroundPriority = -1 )
Variables ¶
var BuiltinFonts = []string{
"04b24.ttf",
"BlockStockRegular-A71p.ttf",
"04B_03__.ttf",
"score.ttf",
}
BuiltinFonts is a list of fonts names this pkg provides
Functions ¶
func AlignPosition ¶
func AlignPosition(align Align, bounds image.Rectangle, sizeX int, sizeY int) (image.Rectangle, error)
AlignPosition returns image.Rectangle bounds for an image within a given bounds
func DrawDiamond ¶
func DrawDownTriangle ¶
func DrawImageAligned ¶
func DrawImageAligned(canvas draw.Image, bounds image.Rectangle, img *image.RGBA, align Align) error
DrawImageAligned draws an image aligned within the given bounds
func DrawRectangle ¶
func DrawRectangle(canvas draw.Image, startX int, startY int, sizeX int, sizeY int, fillColor color.Color) error
DrawRectangle ...
func DrawSquare ¶
func DrawUpTriangle ¶
func DrawVerticalLine ¶
func GradientXRectangle ¶
func GradientXRectangle(bounds image.Rectangle, fillPercentage float64, baseColor color.Color, logger *zap.Logger) image.Image
GradientXRectangle creates a rectangle that has a solid fill in the center of the rect of the given fillPercentage, then gradually increases transparency beyond those bounds in both directions on the X axis
func PlayGIF ¶
PlayGIF reads and draw a gif file from r. It use the contained images and delays and loops over it, until a true is sent to the returned chan
func PlayImages ¶
func PlayImages(ctx context.Context, canvas board.Canvas, images []image.Image, delay []time.Duration, loop int) error
PlayImages plays s series of images. If loop == 0, it will play forever until the context is canceled
func ResizeImage ¶
ResizeImage ...
func SetImageAlign ¶
SetImageAlign ...
func ShiftedSize ¶
ShiftedSize shifts an image's start location and returns its resulting bounds
func ZeroedBounds ¶
ZeroedBounds returns an image.Rectangle with square padding stripped off
func ZeroedXBounds ¶
ZeroedXBounds returns an image.Rectangle with square padding stripped off
func ZeroedYBounds ¶
ZeroedYBounds returns an image.Rectangle with square padding stripped off
Types ¶
type ColorChar ¶
type ColorChar struct { Lines []*ColorCharLine BoxClr color.Color }
ColorChar is used to define text for writing in different colors
type ColorCharLine ¶
ColorCharLine is a line in a multicolored text
type Grid ¶
type Grid struct {
// contains filtered or unexported fields
}
Grid manages sub-canvas "cells" of a larger canvas
func NewGrid ¶
func NewGrid(canvas board.Canvas, numCols int, numRows int, log *zap.Logger, opts ...GridOption) (*Grid, error)
NewGrid ...
func (*Grid) DrawToBase ¶
DrawToBase draws the cells onto a base parent canvas
func (*Grid) FillPadded ¶
FillPadded fills the cell padding with a color
type GridOption ¶
GridOption is an option for a Grid
func WithCellColRatios ¶
func WithCellColRatios(colRatios []float64) GridOption
WithCellColRatios sets col/row sizes with ratios
func WithCellRatios ¶
func WithCellRatios(colRatios []float64, rowRatios []float64) GridOption
WithCellRatios sets col/row sizes with ratios
func WithCellRowRatios ¶
func WithCellRowRatios(rowRatios []float64) GridOption
WithCellRowRatios sets col/row sizes with ratios
func WithPadding ¶
func WithPadding(pad float64) GridOption
WithPadding is an option to specify padding width between cells as a percentage of canvas width
func WithUniformCells ¶
func WithUniformCells() GridOption
WithUniformCells sets all cell sizes to a uniform size
func WithUniformCols ¶
func WithUniformCols() GridOption
WithUniformCols sets all cell sizes to a uniform size
func WithUniformRows ¶
func WithUniformRows() GridOption
WithUniformRows sets all cell sizes to a uniform size
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer is a layer that draws an image.Image onto a board.Canvas
type LayerDrawer ¶
type LayerDrawer struct {
// contains filtered or unexported fields
}
LayerDrawer draws layers on a board.Canvas. It prepares layers simultaneously, then draws each priority simultaneously.
func NewLayerDrawer ¶
NewLayerDrawer ...
func (*LayerDrawer) AddLayer ¶
func (l *LayerDrawer) AddLayer(priority int, layer *Layer)
AddLayer ...
func (*LayerDrawer) AddTextLayer ¶
func (l *LayerDrawer) AddTextLayer(priority int, layer *TextLayer)
AddTextLayer ...
type TextLayer ¶
type TextLayer struct {
// contains filtered or unexported fields
}
TextLayer writes text onto a board.Canvas
type TextPrepare ¶
type TextPrepare func(ctx context.Context) (*TextWriter, []string, error)
TextPrepare is a func type for preparing a TextLayer for drawing
type TextWriter ¶
type TextWriter struct { XStartCorrection int YStartCorrection int FontSize float64 LineSpace float64 // contains filtered or unexported fields }
TextWriter ...
func NewTextWriter ¶
func NewTextWriter(font *truetype.Font, fontSize float64) *TextWriter
NewTextWriter ...
func (*TextWriter) MaxChars ¶
MaxChars returns the maximum number of characters that can fit a given pixel width
func (*TextWriter) MeasureStrings ¶
MeasureStrings measures the pixel width of a list of strings
func (*TextWriter) Write ¶
func (t *TextWriter) Write(canvas draw.Image, bounds image.Rectangle, str []string, clr color.Color) error
Write ...
func (*TextWriter) WriteAligned ¶
func (t *TextWriter) WriteAligned(align Align, canvas draw.Image, bounds image.Rectangle, str []string, clr color.Color) error
WriteAligned writes text aligned within a given bounds
func (*TextWriter) WriteAlignedBoxed ¶
func (t *TextWriter) WriteAlignedBoxed(align Align, canvas draw.Image, bounds image.Rectangle, str []string, clr color.Color, boxColor color.Color) error
WriteAlignedBoxed writes text aligned within a given bounds and draws a box sized to the text width
func (*TextWriter) WriteAlignedColorCodes ¶
func (t *TextWriter) WriteAlignedColorCodes(align Align, canvas draw.Image, bounds image.Rectangle, colorChars *ColorChar) error
WriteAlignedColorCodes writes text aligned within a given bounds and draws a box sized to the text width
func (*TextWriter) WriteColorCodes ¶
func (t *TextWriter) WriteColorCodes(canvas draw.Image, bounds image.Rectangle, colorChars *ColorChar) error
WriteColorCodes writes text aligned within a given bounds and draws a box sized to the text width