win

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 11 Imported by: 4

Documentation

Rendered for windows/amd64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientSize

func ClientSize(window w32.HWND) (w, h int)

func CloseWindow

func CloseWindow(window w32.HWND)

CloseWindow sends a WM_CLOSE event to the given window.

func DisableFullscreen

func DisableFullscreen(window w32.HWND, placement w32.WINDOWPLACEMENT)

DisableFullscreen makes the window have a border and the standard icons (style WS_OVERLAPPEDWINDOW) and places it at the position given by the window placement parameter. Use this in conjunction with IsFullscreen and EnableFullscreen to toggle a window's fullscreen state.

func EnableFullscreen

func EnableFullscreen(window w32.HWND) (windowed w32.WINDOWPLACEMENT)

EnableFullscreen makes the window a borderless window that covers the full area of the monitor under the window. It returns the previous window placement. Store that value and use it with DisableFullscreen to reset the window to what it was before.

func HandlePanics

func HandlePanics(id string)

HandlePanics is designed to be deferred as the first statement in an application's main function. It calls recover to catch unhandled panics. The current stack is output to standard output, to a file in the user's APPDATA folder (which is then opened with the default .txt editor) and to a message box that is shown to the user. The id is used in the log file name.

func HideConsoleWindow

func HideConsoleWindow()

HideConsoleWindow hides the associated console window if it was created because the ldflag H=windowsgui was not provided when building.

func IsFullscreen

func IsFullscreen(window w32.HWND) bool

IsFullscreen returns true if the window has a style different from WS_OVERLAPPEDWINDOW. The EnableFullscreen function will change the style to borderless so this reports whether that function was called on the window. It is not a universally valid test for any window to see if it is fullscreen. It is intended for use in conjunction with EnableFullscreen and DisableFullscreen.

func NewWindow

func NewWindow(opts WindowOptions, f MessageCallback) (w32.HWND, error)

NewWindow creates a window.

func RunMainGameLoop

func RunMainGameLoop(f func())

RunMainGameLoop starts the application's window message handling. It loops until the window is closed. Messages are forwarded to the handler function that was passed to NewWindow. In contrast to RunMainLoop, RunMainGameLoop calls the given function whenever there are now messages to be handled at the moment. You can use this like a classical DOS era endless loop to run any real-time logic in between messages. Tip: if you do not want the game to use all your CPU, do some kind of blocking operation in the function you pass. A simple time.Sleep(0) will do the trick.

func RunMainLoop

func RunMainLoop()

RunMainLoop starts the applications window message handling. It loops until the window is closed. Messages are forwarded to the handler function that was passed to NewWindow.

func SetIconFromExe

func SetIconFromExe(window w32.HWND, resourceID uint16)

SetIconFromExe sets the icon in the window title bar, in the taskbar and when using Alt-Tab to switch between applications. The icon is loaded from the running executable file using the given resource ID. This means that the icon must be embedded in the executable when building by using a resource file for example.

Types

type KeyOptions

type KeyOptions uintptr

func (KeyOptions) IsExtended

func (o KeyOptions) IsExtended() bool

func (KeyOptions) RepeatCount

func (o KeyOptions) RepeatCount() int

func (KeyOptions) ScanCode

func (o KeyOptions) ScanCode() int

func (KeyOptions) WasDown

func (o KeyOptions) WasDown() bool

type MessageCallback

type MessageCallback func(window w32.HWND, msg uint32, w, l uintptr) uintptr

type MessageHandler

type MessageHandler struct {
	OnKeyDown         func(key uintptr, options KeyOptions)
	OnKeyUp           func(key uintptr, options KeyOptions)
	OnMouseMove       func(x, y int, options MouseOptions)
	OnMouseWheel      func(forward float32, x, y int, options MouseOptions)
	OnLeftMouseDown   func(x, y int, options MouseOptions)
	OnRightMouseDown  func(x, y int, options MouseOptions)
	OnMiddleMouseDown func(x, y int, options MouseOptions)
	OnLeftMouseUp     func(x, y int, options MouseOptions)
	OnRightMouseUp    func(x, y int, options MouseOptions)
	OnMiddleMouseUp   func(x, y int, options MouseOptions)
	OnChar            func(r rune)
	OnSize            func(width, height int)
	OnMove            func(x, y int)
	OnActivate        func()
	OnDeactivate      func()
	OnTimer           func(id uintptr)
	OnOther           func(msg uint32, w, l uintptr) (handled bool)
}

MessageHandler translates common Windows messages for you instead of providing generic W and L parameters. Set the handlers that you want and leave the rest at nil. Use the MessageHandler's Callback function as the callback for a window.

func (*MessageHandler) Callback

func (m *MessageHandler) Callback(window w32.HWND, msg uint32, w, l uintptr) uintptr

Callback can be used as the callback function for a window. It will translate common messages into nice function calls. No need to handle generic W and L parameters yourself.

type MouseOptions

type MouseOptions uintptr

func (MouseOptions) ControlDown

func (o MouseOptions) ControlDown() bool

func (MouseOptions) LButtonDown

func (o MouseOptions) LButtonDown() bool

func (MouseOptions) MButtonDown

func (o MouseOptions) MButtonDown() bool

func (MouseOptions) RButtonDown

func (o MouseOptions) RButtonDown() bool

func (MouseOptions) ShiftDown

func (o MouseOptions) ShiftDown() bool

func (MouseOptions) XButton1Down

func (o MouseOptions) XButton1Down() bool

func (MouseOptions) XButton2Down

func (o MouseOptions) XButton2Down() bool

type WindowOptions

type WindowOptions struct {
	X, Y          int
	Width, Height int
	ClassName     string
	Title         string
	Cursor        w32.HCURSOR
	// ClassStyle should include w32.CS_OWNDC for OpenGL
	ClassStyle  uint32
	WindowStyle uint
	Background  w32.HBRUSH
}

func DefaultOptions

func DefaultOptions() WindowOptions

Jump to

Keyboard shortcuts

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