render

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package render provides several types of renderable entities which are used throughout the code base

In addition to entities the package also provides utilities to load images from files and load images from parts of files as well as draw them.

Index

Constants

View Source
const (
	// FpsSmoothing is how much of the fps of the upcoming frame is used
	// relative to the previous fps total when calculating the fps at a given
	// frame
	FpsSmoothing = .25
)
View Source
const (
	// Undraw is a constant used to represent the layer of elements
	// to be undrawn. 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 (
	//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 (

	// DefFontGenerator is a default font generator of no options
	DefFontGenerator = FontGenerator{}
)
View Source
var (
	// GlobalDrawStack is the stack that all draw calls are parsed through.
	GlobalDrawStack = &DrawStack{
		as: []Stackable{NewHeap(false)},
	}
)

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. A folder named 16x8 will have its images split into sheets where each sprite is 16x8, for example. 16 is a shorter way of writing 16x16. An alias.json file can be included that can indicate what dimensions named folders represent, so a "tiles": "32" field in the json would indicate that sprite sheets in the /tiles folder should be read as 32x32

func DrawCircle added in v1.3.0

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 added in v1.3.0

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 DrawForTime

func DrawForTime(r Renderable, d time.Duration, layers ...int) error

DrawForTime draws and after d undraws an element

func DrawGradientLine added in v1.3.0

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 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 added in v1.3.0

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 added in v1.1.0

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

FontColor accesses x/image/colornames and returns an image.Image for the input string. If the string is not defined in x/image/colornames, it will return defaultColor as defined by SetFontDefaults. The set of colors as defined by x/image/colornames matches the set of colors as defined by the SVG 1.1 spec.

func GradientColorAt added in v1.3.0

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(dir string, fontFile string) *truetype.Font

LoadFont loads in a font file and stores it with the given fontFile name. This is necessary before using that file in a generator, otherwise the default directory will be tried at generation time.

func PreDraw

func PreDraw()

PreDraw tries to reset the GlobalDrawStack or performs the GlobalDrawStack's predraw functions

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 ResetDrawStack

func ResetDrawStack()

ResetDrawStack resets the Global stack back to the initial stack

func SetAssetPaths

func SetAssetPaths(imagedir string)

SetAssetPaths sets the directories that files are loaded from when using the LoadSprite utility (and others). Oak will call this with SetupConfig.Assets joined with SetupConfig.Images after Init.

func SetDrawStack

func SetDrawStack(as ...Stackable)

SetDrawStack takes in a set of Addables which act as the set of Drawstacks 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 SetFontDefaults

func SetFontDefaults(wd, assetPath, fontPath, hinting, color, file string, size, dpi float64)

SetFontDefaults updates the default font parameters with the passed in arguments

func SheetIsLoaded

func SheetIsLoaded(fileName string) bool

SheetIsLoaded returns whether when LoadSheet is called, a cached sheet will be used, or if false that a new file will attempt to be loaded and stored

func ShinyDraw

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

ShinyDraw 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 ShinyOverwrite

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

ShinyOverwrite 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 ShinySet

func ShinySet(buff draw.Image, c color.Color, x, y int)

ShinySet sets on a buffer at -x, -y

func SpriteIsLoaded

func SpriteIsLoaded(fileName string) bool

SpriteIsLoaded returns whether, when LoadSprite is called, a cached sheet will be used, or if false that a new file will attempt to be loaded and stored

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

func UnloadAll

func UnloadAll()

UnloadAll resets the cached set of loaded sprites and sheets to empty.

func UpdateDebugMap

func UpdateDebugMap(rName string, r Renderable)

UpdateDebugMap stores a renderable under a name in a package global map. this is used by some built in debugConsole helper functions.

Types

type CanPause added in v1.0.3

type CanPause interface {
	Pause()
	Unpause()
}

CanPause types have pause functions to start and stop animation

type Colorer added in v1.3.0

type Colorer func(float64) color.Color

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

func IdentityColorer added in v1.3.0

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)

Draw draws the CompositeM at its logical position

func (*CompositeM) DrawOffset

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

DrawOffset 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 does not work on a CompositeM and therefore returns nil

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

func (cs *CompositeM) Undraw()

Undraw stops the CompositeM from being drawn

type CompositeR

type CompositeR struct {
	LayeredPoint

	DrawPolygon
	// contains filtered or unexported fields
}

A CompositeR is equivalent to a CompositeM for Renderables instead of Modifiables. CompositeRs can also be used as Draw Stack elements.

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

Draw draws the CompositeR at its logical location and therefore its consituent renderables as well

func (*CompositeR) DrawOffset

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

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

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 added in v1.5.0

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 added in v1.5.0

func (cs *CompositeR) Prepend(r Renderable)

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

func (*CompositeR) Replace

func (cs *CompositeR) Replace(r1, r2 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) 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 {
	// contains filtered or unexported fields
}

DrawFPS is a draw stack element that will draw the fps onto the screen

func NewDrawFPS

func NewDrawFPS() *DrawFPS

NewDrawFPS returns a zero-initialized DrawFPS

func (*DrawFPS) Add

func (df *DrawFPS) Add(Renderable, ...int) Renderable

Add does nothing for a drawFPS

func (*DrawFPS) Copy

func (df *DrawFPS) Copy() Stackable

Copy does effectively nothing for a drawFPS

func (*DrawFPS) PreDraw

func (df *DrawFPS) PreDraw()

PreDraw does nothing for a drawFPS

func (*DrawFPS) Replace

func (df *DrawFPS) Replace(Renderable, Renderable, int)

Replace does nothing for a drawFPS

type DrawPolygon

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

A DrawPolygon is used to determine wheter elements should be drawn, defining a polygonal area for what things should be visible.

func (*DrawPolygon) ClearDrawPolygon

func (dp *DrawPolygon) ClearDrawPolygon()

ClearDrawPolygon will stop checking the set draw polygon for whether elements should be drawn to screen. If SetDrawPolygon was not called before this was called, this does nothing. This may in the future be called at the start of new scenes.

func (*DrawPolygon) DrawPolygonDim

func (dp *DrawPolygon) DrawPolygonDim() floatgeom.Rect2

DrawPolygonDim returns the dimensions of this draw polygon, or (0,0)->(0,0) if there is no draw polygon in use.

func (*DrawPolygon) InDrawPolygon

func (dp *DrawPolygon) InDrawPolygon(xi, yi, x2i, y2i int) bool

InDrawPolygon returns whehter a coordinate and dimension set should be drawn given the draw polygon

func (*DrawPolygon) SetDrawPolygon

func (dp *DrawPolygon) SetDrawPolygon(p polyclip.Polygon)

SetDrawPolygon sets the draw polygon and flags that draw functions should check for containment in the polygon before drawing elements

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 (*DrawStack) Copy

func (ds *DrawStack) Copy() *DrawStack

Copy creates a new deep copy of a Drawstack

func (*DrawStack) Draw

func (ds *DrawStack) Draw(world draw.Image, view image.Point, w, h int)

Draw 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 {
	FontGenerator
	font.Drawer
	// contains filtered or unexported fields
}

A Font is obtained as the result of FontGenerator.Generate(). It's used to create text type renderables.

func DefFont

func DefFont() *Font

DefFont returns a font built of the parameters set by SetFontDefaults.

func (*Font) Copy

func (f *Font) Copy() *Font

Copy returns a copy of this font

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

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

NewStrText is a helper to take in a string instead of a stringer for NewText

func (*Font) NewText

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

NewText takes in anything that has a String() function and returns a text object with the associated font and screen position

func (*Font) Refresh

func (f *Font) Refresh()

Refresh regenerates this font

func (*Font) Reset

func (f *Font) Reset()

Reset sets the font to being a default font

type FontGenerator

type FontGenerator struct {
	File    string
	Color   image.Image
	Size    float64
	Hinting string
	DPI     float64
}

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

func (*FontGenerator) Copy

func (fg *FontGenerator) Copy() *FontGenerator

Copy creates a copy of this FontGenerator

func (*FontGenerator) Generate

func (fg *FontGenerator) Generate() *Font

Generate creates a font from the FontGenerator. Any parameters not supplied will be filled in with defaults set through SetFontDefaults.

type FontManager

type FontManager map[string]*Font

A FontManager is just a map for fonts that contains a default font

func NewFontManager

func NewFontManager() *FontManager

NewFontManager returns a FontManager where 'def' is the default font

func (*FontManager) Get

func (fm *FontManager) Get(name string) *Font

Get retrieves a font from a manager

func (*FontManager) NewFont

func (fm *FontManager) NewFont(name string, fg FontGenerator) error

NewFont adds to the font manager and potentially returns if the key was already defined in the map

type InterruptBool added in v1.4.0

type InterruptBool struct {
	Interruptable bool
}

InterruptBool is a composable struct for NonInterruptable support

func (InterruptBool) IsInterruptable added in v1.4.0

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 NewLayer

func NewLayer(layer int) Layer

NewLayer returns a wrapper around a draw layer integer

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 that has a layer to the given 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. Layers are anticipated to be all positive, and if this is not true the Undraw constant should be changed. Failing to change the Undraw constant to something outside of the range of the set of valid layers could result in unanticipated undrawn renderables.

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 a static small amount so that polygon containment does not throw errors

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
	// contains filtered or unexported fields
}

LogicFPS is a draw stack element that will draw the logical fps onto the screen

func NewLogicFPS

func NewLogicFPS() *LogicFPS

NewLogicFPS returns a zero-initialized LogicFPS

func (*LogicFPS) Add

func (lf *LogicFPS) Add(Renderable, ...int) Renderable

Add does nothing for a drawFPS

func (*LogicFPS) Copy

func (lf *LogicFPS) Copy() Stackable

Copy does effectively nothing for a drawFPS

func (*LogicFPS) Init

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

Init satisfies event.Entity

func (*LogicFPS) PreDraw

func (lf *LogicFPS) PreDraw()

PreDraw does nothing for a drawFPS

func (*LogicFPS) Replace

func (lf *LogicFPS) Replace(Renderable, Renderable, int)

Replace does nothing for a drawFPS

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 added in v1.0.3

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

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

type NonStatic added in v1.0.3

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 Polygon

type Polygon struct {
	*Sprite
	Rect2 floatgeom.Rect2
	// contains filtered or unexported fields
}

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

func NewPolygon

func NewPolygon(points ...floatgeom.Point2) (*Polygon, error)

NewPolygon takes in a set of points and returns a polygon. At least three points must be provided.

func NewStrictPolygon

func NewStrictPolygon(bounds floatgeom.Rect2, points ...floatgeom.Point2) (*Polygon, error)

NewStrictPolygon will draw a polygon of points within a given rectangle, and if the input points lie outside of that rectangle the polygon will clip into and not be drawn outside of that border.

func (*Polygon) Contains

func (pg *Polygon) Contains(x, y float64) (contains bool)

Contains returns whether or not the current Polygon contains the passed in Point. It is the default containment function, versus wrapping and convex.

func (*Polygon) ConvexContains

func (pg *Polygon) ConvexContains(x, y float64) bool

ConvexContains returns whether the given point is contained by the input polygon. It assumes the polygon is convex. It outperforms the alternatives.

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

func (pg *Polygon) UpdatePoints(points ...floatgeom.Point2) error

UpdatePoints resets the points of this polygon to be the passed in points

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)
	DrawOffset(buff draw.Image, xOff, yOff float64)
	GetDims() (int, 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 l[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.

func DrawColor

func DrawColor(c color.Color, x1, y1, x2, y2 float64, layers ...int) (Renderable, error)

DrawColor is equivalent to LoadSpriteAndDraw, but with colorboxes.

func GetDebugRenderable

func GetDebugRenderable(rName string) (Renderable, bool)

GetDebugRenderable returns whatever renderable is stored under the input string, if any.

func LoadSpriteAndDraw

func LoadSpriteAndDraw(filename string, layers ...int) (Renderable, error)

LoadSpriteAndDraw is shorthand for LoadSprite followed by Draw.

type RenderableHeap

type RenderableHeap struct {
	DrawPolygon
	// 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.

func NewHeap

func NewHeap(static bool) *RenderableHeap

NewHeap creates a new renderableHeap. The static boolean represents whether this heap exists relative to the viewport or not-- if true, an element at 40,40 will always be at 40,40. If false, when the viewport moves, the element will move opposite the direction of the viewport.

func (*RenderableHeap) Add

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

Add stages a new Renderable to add to 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) Len

func (rh *RenderableHeap) Len() int

Satisfying the Heap interface Len gets the length of the current heap

func (*RenderableHeap) Less

func (rh *RenderableHeap) Less(i, j int) bool

Less returns whether a renderable at index i is at a lower layer than the one at index j

func (*RenderableHeap) Pop

func (rh *RenderableHeap) Pop() interface{}

Pop pops from the heap

func (*RenderableHeap) PreDraw

func (rh *RenderableHeap) PreDraw()

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

func (*RenderableHeap) Push

func (rh *RenderableHeap) Push(r interface{})

Push adds to the renderable heap

func (*RenderableHeap) Replace

func (rh *RenderableHeap) Replace(r1, r2 Renderable, layer int)

Replace adds a Renderable and removes an old one

func (*RenderableHeap) Swap

func (rh *RenderableHeap) Swap(i, j int)

Swap moves two locations

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) 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 cat be Set Todo: if Set becomes used by more types, this should use an interface like CanPause

func (*Reverting) SetTriggerID added in v1.3.0

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 ScrollBox

type ScrollBox struct {
	*Sprite

	Rs []Renderable

	View physics.Vector
	// contains filtered or unexported fields
}

A ScrollBox is a renderable that draws other renderables to itself in a scrolling fashion, for animating ticker tape feeds or rotating background animations.

func NewScrollBox

func NewScrollBox(rs []Renderable, milliPerPixelX, milliPerPixelY, width, height int) *ScrollBox

NewScrollBox returns a ScrollBox of the input renderables and the given dimensions. milliPerPixel represents the number of milliseconds it will take for the scroll box to move a horizontal or vertical pixel respectively. A negative value for milliPerPixel will move in a negative direction.

func (*ScrollBox) AddRenderable

func (s *ScrollBox) AddRenderable(rs ...Renderable)

AddRenderable adds the inputs to this scrollbox.

func (*ScrollBox) Draw

func (s *ScrollBox) Draw(buff draw.Image)

Draw draws this scroll box to the input buffer

func (*ScrollBox) DrawOffset

func (s *ScrollBox) DrawOffset(buff draw.Image, xOff, yOff float64)

DrawOffset draws this scroll box at +xOff, +yOff

func (*ScrollBox) Pause

func (p *ScrollBox) Pause()

func (*ScrollBox) SetReappearPos

func (s *ScrollBox) SetReappearPos(x, y float64) error

SetReappearPos sets at what point renderables in this box should loop back on themselves to begin scrolling again

func (*ScrollBox) SetScrollRate

func (s *ScrollBox) SetScrollRate(milliPerPixelX, milliPerPixelY int)

SetScrollRate sets how fast this scroll box should rotate its x and y axes Maybe BUG, Consider: The next time that the box will scroll at is not updated immediately after this is called, only after the box is drawn.

func (*ScrollBox) Unpause

func (s *ScrollBox) Unpause()

Unpause resumes this scroll box's scrolling. Will delay the next scroll frame if already unpaused.

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 LoadSheetSequence

func LoadSheetSequence(fileName string, w, h, pad int, fps float64, frames ...int) (*Sequence, error)

LoadSheetSequence loads a sheet and then calls LoadSequence on that sheet

func NewNoiseSequence

func NewNoiseSequence(w, h, frames int, fps float64) *Sequence

NewNoiseSequence returns a sequence of noise boxes

func NewSequence

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

NewSequence returns a new sequence from the input modifiables, playing at 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)

Draw draws this sequence to the input buffer

func (*Sequence) DrawOffset

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

DrawOffset 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) GetRGBA

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

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

func (*Sequence) IsStatic added in v1.0.3

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(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 LoadSheet

func LoadSheet(directory, fileName string, w, h, pad int) (*Sheet, error)

LoadSheet loads a file in some directory with sheets of (w,h) sized sprites, where there is pad pixels of vertical/horizontal pad between each sprite. This will blow away any cached sheet with the same fileName.

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 added in v1.4.0

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

BezierLine converts a bezier into a line sprite.

func BezierThickLine added in v1.5.0

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(fileName 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 LoadSprite

func LoadSprite(directory, fileName 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 fileName for later access through GetSprite. If the empty string is passed in for directory, the directory defined by oak.SetupConfig.Assets.Images will be used.

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

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 added in v1.3.0

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 NewLineColored added in v1.3.0

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

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

func NewNoiseBox

func NewNoiseBox(w, h int) *Sprite

NewNoiseBox returns a box of noise

func NewSeededNoiseBox

func NewSeededNoiseBox(w, h int, seed int64) *Sprite

NewSeededNoiseBox returns a box of noise seeded at a specific value this previously used a complex noise function, but this refused to run on windows 32bit and was overkill, so it now uses math/rand

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 ParseSubSprite

func ParseSubSprite(sheet string, x, y, w, h, pad int) *Sprite

ParseSubSprite pulls a sprite from a loaded sheet

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)

Draw draws this sprite onto the input buffer

func (*Sprite) DrawOffset

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

DrawOffset 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. BUG: The reason the default values of 6,6 are returned is to cover a bug in the library we are using for polygon intersection. Too small objects will always be considered to intersect a draw polygon.

func (*Sprite) GetRGBA

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

GetRGBA returns the rgba behind this sprite

func (*Sprite) IsNil

func (s *Sprite) IsNil() bool

IsNil returns whether or not this sprite's rgba is nil.

func (*Sprite) Modify

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

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

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
	// contains filtered or unexported methods
}

An Stackable manages Renderables

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.

The Switch type removes the need to repeatedly draw and undraw elements of a character, which has a tendency to leave nothing drawn for a draw frame as the switch happens.

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

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)

Draw draws the Switch at its logical location

func (*Switch) DrawOffset

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

DrawOffset 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 NewStrText

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

NewStrText is a helper to take in a string instead of a Stringer for NewText

func NewText

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

NewText creates a text element using the default font.

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)

Draw for a text draws the text at its layeredPoint position

func (*Text) DrawOffset

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

DrawOffset for a text object draws the text at t.(X,Y) + (xOff,yOff)

func (*Text) GetDims added in v1.5.0

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

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

SetIntP takes in an integer pointer that will be drawn at whatever the value is behind the pointer when it is drawn

func (*Text) SetString

func (t *Text) SetString(str string)

SetString accepts a string itself as the stringer to be written

func (*Text) SetText

func (t *Text) SetText(str fmt.Stringer)

SetText sets the string to be written to a new stringer

func (*Text) String

func (t *Text) String() string

func (*Text) StringLiteral added in v1.5.0

func (t *Text) StringLiteral() string

StringLiteral returns what text is currently rendering. Note this avoids the pretty print addtions that the String function adds.

func (*Text) ToSprite added in v1.2.0

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

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 added in v1.3.0

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