brutal/Brutal.Sdl/Generated/Libraries/Sdl.Video.gen.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

2975 lines
143 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// <auto-generated/>
// Generated by Brutal.Sdl.Generate; do not edit by hand.
#nullable enable
namespace Brutal.SdlApi
{
public static unsafe partial class Sdl
{
public static unsafe partial class Video
{
/// <summary>
/// Get the number of video drivers compiled into SDL.
/// </summary>
/// <returns>the number of built in video drivers.</returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetVideoDriver"/>
public static int GetNumVideoDrivers() => PInvoke.GetNumVideoDrivers();
/// <summary>
/// Get the name of a built in video driver.
/// </summary>
/// <param name="index">the index of a video driver.</param>
/// <returns>
/// the name of the video driver with the given <b>index</b>, or NULL if
/// index is out of bounds.
/// </returns>
/// <remarks>
/// <para>
/// The video drivers are presented in the order in which they are normally
/// checked during initialization.
/// </para>
/// <para>
/// The names of drivers are all simple, low-ASCII identifiers, like "cocoa",
/// "x11" or "windows". These never have Unicode characters, and are not meant
/// to be proper names.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumVideoDrivers"/>
public static string? GetVideoDriver(int index) => PInvoke.GetVideoDriver(index);
/// <summary>
/// Get the name of the currently initialized video driver.
/// </summary>
/// <returns>
/// the name of the current video driver or NULL if no driver has been
/// initialized.
/// </returns>
/// <remarks>
/// <para>
/// The names of drivers are all simple, low-ASCII identifiers, like "cocoa",
/// "x11" or "windows". These never have Unicode characters, and are not meant
/// to be proper names.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumVideoDrivers"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetVideoDriver"/>
public static string? GetCurrentVideoDriver() => PInvoke.GetCurrentVideoDriver();
/// <summary>
/// Get the current system theme.
/// </summary>
/// <returns>the current system theme, light, dark, or unknown.</returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static SdlSystemTheme GetSystemTheme() => PInvoke.GetSystemTheme();
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetDisplays</c>.
/// </summary>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
/// <remarks>
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy,
/// and the native buffer is freed with <c>SDL_free</c> before this method returns.
/// </remarks>
public static uint[] GetDisplays()
{
int count;
var ptr = PInvoke.GetDisplays(&count);
if (ptr is null)
throw SdlException.FromError("SDL_GetDisplays failed");
try
{
return new ReadOnlySpan<uint>(ptr, count).ToArray();
}
finally
{
PInvoke.Free(ptr);
}
}
/// <summary>
/// Return the primary display.
/// </summary>
/// <returns>
/// the instance ID of the primary display on success or 0 on failure;
/// call SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static uint GetPrimaryDisplay() => PInvoke.GetPrimaryDisplay();
/// <summary>
/// Get the properties associated with a display.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <returns>
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// The following read-only properties are provided by SDL:
/// </para>
/// <para>
/// - <c>SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN</c>: true if the display has HDR
/// headroom above the SDR white point. This is for informational and
/// diagnostic purposes only, as not all platforms provide this information
/// at the display level.
/// </para>
/// <para>
/// On KMS/DRM:
/// </para>
/// <para>
/// - <c>SDL_PROP_DISPLAY_KMSDRM_PANEL_ORIENTATION_NUMBER</c>: the "panel
/// orientation" property for the display in degrees of clockwise rotation.
/// Note that this is provided only as a hint, and the application is
/// responsible for any coordinate transformations needed to conform to the
/// requested display orientation.
/// </para>
/// <para>
/// On Wayland:
/// </para>
/// <para>
/// - <c>SDL_PROP_DISPLAY_WAYLAND_WL_OUTPUT_POINTER</c>: the wl_output associated
/// with the display
/// </para>
/// <para>
/// On Windows:
/// </para>
/// <para>
/// - <c>SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER</c>: the monitor handle
/// (HMONITOR) associated with the display
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static uint GetDisplayProperties(uint displayID) => PInvoke.GetDisplayProperties(displayID);
/// <summary>
/// Get the name of a display in UTF-8 encoding.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <returns>
/// the name of a display or NULL on failure; call SDL_GetError() for
/// more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static string? GetDisplayName(uint displayID) => PInvoke.GetDisplayName(displayID);
/// <summary>
/// Get the desktop area represented by a display.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <param name="rect">the SDL_Rect structure filled in with the display bounds.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The primary display is often located at (0,0), but may be placed at a
/// different location depending on monitor layout.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplayUsableBounds"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static bool GetDisplayBounds(uint displayID, SdlRect* rect) =>
PInvoke.GetDisplayBounds(displayID, rect) != 0;
/// <summary>
/// Get the usable desktop area represented by a display, in screen
/// coordinates.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <param name="rect">the SDL_Rect structure filled in with the display bounds.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is the same area as SDL_GetDisplayBounds() reports, but with portions
/// reserved by the system removed. For example, on Apple's macOS, this
/// subtracts the area occupied by the menu bar and dock.
/// </para>
/// <para>
/// Setting a window to be fullscreen generally bypasses these unusable areas,
/// so these are good guidelines for the maximum space available to a
/// non-fullscreen window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplayBounds"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static bool GetDisplayUsableBounds(uint displayID, SdlRect* rect) =>
PInvoke.GetDisplayUsableBounds(displayID, rect) != 0;
/// <summary>
/// Get the orientation of a display when it is unrotated.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <returns>
/// the SDL_DisplayOrientation enum value of the display, or
/// <c>SDL_ORIENTATION_UNKNOWN</c> if it isn't available.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static SdlDisplayOrientation GetNaturalDisplayOrientation(uint displayID) =>
PInvoke.GetNaturalDisplayOrientation(displayID);
/// <summary>
/// Get the orientation of a display.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <returns>
/// the SDL_DisplayOrientation enum value of the display, or
/// <c>SDL_ORIENTATION_UNKNOWN</c> if it isn't available.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static SdlDisplayOrientation GetCurrentDisplayOrientation(uint displayID) =>
PInvoke.GetCurrentDisplayOrientation(displayID);
/// <summary>
/// Get the content scale of a display.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <returns>
/// the content scale of the display, or 0.0f on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// The content scale is the expected scale for content based on the DPI
/// settings of the display. For example, a 4K display might have a 2.0 (200%)
/// display scale, which means that the user expects UI elements to be twice as
/// big on this display, to aid in readability.
/// </para>
/// <para>
/// After window creation, SDL_GetWindowDisplayScale() should be used to query
/// the content scale factor for individual windows instead of querying the
/// display for a window and calling this function, as the per-window content
/// scale factor may differ from the base value of the display it is on,
/// particularly on high-DPI and/or multi-monitor desktop configurations.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowDisplayScale"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static float GetDisplayContentScale(uint displayID) => PInvoke.GetDisplayContentScale(displayID);
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetFullscreenDisplayModes</c>.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
/// <remarks>
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy,
/// and the native buffer is freed with <c>SDL_free</c> before this method returns.
/// </remarks>
public static SdlDisplayMode[] GetFullscreenDisplayModes(uint displayID)
{
int count;
var ptr = PInvoke.GetFullscreenDisplayModes(displayID, &count);
if (ptr is null)
throw SdlException.FromError("SDL_GetFullscreenDisplayModes failed");
try
{
var result = new SdlDisplayMode[count];
for (var i = 0; i < count; i++)
result[i] = *ptr[i];
return result;
}
finally
{
PInvoke.Free(ptr);
}
}
/// <summary>
/// Get the closest match to the requested display mode.
/// </summary>
/// <param name="displayID">the instance ID of the display to query.</param>
/// <param name="w">the width in pixels of the desired display mode.</param>
/// <param name="h">the height in pixels of the desired display mode.</param>
/// <param name="refresh_rate">
/// the refresh rate of the desired display mode, or 0.0f
/// for the desktop refresh rate.
/// </param>
/// <param name="include_high_density_modes">
/// boolean to include high density modes in
/// the search.
/// </param>
/// <param name="closest">
/// a pointer filled in with the closest display mode equal to
/// or larger than the desired mode.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The available display modes are scanned and <c>closest</c> is filled in with the
/// closest mode matching the requested mode and returned. The mode format and
/// refresh rate default to the desktop mode if they are set to 0. The modes
/// are scanned with size being first priority, format being second priority,
/// and finally checking the refresh rate. If all the available modes are too
/// small, then false is returned.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetFullscreenDisplayModes"/>
public static bool GetClosestFullscreenDisplayMode(
uint displayID,
int w,
int h,
float refresh_rate,
bool include_high_density_modes,
SdlDisplayMode* closest
) =>
PInvoke.GetClosestFullscreenDisplayMode(
displayID,
w,
h,
refresh_rate,
include_high_density_modes ? (byte)1 : (byte)0,
closest
) != 0;
/// <summary>
/// Get the display containing a point.
/// </summary>
/// <param name="point">the point to query.</param>
/// <returns>
/// the instance ID of the display containing the point or 0 on
/// failure; call SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplayBounds"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static uint GetDisplayForPoint(SdlPoint* point) => PInvoke.GetDisplayForPoint(point);
/// <summary>
/// Get the display primarily containing a rect.
/// </summary>
/// <param name="rect">the rect to query.</param>
/// <returns>
/// the instance ID of the display entirely containing the rect or
/// closest to the center of the rect on success or 0 on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplayBounds"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static uint GetDisplayForRect(SdlRect* rect) => PInvoke.GetDisplayForRect(rect);
/// <summary>
/// Get the display associated with a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the instance ID of the display containing the center of the window
/// on success or 0 on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplayBounds"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetDisplays"/>
public static uint GetDisplayForWindow(SdlWindow window) => PInvoke.GetDisplayForWindow(window);
/// <summary>
/// Get the pixel density of a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the pixel density or 0.0f on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is a ratio of pixel size to window size. For example, if the window is
/// 1920x1080 and it has a high density back buffer of 3840x2160 pixels, it
/// would have a pixel density of 2.0.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowDisplayScale"/>
public static float GetWindowPixelDensity(SdlWindow window) => PInvoke.GetWindowPixelDensity(window);
/// <summary>
/// Get the content display scale relative to a window's pixel size.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the display scale, or 0.0f on failure; call SDL_GetError() for
/// more information.
/// </returns>
/// <remarks>
/// <para>
/// This is a combination of the window pixel density and the display content
/// scale, and is the expected scale for displaying content in this window. For
/// example, if a 3840x2160 window had a display scale of 2.0, the user expects
/// the content to take twice as many pixels and be the same physical size as
/// if it were being displayed in a 1920x1080 window with a display scale of
/// 1.0.
/// </para>
/// <para>
/// Conceptually this value corresponds to the scale display setting, and is
/// updated when that setting is changed, or the window moves to a display with
/// a different scale setting.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static float GetWindowDisplayScale(SdlWindow window) => PInvoke.GetWindowDisplayScale(window);
/// <summary>
/// Set the display mode to use when a window is visible and fullscreen.
/// </summary>
/// <param name="window">the window to affect.</param>
/// <param name="mode">
/// a pointer to the display mode to use, which can be NULL for
/// borderless fullscreen desktop mode, or one of the fullscreen
/// modes returned by SDL_GetFullscreenDisplayModes() to set an
/// exclusive fullscreen mode.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This only affects the display mode used when the window is fullscreen. To
/// change the window size when the window is not fullscreen, use
/// SDL_SetWindowSize().
/// </para>
/// <para>
/// If the window is currently in the fullscreen state, this request is
/// asynchronous on some windowing systems and the new mode dimensions may not
/// be applied immediately upon the return of this function. If an immediate
/// change is required, call SDL_SyncWindow() to block until the changes have
/// taken effect.
/// </para>
/// <para>
/// When the new mode takes effect, an SDL_EVENT_WINDOW_RESIZED and/or an
/// SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event will be emitted with the new mode
/// dimensions.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFullscreenMode"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFullscreen"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool SetWindowFullscreenMode(SdlWindow window, SdlDisplayMode* mode) =>
PInvoke.SetWindowFullscreenMode(window, mode) != 0;
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetWindowICCProfile</c>.
/// </summary>
/// <param name="window">the window to query.</param>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
/// <remarks>
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy,
/// and the native buffer is freed with <c>SDL_free</c> before this method returns.
/// </remarks>
public static byte[] GetWindowICCProfile(SdlWindow window)
{
nuint size;
var ptr = PInvoke.GetWindowICCProfile(window, &size);
if (ptr is null)
throw SdlException.FromError("SDL_GetWindowICCProfile failed");
try
{
return new ReadOnlySpan<byte>(ptr, checked((int)size)).ToArray();
}
finally
{
PInvoke.Free(ptr);
}
}
/// <summary>
/// Get the pixel format associated with the window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the pixel format of the window on success or
/// SDL_PIXELFORMAT_UNKNOWN on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static SdlPixelFormat GetWindowPixelFormat(SdlWindow window) => PInvoke.GetWindowPixelFormat(window);
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetWindows</c>.
/// </summary>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
/// <remarks>
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy,
/// and the native buffer is freed with <c>SDL_free</c> before this method returns. Each element is a
/// <b>borrowed handle</b>: it is owned by SDL, not created by this call, and must not be disposed. Do not
/// call <see cref="System.IDisposable.Dispose"/> on any element.
/// </remarks>
public static SdlWindow[] GetWindows()
{
int count;
var ptr = PInvoke.GetWindows(&count);
if (ptr is null)
throw SdlException.FromError("SDL_GetWindows failed");
try
{
return new ReadOnlySpan<SdlWindow>(ptr, count).ToArray();
}
finally
{
PInvoke.Free(ptr);
}
}
/// <summary>
/// Ergonomic wrapper over <c>SDL_CreateWindow</c>. Throws instead of returning a null handle on failure.
/// </summary>
/// <param name="title">the title of the window, in UTF-8 encoding.</param>
/// <param name="w">the width of the window.</param>
/// <param name="h">the height of the window.</param>
/// <param name="flags">0, or one or more SDL_WindowFlags OR'd together.</param>
/// <returns>The created handle (never a null handle).</returns>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
public static SdlWindow CreateWindow(string title, int w, int h, SdlWindowFlags flags)
{
SdlWindow result = PInvoke.CreateWindow(title, w, h, flags);
if (result.IsNull())
{
throw SdlException.FromError("SDL_CreateWindow failed");
}
return result;
}
/// <summary>
/// Ergonomic wrapper over <c>SDL_CreatePopupWindow</c>. Throws instead of returning a null handle on
/// failure.
/// </summary>
/// <param name="parent">the parent of the window, must not be NULL.</param>
/// <param name="offset_x">
/// the x position of the popup window relative to the origin
/// of the parent.
/// </param>
/// <param name="offset_y">
/// the y position of the popup window relative to the origin
/// of the parent window.
/// </param>
/// <param name="w">the width of the window.</param>
/// <param name="h">the height of the window.</param>
/// <param name="flags">
/// SDL_WINDOW_TOOLTIP or SDL_WINDOW_POPUP_MENU, and zero or more
/// additional SDL_WindowFlags OR'd together.
/// </param>
/// <returns>The created handle (never a null handle).</returns>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
public static SdlWindow CreatePopupWindow(
SdlWindow parent,
int offset_x,
int offset_y,
int w,
int h,
SdlWindowFlags flags
)
{
SdlWindow result = PInvoke.CreatePopupWindow(parent, offset_x, offset_y, w, h, flags);
if (result.IsNull())
{
throw SdlException.FromError("SDL_CreatePopupWindow failed");
}
return result;
}
/// <summary>
/// Ergonomic wrapper over <c>SDL_CreateWindowWithProperties</c>. Throws instead of returning a null
/// handle on failure.
/// </summary>
/// <param name="props">the properties to use.</param>
/// <returns>The created handle (never a null handle).</returns>
/// <exception cref="SdlException">The SDL call failed; the message carries the
/// <c>SDL_GetError</c> text.</exception>
public static SdlWindow CreateWindowWithProperties(uint props)
{
SdlWindow result = PInvoke.CreateWindowWithProperties(props);
if (result.IsNull())
{
throw SdlException.FromError("SDL_CreateWindowWithProperties failed");
}
return result;
}
/// <summary>
/// Get the numeric ID of a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the ID of the window on success or 0 on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// The numeric ID is what SDL_WindowEvent references, and is necessary to map
/// these events to specific SDL_Window objects.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFromID"/>
public static uint GetWindowID(SdlWindow window) => PInvoke.GetWindowID(window);
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetWindowFromID</c>.
/// </summary>
/// <param name="id">the ID of the window.</param>
/// <remarks>
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
/// this call does not own. A null handle is returned on failure.
/// </remarks>
public static SdlWindow GetWindowFromID(uint id) => PInvoke.GetWindowFromID(id);
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetWindowParent</c>.
/// </summary>
/// <param name="window">the window to query.</param>
/// <remarks>
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
/// this call does not own. A null handle is returned on failure.
/// </remarks>
public static SdlWindow GetWindowParent(SdlWindow window) => PInvoke.GetWindowParent(window);
/// <summary>
/// Get the properties associated with a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// The following read-only properties are provided by SDL:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_SHAPE_POINTER</c>: the surface associated with a shaped
/// window
/// - <c>SDL_PROP_WINDOW_HDR_ENABLED_BOOLEAN</c>: true if the window has HDR
/// headroom above the SDR white point. This property can change dynamically
/// when SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
/// - <c>SDL_PROP_WINDOW_SDR_WHITE_LEVEL_FLOAT</c>: the value of SDR white in the
/// SDL_COLORSPACE_SRGB_LINEAR colorspace. On Windows this corresponds to the
/// SDR white level in scRGB colorspace, and on Apple platforms this is
/// always 1.0 for EDR content. This property can change dynamically when
/// SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
/// - <c>SDL_PROP_WINDOW_HDR_HEADROOM_FLOAT</c>: the additional high dynamic range
/// that can be displayed, in terms of the SDR white point. When HDR is not
/// enabled, this will be 1.0. This property can change dynamically when
/// SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
/// </para>
/// <para>
/// On Android:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_ANDROID_WINDOW_POINTER</c>: the ANativeWindow associated
/// with the window
/// - <c>SDL_PROP_WINDOW_ANDROID_SURFACE_POINTER</c>: the EGLSurface associated with
/// the window
/// </para>
/// <para>
/// On iOS:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_UIKIT_WINDOW_POINTER</c>: the <c>(__unsafe_unretained)</c>
/// UIWindow associated with the window
/// - <c>SDL_PROP_WINDOW_UIKIT_METAL_VIEW_TAG_NUMBER</c>: the NSInteger tag
/// associated with metal views on the window
/// - <c>SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER</c>: the OpenGL view's
/// framebuffer object. It must be bound when rendering to the screen using
/// OpenGL.
/// - <c>SDL_PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER</c>: the OpenGL view's
/// renderbuffer object. It must be bound when SDL_GL_SwapWindow is called.
/// - <c>SDL_PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER</c>: the OpenGL
/// view's resolve framebuffer, when MSAA is used.
/// </para>
/// <para>
/// On KMS/DRM:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_KMSDRM_DEVICE_INDEX_NUMBER</c>: the device index associated
/// with the window (e.g. the X in /dev/dri/cardX)
/// - <c>SDL_PROP_WINDOW_KMSDRM_DRM_FD_NUMBER</c>: the DRM FD associated with the
/// window
/// - <c>SDL_PROP_WINDOW_KMSDRM_GBM_DEVICE_POINTER</c>: the GBM device associated
/// with the window
/// </para>
/// <para>
/// On macOS:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_COCOA_WINDOW_POINTER</c>: the <c>(__unsafe_unretained)</c>
/// NSWindow associated with the window
/// - <c>SDL_PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER</c>: the NSInteger tag
/// associated with metal views on the window
/// </para>
/// <para>
/// On OpenVR:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_OPENVR_OVERLAY_ID_NUMBER</c>: the OpenVR Overlay Handle ID
/// for the associated overlay window.
/// </para>
/// <para>
/// On Vivante:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER</c>: the EGLNativeDisplayType
/// associated with the window
/// - <c>SDL_PROP_WINDOW_VIVANTE_WINDOW_POINTER</c>: the EGLNativeWindowType
/// associated with the window
/// - <c>SDL_PROP_WINDOW_VIVANTE_SURFACE_POINTER</c>: the EGLSurface associated with
/// the window
/// </para>
/// <para>
/// On Windows:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_WIN32_HWND_POINTER</c>: the HWND associated with the window
/// - <c>SDL_PROP_WINDOW_WIN32_HDC_POINTER</c>: the HDC associated with the window
/// - <c>SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER</c>: the HINSTANCE associated with
/// the window
/// </para>
/// <para>
/// On Wayland:
/// </para>
/// <para>
/// Note: The <c>xdg_*</c> window objects do not internally persist across window
/// show/hide calls. They will be null if the window is hidden and must be
/// queried each time it is shown.
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER</c>: the wl_display associated with
/// the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER</c>: the wl_surface associated with
/// the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_VIEWPORT_POINTER</c>: the wp_viewport associated
/// with the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER</c>: the wl_egl_window
/// associated with the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_XDG_SURFACE_POINTER</c>: the xdg_surface associated
/// with the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_POINTER</c>: the xdg_toplevel role
/// associated with the window
/// - 'SDL_PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_EXPORT_HANDLE_STRING': the export
/// handle associated with the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_XDG_POPUP_POINTER</c>: the xdg_popup role
/// associated with the window
/// - <c>SDL_PROP_WINDOW_WAYLAND_XDG_POSITIONER_POINTER</c>: the xdg_positioner
/// associated with the window, in popup mode
/// </para>
/// <para>
/// On X11:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_X11_DISPLAY_POINTER</c>: the X11 Display associated with
/// the window
/// - <c>SDL_PROP_WINDOW_X11_SCREEN_NUMBER</c>: the screen number associated with
/// the window
/// - <c>SDL_PROP_WINDOW_X11_WINDOW_NUMBER</c>: the X11 Window associated with the
/// window
/// </para>
/// <para>
/// On Emscripten:
/// </para>
/// <para>
/// - <c>SDL_PROP_WINDOW_EMSCRIPTEN_CANVAS_ID_STRING</c>: the id the canvas element
/// will have
/// - <c>SDL_PROP_WINDOW_EMSCRIPTEN_KEYBOARD_ELEMENT_STRING</c>: the keyboard
/// element that associates keyboard events to this window
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static uint GetWindowProperties(SdlWindow window) => PInvoke.GetWindowProperties(window);
/// <summary>
/// Get the window flags.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>a mask of the SDL_WindowFlags associated with <c>window</c>.</returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.CreateWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.HideWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MaximizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MinimizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFullscreen"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseGrab"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFillDocument"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.ShowWindow"/>
public static SdlWindowFlags GetWindowFlags(SdlWindow window) => PInvoke.GetWindowFlags(window);
/// <summary>
/// Set the title of a window.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="title">the desired window title in UTF-8 format.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This string is expected to be in UTF-8 encoding.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowTitle"/>
public static bool SetWindowTitle(SdlWindow window, string title) =>
PInvoke.SetWindowTitle(window, title) != 0;
/// <summary>
/// Get the title of a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// the title of the window in UTF-8 format or "" if there is no
/// title.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowTitle"/>
public static string? GetWindowTitle(SdlWindow window) => PInvoke.GetWindowTitle(window);
/// <summary>
/// Set the icon for a window.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="icon">an SDL_Surface structure containing the icon for the window.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If this function is passed a surface with alternate representations added
/// using SDL_AddSurfaceAlternateImage(), the surface will be interpreted as
/// the content to be used for 100% display scale, and the alternate
/// representations will be used for high DPI situations. For example, if the
/// original surface is 32x32, then on a 2x macOS display or 200% display scale
/// on Windows, a 64x64 version of the image will be used, if available. If a
/// matching version of the image isn't available, the closest larger size
/// image will be downscaled to the appropriate size and be used instead, if
/// available. Otherwise, the closest smaller image will be upscaled and be
/// used instead.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.AddSurfaceAlternateImage"/>
public static bool SetWindowIcon(SdlWindow window, SdlSurface* icon) =>
PInvoke.SetWindowIcon(window, icon) != 0;
/// <summary>
/// Request that the window's position be set.
/// </summary>
/// <param name="window">the window to reposition.</param>
/// <param name="x">
/// the x coordinate of the window, or <c>SDL_WINDOWPOS_CENTERED</c> or
/// <c>SDL_WINDOWPOS_UNDEFINED</c>.
/// </param>
/// <param name="y">
/// the y coordinate of the window, or <c>SDL_WINDOWPOS_CENTERED</c> or
/// <c>SDL_WINDOWPOS_UNDEFINED</c>.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the window is in an exclusive fullscreen or maximized state, this
/// request has no effect.
/// </para>
/// <para>
/// This can be used to reposition fullscreen-desktop windows onto a different
/// display, however, as exclusive fullscreen windows are locked to a specific
/// display, they can only be repositioned programmatically via
/// SDL_SetWindowFullscreenMode().
/// </para>
/// <para>
/// On some windowing systems this request is asynchronous and the new
/// coordinates may not have have been applied immediately upon the return of
/// this function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window position changes, an SDL_EVENT_WINDOW_MOVED event will be
/// emitted with the window's new coordinates. Note that the new coordinates
/// may not match the exact coordinates requested, as some windowing systems
/// can restrict the position of the window in certain scenarios (e.g.
/// constraining the position so the window is always within desktop bounds).
/// Additionally, as this is just a request, it can be denied by the windowing
/// system.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowPosition"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool SetWindowPosition(SdlWindow window, int x, int y) =>
PInvoke.SetWindowPosition(window, x, y) != 0;
/// <summary>
/// Get the position of a window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <param name="x">
/// a pointer filled in with the x position of the window, may be
/// NULL.
/// </param>
/// <param name="y">
/// a pointer filled in with the y position of the window, may be
/// NULL.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is the current position of the window as last reported by the
/// windowing system.
/// </para>
/// <para>
/// If you do not need the value for one of the positions a NULL may be passed
/// in the <c>x</c> or <c>y</c> parameter.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowPosition"/>
public static bool GetWindowPosition(SdlWindow window, out int x, out int y)
{
x = default;
y = default;
fixed (int* xPtr = &x)
{
fixed (int* yPtr = &y)
{
return PInvoke.GetWindowPosition(window, xPtr, yPtr) != 0;
}
}
}
/// <summary>
/// Request that the size of a window's client area be set.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="w">the width of the window, must be &gt; 0.</param>
/// <param name="h">the height of the window, must be &gt; 0.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the window is in a fullscreen or maximized state, this request has no
/// effect.
/// </para>
/// <para>
/// To change the exclusive fullscreen mode of a window, use
/// SDL_SetWindowFullscreenMode().
/// </para>
/// <para>
/// On some windowing systems, this request is asynchronous and the new window
/// size may not have have been applied immediately upon the return of this
/// function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window size changes, an SDL_EVENT_WINDOW_RESIZED event will be
/// emitted with the new window dimensions. Note that the new dimensions may
/// not match the exact size requested, as some windowing systems can restrict
/// the window size in certain scenarios (e.g. constraining the size of the
/// content area to remain within the usable desktop bounds). Additionally, as
/// this is just a request, it can be denied by the windowing system.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFullscreenMode"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool SetWindowSize(SdlWindow window, int w, int h) =>
PInvoke.SetWindowSize(window, w, h) != 0;
/// <summary>
/// Get the size of a window's client area.
/// </summary>
/// <param name="window">the window to query the width and height from.</param>
/// <param name="w">a pointer filled in with the width of the window, may be NULL.</param>
/// <param name="h">a pointer filled in with the height of the window, may be NULL.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The window pixel size may differ from its window coordinate size if the
/// window is on a high pixel density display. Use SDL_GetWindowSizeInPixels()
/// or SDL_GetRenderOutputSize() to get the real client area size in pixels.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetRenderOutputSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSizeInPixels"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowSize"/>
public static bool GetWindowSize(SdlWindow window, out int w, out int h)
{
w = default;
h = default;
fixed (int* wPtr = &w)
{
fixed (int* hPtr = &h)
{
return PInvoke.GetWindowSize(window, wPtr, hPtr) != 0;
}
}
}
/// <summary>
/// Get the safe area for this window.
/// </summary>
/// <param name="window">the window to query.</param>
/// <param name="rect">
/// a pointer filled in with the client area that is safe for
/// interactive content.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Some devices have portions of the screen which are partially obscured or
/// not interactive, possibly due to on-screen controls, curved edges, camera
/// notches, TV overscan, etc. This function provides the area of the window
/// which is safe to have interactable content. You should continue rendering
/// into the rest of the window, but it should not contain visually important
/// or interactable content.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool GetWindowSafeArea(SdlWindow window, SdlRect* rect) =>
PInvoke.GetWindowSafeArea(window, rect) != 0;
/// <summary>
/// Request that the aspect ratio of a window's client area be set.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="min_aspect">
/// the minimum aspect ratio of the window, or 0.0f for no
/// limit.
/// </param>
/// <param name="max_aspect">
/// the maximum aspect ratio of the window, or 0.0f for no
/// limit.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The aspect ratio is the ratio of width divided by height, e.g. 2560x1600
/// would be 1.6. Larger aspect ratios are wider and smaller aspect ratios are
/// narrower.
/// </para>
/// <para>
/// If, at the time of this request, the window in a fixed-size state, such as
/// maximized or fullscreen, the request will be deferred until the window
/// exits this state and becomes resizable again.
/// </para>
/// <para>
/// On some windowing systems, this request is asynchronous and the new window
/// aspect ratio may not have have been applied immediately upon the return of
/// this function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window size changes, an SDL_EVENT_WINDOW_RESIZED event will be
/// emitted with the new window dimensions. Note that the new dimensions may
/// not match the exact aspect ratio requested, as some windowing systems can
/// restrict the window size in certain scenarios (e.g. constraining the size
/// of the content area to remain within the usable desktop bounds).
/// Additionally, as this is just a request, it can be denied by the windowing
/// system.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowAspectRatio"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool SetWindowAspectRatio(SdlWindow window, float min_aspect, float max_aspect) =>
PInvoke.SetWindowAspectRatio(window, min_aspect, max_aspect) != 0;
/// <summary>
/// Get the aspect ratio of a window's client area.
/// </summary>
/// <param name="window">the window to query the width and height from.</param>
/// <param name="min_aspect">
/// a pointer filled in with the minimum aspect ratio of the
/// window, may be NULL.
/// </param>
/// <param name="max_aspect">
/// a pointer filled in with the maximum aspect ratio of the
/// window, may be NULL.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowAspectRatio"/>
public static bool GetWindowAspectRatio(SdlWindow window, out float min_aspect, out float max_aspect)
{
min_aspect = default;
max_aspect = default;
fixed (float* min_aspectPtr = &min_aspect)
{
fixed (float* max_aspectPtr = &max_aspect)
{
return PInvoke.GetWindowAspectRatio(window, min_aspectPtr, max_aspectPtr) != 0;
}
}
}
/// <summary>
/// Get the size of a window's borders (decorations) around the client area.
/// </summary>
/// <param name="window">
/// the window to query the size values of the border
/// (decorations) from.
/// </param>
/// <param name="top">
/// pointer to variable for storing the size of the top border; NULL
/// is permitted.
/// </param>
/// <param name="left">
/// pointer to variable for storing the size of the left border;
/// NULL is permitted.
/// </param>
/// <param name="bottom">
/// pointer to variable for storing the size of the bottom
/// border; NULL is permitted.
/// </param>
/// <param name="right">
/// pointer to variable for storing the size of the right border;
/// NULL is permitted.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Note: If this function fails (returns false), the size values will be
/// initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as if the
/// window in question was borderless.
/// </para>
/// <para>
/// Note: This function may fail on systems where the window has not yet been
/// decorated by the display server (for example, immediately after calling
/// SDL_CreateWindow). It is recommended that you wait at least until the
/// window has been presented and composited, so that the window system has a
/// chance to decorate the window and provide the border dimensions to SDL.
/// </para>
/// <para>
/// This function also returns false if getting the information is not
/// supported.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSize"/>
public static bool GetWindowBordersSize(
SdlWindow window,
out int top,
out int left,
out int bottom,
out int right
)
{
top = default;
left = default;
bottom = default;
right = default;
fixed (int* topPtr = &top)
{
fixed (int* leftPtr = &left)
{
fixed (int* bottomPtr = &bottom)
{
fixed (int* rightPtr = &right)
{
return PInvoke.GetWindowBordersSize(window, topPtr, leftPtr, bottomPtr, rightPtr) != 0;
}
}
}
}
}
/// <summary>
/// Get the size of a window's client area, in pixels.
/// </summary>
/// <param name="window">the window from which the drawable size should be queried.</param>
/// <param name="w">
/// a pointer to variable for storing the width in pixels, may be
/// NULL.
/// </param>
/// <param name="h">
/// a pointer to variable for storing the height in pixels, may be
/// NULL.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.CreateWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSize"/>
public static bool GetWindowSizeInPixels(SdlWindow window, out int w, out int h)
{
w = default;
h = default;
fixed (int* wPtr = &w)
{
fixed (int* hPtr = &h)
{
return PInvoke.GetWindowSizeInPixels(window, wPtr, hPtr) != 0;
}
}
}
/// <summary>
/// Set the minimum size of a window's client area.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="min_w">the minimum width of the window, or 0 for no limit.</param>
/// <param name="min_h">the minimum height of the window, or 0 for no limit.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMinimumSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMaximumSize"/>
public static bool SetWindowMinimumSize(SdlWindow window, int min_w, int min_h) =>
PInvoke.SetWindowMinimumSize(window, min_w, min_h) != 0;
/// <summary>
/// Get the minimum size of a window's client area.
/// </summary>
/// <param name="window">the window to query.</param>
/// <param name="w">
/// a pointer filled in with the minimum width of the window, may be
/// NULL.
/// </param>
/// <param name="h">
/// a pointer filled in with the minimum height of the window, may be
/// NULL.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMaximumSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMinimumSize"/>
public static bool GetWindowMinimumSize(SdlWindow window, out int w, out int h)
{
w = default;
h = default;
fixed (int* wPtr = &w)
{
fixed (int* hPtr = &h)
{
return PInvoke.GetWindowMinimumSize(window, wPtr, hPtr) != 0;
}
}
}
/// <summary>
/// Set the maximum size of a window's client area.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="max_w">the maximum width of the window, or 0 for no limit.</param>
/// <param name="max_h">the maximum height of the window, or 0 for no limit.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMaximumSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMinimumSize"/>
public static bool SetWindowMaximumSize(SdlWindow window, int max_w, int max_h) =>
PInvoke.SetWindowMaximumSize(window, max_w, max_h) != 0;
/// <summary>
/// Get the maximum size of a window's client area.
/// </summary>
/// <param name="window">the window to query.</param>
/// <param name="w">
/// a pointer filled in with the maximum width of the window, may be
/// NULL.
/// </param>
/// <param name="h">
/// a pointer filled in with the maximum height of the window, may be
/// NULL.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMinimumSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMaximumSize"/>
public static bool GetWindowMaximumSize(SdlWindow window, out int w, out int h)
{
w = default;
h = default;
fixed (int* wPtr = &w)
{
fixed (int* hPtr = &h)
{
return PInvoke.GetWindowMaximumSize(window, wPtr, hPtr) != 0;
}
}
}
/// <summary>
/// Set the border state of a window.
/// </summary>
/// <param name="window">the window of which to change the border state.</param>
/// <param name="bordered">false to remove border, true to add border.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This will add or remove the window's <c>SDL_WINDOW_BORDERLESS</c> flag and add
/// or remove the border from the actual window. This is a no-op if the
/// window's border already matches the requested state.
/// </para>
/// <para>
/// You can't change the border state of a fullscreen window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFlags"/>
public static bool SetWindowBordered(SdlWindow window, bool bordered) =>
PInvoke.SetWindowBordered(window, bordered ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Set the user-resizable state of a window.
/// </summary>
/// <param name="window">the window of which to change the resizable state.</param>
/// <param name="resizable">true to allow resizing, false to disallow.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This will add or remove the window's <c>SDL_WINDOW_RESIZABLE</c> flag and
/// allow/disallow user resizing of the window. This is a no-op if the window's
/// resizable state already matches the requested state.
/// </para>
/// <para>
/// You can't change the resizable state of a fullscreen window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFlags"/>
public static bool SetWindowResizable(SdlWindow window, bool resizable) =>
PInvoke.SetWindowResizable(window, resizable ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Set the window to always be above the others.
/// </summary>
/// <param name="window">the window of which to change the always on top state.</param>
/// <param name="on_top">true to set the window always on top, false to disable.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This will add or remove the window's <c>SDL_WINDOW_ALWAYS_ON_TOP</c> flag. This
/// will bring the window to the front and keep the window above the rest.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFlags"/>
public static bool SetWindowAlwaysOnTop(SdlWindow window, bool on_top) =>
PInvoke.SetWindowAlwaysOnTop(window, on_top ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Set the window to fill the current document space (Emscripten only).
/// </summary>
/// <param name="window">the window of which to change the fill-document state.</param>
/// <param name="fill">true to set the window to fill the document, false to disable.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This will add or remove the window's <c>SDL_WINDOW_FILL_DOCUMENT</c> flag.
/// </para>
/// <para>
/// Currently this flag only applies to the Emscripten target.
/// </para>
/// <para>
/// When enabled, the canvas element fills the entire document. Resize events
/// will be generated as the browser window is resized, as that will adjust the
/// canvas size as well. The canvas will cover anything else on the page,
/// including any controls provided by Emscripten in its generated HTML file
/// (in fact, any elements on the page that aren't the canvas will be moved
/// into a hidden <c>div</c> element).
/// </para>
/// <para>
/// Often times this is desirable for a browser-based game, but it means
/// several things that we expect of an SDL window on other platforms might not
/// work as expected, such as minimum window sizes and aspect ratios.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.4.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFlags"/>
public static bool SetWindowFillDocument(SdlWindow window, bool fill) =>
PInvoke.SetWindowFillDocument(window, fill ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Show a window.
/// </summary>
/// <param name="window">the window to show.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.HideWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.RaiseWindow"/>
public static bool ShowWindow(SdlWindow window) => PInvoke.ShowWindow(window) != 0;
/// <summary>
/// Hide a window.
/// </summary>
/// <param name="window">the window to hide.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.ShowWindow"/>
public static bool HideWindow(SdlWindow window) => PInvoke.HideWindow(window) != 0;
/// <summary>
/// Request that a window be raised above other windows and gain the input
/// focus.
/// </summary>
/// <param name="window">the window to raise.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The result of this request is subject to desktop window manager policy,
/// particularly if raising the requested window would result in stealing focus
/// from another application. If the window is successfully raised and gains
/// input focus, an SDL_EVENT_WINDOW_FOCUS_GAINED event will be emitted, and
/// the window will have the SDL_WINDOW_INPUT_FOCUS flag set.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool RaiseWindow(SdlWindow window) => PInvoke.RaiseWindow(window) != 0;
/// <summary>
/// Request that the window be made as large as possible.
/// </summary>
/// <param name="window">the window to maximize.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Non-resizable windows can't be maximized. The window must have the
/// SDL_WINDOW_RESIZABLE flag set, or this will have no effect.
/// </para>
/// <para>
/// On some windowing systems this request is asynchronous and the new window
/// state may not have have been applied immediately upon the return of this
/// function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window state changes, an SDL_EVENT_WINDOW_MAXIMIZED event will be
/// emitted. Note that, as this is just a request, the windowing system can
/// deny the state change.
/// </para>
/// <para>
/// When maximizing a window, whether the constraints set via
/// SDL_SetWindowMaximumSize() are honored depends on the policy of the window
/// manager. Win32 and macOS enforce the constraints when maximizing, while X11
/// and Wayland window managers may vary.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MinimizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.RestoreWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool MaximizeWindow(SdlWindow window) => PInvoke.MaximizeWindow(window) != 0;
/// <summary>
/// Request that the window be minimized to an iconic representation.
/// </summary>
/// <param name="window">the window to minimize.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the window is in a fullscreen state, this request has no direct effect.
/// It may alter the state the window is returned to when leaving fullscreen.
/// </para>
/// <para>
/// On some windowing systems this request is asynchronous and the new window
/// state may not have been applied immediately upon the return of this
/// function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window state changes, an SDL_EVENT_WINDOW_MINIMIZED event will be
/// emitted. Note that, as this is just a request, the windowing system can
/// deny the state change.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MaximizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.RestoreWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool MinimizeWindow(SdlWindow window) => PInvoke.MinimizeWindow(window) != 0;
/// <summary>
/// Request that the size and position of a minimized or maximized window be
/// restored.
/// </summary>
/// <param name="window">the window to restore.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the window is in a fullscreen state, this request has no direct effect.
/// It may alter the state the window is returned to when leaving fullscreen.
/// </para>
/// <para>
/// On some windowing systems this request is asynchronous and the new window
/// state may not have have been applied immediately upon the return of this
/// function. If an immediate change is required, call SDL_SyncWindow() to
/// block until the changes have taken effect.
/// </para>
/// <para>
/// When the window state changes, an SDL_EVENT_WINDOW_RESTORED event will be
/// emitted. Note that, as this is just a request, the windowing system can
/// deny the state change.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MaximizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MinimizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool RestoreWindow(SdlWindow window) => PInvoke.RestoreWindow(window) != 0;
/// <summary>
/// Request that the window's fullscreen state be changed.
/// </summary>
/// <param name="window">the window to change.</param>
/// <param name="fullscreen">true for fullscreen mode, false for windowed mode.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// By default a window in fullscreen state uses borderless fullscreen desktop
/// mode, but a specific exclusive display mode can be set using
/// SDL_SetWindowFullscreenMode().
/// </para>
/// <para>
/// On some windowing systems this request is asynchronous and the new
/// fullscreen state may not have have been applied immediately upon the return
/// of this function. If an immediate change is required, call SDL_SyncWindow()
/// to block until the changes have taken effect.
/// </para>
/// <para>
/// When the window state changes, an SDL_EVENT_WINDOW_ENTER_FULLSCREEN or
/// SDL_EVENT_WINDOW_LEAVE_FULLSCREEN event will be emitted. Note that, as this
/// is just a request, it can be denied by the windowing system.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowFullscreenMode"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFullscreenMode"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SyncWindow"/>
public static bool SetWindowFullscreen(SdlWindow window, bool fullscreen) =>
PInvoke.SetWindowFullscreen(window, fullscreen ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Block until any pending window state is finalized.
/// </summary>
/// <param name="window">
/// the window for which to wait for the pending state to be
/// applied.
/// </param>
/// <returns>
/// true on success or false if the operation timed out before the
/// window was in the requested state.
/// </returns>
/// <remarks>
/// <para>
/// On asynchronous windowing systems, this acts as a synchronization barrier
/// for pending window state. It will attempt to wait until any pending window
/// state has been applied and is guaranteed to return within finite time. Note
/// that for how long it can potentially block depends on the underlying window
/// system, as window state changes may involve somewhat lengthy animations
/// that must complete before the window is in its final requested state.
/// </para>
/// <para>
/// On windowing systems where changes are immediate, this does nothing.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowSize"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowPosition"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowFullscreen"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MinimizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.MaximizeWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.RestoreWindow"/>
public static bool SyncWindow(SdlWindow window) => PInvoke.SyncWindow(window) != 0;
/// <summary>
/// Return whether the window has a surface associated with it.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>
/// true if there is a surface associated with the window, or false
/// otherwise.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSurface"/>
public static bool WindowHasSurface(SdlWindow window) => PInvoke.WindowHasSurface(window) != 0;
/// <summary>
/// Toggle VSync for the window surface.
/// </summary>
/// <param name="window">the window.</param>
/// <param name="vsync">the vertical refresh sync interval.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// When a window surface is created, vsync defaults to
/// SDL_WINDOW_SURFACE_VSYNC_DISABLED.
/// </para>
/// <para>
/// The <c>vsync</c> parameter can be 1 to synchronize present with every vertical
/// refresh, 2 to synchronize present with every second vertical refresh, etc.,
/// SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync),
/// or SDL_WINDOW_SURFACE_VSYNC_DISABLED to disable. Not every value is
/// supported by every driver, so you should check the return value to see
/// whether the requested setting is supported.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSurfaceVSync"/>
public static bool SetWindowSurfaceVSync(SdlWindow window, int vsync) =>
PInvoke.SetWindowSurfaceVSync(window, vsync) != 0;
/// <summary>
/// Get VSync for the window surface.
/// </summary>
/// <param name="window">the window to query.</param>
/// <param name="vsync">
/// an int filled with the current vertical refresh sync interval.
/// See SDL_SetWindowSurfaceVSync() for the meaning of the value.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowSurfaceVSync"/>
public static bool GetWindowSurfaceVSync(SdlWindow window, out int vsync)
{
vsync = default;
fixed (int* vsyncPtr = &vsync)
{
return PInvoke.GetWindowSurfaceVSync(window, vsyncPtr) != 0;
}
}
/// <summary>
/// Copy the window surface to the screen.
/// </summary>
/// <param name="window">the window to update.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is the function you use to reflect any changes to the surface on the
/// screen.
/// </para>
/// <para>
/// This function is equivalent to the SDL 1.2 API SDL_Flip().
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSurface"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.UpdateWindowSurfaceRects"/>
public static bool UpdateWindowSurface(SdlWindow window) => PInvoke.UpdateWindowSurface(window) != 0;
/// <summary>
/// Copy areas of the window surface to the screen.
/// </summary>
/// <param name="window">the window to update.</param>
/// <param name="rects">
/// an array of SDL_Rect structures representing areas of the
/// surface to copy, in pixels.
/// </param>
/// <param name="numrects">the number of rectangles.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is the function you use to reflect changes to portions of the surface
/// on the screen.
/// </para>
/// <para>
/// This function is equivalent to the SDL 1.2 API SDL_UpdateRects().
/// </para>
/// <para>
/// Note that this function will update <em>at least</em> the rectangles specified,
/// but this is only intended as an optimization; in practice, this might
/// update more of the screen (or all of the screen!), depending on what method
/// SDL uses to send pixels to the system.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSurface"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.UpdateWindowSurface"/>
public static bool UpdateWindowSurfaceRects(SdlWindow window, SdlRect* rects, int numrects) =>
PInvoke.UpdateWindowSurfaceRects(window, rects, numrects) != 0;
/// <summary>
/// Destroy the surface associated with the window.
/// </summary>
/// <param name="window">the window to update.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowSurface"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.WindowHasSurface"/>
public static bool DestroyWindowSurface(SdlWindow window) => PInvoke.DestroyWindowSurface(window) != 0;
/// <summary>
/// Set a window's keyboard grab mode.
/// </summary>
/// <param name="window">the window for which the keyboard grab mode should be set.</param>
/// <param name="grabbed">this is true to grab keyboard, and false to release.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Keyboard grab enables capture of system keyboard shortcuts like Alt+Tab or
/// the Meta/Super key. Note that not all system keyboard shortcuts can be
/// captured by applications (one example is Ctrl+Alt+Del on Windows).
/// </para>
/// <para>
/// This is primarily intended for specialized applications such as VNC clients
/// or VM frontends. Normal games should not use keyboard grab.
/// </para>
/// <para>
/// When keyboard grab is enabled, SDL will continue to handle Alt+Tab when the
/// window is full-screen to ensure the user is not trapped in your
/// application. If you have a custom keyboard shortcut to exit fullscreen
/// mode, you may suppress this behavior with
/// <c>SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED</c>.
/// </para>
/// <para>
/// If the caller enables a grab while another window is currently grabbed, the
/// other window loses its grab in favor of the caller's window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowKeyboardGrab"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseGrab"/>
public static bool SetWindowKeyboardGrab(SdlWindow window, bool grabbed) =>
PInvoke.SetWindowKeyboardGrab(window, grabbed ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Set a window's mouse grab mode.
/// </summary>
/// <param name="window">the window for which the mouse grab mode should be set.</param>
/// <param name="grabbed">this is true to grab mouse, and false to release.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Mouse grab confines the mouse cursor to the window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMouseRect"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseRect"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowKeyboardGrab"/>
public static bool SetWindowMouseGrab(SdlWindow window, bool grabbed) =>
PInvoke.SetWindowMouseGrab(window, grabbed ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Get a window's keyboard grab mode.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>true if keyboard is grabbed, and false otherwise.</returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowKeyboardGrab"/>
public static bool GetWindowKeyboardGrab(SdlWindow window) => PInvoke.GetWindowKeyboardGrab(window) != 0;
/// <summary>
/// Get a window's mouse grab mode.
/// </summary>
/// <param name="window">the window to query.</param>
/// <returns>true if mouse is grabbed, and false otherwise.</returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMouseRect"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseRect"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseGrab"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowKeyboardGrab"/>
public static bool GetWindowMouseGrab(SdlWindow window) => PInvoke.GetWindowMouseGrab(window) != 0;
/// <summary>
/// Ergonomic wrapper over <c>SDL_GetGrabbedWindow</c>.
/// </summary>
/// <remarks>
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
/// this call does not own. A null handle is returned on failure.
/// </remarks>
public static SdlWindow GetGrabbedWindow() => PInvoke.GetGrabbedWindow();
/// <summary>
/// Confines the cursor to the specified area of a window.
/// </summary>
/// <param name="window">the window that will be associated with the barrier.</param>
/// <param name="rect">
/// a rectangle area in window-relative coordinates. If NULL the
/// barrier for the specified window will be destroyed.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Note that this does NOT grab the cursor, it only defines the area a cursor
/// is restricted to when the window has mouse focus.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMouseRect"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowMouseGrab"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowMouseGrab"/>
public static bool SetWindowMouseRect(SdlWindow window, SdlRect* rect) =>
PInvoke.SetWindowMouseRect(window, rect) != 0;
/// <summary>
/// Set the opacity for a window.
/// </summary>
/// <param name="window">the window which will be made transparent or opaque.</param>
/// <param name="opacity">the opacity value (0.0f - transparent, 1.0f - opaque).</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The parameter <c>opacity</c> will be clamped internally between 0.0f
/// (transparent) and 1.0f (opaque).
/// </para>
/// <para>
/// This function also returns false if setting the opacity isn't supported.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetWindowOpacity"/>
public static bool SetWindowOpacity(SdlWindow window, float opacity) =>
PInvoke.SetWindowOpacity(window, opacity) != 0;
/// <summary>
/// Get the opacity of a window.
/// </summary>
/// <param name="window">the window to get the current opacity value from.</param>
/// <returns>
/// the opacity, (0.0f - transparent, 1.0f - opaque), or -1.0f on
/// failure; call SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// If transparency isn't supported on this platform, opacity will be returned
/// as 1.0f without error.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowOpacity"/>
public static float GetWindowOpacity(SdlWindow window) => PInvoke.GetWindowOpacity(window);
/// <summary>
/// Set the window as a child of a parent window.
/// </summary>
/// <param name="window">the window that should become the child of a parent.</param>
/// <param name="parent">the new parent window for the child window.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the window is already the child of an existing window, it will be
/// reparented to the new owner. Setting the parent window to NULL unparents
/// the window and removes child window status.
/// </para>
/// <para>
/// If a parent window is hidden or destroyed, the operation will be
/// recursively applied to child windows. Child windows hidden with the parent
/// that did not have their hidden status explicitly set will be restored when
/// the parent is shown.
/// </para>
/// <para>
/// Attempting to set the parent of a window that is currently in the modal
/// state will fail. Use SDL_SetWindowModal() to cancel the modal status before
/// attempting to change the parent.
/// </para>
/// <para>
/// Popup windows cannot change parents and attempts to do so will fail.
/// </para>
/// <para>
/// Setting a parent window that is currently the sibling or descendent of the
/// child window results in undefined behavior.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowModal"/>
public static bool SetWindowParent(SdlWindow window, SdlWindow parent) =>
PInvoke.SetWindowParent(window, parent) != 0;
/// <summary>
/// Toggle the state of the window as modal.
/// </summary>
/// <param name="window">the window on which to set the modal state.</param>
/// <param name="modal">true to toggle modal status on, false to toggle it off.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// To enable modal status on a window, the window must currently be the child
/// window of a parent, or toggling modal status on will fail.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetWindowParent"/>
public static bool SetWindowModal(SdlWindow window, bool modal) =>
PInvoke.SetWindowModal(window, modal ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Set whether the window may have input focus.
/// </summary>
/// <param name="window">the window to set focusable state.</param>
/// <param name="focusable">true to allow input focus, false to not allow input focus.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool SetWindowFocusable(SdlWindow window, bool focusable) =>
PInvoke.SetWindowFocusable(window, focusable ? (byte)1 : (byte)0) != 0;
/// <summary>
/// Display the system-level window menu.
/// </summary>
/// <param name="window">the window for which the menu will be displayed.</param>
/// <param name="x">
/// the x coordinate of the menu, relative to the origin (top-left) of
/// the client area.
/// </param>
/// <param name="y">
/// the y coordinate of the menu, relative to the origin (top-left) of
/// the client area.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This default window menu is provided by the system and on some platforms
/// provides functionality for setting or changing privileged state on the
/// window, such as moving it between workspaces or displays, or toggling the
/// always-on-top property.
/// </para>
/// <para>
/// On platforms or desktops where this is unsupported, this function does
/// nothing.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool ShowWindowSystemMenu(SdlWindow window, int x, int y) =>
PInvoke.ShowWindowSystemMenu(window, x, y) != 0;
/// <summary>
/// Set the shape of a transparent window.
/// </summary>
/// <param name="window">the window.</param>
/// <param name="shape">
/// the surface representing the shape of the window, or NULL to
/// remove any current shape.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This sets the alpha channel of a transparent window and any fully
/// transparent areas are also transparent to mouse clicks. If you are using
/// something besides the SDL render API, then you are responsible for drawing
/// the alpha channel of the window to match the shape alpha channel to get
/// consistent cross-platform results.
/// </para>
/// <para>
/// The shape is copied inside this function, so you can free it afterwards. If
/// your shape surface changes, you should call SDL_SetWindowShape() again to
/// update the window. This is an expensive operation, so should be done
/// sparingly.
/// </para>
/// <para>
/// The window must have been created with the SDL_WINDOW_TRANSPARENT flag.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool SetWindowShape(SdlWindow window, SdlSurface* shape) =>
PInvoke.SetWindowShape(window, shape) != 0;
/// <summary>
/// Request a window to demand attention from the user.
/// </summary>
/// <param name="window">the window to be flashed.</param>
/// <param name="operation">the operation to perform.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool FlashWindow(SdlWindow window, SdlFlashOperation operation) =>
PInvoke.FlashWindow(window, operation) != 0;
/// <summary>
/// Sets the state of the progress bar for the given window’s taskbar icon.
/// </summary>
/// <param name="window">the window whose progress state is to be modified.</param>
/// <param name="state">
/// the progress state. <c>SDL_PROGRESS_STATE_NONE</c> stops displaying
/// the progress bar.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.4.0.
/// </since>
public static bool SetWindowProgressState(SdlWindow window, SdlProgressState state) =>
PInvoke.SetWindowProgressState(window, state) != 0;
/// <summary>
/// Get the state of the progress bar for the given window’s taskbar icon.
/// </summary>
/// <param name="window">the window to get the current progress state from.</param>
/// <returns>
/// the progress state, or <c>SDL_PROGRESS_STATE_INVALID</c> on failure;
/// call SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.4.0.
/// </since>
public static SdlProgressState GetWindowProgressState(SdlWindow window) =>
PInvoke.GetWindowProgressState(window);
/// <summary>
/// Sets the value of the progress bar for the given window’s taskbar icon.
/// </summary>
/// <param name="window">the window whose progress value is to be modified.</param>
/// <param name="value">
/// the progress value in the range of [0.0f - 1.0f]. If the value
/// is outside the valid range, it gets clamped.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.4.0.
/// </since>
public static bool SetWindowProgressValue(SdlWindow window, float value) =>
PInvoke.SetWindowProgressValue(window, value) != 0;
/// <summary>
/// Get the value of the progress bar for the given window’s taskbar icon.
/// </summary>
/// <param name="window">the window to get the current progress value from.</param>
/// <returns>
/// the progress value in the range of [0.0f - 1.0f], or -1.0f on
/// failure; call SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.4.0.
/// </since>
public static float GetWindowProgressValue(SdlWindow window) => PInvoke.GetWindowProgressValue(window);
/// <summary>
/// Destroy a window.
/// </summary>
/// <param name="window">the window to destroy.</param>
/// <remarks>
/// <para>
/// Any child windows owned by the window will be recursively destroyed as
/// well.
/// </para>
/// <para>
/// Note that on some platforms, the visible window may not actually be removed
/// from the screen until the SDL event loop is pumped again, even though the
/// SDL_Window is no longer valid after this call.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.CreatePopupWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.CreateWindow"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.CreateWindowWithProperties"/>
public static void DestroyWindow(SdlWindow window) => PInvoke.DestroyWindow(window);
/// <summary>
/// Check whether the screensaver is currently enabled.
/// </summary>
/// <returns>true if the screensaver is enabled, false if it is disabled.</returns>
/// <remarks>
/// <para>
/// The screensaver is disabled by default.
/// </para>
/// <para>
/// The default can also be changed using <c>SDL_HINT_VIDEO_ALLOW_SCREENSAVER</c>.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.DisableScreenSaver"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.EnableScreenSaver"/>
public static bool ScreenSaverEnabled() => PInvoke.ScreenSaverEnabled() != 0;
/// <summary>
/// Allow the screen to be blanked by a screen saver.
/// </summary>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.DisableScreenSaver"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.ScreenSaverEnabled"/>
public static bool EnableScreenSaver() => PInvoke.EnableScreenSaver() != 0;
/// <summary>
/// Prevent the screen from being blanked by a screen saver.
/// </summary>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If you disable the screensaver, it is automatically re-enabled when SDL
/// quits.
/// </para>
/// <para>
/// The screensaver is disabled by default, but this may by changed by
/// SDL_HINT_VIDEO_ALLOW_SCREENSAVER.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.EnableScreenSaver"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.ScreenSaverEnabled"/>
public static bool DisableScreenSaver() => PInvoke.DisableScreenSaver() != 0;
/// <summary>
/// Dynamically load an OpenGL library.
/// </summary>
/// <param name="path">
/// the platform dependent OpenGL library name, or NULL to open the
/// default OpenGL library.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This should be done after initializing the video driver, but before
/// creating any OpenGL windows. If no OpenGL library is loaded, the default
/// library will be loaded upon creation of the first OpenGL window.
/// </para>
/// <para>
/// If you do this, you need to retrieve all of the GL functions used in your
/// program from the dynamic library using SDL_GL_GetProcAddress().
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLGetProcAddress"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLUnloadLibrary"/>
public static bool GLLoadLibrary(string path) => PInvoke.GLLoadLibrary(path) != 0;
/// <summary>
/// Unload the OpenGL library previously loaded by SDL_GL_LoadLibrary().
/// </summary>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLLoadLibrary"/>
public static void GLUnloadLibrary() => PInvoke.GLUnloadLibrary();
/// <summary>
/// Check if an OpenGL extension is supported for the current context.
/// </summary>
/// <param name="extension">the name of the extension to check.</param>
/// <returns>true if the extension is supported, false otherwise.</returns>
/// <remarks>
/// <para>
/// This function operates on the current GL context; you must have created a
/// context and it must be current before calling this function. Do not assume
/// that all contexts you create will have the same set of extensions
/// available, or that recreating an existing context will offer the same
/// extensions again.
/// </para>
/// <para>
/// While it's probably not a massive overhead, this function is not an O(1)
/// operation. Check the extensions you care about after creating the GL
/// context and save that information somewhere instead of calling the function
/// every time you need to know.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool GLExtensionSupported(string extension) => PInvoke.GLExtensionSupported(extension) != 0;
/// <summary>
/// Reset all previously set OpenGL context attributes to their default values.
/// </summary>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLGetAttribute"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLSetAttribute"/>
public static void GLResetAttributes() => PInvoke.GLResetAttributes();
/// <summary>
/// Set an OpenGL window attribute before window creation.
/// </summary>
/// <param name="attr">an enum value specifying the OpenGL attribute to set.</param>
/// <param name="value">the desired value for the attribute.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This function sets the OpenGL attribute <c>attr</c> to <c>value</c>. The requested
/// attributes should be set before creating an OpenGL window. You should use
/// SDL_GL_GetAttribute() to check the values after creating the OpenGL
/// context, since the values obtained can differ from the requested ones.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLCreateContext"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLGetAttribute"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLResetAttributes"/>
public static bool GLSetAttribute(SdlGLAttr attr, int value) => PInvoke.GLSetAttribute(attr, value) != 0;
/// <summary>
/// Get the actual value for an attribute from the current context.
/// </summary>
/// <param name="attr">
/// an SDL_GLAttr enum value specifying the OpenGL attribute to
/// get.
/// </param>
/// <param name="value">a pointer filled in with the current value of <c>attr</c>.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLResetAttributes"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLSetAttribute"/>
public static bool GLGetAttribute(SdlGLAttr attr, out int value)
{
value = default;
fixed (int* valuePtr = &value)
{
return PInvoke.GLGetAttribute(attr, valuePtr) != 0;
}
}
/// <summary>
/// Create an OpenGL context for an OpenGL window, and make it current.
/// </summary>
/// <param name="window">the window to associate with the context.</param>
/// <returns>
/// the OpenGL context associated with <c>window</c> or NULL on failure;
/// call SDL_GetError() for more information.
/// </returns>
/// <remarks>
/// <para>
/// The OpenGL context will be created with the current states set through
/// SDL_GL_SetAttribute().
/// </para>
/// <para>
/// The SDL_Window specified must have been created with the SDL_WINDOW_OPENGL
/// flag, or context creation will fail.
/// </para>
/// <para>
/// Windows users new to OpenGL should note that, for historical reasons, GL
/// functions added after OpenGL version 1.1 are not available by default.
/// Those functions must be loaded at run-time, either with an OpenGL
/// extension-handling library or with SDL_GL_GetProcAddress() and its related
/// functions.
/// </para>
/// <para>
/// SDL_GLContext is opaque to the application.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLDestroyContext"/>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLMakeCurrent"/>
public static nint GLCreateContext(SdlWindow window) => PInvoke.GLCreateContext(window);
/// <summary>
/// Set up an OpenGL context for rendering into an OpenGL window.
/// </summary>
/// <param name="window">the window to associate with the context.</param>
/// <param name="context">the OpenGL context to associate with the window.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// The context must have been created with a compatible window.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLCreateContext"/>
public static bool GLMakeCurrent(SdlWindow window, nint context) =>
PInvoke.GLMakeCurrent(window, context) != 0;
/// <summary>
/// Ergonomic wrapper over <c>SDL_GL_GetCurrentWindow</c>.
/// </summary>
/// <remarks>
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
/// this call does not own. A null handle is returned on failure.
/// </remarks>
public static SdlWindow GLGetCurrentWindow() => PInvoke.GLGetCurrentWindow();
/// <summary>
/// Get the currently active OpenGL context.
/// </summary>
/// <returns>
/// the currently active OpenGL context or NULL on failure; call
/// SDL_GetError() for more information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLMakeCurrent"/>
public static nint GLGetCurrentContext() => PInvoke.GLGetCurrentContext();
/// <summary>
/// Set the swap interval for the current OpenGL context.
/// </summary>
/// <param name="interval">
/// 0 for immediate updates, 1 for updates synchronized with
/// the vertical retrace, -1 for adaptive vsync.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// Some systems allow specifying -1 for the interval, to enable adaptive
/// vsync. Adaptive vsync works the same as vsync, but if you've already missed
/// the vertical retrace for a given frame, it swaps buffers immediately, which
/// might be less jarring for the user during occasional framerate drops. If an
/// application requests adaptive vsync and the system does not support it,
/// this function will fail and return false. In such a case, you should
/// probably retry the call with 1 for the interval.
/// </para>
/// <para>
/// Adaptive vsync is implemented for some glX drivers with
/// GLX_EXT_swap_control_tear, and for some Windows drivers with
/// WGL_EXT_swap_control_tear.
/// </para>
/// <para>
/// Read more on the Khronos wiki:
/// https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLGetSwapInterval"/>
public static bool GLSetSwapInterval(int interval) => PInvoke.GLSetSwapInterval(interval) != 0;
/// <summary>
/// Get the swap interval for the current OpenGL context.
/// </summary>
/// <param name="interval">
/// output interval value. 0 if there is no vertical retrace
/// synchronization, 1 if the buffer swap is synchronized with
/// the vertical retrace, and -1 if late swaps happen
/// immediately instead of waiting for the next retrace.
/// </param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// If the system can't determine the swap interval, or there isn't a valid
/// current context, this function will set *interval to 0 as a safe default.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLSetSwapInterval"/>
public static bool GLGetSwapInterval(out int interval)
{
interval = default;
fixed (int* intervalPtr = &interval)
{
return PInvoke.GLGetSwapInterval(intervalPtr) != 0;
}
}
/// <summary>
/// Update a window with OpenGL rendering.
/// </summary>
/// <param name="window">the window to change.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <remarks>
/// <para>
/// This is used with double-buffered OpenGL contexts, which are the default.
/// </para>
/// <para>
/// On macOS, make sure you bind 0 to the draw framebuffer before swapping the
/// window, otherwise nothing will happen. If you aren't using
/// glBindFramebuffer(), this is the default and you won't have to do anything
/// extra.
/// </para>
/// </remarks>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
public static bool GLSwapWindow(SdlWindow window) => PInvoke.GLSwapWindow(window) != 0;
/// <summary>
/// Delete an OpenGL context.
/// </summary>
/// <param name="context">the OpenGL context to be deleted.</param>
/// <returns>
/// true on success or false on failure; call SDL_GetError() for more
/// information.
/// </returns>
/// <threadsafety>
/// This function should only be called on the main thread.
/// </threadsafety>
/// <since>
/// This function is available since SDL 3.2.0.
/// </since>
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GLCreateContext"/>
public static bool GLDestroyContext(nint context) => PInvoke.GLDestroyContext(context) != 0;
}
}
}