display: aqwari.net/exp/display Index | Files

package display

import "aqwari.net/exp/display"

Package display provides functions for creating OpenGL windows and receiving input events.

The display package is cross-platform, and should work on Linux and OSX.

Index

Package Files

display.go doc.go event.go keys.go

type Buffer Uses

type Buffer struct {
    Event <-chan Event
    // contains filtered or unexported fields
}

A Buffer is an OpenGL canvas displayed within an OS window. Events can be received on the Buffer's Event channel.

func Open Uses

func Open(c Config) (*Buffer, error)

Open creates a new Buffer on the screen.

func (*Buffer) CheckEvent Uses

func (w *Buffer) CheckEvent() error

CheckEvents checks the event system for new input without blocking. A Buffer's Event channel will not be populated with new Events unless CheckEvent or WaitEvent is called.

func (*Buffer) Close Uses

func (w *Buffer) Close()

Close() closes a window and releases any resources associated with it.

func (*Buffer) Flip Uses

func (w *Buffer) Flip()

Flip swaps the background buffer with the foregroud buffer. All drawing is done to the background buffer.

func (*Buffer) Resize Uses

func (w *Buffer) Resize(width, height int) error

Resize changes the width and height of a window to the specified dimensions in pixels. Note that height and width are only suggestions; especially in fullscreen mode, window system or hardware restrictions may prevent the desired height and width from being set. The actual screen size may be retrieved with the Size() method.

func (*Buffer) SetTitle Uses

func (w *Buffer) SetTitle(title string)

SetTitle changes a window's title string to a new value. The maximum length of a window title is an unspecified value over 255 characters.

func (*Buffer) Size Uses

func (w *Buffer) Size() (width, height int)

Size returns the window's width and height in pixels

func (*Buffer) Title Uses

func (w *Buffer) Title() string

Title retrieves the current title of a window

func (*Buffer) WaitEvent Uses

func (w *Buffer) WaitEvent() error

WaitEvent blocks until a new Event occurs. New Events will be available on the Buffer's Event channel.

type Button Uses

type Button int

A Button is a bitwise OR mask of all pressed mouse buttons. This format makes it easy to compare mouse state between sequential events with bitwise operations:

var (
	prev = Mouse1 | Mouse2 | Mouse5
	next = Mouse2 | Mouse3
)
pressed := (prev ^ next) & next // => Mouse3
released := (prev ^ next) & prev // => Mouse1 | Mouse5
holding := prev & next // => Mouse2
const (
    Mouse1 Button = 1 << iota
    Mouse2
    Mouse3
    Mouse4
    Mouse5
    Mouse6
    Mouse7
    Mouse8
)

func (Button) String Uses

func (btn Button) String() string

type Config Uses

type Config map[string]string

A Config is used to choose the settings of a window display. Different systems may support different configurations. Most configuration settings should be considered hints rather than requirements. The implementation will make the best effort to provide a window matching the specifications. Keys common to all implementations are:

	Title:          A window's initial title
	Geometry:       A window's size and position (WxH@x,y)
 OpenGL Version: An OpenGL version string ("3.2")

type Cursor Uses

type Cursor struct {
    X, Y int
    When time.Time
}

A Cursor event occurs when the cursor position, usually controlled by the mouse, is changed. Cursor events contain the X and Y position of the cursor in pixels, where the origin is the top left corner of the screen.

func (Cursor) Src Uses

func (Cursor) Src() Device

func (Cursor) String Uses

func (m Cursor) String() string

func (Cursor) Time Uses

func (e Cursor) Time() time.Time

type Damage Uses

type Damage struct {
    When time.Time
}

Damage events occur when the window needs to be redisplayed. This can happen when part of the window is covered by another and the window system does not restore it.

func (Damage) Src Uses

func (Damage) Src() Device

func (Damage) Time Uses

func (e Damage) Time() time.Time

type Device Uses

type Device uint32

All input events must have a globally unique device identifier number, which can be retrieved from an Event throught the Src() method. Note that the underlying window system may not be able to distinguish between individual keyboards or mice. Events from a single device are guaranteed to arrive in chronological order. The window package reserves device ids 0-100 for use by system devices. By convention, the device id 0 is used when the origin device is not important.

type Edit Uses

type Edit struct {
    Text string
    When time.Time
}

An Edit event occurs when a user begins inputting candidate text. This is most notably used when the user is using an input method to input characters that require multiple key presses. The string Text contains the non-commited text the user has typed so far.

func (Edit) Src Uses

func (Edit) Src() Device

func (Edit) String Uses

func (t Edit) String() string

func (Edit) Time Uses

func (e Edit) Time() time.Time

type Event Uses

type Event interface {
    Src() Device
    Time() time.Time
}

All user and system events satisfy the Event interface, which must provide a unique device identifier and an event time.

type Focus Uses

type Focus struct {
    Focused bool
    When    time.Time
}

A Focus event occurs when a window receives or loses focus. In most window systems, a single active window is in focus, and will receive user input.

func (Focus) Src Uses

func (Focus) Src() Device

func (Focus) Time Uses

func (e Focus) Time() time.Time

type Key Uses

type Key int

Keys are named after the character of the key on a standard US keyboard, and may not map to the user's actual keyboard layout.

const (
    KeyUnknown Key = iota
    KeyA
    KeyB
    KeyC
    KeyD
    KeyE
    KeyF
    KeyG
    KeyH
    KeyI
    KeyJ
    KeyK
    KeyL
    KeyM
    KeyN
    KeyO
    KeyP
    KeyQ
    KeyR
    KeyS
    KeyT
    KeyU
    KeyV
    KeyW
    KeyX
    KeyY
    KeyZ
    Key1
    Key2
    Key3
    Key4
    Key5
    Key6
    Key7
    Key8
    Key9
    Key0
    KeyEnter
    KeyEscape
    KeyBackspace
    KeyTab
    KeySpace
    KeyMinus
    KeyEquals
    KeyLeftBracket
    KeyRightBracket
    KeyBackslash
    KeyNonUShash
    KeySemicolon
    KeyApostrophe
    KeyGrave
    KeyComma
    KeyPeriod
    KeySlash
    KeyCapsLock
    KeyF1
    KeyF2
    KeyF3
    KeyF4
    KeyF5
    KeyF6
    KeyF7
    KeyF8
    KeyF9
    KeyF10
    KeyF11
    KeyF12
    KeyPrintScreen
    KeyScrollLock
    KeyPause
    KeyInsert
    KeyHome
    KeyPageUp
    KeyDelete
    KeyEnd
    KeyPageDown
    KeyRight
    KeyLeft
    KeyDown
    KeyUp
    KeyNumLockClear
    KeyPadDivide
    KeyPadMultiply
    KeyPadMinus
    KeyPadPlus
    KeyPadEnter
    KeyPad1
    KeyPad2
    KeyPad3
    KeyPad4
    KeyPad5
    KeyPad6
    KeyPad7
    KeyPad8
    KeyPad9
    KeyPad0
    KeyPadPeriod
    KeyNonUSBackslash
    KeyApplication
    KeyPower
    KeyPadEquals
    KeyF13
    KeyF14
    KeyF15
    KeyF16
    KeyF17
    KeyF18
    KeyF19
    KeyF20
    KeyF21
    KeyF22
    KeyF23
    KeyF24
    KeyExecute
    KeyHelp
    KeyMenu
    KeySelect
    KeyStop
    KeyAgain
    KeyUndo
    KeyCut
    KeyCopy
    KeyPaste
    KeyFind
    KeyMute
    KeyVolumeUp
    KeyVolumeDown
    KeyLockingCapsLock
    KeyLockingNumLock
    KeyLockingScrollLock
    KeyPadComma
    KeyPadEqualsAs400
    KeyInternational1
    KeyInternational2
    KeyInternational3
    KeyInternational4
    KeyInternational5
    KeyInternational6
    KeyInternational7
    KeyInternational8
    KeyInternational9
    KeyLang1
    KeyLang2
    KeyLang3
    KeyLang4
    KeyLang5
    KeyLang6
    KeyLang7
    KeyLang8
    KeyLang9
    KeyAlterase
    KeySysreq
    KeyCancel
    KeyClear
    KeyPrior
    KeyReturn2
    KeySeparator
    KeyOut
    KeyOper
    KeyClearAgain
    KeyCrsel
    KeyExsel
    KeyPad00
    KeyPad000
    KeyThousandsSeparator
    KeyDecimalSeparator
    KeyCurrencyUnit
    KeyCurrencySubUnit
    KeyPadLeftParen
    KeyPadRightParen
    KeyPadLeftBrace
    KeyPadRightBrace
    KeyPadTab
    KeyPadBackspace
    KeyPadA
    KeyPadB
    KeyPadC
    KeyPadD
    KeyPadE
    KeyPadF
    KeyPadXOR
    KeyPadPower
    KeyPadPercent
    KeyPadLess
    KeyPadGreater
    KeyPadAmpersand
    KeyPadDblampersand
    KeyPadVerticalbar
    KeyPadDblverticalbar
    KeyPadColon
    KeyPadHash
    KeyPadSpace
    KeyPadAt
    KeyPadExclam
    KeyPadMemstore
    KeyPadMemrecall
    KeyPadMemclear
    KeyPadMemadd
    KeyPadMemsubtract
    KeyPadMemmultiply
    KeyPadMemdivide
    KeyPadPlusminus
    KeyPadClear
    KeyPadClearentry
    KeyPadBinary
    KeyPadOctal
    KeyPadDecimal
    KeyPadHexadecimal
    KeyLeftControl
    KeyLeftShift
    KeyLeftAlt
    KeyLeftSuper
    KeyRightControl
    KeyRightShift
    KeyRightAlt
    KeyRightSuper
    KeyMode
    KeyAudioNext
    KeyAudioPrev
    KeyAudioStop
    KeyAudioPlay
    KeyAudioMute
    KeyMediaSelect
    KeyWWW
    KeyMail
    KeyCalculator
    KeyComputer
    KeyACSearch
    KeyACHome
    KeyACBack
    KeyACForward
    KeyACStop
    KeyACRefresh
    KeyACBookmarks
    KeyBrightnessDown
    KeyBrightnessUp
    KeyDisplaySwitch
    KeyKbdIllumToggle
    KeyKbdIllumDown
    KeyKbdIllumUp
    KeyEject
    KeySleep
)

func (Key) String Uses

func (k Key) String() string

type KeyPress Uses

type KeyPress struct {
    Mod  Modifier
    Code Key
    Down bool
    When time.Time
}

KeyPress events occur when a user presses or releases a keyboard key. Mod is the bitwise OR mask of all pressed modifiers.

func (KeyPress) Src Uses

func (KeyPress) Src() Device

func (KeyPress) String Uses

func (key KeyPress) String() string

func (KeyPress) Time Uses

func (e KeyPress) Time() time.Time

type Modifier Uses

type Modifier int

A modifier is a bitwise OR mask of all key modifiers which are currently held down. Valid modifiers are any combination of Alt, Shift, Control, or Super. Super may refer to the Windows key on Microsoft Windows, or the Command key on OSX.

const (
    ModAlt Modifier = 1 << iota
    ModShift
    ModCtrl
    ModSuper
    ModHyper
)

func (Modifier) String Uses

func (mod Modifier) String() string

type Mouse Uses

type Mouse struct {
    Btn  Button
    Mod  Modifier
    When time.Time
}

Mouse events occur when a mouse button is pressed or released. Btn is the bitwise OR mask of all pressed mouse buttons. Like a KeyPress, mouse presses may be associated with Modifiers.

func (Mouse) Src Uses

func (Mouse) Src() Device

func (Mouse) String Uses

func (m Mouse) String() string

func (Mouse) Time Uses

func (e Mouse) Time() time.Time

type Resize Uses

type Resize struct {
    Width, Height int
    When          time.Time
}

Resize events occur when a window is resized. Width and Height represent the new size of the window, in pixels.

func (Resize) Src Uses

func (Resize) Src() Device

func (Resize) String Uses

func (r Resize) String() string

func (Resize) Time Uses

func (e Resize) Time() time.Time

type Scroll Uses

type Scroll struct {
    X, Y int
    When time.Time
}

A Scroll event occurs when a user scrolls the window, using a mouse wheel, track pad or otherwise. X and Y represent the relative horizontal and vertical scroll, respectively. Scrolling down and to the right produces positive offsets on both axes.

func (Scroll) Src Uses

func (Scroll) Src() Device

func (Scroll) String Uses

func (s Scroll) String() string

func (Scroll) Time Uses

func (e Scroll) Time() time.Time

type Text Uses

type Text struct {
    Text string
    When time.Time
}

Text events contain a string of UTF-8 encoded text that the user has input, either directly by pressing a keyboard key, or indirectly by commiting candidate text through an input method.

func (Text) Src Uses

func (Text) Src() Device

func (Text) String Uses

func (t Text) String() string

func (Text) Time Uses

func (e Text) Time() time.Time

Bugs

This library is still experimental. Its API is subject to change.

Package display imports 9 packages (graph) and is imported by 5 packages. Updated 2017-08-10. Refresh now. Tools for package owners.