Pixels, Surfaces, Renderer, oh my...
This commit is contained in:
@@ -1,100 +1,28 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Display.hpp
|
||||
* @brief HDK sdl video header only wrapper for the SDL_DisplayID type and related functions
|
||||
*/
|
||||
/// @file Display.hpp
|
||||
/// For complete documentation, see src/video/Display.cpp
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <hdk/grid/PrimitiveWrapper.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
#include <vector>
|
||||
/** Displays represent physical display devices such as monitors. */
|
||||
namespace hdk::sdl {
|
||||
/**
|
||||
* @brief A wrapper for SDL_DisplayID that provides type safety and convenience functions for working with display IDs
|
||||
* in SDL.
|
||||
*
|
||||
*/
|
||||
class Display : public grid::PrimitiveWrapper<SDL_DisplayID> {
|
||||
public:
|
||||
using grid::PrimitiveWrapper<SDL_DisplayID>::PrimitiveWrapper;
|
||||
/** @see SDL_GetClosestFullscreenDisplayMode
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetClosestFullscreenDisplayMode
|
||||
* @brief Get the closest match to the requested display mode for fullscreen mode.
|
||||
* @param w requested width in pixels
|
||||
* @param h requested height in pixels
|
||||
* @param refresh_rate 0.0f for desktop refresh rate,
|
||||
* @param include_high_density_modes whether to include high density display modes in the search
|
||||
* @param closest A pointer to a display mode to be filled in with the closest match of the available display
|
||||
* modes. May be NULL to just get the number of matching video modes.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetClosestFullscreenMode(
|
||||
int w, int h, float refresh_rate, bool include_high_density_modes, SDL_DisplayMode* closest) {
|
||||
return SDL_GetClosestFullscreenDisplayMode(*this, w, h, refresh_rate, include_high_density_modes, closest);
|
||||
}
|
||||
/** @see SDL_GetCurrentDisplayMode
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetCurrentDisplayMode
|
||||
* @brief Get the current display mode of a display.
|
||||
* @return display mode of the display.
|
||||
*/
|
||||
const SDL_DisplayMode* GetCurrentMode() const { return SDL_GetCurrentDisplayMode(*this); }
|
||||
/** @see SDL_GetCurrentDisplayOrientation
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetCurrentDisplayOrientation
|
||||
* @return orientation of the display
|
||||
*/
|
||||
SDL_DisplayOrientation GetCurrentOrientation() const { return SDL_GetCurrentDisplayOrientation(*this); }
|
||||
/** @see SDL_GetDesktopDisplayMode
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDesktopDisplayMode
|
||||
* @return desktop display mode of the display
|
||||
*/
|
||||
const SDL_DisplayMode* GetDesktopMode() const { return SDL_GetDesktopDisplayMode(*this); }
|
||||
/** @see SDL_GetDisplayBounds
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayBounds
|
||||
* @brief Get the bounds of a display.
|
||||
* @param rect A pointer to an SDL_Rect structure to be filled in with the display
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetBounds(SDL_Rect* rect) const { return SDL_GetDisplayBounds(*this, rect); }
|
||||
/** @see SDL_GetDisplayContentScale
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayContentScale
|
||||
* @return The content scale factor for the display
|
||||
*/
|
||||
float GetContentScale() const { return SDL_GetDisplayContentScale(*this); }
|
||||
/** @see SDL_GetDisplayForPoint
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayForPoint
|
||||
* @brief Get the display that contains a point.
|
||||
* @param point A pointer to an SDL_Point structure representing the point to query
|
||||
*/
|
||||
static Display GetForPoint(const SDL_Point* point) { return Display(SDL_GetDisplayForPoint(point)); }
|
||||
/** @see SDL_GetDisplayForRect
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayForRect
|
||||
* @brief Get the display that most closely intersects a rectangle.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the rectangle to query
|
||||
*/
|
||||
static Display GetForRect(const SDL_Rect* rect) { return Display(SDL_GetDisplayForRect(rect)); }
|
||||
/** @see SDL_GetDisplayForWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayForWindow
|
||||
* @brief Get the display associated with a window.
|
||||
* @param window The window to query
|
||||
* @return Display The display associated with the window
|
||||
*/
|
||||
static Display GetForWindow(SDL_Window* window) { return Display(SDL_GetDisplayForWindow(window)); }
|
||||
/** @see SDL_GetDisplayName
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayName
|
||||
* @return The name of the display.
|
||||
*/
|
||||
const char* GetName() const { return SDL_GetDisplayName(*this); }
|
||||
/** @see SDL_GetDisplayProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayProperties
|
||||
* @return Properties associated with the display.
|
||||
*/
|
||||
Properties GetProperties() const { return Properties(SDL_GetDisplayProperties(*this)); }
|
||||
/** @see SDL_GetDisplays
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplays
|
||||
* @param count pointer to int filled with the count of displays
|
||||
* @returns an array of DisplayIDs representing the displays
|
||||
* @note Must be freed with SDL_free() when finished.
|
||||
*/
|
||||
static SDL_DisplayID* GetDisplays(int* count) { return SDL_GetDisplays(count); }
|
||||
/** @see SDL_GetDisplays
|
||||
* @returns std::vector Display(s) available
|
||||
@@ -112,19 +40,7 @@ namespace hdk::sdl {
|
||||
}
|
||||
return displays;
|
||||
}
|
||||
/** @see SDL_GetDisplayUsableBounds
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetDisplayUsableBounds
|
||||
* @brief Get the usable bounds of a display.
|
||||
* @param rect A pointer to an SDL_Rect structure to be filled in with the usable bounds
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetUsableBounds(SDL_Rect* rect) const { return SDL_GetDisplayUsableBounds(*this, rect); }
|
||||
/** @see SDL_GetFullscreenDisplayModes
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetFullscreenDisplayModes
|
||||
* @param count pointer to int filled with the count of display modes
|
||||
* @return null terminated array of display modes available for fullscreen mode
|
||||
* @note Must be freed with SDL_free() when finished.
|
||||
*/
|
||||
SDL_DisplayMode** GetFullscreenModes(int* count) const { return SDL_GetFullscreenDisplayModes(*this, count); }
|
||||
/** @see SDL_GetFullscreenDisplayModes
|
||||
* @returns std::vector of display modes available for fullscreen mode
|
||||
@@ -142,15 +58,7 @@ namespace hdk::sdl {
|
||||
}
|
||||
return displayModes;
|
||||
}
|
||||
/** @see SDL_GetNaturalDisplayOrientation
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetNaturalDisplayOrientation
|
||||
* @return The natural orientation of the display
|
||||
*/
|
||||
SDL_DisplayOrientation GetNaturalOrientation() const { return SDL_GetNaturalDisplayOrientation(*this); }
|
||||
/** @see SDL_GetPrimaryDisplay
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetPrimaryDisplay
|
||||
* @return The primary display
|
||||
*/
|
||||
static Display GetPrimaryDisplay() { return Display(SDL_GetPrimaryDisplay()); }
|
||||
};
|
||||
}
|
||||
@@ -1,199 +1,83 @@
|
||||
#pragma once
|
||||
/** @file Surface.hpp
|
||||
* @brief Defines the Surface class for handling SDL surfaces.
|
||||
*/
|
||||
/// @file Surface.hpp
|
||||
/// For complete documentation, see src/video/Surface.cpp
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
/** Surfaces hold bitmap data **/
|
||||
#include <list>
|
||||
namespace hdk::sdl {
|
||||
class Palette;
|
||||
|
||||
class Surface : public hdk::grid::SharedPtrWrapper<SDL_Surface> {
|
||||
public:
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
friend class Renderer;
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Surface>::SharedPtrWrapper;
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_AddSurfaceAlternateImage
|
||||
* @brief Add an alternate image to a surface.
|
||||
* @param surface The surface to add the alternate image to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool AddAlternateImage(SDL_Surface* surface) const { return SDL_AddSurfaceAlternateImage(*this, surface); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurface
|
||||
* @brief Perform a fast blit from `this` surface to the destination surface.
|
||||
* @param dst_surface The destination surface to blit on to.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination surface to blit
|
||||
* onto, or NULL to blit onto the entire surface.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area of the source surface to blit, or
|
||||
* NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitTo(
|
||||
SDL_Surface* dst_surface, const SDL_Rect* dst_rect = nullptr, const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurface(*this, src_rect, dst_surface, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurface
|
||||
* @brief Perform a fast blit to `this` surface from a source surface.
|
||||
* @param src_surface The source surface to blit from.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area on the source surface to blit
|
||||
* from, or NULL to blit the entire surface.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area of the destination surface to blit,
|
||||
* or NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitFrom(
|
||||
SDL_Surface* src_surface, const SDL_Rect* src_rect = nullptr, const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurface(src_surface, src_rect, *this, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurface9Grid
|
||||
* @brief Perform a blit with 9-grid scaling from `this` surface to the destination surface.
|
||||
* @param dst_surface The destination surface to blit on to.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination
|
||||
* @param left_width The width of the left columns of the 9-grid
|
||||
* @param right_width The width of the right columns of the 9-grid
|
||||
* @param top_height The height of the top rows of the 9-grid
|
||||
* @param bottom_height The height of the bottom rows of the 9-grid
|
||||
* @param scale The scale factor to apply to the center of the 9-grid
|
||||
* @param scale_mode
|
||||
* @param src_rect
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Blit9GridTo(SDL_Surface* dst_surface, const SDL_Rect* dst_rect, int left_width, int right_width,
|
||||
int top_height, int bottom_height, float scale, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurface9Grid(*this, src_rect, left_width, right_width, top_height, bottom_height, scale,
|
||||
scale_mode, dst_surface, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurface9Grid
|
||||
* @brief Perform a blit with 9-grid scaling to `this` surface from a source surface.
|
||||
* @param src_surface The source surface to blit from.
|
||||
* @param src_rect
|
||||
* @param left_width The width of the left columns of the 9-grid
|
||||
* @param right_width The width of the right columns of the 9-grid
|
||||
* @param top_height The height of the top rows of the 9-grid
|
||||
* @param bottom_height The height of the bottom rows of the 9-grid
|
||||
* @param scale The scale factor to apply to the center of the 9-grid
|
||||
* @param scale_mode
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination surface to blit, or
|
||||
NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Blit9GridFrom(SDL_Surface* src_surface, const SDL_Rect* src_rect, int left_width, int right_width,
|
||||
int top_height, int bottom_height, float scale, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurface9Grid(src_surface, src_rect, left_width, right_width, top_height, bottom_height, scale,
|
||||
scale_mode, *this, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceScaled
|
||||
* @brief Perform a scaled blit from `this` surface to the destination surface.
|
||||
* @param dst_surface The destination surface to blit on to.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination
|
||||
* @param scale_mode The scale mode to use for scaling the surface
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area of the source
|
||||
* surface to blit, or NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitScaledTo(SDL_Surface* dst_surface, const SDL_Rect* dst_rect, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceScaled(*this, src_rect, dst_surface, dst_rect, scale_mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceScaled
|
||||
* @brief Perform a scaled blit to `this` surface from a source surface.
|
||||
* @param src_surface The source surface to blit from.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area on the source
|
||||
* @param scale_mode The scale mode to use for scaling the surface
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination surface to blit, or
|
||||
* NULL to blit the entire surface.
|
||||
* @return bool true
|
||||
*/
|
||||
bool BlitScaledFrom(SDL_Surface* src_surface, const SDL_Rect* src_rect, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceScaled(src_surface, src_rect, *this, dst_rect, scale_mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceTiled
|
||||
* @brief Perform a tiled blit from `this` surface to the destination surface.
|
||||
* @param dst_surface The destination surface to blit on to.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination surface to blit
|
||||
* onto, or NULL to blit onto the entire surface.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area of the source surface to blit, or NULL
|
||||
* to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitTiledTo(
|
||||
SDL_Surface* dst_surface, const SDL_Rect* dst_rect = nullptr, const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceTiled(*this, src_rect, dst_surface, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceTiled
|
||||
* @brief Perform a tiled blit to `this` surface from a source surface.
|
||||
* @param src_surface The source surface to blit from.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area on the source surface to blit, or NULL
|
||||
* to blit the entire surface.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area of the destination surface to blit, or
|
||||
* NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitTiledFrom(
|
||||
SDL_Surface* src_surface, const SDL_Rect* src_rect = nullptr, const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceTiled(src_surface, src_rect, *this, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceTiledWithScale
|
||||
* @brief Perform a tiled blit with scale from `this` surface to the destination surface.
|
||||
* @param dst_surface The destination surface to blit on to.
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area on the destination surface to blit
|
||||
* onto, or NULL to blit onto the entire surface.
|
||||
* @param scale The scale factor to apply to the source surface when blitting.
|
||||
* @param scale_mode The scale mode to use for scaling the surface
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area of the source
|
||||
*/
|
||||
bool BlitTiledWithScaleTo(SDL_Surface* dst_surface, const SDL_Rect* dst_rect, float scale,
|
||||
SDL_ScaleMode scale_mode, const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceTiledWithScale(*this, src_rect, scale, scale_mode, dst_surface, dst_rect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceTiledWithScale
|
||||
* @brief Perform a tiled blit with scale to `this` surface from a source surface.
|
||||
* @param src_surface The source surface to blit from.
|
||||
* @param src_rect A pointer to an SDL_Rect structure representing the area of the source surface to blit, or NULL
|
||||
* to blit the entire surface.
|
||||
* @param scale The scale factor to apply to the source surface when blitting.
|
||||
* @param scale_mode The scale mode to use for scaling the surface
|
||||
* @param dst_rect A pointer to an SDL_Rect structure representing the area of the destination surface to blit, or
|
||||
* NULL to blit the entire surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool BlitTiledWithScaleFrom(SDL_Surface* src_surface, const SDL_Rect* src_rect, float scale,
|
||||
SDL_ScaleMode scale_mode, const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceTiledWithScale(src_surface, src_rect, scale, scale_mode, *this, dst_rect);
|
||||
}
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceUnchecked
|
||||
*/
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_BlitSurfaceUncheckedScaled
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ClearSurface
|
||||
* @brief Clear the surface to the specified color.
|
||||
* @param r
|
||||
* @param g
|
||||
* @param b
|
||||
* @param a
|
||||
*/
|
||||
bool BlitUncheckedTo(SDL_Surface* dst_surface, const SDL_Rect* dst_rect = nullptr, const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceUnchecked(*this, src_rect, dst_surface, dst_rect);
|
||||
}
|
||||
bool BlitUncheckedFrom(SDL_Surface* src_surface, const SDL_Rect* src_rect = nullptr, const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceUnchecked(src_surface, src_rect, *this, dst_rect);
|
||||
}
|
||||
bool BlitUncheckedScaledTo(SDL_Surface* dst_surface, const SDL_Rect* dst_rect, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* src_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceUncheckedScaled(*this, src_rect, dst_surface, dst_rect, scale_mode);
|
||||
}
|
||||
bool BlitUncheckedScaledFrom(SDL_Surface* src_surface, const SDL_Rect* src_rect, SDL_ScaleMode scale_mode,
|
||||
const SDL_Rect* dst_rect = nullptr) const {
|
||||
return SDL_BlitSurfaceUncheckedScaled(src_surface, src_rect, *this, dst_rect, scale_mode);
|
||||
}
|
||||
void Clear(float r, float g, float b, float a) const { SDL_ClearSurface(*this, r, g, b, a); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_ConvertPixels
|
||||
*/
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_ConvertPixelsAndColorspace
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ConvertSurface
|
||||
* @brief Convert surface to specified pixel format.
|
||||
* @param format The pixel format to convert to.
|
||||
* @return A new Surface instance with the converted surface, or nullptr on failure.
|
||||
*/
|
||||
Surface Convert(SDL_PixelFormat format) const {
|
||||
return get_or_cache(SDL_ConvertSurface(*this, format), SDL_DestroySurface);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ConvertSurfaceAndColorspace
|
||||
* @brief Convert surface to specified pixel format and colorspace.
|
||||
* @param format
|
||||
* @param palette (optional) The palette to use for the converted surface, or NULL to use the palette from the
|
||||
* original surface.
|
||||
* @param colorspace
|
||||
* @param properties (optional) can be 0.
|
||||
* @return A new Surface instance with the converted surface, or nullptr on failure.
|
||||
*/
|
||||
Surface ConvertAndColorspace(SDL_PixelFormat format, SDL_Palette* palette, SDL_Colorspace colorspace,
|
||||
SDL_PropertiesID properties = 0) const {
|
||||
return get_or_cache(
|
||||
@@ -221,7 +105,11 @@ namespace hdk::sdl {
|
||||
static Surface CreateFrom(int w, int h, SDL_PixelFormat format, void* pixels, int pitch) {
|
||||
return get_or_cache(SDL_CreateSurfaceFrom(w, h, format, pixels, pitch), SDL_DestroySurface);
|
||||
}
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_CreateSurfacePalette */
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateSurfacePalette
|
||||
* @brief Create a new surface with a palette.
|
||||
* @returns a new pallet on success or nullptr on failure
|
||||
*/
|
||||
Palette CreatePalette() const;
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_DestroySurface
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_DuplicateSurface
|
||||
@@ -289,8 +177,27 @@ namespace hdk::sdl {
|
||||
* @return The colorspace of the surface.
|
||||
*/
|
||||
SDL_Colorspace GetColorspace() const { return SDL_GetSurfaceColorspace(*this); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_GetSurfaceImages
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceImages
|
||||
* @brief Get the surface's alternative images.
|
||||
* @param count pointer to an int variable to receive the number of alternative images
|
||||
* @return An array of Surface instances representing the surface's alternative images, or nullptr
|
||||
*/
|
||||
SDL_Surface** GetImages(int* count) const { return SDL_GetSurfaceImages(*this, count); }
|
||||
/**
|
||||
* @brief Get the surface's alternative images as a list.
|
||||
* @return A list of Surface instances representing the surface's alternative images.
|
||||
*/
|
||||
std::list<Surface> GetImages() const {
|
||||
int count = 0;
|
||||
SDL_Surface** images = GetImages(&count);
|
||||
std::list<Surface> image_list;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
image_list.emplace_back(get_or_cache(images[i], SDL_DestroySurface));
|
||||
}
|
||||
SDL_free(images);
|
||||
return image_list;
|
||||
}
|
||||
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_GetSurfacePalette
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceProperties
|
||||
|
||||
@@ -1,62 +1,35 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Window.hpp
|
||||
* @brief HDK sdl video header only wrapper for SDL_Window struct & related functions
|
||||
*/
|
||||
/// @file Window.hpp
|
||||
/// For complete documentation, see src/video/Window.cpp
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
/** Windows are the primary interface for rendering and interacting with the user in SDL */
|
||||
namespace hdk::sdl {
|
||||
class Renderer;
|
||||
namespace evt {
|
||||
class EventConduit;
|
||||
}
|
||||
class Window : public hdk::grid::SharedPtrWrapper<SDL_Window> {
|
||||
public:
|
||||
friend class Renderer;
|
||||
friend class evt::EventConduit;
|
||||
friend std::pair<Window, Renderer> CreateWindowAndRenderer(const char* title, int width, int height, SDL_WindowFlags window_flags);
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::SharedPtrWrapper;
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_DestroyWindowSurface
|
||||
*
|
||||
* @param title The title of the window
|
||||
* @param w The width of the window in pixels.
|
||||
* @param h The height of the window in pixels.
|
||||
* @param flags 0, or one or more SDL_WindowFlags OR'd together.
|
||||
* @return A Window instance that manages the created SDL_Window. If window creation fails, the returned Window
|
||||
* will evaluate to false (i.e., it will be null).
|
||||
*/
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::get_or_cache;
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::get_or_view;
|
||||
static Window Create(const char* title, int w, int h, SDL_WindowFlags flags) {
|
||||
return Window(get_or_cache(SDL_CreateWindow(title, w, h, flags), SDL_DestroyWindow));
|
||||
}
|
||||
/** @see SDL_CreateWindowWithProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateWindowWithProperties
|
||||
* @brief Create a window with properties.
|
||||
* @param propertiesID The ID of the properties set to use for the window.
|
||||
* @return Window The created window. If the creation fails, returns an invalid window.
|
||||
*/
|
||||
static Window CreateWithProperties(
|
||||
SDL_PropertiesID propertiesID) {
|
||||
return Window(
|
||||
get_or_cache(SDL_CreateWindowWithProperties(propertiesID), SDL_DestroyWindow));
|
||||
}
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowFromID
|
||||
* @brief Get window for WindowID
|
||||
* @param id The ID of the window.
|
||||
* @return A Window instance that wraps the SDL_Window. If no window with the given ID exists, the returned Window
|
||||
* will evaluate to false (i.e., it will be null).
|
||||
*/
|
||||
static Window GetFromID(SDL_WindowID id) {
|
||||
/** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window
|
||||
* without taking ownership */
|
||||
return Window(get_or_view(SDL_GetWindowFromID(id)));
|
||||
}
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetGrabbedWindow
|
||||
* @brief Get the currently grabbed window, if any.
|
||||
* @return A Window instance that wraps the currently grabbed SDL_Window. If no window is
|
||||
*/
|
||||
static Window GetGrabbed() {
|
||||
/** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window
|
||||
* without taking ownership */
|
||||
@@ -64,138 +37,29 @@ namespace hdk::sdl {
|
||||
}
|
||||
|
||||
public: // Instance Properties
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowAspectRatio
|
||||
* @brief Get the aspect ratio of the window.
|
||||
* @param min_aspect_ratio A pointer to a float that will be filled with the minimum aspect ratio of the window.
|
||||
* @param max_aspect_ratio A pointer to a float that will be filled with the
|
||||
* @return bool True if the aspect ratio was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetAspectRatio(float* min_aspect_ratio, float* max_aspect_ratio) const {
|
||||
return SDL_GetWindowAspectRatio(*this, min_aspect_ratio, max_aspect_ratio);
|
||||
}
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowBordersSize
|
||||
* @brief Get the size of the window borders.
|
||||
* @param top A pointer to an int that will be filled with the size of the top border of the window.
|
||||
* @param left A pointer to an int that will be filled with the size of the left border of the window.
|
||||
* @param bottom A pointer to an int that will be filled with the size of the bottom border of the window.
|
||||
* @param right A pointer to an int that will be filled with the size of the right border of the window.
|
||||
* @return bool True if the border sizes were successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetBordersSize(int* top, int* left, int* bottom, int* right) const {
|
||||
return SDL_GetWindowBordersSize(*this, top, left, bottom, right);
|
||||
}
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowDisplayScale
|
||||
* @brief Get the display scale of the window.
|
||||
* @return float The display scale of the window. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetDisplayScale() const { return SDL_GetWindowDisplayScale(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowFlags
|
||||
* @brief Get the flags of the window.
|
||||
* @return SDL_WindowFlags The flags of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_WindowFlags GetFlags() const { return SDL_GetWindowFlags(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowFullscreenMode
|
||||
* @brief Get the fullscreen mode of the window.
|
||||
* @return const SDL_DisplayMode* A pointer to an SDL_DisplayMode structure that will be filled with the
|
||||
* fullscreen mode of the window. If the window is not in fullscreen mode or is invalid, returns nullptr.
|
||||
*/
|
||||
const SDL_DisplayMode* GetFullscreenMode() const { return SDL_GetWindowFullscreenMode(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowID
|
||||
* @brief Get the ID of the window.
|
||||
* @return SDL_WindowID The ID of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_WindowID GetID() const { return SDL_GetWindowID(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowKeyboardGrab
|
||||
* @brief Get the keyboard grab state of the window.
|
||||
* @return SDL_bool True if the window has grabbed the keyboard, false otherwise.
|
||||
*/
|
||||
bool GetKeyboardGrab() const { return SDL_GetWindowKeyboardGrab(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowKeyboardGrab
|
||||
* @brief Set the keyboard grab state of the window.
|
||||
* @param grabbed True to grab the keyboard, false to release it.
|
||||
* @return bool True if the keyboard grab state was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetKeyboardGrab(bool grabbed) const { return SDL_SetWindowKeyboardGrab(*this, grabbed); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMouseGrab
|
||||
* @brief Get the mouse grab state of the window.
|
||||
* @return SDL_bool True if the window has grabbed the mouse, false otherwise.
|
||||
*/
|
||||
bool GetMouseGrab() const { return SDL_GetWindowMouseGrab(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMouseGrab
|
||||
* @brief Set the mouse grab state of the window.
|
||||
* @param grabbed True to grab the mouse, false to release it.
|
||||
* @return bool True if the mouse grab state was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMouseGrab(bool grabbed) const { return SDL_SetWindowMouseGrab(*this, grabbed); }
|
||||
/** SDL_GetWindowMouseRect
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowMouseRect
|
||||
* @brief Get the mouse rectangle of the window.
|
||||
* @return const SDL_Rect* A pointer to an SDL_Rect structure that will be filled with the mouse rectangle of the
|
||||
* window. If the window is invalid, returns nullptr.
|
||||
*/
|
||||
const SDL_Rect* GetMouseRect() const { return SDL_GetWindowMouseRect(*this); }
|
||||
/** @see SDL_SetWindowMouseRect
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowMouseRect
|
||||
* @brief Set the mouse rectangle of the window.
|
||||
* @param rect A pointer to an SDL_Rect structure that defines the mouse rectangle of the window.
|
||||
* @return bool True if the mouse rectangle was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMouseRect(const SDL_Rect* rect) const { return SDL_SetWindowMouseRect(*this, rect); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMaximumSize
|
||||
* @brief Get the maximum size of the window.
|
||||
* @param w A pointer to an int that will be filled with the maximum width of the window.
|
||||
* @param h A pointer to an int that will be filled with the maximum height of the window.
|
||||
* @return bool True if the maximum size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetMaximumSize(int* w, int* h) const { return SDL_GetWindowMaximumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMaximumSize
|
||||
* @brief Set the maximum size of the window.
|
||||
* @param w The maximum width of the window in pixels.
|
||||
* @param h The maximum height of the window in pixels.
|
||||
* @return bool True if the maximum size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMaximumSize(int w, int h) const { return SDL_SetWindowMaximumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMinimumSize
|
||||
* @brief Get the minimum size of the window.
|
||||
* @param w A pointer to an int that will be filled with the minimum width of the window.
|
||||
* @param h A pointer to an int that will be filled with the minimum height of the window.
|
||||
* @return bool True if the minimum size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetMinimumSize(int* w, int* h) const { return SDL_GetWindowMinimumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMinimumSize
|
||||
* @brief Set the minimum size of the window.
|
||||
* @param w The minimum width of the window in pixels.
|
||||
* @param h The minimum height of the window in pixels.
|
||||
* @return bool True if the minimum size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMinimumSize(int w, int h) const { return SDL_SetWindowMinimumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowSize
|
||||
* @brief Set the size of the window.
|
||||
* @param w The width of the window in pixels.
|
||||
* @param h The height of the window in pixels.
|
||||
* @return bool True if the size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetSize(int w, int h) const { return SDL_SetWindowSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowSize
|
||||
* @brief Get the size of the window.
|
||||
* @param w A pointer to an int that will be filled with the width of the window.
|
||||
* @param h A pointer to an int that will be filled with the height of the window.
|
||||
* @return bool True if the size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetSize(int* w, int* h) const { return SDL_GetWindowSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowSafeArea
|
||||
* @brief Get the safe area of the window.
|
||||
* @param rect A pointer to an SDL_Rect structure that will be filled with the safe area of the window. If the
|
||||
* window is invalid, the rect will be set to {0, 0, 0, 0}.
|
||||
* @return bool True if the safe area was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetSafeArea(SDL_Rect* rect) const { return SDL_GetWindowSafeArea(*this, rect); }
|
||||
/** @see SDL_GetWindowOpacity
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowOpacity
|
||||
* @brief Get the opacity of the window.
|
||||
* @return float The opacity of the window. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetOpacity() const { return SDL_GetWindowOpacity(*this); }
|
||||
/** @see SDL_SetWindowOpacity
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowOpacity
|
||||
|
||||
Reference in New Issue
Block a user