85dbe33a77
Co-authored-by: Copilot <copilot@github.com>
196 lines
9.4 KiB
C++
196 lines
9.4 KiB
C++
#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); }
|
|
};
|
|
} |