render

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: Apache-2.0 Imports: 33 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 (subsprites such as is used in sprite sheets) as well as draw them.

Renderable package has both simple entites and more complex entites that build off them. There is the Sprite that supports being loaded and drawn in a location, and on the other end of the spectrum there is the Animation that can control how it draws sprite sheet sub components.

Package render provides several types of renderable entities, methods for loading images from file, and methods for drawing those entities to screen.

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 undraw elements
	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: []Addable{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 BoundingRect

func BoundingRect(points []physics.Vector) (MinX, MinY, MaxX, MaxY float64, w, h int)

BoundingRect converts a set of points into their minimum bounding rectangle

func DrawForTime

func DrawForTime(r Renderable, l int, t time.Duration)

DrawForTime is a wrapper for Draw and UndrawAfter

func DrawLineOnto

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

DrawLineOnto draws a line onto an image rgba from one point to another Todo: this and drawLineBetween should be combined to reduce duplicate code

func DrawPolygonDim

func DrawPolygonDim() (int, int, int, int)

DrawPolygonDim returns the dimensions of the draw polygon, or all zeroes if there is none.

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 FlipX

func FlipX(rgba image.Image) *image.RGBA

FlipX returns a new rgba which is flipped over the horizontal axis.

func FlipY

func FlipY(rgba *image.RGBA) *image.RGBA

FlipY returns a new rgba which is flipped over the vertical axis.

func FontColor

func FontColor(s string) image.Image

FontColor converts a small set of strings to colors TODO: Implement a better version or pull in an outside library already doing this as this should be a fairly common utility function

func GetSheet

func GetSheet(fileName string) [][]*Sprite

GetSheet tries to find the given file in the set of loaded sheets. If it fails, it will panic unhelpfully. Todo: fix this If it succeeds, it will return the sheet (a 2d array of sprites)

func InDrawPolygon

func InDrawPolygon(xi, yi, x2i, y2i int) bool

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

func LoadFont

func LoadFont(dir string, fontFile string) *truetype.Font

LoadFont loads in a font file and stores it with the given name. This is necessary before using the fonttype for a Font

func PreDraw

func PreDraw()

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

func ReplaceDraw

func ReplaceDraw(r1, r2 Renderable, stackLayer, layer int)

ReplaceDraw will undraw r1 and draw r2 after the next draw frame Useful for not working

func ResetDrawStack

func ResetDrawStack()

ResetDrawStack resets the Global stack back to the initial stack

func SetDrawPolygon

func SetDrawPolygon(p clip.Polygon)

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

func SetDrawStack

func SetDrawStack(as ...Addable)

SetDrawStack takes in a set of Addables which act as the set of Drawstacks available

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

func UndrawAfter(r Renderable, t time.Duration)

UndrawAfter will trigger a renderable's undraw function after a given time has passed

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 Addable

type Addable interface {
	PreDraw()
	Add(Renderable, int) Renderable
	Replace(Renderable, Renderable, int)
	Copy() Addable
	// contains filtered or unexported methods
}

An Addable manages Renderables

type Animation

type Animation struct {
	LayeredPoint

	Interruptable bool
	// contains filtered or unexported fields
}

Animation takes a set of frames and provides a framework for animating them

func LoadAnimation

func LoadAnimation(sheet *Sheet, w, h, pad int, fps float64, frames []int) (*Animation, error)

LoadAnimation takes in a sheet with sheet dimensions, a frame rate and a list of frames where frames are in x,y pairs ([0,0,1,0,2,0] for (0,0) (1,0) (2,0)) and returns an animation from that

func LoadSheetAnimation

func LoadSheetAnimation(fileName string, w, h, pad int, fps float64, frames []int) (*Animation, error)

LoadSheetAnimation loads a sheet and then calls LoadAnimation on that sheet

func NewAnimation

func NewAnimation(sheetP *Sheet, fps float64, frames []int) (*Animation, error)

NewAnimation creates an Animation

func (*Animation) Copy

func (a *Animation) Copy() Modifiable

Copy creates a new Modifiable that is a copy of the current animation.

func (*Animation) Draw

func (a *Animation) Draw(buff draw.Image)

Draw draws the animation at its logical location

func (*Animation) DrawOffset

func (a *Animation) DrawOffset(buff draw.Image, xOff, yOff float64)

DrawOffset draws the animation with some x,y offset from its logical location

func (*Animation) GetDims

func (a *Animation) GetDims() (int, int)

GetDims returns the dimensions of the animation in terms of x, y

func (*Animation) GetRGBA

func (a *Animation) GetRGBA() *image.RGBA

GetRGBA returns the current frames rgba

func (*Animation) IsStatic added in v1.0.3

func (a *Animation) IsStatic() bool

IsStatic returns false for animations

func (*Animation) Modify

func (a *Animation) Modify(ms ...Modification) Modifiable

Modify applies a set of modifications to the Animation

func (*Animation) Pause

func (p *Animation) Pause()

func (*Animation) SetTriggerID

func (a *Animation) SetTriggerID(id event.CID)

SetTriggerID sets animation's id to the passed in id.

func (*Animation) Unpause

func (p *Animation) Unpause()

type CanPause added in v1.0.3

type CanPause interface {
	Pause()
	Unpause()
}

CanPause types have pause functions to start and stop animation

type Composite

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

Composite Types, distinct from Compound Types, Display all of their parts at the same time, and respect the positions and layers of their parts.

func NewComposite

func NewComposite(sl []Modifiable) *Composite

NewComposite creates a Composite

func (*Composite) Add

func (cs *Composite) Add(i int, r Modifiable)

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

func (*Composite) AddOffset

func (cs *Composite) AddOffset(i int, v physics.Vector)

AddOffset offsets all renderables in the composite by a vector

func (*Composite) AlwaysDirty

func (cs *Composite) AlwaysDirty() bool

AlwaysDirty shows that the Composite always needs updating

func (*Composite) Append

func (cs *Composite) Append(r Modifiable)

Append adds a renderable as is to the composite

func (*Composite) AppendOffset

func (cs *Composite) AppendOffset(r Modifiable, v physics.Vector)

AppendOffset adds a new offset modifiable to the composite

func (*Composite) Copy

func (cs *Composite) Copy() Modifiable

Copy makes a new Composite with the same renderables

func (*Composite) Draw

func (cs *Composite) Draw(buff draw.Image)

Draw draws the Composite at its logical position

func (*Composite) DrawOffset

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

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

func (*Composite) Get

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

Get returns a renderable at the given index within the composite

func (*Composite) GetRGBA

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

GetRGBA does not work on a composite and therefore returns nil

func (*Composite) Modify

func (cs *Composite) Modify(ms ...Modification) Modifiable

Modify applies modifications to the composite

func (*Composite) SetOffsets

func (cs *Composite) SetOffsets(vs []physics.Vector)

SetOffsets applies the initial offsets to the entire Composite

func (*Composite) String

func (cs *Composite) String() string

func (*Composite) UnDraw

func (cs *Composite) UnDraw()

UnDraw stops the composite from being drawn

type CompositeR

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

CompositeR keeps track of a set of renderables at a location

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, i int) Renderable

Add stages a renderable to be added to CompositeR at a give position in the slice

func (*CompositeR) AddOffset

func (cs *CompositeR) AddOffset(i int, v physics.Vector)

AddOffset adds an offset to a given renderable of the slice

func (*CompositeR) AlwaysDirty

func (cs *CompositeR) AlwaysDirty() bool

AlwaysDirty notes that CompositeR is alwaysdirty

func (*CompositeR) Append

func (cs *CompositeR) Append(r Renderable)

Append adds a new renderable to CompositeR

func (*CompositeR) AppendOffset

func (cs *CompositeR) AppendOffset(r Renderable, v physics.Vector)

AppendOffset adds a new renderable to CompositeR with an offset

func (*CompositeR) Copy

func (cs *CompositeR) Copy() Addable

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 at given location in CompositeR

func (*CompositeR) GetRGBA

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

GetRGBA does not work on composites and returns nil

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

func (cs *CompositeR) Replace(r1, r2 Renderable, i int)

Replace updates a renderable in the CompositeR to the new Renderable

func (*CompositeR) SetOffsets

func (cs *CompositeR) SetOffsets(ps []physics.Vector)

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

func (*CompositeR) String

func (cs *CompositeR) String() string

func (*CompositeR) UnDraw

func (cs *CompositeR) UnDraw()

UnDraw undraws the CompositeR and therefore its consituent renderables as well

type Compound

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

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

func NewCompound

func NewCompound(start string, m map[string]Modifiable) *Compound

NewCompound creates a new compound from a map of names to modifiables

func (*Compound) Add

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

Add makes a new entry in the Compounds map

func (*Compound) Copy

func (c *Compound) Copy() Modifiable

Copy creates a copy of the Compound

func (*Compound) Draw

func (c *Compound) Draw(buff draw.Image)

Draw draws the Compound at its logical location

func (*Compound) DrawOffset

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

DrawOffset draws the Compound at an offset from its logical location

func (*Compound) Get

func (c *Compound) Get() string

Get returns the Compound's current key

func (*Compound) GetDims

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

GetDims gets the current Renderables dimensions

func (*Compound) GetRGBA

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

GetRGBA returns the current renderables rgba

func (*Compound) GetSub

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

GetSub returns a keyed Modifiable from this compound's map

func (*Compound) IsInterruptable

func (c *Compound) IsInterruptable() bool

IsInterruptable returns whether the current renderable is interruptable

func (*Compound) IsStatic

func (c *Compound) IsStatic() bool

IsStatic returns whether the current renderable is static

func (*Compound) Modify

func (c *Compound) Modify(ms ...Modification) Modifiable

Modify performs a series of modifications on the Compound

func (*Compound) Pause

func (c *Compound) Pause()

Pause stops the current Renderable if possible

func (*Compound) Revert

func (c *Compound) Revert(mod int)

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

func (*Compound) RevertAll

func (c *Compound) RevertAll()

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

func (*Compound) Set

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

Set sets the current renderable to the one specified

func (*Compound) SetOffsets

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

SetOffsets sets the logical offset for the specified key

func (*Compound) ShiftPos

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

ShiftPos shifts the Compounds logical position

func (*Compound) Unpause

func (c *Compound) Unpause()

Unpause tries to unpause the current Renderable if possible

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

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 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 actively draws the onto the actual screen

func (*DrawStack) Pop

func (ds *DrawStack) Pop()

Pop increments the pop counter

func (*DrawStack) PreDraw

func (ds *DrawStack) PreDraw()

PreDraw takes care of popping and pushing onto the stack. This helps safegaurd against operations taking place in the middle of a draw

func (*DrawStack) Push

func (ds *DrawStack) Push(a Addable)

Push appends an addable to the draw stack during the next predraw

type Font

type Font struct {
	FontGenerator
	font.Drawer
}

A Font can both be generated and drawn

func DefFont

func DefFont() *Font

DefFont returns the default font

func (*Font) Copy

func (f *Font) Copy() *Font

Copy returns a new font from the given fonts generate function

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 the font per its generator's parameters

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 a set of information that can be used to create a font

func (*FontGenerator) Copy

func (fg *FontGenerator) Copy() *FontGenerator

Copy cretaes a copy of the FontGenerator

func (*FontGenerator) Generate

func (fg *FontGenerator) Generate() *Font

Generate creates a font from the FontGenerator

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 Layered

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

A Layered object is one with a layer

func (*Layered) GetLayer

func (ld *Layered) GetLayer() int

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

func (*Layered) SetLayer

func (ld *Layered) SetLayer(l int)

SetLayer sets an object that has a layer to the given layer

func (*Layered) UnDraw

func (ld *Layered) UnDraw()

UnDraw sets that a layered object should be undrawn

type LayeredPoint

type LayeredPoint struct {
	physics.Vector
	Layered
}

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

func (*LayeredPoint) String

func (ldp *LayeredPoint) String() string

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

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(...Modification) Modifiable
	Copy() Modifiable
}

A Modifiable is a Renderable that has functions to change its underlying image. This may be replaced with the gift library down the line

func EmptyRenderable

func EmptyRenderable() Modifiable

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

type Modification

type Modification func(image.Image) *image.RGBA

A Modification takes in an image buffer and returns a new image buffer

func And

func And(ms ...Modification) Modification

And chains together multiple Modifications into a single Modification

func ApplyColor

func ApplyColor(c color.Color) Modification

ApplyColor mixes a color into the rgba values of an image and returns that new rgba.

func ApplyMask

func ApplyMask(img image.RGBA) Modification

ApplyMask mixes the rgba values of two images, according to their alpha levels, and returns that as a new rgba.

func Brighten

func Brighten(brightenBy float32) Modification

Brighten brightens an image

func ColorBalance

func ColorBalance(r, g, b float32) Modification

ColorBalance takes in 3 numbers between -100 and 500 and applies it to the given image

func Cut

func Cut(newWidth, newHeight int) Modification

Cut reduces (or increases, adding nothing) the dimensions of the input image, setting them to newWidth and newHeight. (Consider: use generic int modifiers here so we don't need CutRel and Cut? i.e a function header like Cut(wMod, hMod func(int) int)? )

func CutRel

func CutRel(relWidth, relHeight float64) Modification

CutRel acts like Cut, but takes in a multiplier on the existing dimensions of the image.

func CutRound

func CutRound(xOff, yOff float64) Modification

CutRound rounds the edges of the Modifiable with Bezier curves. Todo: A nice bezier curve toolset would be nice

func Fade

func Fade(alpha int) Modification

Fade reduces the alpha of an image

func FillMask

func FillMask(img image.RGBA) Modification

FillMask replaces alpha 0 pixels in an RGBA with corresponding pixels in a second RGBA.

func Rotate

func Rotate(degrees int) Modification

Rotate returns a rotated rgba.

func Scale

func Scale(xRatio, yRatio float64) Modification

Scale returns a scaled rgba.

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.

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
	Rect
	// 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 []physics.Vector) (*Polygon, error)

NewPolygon takes in a set of points and returns a polygon. If less than three points are provided, this fails.

func ScreenPolygon

func ScreenPolygon(points []physics.Vector, w, h int) (*Polygon, error)

ScreenPolygon returns a polygon on the screen, used for draw polygons.

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

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

func (*Polygon) UpdatePoints

func (pg *Polygon) UpdatePoints(points []physics.Vector)

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

func (*Polygon) WrappingContains

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

WrappingContains returns whether the given point is contained by the input polygon.

type Rect

type Rect struct {
	MinX, MaxX, MinY, MaxY float64
}

A Rect is a helper type storing X1,Y1,X2,Y2 in floats

type Renderable

type Renderable interface {
	// As the engine currently exists,
	// the buffer which is passed into draw
	// is always the same. This leads to
	// several parts of the engine being
	// reliant on shiny/screen when they
	// could call out to somewhere else to
	// determine what they are drawn onto.
	//
	// On the other hand, this allows manually
	// duplicating renderables onto multiple
	// buffers, but in certain implementations
	// (i.e Animation) would have unintended
	// consequences.
	Draw(buff draw.Image)
	DrawOffset(buff draw.Image, xOff, yOff float64)

	// Basic Implementing struct: Point
	ShiftX(x float64)
	GetX() float64
	ShiftY(y float64)
	GetY() float64
	SetPos(x, y float64)
	GetDims() (int, int)

	// Basic Implementing struct: Layered
	GetLayer() int
	SetLayer(l int)
	UnDraw()

	// Utilities
	String() string

	// Physics
	// Basic Implementing struct: physics.Vector
	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, l int) (Renderable, error)

Draw accesses the global draw stack

func DrawColor

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

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, l int) (Renderable, error)

LoadSpriteAndDraw is shorthand for LoadSprite followed by Draw.

type RenderableHeap

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

The RenderableHeap type is set up to manage a set of renderables to prevent any unsafe operations and allow for distinct updates between draw cycles

func NewHeap

func NewHeap(static bool) *RenderableHeap

NewHeap creates a new renderableHeap

func (*RenderableHeap) Add

func (rh *RenderableHeap) Add(r Renderable, layer int) Renderable

Add stages a new Renderable to add to the heap

func (*RenderableHeap) Copy

func (rh *RenderableHeap) Copy() Addable

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 ...Modification) 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) RevertAndModify

func (rv *Reverting) RevertAndModify(n int, ms ...Modification) 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)

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

	Interruptable bool
	// 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 NewNoiseSequence

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

NewNoiseSequence returns a sequence of noise boxes

func NewSequence

func NewSequence(mods []Modifiable, fps float64) *Sequence

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

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) 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 panics todo: don't panic, return an error

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 ...Modification) Modifiable

Modify alters each renderable in this sequence by the given modifications

func (*Sequence) Pause

func (p *Sequence) Pause()

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

func (*Sheet) SubSprite

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

SubSprite gets a sprite from a sheet at the given location

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 LoadSprite

func LoadSprite(fileName string) *Sprite

LoadSprite loads the input fileName into a Sprite

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 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 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) 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 ...Modification) 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 Text

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

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

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

Directories

Path Synopsis
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