sdl

package
v0.0.0-...-c624cc0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 10 Imported by: 12

Documentation

Overview

Package sdl provides an SDL2 renderer for Doodle.

Package sdl provides an SDL2 renderer for Doodle.

Index

Constants

This section is empty.

Variables

View Source
var (
	DebugWindowEvents     = false
	DebugTouchEvents      = false
	DebugMouseEvents      = false
	DebugClickEvents      = false
	DebugKeyEvents        = false
	DebugControllerEvents = false
)

Debug certain SDL events

View Source
var DefaultFontFilename = "DejaVuSans.ttf"

TODO: font filenames

View Source
var (
	// For controllers having a digital (non-analog) Left/Right Trigger, the press percentage
	// for which to consider it a boolean press.
	TriggerAxisBooleanThreshold float64 = 0.5
)

User tuneable properties.

Functions

func ColorToSDL

func ColorToSDL(c render.Color) sdl.Color

ColorToSDL converts Doodle's Color type to an sdl.Color.

func InstallFont

func InstallFont(filename string, binary []byte)

InstallFont preloads the font cache using TTF binary data in memory.

func LoadFont

func LoadFont(filename string, size int) (*ttf.Font, error)

LoadFont loads and caches the font at a given size.

func RectToSDL

func RectToSDL(r render.Rect) sdl.Rect

RectToSDL converts Doodle's Rect type to an sdl.Rect.

Types

type Font

type Font struct {
	Filename string
	// contains filtered or unexported fields
}

Font holds cached SDL_TTF structures for loaded fonts. They are created automatically when fonts are either preinstalled (InstallFont) or loaded for the first time as demanded by the DrawText method.

type GameController

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

GameController holds an abstraction around SDL2 GameControllers.

func NewGameController

func NewGameController(index int, name string, ctrl *sdl.GameController) *GameController

NewGameController creates a GameController from an SDL2 controller.

func (*GameController) ButtonA

func (gc *GameController) ButtonA() bool

ButtonA returns whether the logical Xbox button is pressed.

func (*GameController) ButtonB

func (gc *GameController) ButtonB() bool

ButtonB returns whether the logical Xbox button is pressed.

func (*GameController) ButtonDown

func (gc *GameController) ButtonDown() bool

ButtonDown returns whether the Xbox D-Pad button is pressed.

func (*GameController) ButtonHome

func (gc *GameController) ButtonHome() bool

ButtonHome returns whether the Xbox "guide" button is pressed.

func (*GameController) ButtonL1

func (gc *GameController) ButtonL1() bool

ButtonL1 returns whether the Left Shoulder button is pressed.

func (*GameController) ButtonL2

func (gc *GameController) ButtonL2() bool

ButtonL2 returns whether the Left Trigger (digital) button is pressed. Returns true if the LeftTrigger is 50% pressed or TriggerAxisBooleanThreshold.

func (*GameController) ButtonLStick

func (gc *GameController) ButtonLStick() bool

ButtonLStick returns whether the Left Stick button is pressed.

func (*GameController) ButtonLeft

func (gc *GameController) ButtonLeft() bool

ButtonLeft returns whether the Xbox D-Pad button is pressed.

func (*GameController) ButtonR1

func (gc *GameController) ButtonR1() bool

ButtonR1 returns whether the Right Shoulder button is pressed.

func (*GameController) ButtonR2

func (gc *GameController) ButtonR2() bool

ButtonR2 returns whether the Left Trigger (digital) button is pressed. Returns true if the LeftTrigger is 50% pressed or TriggerAxisBooleanThreshold.

func (*GameController) ButtonRStick

func (gc *GameController) ButtonRStick() bool

ButtonRStick returns whether the Right Stick button is pressed.

func (*GameController) ButtonRight

func (gc *GameController) ButtonRight() bool

ButtonRight returns whether the Xbox D-Pad button is pressed.

func (*GameController) ButtonSelect

func (gc *GameController) ButtonSelect() bool

ButtonSelect returns whether the Xbox "back" button is pressed.

func (*GameController) ButtonStart

func (gc *GameController) ButtonStart() bool

ButtonStart returns whether the logical Xbox button is pressed.

func (*GameController) ButtonUp

func (gc *GameController) ButtonUp() bool

ButtonUp returns whether the Xbox D-Pad button is pressed.

func (*GameController) ButtonX

func (gc *GameController) ButtonX() bool

ButtonX returns whether the logical Xbox button is pressed.

func (*GameController) ButtonY

func (gc *GameController) ButtonY() bool

ButtonY returns whether the logical Xbox button is pressed.

func (*GameController) GetAxisState

func (gc *GameController) GetAxisState(name string) int

GetAxisState returns the underlying SDL2 axis state.

func (*GameController) GetButtonState

func (gc *GameController) GetButtonState(name string) bool

GetButtonState returns the button state by SDL2 button name.

func (*GameController) ID

func (gc *GameController) ID() int

ID returns the controller index as SDL2 knows it.

func (*GameController) LeftStick

func (gc *GameController) LeftStick() event.Vector

LeftStick returns the vector of X and Y of the left analog stick.

func (*GameController) LeftTrigger

func (gc *GameController) LeftTrigger() float64

LeftTrigger returns the vector of the left analog trigger.

func (*GameController) Name

func (gc *GameController) Name() string

Name returns the controller name.

func (*GameController) RightStick

func (gc *GameController) RightStick() event.Vector

RightStick returns the vector of X and Y of the right analog stick.

func (*GameController) RightTrigger

func (gc *GameController) RightTrigger() float64

RightTrigger returns the vector of the left analog trigger.

func (*GameController) SetAxisState

func (gc *GameController) SetAxisState(name string, value int)

SetAxisState sets the axis state.

func (*GameController) SetButtonState

func (gc *GameController) SetButtonState(name string, pressed bool)

SetButtonState sets the state using the SDL2 button names.

type Renderer

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

Renderer manages the SDL state.

func New

func New(title string, width, height int) *Renderer

New creates the SDL renderer.

func (*Renderer) Clear

func (r *Renderer) Clear(color render.Color)

Clear the canvas and set this color.

func (*Renderer) ComputeTextRect

func (r *Renderer) ComputeTextRect(text render.Text) (render.Rect, error)

ComputeTextRect computes and returns a Rect for how large the text would appear if rendered.

func (*Renderer) Copy

func (r *Renderer) Copy(t render.Texturer, src, dst render.Rect)

Copy a texture into the renderer.

func (*Renderer) CountTextures

func (r *Renderer) CountTextures() int

CountTextures is a custom function for the SDL2 Engine only that returns the size of the engine texture cache.

func (*Renderer) Delay

func (r *Renderer) Delay(time uint32)

Delay using sdl.Delay

func (*Renderer) DrawBox

func (r *Renderer) DrawBox(color render.Color, rect render.Rect)

DrawBox draws a filled rectangle.

func (*Renderer) DrawLine

func (r *Renderer) DrawLine(color render.Color, a, b render.Point)

DrawLine draws a line between two points.

func (*Renderer) DrawPoint

func (r *Renderer) DrawPoint(color render.Color, point render.Point)

DrawPoint puts a color at a pixel.

func (*Renderer) DrawRect

func (r *Renderer) DrawRect(color render.Color, rect render.Rect)

DrawRect draws a rectangle.

func (*Renderer) DrawText

func (r *Renderer) DrawText(text render.Text, point render.Point) error

DrawText draws text on the canvas.

func (*Renderer) FreeTextures

func (r *Renderer) FreeTextures() int

FreeTextures flushes the internal cache of SDL2 textures and frees their memory.

func (*Renderer) GetSDL2Renderer

func (r *Renderer) GetSDL2Renderer() *sdl.Renderer

Private access methods

func (*Renderer) GetTicks

func (r *Renderer) GetTicks() uint32

GetTicks gets SDL's current tick count.

func (*Renderer) ListTextures

func (r *Renderer) ListTextures() []string

ListTextures is a custom function to peek into the SDL2 texture cache names.

func (*Renderer) LoadTexture

func (r *Renderer) LoadTexture(name string) (render.Texturer, error)

LoadTexture initializes a texture from a bitmap image.

func (*Renderer) Loop

func (r *Renderer) Loop() error

Loop is the main loop.

func (*Renderer) Maximize

func (r *Renderer) Maximize()

Maximize the window.

func (*Renderer) Poll

func (r *Renderer) Poll() (*event.State, error)

Poll for events.

func (*Renderer) Present

func (r *Renderer) Present() error

Present the current frame.

func (*Renderer) SetTitle

func (r *Renderer) SetTitle(title string)

SetTitle sets the SDL window title.

func (*Renderer) SetWindowIcon

func (r *Renderer) SetWindowIcon(icon image.Image) error

SetWindowIcon sets an icon for the SDL2 window.

func (*Renderer) Setup

func (r *Renderer) Setup() error

Setup the renderer.

func (*Renderer) ShowCursor

func (r *Renderer) ShowCursor(v bool)

ShowCursor sets whether the mouse cursor should be visible.

func (*Renderer) StoreTexture

func (r *Renderer) StoreTexture(name string, img image.Image) (render.Texturer, error)

StoreTexture caches an SDL texture from a bitmap.

func (*Renderer) Teardown

func (r *Renderer) Teardown()

Teardown tasks when exiting the program.

func (*Renderer) WindowSize

func (r *Renderer) WindowSize() (int, int)

WindowSize returns the SDL window size.

type Texture

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

Texture can hold on to SDL textures for caching and optimization.

func (*Texture) Free

func (t *Texture) Free() error

Free the SDL2 texture object.

func (*Texture) Image

func (t *Texture) Image() image.Image

Image returns the underlying Go image.Image.

func (*Texture) Size

func (t *Texture) Size() render.Rect

Size returns the dimensions of the texture.

Jump to

Keyboard shortcuts

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