gfx

package
v0.0.0-...-0a813d1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas[T pixel.Color] struct {
	tinygl.Rect[T]
	// contains filtered or unexported fields
}

A canvas based on small tiles that supports modifying these objects and only redraws the affected tiles. This results in very fast incremental updates if only small parts of the screen changed.

func NewCanvas

func NewCanvas[T pixel.Color](background T, width, height int) *Canvas[T]

NewCanvas creates a new tile canvas.

func (*Canvas[T]) Add

func (c *Canvas[T]) Add(object Object[T])

Add a previously created object to the canvas. An object can't be added more than once.

func (*Canvas[T]) Clear

func (c *Canvas[T]) Clear()

Clear removes all objects from the canvas.

func (*Canvas[T]) HandleEvent

func (c *Canvas[T]) HandleEvent(event tinygl.Event, x, y int)

HandleEvent handles events such as touch events and calls the event handler with the x/y coordinate as parameters.

func (*Canvas[T]) Layout

func (c *Canvas[T]) Layout(width, height int)

Layout implements tinygl.Object.

func (*Canvas[T]) MarkUpdated

func (c *Canvas[T]) MarkUpdated()

func (*Canvas[T]) MinSize

func (c *Canvas[T]) MinSize() (width, height int)

MinSize returns the minimal size as set when the canvas was created.

func (*Canvas[T]) RequestUpdate

func (c *Canvas[T]) RequestUpdate()

func (*Canvas[T]) SetEventHandler

func (c *Canvas[T]) SetEventHandler(eventHandler func(event tinygl.Event, x, y int))

SetEventHandler sets the callback when a (touch) event occurs on this canvas.

func (*Canvas[T]) Size

func (c *Canvas[T]) Size() (width, height int)

Size returns the current canvas size, as updated after the first layout.

func (*Canvas[T]) Update

func (c *Canvas[T]) Update(screen *tinygl.Screen[T], displayX, displayY, displayWidth, displayHeight, x, y int)

Update implements tinygl.Object.

type Circle

type Circle[T pixel.Color] struct {
	// contains filtered or unexported fields
}

Circle is a simple solid color circle.

func NewCircle

func NewCircle[T pixel.Color](color T, x, y, radius int) *Circle[T]

NewCircle implements a circle object, with antialiased edges.

The (x, y) coordinates are of the center of the circle, right in the middle of the innermost 4 pixels. This means for example that if you draw a circle at (0, 0) of a large enough canvas, exactly a quarter of the circle is shown.

Warning: this API might change once circles with holes and/or circles with borders are added.

func (*Circle[T]) Draw

func (obj *Circle[T]) Draw(imgX, imgY int, img pixel.Image[T])

Draw implements the gfx.Object interface.

func (*Circle[T]) Hidden

func (obj *Circle[T]) Hidden() bool

Hidden returns whether this object is currently hidden.

func (*Circle[T]) SetHidden

func (obj *Circle[T]) SetHidden(hidden bool)

SetHidden implements gfx.Object. It sets the visibility status of the circle on screen.

type CustomCanvas

type CustomCanvas[T pixel.Color] struct {
	tinygl.Rect[T]
	// contains filtered or unexported fields
}

CustomCanvas is a canvas widget to draw custom data.

func NewCustomCanvas

func NewCustomCanvas[T pixel.Color](background T, minWidth, minHeight int, update func(screen *tinygl.Screen[T], displayX, displayY, displayWidth, displayHeight, x, y int)) *CustomCanvas[T]

NewCustomCanvas returns a ready made custom canvas. The update callback should always redraw the entire canvas, even if not the entire canvas changed.

func (*CustomCanvas[T]) Layout

func (c *CustomCanvas[T]) Layout(width, height int)

Layout implements tinygl.Object.

func (*CustomCanvas[T]) MinSize

func (c *CustomCanvas[T]) MinSize() (width, height int)

MinSize returns the minimal size as set when the canvas was created.

func (*CustomCanvas[T]) Size

func (c *CustomCanvas[T]) Size() (width, height int)

Size returns the current canvas size, as updated after the first layout.

func (*CustomCanvas[T]) Update

func (c *CustomCanvas[T]) Update(screen *tinygl.Screen[T], displayX, displayY, displayWidth, displayHeight, x, y int)

type Image

type Image[T pixel.Color] struct {
	// contains filtered or unexported fields
}

Image wraps an image.Image object to be drawn on a canvas.

func NewImage

func NewImage[T pixel.Color](img image.Image[T], x, y int) *Image[T]

NewImage creates a new image not yet attached to a canvas.

func (*Image[T]) Bounds

func (obj *Image[T]) Bounds() (x, y, width, height int)

Bounds returns the rectangle coordinates relative to (0, 0) of the canvas.

func (*Image[T]) Draw

func (obj *Image[T]) Draw(bufX, bufY int, buf pixel.Image[T])

Draw implements the gfx.Object interface.

func (*Image[T]) Hidden

func (obj *Image[T]) Hidden() bool

Hidden returns whether this object is currently hidden.

func (*Image[T]) Move

func (obj *Image[T]) Move(x, y int)

Move the rectangle to the new coordinates.

func (*Image[T]) SetHidden

func (obj *Image[T]) SetHidden(hidden bool)

SetHidden implements gfx.Object. It sets the visibility status of the rectangle on screen.

func (*Image[T]) SetImage

func (obj *Image[T]) SetImage(img image.Image[T])

SetImage replaces the image to be drawn on screen.

func (*Image[T]) SetScale

func (obj *Image[T]) SetScale(scale int)

SetScale changes the default scale from 1 (100%) to a different value.

type Line

type Line[T pixel.Color] struct {
	// contains filtered or unexported fields
}

Line is a line from a start coordinate to an end coordinate.

func NewLine

func NewLine[T pixel.Color](color T, x1, y1, x2, y2, strokeWidth int) *Line[T]

NewLine creates a new line object, with antialiased edges.

The two coordinates (x1, y1) and (x2, y2) describe the starting and ending coordinate. The strokeWidth describes the width of the line, like the SVG property. Lines by default have an ending like SVG stroke-linecap="butt".

func (*Line[T]) Draw

func (obj *Line[T]) Draw(imgX, imgY int, img pixel.Image[T])

Draw implements the gfx.Object interface.

func (*Line[T]) Hidden

func (obj *Line[T]) Hidden() bool

Hidden returns whether this object is currently hidden.

func (*Line[T]) SetHidden

func (obj *Line[T]) SetHidden(hidden bool)

SetHidden implements gfx.Object. It sets the visibility status of the object on screen.

func (*Line[T]) SetPosition

func (obj *Line[T]) SetPosition(x1, y1, x2, y2 int)

Set the line position (start and end point).

type Object

type Object[T pixel.Color] interface {
	// Draw the object on the given image.
	// The X and Y coordinates are the offsets of img from the top left (0, 0)
	// of the canvas.
	Draw(x, y int, img pixel.Image[T])

	// SetHidden changes the visibility of an object.
	SetHidden(bool)
	// contains filtered or unexported methods
}

Object on a canvas.

type Rect

type Rect[T pixel.Color] struct {
	// contains filtered or unexported fields
}

Rect is a simple solid color rectangle.

func NewRect

func NewRect[T pixel.Color](color T, x, y, width, height int) *Rect[T]

NewRect returns a new rectangle of the given size to be added to the canvas.

func (*Rect[T]) Bounds

func (obj *Rect[T]) Bounds() (x, y, width, height int)

Bounds returns the rectangle coordinates relative to (0, 0) of the canvas.

func (*Rect[T]) Draw

func (obj *Rect[T]) Draw(imgX, imgY int, img pixel.Image[T])

Draw implements the gfx.Object interface.

func (*Rect[T]) Hidden

func (obj *Rect[T]) Hidden() bool

Hidden returns whether this object is currently hidden.

func (*Rect[T]) Move

func (obj *Rect[T]) Move(x, y int)

Move the rectangle to the new coordinates.

func (*Rect[T]) SetColor

func (obj *Rect[T]) SetColor(color T)

SetColor changes the color of the rectangle.

func (*Rect[T]) SetHidden

func (obj *Rect[T]) SetHidden(hidden bool)

SetHidden implements gfx.Object. It sets the visibility status of the rectangle on screen.

Jump to

Keyboard shortcuts

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