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
- func GLSwap()
- func GetWindowSize() (width, height int32)
- func InitializeWindow(width, height int, name string, resizeable bool, fullscreen bool) error
- func Quit()
- type EventManager
- type InputState
- func (s *InputState) GetState()
- func (s *InputState) KeyDown(key KeyboardKey) bool
- func (s *InputState) KeyValue(key KeyboardKey) float32
- func (s *InputState) MouseButtonDown(button MouseButton) bool
- func (s *InputState) MouseButtonValue(button MouseButton) float32
- func (s *InputState) MousePosition() math.Vector2[float32]
- type KeyboardKey
- type MouseButton
Constants ¶
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 )
const ( Keyboard1 = iota + sdl.SCANCODE_1 Keyboard2 Keyboard3 Keyboard4 Keyboard5 Keyboard6 Keyboard7 Keyboard8 Keyboard9 Keyboard0 )
const ( KeyboardReturn = iota + sdl.SCANCODE_RETURN KeyboardEscape KeyboardBackspace KeyboardTab KeyboardSpace )
const ( KeyboardRight = iota + sdl.SCANCODE_RIGHT KeyboardLeft KeyboardDown KeyboardUp )
const ( KeyboardLCtrl = iota + sdl.SCANCODE_LCTRL KeyboardLShift KeyboardLAlt KeyboardLMeta KeyboardRCtrl KeyboardRShift KeyboardRAlt )
Variables ¶
This section is empty.
Functions ¶
func GetWindowSize ¶
func GetWindowSize() (width, height int32)
GetWindowSize returns the window's dimensions
func InitializeWindow ¶
InitializeWindow a window of width x height and set its name
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 )