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.
A Buffer is an OpenGL canvas displayed within an OS window. Events can be received on the Buffer's Event channel.
Open creates a new Buffer on the screen.
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.
Close() closes a window and releases any resources associated with it.
Flip swaps the background buffer with the foregroud buffer. All drawing is done to the background buffer.
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.
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.
Size returns the window's width and height in pixels
Title retrieves the current title of a window
WaitEvent blocks until a new Event occurs. New Events will be available on the Buffer's Event channel.
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
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")
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.
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.
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.
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.
All user and system events satisfy the Event interface, which must provide a unique device identifier and an event 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.
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 )
KeyPress events occur when a user presses or releases a keyboard key. Mod is the bitwise OR mask of all pressed modifiers.
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.
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.
Resize events occur when a window is resized. Width and Height represent the new size of the window, in pixels.
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.
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.
☞ This library is still experimental. Its API is subject to change.