window

package
v0.0.0-...-682a2af Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package window abstracts a platform-specific window. Depending on the build tags it can be a GLFW desktop window or a browser WebGlCanvas.

Index

Constants

View Source
const (
	KeyUnknown      = Key(glfw.KeyUnknown)
	KeySpace        = Key(glfw.KeySpace)
	KeyApostrophe   = Key(glfw.KeyApostrophe)
	KeyComma        = Key(glfw.KeyComma)
	KeyMinus        = Key(glfw.KeyMinus)
	KeyPeriod       = Key(glfw.KeyPeriod)
	KeySlash        = Key(glfw.KeySlash)
	Key0            = Key(glfw.Key0)
	Key1            = Key(glfw.Key1)
	Key2            = Key(glfw.Key2)
	Key3            = Key(glfw.Key3)
	Key4            = Key(glfw.Key4)
	Key5            = Key(glfw.Key5)
	Key6            = Key(glfw.Key6)
	Key7            = Key(glfw.Key7)
	Key8            = Key(glfw.Key8)
	Key9            = Key(glfw.Key9)
	KeySemicolon    = Key(glfw.KeySemicolon)
	KeyEqual        = Key(glfw.KeyEqual)
	KeyA            = Key(glfw.KeyA)
	KeyB            = Key(glfw.KeyB)
	KeyC            = Key(glfw.KeyC)
	KeyD            = Key(glfw.KeyD)
	KeyE            = Key(glfw.KeyE)
	KeyF            = Key(glfw.KeyF)
	KeyG            = Key(glfw.KeyG)
	KeyH            = Key(glfw.KeyH)
	KeyI            = Key(glfw.KeyI)
	KeyJ            = Key(glfw.KeyJ)
	KeyK            = Key(glfw.KeyK)
	KeyL            = Key(glfw.KeyL)
	KeyM            = Key(glfw.KeyM)
	KeyN            = Key(glfw.KeyN)
	KeyO            = Key(glfw.KeyO)
	KeyP            = Key(glfw.KeyP)
	KeyQ            = Key(glfw.KeyQ)
	KeyR            = Key(glfw.KeyR)
	KeyS            = Key(glfw.KeyS)
	KeyT            = Key(glfw.KeyT)
	KeyU            = Key(glfw.KeyU)
	KeyV            = Key(glfw.KeyV)
	KeyW            = Key(glfw.KeyW)
	KeyX            = Key(glfw.KeyX)
	KeyY            = Key(glfw.KeyY)
	KeyZ            = Key(glfw.KeyZ)
	KeyLeftBracket  = Key(glfw.KeyLeftBracket)
	KeyBackslash    = Key(glfw.KeyBackslash)
	KeyRightBracket = Key(glfw.KeyRightBracket)
	KeyGraveAccent  = Key(glfw.KeyGraveAccent)
	KeyWorld1       = Key(glfw.KeyWorld1)
	KeyWorld2       = Key(glfw.KeyWorld2)
	KeyEscape       = Key(glfw.KeyEscape)
	KeyEnter        = Key(glfw.KeyEnter)
	KeyTab          = Key(glfw.KeyTab)
	KeyBackspace    = Key(glfw.KeyBackspace)
	KeyInsert       = Key(glfw.KeyInsert)
	KeyDelete       = Key(glfw.KeyDelete)
	KeyRight        = Key(glfw.KeyRight)
	KeyLeft         = Key(glfw.KeyLeft)
	KeyDown         = Key(glfw.KeyDown)
	KeyUp           = Key(glfw.KeyUp)
	KeyPageUp       = Key(glfw.KeyPageUp)
	KeyPageDown     = Key(glfw.KeyPageDown)
	KeyHome         = Key(glfw.KeyHome)
	KeyEnd          = Key(glfw.KeyEnd)
	KeyCapsLock     = Key(glfw.KeyCapsLock)
	KeyScrollLock   = Key(glfw.KeyScrollLock)
	KeyNumLock      = Key(glfw.KeyNumLock)
	KeyPrintScreen  = Key(glfw.KeyPrintScreen)
	KeyPause        = Key(glfw.KeyPause)
	KeyF1           = Key(glfw.KeyF1)
	KeyF2           = Key(glfw.KeyF2)
	KeyF3           = Key(glfw.KeyF3)
	KeyF4           = Key(glfw.KeyF4)
	KeyF5           = Key(glfw.KeyF5)
	KeyF6           = Key(glfw.KeyF6)
	KeyF7           = Key(glfw.KeyF7)
	KeyF8           = Key(glfw.KeyF8)
	KeyF9           = Key(glfw.KeyF9)
	KeyF10          = Key(glfw.KeyF10)
	KeyF11          = Key(glfw.KeyF11)
	KeyF12          = Key(glfw.KeyF12)
	KeyF13          = Key(glfw.KeyF13)
	KeyF14          = Key(glfw.KeyF14)
	KeyF15          = Key(glfw.KeyF15)
	KeyF16          = Key(glfw.KeyF16)
	KeyF17          = Key(glfw.KeyF17)
	KeyF18          = Key(glfw.KeyF18)
	KeyF19          = Key(glfw.KeyF19)
	KeyF20          = Key(glfw.KeyF20)
	KeyF21          = Key(glfw.KeyF21)
	KeyF22          = Key(glfw.KeyF22)
	KeyF23          = Key(glfw.KeyF23)
	KeyF24          = Key(glfw.KeyF24)
	KeyF25          = Key(glfw.KeyF25)
	KeyKP0          = Key(glfw.KeyKP0)
	KeyKP1          = Key(glfw.KeyKP1)
	KeyKP2          = Key(glfw.KeyKP2)
	KeyKP3          = Key(glfw.KeyKP3)
	KeyKP4          = Key(glfw.KeyKP4)
	KeyKP5          = Key(glfw.KeyKP5)
	KeyKP6          = Key(glfw.KeyKP6)
	KeyKP7          = Key(glfw.KeyKP7)
	KeyKP8          = Key(glfw.KeyKP8)
	KeyKP9          = Key(glfw.KeyKP9)
	KeyKPDecimal    = Key(glfw.KeyKPDecimal)
	KeyKPDivide     = Key(glfw.KeyKPDivide)
	KeyKPMultiply   = Key(glfw.KeyKPMultiply)
	KeyKPSubtract   = Key(glfw.KeyKPSubtract)
	KeyKPAdd        = Key(glfw.KeyKPAdd)
	KeyKPEnter      = Key(glfw.KeyKPEnter)
	KeyKPEqual      = Key(glfw.KeyKPEqual)
	KeyLeftShift    = Key(glfw.KeyLeftShift)
	KeyLeftControl  = Key(glfw.KeyLeftControl)
	KeyLeftAlt      = Key(glfw.KeyLeftAlt)
	KeyLeftSuper    = Key(glfw.KeyLeftSuper)
	KeyRightShift   = Key(glfw.KeyRightShift)
	KeyRightControl = Key(glfw.KeyRightControl)
	KeyRightAlt     = Key(glfw.KeyRightAlt)
	KeyRightSuper   = Key(glfw.KeyRightSuper)
	KeyMenu         = Key(glfw.KeyMenu)
	KeyLast         = Key(glfw.KeyLast)
)

Keycodes

View Source
const (
	ModShift   = ModifierKey(glfw.ModShift)
	ModControl = ModifierKey(glfw.ModControl)
	ModAlt     = ModifierKey(glfw.ModAlt)
	ModSuper   = ModifierKey(glfw.ModSuper)
)

Modifier keys

View Source
const (
	MouseButton1      = MouseButton(glfw.MouseButton1)
	MouseButton2      = MouseButton(glfw.MouseButton2)
	MouseButton3      = MouseButton(glfw.MouseButton3)
	MouseButton4      = MouseButton(glfw.MouseButton4)
	MouseButton5      = MouseButton(glfw.MouseButton5)
	MouseButton6      = MouseButton(glfw.MouseButton6)
	MouseButton7      = MouseButton(glfw.MouseButton7)
	MouseButton8      = MouseButton(glfw.MouseButton8)
	MouseButtonLast   = MouseButton(glfw.MouseButtonLast)
	MouseButtonLeft   = MouseButton(glfw.MouseButtonLeft)
	MouseButtonRight  = MouseButton(glfw.MouseButtonRight)
	MouseButtonMiddle = MouseButton(glfw.MouseButtonMiddle)
)

Mouse buttons

View Source
const (
	CursorInputMode             = InputMode(glfw.CursorMode)             // See Cursor mode values
	StickyKeysInputMode         = InputMode(glfw.StickyKeysMode)         // Value can be either 1 or 0
	StickyMouseButtonsInputMode = InputMode(glfw.StickyMouseButtonsMode) // Value can be either 1 or 0
)

Input modes

View Source
const (
	CursorNormal   = CursorMode(glfw.CursorNormal)
	CursorHidden   = CursorMode(glfw.CursorHidden)
	CursorDisabled = CursorMode(glfw.CursorDisabled)
)

Cursor mode values

View Source
const (
	ArrowCursor = Cursor(iota)
	IBeamCursor
	CrosshairCursor
	HandCursor
	HResizeCursor
	VResizeCursor
	DiagResize1Cursor
	DiagResize2Cursor
	CursorLast = DiagResize2Cursor
)

Standard cursors for G3N.

View Source
const (
	OnWindowFocus = "w.OnWindowFocus" //    x    |    x    |
	OnWindowPos   = "w.OnWindowPos"   //    x    |         |
	OnWindowSize  = "w.OnWindowSize"  //    x    |         |
	OnKeyUp       = "w.OnKeyUp"       //    x    |    x    |
	OnKeyDown     = "w.OnKeyDown"     //    x    |    x    |
	OnKeyRepeat   = "w.OnKeyRepeat"   //    x    |         |
	OnChar        = "w.OnChar"        //    x    |    x    |
	OnCursor      = "w.OnCursor"      //    x    |    x    |
	OnMouseUp     = "w.OnMouseUp"     //    x    |    x    |
	OnMouseDown   = "w.OnMouseDown"   //    x    |    x    |
	OnScroll      = "w.OnScroll"      //    x    |    x    |
)

Window event names. See availability per platform below ("x" indicates available).

Variables

This section is empty.

Functions

func Init

func Init(width, height int, title string) error

Init initializes the GlfwWindow singleton with the specified width, height, and title.

Types

type CharEvent

type CharEvent struct {
	Char rune
	Mods ModifierKey
}

CharEvent describes a window char event

type Cursor

type Cursor int

Cursor corresponds to a g3n standard or user-created cursor icon.

type CursorEvent

type CursorEvent struct {
	Xpos float32
	Ypos float32
	Mods ModifierKey
}

CursorEvent describes a cursor position changed event

type CursorMode

type CursorMode int

InputMode corresponds to an input mode.

type FocusEvent

type FocusEvent struct {
	Focused bool
}

FocusEvent describes a focus event

type GlfwWindow

type GlfwWindow struct {
	*glfw.Window    // Embedded GLFW window
	core.Dispatcher // Embedded event dispatcher
	// contains filtered or unexported fields
}

GlfwWindow describes one glfw window

func (*GlfwWindow) CreateCursor

func (w *GlfwWindow) CreateCursor(imgFile string, xhot, yhot int) (Cursor, error)

CreateCursor creates a new custom cursor and returns an int handle.

func (*GlfwWindow) Destroy

func (w *GlfwWindow) Destroy()

Destroy destroys this window and its context

func (*GlfwWindow) DisposeAllCustomCursors

func (w *GlfwWindow) DisposeAllCustomCursors()

DisposeAllCursors deletes all existing custom cursors.

func (*GlfwWindow) DisposeCursor

func (w *GlfwWindow) DisposeCursor(cursor Cursor)

DisposeCursor deletes the existing custom cursor with the provided int handle.

func (*GlfwWindow) FullScreen

func (w *GlfwWindow) FullScreen() bool

FullScreen returns whether this windows is currently fullscreen.

func (*GlfwWindow) GetScale

func (w *GlfwWindow) GetScale() (x float64, y float64)

Scale returns this window's DPI scale factor (FramebufferSize / Size)

func (*GlfwWindow) Gls

func (w *GlfwWindow) Gls() *gls.GLS

Gls returns the associated OpenGL state.

func (*GlfwWindow) PollEvents

func (w *GlfwWindow) PollEvents()

PollEvents process events in the event queue

func (*GlfwWindow) ScreenResolution

func (w *GlfwWindow) ScreenResolution() (width, height int)

ScreenResolution returns the screen resolution

func (*GlfwWindow) SetCursor

func (w *GlfwWindow) SetCursor(cursor Cursor)

SetCursor sets the window's cursor.

func (*GlfwWindow) SetFullScreen

func (w *GlfwWindow) SetFullScreen(full bool)

SetFullScreen sets this window as fullscreen on the primary monitor TODO allow for fullscreen with resolutions different than the monitor's

func (*GlfwWindow) SetSwapInterval

func (w *GlfwWindow) SetSwapInterval(interval int)

SetSwapInterval sets the number of screen updates to wait from the time SwapBuffer() is called before swapping the buffers and returning.

type IWindow

type IWindow interface {
	core.IDispatcher
	Gls() *gls.GLS
	GetFramebufferSize() (width int, height int)
	GetSize() (width int, height int)
	GetScale() (x float64, y float64)
	CreateCursor(imgFile string, xhot, yhot int) (Cursor, error)
	SetCursor(cursor Cursor)
	DisposeAllCustomCursors()
	Destroy()
	FullScreen() bool
	SetFullScreen(full bool)
}

IWindow is the interface for all windows

func Get

func Get() IWindow

Get returns the IWindow singleton.

type InputMode

type InputMode int

InputMode corresponds to an input mode.

type Key

type Key int

Key corresponds to a keyboard key.

type KeyEvent

type KeyEvent struct {
	Key  Key
	Mods ModifierKey
}

KeyEvent describes a window key event

type KeyState

type KeyState struct {
	// contains filtered or unexported fields
}

KeyState keeps track of the state of all keys.

func NewKeyState

func NewKeyState(win core.IDispatcher) *KeyState

NewKeyState returns a new KeyState object.

func (*KeyState) Dispose

func (ks *KeyState) Dispose()

Dispose unsubscribes from the window events.

func (*KeyState) Pressed

func (ks *KeyState) Pressed(k Key) bool

Pressed returns whether the specified key is currently pressed.

type ModifierKey

type ModifierKey int

ModifierKey corresponds to a set of modifier keys (bitmask).

type MouseButton

type MouseButton int

MouseButton corresponds to a mouse button.

type MouseEvent

type MouseEvent struct {
	Xpos   float32
	Ypos   float32
	Button MouseButton
	Mods   ModifierKey
}

MouseEvent describes a mouse event over the window

type PosEvent

type PosEvent struct {
	Xpos int
	Ypos int
}

PosEvent describes a windows position changed event

type ScrollEvent

type ScrollEvent struct {
	Xoffset float32
	Yoffset float32
	Mods    ModifierKey
}

ScrollEvent describes a scroll event

type SizeEvent

type SizeEvent struct {
	Width  int
	Height int
}

SizeEvent describers a window size changed event

Jump to

Keyboard shortcuts

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