gui

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

func BarHeight added in v0.5.0

func BarHeight(squareSize int) int

BarHeight is the info bar's height for a given square size, floored so the two lines of text always fit.

func DrawFrame added in v0.5.0

func DrawFrame(c *canvas.Canvas, cfg Config, f Faces, v BoardView)

DrawFrame composes a whole frame onto c: the board, the highlights, the pieces, the info bar and — once the game ends — the result banner. Drawing through the software canvas rather than the display means the same code paints a live window and a headless recording, pixel for pixel.

func FrameSize added in v0.5.0

func FrameSize(cfg Config) (w, h int)

FrameSize is the window's pixel size for a given square size.

func Render added in v0.5.0

func Render(cfg Config) error

Render records a game to cfg.Rec.Path without opening a window, one frame per move. Frames come from the same DrawFrame the window uses, so the media matches what a player sees — and it needs no display.

The file extension picks the format: .gif or .mp4.

func Run

func Run(cfg Config) error

Types

type BoardView added in v0.5.0

type BoardView struct {
	Snapshot [64]chess.Piece
	Flipped  bool
	Selected chess.Square
	// Legal is the current legal move list, used to light up the squares the
	// selected piece can reach.
	Legal []chess.Move

	WhiteName, BlackName string
	Moves                int
	Over                 bool
	Paused               bool
	AwaitingHuman        bool
	Result               chess.Result
	DrawReason           chess.DrawReason
}

BoardView is everything a frame draws: the position, what the player has selected, and how the game stands.

type Config

type Config struct {
	Game    *game.Game
	NewGame func() *game.Game
	Logger  *applog.Logger

	SquareSize   int
	LightSquare  color.RGBA
	DarkSquare   color.RGBA
	MoveDelay    time.Duration
	ThinkTimeout time.Duration

	// Rec names the recording [Render] writes; RecordDelay is gambit's own
	// per-move frame delay for the paced clip. Both are set by tools/demogen.
	Rec         record.Options
	RecordDelay int
}

func DefaultConfig

func DefaultConfig() Config

type Faces added in v0.5.0

type Faces struct {
	Piece  font.Face
	Bar    font.Face
	Banner font.Face
}

Faces are the three sizes the board draws in: the piece figurines, the info bar, and the end-of-game banner.

func LoadFaces added in v0.5.0

func LoadFaces(squareSize, barHeight int) (Faces, error)

LoadFaces renders the bundled font at the sizes a board of the given square size needs. It returns display-free faces, so the same typography serves a live window and a headless recording.

Jump to

Keyboard shortcuts

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