rgbrender

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 DrawDiamond(canvas draw.Image, start image.Point, width int, height int, outlineColor color.Color, fillColor color.Color)

func DrawDownTriangle

func DrawDownTriangle(canvas draw.Image, start image.Point, width int, height int, outlineColor color.Color, fillColor color.Color)

func DrawImage

func DrawImage(canvas draw.Image, bounds image.Rectangle, img image.Image) error

DrawImage draws an image

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 DrawSquare(canvas draw.Image, start image.Point, width int, outlineClr color.Color, fillClr color.Color)

func DrawUpTriangle

func DrawUpTriangle(canvas draw.Image, start image.Point, width int, height int, outlineColor color.Color, fillColor color.Color)

func DrawVerticalLine

func DrawVerticalLine(canvas draw.Image, start image.Point, end image.Point, clr color.Color)

func FitImage

func FitImage(img image.Image, bounds image.Rectangle, zoom float64) image.Image

FitImage ...

func GetFont

func GetFont(name string) (*truetype.Font, error)

GetFont gets a builtin font by the given name

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 HexToRGB

func HexToRGB(hexClr string) (uint8, uint8, uint8, error)

func PlayGIF

func PlayGIF(ctx context.Context, canvas board.Canvas, gif *gif.GIF) error

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 ResizeGIF

func ResizeGIF(ctx context.Context, g *gif.GIF, bounds image.Rectangle, zoom float64) error

ResizeGIF ...

func ResizeImage

func ResizeImage(img image.Image, bounds image.Rectangle, zoom float64) image.Image

ResizeImage ...

func SaveGif

func SaveGif(img *gif.GIF, fileName string) error

SaveGif ...

func SavePng

func SavePng(img image.Image, fileName string) error

SavePng ...

func SetImageAlign

func SetImageAlign(canvas *cnvs.Canvas, align Align, img image.Image) (image.Image, error)

SetImageAlign ...

func ShiftedSize

func ShiftedSize(xStart int, yStart int, bounds image.Rectangle) image.Rectangle

ShiftedSize shifts an image's start location and returns its resulting bounds

func ZeroedBounds

func ZeroedBounds(bounds image.Rectangle) image.Rectangle

ZeroedBounds returns an image.Rectangle with square padding stripped off

func ZeroedXBounds

func ZeroedXBounds(bounds image.Rectangle) image.Rectangle

ZeroedXBounds returns an image.Rectangle with square padding stripped off

func ZeroedYBounds

func ZeroedYBounds(bounds image.Rectangle) image.Rectangle

ZeroedYBounds returns an image.Rectangle with square padding stripped off

func ZoomImageSize

func ZoomImageSize(img image.Image, zoom float64) (int, int)

ZoomImageSize takes a zoom percentage and returns the resulting image size.

Types

type Align

type Align int

Align represents alignment vertically and horizontally

const (
	// CenterCenter ...
	CenterCenter Align = iota
	// CenterTop ...
	CenterTop
	// CenterBottom ...
	CenterBottom
	// RightCenter ...
	RightCenter
	// RightTop ...
	RightTop
	// RightBottom ...
	RightBottom
	// LeftCenter ...
	LeftCenter
	// LeftTop ...
	LeftTop
	// LeftBottom ...
	LeftBottom
)

type Cell

type Cell struct {
	Canvas board.Canvas
	Bounds image.Rectangle
	Col    int
	Row    int
}

Cell contains a canvas and it's bounds related to it's parent canvas

type ColorChar

type ColorChar struct {
	Lines  []*ColorCharLine
	BoxClr color.Color
}

ColorChar is used to define text for writing in different colors

type ColorCharLine

type ColorCharLine struct {
	Chars []string
	Clrs  []color.Color
}

ColorCharLine is a line in a multicolored text

type Draw

type Draw func(canvas board.Canvas, img image.Image) error

Draw is a func type that draws a Layer

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) Cell

func (g *Grid) Cell(index int) (*Cell, error)

Cell returns a cell at a given index

func (*Grid) Cells

func (g *Grid) Cells() []*Cell

Cells returns all the cells

func (*Grid) Clear

func (g *Grid) Clear() error

Clear removes cells and regenerates them

func (*Grid) DrawToBase

func (g *Grid) DrawToBase(base board.Canvas) error

DrawToBase draws the cells onto a base parent canvas

func (*Grid) FillPadded

func (g *Grid) FillPadded(canvas board.Canvas, clr color.Color)

FillPadded fills the cell padding with a color

func (*Grid) GetCol

func (g *Grid) GetCol(col int) []*Cell

GetCol gets all the cells in a given column

func (*Grid) GetRow

func (g *Grid) GetRow(row int) []*Cell

GetRow get all the cells in the given row

func (*Grid) NumCols

func (g *Grid) NumCols() int

NumCols ...

func (*Grid) NumRows

func (g *Grid) NumRows() int

NumRows ...

type GridOption

type GridOption func(grid *Grid) error

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

func NewLayer

func NewLayer(prepare Prepare, draw Draw) *Layer

NewLayer ...

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

func NewLayerDrawer(timeout time.Duration, log *zap.Logger) (*LayerDrawer, error)

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 ...

func (*LayerDrawer) ClearLayers

func (l *LayerDrawer) ClearLayers()

ClearLayers ...

func (*LayerDrawer) Draw

func (l *LayerDrawer) Draw(ctx context.Context, canvas board.Canvas) error

Draw draws each layer. It does each priority level concurrently

func (*LayerDrawer) Prepare

func (l *LayerDrawer) Prepare(ctx context.Context) error

Prepare runs the prepare func of each layer concurrently

type Prepare

type Prepare func(ctx context.Context) (image.Image, error)

Prepare is a func type for preparing a Layer for drawing

type TextLayer

type TextLayer struct {
	// contains filtered or unexported fields
}

TextLayer writes text onto a board.Canvas

func NewTextLayer

func NewTextLayer(prepare TextPrepare, write Write) *TextLayer

NewTextLayer ...

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 DefaultTextWriter

func DefaultTextWriter() (*TextWriter, error)

DefaultTextWriter ...

func NewTextWriter

func NewTextWriter(font *truetype.Font, fontSize float64) *TextWriter

NewTextWriter ...

func (*TextWriter) BreakText

func (t *TextWriter) BreakText(canvas draw.Image, maxPixWidth int, text string) ([]string, error)

BreakText breaks text into lines based on a max pixel width

func (*TextWriter) MaxChars

func (t *TextWriter) MaxChars(canvas draw.Image, pixWidth int) (int, error)

MaxChars returns the maximum number of characters that can fit a given pixel width

func (*TextWriter) MeasureStrings

func (t *TextWriter) MeasureStrings(canvas draw.Image, str []string) ([]int, error)

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

type Write

type Write func(canvas board.Canvas, writer *TextWriter, text []string) error

Write is a func type that draws a TextLayer

Jump to

Keyboard shortcuts

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