sdl

package
v0.0.0-...-dcd4c77 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2014 License: MIT Imports: 7 Imported by: 3

Documentation

Overview

Package sdl provides a binding of SDL2 with an object-oriented twist.

The Do Function

SDL is not an inherently thread-safe library, and some operating systems force windowing calls to be made on the main thread. Thus, most functions in this package must be called from the Do function, and the main function must call sdl.Main.

package main

import "github.com/adam000/Go-SDL2/sdl"

func main() {
	go run()
	sdl.Main()
}

func run() {
	defer sdl.Quit()

	sdl.Do(func() {
		// make SDL calls here
	})
}

Pointers And Destruction

These bindings will return pointers to the actual underlying SDL structures in many places. These data types will not be garbage- collected because they are allocated by C. When you are finished with such a pointer, you must call the Destroy method. Any further usage of a pointer after the Destroy call will likely lead to a dangling pointer issue.

Index

Constants

View Source
const (
	WindowPosUndefined = C.SDL_WINDOWPOS_UNDEFINED
	WindowPosCentered  = C.SDL_WINDOWPOS_CENTERED
)

Window positions. Used for the origin in NewWindow.

Variables

This section is empty.

Functions

func Do

func Do(f func())

Do executes a function on the main thread. Calls to Do cannot nest -- calling Do inside of a function passed to Do will cause deadlock.

func GetError

func GetError() error

GetError returns the current SDL error as a Go error value. This is internal to SDL but exported because it is cross-package.

func GetMouseState

func GetMouseState() (x, y int32, buttonMask uint32)

GetMouseState returns the current mouse (x, y) position relative to the focus window and buttons pressed.

func HasEvent

func HasEvent() bool

HasEvent returns whether there is a pending event available.

func Init

func Init(flags ...InitFlag) error

Init initializes SDL subsystems. Multiple flags will be ORed together. You don't have to call Init unless you need a particular subsystem.

func Main

func Main()

Main runs the main SDL service loop. The binary's main.main must call sdl.Main() to run this loop. If the binary needs to do other work, it must do it in separate goroutines. Main will return after calling Quit.

func Quit

func Quit()

Quit cleans up SDL. Main will return after calling Quit.

Types

type ControllerAxisEvent

type ControllerAxisEvent struct {
	Time  uint32
	Which JoystickID
	Axis  uint8 // TODO(light): GameControllerAxis
	Value int16
}

ControllerAxisEvent holds a controller axis movement event.

func (*ControllerAxisEvent) Timestamp

func (e *ControllerAxisEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*ControllerAxisEvent) Type

func (e *ControllerAxisEvent) Type() EventType

Type returns ControllerAxisMotionEventType.

type ControllerButtonEvent

type ControllerButtonEvent struct {
	Time    uint32
	Which   JoystickID
	Button  uint8 // TODO(light): GameControllerButton
	Pressed bool
}

ControllerButtonEvent holds a game controller button event.

func (*ControllerButtonEvent) Timestamp

func (e *ControllerButtonEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*ControllerButtonEvent) Type

func (e *ControllerButtonEvent) Type() EventType

Type returns ControllerButtonDownEventType or ControllerButtonUpEventType.

type ControllerDeviceEvent

type ControllerDeviceEvent struct {
	EventType EventType
	Time      uint32
	Which     int32 // the device index for add events, otherwise the instance ID
}

ControllerDeviceEvent holds a game controller device change event.

func (*ControllerDeviceEvent) Timestamp

func (e *ControllerDeviceEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*ControllerDeviceEvent) Type

func (e *ControllerDeviceEvent) Type() EventType

Type returns one of ControllerDeviceAddedEventType, ControllerDeviceRemovedEventType, or ControllerDeviceRemappedEventType.

type DollarGestureEvent

type DollarGestureEvent struct {
	Time       uint32
	TouchID    int64 // TODO(light): SDL_TouchID
	GestureID  int64 // TODO(light): SDL_GestureID
	NumFingers int
	Error      float32 // difference between recognized and actual gesture (lower is better)
	X, Y       float32 // center
	Record     bool
}

DollarGestureEvent holds a gesture recognition event.

func (*DollarGestureEvent) Timestamp

func (e *DollarGestureEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*DollarGestureEvent) Type

func (e *DollarGestureEvent) Type() EventType

Type returns DollarGestureEventType or DollarRecordEventType.

type DropEvent

type DropEvent struct {
	Time uint32
	Path string
}

DropEvent holds a file-open (usually by drag-and-drop) event.

func (*DropEvent) Timestamp

func (e *DropEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*DropEvent) Type

func (e *DropEvent) Type() EventType

Type returns DropFileEventType.

type Error

type Error string

Error stores an SDL error.

func (Error) Error

func (e Error) Error() string

type Event

type Event interface {
	// Type returns the event's type.
	Type() EventType

	// Timestamp returns the number of milliseconds since the SDL library initialization.
	Timestamp() uint32
}

Event is implemented by all SDL events.

func PollEvent

func PollEvent() Event

PollEvent returns the next available event, or nil if there is no event pending.

type EventType

type EventType uint32

EventType represents the type of an application event.

const (
	FirstEventType EventType = C.SDL_FIRSTEVENT

	// Events UserEvent through LastEvent are for your use, and should be allocated
	// with RegisterEvents.
	UserEventType EventType = C.SDL_USEREVENT
	LastEventType EventType = C.SDL_LASTEVENT
)

Special event numbers

const (
	QuitEventType EventType = C.SDL_QUIT

	// These application events have special meaning on iOS, see README-ios.txt for details
	AppTerminatingEventType         EventType = C.SDL_APP_TERMINATING
	AppLowMemoryEventType           EventType = C.SDL_APP_LOWMEMORY
	AppWillEnterBackgroundEventType EventType = C.SDL_APP_WILLENTERBACKGROUND
	AppDidEnterBackgroundEventType  EventType = C.SDL_APP_DIDENTERBACKGROUND
	AppWillEnterForegroundEventType EventType = C.SDL_APP_WILLENTERFOREGROUND
	AppDidEnterForegroundEventType  EventType = C.SDL_APP_DIDENTERFOREGROUND
)

Application events

const (
	WindowEventType EventType = C.SDL_WINDOWEVENT
	SysWMEventType  EventType = C.SDL_SYSWMEVENT
)

Window events

const (
	KeyDownEventType     EventType = C.SDL_KEYDOWN
	KeyUpEventType       EventType = C.SDL_KEYUP
	TextEditingEventType EventType = C.SDL_TEXTEDITING
	TextInputEventType   EventType = C.SDL_TEXTINPUT
)

Keyboard events

const (
	MouseMotionEventType     EventType = C.SDL_MOUSEMOTION
	MouseButtonDownEventType EventType = C.SDL_MOUSEBUTTONDOWN
	MouseButtonUpEventType   EventType = C.SDL_MOUSEBUTTONUP
	MouseWheelEventType      EventType = C.SDL_MOUSEWHEEL
)

Mouse events

const (
	JoyAxisMotionEventType    EventType = C.SDL_JOYAXISMOTION
	JoyBallMotionEventType    EventType = C.SDL_JOYBALLMOTION
	JoyHatMotionEventType     EventType = C.SDL_JOYHATMOTION
	JoyButtonDownEventType    EventType = C.SDL_JOYBUTTONDOWN
	JoyButtonUpEventType      EventType = C.SDL_JOYBUTTONUP
	JoyDeviceAddedEventType   EventType = C.SDL_JOYDEVICEADDED
	JoyDeviceRemovedEventType EventType = C.SDL_JOYDEVICEREMOVED
)

Joystick events

const (
	ControllerAxisMotionEventType     EventType = C.SDL_CONTROLLERAXISMOTION
	ControllerButtonDownEventType     EventType = C.SDL_CONTROLLERBUTTONDOWN
	ControllerButtonUpEventType       EventType = C.SDL_CONTROLLERBUTTONUP
	ControllerDeviceAddedEventType    EventType = C.SDL_CONTROLLERDEVICEADDED
	ControllerDeviceRemovedEventType  EventType = C.SDL_CONTROLLERDEVICEREMOVED
	ControllerDeviceRemappedEventType EventType = C.SDL_CONTROLLERDEVICEREMAPPED
)

Game controller events

const (
	FingerDownEventType   EventType = C.SDL_FINGERDOWN
	FingerUpEventType     EventType = C.SDL_FINGERUP
	FingerMotionEventType EventType = C.SDL_FINGERMOTION
)

Touch events

const (
	DollarGestureEventType EventType = C.SDL_DOLLARGESTURE
	DollarRecordEventType  EventType = C.SDL_DOLLARRECORD
	MultiGestureEventType  EventType = C.SDL_MULTIGESTURE
)

Gesture events

const (
	ClipboardUpdateEventType EventType = C.SDL_CLIPBOARDUPDATE
)

Clipboard events

const (
	DropFileEventType EventType = C.SDL_DROPFILE
)

Drag and drop events

func (EventType) IsUserEvent

func (t EventType) IsUserEvent() bool

IsUserEvent reports whether t is a custom application event.

func (EventType) String

func (t EventType) String() string

String returns the name of the event type.

type GLContext

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

A GLContext is an opaque handle to an OpenGL context.

func NewGLContext

func NewGLContext(w *Window) (GLContext, error)

NewGLContext creates a new GLContext for use with w and makes it the current context.

func (GLContext) Destroy

func (ctx GLContext) Destroy()

Destroy destroys the OpenGL context. It is not safe to use the context after Destroy is called.

func (GLContext) MakeCurrent

func (ctx GLContext) MakeCurrent(w *Window) error

MakeCurrent makes the context the current context and associates it with w. w must be a compatible window.

type HatPosition

type HatPosition uint8

HatPosition is a joystick hat position. Cardinal directions are OR'd together to describe diagonals.

const (
	HatCentered HatPosition = C.SDL_HAT_CENTERED

	HatUp    HatPosition = C.SDL_HAT_UP
	HatRight HatPosition = C.SDL_HAT_RIGHT
	HatDown  HatPosition = C.SDL_HAT_DOWN
	HatLeft  HatPosition = C.SDL_HAT_LEFT

	// OR'd combinations of the above.
	HatRightUp   HatPosition = C.SDL_HAT_RIGHTUP
	HatRightDown HatPosition = C.SDL_HAT_RIGHTDOWN
	HatLeftUp    HatPosition = C.SDL_HAT_LEFTUP
	HatLeftDown  HatPosition = C.SDL_HAT_LEFTDOWN
)

Hat positions.

type InitFlag

type InitFlag uint32

An InitFlag represents a set of SDL subsystems to initialize.

const (
	InitTimer          InitFlag = C.SDL_INIT_TIMER
	InitAudio          InitFlag = C.SDL_INIT_AUDIO
	InitVideo          InitFlag = C.SDL_INIT_VIDEO    // InitVideo implies InitEvents
	InitJoystick       InitFlag = C.SDL_INIT_JOYSTICK // InitJoystick implies InitEvents
	InitHaptic         InitFlag = C.SDL_INIT_HAPTIC
	InitGameController InitFlag = C.SDL_INIT_GAMECONTROLLER // InitGameController implies InitJoystick
	InitEvents         InitFlag = C.SDL_INIT_EVENTS
	InitNoParachute    InitFlag = C.SDL_INIT_NOPARACHUTE // Don't catch fatal signals

	InitEverything InitFlag = C.SDL_INIT_EVERYTHING
)

InitFlag masks.

type JoyAxisEvent

type JoyAxisEvent struct {
	Time  uint32
	Which JoystickID
	Axis  uint8
	Value int16
}

JoyAxisEvent holds a joystick axis movement event.

func (*JoyAxisEvent) Timestamp

func (e *JoyAxisEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*JoyAxisEvent) Type

func (e *JoyAxisEvent) Type() EventType

Type returns JoyAxisMotionEventType.

type JoyBallEvent

type JoyBallEvent struct {
	Time       uint32
	Which      JoystickID
	Ball       uint8
	RelX, RelY int16
}

JoyBallEvent holds a joystick trackball motion event.

func (*JoyBallEvent) Timestamp

func (e *JoyBallEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*JoyBallEvent) Type

func (e *JoyBallEvent) Type() EventType

Type returns JoyBallMotionEventType.

type JoyButtonEvent

type JoyButtonEvent struct {
	Time    uint32
	Which   JoystickID
	Button  uint8
	Pressed bool
}

JoyButtonEvent holds a EVENT

func (*JoyButtonEvent) Timestamp

func (e *JoyButtonEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*JoyButtonEvent) Type

func (e *JoyButtonEvent) Type() EventType

Type returns either JoyButtonDownEventType or JoyButtonUpEventType.

type JoyDeviceEvent

type JoyDeviceEvent struct {
	Time  uint32
	Which int32 // joystick device index for an added event or instance ID for a removal event.
	Added bool
}

JoyDeviceEvent holds a joystick connection or disconnection event.

func (*JoyDeviceEvent) Timestamp

func (e *JoyDeviceEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*JoyDeviceEvent) Type

func (e *JoyDeviceEvent) Type() EventType

Type returns either JoyDeviceAddedEventType or JoyDeviceRemovedEventType.

type JoyHatEvent

type JoyHatEvent struct {
	Time     uint32
	Which    JoystickID
	Hat      uint8
	Position HatPosition
}

JoyHatEvent holds a joystick hat movement event.

func (*JoyHatEvent) Timestamp

func (e *JoyHatEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*JoyHatEvent) Type

func (e *JoyHatEvent) Type() EventType

Type returns JoyHatMotionEventType.

type JoystickID

type JoystickID int32

JoystickID is a transient joystick ID.

type KeySym

type KeySym struct {
	Scancode keys.Scancode
	Code     keys.Code
	Mod      keys.Mod
}

KeySym holds the keyboard information from a keyboard event.

type KeyboardEvent

type KeyboardEvent struct {
	Time     uint32
	WindowID uint32
	Pressed  bool
	Repeat   bool
	KeySym
}

KeyboardEvent holds a key press or key release event.

func (*KeyboardEvent) Timestamp

func (e *KeyboardEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*KeyboardEvent) Type

func (e *KeyboardEvent) Type() EventType

Type returns KeyDownEventType or KeyUpEventType.

func (*KeyboardEvent) Window

func (e *KeyboardEvent) Window() uint32

Window returns the window with keyboard focus or zero.

type MouseButton

type MouseButton uint8

MouseButton is an enumeration of mouse buttons.

const (
	LeftMouseButton   MouseButton = C.SDL_BUTTON_LEFT
	MiddleMouseButton MouseButton = C.SDL_BUTTON_MIDDLE
	RightMouseButton  MouseButton = C.SDL_BUTTON_RIGHT
	X1MouseButton     MouseButton = C.SDL_BUTTON_X1
	X2MouseButton     MouseButton = C.SDL_BUTTON_X2
)

Common mouse buttons

func (MouseButton) Mask

func (mb MouseButton) Mask() uint32

Mask returns the bitmask for checking a mouse state.

func (MouseButton) String

func (mb MouseButton) String() string

String returns the button's name like "LeftMouseButton".

type MouseButtonEvent

type MouseButtonEvent struct {
	Time     uint32
	WindowID uint32
	Which    uint32
	Button   MouseButton
	Pressed  bool
	Clicks   uint8 // number of clicks in sequence: 1 for single-click, 2 for double-click, etc.
	X, Y     int32
}

MouseButtonEvent holds a mouse button press or release event.

func (*MouseButtonEvent) IsTouch

func (e *MouseButtonEvent) IsTouch() bool

IsTouch reports whether this event was generated by a touch input device.

func (*MouseButtonEvent) Timestamp

func (e *MouseButtonEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*MouseButtonEvent) Type

func (e *MouseButtonEvent) Type() EventType

Type returns either MouseButtonDownEventType or MouseButtonUpEventType.

func (*MouseButtonEvent) Window

func (e *MouseButtonEvent) Window() uint32

Window returns the window with mouse focus, or zero if no window has focus.

type MouseMotionEvent

type MouseMotionEvent struct {
	Time       uint32
	WindowID   uint32
	Which      uint32 // mouse that triggered the event
	State      uint32
	X, Y       int32
	RelX, RelY int32
}

MouseMotionEvent holds a mouse movement event.

func (*MouseMotionEvent) Timestamp

func (e *MouseMotionEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*MouseMotionEvent) Type

func (e *MouseMotionEvent) Type() EventType

Type returns MouseMotionEventType.

func (*MouseMotionEvent) Window

func (e *MouseMotionEvent) Window() uint32

WindowID returns the window with mouse focus, or zero if no window has focus.

type MouseWheelEvent

type MouseWheelEvent struct {
	Time     uint32
	WindowID uint32
	Which    uint32
	X, Y     int32 // Scroll delta. The axes increase right and up.
}

MouseWheelEvent holds a mouse wheel movement event.

func (*MouseWheelEvent) Timestamp

func (e *MouseWheelEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*MouseWheelEvent) Type

func (e *MouseWheelEvent) Type() EventType

Type returns MouseWheelEventType.

func (*MouseWheelEvent) Window

func (e *MouseWheelEvent) Window() uint32

Window returns the window with mouse focus, or zero if no window has focus.

type MultiGestureEvent

type MultiGestureEvent struct {
	Time       uint32
	TouchID    int64 // TODO(light): SDL_TouchID
	DTheta     float32
	DDist      float32
	X, Y       float32 // center
	NumFingers int
}

MultiGestureEvent holds a multi-finger touch event.

func (*MultiGestureEvent) Timestamp

func (e *MultiGestureEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*MultiGestureEvent) Type

func (e *MultiGestureEvent) Type() EventType

Type returns MultiGestureEventType.

type PixelData

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

PixelData is a mutable view of a surface's pixels. The data is only available while a surface is locked, so pixel data should be closed to allow the surface to be used again.

PixelData implements the image.Image and draw.Image interfaces. See: http://golang.org/pkg/image/#Image and http://golang.org/pkg/image/draw/#Image.

func (PixelData) At

func (pix PixelData) At(x, y int) color.Color

At returns the pixel at the given position.

func (PixelData) Bounds

func (pix PixelData) Bounds() image.Rectangle

Bounds returns a rectangle of (0,0) => (w,h).

func (PixelData) ColorModel

func (pix PixelData) ColorModel() color.Model

ColorModel returns the color model of the pixel data.

func (PixelData) Destroy

func (pix PixelData) Destroy()

Destroy unlocks the underlying surface. pix should not be used after calling Destroy.

func (PixelData) Set

func (pix PixelData) Set(x, y int, c color.Color)

Set sets the color at an x, y position in the PixelData to a given color.

type PixelFormat

type PixelFormat struct {
	Format PixelFormatEnum
	// TODO(light): palette
	BitsPerPixel  uint8
	BytesPerPixel uint8

	Rmask, Gmask, Bmask, Amask uint32
}

PixelFormat describes a surface's pixel memory format.

type PixelFormatEnum

type PixelFormatEnum uint32

PixelFormatEnum describes the method of storing pixel data.

const (
	PixelFormatUnknown     PixelFormatEnum = C.SDL_PIXELFORMAT_UNKNOWN
	PixelFormatIndex1LSB   PixelFormatEnum = C.SDL_PIXELFORMAT_INDEX1LSB
	PixelFormatIndex1MSB   PixelFormatEnum = C.SDL_PIXELFORMAT_INDEX1MSB
	PixelFormatIndex4LSB   PixelFormatEnum = C.SDL_PIXELFORMAT_INDEX4LSB
	PixelFormatIndex4MSB   PixelFormatEnum = C.SDL_PIXELFORMAT_INDEX4MSB
	PixelFormatIndex8      PixelFormatEnum = C.SDL_PIXELFORMAT_INDEX8
	PixelFormatRGB332      PixelFormatEnum = C.SDL_PIXELFORMAT_RGB332
	PixelFormatRGB444      PixelFormatEnum = C.SDL_PIXELFORMAT_RGB444
	PixelFormatRGB555      PixelFormatEnum = C.SDL_PIXELFORMAT_RGB555
	PixelFormatBGR555      PixelFormatEnum = C.SDL_PIXELFORMAT_BGR555
	PixelFormatARGB4444    PixelFormatEnum = C.SDL_PIXELFORMAT_ARGB4444
	PixelFormatRGBA4444    PixelFormatEnum = C.SDL_PIXELFORMAT_RGBA4444
	PixelFormatABGR4444    PixelFormatEnum = C.SDL_PIXELFORMAT_ABGR4444
	PixelFormatBGRA4444    PixelFormatEnum = C.SDL_PIXELFORMAT_BGRA4444
	PixelFormatARGB1555    PixelFormatEnum = C.SDL_PIXELFORMAT_ARGB1555
	PixelFormatRGBA5551    PixelFormatEnum = C.SDL_PIXELFORMAT_RGBA5551
	PixelFormatABGR1555    PixelFormatEnum = C.SDL_PIXELFORMAT_ABGR1555
	PixelFormatBGRA5551    PixelFormatEnum = C.SDL_PIXELFORMAT_BGRA5551
	PixelFormatRGB565      PixelFormatEnum = C.SDL_PIXELFORMAT_RGB565
	PixelFormatBGR565      PixelFormatEnum = C.SDL_PIXELFORMAT_BGR565
	PixelFormatRGB24       PixelFormatEnum = C.SDL_PIXELFORMAT_RGB24
	PixelFormatBGR24       PixelFormatEnum = C.SDL_PIXELFORMAT_BGR24
	PixelFormatRGB888      PixelFormatEnum = C.SDL_PIXELFORMAT_RGB888
	PixelFormatRGBX8888    PixelFormatEnum = C.SDL_PIXELFORMAT_RGBX8888
	PixelFormatBGR888      PixelFormatEnum = C.SDL_PIXELFORMAT_BGR888
	PixelFormatBGRX8888    PixelFormatEnum = C.SDL_PIXELFORMAT_BGRX8888
	PixelFormatARGB8888    PixelFormatEnum = C.SDL_PIXELFORMAT_ARGB8888
	PixelFormatRGBA8888    PixelFormatEnum = C.SDL_PIXELFORMAT_RGBA8888
	PixelFormatABGR8888    PixelFormatEnum = C.SDL_PIXELFORMAT_ABGR8888
	PixelFormatBGRA8888    PixelFormatEnum = C.SDL_PIXELFORMAT_BGRA8888
	PixelFormatARGB2101010 PixelFormatEnum = C.SDL_PIXELFORMAT_ARGB2101010
	PixelFormatYV12        PixelFormatEnum = C.SDL_PIXELFORMAT_YV12
	PixelFormatIYUV        PixelFormatEnum = C.SDL_PIXELFORMAT_IYUV
	PixelFormatYUY2        PixelFormatEnum = C.SDL_PIXELFORMAT_YUY2
	PixelFormatUYVY        PixelFormatEnum = C.SDL_PIXELFORMAT_UYVY
	PixelFormatYVYU        PixelFormatEnum = C.SDL_PIXELFORMAT_YVYU
)

Defined pixel formats.

func (PixelFormatEnum) BitsPerPixel

func (pf PixelFormatEnum) BitsPerPixel() int

BitsPerPixel returns the number of significant bits in a pixel value stored in this format.

func (PixelFormatEnum) BytesPerPixel

func (pf PixelFormatEnum) BytesPerPixel() int

BytesPerPixel returns the number of bytes required to hold a pixel value stored in this format.

func (PixelFormatEnum) IsAlpha

func (pf PixelFormatEnum) IsAlpha() bool

IsAlpha reports whether the pixel format has an alpha channel.

func (PixelFormatEnum) IsFourCC

func (pf PixelFormatEnum) IsFourCC() bool

IsFourCC reports whether the pixel format is a four-character code, like YUV.

func (PixelFormatEnum) IsIndexed

func (pf PixelFormatEnum) IsIndexed() bool

IsIndexed reports whether the pixel format has a palette.

func (PixelFormatEnum) Layout

func (pf PixelFormatEnum) Layout() PixelLayout

Layout returns the layout of channels in a packed pixel format.

func (PixelFormatEnum) Order

func (pf PixelFormatEnum) Order() PixelOrder

Order returns the ordering of channels in the pixel format.

func (PixelFormatEnum) String

func (pf PixelFormatEnum) String() string

String returns the SDL constant name of the pixel format.

func (PixelFormatEnum) Type

func (pf PixelFormatEnum) Type() PixelType

Type returns the data type used for the pixel format.

type PixelLayout

type PixelLayout uint8

PixelLayout is a packed pixel format's channel bit layout.

const (
	PackedLayoutNone    PixelLayout = C.SDL_PACKEDLAYOUT_NONE
	PackedLayout332     PixelLayout = C.SDL_PACKEDLAYOUT_332
	PackedLayout4444    PixelLayout = C.SDL_PACKEDLAYOUT_4444
	PackedLayout1555    PixelLayout = C.SDL_PACKEDLAYOUT_1555
	PackedLayout5551    PixelLayout = C.SDL_PACKEDLAYOUT_5551
	PackedLayout565     PixelLayout = C.SDL_PACKEDLAYOUT_565
	PackedLayout8888    PixelLayout = C.SDL_PACKEDLAYOUT_8888
	PackedLayout2101010 PixelLayout = C.SDL_PACKEDLAYOUT_2101010
	PackedLayout1010102 PixelLayout = C.SDL_PACKEDLAYOUT_1010102
)

Packed channel layouts.

type PixelOrder

type PixelOrder uint8

PixelOrder is a pixel format's channel order.

const (
	BitmapOrderNone PixelOrder = C.SDL_BITMAPORDER_NONE
	BitmapOrder4321 PixelOrder = C.SDL_BITMAPORDER_4321
	BitmapOrder1234 PixelOrder = C.SDL_BITMAPORDER_1234
)

Bitmap pixel order, high bit -> low bit.

const (
	PackedOrderNone PixelOrder = C.SDL_PACKEDORDER_NONE
	PackedOrderXRGB PixelOrder = C.SDL_PACKEDORDER_XRGB
	PackedOrderRGBX PixelOrder = C.SDL_PACKEDORDER_RGBX
	PackedOrderARGB PixelOrder = C.SDL_PACKEDORDER_ARGB
	PackedOrderRGBA PixelOrder = C.SDL_PACKEDORDER_RGBA
	PackedOrderXBGR PixelOrder = C.SDL_PACKEDORDER_XBGR
	PackedOrderBGRX PixelOrder = C.SDL_PACKEDORDER_BGRX
	PackedOrderABGR PixelOrder = C.SDL_PACKEDORDER_ABGR
	PackedOrderBGRA PixelOrder = C.SDL_PACKEDORDER_BGRA
)

Packed component order, high bit -> low bit.

const (
	ArrayOrderNone PixelOrder = C.SDL_ARRAYORDER_NONE
	ArrayOrderRGB  PixelOrder = C.SDL_ARRAYORDER_RGB
	ArrayOrderRGBA PixelOrder = C.SDL_ARRAYORDER_RGBA
	ArrayOrderARGB PixelOrder = C.SDL_ARRAYORDER_ARGB
	ArrayOrderBGR  PixelOrder = C.SDL_ARRAYORDER_BGR
	ArrayOrderBGRA PixelOrder = C.SDL_ARRAYORDER_BGRA
	ArrayOrderABGR PixelOrder = C.SDL_ARRAYORDER_ABGR
)

Array component order, low byte -> high byte.

type PixelType

type PixelType uint8

PixelType is a pixel format's data type.

const (
	PixelTypeUnknown  PixelType = C.SDL_PIXELTYPE_UNKNOWN
	PixelTypeIndex1   PixelType = C.SDL_PIXELTYPE_INDEX1
	PixelTypeIndex4   PixelType = C.SDL_PIXELTYPE_INDEX4
	PixelTypeIndex8   PixelType = C.SDL_PIXELTYPE_INDEX8
	PixelTypePacked8  PixelType = C.SDL_PIXELTYPE_PACKED8
	PixelTypePacked16 PixelType = C.SDL_PIXELTYPE_PACKED16
	PixelTypePacked32 PixelType = C.SDL_PIXELTYPE_PACKED32
	PixelTypeArrayU8  PixelType = C.SDL_PIXELTYPE_ARRAYU8
	PixelTypeArrayU16 PixelType = C.SDL_PIXELTYPE_ARRAYU16
	PixelTypeArrayU32 PixelType = C.SDL_PIXELTYPE_ARRAYU32
	PixelTypeArrayF16 PixelType = C.SDL_PIXELTYPE_ARRAYF16
	PixelTypeArrayF32 PixelType = C.SDL_PIXELTYPE_ARRAYF32
)

Pixel types.

type Point

type Point struct {
	X, Y int
}

Point is a two-dimensional point. The axes increase right and down.

func Pt

func Pt(x, y int) Point

Pt is shorthand for Point{x, y}.

func (Point) String

func (p Point) String() string

String returns a string representation of p like "(3, 4)".

type Rectangle

type Rectangle struct {
	Origin Point
	W, H   int
}

Rectangle is a rectangle, with the origin at the upper left.

func Rect

func Rect(x, y, w, h int) Rectangle

Rect is shorthand for Rectangle{Pt(x, y), w, h}

func (Rectangle) IsEmpty

func (r Rectangle) IsEmpty() bool

IsEmpty reports whether width <= 0 or height <= 0.

func (Rectangle) String

func (r Rectangle) String() string

String returns a string representation of r like "(3, 4) 5x7".

type Renderer

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

A Renderer represents the rendering state.

func (*Renderer) Clear

func (r *Renderer) Clear() error

Clear clears the current rendering target with the drawing color.

func (*Renderer) CopyTexture

func (r *Renderer) CopyTexture(texture *Texture, srcRect, destRect *Rectangle) error

CopyTexture copies a portion of the texture to the current rendering context.

func (*Renderer) Destroy

func (r *Renderer) Destroy()

Destroy destroys the renderer. The renderer should not be used after calling Destroy.

func (*Renderer) Info

func (r *Renderer) Info() (*RendererInfo, error)

Info returns the renderer's capabilities.

func (*Renderer) Present

func (r *Renderer) Present()

Present updates the screen with rendering performed.

type RendererFlag

type RendererFlag uint32

A RendererFlag is an option for creating a renderer.

const (
	// Software fallback
	RendererSoftware RendererFlag = C.SDL_RENDERER_SOFTWARE
	// Hardware accelerated
	RendererAccelerated RendererFlag = C.SDL_RENDERER_ACCELERATED
	// Present is synchronized with the refresh rate
	RendererPresentVSync RendererFlag = C.SDL_RENDERER_PRESENTVSYNC
	// Render to texture support
	RendererTargetTexture RendererFlag = C.SDL_RENDERER_TARGETTEXTURE
)

Renderer creation flags.

type RendererInfo

type RendererInfo struct {
	Name             string
	Flags            RendererFlag
	TextureFormats   []PixelFormatEnum
	MaxTextureWidth  int
	MaxTextureHeight int
}

RendererInfo describes the capabilities of a Renderer.

type Surface

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

Surface is a rectangular array of pixels.

func (*Surface) Destroy

func (surface *Surface) Destroy()

Destroy destroys the surface. The surface should not be used after a call to Destroy.

func (*Surface) PixelData

func (surface *Surface) PixelData() (PixelData, error)

PixelData locks the surface and returns a PixelData value, which can be used to access and modify the surface's pixels. The returned PixelData must be closed before the surface can be used again.

func (*Surface) PixelFormat

func (surface *Surface) PixelFormat() *PixelFormat

PixelFormat returns the surface's pixel format.

func (*Surface) Size

func (surface *Surface) Size() Point

Size returns the surface's width and height.

type TextEditingEvent

type TextEditingEvent struct {
	Time     uint32
	WindowID uint32
	Text     string
	Start    int // location to begin editing from
	Length   int // number of characters to edit
}

TextEditingEvent holds a partial text input event. See the description of TextInputEvent.

func (*TextEditingEvent) Timestamp

func (e *TextEditingEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*TextEditingEvent) Type

func (e *TextEditingEvent) Type() EventType

Type returns TextEditingEventType.

func (*TextEditingEvent) Window

func (e *TextEditingEvent) Window() uint32

Window returns the window with keyboard focus or zero.

type TextInputEvent

type TextInputEvent struct {
	Time     uint32
	WindowID uint32
	Text     string
}

TextInputEvent holds a complete text input event.

For every text input, there are one or more text editing events followed by one text input event. An input method may require multiple key presses to input a single character. The text editing events allow an application to render feedback of receiving the characters before inputting the final character.

func (*TextInputEvent) Timestamp

func (e *TextInputEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*TextInputEvent) Type

func (e *TextInputEvent) Type() EventType

Type returns TextInputEventType.

func (*TextInputEvent) Window

func (e *TextInputEvent) Window() uint32

Window returns the window with keyboard focus or zero.

type Texture

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

Texture is an efficient driver-specific representation of pixel data.

func NewTextureFromSurface

func NewTextureFromSurface(renderer *Renderer, surface *Surface) (*Texture, error)

NewTextureFromSurface creates a new texture from an existing surface.

func (*Texture) Destroy

func (t *Texture) Destroy()

Destroy destroys the texture. The texture should not be used after calling Destroy.

type TouchFingerEvent

type TouchFingerEvent struct {
	EventType  EventType
	Time       uint32
	TouchID    int64 // TODO(light): SDL_TouchID
	FingerID   int64 // TODO(light): SDL_FingerID
	X, Y       float32
	RelX, RelY float32
	Pressure   float32
}

TouchFingerEvent holds a finger touch event.

func (*TouchFingerEvent) Timestamp

func (e *TouchFingerEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*TouchFingerEvent) Type

func (e *TouchFingerEvent) Type() EventType

Type returns one of FingerMotionEventType, FingerDownEventType, or FingerUpEventType.

type UserEvent

type UserEvent struct {
	EventType    EventType
	Time         uint32
	WindowID     uint32
	Code         int32
	Data1, Data2 unsafe.Pointer
}

UserEvent holds a user-defined event.

func (*UserEvent) Timestamp

func (e *UserEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*UserEvent) Type

func (e *UserEvent) Type() EventType

Type returns the event's type.

func (*UserEvent) Window

func (e *UserEvent) Window() uint32

Window returns the associated window ID or zero.

type Window

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

Window is a window in a GUI environment.

func NewWindow

func NewWindow(title string, r Rectangle, flags ...WindowFlag) (*Window, error)

NewWindow creates a new window. r.x or r.y may also be WindowPosCentered or WindowPosUndefined. Multiple flags will be ORed together.

func (*Window) CreateRenderer

func (w *Window) CreateRenderer(driverIndex int, flags ...RendererFlag) (*Renderer, error)

CreateRenderer creates a 2D rendering context for a window. driverIndex is the index of the rendering driver to initialize, or -1 to initialize the first one that supports the requested configuration. Multiple flags will be ORed together.

func (*Window) Destroy

func (w *Window) Destroy()

Destroy destroys a window. It is not safe to use the window after calling Destroy.

func (*Window) GLSwap

func (w *Window) GLSwap()

GLSwap updates a window with an OpenGL rendering. (Used in double-buffering environments, which are the default)

func (*Window) Renderer

func (w *Window) Renderer() *Renderer

Renderer returns the window's renderer or nil if it doesn't have one.

func (*Window) Size

func (w *Window) Size() (int, int)

Size returns the size of the SDL window, in pixels.

func (*Window) Surface

func (w *Window) Surface() *Surface

Surface returns the window's surface.

type WindowEvent

type WindowEvent struct {
	Time     uint32
	WindowID uint32
	Event    WindowEventID

	// For move events, this is the new (x, y) position of the window.
	// For resize events, this is the new window size.
	Data1, Data2 int32
}

WindowEvent holds window state change event data.

func (*WindowEvent) Timestamp

func (e *WindowEvent) Timestamp() uint32

Timestamp returns the number of milliseconds since the SDL library initialization.

func (*WindowEvent) Type

func (e *WindowEvent) Type() EventType

Type returns WindowEventType.

func (*WindowEvent) Window

func (e *WindowEvent) Window() uint32

Window returns the ID of the window that this event occurred in.

type WindowEventID

type WindowEventID uint8

WindowEventID is a window event subtype.

const (
	WindowEventShown       WindowEventID = C.SDL_WINDOWEVENT_SHOWN
	WindowEventHidden      WindowEventID = C.SDL_WINDOWEVENT_HIDDEN
	WindowEventExposed     WindowEventID = C.SDL_WINDOWEVENT_EXPOSED
	WindowEventMoved       WindowEventID = C.SDL_WINDOWEVENT_MOVED
	WindowEventResized     WindowEventID = C.SDL_WINDOWEVENT_RESIZED
	WindowEventSizeChanged WindowEventID = C.SDL_WINDOWEVENT_SIZE_CHANGED
	WindowEventMinimized   WindowEventID = C.SDL_WINDOWEVENT_MINIMIZED
	WindowEventMaximized   WindowEventID = C.SDL_WINDOWEVENT_MAXIMIZED
	WindowEventRestored    WindowEventID = C.SDL_WINDOWEVENT_RESTORED
	WindowEventEnter       WindowEventID = C.SDL_WINDOWEVENT_ENTER
	WindowEventLeave       WindowEventID = C.SDL_WINDOWEVENT_LEAVE
	WindowEventFocusGained WindowEventID = C.SDL_WINDOWEVENT_FOCUS_GAINED
	WindowEventFocusLost   WindowEventID = C.SDL_WINDOWEVENT_FOCUS_LOST
	WindowEventClose       WindowEventID = C.SDL_WINDOWEVENT_CLOSE
)

Window event subtypes

type WindowFlag

type WindowFlag uint32

WindowFlag is a window creation option.

const (
	WindowFullscreen        WindowFlag = C.SDL_WINDOW_FULLSCREEN
	WindowOpenGL            WindowFlag = C.SDL_WINDOW_OPENGL
	WindowShown             WindowFlag = C.SDL_WINDOW_SHOWN
	WindowHidden            WindowFlag = C.SDL_WINDOW_HIDDEN
	WindowBorderless        WindowFlag = C.SDL_WINDOW_BORDERLESS
	WindowResizable         WindowFlag = C.SDL_WINDOW_RESIZABLE
	WindowMinimized         WindowFlag = C.SDL_WINDOW_MINIMIZED
	WindowMaximized         WindowFlag = C.SDL_WINDOW_MAXIMIZED
	WindowInputGrabbed      WindowFlag = C.SDL_WINDOW_INPUT_GRABBED
	WindowInputFocus        WindowFlag = C.SDL_WINDOW_INPUT_FOCUS
	WindowMouseFocus        WindowFlag = C.SDL_WINDOW_MOUSE_FOCUS
	WindowForeign           WindowFlag = C.SDL_WINDOW_FOREIGN
	WindowAllowHighDPI      WindowFlag = C.SDL_WINDOW_ALLOW_HIGHDPI
	WindowFullscreenDesktop WindowFlag = C.SDL_WINDOW_FULLSCREEN_DESKTOP
)

Window creation options.

Directories

Path Synopsis
Package keys provides constants for keyboard codes.
Package keys provides constants for keyboard codes.

Jump to

Keyboard shortcuts

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