gruid-sdl – codeberg.org/anaseto/gruid-sdl Index | Files

package sdl

import "codeberg.org/anaseto/gruid-sdl"

Package sdl provides a Driver for making native graphical apps.

Index

Types

type Config

type Config struct {
	TileManager TileManager // for retrieving tiles (required)
	Width       int32       // initial screen width in cells (default: 80)
	Height      int32       // initial screen height in cells (default: 24)
	Fullscreen  bool        // use “real” fullscreen with a videomode change
	Accelerated bool        // use accelerated renderer (rarely necessary)
	WindowTitle string      // window title (default: gruid go-sdl2)
	WindowIcon  image.Image // window icon (optional)
}

Config contains configurations options for the driver.

type Driver

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

Driver implements gruid.Driver using the go-sdl2 bindings for the SDL library. When using an gruid.App, Start has to be used on the main routine, as the video functions of SDL are not thread safe.

func NewDriver

func NewDriver(cfg Config) *Driver

NewDriver returns a new driver with given configuration options.

func (*Driver) ClearCache

func (dr *Driver) ClearCache()

ClearCache clears the tile textures internal cache.

func (*Driver) Close

func (dr *Driver) Close()

Close implements gruid.Driver.Close. It releases some resources and calls sdl.Quit.

func (*Driver) Flush

func (dr *Driver) Flush(frame gruid.Frame)

Flush implements gruid.Driver.Flush.

func (*Driver) Init

func (dr *Driver) Init() error

Init implements gruid.Driver.Init. It initializes structures and calls sdl.Init().

func (*Driver) PollMsg

func (dr *Driver) PollMsg() (gruid.Msg, error)

PollMsg makes Driver implement gruid.DriverPollMsg. It returns return an input message, if any, in a non-blocking way.

func (*Driver) PollMsgs

func (dr *Driver) PollMsgs(ctx context.Context, msgs chan<- gruid.Msg) error

PollMsgs implements gruid.Driver.PollMsgs.

func (*Driver) PreventQuit

func (dr *Driver) PreventQuit()

PreventQuit will make next call to Close keep sdl and the main window running. It can be used to chain two applications with the same sdl session and window. It is then your reponsibility to either run another application or call Close manually to properly quit.

func (*Driver) SetScale

func (dr *Driver) SetScale(scaleX, scaleY float32)

SetScale modifies the rendering scale for rendering, and updates the window size accordingly. Integer values give more accurate results.

func (*Driver) SetTileManager

func (dr *Driver) SetTileManager(tm TileManager)

SetTileManager allows to change the used tile manager. If the driver is already running, change will take effect with next Flush so that the function is thread safe.

func (*Driver) SetWindowTitle

func (dr *Driver) SetWindowTitle(title string)

SetWindowTitle sets the window title.

type TileManager

type TileManager interface {
	// GetImage returns the image to be used for a given cell style.
	GetImage(gruid.Cell) image.Image

	// TileSize returns the (width, height) in pixels of the tiles. Both
	// should be positive and non-zero.
	TileSize() gruid.Point
}

TileManager manages tiles fetching.

Source Files

sdl.go

Version
v0.5.0 (latest)
Published
Aug 23, 2023
Platform
linux/amd64
Imports
11 packages
Last checked
1 week ago

Tools for package owners.