浏览代码

libobs: Add int/float slider properties

This optionally specifies that the int/float value should be displayed
with a slider rather than and up/down control.  UIs are not necessarily
required to implement it, it's meant to be more of a hint.
jp9000 10 年之前
父节点
当前提交
0a8e3a643c
共有 2 个文件被更改,包括 63 次插入4 次删除
  1. 48 4
      libobs/obs-properties.c
  2. 15 0
      libobs/obs-properties.h

+ 48 - 4
libobs/obs-properties.c

@@ -26,10 +26,12 @@ static inline void *get_property_data(struct obs_property *prop);
 
 struct float_data {
 	double min, max, step;
+	enum obs_number_type type;
 };
 
 struct int_data {
 	int min, max, step;
+	enum obs_number_type type;
 };
 
 struct list_item {
@@ -301,8 +303,9 @@ obs_property_t *obs_properties_add_bool(obs_properties_t *props,
 	return new_prop(props, name, desc, OBS_PROPERTY_BOOL);
 }
 
-obs_property_t *obs_properties_add_int(obs_properties_t *props,
-		const char *name, const char *desc, int min, int max, int step)
+static obs_property_t *add_int(obs_properties_t *props,
+		const char *name, const char *desc, int min, int max, int step,
+		enum obs_number_type type)
 {
 	if (!props || has_prop(props, name)) return NULL;
 
@@ -311,12 +314,14 @@ obs_property_t *obs_properties_add_int(obs_properties_t *props,
 	data->min  = min;
 	data->max  = max;
 	data->step = step;
+	data->type = type;
 	return p;
 }
 
-obs_property_t *obs_properties_add_float(obs_properties_t *props,
+static obs_property_t *add_flt(obs_properties_t *props,
 		const char *name, const char *desc,
-		double min, double max, double step)
+		double min, double max, double step,
+		enum obs_number_type type)
 {
 	if (!props || has_prop(props, name)) return NULL;
 
@@ -326,9 +331,36 @@ obs_property_t *obs_properties_add_float(obs_properties_t *props,
 	data->min  = min;
 	data->max  = max;
 	data->step = step;
+	data->type = type;
 	return p;
 }
 
+obs_property_t *obs_properties_add_int(obs_properties_t *props,
+		const char *name, const char *desc, int min, int max, int step)
+{
+	return add_int(props, name, desc, min, max, step, OBS_NUMBER_SCROLLER);
+}
+
+obs_property_t *obs_properties_add_float(obs_properties_t *props,
+		const char *name, const char *desc,
+		double min, double max, double step)
+{
+	return add_flt(props, name, desc, min, max, step, OBS_NUMBER_SCROLLER);
+}
+
+obs_property_t *obs_properties_add_int_slider(obs_properties_t *props,
+		const char *name, const char *desc, int min, int max, int step)
+{
+	return add_int(props, name, desc, min, max, step, OBS_NUMBER_SLIDER);
+}
+
+obs_property_t *obs_properties_add_float_slider(obs_properties_t *props,
+		const char *name, const char *desc,
+		double min, double max, double step)
+{
+	return add_flt(props, name, desc, min, max, step, OBS_NUMBER_SLIDER);
+}
+
 obs_property_t *obs_properties_add_text(obs_properties_t *props,
 		const char *name, const char *desc, enum obs_text_type type)
 {
@@ -521,6 +553,12 @@ int obs_property_int_step(obs_property_t *p)
 	return data ? data->step : 0;
 }
 
+enum obs_number_type obs_property_int_type(obs_property_t *p)
+{
+	struct int_data *data = get_type_data(p, OBS_PROPERTY_INT);
+	return data ? data->type : OBS_NUMBER_SCROLLER;
+}
+
 double obs_property_float_min(obs_property_t *p)
 {
 	struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
@@ -539,6 +577,12 @@ double obs_property_float_step(obs_property_t *p)
 	return data ? data->step : 0;
 }
 
+enum obs_number_type obs_property_float_type(obs_property_t *p)
+{
+	struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
+	return data ? data->type : OBS_NUMBER_SCROLLER;
+}
+
 enum obs_text_type obs_proprety_text_type(obs_property_t *p)
 {
 	struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT);

+ 15 - 0
libobs/obs-properties.h

@@ -78,6 +78,11 @@ enum obs_text_type {
 	OBS_TEXT_MULTILINE,
 };
 
+enum obs_number_type {
+	OBS_NUMBER_SCROLLER,
+	OBS_NUMBER_SLIDER
+};
+
 #define OBS_FONT_BOLD      (1<<0)
 #define OBS_FONT_ITALIC    (1<<1)
 #define OBS_FONT_UNDERLINE (1<<2)
@@ -135,6 +140,14 @@ EXPORT obs_property_t *obs_properties_add_float(obs_properties_t *props,
 		const char *name, const char *description,
 		double min, double max, double step);
 
+EXPORT obs_property_t *obs_properties_add_int_slider(obs_properties_t *props,
+		const char *name, const char *description,
+		int min, int max, int step);
+
+EXPORT obs_property_t *obs_properties_add_float_slider(obs_properties_t *props,
+		const char *name, const char *description,
+		double min, double max, double step);
+
 EXPORT obs_property_t *obs_properties_add_text(obs_properties_t *props,
 		const char *name, const char *description,
 		enum obs_text_type type);
@@ -216,9 +229,11 @@ EXPORT bool                   obs_property_next(obs_property_t **p);
 EXPORT int                    obs_property_int_min(obs_property_t *p);
 EXPORT int                    obs_property_int_max(obs_property_t *p);
 EXPORT int                    obs_property_int_step(obs_property_t *p);
+EXPORT enum obs_number_type   obs_property_int_type(obs_property_t *p);
 EXPORT double                 obs_property_float_min(obs_property_t *p);
 EXPORT double                 obs_property_float_max(obs_property_t *p);
 EXPORT double                 obs_property_float_step(obs_property_t *p);
+EXPORT enum obs_number_type   obs_property_float_type(obs_property_t *p);
 EXPORT enum obs_text_type     obs_proprety_text_type(obs_property_t *p);
 EXPORT enum obs_path_type     obs_property_path_type(obs_property_t *p);
 EXPORT const char *           obs_property_path_filter(obs_property_t *p);