device

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2013 License: BSD-2-Clause-Views, Zlib Imports: 2 Imported by: 0

Documentation

Overview

Package device provides platform/os access to a 3D rendering context and user input. It provides only what is necessary to get a OS specific window with a 3D rendering context. The application layer is expected to provide any necessary buttons, controls and sub-panels.

Package device provides access to user keyboard and mouse input through the Update method and Pressed structure.

Package device is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

View Source
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 down a key 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)

	// 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()

func New

func New(title string, x, y, width, height int) Device

New provides a newly initialized Device with an underlying window and graphics context created, but not yet displayed. The only thing left to do is to open the device and start polling it for user input.

type Pressed added in v1.3.1

type Pressed struct {
	Mx, My  int            // Current mouse location.
	Down    map[string]int // Pressed keys and pressed duration.
	Shift   bool           // True if the shift modifier is pressed.
	Control bool           // True if the control modifier is pressed.
	Focus   bool           // True if window has focus.
	Resized bool           // True if window was resized or moved.
}

Pressed is used to communicate current user input. This is 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 duration prior to release can be determined by its difference with KEY_RELEASE.

Jump to

Keyboard shortcuts

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