obs-properties: Add a few features
Just wanted the ability to be able to add private data to the properties data. Makes it a little easier to manage data if you get updates from controls.
This commit is contained in:
parent
79b88c4cbb
commit
7a60694159
@ -85,6 +85,8 @@ struct obs_property {
|
||||
|
||||
struct obs_properties {
|
||||
const char *locale;
|
||||
void *param;
|
||||
void (*destroy)(void *param);
|
||||
|
||||
struct obs_property *first_property;
|
||||
struct obs_property **last;
|
||||
@ -99,6 +101,32 @@ obs_properties_t obs_properties_create(const char *locale)
|
||||
return props;
|
||||
}
|
||||
|
||||
void obs_properties_set_param(obs_properties_t props,
|
||||
void *param, void (*destroy)(void *param))
|
||||
{
|
||||
if (!props)
|
||||
return;
|
||||
|
||||
if (props->param && props->destroy)
|
||||
props->destroy(props->param);
|
||||
|
||||
props->param = param;
|
||||
props->destroy = destroy;
|
||||
}
|
||||
|
||||
void *obs_properties_get_param(obs_properties_t props)
|
||||
{
|
||||
return props ? props->param : NULL;
|
||||
}
|
||||
|
||||
obs_properties_t obs_properties_create_param(const char *locale,
|
||||
void *param, void (*destroy)(void *param))
|
||||
{
|
||||
struct obs_properties *props = obs_properties_create(locale);
|
||||
obs_properties_set_param(props, param, destroy);
|
||||
return props;
|
||||
}
|
||||
|
||||
static void obs_property_destroy(struct obs_property *property)
|
||||
{
|
||||
if (property->type == OBS_PROPERTY_LIST) {
|
||||
@ -113,6 +141,10 @@ void obs_properties_destroy(obs_properties_t props)
|
||||
{
|
||||
if (props) {
|
||||
struct obs_property *p = props->first_property;
|
||||
|
||||
if (props->destroy && props->param)
|
||||
props->destroy(props->param);
|
||||
|
||||
while (p) {
|
||||
struct obs_property *next = p->next;
|
||||
obs_property_destroy(p);
|
||||
|
@ -61,8 +61,14 @@ typedef struct obs_property *obs_property_t;
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
EXPORT obs_properties_t obs_properties_create(const char *locale);
|
||||
EXPORT obs_properties_t obs_properties_create_param(const char *locale,
|
||||
void *param, void (*destroy)(void *param));
|
||||
EXPORT void obs_properties_destroy(obs_properties_t props);
|
||||
|
||||
EXPORT void obs_properties_set_param(obs_properties_t props,
|
||||
void *param, void (*destroy)(void *param));
|
||||
EXPORT void *obs_properties_get_param(obs_properties_t props);
|
||||
|
||||
EXPORT const char *obs_properties_locale(obs_properties_t props);
|
||||
|
||||
EXPORT obs_property_t obs_properties_first(obs_properties_t props);
|
||||
|
Loading…
x
Reference in New Issue
Block a user