sdl

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: ISC Imports: 11 Imported by: 1

README

gruid-sdl

pkg.go.dev godocs.io

The gruid-sdl2 module provides a gruid Driver for using the SDL2 library to build native graphical applications.

The module's package is called sdl. For it to work, you need to install the SDL2 library on your system before.

Be sure to install the dev version of the package, for distributions that make such a distinction. For example, in Debian-derived systems, a command like apt install libsdl2-dev may be used.

Documentation

Overview

Package sdl provides a Driver for making native graphical apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 added in v0.4.0

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.

Jump to

Keyboard shortcuts

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