From f548130d140b5b4dbb0dc5b9faf3c5a9f79410c5 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Tue, 25 May 2021 15:51:45 +0200 Subject: [PATCH] Add Window-related functions --- raylib/core.go | 153 ++++++++++++++++++++++++++++--------- raylib/platform_desktop.go | 39 ---------- 2 files changed, 117 insertions(+), 75 deletions(-) diff --git a/raylib/core.go b/raylib/core.go index d10b6f2..57b5b0c 100644 --- a/raylib/core.go +++ b/raylib/core.go @@ -50,6 +50,13 @@ func (b *BoundingBox) cptr() *C.BoundingBox { return (*C.BoundingBox)(unsafe.Pointer(b)) } +// WindowShouldClose - Check if KEY_ESCAPE pressed or Close icon pressed +func WindowShouldClose() bool { + ret := C.WindowShouldClose() + v := bool(ret) + return v +} + // CloseWindow - Close Window and Terminate Context func CloseWindow() { C.CloseWindow() @@ -62,23 +69,9 @@ func IsWindowReady() bool { return v } -// WindowShouldClose - Detect if KEY_ESCAPE pressed or Close icon pressed -func WindowShouldClose() bool { - ret := C.WindowShouldClose() - v := bool(ret) - return v -} - -// IsWindowMinimized - Detect if window has been minimized (or lost focus) -func IsWindowMinimized() bool { - ret := C.IsWindowMinimized() - v := bool(ret) - return v -} - -// IsWindowResized - Check if window has been resized -func IsWindowResized() bool { - ret := C.IsWindowResized() +// IsWindowFullscreen - Check if window is currently fullscreen +func IsWindowFullscreen() bool { + ret := C.IsWindowFullscreen() v := bool(ret) return v } @@ -90,11 +83,74 @@ func IsWindowHidden() bool { return v } +// IsWindowMinimized - Check if window is currently minimized +func IsWindowMinimized() bool { + ret := C.IsWindowMinimized() + v := bool(ret) + return v +} + +// IsWindowMaximized - Check if window is currently maximized +func IsWindowMaximized() bool { + ret := C.IsWindowMaximized() + v := bool(ret) + return v +} + +// IsWindowFocused - Check if window is currently focused +func IsWindowFocused() bool { + ret := C.IsWindowFocused() + v := bool(ret) + return v +} + +// IsWindowResized - Check if window has been resized +func IsWindowResized() bool { + ret := C.IsWindowResized() + v := bool(ret) + return v +} + +// IsWindowState - Check if one specific window flag is enabled +func IsWindowState(flag byte) bool { + cflag := (C.uint)(flag) + ret := C.IsWindowState(cflag) + v := bool(ret) + return v +} + +// SetWindowState - Set window configuration state using flags +func SetWindowState(flags byte) { + cflags := (C.uint)(flags) + C.SetWindowState(cflags) +} + +// ClearWindowState - Clear window configuration state flags +func ClearWindowState(flags byte) { + cflags := (C.uint)(flags) + C.ClearWindowState(cflags) +} + // ToggleFullscreen - Fullscreen toggle (only PLATFORM_DESKTOP) func ToggleFullscreen() { C.ToggleFullscreen() } +// MaximizeWindow - Set window state: maximized, if resizable +func MaximizeWindow() { + C.MaximizeWindow() +} + +// MinimizeWindow - Set window state: minimized, if resizable +func MinimizeWindow() { + C.MinimizeWindow() +} + +// RestoreWindow - Set window state: not minimized/maximized +func RestoreWindow() { + C.RestoreWindow() +} + // SetWindowIcon - Set icon for window (only PLATFORM_DESKTOP) func SetWindowIcon(image Image) { cimage := image.cptr() @@ -135,18 +191,6 @@ func SetWindowSize(w, h int) { C.SetWindowSize(cw, ch) } -// SetWindowState - Set window configuration state using flags -func SetWindowState(flags byte) { - cflags := (C.uint)(flags) - C.SetWindowState(cflags) -} - -// ClearWindowState - Clear window configuration state flags -func ClearWindowState(flags byte) { - cflags := (C.uint)(flags) - C.ClearWindowState(cflags) -} - // GetScreenWidth - Get current screen width func GetScreenWidth() int { ret := C.GetScreenWidth() @@ -168,6 +212,21 @@ func GetMonitorCount() int { return v } +// GetCurrentMonitor - Get current connected monitor +func GetCurrentMonitor() int { + ret := C.GetCurrentMonitor() + v := (int)(ret) + return v +} + +// GetMonitorPosition - Get specified monitor position +func GetMonitorPosition(monitor int) Vector2 { + cmonitor := (C.int)(monitor) + ret := C.GetMonitorPosition(cmonitor) + v := newVector2FromPointer(unsafe.Pointer(&ret)) + return v +} + // GetMonitorWidth - Get primary monitor width func GetMonitorWidth(monitor int) int { cmonitor := (C.int)(monitor) @@ -200,6 +259,28 @@ func GetMonitorPhysicalHeight(monitor int) int { return v } +// GetMonitorRefreshRate - Get specified monitor refresh rate +func GetMonitorRefreshRate(monitor int) int { + cmonitor := (C.int)(monitor) + ret := C.GetMonitorRefreshRate(cmonitor) + v := (int)(ret) + return v +} + +// GetWindowPosition - Get window position XY on monitor +func GetWindowPosition() Vector2 { + ret := C.GetWindowPosition() + v := newVector2FromPointer(unsafe.Pointer(&ret)) + return v +} + +// GetWindowScaleDPI - Get window scale DPI factor +func GetWindowScaleDPI() Vector2 { + ret := C.GetWindowScaleDPI() + v := newVector2FromPointer(unsafe.Pointer(&ret)) + return v +} + // GetMonitorName - Get the human-readable, UTF-8 encoded name of the primary monitor func GetMonitorName(monitor int) string { cmonitor := (C.int)(monitor) @@ -208,13 +289,6 @@ func GetMonitorName(monitor int) string { return v } -// GetClipboardText - Get clipboard text content -func GetClipboardText() string { - ret := C.GetClipboardText() - v := C.GoString(ret) - return v -} - // SetClipboardText - Set clipboard text content func SetClipboardText(data string) { cdata := C.CString(data) @@ -222,6 +296,13 @@ func SetClipboardText(data string) { C.SetClipboardText(cdata) } +// GetClipboardText - Get clipboard text content +func GetClipboardText() string { + ret := C.GetClipboardText() + v := C.GoString(ret) + return v +} + // ClearBackground - Sets Background Color func ClearBackground(color Color) { ccolor := color.cptr() diff --git a/raylib/platform_desktop.go b/raylib/platform_desktop.go index f73a426..04e0ec8 100644 --- a/raylib/platform_desktop.go +++ b/raylib/platform_desktop.go @@ -91,45 +91,6 @@ func OpenAsset(name string) (Asset, error) { return f, nil } -// IsWindowMaximized - Check if window has been maximized (only PLATFORM_DESKTOP) -func IsWindowMaximized() bool { - ret := C.IsWindowMaximized() - v := bool(ret) - return v -} - -// IsWindowFocused - Check if window has been focused -func IsWindowFocused() bool { - ret := C.IsWindowFocused() - v := bool(ret) - return v -} - -// MaximizeWindow - Maximize the window, if resizable (only PLATFORM_DESKTOP) -func MaximizeWindow() { - C.MaximizeWindow() -} - -// RestoreWindow - Restore the window, if resizable (only PLATFORM_DESKTOP) -func RestoreWindow() { - C.RestoreWindow() -} - -// GetMonitorRefreshRate - Get primary monitor refresh rate -func GetMonitorRefreshRate(monitor int) int { - cmonitor := (C.int)(monitor) - ret := C.GetMonitorRefreshRate(cmonitor) - v := (int)(ret) - return v -} - -// GetWindowScaleDPI - Get window scale DPI factor -func GetWindowScaleDPI() Vector2 { - ret := C.GetWindowScaleDPI() - v := newVector2FromPointer(unsafe.Pointer(&ret)) - return v -} - // IsCursorOnScreen - Check if cursor is on the current screen. func IsCursorOnScreen() bool { ret := C.IsCursorOnScreen()