瀏覽代碼

libobs: Add editable list property

Add an editable list property, primarily used for adding files to a
playlist for example.
jp9000 10 年之前
父節點
當前提交
a752b32b83
共有 2 個文件被更改,包括 65 次插入0 次删除
  1. 55 0
      libobs/obs-properties.c
  2. 10 0
      libobs/obs-properties.h

+ 55 - 0
libobs/obs-properties.c

@@ -61,6 +61,12 @@ struct list_data {
 	enum obs_combo_format    format;
 };
 
+struct editable_list_data {
+	bool                        allow_files;
+	char                        *filter;
+	char                        *default_path;
+};
+
 struct button_data {
 	obs_property_clicked_t callback;
 };
@@ -72,6 +78,12 @@ static inline void path_data_free(struct path_data *data)
 		bfree(data->filter);
 }
 
+static inline void editable_list_data_free(struct editable_list_data *data)
+{
+	bfree(data->default_path);
+	bfree(data->filter);
+}
+
 static inline void list_item_free(struct list_data *data,
 		struct list_item *item)
 {
@@ -164,6 +176,8 @@ static void obs_property_destroy(struct obs_property *property)
 		list_data_free(get_property_data(property));
 	else if (property->type == OBS_PROPERTY_PATH)
 		path_data_free(get_property_data(property));
+	else if (property->type == OBS_PROPERTY_EDITABLE_LIST)
+		editable_list_data_free(get_property_data(property));
 
 	bfree(property);
 }
@@ -242,6 +256,8 @@ static inline size_t get_property_size(enum obs_property_type type)
 	case OBS_PROPERTY_COLOR:     return 0;
 	case OBS_PROPERTY_BUTTON:    return sizeof(struct button_data);
 	case OBS_PROPERTY_FONT:      return 0;
+	case OBS_PROPERTY_EDITABLE_LIST:
+		return sizeof(struct editable_list_data);
 	}
 
 	return 0;
@@ -438,6 +454,24 @@ obs_property_t *obs_properties_add_font(obs_properties_t *props,
 	return new_prop(props, name, desc, OBS_PROPERTY_FONT);
 }
 
+obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
+		const char *name, const char *desc,
+		bool allow_files, const char *filter,
+		const char *default_path)
+{
+	if (!props || has_prop(props, name)) return NULL;
+	struct obs_property *p = new_prop(props, name, desc,
+			OBS_PROPERTY_EDITABLE_LIST);
+
+	struct editable_list_data *data = get_property_data(p);
+	data->allow_files = allow_files;
+	data->filter = bstrdup(filter);
+	data->default_path = bstrdup(default_path);
+	return p;
+}
+
+/* ------------------------------------------------------------------------- */
+
 static inline bool is_combo(struct obs_property *p)
 {
 	return p->type == OBS_PROPERTY_LIST;
@@ -767,3 +801,24 @@ double obs_property_list_item_float(obs_property_t *p, size_t idx)
 	return (data && idx < data->items.num) ?
 		data->items.array[idx].d : 0.0;
 }
+
+bool obs_property_editable_list_allow_files(obs_property_t *p)
+{
+	struct editable_list_data *data = get_type_data(p,
+			OBS_PROPERTY_EDITABLE_LIST);
+	return data ? data->allow_files : false;
+}
+
+const char *obs_property_editable_list_filter(obs_property_t *p)
+{
+	struct editable_list_data *data = get_type_data(p,
+			OBS_PROPERTY_EDITABLE_LIST);
+	return data ? data->filter : NULL;
+}
+
+const char *obs_property_editable_list_default_path(obs_property_t *p)
+{
+	struct editable_list_data *data = get_type_data(p,
+			OBS_PROPERTY_EDITABLE_LIST);
+	return data ? data->default_path : NULL;
+}

+ 10 - 0
libobs/obs-properties.h

@@ -52,6 +52,7 @@ enum obs_property_type {
 	OBS_PROPERTY_COLOR,
 	OBS_PROPERTY_BUTTON,
 	OBS_PROPERTY_FONT,
+	OBS_PROPERTY_EDITABLE_LIST,
 };
 
 enum obs_combo_format {
@@ -196,6 +197,11 @@ EXPORT obs_property_t *obs_properties_add_button(obs_properties_t *props,
 EXPORT obs_property_t *obs_properties_add_font(obs_properties_t *props,
 		const char *name, const char *description);
 
+EXPORT obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
+		const char *name, const char *description,
+		bool allow_files, const char *filter,
+		const char *default_path);
+
 /* ------------------------------------------------------------------------- */
 
 /**
@@ -269,6 +275,10 @@ EXPORT const char *obs_property_list_item_string(obs_property_t *p, size_t idx);
 EXPORT long long   obs_property_list_item_int(obs_property_t *p, size_t idx);
 EXPORT double      obs_property_list_item_float(obs_property_t *p, size_t idx);
 
+EXPORT bool        obs_property_editable_list_allow_files(obs_property_t *p);
+EXPORT const char *obs_property_editable_list_filter(obs_property_t *p);
+EXPORT const char *obs_property_editable_list_default_path(obs_property_t *p);
+
 #ifdef __cplusplus
 }
 #endif