render

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 37 Imported by: 8

Documentation

Overview

Package render provides structures for organizing graphics to draw to a window and essential graphical primitives.

Index

Examples

Constants

View Source
const (
	// Undraw is a layer representing elements that should be undrawn, or removed
	// from the draw stack. This is exported in the rare case that there is
	// a need to use the default value for something else.
	Undraw = -1000
)

Variables

View Source
var (
	// DefFontGenerator is a default font generator, using an internally
	// compiled font colored white by default.
	//
	// Deprecated: use DefaultFontGenerator instead
	DefFontGenerator = FontGenerator{
		Color:   image.White,
		RawFile: luxisrTTF,
	}
	// DefaultFontGenerator is a default font generator, using an internally
	// compiled font colored white by default.
	DefaultFontGenerator = DefFontGenerator
)
View Source
var (
	//HorizontalProgress measures progress as x / w
	HorizontalProgress = func(x, y, w, h int) float64 {
		return float64(x) / float64(w)
	}
	//VerticalProgress measures progress as y / h
	VerticalProgress = func(x, y, w, h int) float64 {
		return float64(y) / float64(h)
	}
	//CircularProgress measures progress as distance from the center of a circle.
	CircularProgress = func(x, y, w, h int) float64 {
		xRadius := float64(w) / 2
		yRadius := float64(h) / 2
		dX := math.Abs(float64(x) - xRadius)
		dY := math.Abs(float64(y) - yRadius)
		progress := math.Pow(dX/xRadius, 2) + math.Pow(dY/yRadius, 2)
		if progress > 1 {
			progress = 1
		}
		return progress
	}
)

Progress functions

View Source
var DefaultCache = NewCache()

DefaultCache is the receiver for package level sprites, sheets, and font loading operations.

View Source
var (
	// GlobalDrawStack is the stack that all draw calls are sent through.
	GlobalDrawStack = NewDrawStack(NewDynamicHeap())
)

Functions

func BatchLoad

func BatchLoad(baseFolder string) error

BatchLoad loads subdirectories from the given base folder and imports all files, using alias rules to automatically determine the size of sprites and sheets in subfolders.

func BlankBatchLoad

func BlankBatchLoad(baseFolder string, maxFileSize int64) error

BlankBatchLoad acts like BatchLoad, but will not load and instead return a blank image of the appropriate dimensions for anything above maxFileSize.

func DrawCircle

func DrawCircle(rgba *image.RGBA, c color.Color, radius, thickness float64, offsets ...float64)

DrawCircle draws a circle on the input rgba, of color c.

func DrawCurve

func DrawCurve(rgba *image.RGBA, c color.Color, radius, thickness,
	initialAngle, circlePercentage float64, offsets ...float64)

DrawCurve draws a curve inward on the input rgba, of color c.

func DrawGradientLine

func DrawGradientLine(rgba *image.RGBA, x1, y1, x2, y2 int, c1, c2 color.Color, thickness int)

DrawGradientLine acts like DrawThickLine but also applies a gradient to the line

func DrawImage

func DrawImage(buff draw.Image, img image.Image, x, y int)

DrawImage performs a draw operation at -x, -y, because shiny/screen represents quadrant 4 as negative in both axes. draw.Over will merge two pixels at a given position based on their alpha channel.

func DrawLine

func DrawLine(rgba *image.RGBA, x1, y1, x2, y2 int, c color.Color)

DrawLine draws a line onto an image rgba from one point to another

func DrawLineColored

func DrawLineColored(rgba *image.RGBA, x1, y1, x2, y2, thickness int, colorer Colorer)

DrawLineColored acts like DrawThickLine, but takes in a custom colorer function for how it draws its line.

func DrawThickLine

func DrawThickLine(rgba *image.RGBA, x1, y1, x2, y2 int, c color.Color, thickness int)

DrawThickLine acts like DrawlineOnto, but takes in thickness of the given line

func FontColor

func FontColor(s string) (image.Image, error)

FontColor returns an image.Image color matching the SVG 1.1 spec. If the string does not align to a color in the spec, it will error.

func GetFont

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

GetFont calls GetFont on the Default Cache.

func GradientColorAt

func GradientColorAt(c1, c2 color.Color, progress float64) color.RGBA64

GradientColorAt returns a new color via a gradient between two colors and the progress between them

func LoadFont

func LoadFont(file string) (*truetype.Font, error)

LoadFont calls LoadFont on the Default Cache.

func OverwriteImage

func OverwriteImage(buff draw.Image, img image.Image, x, y int)

OverwriteImage is equivalent to ShinyDraw, but uses draw.Src draw.Src will overwrite pixels beneath the given image regardless of the new image's alpha.

func RegisterCfgDecoder

func RegisterCfgDecoder(ext string, decoder CfgDecoder) error

RegisterCfgDecoder acts like RegisterDecoder for CfgDecoders

func RegisterDecoder

func RegisterDecoder(ext string, decoder Decoder) error

RegisterDecoder adds a decoder to the set of image decoders for file loading. If the extension string is already set, the existing decoder will not be overwritten.

func SetDrawStack

func SetDrawStack(stackLayers ...Stackable)

SetDrawStack takes in a set of Stackables which act as the Drawstack available and resets how calls to Draw will act. If this is called mid scene, all elements on the existing draw stack will be lost.

func Tween

func Tween(start image.Image, end image.Image, frames int) []*image.RGBA

Tween takes two images and returns a set of images tweening between the two over some number of frames

Types

type Cache

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

Cache is a simple image data cache

func NewCache

func NewCache() *Cache

NewCache returns an empty Cache

func (*Cache) Clear

func (c *Cache) Clear(key string)

Clear will remove elements matching the given key from the Cache.

func (*Cache) ClearAll

func (c *Cache) ClearAll()

ClearAll will remove all elements from a Cache

func (*Cache) GetFont

func (c *Cache) GetFont(file string) (*truetype.Font, error)

GetFont returns a cached font, or an error if the font is not cached.

func (*Cache) GetSheet

func (c *Cache) GetSheet(fileName string) (*Sheet, error)

GetSheet tries to find the given file in the set of loaded sheets. If SheetIsLoaded(filename) is not true, this returns an error. Otherwise it will return the sheet as a 2d array of sprites

func (*Cache) GetSprite

func (c *Cache) GetSprite(file string) (*Sprite, error)

GetSprite tries to find the given file in a private set of loaded sprites. If that file isn't cached, it will return an error.

func (*Cache) LoadFont

func (c *Cache) LoadFont(file string) (*truetype.Font, error)

LoadFont loads the given font file, parses it, and caches it under its full path and its final path element.

func (*Cache) LoadSheet

func (c *Cache) LoadSheet(file string, cellSize intgeom.Point2) (*Sheet, error)

LoadSheet loads a file in some directory with sheets of (w,h) sized sprites. This will blow away any cached sheet with the same fileName.

func (*Cache) LoadSprite

func (c *Cache) LoadSprite(file string) (*Sprite, error)

LoadSprite will load the given file as an image by combining directory and fileName. The resulting image, if found, will be cached under its last path element for later access through GetSprite.

type CanPause

type CanPause interface {
	Pause()
	Unpause()
}

CanPause types have pause functions to start and stop animation

type CfgDecoder

type CfgDecoder func(io.Reader) (image.Config, error)

CfgDecoder is an equivalent to Decoder that just exports the color model and dimensions of the image.

type ColorBoxR added in v3.2.0

type ColorBoxR struct {
	LayeredPoint
	Dims  intgeom.Point2
	Color *image.Uniform
}

ColorBoxR is a renderable color box. It is a smaller structure and should render faster than a ColorBoxM.

func NewColorBoxR added in v3.2.0

func NewColorBoxR(w, h int, c color.Color) *ColorBoxR

NewColorBoxR creates a color box. Colorboxes made without using this constructor may not function.

func (*ColorBoxR) Draw added in v3.2.0

func (cb *ColorBoxR) Draw(buff draw.Image, xOff, yOff float64)

Draw renders this colorbox to screen.

func (*ColorBoxR) GetDims added in v3.2.0

func (cb *ColorBoxR) GetDims() (int, int)

GetDims returns the dimensiosn of this colorbox

type Colorer

type Colorer func(float64) color.Color

A Colorer takes some notion of linear progress and returns a color

func IdentityColorer

func IdentityColorer(c color.Color) Colorer

IdentityColorer returns the same color it was given at initialization, regardless of progress.

type CompositeM

type CompositeM struct {
	LayeredPoint
	// contains filtered or unexported fields
}

CompositeM Types display all of their parts at the same time, and respect the positions of their parts as relative to the position of the composite itself

func NewCompositeM

func NewCompositeM(sl ...Modifiable) *CompositeM

NewCompositeM creates a CompositeM

func (*CompositeM) AddOffset

func (cs *CompositeM) AddOffset(i int, p floatgeom.Point2)

AddOffset offsets all renderables in the CompositeM by a vector

func (*CompositeM) Append

func (cs *CompositeM) Append(r Modifiable)

Append adds a renderable as is to the CompositeM

func (*CompositeM) AppendOffset

func (cs *CompositeM) AppendOffset(r Modifiable, p floatgeom.Point2)

AppendOffset adds a new offset modifiable to the CompositeM

func (*CompositeM) Copy

func (cs *CompositeM) Copy() Modifiable

Copy makes a new CompositeM with the same renderables

func (*CompositeM) Draw

func (cs *CompositeM) Draw(buff draw.Image, xOff, yOff float64)

Draw draws the CompositeM with some offset from its logical position (and therefore sub renderables logical positions).

func (*CompositeM) Filter

func (cs *CompositeM) Filter(fs ...mod.Filter)

Filter filters each component part of this CompositeM by all of the inputs.

func (*CompositeM) Get

func (cs *CompositeM) Get(i int) Modifiable

Get returns a renderable at the given index within the CompositeM

func (*CompositeM) GetRGBA

func (cs *CompositeM) GetRGBA() *image.RGBA

GetRGBA always returns nil from Composites

func (*CompositeM) Len

func (cs *CompositeM) Len() int

Len returns the number of renderables in this CompositeM.

func (*CompositeM) Modify

func (cs *CompositeM) Modify(ms ...mod.Mod) Modifiable

Modify applies mods to the CompositeM

func (*CompositeM) Prepend

func (cs *CompositeM) Prepend(r Modifiable)

Prepend adds a new renderable to the front of the CompositeMR.

func (*CompositeM) SetIndex

func (cs *CompositeM) SetIndex(i int, r Modifiable)

SetIndex places a renderable at a certain point in the CompositeMs renderable slice

func (*CompositeM) SetOffsets

func (cs *CompositeM) SetOffsets(vs ...floatgeom.Point2)

SetOffsets applies the initial offsets to the entire CompositeM

func (*CompositeM) Slice

func (cs *CompositeM) Slice(start, end int) *CompositeM

Slice creates a new CompositeM as a subslice of the existing CompositeM. No Modifiables will be copied, and the original will not be modified.

func (*CompositeM) ToSprite

func (cs *CompositeM) ToSprite() *Sprite

ToSprite converts the composite into a sprite by drawing each layer in order and overwriting lower layered pixels

func (*CompositeM) Undraw

func (cs *CompositeM) Undraw()

Undraw stops the CompositeM from being drawn

type CompositeR

type CompositeR struct {
	LayeredPoint
	// contains filtered or unexported fields
}

A CompositeR is equivalent to a CompositeM for Renderables instead of Modifiables. CompositeRs also implements Stackable.

func NewCompositeR

func NewCompositeR(sl ...Renderable) *CompositeR

NewCompositeR creates a new CompositeR from a slice of renderables

func (*CompositeR) Add

func (cs *CompositeR) Add(r Renderable, _ ...int) Renderable

Add stages a renderable to be added to the Composite at the next PreDraw

func (*CompositeR) AddOffset

func (cs *CompositeR) AddOffset(i int, p floatgeom.Point2)

AddOffset adds an offset to a given renderable of the slice

func (*CompositeR) Append

func (cs *CompositeR) Append(r Renderable)

Append adds a new renderable to the end of the CompositeR.

func (*CompositeR) AppendOffset

func (cs *CompositeR) AppendOffset(r Renderable, p floatgeom.Point2)

AppendOffset adds a new renderable to CompositeR with an offset

func (*CompositeR) Clear

func (cs *CompositeR) Clear()

Clear resets a composite to be empty.

func (*CompositeR) Copy

func (cs *CompositeR) Copy() Stackable

Copy returns a new composite with the same length slice of renderables but no actual renderables... CompositeRs cannot have their internal elements copied, as renderables cannot be copied.

func (*CompositeR) Draw

func (cs *CompositeR) Draw(buff draw.Image, xOff, yOff float64)

Draw Draws the CompositeR with an offset from its logical location.

func (*CompositeR) DrawToScreen

func (cs *CompositeR) DrawToScreen(world draw.Image, viewPos *intgeom.Point2, screenW, screenH int)

DrawToScreen draws the elements in this composite to the given screen image.

func (*CompositeR) Get

func (cs *CompositeR) Get(i int) Renderable

Get returns renderable from a given index in CompositeR

func (*CompositeR) GetRGBA

func (cs *CompositeR) GetRGBA() *image.RGBA

GetRGBA always returns nil from Composites

func (*CompositeR) Len

func (cs *CompositeR) Len() int

Len returns the number of renderables in this composite.

func (*CompositeR) PreDraw

func (cs *CompositeR) PreDraw()

PreDraw updates the CompositeR with the new renderables to add. This helps keep consistency and mitigates the threat of unsafe operations.

func (*CompositeR) Prepend

func (cs *CompositeR) Prepend(r Renderable)

Prepend adds a new renderable to the front of the CompositeR.

func (*CompositeR) Replace

func (cs *CompositeR) Replace(old, new Renderable, i int)

Replace updates a renderable in the CompositeR to the new Renderable

func (*CompositeR) SetIndex

func (cs *CompositeR) SetIndex(i int, r Renderable)

SetIndex places a renderable at a certain point in the composites renderable slice

func (*CompositeR) SetOffsets

func (cs *CompositeR) SetOffsets(ps ...floatgeom.Point2)

SetOffsets sets all renderables in CompositeR to the passed in Vector positions positions

func (*CompositeR) ToSprite

func (cs *CompositeR) ToSprite() *Sprite

ToSprite converts the composite into a sprite by drawing each layer in order and overwriting lower layered pixels

func (*CompositeR) Undraw

func (cs *CompositeR) Undraw()

Undraw undraws the CompositeR and its consituent renderables

type Decoder

type Decoder func(io.Reader) (image.Image, error)

Decoder functions convert arbitrary readers to images. The input of a decoder in oak's loader will generally be an image file.

type DrawFPS

type DrawFPS struct {
	*Text

	Smoothing float64
	// contains filtered or unexported fields
}

DrawFPS is a Renderable that will display how fast it is rendered. If it is a part of a dynamically ordered stackable, like a Heap, how fast it will be rendered can change in each iteration of the stackable's draw. For this reason, its recommended to isolate a DrawFPS to its own stack layer or layer within a heap.

func NewDrawFPS

func NewDrawFPS(smoothing float64, font *Font, x, y float64) *DrawFPS

NewDrawFPS returns a DrawFPS, which will render a counter of how fast it is being drawn. If font is not provided, DefaultFont is used. If smoothing is 0, a reasonable default will be used.

func (*DrawFPS) Draw

func (df *DrawFPS) Draw(buff draw.Image, xOff, yOff float64)

Draw renders a DrawFPS to a buffer.

type DrawStack

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

The DrawStack is a stack with a safe adding mechanism that creates isolation between draw steps via predraw

func NewDrawStack

func NewDrawStack(stack ...Stackable) *DrawStack

NewDrawStack creates a DrawStack with the given stackable items, drawn in descending index order.

func (*DrawStack) Clear

func (ds *DrawStack) Clear()

Clear clears all stackables in a draw stack. This should revert the stack to contain no renderable components.

func (*DrawStack) Copy

func (ds *DrawStack) Copy() *DrawStack

Copy creates a new deep copy of a Drawstack

func (*DrawStack) Draw

func (ds *DrawStack) Draw(r Renderable, layers ...int) (Renderable, error)

Draw adds the given renderable to the draw stack at the appropriate position based on the input layers. See render.Draw.

func (*DrawStack) DrawToScreen

func (ds *DrawStack) DrawToScreen(world draw.Image, view *intgeom.Point2, w, h int)

DrawToScreen on a stack will render its contents to the input buffer, for a screen of w,h dimensions, from a view point of view.

func (*DrawStack) Pop

func (ds *DrawStack) Pop()

Pop pops an element from the stack at the next PreDraw call.

func (*DrawStack) PreDraw

func (ds *DrawStack) PreDraw()

PreDraw performs whatever processes need to occur before this can be drawn. In the case of the stack, it enacts previous Push and Pop calls, and signals to elements on the stack to also prepare to be drawn.

func (*DrawStack) Push

func (ds *DrawStack) Push(a Stackable)

Push appends a Stackable to the draw stack during the next PreDraw.

type Font

type Font struct {
	font.Drawer

	Unsafe bool

	Fallbacks []*Font
	// contains filtered or unexported fields
}

A Font can create text renderables. It should be constructed from FontGenerator.Generate().

func DefaultFont

func DefaultFont() *Font

DefaultFont returns a font built from DefFontGenerator.

func (*Font) Copy

func (f *Font) Copy() *Font

Copy returns a copy of this font

func (*Font) Height

func (f *Font) Height() float64

Height returns the height or size of the font

func (*Font) MeasureString

func (f *Font) MeasureString(s string) fixed.Int26_6

MeasureString calculates the width of a rendered text this font would draw from the given input string.

func (*Font) NewIntText

func (f *Font) NewIntText(str *int, x, y float64) *Text

NewIntText wraps the given int pointer in a stringer interface

func (*Font) NewStrPtrText

func (f *Font) NewStrPtrText(str *string, x, y float64) *Text

NewStrPtrText creates a renderable text component with a body matching and updating to match the content behind the provided string pointer

func (*Font) NewStringerText

func (f *Font) NewStringerText(str fmt.Stringer, x, y float64) *Text

NewStringerText creates a renderable text component that will draw the string provided by the given stringer each frame.

func (*Font) NewText

func (f *Font) NewText(str string, x, y float64) *Text

NewText creates a renderable text component with the given string body

func (*Font) RegenerateWith

func (f *Font) RegenerateWith(fgFunc func(FontGenerator) FontGenerator) (*Font, error)

RegenerateWith creates a new font based on this font after changing its generation settings.

type FontGenerator

type FontGenerator struct {
	Cache   *Cache
	File    string
	RawFile []byte
	Color   image.Image
	// FontOptions holds all optional font components. Reasonable defaults
	// will be used if these are not provided.
	FontOptions
}

A FontGenerator stores information that can be used to create a font

func (*FontGenerator) Generate

func (fg *FontGenerator) Generate() (*Font, error)

Generate generates a font. File or RawFile and Color must be provided. If Cache and File are provided, the generated font will be stored in the provided cache. If Cache is not provided, it will default to DefaultCache.

func (FontGenerator) RegenerateWith

func (fg FontGenerator) RegenerateWith(fgFunc func(FontGenerator) FontGenerator) (*Font, error)

RegenerateWith creates a new font off of this generator after changing its generation settings.

type FontOptions

type FontOptions = truetype.Options

FontOptions are optional options used in font generation.

type InterruptBool

type InterruptBool struct {
	Interruptable bool
}

InterruptBool is a composable struct for NonInterruptable support

func (InterruptBool) IsInterruptable

func (ib InterruptBool) IsInterruptable() bool

IsInterruptable returns whether this can be interrupted.

type Layer

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

A Layer object has a draw layer

func (*Layer) GetLayer

func (ld *Layer) GetLayer() int

GetLayer returns the layer of an object if it has one or else returns that the object needs to be undrawn

func (*Layer) SetLayer

func (ld *Layer) SetLayer(l int)

SetLayer sets an object's layer

func (*Layer) Undraw

func (ld *Layer) Undraw()

Undraw sets that a Layer object should be undrawn

type Layered

type Layered interface {
	GetLayer() int
	SetLayer(l int)
	Undraw()
}

Layered types know the order they should be drawn in relative to other layered types. Higher layers are drawn after lower layers, and so will appear on top of them. Drawn layers are anticipated to be all positive.

Basic Implementing struct: Layer

type LayeredPoint

type LayeredPoint struct {
	physics.Vector
	Layer
}

A LayeredPoint is an object with a position Vector and a layer

func NewLayeredPoint

func NewLayeredPoint(x, y float64, l int) LayeredPoint

NewLayeredPoint creates a new LayeredPoint at a given location and layer

func (*LayeredPoint) Copy

func (ldp *LayeredPoint) Copy() LayeredPoint

Copy deep copies the LayeredPoint

func (*LayeredPoint) GetDims

func (ldp *LayeredPoint) GetDims() (int, int)

GetDims returns the dimensions of this object. As a single point, LayeredPoint returns (1,1).

func (*LayeredPoint) GetLayer

func (ldp *LayeredPoint) GetLayer() int

GetLayer returns the layer of this point. If this is nil, it will return Undraw

func (*LayeredPoint) SetPos

func (ldp *LayeredPoint) SetPos(x, y float64)

SetPos sets the LayeredPoint's position to the given x, y

func (*LayeredPoint) ShiftX

func (ldp *LayeredPoint) ShiftX(x float64)

ShiftX moves the LayeredPoint by the given x

func (*LayeredPoint) ShiftY

func (ldp *LayeredPoint) ShiftY(y float64)

ShiftY moves the LayeredPoint by the given y

type LogicFPS

type LogicFPS struct {
	event.CID
	*Text

	Smoothing float64
	// contains filtered or unexported fields
}

LogicFPS is a Stackable that will draw the logical fps onto the screen when a part of the draw stack.

func NewLogicFPS

func NewLogicFPS(smoothing float64, font *Font, x, y float64) *LogicFPS

NewLogicFPS returns a LogicFPS, which will render a counter of how fast it receives event.Enter events. If font is not provided, DefaultFont is used. If smoothing is 0, a reasonable default is used.

func (*LogicFPS) Init

func (lf *LogicFPS) Init() event.CID

Init satisfies event.Entity

type Modifiable

type Modifiable interface {
	Renderable
	GetRGBA() *image.RGBA
	Modify(...mod.Mod) Modifiable
	Filter(...mod.Filter)
	Copy() Modifiable
}

A Modifiable is a Renderable that has functions to change its underlying image.

func EmptyRenderable

func EmptyRenderable() Modifiable

EmptyRenderable returns a minimal, 1-width and height pseudo-nil Renderable (and Modifiable)

type NonInterruptable

type NonInterruptable interface {
	IsInterruptable() bool
}

NonInterruptable types are not always interruptable. If something is not NonInterruptable, it is equivalent to having IsInterruptable always return true.

The intended use of the Interruptable datatypes is entirely external-- oak does not use them internally. The use case is for an entity that has a set of potential animations, and attempts to switch from one animation to another. The Interuptable boolean should represent whether that animation should be able to be switched out of before it ends.

Because this use case is minor, this is a candidate for removal from render and moving into an auxiliary package.

Unless otherwise noted, all NonInterruptable types are interruptable when they are initialized and need to be switched (if the type supports it) to be non interruptable.

type NonStatic

type NonStatic interface {
	IsStatic() bool
}

NonStatic types are not always static. If something is not NonStatic, it is equivalent to having IsStatic always return true.

type NoopStackable

type NoopStackable struct{}

NoopStackable is a Stackable element where all methods are no-ops. Use for tests to disable rendering.

func (NoopStackable) Add

func (ns NoopStackable) Add(r Renderable, _ ...int) Renderable

Add on a NoopStackable does nothing. The input Renderable is still returned.

func (NoopStackable) Clear

func (ns NoopStackable) Clear()

Clear on a NoopStackable does nothing.

func (NoopStackable) Copy

func (ns NoopStackable) Copy() Stackable

Copy on a NoopStackable returns itself.

func (NoopStackable) DrawToScreen

func (ns NoopStackable) DrawToScreen(draw.Image, *intgeom.Point2, int, int)

DrawToScreen on a NoopStackable does nothing.

func (NoopStackable) PreDraw

func (ns NoopStackable) PreDraw()

PreDraw on a NoopStackable does nothing.

func (NoopStackable) Replace

func (ns NoopStackable) Replace(Renderable, Renderable, int)

Replace on a NoopStackable does nothing.

type Polygon

type Polygon struct {
	*Sprite
	floatgeom.Polygon2
}

A Polygon is a renderable that is represented by a set of in order points on a plane.

func NewPointsPolygon

func NewPointsPolygon(p1, p2, p3 floatgeom.Point2, pn ...floatgeom.Point2) *Polygon

NewPointsPolygon is a helper function for `NewPolygon(floatgeom.NewPolygon2(p1, p2, p3, pn...))`

func NewPolygon

func NewPolygon(poly floatgeom.Polygon2) *Polygon

NewPolygon constructs a renderable polygon. It will display nothing until Fill or FillInverse is called on it.

func (*Polygon) Fill

func (pg *Polygon) Fill(c color.Color)

Fill fills the inside of this polygon with the input color

func (*Polygon) FillInverse

func (pg *Polygon) FillInverse(c color.Color)

FillInverse colors this polygon's exterior the given color

func (*Polygon) GetColoredOutline

func (pg *Polygon) GetColoredOutline(colorer Colorer, thickness int) *CompositeM

GetColoredOutline returns a set of lines of the given color along this polygon's outline

func (*Polygon) GetGradientOutline

func (pg *Polygon) GetGradientOutline(c1, c2 color.Color, thickness int) *CompositeM

GetGradientOutline returns a set of lines of the given color along this polygon's outline, at the given thickness, ranging from c1 to c2 in color

func (*Polygon) GetOutline

func (pg *Polygon) GetOutline(c color.Color) *CompositeM

GetOutline returns a set of lines of the given color along this polygon's outline

func (*Polygon) GetThickOutline

func (pg *Polygon) GetThickOutline(c color.Color, thickness int) *CompositeM

GetThickOutline returns a set of lines of the given color along this polygon's outline, at the given thickness

type Positional

type Positional interface {
	X() float64
	Y() float64
	ShiftX(x float64)
	ShiftY(y float64)
	SetPos(x, y float64)
}

Positional types have 2D positions on a screen and can be manipulated to be in a certain position on that screen.

Basic Implementing struct: physics.Vector

type Renderable

type Renderable interface {
	Draw(buff draw.Image, xOff, yOff float64)
	GetDims() (width int, height int)

	Positional
	Layered
	physics.Attachable
}

A Renderable is anything which can be drawn at a given draw layer, undrawn, and set in a particular position.

Basic Implementing struct: Sprite

func Draw

func Draw(r Renderable, layers ...int) (Renderable, error)

Draw adds the given renderable to the global draw stack.

If the draw stack has only one stackable, the item will be added to that stackable with the input layers as its argument. Otherwise, the item will be added to the layers[0]th stackable, with remaining layers supplied to the stackable as arguments.

If zero layers are provided, it will add to the zeroth stack layer and give nothing to the stackable's argument.

Example
// We haven't modified the draw stack, so it contains a single draw heap.
// Draw a Color Box
Draw(NewColorBox(10, 10, color.RGBA{255, 255, 255, 255}), 3)
// Draw a Gradient Box above that color box
Draw(NewHorizontalGradientBox(5, 5, color.RGBA{255, 0, 0, 255}, color.RGBA{0, 255, 0, 255}), 4)
Output:

func DrawColor

func DrawColor(c color.Color, x, y, w, h float64, layers ...int) (Renderable, error)

DrawColor is equivalent to LoadSpriteAndDraw, but with colorboxes.

func DrawPoint

func DrawPoint(c color.Color, x1, y1 float64, layers ...int) (Renderable, error)

DrawPoint draws a color on the screen as a single-widthed pixel (box)

type RenderableHeap

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

A RenderableHeap manages a set of renderables to be drawn in explicit layered order, using an internal heap to manage that order. It implements Stackable.

func NewDynamicHeap

func NewDynamicHeap() *RenderableHeap

NewDynamicHeap creates a renderable heap for drawing renderables by layer where the position of the viewport is taken into account to produce the drawn location of the renderable.

Example: If drawing a Sprite at (100,100) with the viewport at (50,0), the sprite will appear at (50, 100).

func NewStaticHeap

func NewStaticHeap() *RenderableHeap

NewStaticHeap creates a renderable heap for drawing renderables by layer where the position of renderable is absolute with regards to the viewport.

Example: If drawing a Sprite at (100,100) with the viewport at (50,0), the sprite will appear at (100, 100).

func (*RenderableHeap) Add

func (rh *RenderableHeap) Add(r Renderable, layers ...int) Renderable

Add stages a new Renderable to add to the heap

func (*RenderableHeap) Clear

func (rh *RenderableHeap) Clear()

Clear empties out the heap.

func (*RenderableHeap) Copy

func (rh *RenderableHeap) Copy() Stackable

Copy on a renderableHeap does not include any of its elements, as renderables cannot be copied.

func (*RenderableHeap) DrawToScreen

func (rh *RenderableHeap) DrawToScreen(world draw.Image, viewPos *intgeom.Point2, screenW, screenH int)

DrawToScreen draws all elements in the heap to the screen.

func (*RenderableHeap) PreDraw

func (rh *RenderableHeap) PreDraw()

PreDraw parses through renderables to be pushed and adds them to the drawheap.

func (*RenderableHeap) Replace

func (rh *RenderableHeap) Replace(old, new Renderable, layer int)

Replace adds a Renderable and removes an old one

type Reverting

type Reverting struct {
	Modifiable
	// contains filtered or unexported fields
}

The Reverting structure lets modifications be made to a Modifiable and then reverted, up to arbitrary history limits.

func NewReverting

func NewReverting(m Modifiable) *Reverting

NewReverting returns a Reverting type wrapped around the given modifiable

func (*Reverting) Copy

func (rv *Reverting) Copy() Modifiable

Copy returns a copy of this Reverting

func (*Reverting) Filter

func (rv *Reverting) Filter(ms ...mod.Filter)

Filter alters this reverting by the given filters, appending the new modified renderable to it's list of modified versions and displaying it.

func (*Reverting) Get

func (rv *Reverting) Get() string

Get calls Get on the active renderable below this Reverting. If nothing has a Get method, it returns the empty string.

func (*Reverting) IsInterruptable

func (rv *Reverting) IsInterruptable() bool

IsInterruptable returns if whatever this reverting is currently dispalying is interruptable.

func (*Reverting) IsStatic

func (rv *Reverting) IsStatic() bool

IsStatic returns if whatever this reverting is currently displaying is static.

func (*Reverting) Modify

func (rv *Reverting) Modify(ms ...mod.Mod) Modifiable

Modify alters this reverting by the given modifications, appending the new modified renderable to it's list of modified versions and displaying it.

func (*Reverting) Pause

func (rv *Reverting) Pause()

Pause ceases animating any renderable types that animate underneath this

func (*Reverting) Revert

func (rv *Reverting) Revert(n int)

Revert goes back n steps in this Reverting's history and displays that Modifiable

func (*Reverting) RevertAll

func (rv *Reverting) RevertAll()

RevertAll resets this reverting to its original Modifiable

func (*Reverting) RevertAndFilter

func (rv *Reverting) RevertAndFilter(n int, fs ...mod.Filter) Modifiable

RevertAndFilter acts as RevertAndModify, but with Filters.

func (*Reverting) RevertAndModify

func (rv *Reverting) RevertAndModify(n int, ms ...mod.Mod) Modifiable

RevertAndModify reverts n steps and then modifies this reverting. This is a separate function from Revert followed by Modify to prevent skipped draw frames.

func (*Reverting) Set

func (rv *Reverting) Set(k string) error

Set calls Set on underlying types below this Reverting that can be Set Todo: if Set becomes used by more types, this should use an interface like CanPause

func (*Reverting) SetTriggerID

func (rv *Reverting) SetTriggerID(cid event.CID)

SetTriggerID sets the ID AnimationEnd will trigger on for animating subtypes.

func (*Reverting) Unpause

func (rv *Reverting) Unpause()

Unpause resumes animating any renderable types that animate underneath this

type Sequence

type Sequence struct {
	LayeredPoint

	InterruptBool
	// contains filtered or unexported fields
}

A Sequence is a series of modifiables drawn as an animation. It is more primitive than animation, but less efficient.

func NewSequence

func NewSequence(fps float64, mods ...Modifiable) *Sequence

NewSequence returns a new sequence from the input modifiables, playing at the given fps rate.

func NewSheetSequence

func NewSheetSequence(sheet *Sheet, fps float64, frames ...int) (*Sequence, error)

NewSheetSequence creates a Sequence from a sheet and a list of x,y frame coordinates. A sequence will be created by getting the sheet's [i][i+1]th elements incrementally from the input frames. If the number of input frames is uneven, an error is returned.

func TweenSequence

func TweenSequence(a, b image.Image, frames int, fps float64) *Sequence

TweenSequence returns a sequence that is the tweening between the input images at the given frame rate over the given frame count.

func (*Sequence) Copy

func (sq *Sequence) Copy() Modifiable

Copy copies each modifiable inside this sequence in order to produce a new copied sequence

func (*Sequence) Draw

func (sq *Sequence) Draw(buff draw.Image, xOff, yOff float64)

Draw draws this sequence at +xOff, +yOff

func (*Sequence) Filter

func (sq *Sequence) Filter(fs ...mod.Filter)

Filter filters each element in the sequence by the inputs

func (*Sequence) Get

func (sq *Sequence) Get(i int) Modifiable

Get returns the Modifiable stored at this sequence's ith index. If the sequence does not have an ith index this returns nil

func (*Sequence) GetDims

func (sq *Sequence) GetDims() (int, int)

GetDims of a Sequence returns the dims of the current Renderable for the sequence

func (*Sequence) GetRGBA

func (sq *Sequence) GetRGBA() *image.RGBA

GetRGBA returns the RGBA of the currently showing frame of this sequence

func (*Sequence) IsStatic

func (sq *Sequence) IsStatic() bool

IsStatic returns false for sequences

func (*Sequence) Modify

func (sq *Sequence) Modify(ms ...mod.Mod) Modifiable

Modify alters each renderable in this sequence by the given modifications

func (*Sequence) Pause

func (p *Sequence) Pause()

func (*Sequence) SetFPS

func (sq *Sequence) SetFPS(fps float64)

SetFPS sets the number of frames that should advance per second to be the input fps

func (*Sequence) SetTriggerID

func (sq *Sequence) SetTriggerID(id event.CID)

SetTriggerID sets the ID that AnimationEnd will be triggered on when this sequence loops over from its last frame to its first

func (*Sequence) Unpause

func (p *Sequence) Unpause()

type Sheet

type Sheet [][]*image.RGBA

Sheet is a 2D array of image rgbas

func GetSheet

func GetSheet(file string) (*Sheet, error)

GetSheet calls GetSheet on the Default Cache.

func LoadSheet

func LoadSheet(file string, cellSize intgeom.Point2) (*Sheet, error)

LoadSheet calls LoadSheet on the Default Cache.

func MakeSheet

func MakeSheet(rgba *image.RGBA, cellSize intgeom.Point2) (*Sheet, error)

MakeSheet converts an image into a sheet with cellSize sized sprites

func (*Sheet) SubSprite

func (sh *Sheet) SubSprite(x, y int) *Sprite

SubSprite gets a sprite from a sheet at the given location

func (*Sheet) ToSprites

func (sh *Sheet) ToSprites() [][]*Sprite

ToSprites returns this sheet as a 2D array of Sprites

type Sprite

type Sprite struct {
	LayeredPoint
	// contains filtered or unexported fields
}

A Sprite is a basic wrapper around image data and a point. The most basic Renderable.

func BezierLine

func BezierLine(b shape.Bezier, c color.Color) *Sprite

BezierLine converts a bezier into a line sprite.

func BezierThickLine

func BezierThickLine(b shape.Bezier, c color.Color, thickness int) *Sprite

BezierThickLine draws a BezierLine wrapping each colored pixel in a square of width and height = thickness

func GetSprite

func GetSprite(file string) (*Sprite, error)

GetSprite calls GetSprite on the Default Cache.

func LoadSprite

func LoadSprite(file string) (*Sprite, error)

LoadSprite calls LoadSprite on the Default Cache.

func NewCircle

func NewCircle(c color.Color, radius, thickness float64, offsets ...float64) *Sprite

NewCircle creates a sprite and draws a circle onto it

func NewCircularGradientBox

func NewCircularGradientBox(w, h int, startColor, endColor color.Color) *Sprite

NewCircularGradientBox returns a gradient box where the center will be startColor and the gradient will radiate as a circle out from the center.

func NewColorBox

func NewColorBox(w, h int, c color.Color) *Sprite

NewColorBox returns a Sprite full of a given color with the given dimensions Deprecated: Use NewColorboxM (for a Modifiable) or NewColorBoxR.

func NewColorBoxM added in v3.2.0

func NewColorBoxM(w, h int, c color.Color) *Sprite

NewColorBoxM returns a modifiable Color Box (as a Sprite)

func NewColoredLine

func NewColoredLine(x1, y1, x2, y2 float64, colorer Colorer, thickness int) *Sprite

NewColoredLine returns a line with a custom function for how each pixel in that line should be colored.

func NewEmptySprite

func NewEmptySprite(x, y float64, w, h int) *Sprite

NewEmptySprite returns a sprite of the given dimensions with a blank RGBA

func NewGradientBox

func NewGradientBox(w, h int, startColor, endColor color.Color, pFunction progressFunction) *Sprite

NewGradientBox returns a gradient box defined on the two input colors and the given progress function

func NewGradientLine

func NewGradientLine(x1, y1, x2, y2 float64, c1, c2 color.Color, thickness int) *Sprite

NewGradientLine returns a Line that has some value of thickness along with a start and end color

func NewHorizontalGradientBox

func NewHorizontalGradientBox(w, h int, startColor, endColor color.Color) *Sprite

NewHorizontalGradientBox returns a gradient box with a horizontal gradient from the start to end color, left to right.

func NewLine

func NewLine(x1, y1, x2, y2 float64, c color.Color) *Sprite

NewLine returns a line from x1,y1 to x2,y2 with the given color

func NewSprite

func NewSprite(x, y float64, r *image.RGBA) *Sprite

NewSprite creates a new sprite

func NewThickLine

func NewThickLine(x1, y1, x2, y2 float64, c color.Color, thickness int) *Sprite

NewThickLine returns a Line that has some value of thickness

func NewVerticalGradientBox

func NewVerticalGradientBox(w, h int, startColor, endColor color.Color) *Sprite

NewVerticalGradientBox returns a gradient box with a vertical gradient from the start to end color, top to bottom.

func OverlaySprites

func OverlaySprites(sps []*Sprite) *Sprite

OverlaySprites combines sprites together through masking to form a single sprite

func (*Sprite) At

func (s *Sprite) At(x, y int) color.Color

At returns the color of a given pixel location

func (*Sprite) Bounds

func (s *Sprite) Bounds() image.Rectangle

Bounds is an alternative to GetDims that alows a sprite to satisfy draw.Image.

func (*Sprite) ColorModel

func (s *Sprite) ColorModel() color.Model

ColorModel allows sprites to satisfy draw.Image. Returns color.RGBAModel.

func (*Sprite) Copy

func (s *Sprite) Copy() Modifiable

Copy returns a copy of this Sprite

func (*Sprite) Draw

func (s *Sprite) Draw(buff draw.Image, xOff, yOff float64)

Draw draws this sprite at +xOff, +yOff

func (*Sprite) Filter

func (s *Sprite) Filter(fs ...mod.Filter)

Filter filters this sprite's rgba on all the input filters

func (*Sprite) GetDims

func (s *Sprite) GetDims() (int, int)

GetDims returns the dimensions of this sprite, or if this sprite has no defined RGBA returns default values.

func (*Sprite) GetRGBA

func (s *Sprite) GetRGBA() *image.RGBA

GetRGBA returns the rgba behind this sprite

func (*Sprite) Modify

func (s *Sprite) Modify(ms ...mod.Mod) Modifiable

Modify takes in modifications (modify.go) and alters this sprite accordingly

func (*Sprite) Set

func (s *Sprite) Set(x, y int, c color.Color)

Set sets a color of a given pixel location

func (*Sprite) SetRGBA

func (s *Sprite) SetRGBA(r *image.RGBA)

SetRGBA will replace the rgba behind this sprite

type Stackable

type Stackable interface {
	PreDraw()
	Add(Renderable, ...int) Renderable
	Replace(Renderable, Renderable, int)
	Copy() Stackable
	DrawToScreen(draw.Image, *intgeom.Point2, int, int)
	Clear()
}

A Stackable can be put onto a draw stack. It usually manages how a subset of renderables are drawn.

type Switch

type Switch struct {
	LayeredPoint
	// contains filtered or unexported fields
}

The Switch type is intended for use to easily swap between multiple renderables that are drawn at the same position on the same layer. A common use case for this would be a character entitiy who switches their animation based on how they are moving or what they are doing, or a button that has changes state when selected or hovered over.

func NewSwitch

func NewSwitch(start string, m map[string]Modifiable) *Switch

NewSwitch creates a new Switch from a map of names to modifiables

func (*Switch) Add

func (c *Switch) Add(k string, v Modifiable) (err error)

Add makes a new entry in the Switch's map. If the key already existed, it will be overwritten and an error will be returned.

func (*Switch) Copy

func (c *Switch) Copy() Modifiable

Copy creates a copy of the Switch

func (*Switch) Draw

func (c *Switch) Draw(buff draw.Image, xOff float64, yOff float64)

Draw draws the Switch at an offset from its logical location

func (*Switch) Filter

func (c *Switch) Filter(fs ...mod.Filter)

Filter filters all elements of the Switch with fs

func (*Switch) Get

func (c *Switch) Get() string

Get returns the Switch's current key

func (*Switch) GetDims

func (c *Switch) GetDims() (int, int)

GetDims gets the current Renderables dimensions

func (*Switch) GetRGBA

func (c *Switch) GetRGBA() *image.RGBA

GetRGBA returns the current renderables rgba

func (*Switch) GetSub

func (c *Switch) GetSub(s string) Modifiable

GetSub returns a keyed Modifiable from this Switch's map

func (*Switch) IsInterruptable

func (c *Switch) IsInterruptable() bool

IsInterruptable returns whether the current renderable is interruptable

func (*Switch) IsStatic

func (c *Switch) IsStatic() bool

IsStatic returns whether the current renderable is static

func (*Switch) Modify

func (c *Switch) Modify(ms ...mod.Mod) Modifiable

Modify performs the input modifications on all elements of the Switch

func (*Switch) Pause

func (c *Switch) Pause()

Pause stops the current Renderable if possible

func (*Switch) Revert

func (c *Switch) Revert(mod int)

Revert will revert all parts of this Switch that can be reverted

func (*Switch) RevertAll

func (c *Switch) RevertAll()

RevertAll will revert all parts of this Switch that can be reverted, back to their original state.

func (*Switch) Set

func (c *Switch) Set(k string) error

Set sets the current renderable to the one specified

func (*Switch) SetOffsets

func (c *Switch) SetOffsets(k string, offsets physics.Vector)

SetOffsets sets the logical offset for the specified key

func (*Switch) SetTriggerID

func (c *Switch) SetTriggerID(cid event.CID)

SetTriggerID sets the ID AnimationEnd will trigger on for animating subtypes. Todo: standardize this with the other interface Set functions so that it also only acts on the current subRenderable, or the other way around, or somehow offer both options

func (*Switch) ShiftPos

func (c *Switch) ShiftPos(x, y float64)

ShiftPos shifts the Switch's logical position

func (*Switch) Unpause

func (c *Switch) Unpause()

Unpause tries to unpause the current Renderable if possible

type Text

type Text struct {
	LayeredPoint
	// contains filtered or unexported fields
}

A Text is a renderable that represents some text to print on screen

func NewIntText

func NewIntText(str *int, x, y float64) *Text

NewIntText wraps the given int pointer in a stringer interface and creates a text renderable that will diplay the underlying int value.

func NewStrPtrText

func NewStrPtrText(str *string, x, y float64) *Text

NewStrPtrText is a helper to take in a string pointer for NewText

func NewStringerText

func NewStringerText(str fmt.Stringer, x, y float64) *Text

NewStringerText creates a text element using the default font and a stringer.

func NewText

func NewText(str string, x, y float64) *Text

NewText is a helper to create a text element with the default font and a string.

func (*Text) Center

func (t *Text) Center()

Center will shift the text so that the existing leftmost point where the text sits becomes the center of the new text.

func (*Text) Draw

func (t *Text) Draw(buff draw.Image, xOff, yOff float64)

Draw for a text draws the text at its layeredPoint position

func (*Text) GetDims

func (t *Text) GetDims() (int, int)

GetDims reports the width and height of a text renderable

func (*Text) SetFont

func (t *Text) SetFont(f *Font)

SetFont sets the drawer which renders the text each frame

func (*Text) SetInt

func (t *Text) SetInt(i int)

SetInt takes and converts the input integer to a string to write

func (*Text) SetIntPtr

func (t *Text) SetIntPtr(i *int)

SetIntPtr takes in an integer pointer that will draw the integer behind the pointer, in base 10, each frame

func (*Text) SetString

func (t *Text) SetString(str string)

SetString accepts a string itself as the stringer to be written

func (*Text) SetStringPtr

func (t *Text) SetStringPtr(str *string)

SetStringPtr accepts a string pointer as the stringer to be written

func (*Text) SetStringer

func (t *Text) SetStringer(s fmt.Stringer)

SetStringer accepts an fmt.Stringer to write

func (*Text) StringLiteral

func (t *Text) StringLiteral() string

StringLiteral returns what text is currently rendering.

func (*Text) ToSprite

func (t *Text) ToSprite() *Sprite

ToSprite converts this text into a sprite, so that it is no longer modifiable in terms of its text content, but is modifiable in terms of mod.Transform or mod.Filter.

func (*Text) Wrap

func (t *Text) Wrap(charLimit int, vertInc float64) []*Text

Wrap returns the input text split into a list of texts spread vertically, splitting after each charLimit is reached. the input vertInc is how much each text in the slice will differ by in y value

type Triggerable

type Triggerable interface {
	SetTriggerID(event.CID)
}

Triggerable types can have an ID set so when their animations finish, they trigger AnimationEnd on that ID.

Directories

Path Synopsis
Package mod stores modification functions for images.
Package mod stores modification functions for images.
Package particle provides options for generating renderable particle sources.
Package particle provides options for generating renderable particle sources.

Jump to

Keyboard shortcuts

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