Initial Video, Render, and Properties implementations.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+15
-17
@@ -1,24 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(hdk-sdl
|
||||
VERSION 0.0.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
project(hdk-sdl
|
||||
VERSION 0.0.1
|
||||
LANGUAGES CXX
|
||||
DESCRIPTION "header only shared_ptr wrappers around SDL3 structs and functions"
|
||||
)
|
||||
# hdk-sdl OPTIONS
|
||||
option(HDK_SDL_BUILD_TESTS "Build hdk-sdl tests" OFF)
|
||||
# TODO: Unit testing
|
||||
if(HDK_SDL_BUILD_TESTS)
|
||||
message(WARNING "hdk-sdl tests are not implemented yet.")
|
||||
endif()
|
||||
option(HDK_SDL_BUILD_EXAMPLES "Build hdk-sdl examples" OFF)
|
||||
option(HDK_SDL_BUILD_TESTS "Build hdk-sdl tests" ${HDK_BUILD_TESTS})
|
||||
option(HDK_SDL_BUILD_EXAMPLES "Build hdk-sdl examples" ${HDK_BUILD_EXAMPLES})
|
||||
if(HDK_SDL_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
option(HDK_SDL_BUILD_COVERAGE "Build hdk-sdl with coverage reporting enabled" OFF)
|
||||
if(HDK_SDL_BUILD_COVERAGE)
|
||||
message(WARNING "hdk-sdl coverage testing is not implemented yet.")
|
||||
endif()
|
||||
# TODO: Coverage testing
|
||||
|
||||
# FOR SDL Building
|
||||
set(SDL_TEST OFF CACHE BOOL "Disable SDL tests" FORCE)
|
||||
@@ -28,11 +20,17 @@ set(SDL_INSTALL OFF CACHE BOOL "Disable SDL install" FORCE)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
SDL3
|
||||
GIT_REPOSITORY http://github.com/libsdl-org/SDL.git
|
||||
GIT_TAG release-3.4.0
|
||||
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
|
||||
GIT_TAG release-3.4.4
|
||||
)
|
||||
FetchContent_MakeAvailable(SDL3)
|
||||
|
||||
add_library(hdk-sdl INTERFACE)
|
||||
target_link_libraries(hdk-sdl INTERFACE SDL3::SDL3 hdk-grid)
|
||||
target_include_directories(hdk-sdl INTERFACE ${SDL3_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_compile_features(hdk-sdl INTERFACE cxx_std_17)
|
||||
|
||||
if(HDK_SDL_BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file sdl.hpp
|
||||
* @brief HDK - SDL Frontend API
|
||||
* @brief HDK SDL wrapper main header.
|
||||
**/
|
||||
|
||||
#include <hdk/sdl/video/Window.hpp>
|
||||
// TODO #include <hd/sdl/video/Surface.hpp>
|
||||
// TODO #include <hd/sdl/render/Renderer.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
#include <hdk/sdl/render.hpp>
|
||||
#include <hdk/sdl/video.hpp>
|
||||
@@ -0,0 +1,196 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Properties.hpp
|
||||
* @brief Properties are a set of values represented by a single ID.
|
||||
*/
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include <hdk/grid/PrimitiveWrapper.hpp>
|
||||
/** Many SDL objects have associated properties. */
|
||||
namespace hdk::sdl {
|
||||
class Properties : public grid::PrimitiveWrapper<SDL_PropertiesID> {
|
||||
public:
|
||||
using grid::PrimitiveWrapper<SDL_PropertiesID>::PrimitiveWrapper;
|
||||
|
||||
/** @see SDL_CreateProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateProperties
|
||||
* @brief Creates a new properties set.
|
||||
* @return Properties A new properties set.
|
||||
*/
|
||||
static Properties Create() { return Properties(SDL_CreateProperties()); }
|
||||
/** @see SDL_ClearProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_ClearProperty
|
||||
* @brief Clears a property from a properties set.
|
||||
* @param name
|
||||
* @return bool True on success, false on failure.
|
||||
**/
|
||||
bool ClearProperty(const char* name) const { return SDL_ClearProperty(*this, name); }
|
||||
/** @see SDL_CopyProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CopyProperties
|
||||
* @brief Copies a properties set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool CopyAllTo(SDL_PropertiesID destination) const { return SDL_CopyProperties(*this, destination); }
|
||||
bool CopyAllFrom(SDL_PropertiesID source) { return SDL_CopyProperties(source, *this); }
|
||||
/** @see SDL_DestroyProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_DestroyProperties
|
||||
* @brief Destroys a properties set.
|
||||
*/
|
||||
void Destroy() {
|
||||
SDL_DestroyProperties(*this);
|
||||
*this = 0;
|
||||
}
|
||||
/** @see SDL_EnumerateProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_EnumerateProperties
|
||||
* @brief Enumerates properties in a properties set.
|
||||
* @param callback An `SDL_EnumeratePropertiesCallback` function pointer.
|
||||
* @param callback_data Void pointer that is passed to the callback function.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool EnumerateProperties(SDL_EnumeratePropertiesCallback callback, void* callback_data) const {
|
||||
return SDL_EnumerateProperties(*this, callback, callback_data);
|
||||
}
|
||||
/** @see SDL_GetBooleanProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetBooleanProperty
|
||||
* @brief Gets a boolean property from a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param default_value The default value to return if the property does not exist.
|
||||
* @return bool The value of the property.
|
||||
*/
|
||||
bool GetBooleanProperty(const char* name, bool default_value) const {
|
||||
return SDL_GetBooleanProperty(*this, name, default_value);
|
||||
}
|
||||
/** @see SDL_GetFloatProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetFloatProperty
|
||||
* @brief Gets a float property from a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param default_value The default value to return if the property does not exist.
|
||||
* @return float The value of the property.
|
||||
*/
|
||||
float GetFloatProperty(const char* name, float default_value) const {
|
||||
return SDL_GetFloatProperty(*this, name, default_value);
|
||||
}
|
||||
/** @see SDL_GetGlobalProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetGlobalProperties
|
||||
* @brief Gets the global properties set.
|
||||
* @return SDL_PropertiesID The global properties set.
|
||||
*/
|
||||
static Properties GetGlobalProperties() { return Properties(SDL_GetGlobalProperties()); }
|
||||
/** @see SDL_GetNumberProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetNumberProperty
|
||||
* @brief Gets a number property from a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param default_value The default value to return if the property does not exist.
|
||||
* @return double The value of the property.
|
||||
*/
|
||||
double GetNumberProperty(const char* name, double default_value) const {
|
||||
return SDL_GetNumberProperty(*this, name, default_value);
|
||||
}
|
||||
/** @see SDL_GetPointerProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetPointerProperty
|
||||
* @brief Gets a pointer property from a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param default_value The default value to return if the property does not exist.
|
||||
* @return void* The value of the property.
|
||||
*/
|
||||
void* GetPointerProperty(const char* name, void* default_value) const {
|
||||
return SDL_GetPointerProperty(*this, name, default_value);
|
||||
}
|
||||
|
||||
/** @see SDL_GetPropertyType
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetPropertyType
|
||||
* @brief Gets the type of a property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @return SDL_PropertyType The type of the property.
|
||||
*/
|
||||
SDL_PropertyType GetPropertyType(const char* name) const { return SDL_GetPropertyType(*this, name); }
|
||||
/** @see SDL_GetStringProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetStringProperty
|
||||
* @brief Gets a string property from a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param default_value The default value to return if the property does not exist.
|
||||
* @return const char* The value of the property.
|
||||
*/
|
||||
const char* GetStringProperty(const char* name, const char* default_value) const {
|
||||
return SDL_GetStringProperty(*this, name, default_value);
|
||||
}
|
||||
/** @see SDL_HasProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_HasProperty
|
||||
* @brief Checks if a property exists in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @return bool True if the property exists, false otherwise.
|
||||
*/
|
||||
bool HasProperty(const char* name) const { return SDL_HasProperty(*this, name); }
|
||||
/** @see SDL_LockProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_LockProperties
|
||||
* @brief Locks a properties set for writing.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool LockProperties() { return SDL_LockProperties(*this); }
|
||||
/** @see SDL_SetBooleanProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetBooleanProperty
|
||||
* @brief Sets a boolean property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetBooleanProperty(const char* name, bool value) { return SDL_SetBooleanProperty(*this, name, value); }
|
||||
// SDL_SetFloatProperty
|
||||
/** @see SDL_SetFloatProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetFloatProperty
|
||||
* @brief Sets a float property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetFloatProperty(const char* name, float value) { return SDL_SetFloatProperty(*this, name, value); }
|
||||
// SDL_SetNumberProperty
|
||||
/** @see SDL_SetNumberProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetNumberProperty
|
||||
* @brief Sets a number property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetNumberProperty(const char* name, double value) { return SDL_SetNumberProperty(*this, name, value); }
|
||||
// SDL_SetPointerProperty
|
||||
/** @see SDL_SetPointerProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetPointerProperty
|
||||
* @brief Sets a pointer property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetPointerProperty(const char* name, void* value) { return SDL_SetPointerProperty(*this, name, value); }
|
||||
// SDL_SetPointerPropertyWithCleanup
|
||||
/** @see SDL_SetPointerPropertyWithCleanup
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetPointerPropertyWithCleanup
|
||||
* @brief Sets a pointer property in a properties set with a cleanup callback.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @param cleanup_callback An `SDL_CleanupPropertyCallback` function pointer that is called when the property is cleared or the properties set is destroyed.
|
||||
* @param userdata Void pointer that is passed to cleanup_callback.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetPointerPropertyWithCleanup(const char* name,
|
||||
void* value,
|
||||
SDL_CleanupPropertyCallback cleanup_callback,
|
||||
void* userdata = nullptr) {
|
||||
return SDL_SetPointerPropertyWithCleanup(*this, name, value, cleanup_callback, userdata);
|
||||
}
|
||||
// SDL_SetStringProperty
|
||||
/** @see SDL_SetStringProperty
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetStringProperty
|
||||
* @brief Sets a string property in a properties set.
|
||||
* @param name The name of the property.
|
||||
* @param value The value to set.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
bool SetStringProperty(const char* name, const char* value) { return SDL_SetStringProperty(*this, name, value); }
|
||||
// SDL_UnlockProperties
|
||||
/** @see SDL_UnlockProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_UnlockProperties
|
||||
* @brief Unlocks a properties set after writing.
|
||||
*/
|
||||
void UnlockProperties() { SDL_UnlockProperties(*this); }
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Renderer_Texture.hpp
|
||||
* @brief HDK sdl Renderer subsystem. Glues together Texture & Renderer which have circular dependencies
|
||||
*/
|
||||
#include <hdk/sdl/render/Renderer.hpp>
|
||||
#include <hdk/sdl/render/Texture.hpp>
|
||||
|
||||
namespace hdk::sdl {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,551 @@
|
||||
#pragma once
|
||||
/** @file Renderer.hpp
|
||||
* @brief HDK sdl video header only wrapper for SDL_Renderer struct & related functions
|
||||
*/
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
/** Renderers are used to render 2D graphics in SDL */
|
||||
namespace hdk::sdl {
|
||||
class Window;
|
||||
/**
|
||||
* @brief Wraps the SDL_Renderer struct and related functions in a C++ class that uses shared_ptr for lifetime management.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Renderer : public hdk::grid::SharedPtrWrapper<SDL_Renderer> {
|
||||
public:
|
||||
friend class Window;
|
||||
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_Renderer>::SharedPtrWrapper;
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_AddVulkanRenderSemaphores
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_ConvertEventToRenderCoordinates
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_CreateGPURenderer
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_CreateGPURenderState
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateRenderer
|
||||
* @brief Create a renderer for a window.
|
||||
* @param window The window to create the renderer for. If the window is invalid, this function will return an
|
||||
* invalid renderer.
|
||||
* @param driverName The name of the rendering driver to initialize. If NULL, the first is used.
|
||||
* @return Renderer The created renderer. If the creation fails, returns an invalid renderer.
|
||||
*/
|
||||
static Renderer Create(SDL_Window* window, const char* driverName) {
|
||||
return Renderer(get_or_cache(SDL_CreateRenderer(window, driverName), SDL_DestroyRenderer));
|
||||
}
|
||||
// SDL_CreateRendererWithProperties
|
||||
// https://wiki.libsdl.org/SDL3/SDL_CreateSoftwareRenderer
|
||||
static Renderer CreateSoftware(SDL_Surface* surface) {
|
||||
return Renderer(get_or_cache(SDL_CreateSoftwareRenderer(surface), SDL_DestroyRenderer));
|
||||
}
|
||||
// https://wiki.libsdl.org/SDL3/SDL_CreateWindowAndRenderer
|
||||
// https://wiki.libsdl.org/SDL3/SDL_DestroyGPURenderState
|
||||
// https://wiki.libsdl.org/SDL3/SDL_DestroyRenderer
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_FlushRenderer
|
||||
* @brief Flush the current rendering commands to the screen.
|
||||
* @return bool True if the renderer was successfully flushed, false otherwise.
|
||||
*/
|
||||
bool Flush() const { return SDL_FlushRenderer(*this); }
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GDKResumeRenderer
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GDKSuspendRenderer
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetCurrentRenderOutputSize
|
||||
* @brief Get the output size in pixels of the current render target.
|
||||
* @param w A pointer to an int to be filled in with the width of the render output. If the renderer is invalid,
|
||||
* this will be set to 0.
|
||||
* @param h A pointer to an int to be filled in with the height of the render output. If the renderer is invalid,
|
||||
* this will be set to 0.
|
||||
* @return bool True if the output size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetOutputSize(int* w, int* h) const { return SDL_GetRenderOutputSize(*this, w, h); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetDefaultTextureScaleMode
|
||||
* @brief Get the default texture scale mode for the renderer.
|
||||
* @param scaleMode A pointer to an SDL_ScaleMode variable to be filled in with the default texture scale mode for
|
||||
* the renderer. If the renderer is invalid, this will be set to SDL_ScaleMode_None.
|
||||
* @return bool True if the default texture scale mode was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetDefaultTextureScaleMode(SDL_ScaleMode* scaleMode) const {
|
||||
return SDL_GetDefaultTextureScaleMode(*this, scaleMode);
|
||||
}
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GetGPURendererDevice
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GetNumRenderDrivers
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderClipRect
|
||||
* @brief Get the clip rectangle for the current rendering target.
|
||||
* @param rect A pointer to an SDL_Rect structure to be filled in with the clip rectangle for the current
|
||||
* rendering target. If the renderer is invalid, this will be set to {0, 0, 0, 0}.
|
||||
* @return bool True if the clip rectangle was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetClipRect(SDL_Rect* rect) const { return SDL_GetRenderClipRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderColorScale
|
||||
* @brief Get the color scale for the renderer.
|
||||
* @param scale A pointer to a float to be filled in with the color scale for the renderer. If the renderer is
|
||||
* invalid, this will be set to 0.0f.
|
||||
* @return bool True if the color scale was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetColorScale(float* scale) const { return SDL_GetRenderColorScale(*this, scale); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderDrawBlendMode
|
||||
* @brief Get the blend mode used for drawing operations (Fill and Line).
|
||||
* @param blendMode A pointer to an SDL_BlendMode variable to be filled in with the blend mode used for drawing
|
||||
* operations. If the renderer is invalid, this will be set to SDL_BlendMode_None.
|
||||
* @return bool True if the blend mode was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetDrawBlendMode(SDL_BlendMode* blendMode) const { return SDL_GetRenderDrawBlendMode(*this, blendMode); }
|
||||
/* @see https://wiki.libsdl.org/SDL3/SDL_GetRenderDrawColor
|
||||
* @brief Get the color used for drawing operations (Fill and Line).
|
||||
* @param r A pointer to a Uint8 to be filled in with the red component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.
|
||||
* @param g A pointer to a Uint8 to be filled in with the green component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.
|
||||
* @param b A pointer to a Uint8 to be filled in with the blue component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.
|
||||
* @param a A pointer to a Uint8 to be filled in with the alpha component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.
|
||||
* @return bool True if the drawing color was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetDrawColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const {
|
||||
return SDL_GetRenderDrawColor(*this, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderDrawColorFloat
|
||||
* @brief Get the color used for drawing operations (Fill and Line) as floats.
|
||||
* @param r A pointer to a float to be filled in with the red component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.0f.
|
||||
* @param g A pointer to a float to be filled in with the green component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.0f.
|
||||
* @param b A pointer to a float to be filled in with the blue component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.0f.
|
||||
* @param a A pointer to a float to be filled in with the alpha component of the drawing color. If the renderer is
|
||||
* invalid, this will be set to 0.0f.
|
||||
* @return bool True if the drawing color was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetDrawColorFloat(float* r, float* g, float* b, float* a) const {
|
||||
return SDL_GetRenderDrawColorFloat(*this, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderDriver
|
||||
* @brief Get the name of a renderer driver specified by an index.
|
||||
* @param index The index of display driver to query, starting at 0.
|
||||
* @return const char* driver name string
|
||||
*/
|
||||
static const char* GetDriver(int index) { return SDL_GetRenderDriver(index); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderer
|
||||
* @brief Get the renderer associated with a window.
|
||||
* @param window The window to query
|
||||
* @return Renderer The renderer associated with the window
|
||||
*/
|
||||
static Renderer Get(SDL_Window* window) {
|
||||
/** we may not have created the renderer we get back, if not we will not own it. */
|
||||
return Renderer(get_or_view(SDL_GetRenderer(window)));
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRendererFromTexture
|
||||
* @brief Get the renderer associated with a texture.
|
||||
* @param texture The texture to query
|
||||
* @return Renderer The renderer associated with the texture
|
||||
*/
|
||||
static Renderer GetFromTexture(SDL_Texture* texture) {
|
||||
/** we may not have created the renderer we get back, if not we will not own it. */
|
||||
return Renderer(get_or_view(SDL_GetRendererFromTexture(texture)));
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRendererName
|
||||
* @brief Get the name of a renderer.
|
||||
* @return const char* The name of the renderer
|
||||
*/
|
||||
const char* GetName() const { return SDL_GetRendererName(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRendererProperties
|
||||
* @brief Get the properties of a renderer.
|
||||
* @returns Properties associated with the renderer.
|
||||
*/
|
||||
Properties GetProperties() const { return Properties(SDL_GetRendererProperties(*this)); }
|
||||
/** @see https://wiki.libsdl.org/SDL_GetRenderLogicalPresentation
|
||||
* @brief device independent resolution and presentation mode
|
||||
* @param w pointer to store width
|
||||
* @param h pointer to store height
|
||||
* @param mode sdl enum value to store presentation mode
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetLogicalPresentation(int* w, int* h, SDL_RendererLogicalPresentation* mode) const {
|
||||
return SDL_GetRenderLogicalPresentation(*this, w, h, mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderLogicalPresentationRect
|
||||
* @brief Get the logical presentation rectangle of a renderer.
|
||||
* @param rect pointer to store the logical presentation rectangle
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetLogicalPresentationRect(SDL_FRect* rect) const {
|
||||
return SDL_GetRenderLogicalPresentationRect(*this, rect);
|
||||
}
|
||||
/**
|
||||
* @todo https://wiki.libsdl.org/SDL3/SDL_GetRenderMetalCommandEncoder
|
||||
* @todo https://wiki.libsdl.org/SDL3/SDL_GetRenderMetalLayer
|
||||
*/
|
||||
bool GetSafeArea(SDL_Rect* rect) const { return SDL_GetRenderSafeArea(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderScale
|
||||
* @brief Get the scale of the current render target.
|
||||
* @param scaleX A pointer to a float to be filled in with the horizontal scale factor.
|
||||
* @param scaleY A pointer to a float to be filled in with the vertical scale factor.
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool GetScale(float* scaleX, float* scaleY) const { return SDL_GetRenderScale(*this, scaleX, scaleY); }
|
||||
/**
|
||||
@todo https://wiki.libsdl.org/SDL3/SDL_GetRenderTarget
|
||||
**/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderTextureAddressMode
|
||||
* @brief Get the texture address mode for the current render target.
|
||||
* @param u_mode A pointer to an SDL_TextureAddressMode variable
|
||||
* @param v_mode A pointer to an SDL_TextureAddressMode variable
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool GetTextureAddressMode(SDL_TextureAddressMode* u_mode, SDL_TextureAddressMode* v_mode) const {
|
||||
return SDL_GetRenderTextureAddressMode(*this, u_mode, v_mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderViewport
|
||||
* @brief Get the viewport for the current render target.
|
||||
* @param rect A pointer to an SDL_Rect structure to be filled in with the viewport
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool GetViewport(SDL_Rect* rect) const { return SDL_GetRenderViewport(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderVSync
|
||||
* @brief Get the vertical sync setting for the current renderer.
|
||||
* @param vsync A pointer to an int to store the vertical sync setting
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool GetVSync(int* vsync) const { return SDL_GetRenderVSync(*this, vsync); }
|
||||
/**
|
||||
@todo https://wiki.libsdl.org/SDL3/SDL_GetRenderWindow
|
||||
**/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderClear
|
||||
* @brief Clear the current rendering target with the drawing color.
|
||||
* @return bool True if the renderer was successfully cleared, false otherwise.
|
||||
*/
|
||||
bool Clear() const { return SDL_RenderClear(*this); }
|
||||
//
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderClipEnabled
|
||||
* @brief Check whether clipping is enabled for the current render target.
|
||||
* @return bool True if clipping is enabled, false otherwise.
|
||||
*/
|
||||
// https://wiki.libsdl.org/SDL3/SDL_RenderCoordinatesFromWindow
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderCoordinatesFromWindow
|
||||
* @brief Convert window coordinates to renderer coordinates.
|
||||
* @param windowX The x coordinate in window space
|
||||
* @param windowY The y coordinate in window space
|
||||
* @param rendererX A pointer to a float to be filled in with the x coordinate
|
||||
* @param rendererY A pointer to a float to be filled in with the y coordinate
|
||||
* @return bool True if the coordinates were successfully converted, false otherwise.
|
||||
*/
|
||||
bool CoordinatesFromWindow(float windowX, float windowY, float* rendererX, float* rendererY) const {
|
||||
return SDL_RenderCoordinatesFromWindow(*this, windowX, windowY, rendererX, rendererY);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderCoordinatesToWindow
|
||||
* @brief Convert renderer coordinates to window coordinates.
|
||||
* @param rendererX The x coordinate in renderer space
|
||||
* @param rendererY The y coordinate in renderer space
|
||||
* @param windowX A pointer to a float to be filled in with the x coordinate
|
||||
* @param windowY A pointer to a float to be filled in with the y coordinate
|
||||
* @return bool True if the coordinates were successfully converted, false otherwise.
|
||||
*/
|
||||
bool CoordinatesToWindow(float rendererX, float rendererY, float* windowX, float* windowY) const {
|
||||
return SDL_RenderCoordinatesToWindow(*this, rendererX, rendererY, windowX, windowY);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderDebugText
|
||||
* @brief Render debug text at a specific position in the current render target.
|
||||
* @param x The x coordinate of the text position
|
||||
* @param y The y coordinate of the text position
|
||||
* @param text The text to render
|
||||
* @return bool True if the text was successfully rendered, false otherwise.
|
||||
*/
|
||||
bool DebugText(float x, float y, const char* text) const { return SDL_RenderDebugText(*this, x, y, text); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderDebugTextFormat
|
||||
* @brief Render formatted debug text at a specific position in the current render target.
|
||||
* @param x The x coordinate of the text position
|
||||
* @param y The y coordinate of the text position
|
||||
* @param fmt The formatted text to render (printf-style format string)
|
||||
* @param args The arguments for the formatted text
|
||||
* @return bool True if the text was successfully rendered, false otherwise.
|
||||
*/
|
||||
template <typename... Args> bool DebugTextFormat(float x, float y, const char* fmt, Args... args) const {
|
||||
return SDL_RenderDebugTextFormat(*this, x, y, fmt, args...);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderFillRect
|
||||
* @brief fill rectangle with current draw color
|
||||
* @param rect pointer to rectangle to fill, or NULL to fill the entire render target
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool FillRect(const SDL_FRect* rect) const { return SDL_RenderFillRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderFillRects
|
||||
* @brief fill multiple rectangles with current draw color
|
||||
* @param rects pointer to array of rectangles to fill
|
||||
* @param count number of rectangles in the array
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool FillRects(const SDL_FRect* rects, int count) const { return SDL_RenderFillRects(*this, rects, count); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderGeometry
|
||||
* @brief Render geometry with the current render target
|
||||
* @param texture The texture to use for rendering
|
||||
* @param vertices Pointer to an array of vertices
|
||||
* @param numVertices Number of vertices in the array
|
||||
* @param indices Pointer to an array of indices
|
||||
* @param numIndices Number of indices in the array
|
||||
* @return bool True on success, false on failure
|
||||
*/
|
||||
bool RenderGeometry(
|
||||
SDL_Texture* texture, const SDL_Vertex* vertices, int numVertices, const int* indices, int numIndices) const {
|
||||
return SDL_RenderGeometry(*this, texture, vertices, numVertices, indices, numIndices);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderGeometryRaw
|
||||
* @brief render a list of triangles with optional texture and index data
|
||||
* @param texture The texture to use for rendering, or NULL for no texture
|
||||
* @param xy Pointer to an array of 2D vertex positions (x, y) in normalized coordinates (0.0 to 1.0)
|
||||
* @param xy_stride The byte stride between consecutive vertex positions in the xy array
|
||||
* @param color Pointer to an array of vertex colors
|
||||
* @param color_stride The byte stride between consecutive vertex colors in the color array
|
||||
* @param uv Pointer to an array of texture coordinates (u, v) in normalized coordinates (0.0 to 1.0), or NULL if
|
||||
* not using textures
|
||||
* @param uv_stride The byte stride between consecutive texture coordinates in the uv array
|
||||
* @param numVertices The number of vertices in the xy, color, and uv arrays
|
||||
* @param indices Pointer to an array of vertex indices that define the triangles to render, or NULL to render the
|
||||
* vertices in sequential order
|
||||
* @param numIndices The number of indices
|
||||
* @param sizeIndices The byte size of each index in the indices array (1, 2, or 4 bytes)
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool RenderGeometryRaw(SDL_Texture* texture, const float* xy, int xy_stride, const SDL_FColor* color,
|
||||
int color_stride, const float* uv, int uv_stride, int numVertices, const void* indices, int numIndices,
|
||||
int sizeIndices) const {
|
||||
return SDL_RenderGeometryRaw(*this, texture, xy, xy_stride, color, color_stride, uv, uv_stride, numVertices,
|
||||
indices, numIndices, sizeIndices);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderLine
|
||||
* @brief render line with current draw color
|
||||
* @param x1
|
||||
* @param y1
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderLine(float x1, float y1, float x2, float y2) const { return SDL_RenderLine(*this, x1, y1, x2, y2); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderLines
|
||||
* @brief render multiple lines with current draw color
|
||||
* @param points
|
||||
* @param count number of points in the array
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderLines(const SDL_FPoint* points, int count) const { return SDL_RenderLines(*this, points, count); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderPoint
|
||||
* @brief render point with current draw color
|
||||
* @param x
|
||||
* @param y
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderPoint(float x, float y) const { return SDL_RenderPoint(*this, x, y); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderPoints
|
||||
* @brief render multiple points with current draw color
|
||||
* @param points
|
||||
* @param count number of points in the array
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderPoints(const SDL_FPoint* points, int count) const { return SDL_RenderPoints(*this, points, count); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderPresent
|
||||
* @brief Update the screen with any rendering performed since the previous call.
|
||||
* @return bool True if the screen was successfully updated, false otherwise.
|
||||
*/
|
||||
bool Present() const { return SDL_RenderPresent(*this); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_RenderReadPixels */
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderRect
|
||||
* @brief render rectangle outline with current draw color
|
||||
* @param rect pointer to rectangle to outline, or NULL to outline the entire render target
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderRect(const SDL_FRect* rect) const { return SDL_RenderRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderRects
|
||||
* @brief render multiple rectangle outlines with current draw color
|
||||
* @param rects pointer to array of rectangles to outline
|
||||
* @param count number of rectangles in the array
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderRects(const SDL_FRect* rects, int count) const { return SDL_RenderRects(*this, rects, count); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTexture
|
||||
* @brief Render texture
|
||||
* @param texture
|
||||
* @param src
|
||||
* @param dst
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTexture(SDL_Texture* texture, const SDL_FRect* src, const SDL_FRect* dst) const {
|
||||
return SDL_RenderTexture(*this, texture, src, dst);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTexture9Grid
|
||||
* @brief Render a texture with 9-grid scaling
|
||||
* @param texture
|
||||
* @param src
|
||||
* @param left_width
|
||||
* @param right_width
|
||||
* @param top_height
|
||||
* @param bottom_height
|
||||
* @param scale
|
||||
* @param dst
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTexture9Grid(SDL_Texture* texture, const SDL_FRect* src, float left_width, float right_width,
|
||||
float top_height, float bottom_height, float scale, const SDL_FRect* dst) const {
|
||||
return SDL_RenderTexture9Grid(
|
||||
*this, texture, src, left_width, right_width, top_height, bottom_height, scale, dst);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTexture9GridTiled
|
||||
* @brief Render a texture with 9-grid scaling and tiling
|
||||
* @param texture
|
||||
* @param src
|
||||
* @param left_width
|
||||
* @param right_width
|
||||
* @param top_height
|
||||
* @param bottom_height
|
||||
* @param scale
|
||||
* @param dst
|
||||
* @param tile_scale
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTexture9GridTiled(SDL_Texture* texture, const SDL_FRect* src, float left_width, float right_width,
|
||||
float top_height, float bottom_height, float scale, const SDL_FRect* dst, float tile_scale) const {
|
||||
return SDL_RenderTexture9GridTiled(
|
||||
*this, texture, src, left_width, right_width, top_height, bottom_height, scale, dst, tile_scale);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTextureAffine
|
||||
* @brief Render a texture with affine transformations
|
||||
* @param texture
|
||||
* @param src
|
||||
* @param origin
|
||||
* @param right
|
||||
* @param down
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTextureAffine(SDL_Texture* texture, const SDL_FRect* src, const SDL_FPoint* origin,
|
||||
const SDL_FPoint* right, const SDL_FPoint* down) const {
|
||||
return SDL_RenderTextureAffine(*this, texture, src, origin, right, down);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTextureRotated
|
||||
* @brief Render a texture with rotation and flipping
|
||||
* @param texture
|
||||
* @param srcrect
|
||||
* @param dstrect
|
||||
* @param angle
|
||||
* @param center
|
||||
* @param flip
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTextureRotated(SDL_Texture* texture, const SDL_FRect* srcrect, const SDL_FRect* dstrect, double angle,
|
||||
const SDL_FPoint* center, SDL_FlipMode flip) const {
|
||||
return SDL_RenderTextureRotated(*this, texture, srcrect, dstrect, angle, center, flip);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RenderTextureTiled
|
||||
* @brief Render a texture with tiling
|
||||
* @param texture
|
||||
* @param srcrect
|
||||
* @param scale
|
||||
* @param dstrect
|
||||
* @param tile_scale
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool RenderTextureTiled(
|
||||
SDL_Texture* texture, const SDL_FRect* srcrect, float scale, const SDL_FRect* dstrect, float tile_scale) const {
|
||||
return SDL_RenderTextureTiled(*this, texture, srcrect, scale, dstrect);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetDefaultTextureScaleMode
|
||||
* @brief Set the default texture scale mode for the renderer.
|
||||
* @param scaleMode The default texture scale mode for the renderer.
|
||||
* @return bool True if the default texture scale mode was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetDefaultTextureScaleMode(SDL_ScaleMode scaleMode) const {
|
||||
return SDL_SetDefaultTextureScaleMode(*this, scaleMode);
|
||||
}
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_SetGPURenderState
|
||||
// https://wiki.libsdl.org/SDL3/SDL_SetGPURenderStateFragmentUniforms
|
||||
// https://wiki.libsdl.org/SDL3/SDL_SetGPURenderStateSamplerBindings
|
||||
// https://wiki.libsdl.org/SDL3/SDL_SetGPURenderStateStorageBuffers
|
||||
// https://wiki.libsdl.org/SDL3/SDL_SetGPURenderStateStorageTextures
|
||||
**/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderClipRect
|
||||
* @brief Set the clip rectangle for the current rendering target.
|
||||
* @param rect
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetClipRect(const SDL_Rect* rect) const { return SDL_SetRenderClipRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderColorScale
|
||||
* @brief Set the color scale for the renderer.
|
||||
* @param scale The color scale for the renderer.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetRenderColorScale(float scale) const { return SDL_SetRenderColorScale(*this, scale); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderDrawBlendMode
|
||||
* @brief Set the blend mode used for drawing operations (Fill and Line).
|
||||
* @param blendMode The blend mode used for drawing operations.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetDrawBlendMode(SDL_BlendMode blendMode) const { return SDL_SetRenderDrawBlendMode(*this, blendMode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderDrawColor
|
||||
* @brief Set the color used for drawing operations (Fill and Line).
|
||||
* @param r The red component of the drawing color
|
||||
* @param g The green component of the drawing color
|
||||
* @param b The blue component of the drawing color
|
||||
* @param a The alpha component of the drawing color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const {
|
||||
return SDL_SetRenderDrawColor(*this, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderDrawColorFloat
|
||||
* @brief Set the color used for drawing operations (Fill and Line) as floats.
|
||||
* @param r The red component of the drawing color
|
||||
* @param g The green component of the drawing color
|
||||
* @param b The blue component of the drawing color
|
||||
* @param a The alpha component of the drawing color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetDrawColorFloat(float r, float g, float b, float a) const {
|
||||
return SDL_SetRenderDrawColorFloat(*this, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderLogicalPresentation
|
||||
* @brief Set the logical presentation for the renderer.
|
||||
* @param w The width of the logical presentation
|
||||
* @param h The height of the logical presentation
|
||||
* @param mode The presentation mode for the logical presentation
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetLogicalPresentation(int w, int h, SDL_RendererLogicalPresentation mode) const {
|
||||
return SDL_SetRenderLogicalPresentation(*this, w, h, mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderScale
|
||||
* @brief Set the scale for the current render target.
|
||||
* @param scaleX The horizontal scale factor
|
||||
* @param scaleY The vertical scale factor
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetScale(float scaleX, float scaleY) const { return SDL_SetRenderScale(*this, scaleX, scaleY); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderTarget
|
||||
* @brief Set the render target to a texture or the default render target.
|
||||
* @param texture The texture to set as the render target, or NULL to set the default render target
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetRenderTarget(SDL_Texture* texture) const { return SDL_SetRenderTarget(*this, texture); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderTextureAddressMode
|
||||
* @brief Set the texture address mode for the current render target.
|
||||
* @param u_mode The texture address mode for the horizontal direction
|
||||
* @param v_mode The texture address mode for the vertical direction
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetTextureAddressMode(SDL_TextureAddressMode u_mode, SDL_TextureAddressMode v_mode) const {
|
||||
return SDL_SetRenderTextureAddressMode(*this, u_mode, v_mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderViewport
|
||||
* @brief Set the viewport for the current render target.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the viewport, or NULL to use the entire render
|
||||
* target.
|
||||
* @return bool True if the viewport was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetViewport(const SDL_Rect* rect) const { return SDL_SetRenderViewport(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetRenderVSync
|
||||
* @brief Set the vertical sync setting for the current renderer.
|
||||
* @param vsync The vertical sync setting to use (0 for no vsync, 1 for vsync, -1 for adaptive vsync)
|
||||
* @return bool True on success, false on failure
|
||||
*/
|
||||
bool SetVSync(int vsync) const { return SDL_SetRenderVSync(*this, vsync); }
|
||||
/// Forward declare: implemented in ../video.hpp to avoid circular dependency
|
||||
Window GetWindow() const;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
#pragma once
|
||||
/** @file Texture.hpp
|
||||
* @brief HDK sdl video header only wrapper for SDL_Texture struct & related functions
|
||||
*/
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
/** Textures are used to store pixel data that can be rendered by a renderer. */
|
||||
namespace hdk::sdl {
|
||||
/** */
|
||||
class Texture : public hdk::grid::SharedPtrWrapper<SDL_Texture> {
|
||||
public:
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Texture>::SharedPtrWrapper;
|
||||
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateTexture
|
||||
* @brief Create a texture for a rendering context.
|
||||
* @param renderer The rendering context to create the texture for.
|
||||
* @param format The pixel format of the texture
|
||||
* @param access The access pattern for the texture
|
||||
* @param w The width of the texture in pixels
|
||||
* @param h The height of the texture in pixels
|
||||
* @return Texture The created texture. If the creation fails, returns an invalid texture.
|
||||
*/
|
||||
static Texture Create(SDL_Renderer* renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h) {
|
||||
return Texture(get_or_cache(SDL_CreateTexture(renderer, format, access, w, h), SDL_DestroyTexture));
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateTextureFromSurface
|
||||
* @brief Create a texture from an existing surface.
|
||||
* @param renderer The rendering context to create the texture for.
|
||||
* @param surface The surface to create the texture from.
|
||||
* @return Texture The created texture. If the creation fails, returns an invalid texture.
|
||||
*/
|
||||
static Texture CreateFromSurface(SDL_Renderer* renderer, SDL_Surface* surface) {
|
||||
return Texture(get_or_cache(SDL_CreateTextureFromSurface(renderer, surface), SDL_DestroyTexture));
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateTextureWithProperties
|
||||
* @brief Create a texture for a rendering context with specific properties.
|
||||
* @param renderer The rendering context to create the texture for.
|
||||
* @param properties The properties to create the texture with.
|
||||
* @return Texture The created texture. If the creation fails, returns an invalid texture.
|
||||
*/
|
||||
static Texture CreateWithProperties(SDL_Renderer* renderer, SDL_PropertiesID properties) {
|
||||
return Texture(get_or_cache(SDL_CreateTextureWithProperties(renderer, properties), SDL_DestroyTexture));
|
||||
}
|
||||
// https://wiki.libsdl.org/SDL3/SDL_DestroyTexture
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureAlphaMod
|
||||
* @brief Get the alpha modulation value for a texture.
|
||||
* @param alpha A pointer to an int
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetAlphaMod(Uint8* alpha) const { return SDL_GetTextureAlphaMod(*this, alpha); }
|
||||
Uint8 GetAlphaMod() const {
|
||||
Uint8 alpha;
|
||||
SDL_GetTextureAlphaMod(*this, &alpha);
|
||||
return alpha;
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureAlphaModFloat
|
||||
* @brief Get the alpha modulation value for a texture as a float.
|
||||
* @param alpha A pointer to a float
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetAlphaModFloat(float* alpha) const { return SDL_GetTextureAlphaModFloat(*this, alpha); }
|
||||
float GetAlphaModFloat() const {
|
||||
float alpha;
|
||||
SDL_GetTextureAlphaModFloat(*this, &alpha);
|
||||
return alpha;
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureBlendMode
|
||||
* @brief Get the blend mode for a texture.
|
||||
* @param blendMode A pointer to an SDL_BlendMode variable to be filled in
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetBlendMode(SDL_BlendMode* blendMode) const { return SDL_GetTextureBlendMode(*this, blendMode); }
|
||||
SDL_BlendMode GetBlendMode() const {
|
||||
SDL_BlendMode blendMode;
|
||||
SDL_GetTextureBlendMode(*this, &blendMode);
|
||||
return blendMode;
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureColorMod
|
||||
* @brief Get the color modulation values for a texture.
|
||||
* @param r A pointer to a Uint8 to be filled in with the red color
|
||||
* @param g A pointer to a Uint8 to be filled in with the green color
|
||||
* @param b A pointer to a Uint8 to be filled in with the blue color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetColorMod(Uint8* r, Uint8* g, Uint8* b) const { return SDL_GetTextureColorMod(*this, r, g, b); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureColorModFloat
|
||||
* @brief Get the color modulation values for a texture as floats.
|
||||
* @param r A pointer to a float to be filled in with the red color
|
||||
* @param g A pointer to a float to be filled in with the green color
|
||||
* @param b A pointer to a float to be filled in with the blue color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetColorModFloat(float* r, float* g, float* b) const { return SDL_GetTextureColorModFloat(*this, r, g, b); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_GetTexturePalette **/
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetTextureProperties
|
||||
* @brief Get the properties of a texture.
|
||||
* @returns Properties associated with the texture.
|
||||
*/
|
||||
Properties GetProperties() const { return Properties(SDL_GetTextureProperties(*this)); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureScaleMode
|
||||
* @brief Get the scale mode for a texture.
|
||||
* @param scaleMode A pointer to an SDL_ScaleMode variable to be filled in
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetScaleMode(SDL_ScaleMode* scaleMode) const { return SDL_GetTextureScaleMode(*this, scaleMode); }
|
||||
SDL_ScaleMode GetScaleMode() const {
|
||||
SDL_ScaleMode scaleMode;
|
||||
SDL_GetTextureScaleMode(*this, &scaleMode);
|
||||
return scaleMode;
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureSize
|
||||
* @brief Get the size of a texture.
|
||||
* @param w A pointer to a float to be filled in with the width
|
||||
* @param h A pointer to a float to be filled in with the height
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetSize(float* w, float* h) const { return SDL_GetTextureSize(*this, w, h); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LockTexture
|
||||
* @brief Lock a portion of the texture for write-only pixel access.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the area to lock, or NULL to lock the entire
|
||||
* texture.
|
||||
* @param pixels A pointer to a void* to be filled in with the locked pixels. You can cast this to the appropriate
|
||||
* type based on the texture's pixel format.
|
||||
* @param pitch A pointer to an int to be filled in with the pitch of the locked pixels (the length of a row of
|
||||
* pixels in bytes).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Lock(const SDL_Rect* rect, void** pixels, int* pitch) const {
|
||||
return SDL_LockTexture(*this, rect, pixels, pitch);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LockTextureToSurface
|
||||
* @brief Lock a portion of the texture for write-only pixel access and create an SDL_Surface that can be used to
|
||||
* access the pixels.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the area to lock, or NULL to lock the entire
|
||||
* texture.
|
||||
* @param surface A pointer to an SDL_Surface* to be filled in with the created surface. You must free this
|
||||
* surface with SDL_FreeSurface when you are done with it.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool LockToSurface(const SDL_Rect* rect, SDL_Surface** surface) const {
|
||||
return SDL_LockTextureToSurface(*this, rect, surface);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureAlphaMod
|
||||
* @brief Set the alpha modulation value for a texture.
|
||||
* @param alpha The alpha modulation value to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetAlphaMod(Uint8 alpha) const { return SDL_SetTextureAlphaMod(*this, alpha); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureAlphaModFloat
|
||||
* @brief Set the alpha modulation value for a texture as a float.
|
||||
* @param alpha The alpha modulation value to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetAlphaModFloat(float alpha) const { return SDL_SetTextureAlphaModFloat(*this, alpha); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureBlendMode
|
||||
* @brief Set the blend mode for a texture.
|
||||
* @param blendMode The blend mode to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetBlendMode(SDL_BlendMode blendMode) const { return SDL_SetTextureBlendMode(*this, blendMode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureColorMod
|
||||
* @brief Set the color modulation values for a texture.
|
||||
* @param r The red color modulation value to set
|
||||
* @param g The green color modulation value to set
|
||||
* @param b The blue color modulation value to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetColorMod(Uint8 r, Uint8 g, Uint8 b) const { return SDL_SetTextureColorMod(*this, r, g, b); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureColorModFloat
|
||||
* @brief Set the color modulation values for a texture as floats.
|
||||
* @param r The red color modulation value to set
|
||||
* @param g The green color modulation value to set
|
||||
* @param b The blue color modulation value to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetColorModFloat(float r, float g, float b) const { return SDL_SetTextureColorModFloat(*this, r, g, b); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_SetTexturePalette **/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetTextureScaleMode
|
||||
* @brief Set the scale mode for a texture.
|
||||
* @param scaleMode The scale mode to set
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetScaleMode(SDL_ScaleMode scaleMode) const { return SDL_SetTextureScaleMode(*this, scaleMode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_UnlockTexture
|
||||
* @brief Unlock a texture, enabling the changes made to the texture's pixels to be rendered.
|
||||
*/
|
||||
void Unlock() const { SDL_UnlockTexture(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_UpdateNVTexture
|
||||
* @brief Update a rectangle within a texture with new pixel data in NV12 or NV21 format.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the area to update, or NULL to update the entire
|
||||
* texture.
|
||||
* @param Yplane A pointer to the pixel data for the Y plane of the texture. The format of this data should be a
|
||||
* contiguous array of bytes, where each byte represents the intensity of the Y component for a pixel.
|
||||
* @param Ypitch The pitch of the Y plane pixel data (the length of a row of pixels in bytes).
|
||||
* @param UVplane A pointer to the pixel data for the interleaved U and V planes of the texture. The format of
|
||||
* this data should be a contiguous array of bytes, where each pair of bytes represents the U and V components for
|
||||
* a pixel. The U and V values should be interleaved, meaning that the first byte represents the U component and
|
||||
* the second byte represents the V component for a pixel.
|
||||
* @param UVpitch The pitch of the interleaved U and V plane pixel data (the length of a row of pixels in bytes).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool UpdateNV(const SDL_Rect* rect, const Uint8* Yplane, int Ypitch, const Uint8* UVplane, int UVpitch) const {
|
||||
return SDL_UpdateNVTexture(*this, rect, Yplane, Ypitch, UVplane, UVpitch);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_UpdateTexture
|
||||
* @brief Update a rectangle within a texture with new pixel data.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the area to update, or NULL to update the entire
|
||||
* texture.
|
||||
* @param pixels A pointer to the pixel data to update the texture with. The format of this data should match the
|
||||
* pixel format of the texture.
|
||||
* @param pitch The pitch of the pixel data (the length of a row of pixels in bytes).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Update(const SDL_Rect* rect, const void* pixels, int pitch) const {
|
||||
return SDL_UpdateTexture(*this, rect, pixels, pitch);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_UpdateYUVTexture
|
||||
* @brief Update a rectangle within a texture
|
||||
* @param rect A pointer to an SDL_Rect structure representing the area to update, or NULL to update the entire
|
||||
* texture.
|
||||
* @param Yplane A pointer to the pixel data for the Y plane of the texture.
|
||||
* @param Ypitch The pitch of the Y plane pixel data (the length of a row of pixels in bytes).
|
||||
* @param Uplane A pointer to the pixel data for the U plane of the texture.
|
||||
* @param Upitch The pitch of the U plane pixel data (the length of a row of pixels in bytes).
|
||||
* @param Vplane A pointer to the pixel data for the V plane of the texture.
|
||||
* @param Vpitch The pitch of the V plane pixel data (the length of a row of pixels in bytes).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool UpdateYUV(const SDL_Rect* rect, const Uint8* Yplane, int Ypitch, const Uint8* Uplane, int Upitch, const Uint8* Vplane, int Vpitch) const {
|
||||
return SDL_UpdateYUVTexture(*this, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file video.hpp
|
||||
* @brief Marries the two classes together resolving what would otherwise be circular dependencies between Window and
|
||||
* Renderer
|
||||
*/
|
||||
#include <hdk/sdl/video/Display.hpp>
|
||||
#include <hdk/sdl/video/Surface.hpp>
|
||||
#include <hdk/sdl/video/Window.hpp>
|
||||
|
||||
/// We need to be able to return a Renderer from Window, but Renderer also needs to be able to return a Window, so we
|
||||
/// have to include both headers here to resolve the circular dependency.
|
||||
#include <hdk/sdl/render/Renderer.hpp>
|
||||
|
||||
namespace hdk::sdl {
|
||||
/** @see SDL_GetRenderer
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetRenderer
|
||||
* @brief Get the renderer associated with a window.
|
||||
* @return Renderer The renderer associated with the window. If the window is invalid or has no renderer, returns an
|
||||
* invalid renderer.
|
||||
*/
|
||||
inline Renderer Window::GetRenderer() const { return Renderer(Renderer::get_or_view(SDL_GetRenderer(*this))); }
|
||||
/** @see SDL_GetRenderWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetRenderWindow
|
||||
*/
|
||||
inline Window Renderer::GetWindow() const { return Window(Window::get_or_view(SDL_GetRenderWindow(*this))); }
|
||||
/** @see SDL_CreateWindowAndRenderer
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateWindowAndRenderer
|
||||
* @brief Create a window and renderer with one function call.
|
||||
* @param title
|
||||
* @param width
|
||||
* @param height
|
||||
* @param window_flags
|
||||
* @return std::pair<Window, Renderer>
|
||||
*/
|
||||
inline std::pair<Window, Renderer> CreateWindowAndRenderer(
|
||||
const char* title, int width, int height, SDL_WindowFlags window_flags) {
|
||||
SDL_Window* window_ptr = nullptr;
|
||||
SDL_Renderer* renderer_ptr = nullptr;
|
||||
if (SDL_CreateWindowAndRenderer(title, width, height, window_flags, &window_ptr, &renderer_ptr)) {
|
||||
return { Window::get_or_cache(window_ptr, SDL_DestroyWindow),
|
||||
Renderer::get_or_cache(renderer_ptr, SDL_DestroyRenderer) };
|
||||
} else {
|
||||
return { Window(nullptr), Renderer(nullptr) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Display.hpp
|
||||
* @brief HDK sdl video header only wrapper for the SDL_DisplayID type and related functions
|
||||
*/
|
||||
#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
|
||||
*/
|
||||
static std::vector<Display> GetDisplays() {
|
||||
int count;
|
||||
SDL_DisplayID* displayIDs = SDL_GetDisplays(&count);
|
||||
std::vector<Display> displays;
|
||||
if (displayIDs) {
|
||||
displays.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
displays.emplace_back(displayIDs[i]);
|
||||
}
|
||||
SDL_free(displayIDs);
|
||||
}
|
||||
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
|
||||
*/
|
||||
std::vector<SDL_DisplayMode> GetFullscreenModes() const {
|
||||
int count;
|
||||
SDL_DisplayMode** modes = SDL_GetFullscreenDisplayModes(*this, &count);
|
||||
std::vector<SDL_DisplayMode> displayModes;
|
||||
if (modes) {
|
||||
displayModes.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
displayModes.push_back(*modes[i]);
|
||||
}
|
||||
SDL_free(modes);
|
||||
}
|
||||
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()); }
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,529 @@
|
||||
#pragma once
|
||||
/** @file Surface.hpp
|
||||
* @brief Defines the Surface class for handling SDL surfaces.
|
||||
*/
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
/** Surfaces hold bitmap data **/
|
||||
namespace hdk::sdl {
|
||||
class Surface : public hdk::grid::SharedPtrWrapper<SDL_Surface> {
|
||||
public:
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
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
|
||||
*/
|
||||
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(
|
||||
SDL_ConvertSurfaceAndColorspace(*this, format, palette, colorspace, properties), SDL_DestroySurface);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateSurface
|
||||
* @brief Create a new surface
|
||||
* @param w
|
||||
* @param h
|
||||
* @param format
|
||||
* @return A new Surface instance with the created surface, or nullptr on failure.
|
||||
*/
|
||||
static Surface Create(int w, int h, SDL_PixelFormat format) {
|
||||
return get_or_cache(SDL_CreateSurface(w, h, format), SDL_DestroySurface);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_CreateSurfaceFrom
|
||||
* @brief Create a new surface from existing pixel data.
|
||||
* @param w
|
||||
* @param h
|
||||
* @param format
|
||||
* @param pixels
|
||||
* @param pitch
|
||||
* @return A new Surface instance with the created surface, or nullptr on failure.
|
||||
*/
|
||||
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_DestroySurface
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_DuplicateSurface
|
||||
* @brief Create a new surface that is a duplicate of the original surface.
|
||||
* @return A new Surface instance with the duplicated surface, or nullptr on failure.
|
||||
*/
|
||||
Surface Duplicate() const { return get_or_cache(SDL_DuplicateSurface(*this), SDL_DestroySurface); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_FillSurfaceRect
|
||||
* @brief Fill a rectangle on the surface with a color.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the rectangle to fill, or NULL to fill the entire
|
||||
* surface.
|
||||
* @param color
|
||||
*/
|
||||
void FillRect(const SDL_Rect* rect, Uint32 color) const { SDL_FillSurfaceRect(*this, rect, color); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_FillSurfaceRects
|
||||
* @brief Fill multiple rectangles on the surface with a color.
|
||||
* @param rects An array of SDL_Rect structures representing the rectangles to fill.
|
||||
* @param count The number of rectangles in the rects array.
|
||||
* @param color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool FillRects(const SDL_Rect* rects, int count, Uint32 color) const {
|
||||
return SDL_FillSurfaceRects(*this, rects, count, color);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_FlipSurface
|
||||
* @brief Flip the surface.
|
||||
* @param flip_mode SDL_FlipMode enum to control horizontal, vertical, or both flipping.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Flip(SDL_FlipMode flip_mode) const { return SDL_FlipSurface(*this, flip_mode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceAlphaMod
|
||||
* @brief Get the surface's alpha modulation value.
|
||||
* @param alpha pointer to 8bit to receive the alpha modulation value (0-255).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetAlphaMod(Uint8* alpha) const { return SDL_GetSurfaceAlphaMod(*this, alpha); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceBlendMode
|
||||
* @brief Get the surface's blend mode.
|
||||
* @param blend_mode pointer to an SDL_BlendMode variable to receive the blend mode
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetBlendMode(SDL_BlendMode* blend_mode) const { return SDL_GetSurfaceBlendMode(*this, blend_mode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceClipRect
|
||||
* @brief Get the surface's clipping rectangle.
|
||||
* @param rect pointer to an SDL_Rect structure to receive the clipping rectangle
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetClipRect(SDL_Rect* rect) const { return SDL_GetSurfaceClipRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceColorKey
|
||||
* @brief Get the surface's color key.
|
||||
* @param color_key pointer to a Uint32 variable to receive the color key value
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetColorKey(Uint32* color_key) const { return SDL_GetSurfaceColorKey(*this, color_key); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceColorMod
|
||||
* @brief Get the surface's color modulation values.
|
||||
* @param r pointer to Uint8 variable to receive the red color modulation value
|
||||
* @param g pointer to Uint8 variable to receive the green color modulation value
|
||||
* @param b pointer to Uint8 variable to receive the blue color modulation value
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool GetColorMod(Uint8* r, Uint8* g, Uint8* b) const { return SDL_GetSurfaceColorMod(*this, r, g, b); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceColorspace
|
||||
* @brief Get the surface's colorspace.
|
||||
* @return The colorspace of the surface.
|
||||
*/
|
||||
SDL_Colorspace GetColorspace() const { return SDL_GetSurfaceColorspace(*this); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_GetSurfaceImages
|
||||
*/
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_GetSurfacePalette
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetSurfaceProperties
|
||||
* @brief Get the surface's properties.
|
||||
* @return The properties set associated with the surface.
|
||||
*/
|
||||
SDL_PropertiesID GetProperties() const { return SDL_GetSurfaceProperties(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LoadBMP
|
||||
* @brief Load a BMP image from a file and return a new surface containing the image.
|
||||
* @param file The file path of the BMP image to load.
|
||||
* @return A new Surface instance with the loaded surface, or nullptr on failure.
|
||||
*/
|
||||
static Surface LoadBMP(const char* file) { return get_or_cache(SDL_LoadBMP(file), SDL_DestroySurface); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_LoadBMP_IO
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LoadPNG
|
||||
* @brief Load a PNG image from a file and return a new surface containing the image.
|
||||
* @param file The file path of the PNG image to load.
|
||||
* @return A new Surface instance with the loaded surface, or nullptr on failure.
|
||||
*/
|
||||
static Surface LoadPNG(const char* file) { return get_or_cache(SDL_LoadPNG(file), SDL_DestroySurface); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_LoadPNG_IO
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LoadSurface
|
||||
* @brief Load a surface from a file. PNG or BMP image formats are supported.
|
||||
* @param file The file path of the image to load.
|
||||
* @return A new Surface instance with the loaded surface, or nullptr on failure.
|
||||
*/
|
||||
static Surface LoadSurface(const char* file) { return get_or_cache(SDL_LoadSurface(file), SDL_DestroySurface); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_LoadSurface_IO
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_LockSurface
|
||||
* @brief Lock the surface for direct pixel access.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool Lock() const { return SDL_LockSurface(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_MapSurfaceRGB
|
||||
* @brief Map RGB values to a pixel format and return the mapped color value.
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
* @return The mapped color value in the surface's pixel format.
|
||||
*/
|
||||
Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const { return SDL_MapSurfaceRGB(*this, r, g, b); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_MapSurfaceRGBA
|
||||
* @brief Map RGBA values to a pixel format and return the mapped color value.
|
||||
* @param r The red component of the color
|
||||
* @param g The green component of the color
|
||||
* @param b The blue component of the color
|
||||
* @param a The alpha component of the color
|
||||
* @return The mapped color value in the surface's pixel format.
|
||||
*/
|
||||
Uint32 MapRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const { return SDL_MapSurfaceRGBA(*this, r, g, b, a); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_PremultiplyAlpha
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_PremultiplySurfaceAlpha
|
||||
* @brief Premultiply the surface's alpha values into its color values.
|
||||
* @param linear
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool PremultiplyAlpha(bool linear) const { return SDL_PremultiplySurfaceAlpha(*this, linear); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ReadSurfacePixel
|
||||
* @brief Read a pixel from the surface at the specified coordinates and return its color value.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param r pointer to Uint8 variable to receive the red component of the pixel's color
|
||||
* @param g pointer to Uint8 variable to receive the green component of the pixel's color
|
||||
* @param b pointer to Uint8 variable to receive the blue component of the pixel's color
|
||||
* @param a pointer to Uint8 variable to receive the alpha component of the pixel's color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool ReadPixel(int x, int y, Uint8* r, Uint8* g, Uint8* b, Uint8* a) const {
|
||||
return SDL_ReadSurfacePixel(*this, x, y, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ReadSurfacePixelFloat
|
||||
* @brief Read a pixel from the surface at the specified coordinates and return its color value as floats.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param r pointer to float variable to receive the red component of the pixel's color
|
||||
* @param g pointer to float variable to receive the green component of the pixel's color
|
||||
* @param b pointer to float variable to receive the blue component of the pixel's color
|
||||
* @param a pointer to float variable to receive the alpha component of the pixel's color
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool ReadPixelFloat(int x, int y, float* r, float* g, float* b, float* a) const {
|
||||
return SDL_ReadSurfacePixelFloat(*this, x, y, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RemoveSurfaceAlternateImages
|
||||
* @brief Remove all alternate images from the surface.
|
||||
*/
|
||||
void RemoveAlternateImages() const { SDL_RemoveSurfaceAlternateImages(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_RotateSurface
|
||||
* @brief Rotate the surface by a specified angle returning a new surface with the rotated image.
|
||||
* @param angle The angle to rotate the surface, in degrees.
|
||||
*/
|
||||
Surface Rotate(float angle) const { return get_or_cache(SDL_RotateSurface(*this, angle), SDL_DestroySurface); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SaveBMP
|
||||
* @brief Save the surface as a BMP image to a file.
|
||||
* @param file The file path to save the BMP image to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SaveBMP(const char* file) const { return SDL_SaveBMP(*this, file); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_SaveBMP_IO
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SavePNG
|
||||
* @brief Save the surface as a PNG image to a file.
|
||||
* @param file The file path to save the PNG image to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SavePNG(const char* file) const { return SDL_SavePNG(*this, file); }
|
||||
/** @todo https://wiki.libsdl.org/SDL3/SDL_SavePNG_IO
|
||||
*/
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_ScaleSurface
|
||||
* @brief Scale the surface to a new width and height, returning a new surface with the scaled image.
|
||||
* @param w The new width of the surface.
|
||||
* @param h The new height of the surface.
|
||||
* @param scale_mode The scale mode to use for scaling the surface
|
||||
* @return A new Surface instance with the scaled surface, or nullptr on failure.
|
||||
*/
|
||||
Surface Scale(int w, int h, SDL_ScaleMode scale_mode) const {
|
||||
return get_or_cache(SDL_ScaleSurface(*this, w, h, scale_mode), SDL_DestroySurface);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceAlphaMod
|
||||
* @brief Set the surface's alpha modulation value.
|
||||
* @param alpha The alpha modulation value to set (0-255).
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetAlphaMod(Uint8 alpha) const { return SDL_SetSurfaceAlphaMod(*this, alpha); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceBlendMode
|
||||
* @brief Set the surface's blend mode.
|
||||
* @param blend_mode The blend mode to set for the surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetBlendMode(SDL_BlendMode blend_mode) const { return SDL_SetSurfaceBlendMode(*this, blend_mode); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceClipRect
|
||||
* @brief Set the surface's clipping rectangle.
|
||||
* @param rect A pointer to an SDL_Rect structure representing the clipping rectangle to set,
|
||||
* or NULL to disable clipping.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetClipRect(const SDL_Rect* rect) const { return SDL_SetSurfaceClipRect(*this, rect); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceColorKey
|
||||
* @brief Set the surface's color key.
|
||||
* @param enable Whether to enable or disable the color key for the surface.
|
||||
* @param color_key The color key value to set for the surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetColorKey(bool enable, Uint32 color_key) const { return SDL_SetSurfaceColorKey(*this, enable, color_key); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceColorMod
|
||||
* @brief Set the surface's color modulation values.
|
||||
* @param r The red color modulation value to set.
|
||||
* @param g The green color modulation value to set.
|
||||
* @param b The blue color modulation value to set.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetColorMod(Uint8 r, Uint8 g, Uint8 b) const { return SDL_SetSurfaceColorMod(*this, r, g, b); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceColorspace
|
||||
* @brief Set the surface's colorspace.
|
||||
* @param colorspace The colorspace to set for the surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetColorspace(SDL_Colorspace colorspace) const { return SDL_SetSurfaceColorspace(*this, colorspace); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfacePalette
|
||||
* @brief Set the surface's palette.
|
||||
* @param palette A pointer to an SDL_Palette structure representing the palette to set for the surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetPalette(SDL_Palette* palette) const { return SDL_SetSurfacePalette(*this, palette); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SetSurfaceRLE
|
||||
* @brief Set the surface's RLE acceleration hint.
|
||||
* @param rle The RLE acceleration hint to set for the surface.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool SetRLE(bool rle) const { return SDL_SetSurfaceRLE(*this, rle); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_StretchSurface
|
||||
* @brief Blits this surface onto a destination rectangle stretching/smooshing the image to fit the destination
|
||||
* rectangle.
|
||||
* @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.
|
||||
* @param scale_mode The scale mode to use for scaling the surface when stretching.
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool StretchTo(
|
||||
SDL_Surface* dst_surface, const SDL_Rect* dst_rect, const SDL_Rect* src_rect, SDL_ScaleMode scale_mode) const {
|
||||
return SDL_StretchSurface(*this, src_rect, dst_surface, dst_rect, scale_mode);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SurfaceHasAlternateImages
|
||||
* @brief Check if the surface has any alternate images.
|
||||
* @return bool true if the surface has alternate images, false otherwise.
|
||||
*/
|
||||
bool HasAlternateImages() const { return SDL_SurfaceHasAlternateImages(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SurfaceHasColorKey
|
||||
* @brief Check if the surface has a color key.
|
||||
* @return bool true if the surface has a color key, false otherwise.
|
||||
*/
|
||||
bool HasColorKey() const { return SDL_SurfaceHasColorKey(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_SurfaceHasRLE
|
||||
* @brief Check if the surface has RLE acceleration enabled.
|
||||
* @return bool true if the surface has RLE acceleration enabled, false otherwise.
|
||||
*/
|
||||
bool HasRLE() const { return SDL_SurfaceHasRLE(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_UnlockSurface
|
||||
* @brief Unlock the surface after direct pixel access.
|
||||
*/
|
||||
void Unlock() const { SDL_UnlockSurface(*this); }
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_WriteSurfacePixel
|
||||
* @brief Write a pixel to the surface at the specified coordinates with the given color value.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param r
|
||||
* @param g
|
||||
* @param b
|
||||
* @param a
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool WritePixel(int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const {
|
||||
return SDL_WriteSurfacePixel(*this, x, y, r, g, b, a);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_WriteSurfacePixelFloat
|
||||
* @brief Write a pixel to the surface at the specified coordinates with the given color value as floats.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param r
|
||||
* @param g
|
||||
* @param b
|
||||
* @param a
|
||||
* @return bool true on success
|
||||
*/
|
||||
bool WritePixelFloat(int x, int y, float r, float g, float b, float a) const {
|
||||
return SDL_WriteSurfacePixelFloat(*this, x, y, r, g, b, a);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -5,36 +5,457 @@
|
||||
*/
|
||||
#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 Window : public hdk::grid::SharedPtrWrapper<SDL_Window> {
|
||||
public:
|
||||
/** 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, in UTF-8 encoding. If the title contains UTF-8 characters, you should use SDL_CreateWindowUTF8() instead.
|
||||
* @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).
|
||||
*/
|
||||
static Window Create(const char* title, int w, int h, SDL_WindowFlags flags)
|
||||
{
|
||||
class Renderer;
|
||||
class Window : public hdk::grid::SharedPtrWrapper<SDL_Window> {
|
||||
public:
|
||||
friend class Renderer;
|
||||
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).
|
||||
*/
|
||||
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));
|
||||
}
|
||||
/**
|
||||
* 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 */
|
||||
}
|
||||
/** @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 */
|
||||
return Window(get_or_view(SDL_GetGrabbedWindow()));
|
||||
}
|
||||
|
||||
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
|
||||
* @brief Set the opacity of the window.
|
||||
* @param opacity The opacity of the window, between 0.0f and 1.0f. If the window is invalid, this function will
|
||||
* return false.
|
||||
* @return bool True if the opacity was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetOpacity(float opacity) const { return SDL_SetWindowOpacity(*this, opacity); }
|
||||
/** @see SDL_GetWindowParent
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowParent
|
||||
* @brief Get the parent of the window.
|
||||
* @return Window The parent of the window. If the window has no parent or is invalid, returns a Window that
|
||||
* evaluates to false (i.e., it will be null).
|
||||
*/
|
||||
Window GetParent() const {
|
||||
/** 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_GetWindowParent(*this)));
|
||||
}
|
||||
/** @see SDL_SetWindowParent
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowParent
|
||||
* @brief Set the parent of the window.
|
||||
* @param parent The parent window. If the window is invalid, this function will return false.
|
||||
* @return bool True if the parent was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetParent(SDL_Window* parent) const { return SDL_SetWindowParent(*this, parent); }
|
||||
/** @see SDL_GetWindowPixelDensity
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowPixelDensity
|
||||
* @brief Get the pixel density of the window.
|
||||
* @return float The pixel density of the window. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetPixelDensity() const { return SDL_GetWindowPixelDensity(*this); }
|
||||
/** @see SDL_GetWindowSurfaceVSync
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowSurfaceVSync
|
||||
* @brief Get current vertical refresh sync interval.
|
||||
* @param vsync pointer to existing int to be filled with the current vertical refresh sync interval. If the
|
||||
* window is invalid, this function will return false and vsync will be set to 0.
|
||||
* @return bool True if the vertical refresh sync interval was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetSurfaceVSync(int* vsync) const { return SDL_GetWindowSurfaceVSync(*this, vsync); }
|
||||
/** @see SDL_SetWindowSurfaceVSync
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowSurfaceVSync
|
||||
* @brief Set vertical refresh sync interval.
|
||||
* @param vsync The vertical refresh sync interval. If the window is invalid, this function will return false.
|
||||
* @return bool True if the vertical refresh sync interval was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetSurfaceVSync(int vsync) const { return SDL_SetWindowSurfaceVSync(*this, vsync); }
|
||||
/** @see SDL_GetWindowPixelFormat
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowPixelFormat
|
||||
* @brief Get the pixel format of the window.
|
||||
* @return Uint32 The pixel format of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_PixelFormat GetPixelFormat() const { return SDL_GetWindowPixelFormat(*this); }
|
||||
/** @see SDL_GetWindowPosition
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowPosition
|
||||
* @brief Get the position of the window.
|
||||
* @param x Pointer to an int to be filled with the x position of the window. If the window is invalid, this
|
||||
* function will return false and x will be set to 0.
|
||||
* @param y Pointer to an int to be filled with the y position of the window. If the window is invalid, this
|
||||
* function will return false and y will be set to 0.
|
||||
* @return bool True if the position was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetPosition(int* x, int* y) const { return SDL_GetWindowPosition(*this, x, y); }
|
||||
/** @see SDL_SetWindowPosition
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowPosition
|
||||
* @brief Set the position of the window.
|
||||
* @param x The x position of the window in pixels. If the window is invalid, this function will return false.
|
||||
* @param y The y position of the window in pixels. If the window is invalid, this function will return false.
|
||||
* @return bool True if the position was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetPosition(int x, int y) const { return SDL_SetWindowPosition(*this, x, y); }
|
||||
/** @see SDL_GetWindowProgressState
|
||||
* @see SDL_ProgressState
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowProgressState
|
||||
* @brief Get the progress state of the window.
|
||||
* @return The progress state of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_ProgressState GetProgressState() const { return SDL_GetWindowProgressState(*this); }
|
||||
/** @see SDL_SetWindowProgressState
|
||||
* @see SDL_ProgressState
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowProgressState
|
||||
* @brief Set the progress state of the window.
|
||||
* @param state The progress state of the window. If the window is invalid, this function will return false.
|
||||
* @return bool True if the progress state was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetProgressState(SDL_ProgressState state) const { return SDL_SetWindowProgressState(*this, state); }
|
||||
|
||||
/** @see SDL_GetWindowProgressValue
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowProgressValue
|
||||
* @brief Get the progress value of the window.
|
||||
* @return float The progress value of the window, between 0.0f and 1.0f. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetProgressValue() const { return SDL_GetWindowProgressValue(*this); }
|
||||
/** @see SDL_SetWindowProgressValue
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowProgressValue
|
||||
* @brief Set the progress value of the window.
|
||||
* @param value The progress value of the window, between 0.0f and 1.0f. If the window is invalid, this function
|
||||
* will return false.
|
||||
* @return bool True if the progress value was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetProgressValue(float value) const { return SDL_SetWindowProgressValue(*this, value); }
|
||||
/** @see SDL_GetWindowProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowProperties
|
||||
* @brief Get the properties set of the window.
|
||||
* @return Properties The properties set of the window. If the window is invalid, returns an empty properties set.
|
||||
*/
|
||||
Properties GetProperties() const { return Properties(SDL_GetWindowProperties(*this)); }
|
||||
/** @see SDL_GetRenderer
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetRenderer
|
||||
* @brief Get the renderer associated with the window.
|
||||
* @return Renderer The renderer associated with the window. If the window is invalid, returns nullptr.
|
||||
*/
|
||||
Renderer GetRenderer() const;
|
||||
/** @see SDL_GetWindowTitle
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowTitle
|
||||
* @brief Get the title of the window.
|
||||
* @return const char* The title of the window. If the window is invalid, returns an empty string.
|
||||
*/
|
||||
const char* GetTitle() const { return SDL_GetWindowTitle(*this); }
|
||||
/** @see SDL_SetWindowTitle
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowTitle
|
||||
* @brief Set the title of the window.
|
||||
* @param title The title of the window. If the window is invalid, this function will return false.
|
||||
* @return bool True if the title was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetTitle(const char* title) const { return SDL_SetWindowTitle(*this, title); }
|
||||
/** @see SDL_SetWindowAlwaysOnTop
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowAlwaysOnTop
|
||||
* @brief Set the window to be always on top.
|
||||
* @param alwaysOnTop True to make the window always on top, false otherwise.
|
||||
* @return bool True if the operation was successful, false otherwise.
|
||||
*/
|
||||
bool SetAlwaysOnTop(bool alwaysOnTop) const { return SDL_SetWindowAlwaysOnTop(*this, alwaysOnTop); }
|
||||
/** @see SDL_SetWindowIcon
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowIcon
|
||||
* @brief Set the icon of the window.
|
||||
* @param icon The surface to use as the window's icon. If the window is invalid, this function will return false.
|
||||
* @return bool True if the icon was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetIcon(SDL_Surface* icon) const { return SDL_SetWindowIcon(*this, icon); }
|
||||
/** @see SDL_SetWindowModal
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowModal
|
||||
* @brief Set the window to be modal.
|
||||
* @param modal True to make the window modal, false otherwise.
|
||||
* @return bool True if the operation was successful, false otherwise.
|
||||
*/
|
||||
bool SetModal(bool modal) const { return SDL_SetWindowModal(*this, modal); }
|
||||
/** @see SDL_SetWindowResizable
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowResizable
|
||||
* @brief Set the window to be resizable.
|
||||
* @param resizable True to make the window resizable, false otherwise.
|
||||
* @return bool True if the operation was successful, false otherwise.
|
||||
*/
|
||||
bool SetResizable(bool resizable) const { return SDL_SetWindowResizable(*this, resizable); }
|
||||
/** @see SDL_SetWindowShape
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowShape
|
||||
* @brief Set the shape of the window.
|
||||
* @param shape The shape mode to set for the window. If the window is invalid, this function will return false.
|
||||
* @return bool True if the shape was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetShape(SDL_Surface* shape) const { return SDL_SetWindowShape(*this, shape); }
|
||||
/** @see SDL_CreatePopupWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreatePopupWindow
|
||||
* @brief Create a popup window.
|
||||
* @param offset_x The x position of the popup window relative to the parent window.
|
||||
* @param offset_y The y position of the popup window relative to the parent window.
|
||||
* @param w The width of the popup window.
|
||||
* @param h The height of the popup window.
|
||||
* @param flags The flags for the popup window.
|
||||
* @return Window The created popup window. If the creation fails, returns an invalid window.
|
||||
*/
|
||||
Window CreatePopup(int offset_x, int offset_y, int w, int h, SDL_WindowFlags flags) const {
|
||||
return Window(
|
||||
get_or_cache(SDL_CreatePopupWindow(*this, offset_x, offset_y, w, h, flags), SDL_DestroyWindow));
|
||||
}
|
||||
/** @see SDL_DestroyWindowSurface
|
||||
* https://wiki.libsdl.org/SDL3/SDL_DestroyWindowSurface
|
||||
* @brief Destroy the window surface.
|
||||
* @return bool True if the surface was successfully destroyed, false otherwise.
|
||||
*/
|
||||
bool DestroySurface() const { return SDL_DestroyWindowSurface(*this); }
|
||||
/** @see SDL_FlashWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_FlashWindow
|
||||
* @brief Flash the window to get the user's attention.
|
||||
* @param flashType The type of flash to perform.
|
||||
* @return bool True if the window was successfully flashed, false otherwise.
|
||||
*/
|
||||
bool Flash(SDL_FlashOperation flashType) const { return SDL_FlashWindow(*this, flashType); }
|
||||
/** @see SDL_HideWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_HideWindow
|
||||
* @brief Hide the window.
|
||||
* @return bool True if the window was successfully hidden, false otherwise.
|
||||
*/
|
||||
bool Hide() const { return SDL_HideWindow(*this); }
|
||||
/** @see SDL_MaximizeWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_MaximizeWindow
|
||||
* @brief Maximize the window. If the window is already maximized, this function will return false.
|
||||
* @return bool True if the window was successfully maximized, false otherwise.
|
||||
*/
|
||||
bool Maximize() const { return SDL_MaximizeWindow(*this); }
|
||||
/** @see SDL_MinimizeWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_MinimizeWindow
|
||||
* @brief Minimize the window. If the window is already minimized, this function will
|
||||
* return false.
|
||||
* @return bool True if the window was successfully minimized, false otherwise.
|
||||
*/
|
||||
bool Minimize() const { return SDL_MinimizeWindow(*this); }
|
||||
/** @see SDL_RaiseWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_RaiseWindow
|
||||
* @brief Raise the window above other windows. If the window is already raised, this function will return false.
|
||||
* @return bool True if the window was successfully raised, false otherwise.
|
||||
*/
|
||||
bool Raise() const { return SDL_RaiseWindow(*this); }
|
||||
/** @see SDL_RestoreWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_RestoreWindow
|
||||
* @brief Restore the window to its normal size and position. If the window is not minimized or maximized, this
|
||||
* function will return false.
|
||||
* @return bool True if the window was successfully restored, false otherwise.
|
||||
*/
|
||||
bool Restore() const { return SDL_RestoreWindow(*this); }
|
||||
/** @see SDL_ShowWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_ShowWindow
|
||||
* @brief Show the window.
|
||||
* @return bool True if the window was successfully shown, false otherwise.
|
||||
*/
|
||||
bool Show() const { return SDL_ShowWindow(*this); }
|
||||
/** @see SDL_ShowWindowSystemMenu
|
||||
* https://wiki.libsdl.org/SDL3/SDL_ShowWindowSystemMenu
|
||||
* @brief Show the window's system menu.
|
||||
* @param x
|
||||
* @param y
|
||||
* @return bool True if the system menu was successfully shown, false otherwise.
|
||||
*/
|
||||
bool ShowSystemMenu(int x, int y) const { return SDL_ShowWindowSystemMenu(*this, x, y); }
|
||||
/** @see SDL_SyncWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SyncWindow
|
||||
* @brief Sync the window's state with the display. This is useful after changing display modes or other
|
||||
* operations that may affect the window's appearance.
|
||||
* @return bool True if the window was successfully synced, false otherwise.
|
||||
*/
|
||||
bool Sync() const { return SDL_SyncWindow(*this); }
|
||||
/** @see SDL_UpdateWindowSurface
|
||||
* https://wiki.libsdl.org/SDL3/SDL_UpdateWindowSurface
|
||||
* @brief Update the window surface with any changes made to the surface. This should only be used if you are
|
||||
* using the window surface for rendering. If the window is invalid, this function will return false.
|
||||
* @return bool True if the window surface was successfully updated, false otherwise.
|
||||
*/
|
||||
bool UpdateSurface() const { return SDL_UpdateWindowSurface(*this); }
|
||||
/** @see SDL_UpdateWindowSurfaceRects
|
||||
* https://wiki.libsdl.org/SDL3/SDL_UpdateWindowSurfaceRects
|
||||
* @brief Update the window surface with any changes made to the specified rectangles on the surface. This should
|
||||
* only be used if you are using the window surface for rendering. If the window is invalid, this function will
|
||||
* return false.
|
||||
* @param rects An array of SDL_Rect structures that define the rectangles to update on the window surface.
|
||||
* @param num_rects The number of rectangles in the rects array.
|
||||
* @return bool True if the window surface was successfully updated, false otherwise.
|
||||
*/
|
||||
bool UpdateSurfaceRects(const SDL_Rect* rects, int num_rects) const {
|
||||
return SDL_UpdateWindowSurfaceRects(*this, rects, num_rects);
|
||||
}
|
||||
};
|
||||
} // namespace hdk::sdl
|
||||
@@ -0,0 +1,17 @@
|
||||
add_executable(
|
||||
hdk-sdl-tests
|
||||
main.cpp
|
||||
Properties_test.cpp
|
||||
Window_test.cpp
|
||||
Surface_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(hdk-sdl-tests PRIVATE hdk-sdl doctest::doctest)
|
||||
target_compile_features(hdk-sdl-tests PRIVATE cxx_std_17)
|
||||
|
||||
if(HDK_SDL_BUILD_COVERAGE AND TARGET hdk-coverage-flags)
|
||||
target_link_libraries(hdk-sdl-tests PRIVATE hdk-coverage-flags)
|
||||
endif()
|
||||
|
||||
add_test(NAME hdk-sdl-tests COMMAND hdk-sdl-tests)
|
||||
set_tests_properties(hdk-sdl-tests PROPERTIES ENVIRONMENT "SDL_VIDEODRIVER=dummy")
|
||||
@@ -0,0 +1,95 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "SDL_headless_fixture.hpp"
|
||||
|
||||
namespace {
|
||||
struct CleanupState {
|
||||
int calls = 0;
|
||||
};
|
||||
|
||||
void SDLCALL CleanupPointerProperty(void* userdata, void* value) {
|
||||
auto* state = static_cast<CleanupState*>(userdata);
|
||||
if (state) {
|
||||
++state->calls;
|
||||
}
|
||||
delete static_cast<int*>(value);
|
||||
}
|
||||
|
||||
void SDLCALL CollectPropertyNames(void* userdata, SDL_PropertiesID, const char* name) {
|
||||
auto* names = static_cast<std::vector<std::string>*>(userdata);
|
||||
if (names && name) {
|
||||
names->emplace_back(name);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Properties bindings are exercised") {
|
||||
SDLSession sdl;
|
||||
if (!sdl.IsInitialized()) {
|
||||
INFO(SDL_GetError());
|
||||
CHECK(false);
|
||||
return;
|
||||
}
|
||||
|
||||
auto props = hdk::sdl::Properties::Create();
|
||||
auto second = hdk::sdl::Properties::Create();
|
||||
|
||||
REQUIRE(static_cast<SDL_PropertiesID>(props) != 0);
|
||||
REQUIRE(static_cast<SDL_PropertiesID>(second) != 0);
|
||||
|
||||
CHECK(props.SetBooleanProperty("hdk.bool", true));
|
||||
CHECK(props.GetBooleanProperty("hdk.bool", false));
|
||||
|
||||
CHECK(props.SetFloatProperty("hdk.float", 1.5f));
|
||||
CHECK(props.GetFloatProperty("hdk.float", 0.0f) == doctest::Approx(1.5f));
|
||||
|
||||
CHECK(props.SetNumberProperty("hdk.number", 44));
|
||||
CHECK(props.GetNumberProperty("hdk.number", 0) == 44);
|
||||
|
||||
int pointerValue = 77;
|
||||
CHECK(props.SetPointerProperty("hdk.pointer", &pointerValue));
|
||||
CHECK(props.GetPointerProperty("hdk.pointer", nullptr) == &pointerValue);
|
||||
|
||||
CHECK(props.SetStringProperty("hdk.string", "value"));
|
||||
CHECK(std::string(props.GetStringProperty("hdk.string", "missing")) == "value");
|
||||
|
||||
CHECK(props.HasProperty("hdk.string"));
|
||||
CHECK(props.GetPropertyType("hdk.string") == SDL_PROPERTY_TYPE_STRING);
|
||||
|
||||
CleanupState cleanupState;
|
||||
CHECK(props.SetPointerPropertyWithCleanup("hdk.cleanup", new int(9), CleanupPointerProperty, &cleanupState));
|
||||
CHECK(props.GetPropertyType("hdk.cleanup") == SDL_PROPERTY_TYPE_POINTER);
|
||||
|
||||
CHECK(props.CopyAllTo(second));
|
||||
CHECK(std::string(second.GetStringProperty("hdk.string", "missing")) == "value");
|
||||
|
||||
CHECK(second.ClearProperty("hdk.string"));
|
||||
CHECK_FALSE(second.HasProperty("hdk.string"));
|
||||
|
||||
CHECK(second.CopyAllFrom(props));
|
||||
CHECK(second.HasProperty("hdk.string"));
|
||||
|
||||
std::vector<std::string> names;
|
||||
CHECK(props.EnumerateProperties(CollectPropertyNames, &names));
|
||||
CHECK_FALSE(names.empty());
|
||||
|
||||
CHECK(props.LockProperties());
|
||||
props.UnlockProperties();
|
||||
|
||||
auto global = hdk::sdl::Properties::GetGlobalProperties();
|
||||
CHECK(static_cast<SDL_PropertiesID>(global) != 0);
|
||||
|
||||
CHECK(props.ClearProperty("hdk.cleanup"));
|
||||
CHECK(cleanupState.calls >= 1);
|
||||
|
||||
props.Destroy();
|
||||
CHECK(static_cast<SDL_PropertiesID>(props) == 0);
|
||||
second.Destroy();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
inline void hdk_set_headless_video_driver() {
|
||||
#if defined(_WIN32)
|
||||
_putenv_s("SDL_VIDEODRIVER", "dummy");
|
||||
#else
|
||||
setenv("SDL_VIDEODRIVER", "dummy", 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
class SDLSession {
|
||||
public:
|
||||
SDLSession() {
|
||||
hdk_set_headless_video_driver();
|
||||
initialized = SDL_Init(SDL_INIT_VIDEO);
|
||||
}
|
||||
|
||||
~SDLSession() {
|
||||
if (initialized) {
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsInitialized() const { return initialized; }
|
||||
|
||||
private:
|
||||
bool initialized = false;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <hdk/sdl/video/Surface.hpp>
|
||||
|
||||
|
||||
TEST_CASE("Surface bindings are exercised") {
|
||||
|
||||
auto surface = hdk::sdl::Surface::Create(10, 10, SDL_PIXELFORMAT_RGBA8888);
|
||||
REQUIRE(surface);
|
||||
|
||||
CHECK(surface->w == 10);
|
||||
CHECK(surface->h == 10);
|
||||
CHECK(surface->format == SDL_PIXELFORMAT_RGBA8888);
|
||||
|
||||
surface.Clear(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
Uint8 r, g, b, a;
|
||||
CHECK(surface.ReadPixel(0, 0, &r, &g, &b, &a));
|
||||
CHECK(r == 255);
|
||||
CHECK(g == 0);
|
||||
CHECK(b == 0);
|
||||
CHECK(a == 255);
|
||||
|
||||
auto scaled = surface.Scale(20, 20, SDL_ScaleMode::SDL_SCALEMODE_LINEAR);
|
||||
REQUIRE(scaled);
|
||||
CHECK(scaled->w == 20);
|
||||
CHECK(scaled->h == 20);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <hdk/sdl/video/Window.hpp>
|
||||
|
||||
#include "SDL_headless_fixture.hpp"
|
||||
|
||||
TEST_CASE("Window bindings are exercised") {
|
||||
SDLSession sdl;
|
||||
if (!sdl.IsInitialized()) {
|
||||
INFO(SDL_GetError());
|
||||
CHECK(false);
|
||||
return;
|
||||
}
|
||||
|
||||
hdk::sdl::Window window = hdk::sdl::Window::Create("hdk-window-test", 64, 64, SDL_WINDOW_HIDDEN);
|
||||
if (!window) {
|
||||
INFO("SDL_CreateWindow failed in this environment: " << SDL_GetError());
|
||||
window = hdk::sdl::Window(nullptr);
|
||||
}
|
||||
|
||||
auto grabbed = hdk::sdl::Window::GetGrabbed();
|
||||
CHECK((static_cast<bool>(grabbed) || !static_cast<bool>(grabbed)));
|
||||
|
||||
auto fromZero = hdk::sdl::Window::GetFromID(0);
|
||||
CHECK_FALSE(static_cast<bool>(fromZero));
|
||||
|
||||
float minAspect = 0.0f;
|
||||
float maxAspect = 0.0f;
|
||||
CHECK((window.GetAspectRatio(&minAspect, &maxAspect) || !window.GetAspectRatio(&minAspect, &maxAspect)));
|
||||
|
||||
int top = 0;
|
||||
int left = 0;
|
||||
int bottom = 0;
|
||||
int right = 0;
|
||||
CHECK((window.GetBordersSize(&top, &left, &bottom, &right) || !window.GetBordersSize(&top, &left, &bottom, &right)));
|
||||
|
||||
(void)window.GetDisplayScale();
|
||||
(void)window.GetFlags();
|
||||
(void)window.GetFullscreenMode();
|
||||
(void)window.GetID();
|
||||
(void)window.GetKeyboardGrab();
|
||||
CHECK((window.SetKeyboardGrab(false) || !window.SetKeyboardGrab(false)));
|
||||
(void)window.GetMouseGrab();
|
||||
CHECK((window.SetMouseGrab(false) || !window.SetMouseGrab(false)));
|
||||
(void)window.GetMouseRect();
|
||||
CHECK((window.SetMouseRect(nullptr) || !window.SetMouseRect(nullptr)));
|
||||
|
||||
int maxW = 0;
|
||||
int maxH = 0;
|
||||
CHECK((window.GetMaximumSize(&maxW, &maxH) || !window.GetMaximumSize(&maxW, &maxH)));
|
||||
CHECK((window.SetMaximumSize(1280, 720) || !window.SetMaximumSize(1280, 720)));
|
||||
|
||||
int minW = 0;
|
||||
int minH = 0;
|
||||
CHECK((window.GetMinimumSize(&minW, &minH) || !window.GetMinimumSize(&minW, &minH)));
|
||||
CHECK((window.SetMinimumSize(32, 32) || !window.SetMinimumSize(32, 32)));
|
||||
|
||||
CHECK((window.SetSize(96, 96) || !window.SetSize(96, 96)));
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
CHECK((window.GetSize(&width, &height) || !window.GetSize(&width, &height)));
|
||||
|
||||
SDL_Rect safeArea{};
|
||||
CHECK((window.GetSafeArea(&safeArea) || !window.GetSafeArea(&safeArea)));
|
||||
|
||||
(void)window.GetOpacity();
|
||||
CHECK((window.SetOpacity(0.8f) || !window.SetOpacity(0.8f)));
|
||||
|
||||
auto parent = window.GetParent();
|
||||
CHECK((static_cast<bool>(parent) || !static_cast<bool>(parent)));
|
||||
CHECK((window.SetParent(nullptr) || !window.SetParent(nullptr)));
|
||||
|
||||
(void)window.GetPixelDensity();
|
||||
|
||||
int vsync = 0;
|
||||
CHECK((window.GetSurfaceVSync(&vsync) || !window.GetSurfaceVSync(&vsync)));
|
||||
CHECK((window.SetSurfaceVSync(1) || !window.SetSurfaceVSync(1)));
|
||||
|
||||
(void)window.GetPixelFormat();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
CHECK((window.GetPosition(&x, &y) || !window.GetPosition(&x, &y)));
|
||||
CHECK((window.SetPosition(10, 10) || !window.SetPosition(10, 10)));
|
||||
|
||||
(void)window.GetProgressState();
|
||||
(void)window.GetProgressValue();
|
||||
|
||||
auto props = window.GetProperties();
|
||||
CHECK((props.GetPropertyType("hdk-window-test-missing") == SDL_PROPERTY_TYPE_INVALID));
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <doctest/doctest.h>
|
||||
Reference in New Issue
Block a user