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
- Variables
- func BatchLoad(baseFolder string) error
- func BoundingRect(points []physics.Vector) (MinX, MinY, MaxX, MaxY float64, w, h int)
- func DrawCircle(rgba *image.RGBA, c color.Color, radius, thickness float64, offsets ...float64)
- func DrawCurve(rgba *image.RGBA, c color.Color, ...)
- func DrawForTime(r Renderable, l int, t time.Duration)
- func DrawGradientLine(rgba *image.RGBA, x1, y1, x2, y2 int, c1, c2 color.Color, thickness int)
- func DrawLineColored(rgba *image.RGBA, x1, y1, x2, y2, thickness int, colorer Colorer)
- func DrawLineOnto(rgba *image.RGBA, x1, y1, x2, y2 int, c color.Color)
- func DrawPolygonDim() (int, int, int, int)
- func DrawThickLine(rgba *image.RGBA, x1, y1, x2, y2 int, c color.Color, thickness int)
- func FontColor(s string) image.Image
- func GetSheet(fileName string) [][]*Sprite
- func GradientColorAt(c1, c2 color.Color, progress float64) color.RGBA64
- func InDrawPolygon(xi, yi, x2i, y2i int) bool
- func LoadFont(dir string, fontFile string) *truetype.Font
- func PreDraw()
- func ReplaceDraw(r1, r2 Renderable, stackLayer, layer int)
- func ResetDrawStack()
- func SetDrawPolygon(p clip.Polygon)
- func SetDrawStack(as ...Addable)
- func SetFontDefaults(wd, assetPath, fontPath, hinting, color, file string, size, dpi float64)
- func ShinyDraw(buff draw.Image, img image.Image, x, y int)
- func ShinyOverwrite(buff draw.Image, img image.Image, x, y int)
- func ShinySet(buff draw.Image, c color.Color, x, y int)
- func Tween(start image.Image, end image.Image, frames int) []*image.RGBA
- func UndrawAfter(r Renderable, t time.Duration)
- func UpdateDebugMap(rName string, r Renderable)
- func Zoom(xPerc, yPerc, zoom float64) func(rgba image.Image) *image.RGBA
- type Addable
- type Animation
- func (a *Animation) Copy() Modifiable
- func (a *Animation) Draw(buff draw.Image)
- func (a *Animation) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (a *Animation) GetDims() (int, int)
- func (a *Animation) GetRGBA() *image.RGBA
- func (a *Animation) IsStatic() bool
- func (a *Animation) Modify(ms ...Modification) Modifiable
- func (p *Animation) Pause()
- func (a *Animation) SetTriggerID(id event.CID)
- func (p *Animation) Unpause()
- type CanPause
- type Colorer
- type Composite
- func (cs *Composite) Add(i int, r Modifiable)
- func (cs *Composite) AddOffset(i int, v physics.Vector)
- func (cs *Composite) AlwaysDirty() bool
- func (cs *Composite) Append(r Modifiable)
- func (cs *Composite) AppendOffset(r Modifiable, v physics.Vector)
- func (cs *Composite) Copy() Modifiable
- func (cs *Composite) Draw(buff draw.Image)
- func (cs *Composite) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (cs *Composite) Get(i int) Modifiable
- func (cs *Composite) GetRGBA() *image.RGBA
- func (cs *Composite) Modify(ms ...Modification) Modifiable
- func (cs *Composite) SetOffsets(vs []physics.Vector)
- func (cs *Composite) String() string
- func (cs *Composite) UnDraw()
- type CompositeR
- func (cs *CompositeR) Add(r Renderable, i int) Renderable
- func (cs *CompositeR) AddOffset(i int, v physics.Vector)
- func (cs *CompositeR) AlwaysDirty() bool
- func (cs *CompositeR) Append(r Renderable)
- func (cs *CompositeR) AppendOffset(r Renderable, v physics.Vector)
- func (cs *CompositeR) Copy() Addable
- func (cs *CompositeR) Draw(buff draw.Image)
- func (cs *CompositeR) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (cs *CompositeR) Get(i int) Renderable
- func (cs *CompositeR) GetRGBA() *image.RGBA
- func (cs *CompositeR) PreDraw()
- func (cs *CompositeR) Replace(r1, r2 Renderable, i int)
- func (cs *CompositeR) SetOffsets(ps []physics.Vector)
- func (cs *CompositeR) String() string
- func (cs *CompositeR) UnDraw()
- type Compound
- func (c *Compound) Add(k string, v Modifiable) (err error)
- func (c *Compound) Copy() Modifiable
- func (c *Compound) Draw(buff draw.Image)
- func (c *Compound) DrawOffset(buff draw.Image, xOff float64, yOff float64)
- func (c *Compound) Get() string
- func (c *Compound) GetDims() (int, int)
- func (c *Compound) GetRGBA() *image.RGBA
- func (c *Compound) GetSub(s string) Modifiable
- func (c *Compound) IsInterruptable() bool
- func (c *Compound) IsStatic() bool
- func (c *Compound) Modify(ms ...Modification) Modifiable
- func (c *Compound) Pause()
- func (c *Compound) Revert(mod int)
- func (c *Compound) RevertAll()
- func (c *Compound) Set(k string) error
- func (c *Compound) SetOffsets(k string, offsets physics.Vector)
- func (c *Compound) SetTriggerID(cid event.CID)
- func (c *Compound) ShiftPos(x, y float64)
- func (c *Compound) Unpause()
- type DrawFPS
- type DrawStack
- type Font
- type FontGenerator
- type FontManager
- type Layered
- type LayeredPoint
- func (ldp *LayeredPoint) Copy() LayeredPoint
- func (ldp *LayeredPoint) GetDims() (int, int)
- func (ldp *LayeredPoint) GetLayer() int
- func (ldp *LayeredPoint) SetPos(x, y float64)
- func (ldp *LayeredPoint) ShiftX(x float64)
- func (ldp *LayeredPoint) ShiftY(y float64)
- func (ldp *LayeredPoint) String() string
- type LogicFPS
- type Modifiable
- type Modification
- func And(ms ...Modification) Modification
- func ApplyColor(c color.Color) Modification
- func ApplyMask(img image.RGBA) Modification
- func Brighten(brightenBy float32) Modification
- func ColorBalance(r, g, b float32) Modification
- func ConformToPallete(p color.Palette) Modification
- func Cut(newWidth, newHeight int) Modification
- func CutRel(relWidth, relHeight float64) Modification
- func CutRound(xOff, yOff float64) Modification
- func Fade(alpha int) Modification
- func FillMask(img image.RGBA) Modification
- func GiftFilter(fis ...gift.Filter) Modification
- func Rotate(degrees int) Modification
- func RotateInterpolated(degrees int, interpolation gift.Interpolation) Modification
- func Saturate(saturateBy float32) Modification
- func Scale(xRatio, yRatio float64) Modification
- func TrimColor(trimUnder color.Color) Modification
- type NonInterruptable
- type NonStatic
- type Polygon
- func (pg *Polygon) Contains(x, y float64) (contains bool)
- func (pg *Polygon) ConvexContains(x, y float64) bool
- func (pg *Polygon) Fill(c color.Color)
- func (pg *Polygon) FillInverse(c color.Color)
- func (pg *Polygon) GetOutline(c color.Color) *Composite
- func (pg *Polygon) UpdatePoints(points []physics.Vector)
- func (pg *Polygon) WrappingContains(x, y float64) bool
- type Rect
- type Renderable
- type RenderableHeap
- func (rh *RenderableHeap) Add(r Renderable, layer int) Renderable
- func (rh *RenderableHeap) Copy() Addable
- func (rh *RenderableHeap) Len() int
- func (rh *RenderableHeap) Less(i, j int) bool
- func (rh *RenderableHeap) Pop() interface{}
- func (rh *RenderableHeap) PreDraw()
- func (rh *RenderableHeap) Push(r interface{})
- func (rh *RenderableHeap) Replace(r1, r2 Renderable, layer int)
- func (rh *RenderableHeap) Swap(i, j int)
- type Reverting
- func (rv *Reverting) Copy() Modifiable
- func (rv *Reverting) IsInterruptable() bool
- func (rv *Reverting) IsStatic() bool
- func (rv *Reverting) Modify(ms ...Modification) Modifiable
- func (rv *Reverting) Pause()
- func (rv *Reverting) Revert(n int)
- func (rv *Reverting) RevertAll()
- func (rv *Reverting) RevertAndModify(n int, ms ...Modification) Modifiable
- func (rv *Reverting) Set(k string)
- func (rv *Reverting) SetTriggerID(cid event.CID)
- func (rv *Reverting) Unpause()
- type ScrollBox
- func (s *ScrollBox) AddRenderable(rs ...Renderable)
- func (s *ScrollBox) Draw(buff draw.Image)
- func (s *ScrollBox) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (p *ScrollBox) Pause()
- func (s *ScrollBox) SetReappearPos(x, y float64) error
- func (s *ScrollBox) SetScrollRate(milliPerPixelX, milliPerPixelY int)
- func (s *ScrollBox) Unpause()
- type Sequence
- func (sq *Sequence) Copy() Modifiable
- func (sq *Sequence) Draw(buff draw.Image)
- func (sq *Sequence) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (sq *Sequence) Get(i int) Modifiable
- func (sq *Sequence) GetRGBA() *image.RGBA
- func (sq *Sequence) IsStatic() bool
- func (sq *Sequence) Modify(ms ...Modification) Modifiable
- func (p *Sequence) Pause()
- func (sq *Sequence) SetTriggerID(id event.CID)
- func (p *Sequence) Unpause()
- type Sheet
- type Sprite
- func LoadSprite(fileName string) *Sprite
- func NewCircularGradientBox(w, h int, startColor, endColor color.Color) *Sprite
- func NewColorBox(w, h int, c color.Color) *Sprite
- func NewEmptySprite(x, y float64, w, h int) *Sprite
- func NewGradientBox(w, h int, startColor, endColor color.Color, pFunction progressFunction) *Sprite
- func NewGradientLine(x1, y1, x2, y2 float64, c1, c2 color.Color, thickness int) *Sprite
- func NewHorizontalGradientBox(w, h int, startColor, endColor color.Color) *Sprite
- func NewLine(x1, y1, x2, y2 float64, c color.Color) *Sprite
- func NewLineColored(x1, y1, x2, y2 float64, colorer Colorer, thickness int) *Sprite
- func NewNoiseBox(w, h int) *Sprite
- func NewSeededNoiseBox(w, h int, seed int64) *Sprite
- func NewSprite(x, y float64, r *image.RGBA) *Sprite
- func NewThickLine(x1, y1, x2, y2 float64, c color.Color, thickness int) *Sprite
- func NewVerticalGradientBox(w, h int, startColor, endColor color.Color) *Sprite
- func OverlaySprites(sps []Sprite) *Sprite
- func ParseSubSprite(sheet string, x, y, w, h, pad int) *Sprite
- func (s *Sprite) Copy() Modifiable
- func (s *Sprite) Draw(buff draw.Image)
- func (s *Sprite) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (s *Sprite) GetDims() (int, int)
- func (s *Sprite) GetRGBA() *image.RGBA
- func (s *Sprite) IsNil() bool
- func (s *Sprite) Modify(ms ...Modification) Modifiable
- func (s *Sprite) SetRGBA(r *image.RGBA)
- type Text
- func (t *Text) Center()
- func (t *Text) Draw(buff draw.Image)
- func (t *Text) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (t *Text) SetFont(f *Font)
- func (t *Text) SetInt(i int)
- func (t *Text) SetIntP(i *int)
- func (t *Text) SetString(str string)
- func (t *Text) SetText(str fmt.Stringer)
- func (t *Text) String() string
- func (t *Text) ToSprite() *Sprite
- func (t *Text) Wrap(charLimit int, vertInc float64) []*Text
- type Triggerable
Constants ¶
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 )
const (
// Undraw is a constant used to undraw elements
Undraw = -1000
)
Variables ¶
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
var ( // DefFontGenerator is a default font generator of no options DefFontGenerator = FontGenerator{} )
var FlipX = GiftFilter(gift.FlipHorizontal())
FlipX returns a new rgba which is flipped over the horizontal axis.
var FlipY = GiftFilter(gift.FlipVertical())
FlipY returns a new rgba which is flipped over the vertical axis.
var ( // GlobalDrawStack is the stack that all draw calls are parsed through. GlobalDrawStack = &DrawStack{ as: []Addable{NewHeap(false)}, } )
Functions ¶
func BatchLoad ¶
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 ¶
BoundingRect converts a set of points into their minimum bounding rectangle
func DrawCircle ¶ added in v1.3.0
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, l int, t time.Duration)
DrawForTime is a wrapper for Draw and UndrawAfter
func DrawGradientLine ¶ added in v1.3.0
DrawGradientLine acts like DrawThickLine but also applies a gradient to the line
func DrawLineColored ¶ added in v1.3.0
DrawLineColored acts like DrawThickLine, but takes in a custom colorer function for how it draws its line.
func DrawLineOnto ¶
DrawLineOnto draws a line onto an image rgba from one point to another Todo: 2.0, rename to DrawLine
func DrawPolygonDim ¶
DrawPolygonDim returns the dimensions of the draw polygon, or all zeroes if there is none.
func DrawThickLine ¶ added in v1.1.0
DrawThickLine acts like DrawlineOnto, but takes in thickness of the given line
func FontColor ¶
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 ¶
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 GradientColorAt ¶ added in v1.3.0
GradientColorAt returns a new color via a gradient between two colors and the progress between them
func InDrawPolygon ¶
InDrawPolygon returns whehter a coordinate and dimension set should be drawn given the draw polygon
func LoadFont ¶
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 ¶
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 ¶
SetFontDefaults updates the default font parameters with the passed in arguments
func ShinyDraw ¶
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 ¶
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 Tween ¶
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 ¶
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 ¶
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) DrawOffset ¶
DrawOffset draws the animation with some x,y offset from its logical location
func (*Animation) Modify ¶
func (a *Animation) Modify(ms ...Modification) Modifiable
Modify applies a set of modifications to the Animation
func (*Animation) SetTriggerID ¶
SetTriggerID sets animation's id to the passed in id.
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
A Colorer takes some notion of linear progress and returns a color
func IdentityColorer ¶ added in v1.3.0
IdentityColorer returns the same color it was given at initalization, regardless of progress.
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 (*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) AlwaysDirty ¶
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) DrawOffset ¶
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) Modify ¶
func (cs *Composite) Modify(ms ...Modification) Modifiable
Modify applies modifications to the composite
func (*Composite) SetOffsets ¶
SetOffsets applies the initial offsets to the entire Composite
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) DrawOffset ¶
DrawOffset draws the Compound at an offset from its logical location
func (*Compound) GetSub ¶
func (c *Compound) GetSub(s string) Modifiable
GetSub returns a keyed Modifiable from this compound's map
func (*Compound) IsInterruptable ¶
IsInterruptable returns whether the current renderable is interruptable
func (*Compound) Modify ¶
func (c *Compound) Modify(ms ...Modification) Modifiable
Modify performs a series of modifications on the Compound
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) SetOffsets ¶
SetOffsets sets the logical offset for the specified key
func (*Compound) SetTriggerID ¶ added in v1.3.0
SetTriggerID sets the ID AnimationEnd will trigger on for animating subtypes.
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 (*DrawFPS) Add ¶
func (df *DrawFPS) Add(Renderable, int) Renderable
Add 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
type Font ¶
type Font struct { FontGenerator font.Drawer }
A Font can both be generated and drawn
func (*Font) NewIntText ¶
NewIntText wraps the given int pointer in a stringer interface
func (*Font) NewStrText ¶
NewStrText is a helper to take in a string instead of a stringer for NewText
func (*Font) NewText ¶
NewText takes in anything that has a String() function and returns a text object with the associated font and screen position
type FontGenerator ¶
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 ¶
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 ¶
GetLayer returns the layer of an object if it has one or else returns that the object needs to be undrawn
type LayeredPoint ¶
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 ¶
LogicFPS is a draw stack element that will draw the logical fps onto the screen
func (*LogicFPS) Add ¶
func (lf *LogicFPS) Add(Renderable, int) Renderable
Add 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 pseudo-nil Renderable (and Modifiable)
type Modification ¶
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 between -100 and 100. 100 will be solid white, -100 will be solid black.
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 ConformToPallete ¶ added in v1.3.0
func ConformToPallete(p color.Palette) Modification
ConformToPallete modifies the input image so that it's colors all fall in the input color palette.
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 FillMask ¶
func FillMask(img image.RGBA) Modification
FillMask replaces alpha 0 pixels in an RGBA with corresponding pixels in a second RGBA.
func GiftFilter ¶ added in v1.3.0
func GiftFilter(fis ...gift.Filter) Modification
GiftFilter converts any set of gift.Filters into a Modification.
func RotateInterpolated ¶ added in v1.3.0
func RotateInterpolated(degrees int, interpolation gift.Interpolation) Modification
RotateInterpolated acts as Rotate, but accepts an interpolation argument. standard rotation does this with Cubic Interpolation.
func Saturate ¶ added in v1.3.0
func Saturate(saturateBy float32) Modification
Saturate saturates the input between -100 and 500 percent.
func TrimColor ¶ added in v1.3.0
func TrimColor(trimUnder color.Color) Modification
TrimColor will trim inputs so that any rows or columns where each pixel is less than or equal to the input color are removed. This will change the dimensions of the image.
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 ¶
A Polygon is a renderable that is represented by a set of in order points on a plane.
func NewPolygon ¶
NewPolygon takes in a set of points and returns a polygon. If less than three points are provided, this fails.
func ScreenPolygon ¶
ScreenPolygon returns a polygon on the screen, used for draw polygons.
func (*Polygon) Contains ¶
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 ¶
ConvexContains returns whether the given point is contained by the input polygon. It assumes the polygon is convex. It outperforms the alternatives.
func (*Polygon) FillInverse ¶
FillInverse colors this polygon's exterior the given color
func (*Polygon) GetOutline ¶
GetOutline returns a set of lines of the given color along this polygon's outline
func (*Polygon) UpdatePoints ¶
UpdatePoints resets the points of this polygon to be the passed in points
func (*Polygon) WrappingContains ¶
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 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
}
A RenderableHeap managed 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, 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) 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
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 ¶
IsInterruptable returns if whatever this reverting is currently dispalying is interruptable.
func (*Reverting) IsStatic ¶
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 ¶
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 ¶
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
SetTriggerID sets the ID AnimationEnd will trigger on for animating subtypes.
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) DrawOffset ¶
DrawOffset draws this scroll box at +xOff, +yOff
func (*ScrollBox) SetReappearPos ¶
SetReappearPos sets at what point renderables in this box should loop back on themselves to begin scrolling again
func (*ScrollBox) SetScrollRate ¶
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.
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 ¶
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 ¶
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) DrawOffset ¶
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) Modify ¶
func (sq *Sequence) Modify(ms ...Modification) Modifiable
Modify alters each renderable in this sequence by the given modifications
func (*Sequence) SetTriggerID ¶
SetTriggerID sets the ID that AnimationEnd will be triggered on when this sequence loops over from its last frame to its first
type Sheet ¶
Sheet is a 2D array of image rgbas
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 ¶
LoadSprite loads the input fileName into a Sprite
func NewCircularGradientBox ¶
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 ¶
NewColorBox returns a Sprite full of a given color with the given dimensions
func NewEmptySprite ¶
NewEmptySprite returns a sprite of the given dimensions with a blank RGBA
func NewGradientBox ¶
NewGradientBox returns a gradient box defined on the two input colors and the given progress function
func NewGradientLine ¶ added in v1.3.0
NewGradientLine returns a Line that has some value of thickness along with a start and end color
func NewHorizontalGradientBox ¶
NewHorizontalGradientBox returns a gradient box with a horizontal gradient from the start to end color, left to right.
func NewLineColored ¶ added in v1.3.0
NewLineColored returns a line with a custom function for how each pixel in that line should be colored.
func NewSeededNoiseBox ¶
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 NewThickLine ¶
NewThickLine returns a Line that has some value of thickness
func NewVerticalGradientBox ¶
NewVerticalGradientBox returns a gradient box with a vertical gradient from the start to end color, top to bottom.
func OverlaySprites ¶
OverlaySprites combines sprites together through masking to form a single sprite
func ParseSubSprite ¶
ParseSubSprite pulls a sprite from a loaded sheet
func (*Sprite) DrawOffset ¶
DrawOffset draws this sprite at +xOff, +yOff
func (*Sprite) GetDims ¶
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) Modify ¶
func (s *Sprite) Modify(ms ...Modification) Modifiable
Modify takes in modifications (modify.go) and alters this sprite accordingly
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) DrawOffset ¶
DrawOffset for a text object draws the text at t.(X,Y) + (xOff,yOff)
func (*Text) SetIntP ¶
SetIntP takes in an integer pointer that will be drawn at whatever the value is behind the pointer when it is drawn
type Triggerable ¶ added in v1.3.0
Triggerable types can have an ID set so when their animations finish, they trigger AnimationEnd on that ID.
Source Files ¶
- animation.go
- colorbox.go
- colorer.go
- composite.go
- compound.go
- curve.go
- debugMap.go
- doc.go
- draw.go
- drawHeap.go
- drawPolygon.go
- drawStack.go
- font.go
- fontManager.go
- fps.go
- gradientbox.go
- gradients.go
- interfaceFeatures.go
- layered.go
- line.go
- loader.go
- logicfps.go
- modify.go
- noisebox.go
- pausing.go
- polygon.go
- renderable.go
- reverting.go
- scrollbox.go
- sequence.go
- shiny.go
- sprite.go
- text.go
- tween.go