paint

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

The paint package provides utilities for painting all kinds of things using Ebiten.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetManager

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

func NewAssetManager

func NewAssetManager(fs fs.FS) *AssetManager

NewAssetManager creates a new asset manager for loading images and more based on a file system. You can, for example, use this with go:embed (which you should probably).

func (*AssetManager) Clear

func (am *AssetManager) Clear()

func (*AssetManager) GetFont

func (am *AssetManager) GetFont(path string) (*text.GoTextFaceSource, error)

GetFont loads a font from the asset file system and caches it.

Automatic cleanup of the cache is planned.

func (*AssetManager) GetImage

func (am *AssetManager) GetImage(path string) (*ebiten.Image, error)

GetImage loads an image from a certain path in the asset file system. It supports caching as well.

Automatic cleanup of the cache is planned.

type EbitenPainter

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

func NewEbitenPainter

func NewEbitenPainter(screen *ebiten.Image, antialias bool, assets *AssetManager) *EbitenPainter

Create a new renderer using Ebitengine's image API and a custom filesystem for assets.

func (*EbitenPainter) Clear

func (er *EbitenPainter) Clear()

func (*EbitenPainter) DrawRaw

func (er *EbitenPainter) DrawRaw(image *ebiten.Image, op *ebiten.DrawImageOptions)

func (*EbitenPainter) Paint

func (er *EbitenPainter) Paint(command RenderCommand)

func (*EbitenPainter) PaintMulti

func (er *EbitenPainter) PaintMulti(commands []RenderCommand)

func (*EbitenPainter) Screen

func (er *EbitenPainter) Screen() *ebiten.Image

func (*EbitenPainter) SetTransform

func (e *EbitenPainter) SetTransform(transform Transform)

func (*EbitenPainter) Transform

func (e *EbitenPainter) Transform() Transform

type Image

type Image struct {
	Path       string        `json:"path"`
	Position   scath.Vec     `json:"position"`
	Size       scath.Vec     `json:"size"`
	FilterMode ebiten.Filter `json:"filterMode"`
}

func (Image) ID

func (Image) ID() string

type Line

type Line struct {
	Start     scath.Vec   `json:"start"`
	End       scath.Vec   `json:"end"`
	Color     color.Color `json:"color"`
	Thickness float64     `json:"thickness"`
}

func (Line) ID

func (Line) ID() string

type Painter

type Painter interface {
	// Get the current transform
	Transform() Transform

	// Set a transform
	SetTransform(transform Transform)

	// Clear the canvas for a new frame
	Clear()

	// Should draw one render command on top of everything else that has already been drawn.
	Paint(command RenderCommand)

	// Draw an image directly onto the screen
	DrawRaw(image *ebiten.Image, op *ebiten.DrawImageOptions)

	// Should draw all of the commands in order, the first index gets drawn first, etc.
	PaintMulti(commands []RenderCommand)
}

type Rectangle

type Rectangle struct {
	Position     scath.Vec   `json:"position"`
	Size         scath.Vec   `json:"size"`
	FillColor    color.Color `json:"fillColor"`
	BorderRadius float64     `json:"borderRadius"`
}

func (Rectangle) ID

func (Rectangle) ID() string

type RectangleStroke

type RectangleStroke struct {
	Position     scath.Vec   `json:"position"`
	Size         scath.Vec   `json:"size"`
	Color        color.Color `json:"color"`
	BorderRadius float64     `json:"borderRadius"`
	Thickness    float64     `json:"thickness"`
}

func (RectangleStroke) ID

func (RectangleStroke) ID() string

type RenderCommand

type RenderCommand interface {
	ID() string
}

This is so we can actually parse commands to JSON. Why? For live-reloading, but that's a future ambition.

type Text

type Text struct {
	Direction      text.Direction `json:"direction"`
	Font           string         `json:"font"`
	Color          color.Color    `json:"color"`
	FontSize       float64        `json:"fontSize"`
	LineSpacing    float64        `json:"lineSpacing"`
	Text           string         `json:"text"`
	Position       scath.Vec      `json:"position"`
	PrimaryAlign   text.Align     `json:"primaryAlign"`
	SecondaryAlign text.Align     `json:"secondaryAlign"`
}

func (Text) ID

func (Text) ID() string

type Transform

type Transform struct {
	CamX          float64
	CamY          float64
	CenterOffsetX float64
	CenterOffsetY float64
	Angle         float64 // in radians
	ZoomFactor    float64
}

func NewTransform

func NewTransform() Transform

NewTransform returns a default Transform with scale (1, 1).

Jump to

Keyboard shortcuts

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