platform

package
v0.0.0-...-1344eab Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Platform abstracts platoform specific actions such as creating a window and gathering input events. It is currently implemented with SDL2 but the intent is to encapsulate all SDL functionality and and make it easy to swap out for other platform tools if needed. The platform package does not define its own abstactions. Instead it conforms to the needs of other ngl packages. For example, although it needs a keypress abstraction, it uses that of the input package.

Index

Constants

View Source
const (
	KeyboardA = iota + sdl.SCANCODE_A
	KeyboardB
	KeyboardC
	KeyboardD
	KeyboardE
	KeyboardF
	KeyboardG
	KeyboardH
	KeyboardI
	KeyboardJ
	KeyboardK
	KeyboardL
	KeyboardM
	KeyboardN
	KeyboardO
	KeyboardP
	KeyboardQ
	KeyboardR
	KeyboardS
	KeyboardT
	KeyboardU
	KeyboardV
	KeyboardW
	KeyboardX
	KeyboardY
	KeyboardZ
)
View Source
const (
	Keyboard1 = iota + sdl.SCANCODE_1
	Keyboard2
	Keyboard3
	Keyboard4
	Keyboard5
	Keyboard6
	Keyboard7
	Keyboard8
	Keyboard9
	Keyboard0
)
View Source
const (
	KeyboardReturn = iota + sdl.SCANCODE_RETURN
	KeyboardEscape
	KeyboardBackspace
	KeyboardTab
	KeyboardSpace
)
View Source
const (
	KeyboardRight = iota + sdl.SCANCODE_RIGHT
	KeyboardLeft
	KeyboardDown
	KeyboardUp
)
View Source
const (
	KeyboardLCtrl = iota + sdl.SCANCODE_LCTRL
	KeyboardLShift
	KeyboardLAlt
	KeyboardLMeta
	KeyboardRCtrl
	KeyboardRShift
	KeyboardRAlt
)

Variables

This section is empty.

Functions

func GLSwap

func GLSwap()

func GetWindowSize

func GetWindowSize() (width, height int32)

GetWindowSize returns the window's dimensions

func InitializeWindow

func InitializeWindow(width, height int, name string, resizeable bool, fullscreen bool) error

InitializeWindow a window of width x height and set its name

func Quit

func Quit()

Types

type EventManager

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

func (*EventManager) GatherEvents

func (m *EventManager) GatherEvents()

GatherEvents parses sdl events and stores them internally. The events can be accessed using EventManager's Get functions. Currently handles keyboard input, window resizing and the quit event.

Keyboard events are parsed and converted into a list of keypresses as specified in the input package

Window resize events are simply stored as a list of points.

func (*EventManager) GetKeyboardEvents

func (m *EventManager) GetKeyboardEvents() []input.KeyboardEvent

func (*EventManager) GetQuitEvent

func (m *EventManager) GetQuitEvent() bool

func (*EventManager) GetResizeEvents

func (m *EventManager) GetResizeEvents() []math.Vector2[int]

type InputState

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

InputState holds state information about input devices. Used as a low-level alternative to EventManager when using events is not sufficient like game input or typing with a custom repeat frequency.

func NewInputState

func NewInputState() *InputState

func (*InputState) GetState

func (s *InputState) GetState()

Refresh input state. Call this in a loop.

func (*InputState) KeyDown

func (s *InputState) KeyDown(key KeyboardKey) bool

Returns true if the key is pressed false otherwise.

func (*InputState) KeyValue

func (s *InputState) KeyValue(key KeyboardKey) float32

Returns 1 if the key is pressed 0 otherwise.

func (*InputState) MouseButtonDown

func (s *InputState) MouseButtonDown(button MouseButton) bool

Check if the mouse button is pressed.

func (*InputState) MouseButtonValue

func (s *InputState) MouseButtonValue(button MouseButton) float32

Returns 1 if the button is pressed 0 otherwise.

func (*InputState) MousePosition

func (s *InputState) MousePosition() math.Vector2[float32]

Returns the mouse position normalized by the window dimentions.

type KeyboardKey

type KeyboardKey int

type MouseButton

type MouseButton int
const (
	MouseLeft MouseButton = iota
	MouseMiddle
	MouseRight
	MouseButtonDown
	MouseButtonUp
)

Jump to

Keyboard shortcuts

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