2023-10-10 13:38:22 -06:00
|
|
|
/*
|
|
|
|
Simple DiretMedia Layer
|
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file SDL_properties.h
|
|
|
|
*
|
2023-11-06 08:26:06 -07:00
|
|
|
* Header file for SDL properties.
|
2023-10-10 13:38:22 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SDL_properties_h_
|
|
|
|
#define SDL_properties_h_
|
|
|
|
|
|
|
|
#include <SDL3/SDL_begin_code.h>
|
|
|
|
/* Set up for C function definitions, even when using C++ */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SDL properties ID
|
|
|
|
*/
|
|
|
|
typedef Uint32 SDL_PropertiesID;
|
|
|
|
|
2023-11-12 10:47:31 -07:00
|
|
|
/**
|
|
|
|
* SDL property type
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SDL_PROPERTY_TYPE_INVALID,
|
|
|
|
SDL_PROPERTY_TYPE_POINTER,
|
|
|
|
SDL_PROPERTY_TYPE_STRING,
|
|
|
|
SDL_PROPERTY_TYPE_NUMBER,
|
|
|
|
SDL_PROPERTY_TYPE_FLOAT,
|
2023-11-12 19:34:22 -07:00
|
|
|
SDL_PROPERTY_TYPE_BOOLEAN,
|
2023-11-12 10:47:31 -07:00
|
|
|
} SDL_PropertyType;
|
|
|
|
|
2023-11-08 12:55:04 -07:00
|
|
|
/**
|
|
|
|
* Get the global SDL properties
|
|
|
|
*
|
|
|
|
* \returns a valid property ID on success or 0 on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetProperty
|
|
|
|
* \sa SDL_SetProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
|
|
|
|
|
2023-10-10 13:38:22 -06:00
|
|
|
/**
|
|
|
|
* Create a set of properties
|
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* All properties are automatically destroyed when SDL_Quit() is called.
|
|
|
|
*
|
2023-10-12 13:20:53 -06:00
|
|
|
* \returns an ID for a new set of properties, or 0 on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
2023-10-10 13:38:22 -06:00
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_DestroyProperties
|
|
|
|
*/
|
|
|
|
extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock a set of properties
|
|
|
|
*
|
2023-10-12 13:20:53 -06:00
|
|
|
* Obtain a multi-threaded lock for these properties. Other threads will wait
|
|
|
|
* while trying to lock these properties until they are unlocked. Properties
|
|
|
|
* must be unlocked before they are destroyed.
|
2023-10-10 13:38:22 -06:00
|
|
|
*
|
2023-10-12 13:20:53 -06:00
|
|
|
* The lock is automatically taken when setting individual properties, this
|
|
|
|
* function is only needed when you want to set several properties atomically
|
|
|
|
* or want to guarantee that properties being queried aren't freed in another
|
|
|
|
* thread.
|
2023-10-10 13:38:22 -06:00
|
|
|
*
|
|
|
|
* \param props the properties to lock
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_UnlockProperties
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to unlock
|
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_LockProperties
|
|
|
|
*/
|
|
|
|
extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
|
|
|
|
|
2023-11-12 10:47:31 -07:00
|
|
|
/**
|
|
|
|
* Set a property on a set of properties with a cleanup function that is
|
|
|
|
* called when the property is deleted
|
|
|
|
*
|
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property, or NULL to delete the property
|
|
|
|
* \param cleanup the function to call when this property is deleted, or NULL
|
|
|
|
* if no cleanup is necessary
|
|
|
|
* \param userdata a pointer that is passed to the cleanup function
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetProperty
|
|
|
|
* \sa SDL_SetProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
|
|
|
|
|
2023-10-10 13:38:22 -06:00
|
|
|
/**
|
|
|
|
* Set a property on a set of properties
|
|
|
|
*
|
2023-11-07 13:33:43 -07:00
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property, or NULL to delete the property
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetProperty
|
|
|
|
* \sa SDL_SetPropertyWithCleanup
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
|
|
|
|
|
|
|
|
/**
|
2023-11-12 10:47:31 -07:00
|
|
|
* Set a string property on a set of properties
|
2023-11-07 10:56:05 -07:00
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property, or NULL to delete the property
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
2023-11-12 10:47:31 -07:00
|
|
|
* \sa SDL_GetStringProperty
|
2023-10-10 13:38:22 -06:00
|
|
|
*/
|
2023-11-12 10:47:31 -07:00
|
|
|
extern DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an integer property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetNumberProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a floating point property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetFloatProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
|
|
|
|
|
2023-11-12 19:34:22 -07:00
|
|
|
/**
|
|
|
|
* Set a boolean property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to modify
|
|
|
|
* \param value the new value of the property
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetBooleanProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value);
|
|
|
|
|
2023-11-12 10:47:31 -07:00
|
|
|
/**
|
|
|
|
* Get the type of a property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is
|
|
|
|
* not set.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*/
|
|
|
|
extern DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name);
|
2023-10-10 13:38:22 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a property on a set of properties
|
|
|
|
*
|
2023-11-09 18:11:23 -07:00
|
|
|
* By convention, the names of properties that SDL exposes on objects will
|
|
|
|
* start with "SDL.", and properties that SDL uses internally will start with
|
|
|
|
* "SDL.internal.". These should be considered read-only and should not be
|
|
|
|
* modified by applications.
|
2023-11-07 13:33:43 -07:00
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
2023-11-12 10:47:31 -07:00
|
|
|
* \param default_value the default value of the property
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the value of the property, or `default_value` if it is not set or
|
|
|
|
* not a pointer property.
|
2023-10-10 13:38:22 -06:00
|
|
|
*
|
2023-10-18 23:14:13 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread, although
|
|
|
|
* the data returned is not protected and could potentially be
|
2023-10-18 23:18:12 -06:00
|
|
|
* freed if you call SDL_SetProperty() or SDL_ClearProperty() on
|
|
|
|
* these properties from another thread. If you need to avoid
|
|
|
|
* this, use SDL_LockProperties() and SDL_UnlockProperties().
|
2023-10-18 23:13:33 -06:00
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
2023-11-12 10:47:31 -07:00
|
|
|
* \sa SDL_GetPropertyType
|
2023-10-10 13:38:22 -06:00
|
|
|
* \sa SDL_SetProperty
|
|
|
|
*/
|
2023-11-12 10:47:31 -07:00
|
|
|
extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a string property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
|
|
|
* \param default_value the default value of the property
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the value of the property, or `default_value` if it is not set or
|
|
|
|
* not a string property.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetPropertyType
|
|
|
|
* \sa SDL_SetStringProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC const char *SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a number property on a set of properties
|
|
|
|
*
|
2023-11-13 11:03:42 -07:00
|
|
|
* You can use SDL_GetPropertyType() to query whether the property exists and
|
|
|
|
* is a number property.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
|
|
|
* \param default_value the default value of the property
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the value of the property, or `default_value` if it is not set or
|
|
|
|
* not a number property.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetPropertyType
|
|
|
|
* \sa SDL_SetNumberProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a floating point property on a set of properties
|
|
|
|
*
|
2023-11-13 11:03:42 -07:00
|
|
|
* You can use SDL_GetPropertyType() to query whether the property exists and
|
|
|
|
* is a floating point property.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
|
|
|
* \param default_value the default value of the property
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the value of the property, or `default_value` if it is not set or
|
|
|
|
* not a float property.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetPropertyType
|
|
|
|
* \sa SDL_SetFloatProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value);
|
2023-10-10 13:38:22 -06:00
|
|
|
|
2023-11-12 19:34:22 -07:00
|
|
|
/**
|
|
|
|
* Get a boolean property on a set of properties
|
|
|
|
*
|
2023-11-13 11:03:42 -07:00
|
|
|
* You can use SDL_GetPropertyType() to query whether the property exists and
|
|
|
|
* is a boolean property.
|
2023-11-12 19:34:22 -07:00
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param name the name of the property to query
|
|
|
|
* \param default_value the default value of the property
|
2023-11-13 11:03:42 -07:00
|
|
|
* \returns the value of the property, or `default_value` if it is not set or
|
|
|
|
* not a float property.
|
2023-11-12 19:34:22 -07:00
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetPropertyType
|
|
|
|
* \sa SDL_SetBooleanProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC SDL_bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool default_value);
|
|
|
|
|
2023-10-11 17:59:51 -06:00
|
|
|
/**
|
|
|
|
* Clear a property on a set of properties
|
|
|
|
*
|
|
|
|
* \param props the properties to modify
|
|
|
|
* \param name the name of the property to clear
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
2023-10-18 23:13:33 -06:00
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
2023-10-11 17:59:51 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_GetProperty
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
|
|
|
|
|
2023-11-12 10:47:31 -07:00
|
|
|
typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name);
|
2023-11-13 11:03:42 -07:00
|
|
|
|
2023-11-12 10:47:31 -07:00
|
|
|
/**
|
|
|
|
* Enumerate the properties on a set of properties
|
|
|
|
*
|
2023-11-13 11:03:42 -07:00
|
|
|
* The callback function is called for each property on the set of properties.
|
|
|
|
* The properties are locked during enumeration.
|
2023-11-12 10:47:31 -07:00
|
|
|
*
|
|
|
|
* \param props the properties to query
|
|
|
|
* \param callback the function to call for each property
|
|
|
|
* \param userdata a pointer that is passed to `callback`
|
|
|
|
* \returns 0 on success or a negative error code on failure; call
|
|
|
|
* SDL_GetError() for more information.
|
|
|
|
*
|
|
|
|
* \threadsafety It is safe to call this function from any thread.
|
|
|
|
*
|
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*/
|
|
|
|
extern DECLSPEC int SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
|
|
|
|
|
2023-10-10 13:38:22 -06:00
|
|
|
/**
|
|
|
|
* Destroy a set of properties
|
|
|
|
*
|
2023-10-12 13:20:53 -06:00
|
|
|
* All properties are deleted and their cleanup functions will be called, if
|
2023-10-18 23:19:50 -06:00
|
|
|
* any.
|
2023-10-10 13:38:22 -06:00
|
|
|
*
|
|
|
|
* \param props the properties to destroy
|
|
|
|
*
|
2023-10-18 23:18:12 -06:00
|
|
|
* \threadsafety This function should not be called while these properties are
|
|
|
|
* locked or other threads might be setting or getting values
|
|
|
|
* from these properties.
|
2023-10-18 23:13:33 -06:00
|
|
|
*
|
2023-10-10 13:38:22 -06:00
|
|
|
* \since This function is available since SDL 3.0.0.
|
|
|
|
*
|
|
|
|
* \sa SDL_CreateProperties
|
|
|
|
*/
|
|
|
|
extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
|
|
|
|
|
|
|
|
/* Ends C function definitions when using C++ */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#include <SDL3/SDL_close_code.h>
|
|
|
|
|
|
|
|
#endif /* SDL_properties_h_ */
|