Documentation
¶
Overview ¶
Package window is the easiest way to open a window and render graphics.
The window package effectively provides an easy cross-platform way to create and configure a window, as well as manipulate it and receive user input from it efficiently.
The window package lays the groundwork for developing applications that are truly cross-platform (i.e. desktop and mobile applications) using nearly the exact same API in the future. As such, the window package is mostly just an abstraction layer for GLFW on desktop operating systems.
If you truly need features not found in this package then you might be best using GLFW directly if you intend to just write desktop applications. Some features are not supported by this package intentionally, like multiple windows because mobile devices don't have them.
The goal of the window package is not to provide a one solution fits all, it is instead to abstract away the tedious parts of writing cross-device applications in the future.
The window package is also extremely simple to use:
func gfxLoop(w window.Window, r gfx.Renderer) { // Initialization here. for { // Render loop here. } } func main() { window.Run(gfxLoop, nil) }
Index ¶
- Variables
- func Run(gfxLoop func(w Window, r gfx.Renderer), p *Props)
- type Close
- type CursorEnter
- type CursorExit
- type CursorMoved
- type Damaged
- type Event
- type EventMask
- type FramebufferResized
- type GainedFocus
- type ItemsDropped
- type LostFocus
- type Minimized
- type Moved
- type Props
- func (p *Props) AlwaysOnTop() bool
- func (p *Props) CursorGrabbed() bool
- func (p *Props) CursorPos() (x, y float64)
- func (p *Props) Decorated() bool
- func (p *Props) Focused() bool
- func (p *Props) FramebufferSize() (width, height int)
- func (p *Props) Fullscreen() bool
- func (p *Props) Minimized() bool
- func (p *Props) Pos() (x, y int)
- func (p *Props) Precision() gfx.Precision
- func (p *Props) Resizable() bool
- func (p *Props) SetAlwaysOnTop(alwaysOnTop bool)
- func (p *Props) SetCursorGrabbed(grabbed bool)
- func (p *Props) SetCursorPos(x, y float64)
- func (p *Props) SetDecorated(decorated bool)
- func (p *Props) SetFocused(focused bool)
- func (p *Props) SetFramebufferSize(width, height int)
- func (p *Props) SetFullscreen(fullscreen bool)
- func (p *Props) SetMinimized(minimized bool)
- func (p *Props) SetPos(x, y int)
- func (p *Props) SetPrecision(precision gfx.Precision)
- func (p *Props) SetResizable(resizable bool)
- func (p *Props) SetShouldClose(shouldClose bool)
- func (p *Props) SetSize(width, height int)
- func (p *Props) SetTitle(title string)
- func (p *Props) SetVSync(vsync bool)
- func (p *Props) SetVisible(visible bool)
- func (p *Props) ShouldClose() bool
- func (p *Props) Size() (width, height int)
- func (p *Props) String() string
- func (p *Props) Title() string
- func (p *Props) VSync() bool
- func (p *Props) Visible() bool
- type Resized
- type Restored
- type Window
Constants ¶
This section is empty.
Variables ¶
var DefaultProps = NewProps()
DefaultProps is the default set of window properties. You may modify them as you see fit.
They are used in place of nil properties (e.g. see the Run function).
Functions ¶
func Run ¶
Run opens a window with the given properties and runs the given graphics loop in a separate goroutine.
Interpretation of the given properties is left strictly up to the platform dependant implementation (for instance, on Android you cannot set the window's size so it is simply ignored).
Requesting a specific framebuffer configuration via Props.SetPrecision is just a request. You may be given some other configuration (most likely one closest to it). You can check what you received by looking at:
r.Canvas.Precision()
If the properties are nil, DefaultProps is used instead.
Types ¶
type Close ¶
Close is sent when the user requests that the application window be closed, using the exit button or a quick-key combination like Alt + F4, etc.
type CursorEnter ¶
CursorEnter is an event where the user moved the mouse cursor inside of the window.
func (CursorEnter) String ¶
func (ev CursorEnter) String() string
String returns a string representation of this event.
func (CursorEnter) Time ¶
func (ev CursorEnter) Time() time.Time
Time implements the Event interface.
type CursorExit ¶
CursorExit is an event where the user moved the mouse cursor outside of the window.
func (CursorExit) String ¶
func (ev CursorExit) String() string
String returns a string representation of this event.
type CursorMoved ¶
type CursorMoved struct {
// Position of cursor relative to the upper-left corner of the window.
X, Y float64
// Whether or not the event's X and Y values are actually relative delta
// values (e.g. for a FPS style camera).
Delta bool
T time.Time
}
CursorMoved is sent when the user has moved the mouse cursor.
func (CursorMoved) String ¶
func (ev CursorMoved) String() string
String returns a string representation of this event.
func (CursorMoved) Time ¶
func (ev CursorMoved) Time() time.Time
Time implements the Event interface.
type Damaged ¶
Damaged is sent when the window's client area has been damaged and the window needs to be redrawn.
type Event ¶
Event represents an event of some sort. The only requirement is that the event specify the point in time at which it happened.
Using a type assertion or a type switch you can determine the actualy type of event which contains much more information:
select ev := event.(type){ case *keyboard.StateEvent: fmt.Println("The keyboard button", ev.Key, "is now", ev.State) // example: "The keyboard button keyboard.A is now keyboard.Down" }
type EventMask ¶
type EventMask uint32
EventMask is a bitmask of event types. They can be combined, for instance:
mask := GenericEvents mask |= MouseEvents mask |= KeyboardEvents
would select generic, mouse, and keyboard events.
const ( // Event mask matching no events at all. NoEvents EventMask = 0 // Each event mask below matches it's corresponding event (defined in this // package) without the `Events` suffix. CloseEvents EventMask = 1 << 0 DamagedEvents EventMask = 1 << 1 CursorMovedEvents EventMask = 1 << 2 CursorEnterEvents EventMask = 1 << 3 CursorExitEvents EventMask = 1 << 4 MinimizedEvents EventMask = 1 << 5 RestoredEvents EventMask = 1 << 6 GainedFocusEvents EventMask = 1 << 7 LostFocusEvents EventMask = 1 << 8 MovedEvents EventMask = 1 << 9 ResizedEvents EventMask = 1 << 10 FramebufferResizedEvents EventMask = 1 << 11 ItemsDroppedEvents EventMask = 1 << 12 // Event mask for the mouse.Event event type. MouseEvents EventMask = 1 << 13 // Event mask for the mouse.Scrolled event type. MouseScrolledEvents EventMask = 1 << 14 // Event mask for the keyboard.TypedEvent event type. KeyboardTypedEvents EventMask = 1 << 15 // Event mask for the keyboard.StateEvent event type. KeyboardStateEvents EventMask = 1 << 16 // Event mask matching all possible events. AllEvents = EventMask(math.MaxUint32) )
type FramebufferResized ¶
type FramebufferResized struct {
// Size of the framebuffer in pixels.
Width, Height int
T time.Time
}
FramebufferResized is an event where the framebuffer of the window has been resized.
func (FramebufferResized) String ¶
func (ev FramebufferResized) String() string
String returns a string representation of this event.
func (FramebufferResized) Time ¶
func (ev FramebufferResized) Time() time.Time
Time implements the Event interface.
type GainedFocus ¶
GainedFocus is an event where the window has gained focus.
func (GainedFocus) String ¶
func (ev GainedFocus) String() string
String returns a string representation of this event.
func (GainedFocus) Time ¶
func (ev GainedFocus) Time() time.Time
Time implements the Event interface.
type ItemsDropped ¶
ItemsDropped is an event where the user dropped an item (or multiple items) onto the window.
func (ItemsDropped) String ¶
func (ev ItemsDropped) String() string
String returns a string representation of this event.
func (ItemsDropped) Time ¶
func (ev ItemsDropped) Time() time.Time
Time implements the Event interface.
type LostFocus ¶
LostFocus is an event where the window has lost focus.
type Minimized ¶
Minimized is an event where the user minimized the window.
type Moved ¶
type Moved struct {
// Position of the window's client area, relative to the top-left of the
// screen.
X, Y int
T time.Time
}
Moved is an event where the user changed the position of the window.
type Props ¶
type Props struct {
// contains filtered or unexported fields
}
Props represents window properties. Properties are safe for use concurrently from multiple goroutines.
func NewProps ¶
func NewProps() *Props
NewProps returns a new initialized set of window properties. The default values for each property are as follows:
Title: "Azul3D - {FPS}" Size: 800x450 Pos: -1, -1 (centered on screen) CursorPos: -1.0, -1.0 (current position) ShouldClose: true Visible: true Minimized: false Fullscreen: false Focused: true VSync: true Resizable: true Decorated: true AlwaysOnTop: false CursorGrabbed: false FramebufferSize: 1x1 (set via window owner) Precision: gfx.Precision{ RedBits: 8, GreenBits: 8, BlueBits: 8, AlphaBits: 0, DepthBits: 24, StencilBits: 0, Samples: 2, }
func (*Props) AlwaysOnTop ¶
AlwaysOnTop tells whether or not the window is set to be always on top of other windows.
func (*Props) CursorGrabbed ¶
CursorGrabbed returns whether or not the cursor is grabbed.
func (*Props) FramebufferSize ¶
FramebufferSize returns the size of the framebuffer in pixels.
func (*Props) Fullscreen ¶
Fullscreen tells whether or not the window is fullscreen.
func (*Props) Pos ¶
Pos returns the position of the upper-left corner of the client area of the window in screen coordinates.
func (*Props) Precision ¶
func (p *Props) Precision() gfx.Precision
Precision returns the requested framebuffer precision to be requested.
func (*Props) SetAlwaysOnTop ¶
SetAlwaysOnTop sets whether or not the window is always on top of other windows.
func (*Props) SetCursorGrabbed ¶
SetCursorGrabbed sets whether or not the cursor should be grabbed. If the cursor is grabbed, it is hidden from sight and cannot leave the window.
When grabbed, a window generates CursorMoved events with Delta=true, this is useful for e.g. FPS style cameras.
func (*Props) SetCursorPos ¶
SetCursorPos sets the position of the mouse cursor.
A special value of x=-1.0, y=-1.0 means to not move the mouse cursor at all.
func (*Props) SetDecorated ¶
SetDecorated sets whether or not the window has it's decorations shown.
func (*Props) SetFocused ¶
SetFocused sets whether or not the window has focus.
func (*Props) SetFramebufferSize ¶
SetFramebufferSize sets the size of the framebuffer in pixels. Each value is clamped to at least a value of 1.
Only the window owner should ever set the framebuffer size.
func (*Props) SetFullscreen ¶
SetFullscreen sets whether or not the window is fullscreen.
func (*Props) SetMinimized ¶
SetMinimized sets whether or not the window is minimized.
func (*Props) SetPos ¶
SetPos sets the position of the upper-left corner of the client area of the window in screen coordinates.
A special value of x=-1, y=-1 means to center the window on the screen.
func (*Props) SetPrecision ¶
func (p *Props) SetPrecision(precision gfx.Precision)
SetPrecision sets the framebuffer precision to be requested.
func (*Props) SetResizable ¶
SetResizable sets whether or not the window can be resized.
func (*Props) SetShouldClose ¶
SetShouldClose sets whether the window should close or not when the user tries to close the window.
func (*Props) SetSize ¶
SetSize sets the size of the window in screen coordinates. Each value is clamped to at least a value of 1.
func (*Props) SetTitle ¶
SetTitle sets the title of the window. The backend will replace the first string in the title matching "{FPS}" with the actual frames per second.
For example, a title "Hello World - {FPS}" would end up as:
"Hello world - 60FPS"
func (*Props) SetVisible ¶
SetVisible sets whether or not the window is visible or hidden.
func (*Props) ShouldClose ¶
ShouldClose tells if the window will close or not when the user tries to close the window.
func (*Props) String ¶
String returns a string like:
"Window(Title="Hello World!", Fullscreen=false)"
type Resized ¶
Resized is an event where the user changed the size of the window.
type Restored ¶
Restored is an event where the user restored (un-minimized) the window.
type Window ¶
type Window interface { // Props returns the window's properties. Props() *Props // Request makes a request to use a new set of properties, p. It is then // reccomended to make changes to the window using something like: // props := window.Props() // props.SetTitle("Hello World!") // props.SetSize(640, 480) // window.Request(props) // // Interpretation of the given properties is left strictly up to the // platform dependant implementation (for instance, on Android you cannot // set the window's size, so instead a request for this is simply ignored. Request(p *Props) // Keyboard returns a keyboard watcher for the window. It can be used to // tell if certain keyboard buttons are currently held down, for instance: // // if w.Keyboard().Down(keyboard.W) { // fmt.Println("The W key is currently held down") // } Keyboard() *keyboard.Watcher // Mouse returns a mouse watcher for the window. It can be used to tell if // certain mouse buttons are currently held down, for instance: // // if w.Mouse().Down(mouse.Left) { // fmt.Println("The left mouse button is currently held down") // } Mouse() *mouse.Watcher // SetClipboard sets the clipboard string. SetClipboard(clipboard string) // Clipboard returns the clipboard string. Clipboard() string // Notify causes the window to relay window events to ch based on the event // mask. // // The special event mask NoEvents causes the window to stop relaying any // events to the given channel. You should always perform this action when // you are done using the event channel. // // The window will not block sending events to ch: the caller must ensure // that ch has a sufficient amount of buffer space to keep up with the // event rate. // // If you only expect to receive a single event like Close then a buffer // size of one is acceptable. // // You are allowed to make multiple calls to this method with the same // channel, if you do then the same event will be sent over the channel // multiple times. When you no longer want the channel to receive events // then call this function again with NoEvents: // w.Notify(ch, NoEvents) // // Multiple calls to Events with different channels works as you would // expect, each channel receives a copy of the events independant of other // ones. // // Warning: Many people use high-precision mice, some which can reach well // above 1000hz, so for cursor events a generous buffer size (256, etc) is // highly recommended. // // Warning: Depending on the operating system, window manager, etc, some of // the events may never be sent or may only be sent sporiadically, so plan // for this. Notify(ch chan<- Event, m EventMask) // Close closes the window, and causes Run() to return. Close() }
Window represents a single window that graphics can be rendered to. The window is safe for use concurrently from multiple goroutines.