gfx

package
v0.0.0-...-4d18667 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gfx provides different kinds of functions and graphic primitives that bring life onto the screen.

Index

Constants

This section is empty.

Variables

View Source
var Fullscreen bool

Fullscreen indicates whether the graphics are in fullscreen mode or not.

View Source
var Height int32

Height is the height in pixels of the complete drawing area.

View Source
var Width int32

Width is the width in pixels of the complete drawing area.

Functions

func CanvasAvailable

func CanvasAvailable() bool

CanvasAvailable returns if the hardware supports a canvas.

func Clear

func Clear()

Clear clears the whole drawing area.

func Render

func Render(r renderer, p *Params)

Render uses a renderer to put pixels onto the screen directly.

func SetCamera

func SetCamera(c *Camera)

SetCamera sets the currently used Camera.

func SetClearColor

func SetClearColor(r, g, b float64)

SetClearColor sets the color with which the screen will be filled when calling Clear().

func SetDefaultFilterMode

func SetDefaultFilterMode(fm FilterMode)

SetDefaultFilterMode sets the filter mode which will be used by default when creating a new Image or Canvas.

func SetPixelSize

func SetPixelSize(size int32)

SetPixelSize scales all graphics by the given factor.

Types

type Camera

type Camera struct {
	X, Y          int32
	Width, Height int32
	// contains filtered or unexported fields
}

Camera represents an area on the screen.

func CurrentCamera

func CurrentCamera() *Camera

CurrentCamera returns the currently used Camera.

func NewCamera

func NewCamera(w, h, x, y, ps int32) *Camera

NewCamera returns a new Camera

func (*Camera) Move

func (c *Camera) Move(x, y float64)

Move moves the camera bey the given values.

func (*Camera) Render

func (c *Camera) Render(r renderer, p *Params)

Render renders the given Renderer with the given Params.

func (*Camera) SetPixelSize

func (c *Camera) SetPixelSize(i int32)

SetPixelSize scales all graphics by the given factor.

type Canvas

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

Canvas is an offscreen area which can be rendered to and rendered on to the screen.

func NewCanvas

func NewCanvas(width, height int) (*Canvas, error)

NewCanvas returns a new canvas.

func (*Canvas) Clear

func (c *Canvas) Clear()

Clear clears the canvas.

func (*Canvas) Delete

func (c *Canvas) Delete()

Delete removes the canvas from memory.

func (*Canvas) Render

func (c *Canvas) Render(r renderer, p *Params)

Render uses a renderer to put pixels onto the canvas.

type Circle

type Circle struct {
	Radius float64

	Filled bool
	Mode   *LineMode
	// contains filtered or unexported fields
}

Circle is a geometric shape that can be rendered with gfx.Render.

func NewCircle

func NewCircle(r float64, segments int, filled bool, mode ...*LineMode) (*Circle, error)

NewCircle returns a pointer to a new Circle. the number of segments must be at least 3. The given mode is optional. If no mode is given a default LineMode with width 1 is used.

type FilterMode

type FilterMode int

FilterMode represents the interpolation mode for texture rendering.

const (
	// NearestFilter scales images with nearest neighbor interpolation.
	NearestFilter FilterMode = iota
	// LinearFilter scales image with linear interpolation.
	LinearFilter
)

type FlipBook

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

FlipBook represents a timed sequence of renderers.

func NewFlipBook

func NewFlipBook(l bool, pages ...*Page) *FlipBook

NewFlipBook returns a pointer to a new FlipBook.

func (*FlipBook) AddPageListener

func (fb *FlipBook) AddPageListener(of OnFlip)

AddPageListener adds a callback that will be called when the page is changed.

func (*FlipBook) ClearPageListeners

func (fb *FlipBook) ClearPageListeners()

ClearPageListeners removes all callback functions.

func (*FlipBook) Finished

func (fb *FlipBook) Finished() bool

Finished indicates if the FlipBook is at the end

func (*FlipBook) Reset

func (fb *FlipBook) Reset()

Reset resets the FlipBook to the first frame

func (*FlipBook) Update

func (fb *FlipBook) Update(delta time.Duration)

Update updates increases the elapsed time and sets the current renderer for rendering.

type Font

type Font struct {
	Bold          bool
	Italic        bool
	Underline     bool
	Strikethrough bool
	AntiAliased   bool
	// contains filtered or unexported fields
}

Font represents a ttf font which can convert a string into an image.

func NewFont

func NewFont(filename string, size int) (*Font, error)

NewFont creates a new font from a given file for a given size.

func (*Font) Delete

func (f *Font) Delete()

Delete deletes the font from memory.

func (*Font) Render

func (f *Font) Render(text string) (*Image, error)

Render converts the given Text into an Image.

func (*Font) Size

func (f *Font) Size(text string) (x, y int, err error)

Size returns the width and height for the given text.

type Image

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

Image represents an image and can be rendered on the screen.

func NewImage

func NewImage(file string) (*Image, error)

NewImage creates a new Image from the given file name. File must be a png.

func (*Image) Delete

func (i *Image) Delete()

Delete removes the image from memory.

func (*Image) Height

func (i *Image) Height() int

Height returns the height of the image in pixels.

func (*Image) Width

func (i *Image) Width() int

Width returns the width of the image in pixels.

type Line

type Line struct {
	Points []float64
	Mode   *LineMode
}

Line is a geometric shape that can be rendered with gfx.Render.

func NewLine

func NewLine(mode *LineMode, coordinates ...float64) (*Line, error)

NewLine returns a pointer to a new line for the given coordinates and Line mode. The number of coordinates must be at least 4.

type LineMode

type LineMode struct {
	Width  float32
	Smooth bool
}

LineMode defines the way how (out)lines are rendered.

func NewLineMode

func NewLineMode() *LineMode

NewLineMode returns a pointer to a new LineMode with width 1.0 and not smooth.

type OnFlip

type OnFlip func(page int)

OnFlip is a callback that gets triggered when a page is changed. The param page is the page number of the new page.

type Page

type Page struct {
	Duration time.Duration
	Renderer renderer
}

Page represents one part of a FlipBook animation. May have nil as renderer for empty pages.

type Params

type Params struct {
	X     float64
	Y     float64
	R     float64
	G     float64
	B     float64
	A     float64
	Rot   Rotation
	Scale Scale
}

Params encompasses all transformations that can be done while rendering an Image.

func NewParams

func NewParams() *Params

NewParams returns new Params with sensible default values.

type Polygon

type Polygon struct {
	Points []float64
	Filled bool
	Mode   *LineMode
}

Polygon is a geometric shape that can be rendered with gfx.Render.

type Rectangle

type Rectangle struct {
	X1     float64
	Y1     float64
	X2     float64
	Y2     float64
	Filled bool
	Mode   *LineMode
}

Rectangle is a geometric shape that can be rendered with gfx.Render.

func NewRectangle

func NewRectangle(x1, y1, x2, y2 float64, filled bool, mode ...*LineMode) (*Rectangle, error)

NewRectangle returns a pointer ro a new rectangle for the given coordinates. The given mode is optional. If no mode is given a default LineMode with width 1 is used.

type Rotation

type Rotation struct {
	Angle float64
	X     float64
	Y     float64
}

Rotation describes the clockwise rotation around the center at X, Y.

type Scale

type Scale struct {
	Factor float64
	X      float64
	Y      float64
}

Scale describes a scale with a center at x, y.

Directories

Path Synopsis
Package animation provides functionality to animate graphic primitives on the screen.
Package animation provides functionality to animate graphic primitives on the screen.

Jump to

Keyboard shortcuts

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