Documentation ¶
Overview ¶
Package device provides minimal platform/os access to a 3D rendering context and user input. Access to user keyboard and mouse input is provided through the Update method and Pressed structure. The application is responsible for providing any windowing constructs like buttons, controls, dialogs, sub-panels, text-boxes, etc.
Package device is provided as part of the vu (virtual universe) 3D engine.
Index ¶
Constants ¶
const KEY_RELEASED = -1000000000
KEY_RELEASED is used to indicate a key up event has occurred. The total duration of a key press can be calculated by the difference of Pressed.Down duration with KEY_RELEASED. A user would have to hold a key down for 24 hours before the released duration became positive (assuming a reasonable update time of 0.02 seconds).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device interface { Open() // Open the window and process events. ShowCursor(show bool) // Displays or hides the cursor. SetCursorAt(x, y int) // Places the cursor at the given window location. Dispose() // Release OS specific resources. // IsAlive returns true as long as the window is able to process user input. // Quitting the application window will cause IsAlive to return false. IsAlive() bool // Size returns the usable graphics context location and size excluding any OS // specific window trim. The window x, y (0, 0) coordinates are at the bottom // left of the window. Size() (x, y, width, height int) IsFullScreen() bool // Returns true if window is full screen. ToggleFullScreen() // Flips between full screen and windowed mode. // SwapBuffers exchanges the graphic drawing buffers. Expected to be called // after completing a render. All rendering contexts are double buffered. SwapBuffers() // Update returns the current (key/mouse) pressed state. The calling application // is expected to: // 1. Treat the pressed information as read only. // 2. Call this method every update loop. This method is responsible // for regular processing of the native OS window events. Update() *Pressed }
Device wraps OS specific functionality. The expected usage is:
dev := device.New("title", x, y, width, height) // Application initialization code. dev.Open() for dev.IsAlive() { pressed := dev.Update() // Application update and render code. dev.SwapBuffers() } dev.Dispose()
type Pressed ¶
type Pressed struct {
Mx, My int // Current mouse location.
Scroll int // The amount of scrolling, if any.
Down map[string]int // Pressed keys and pressed duration.
Focus bool // True if window has focus.
Resized bool // True if window was resized or moved.
}
Pressed is used to communicate current user input. Input mainly consists of the list of keys that are currently being pressed and how long they have been pressed (measured in update ticks). A postitive duration means the key is still being held down. A negative duration means that the key has been released since the last poll. The total pressed duration prior to release can be determined using the difference with KEY_RELEASED.