Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/RNA_define.h1
-rw-r--r--source/blender/makesrna/RNA_types.h26
-rw-r--r--source/blender/makesrna/intern/makesrna.c27
-rw-r--r--source/blender/makesrna/intern/rna_access.c18
-rw-r--r--source/blender/makesrna/intern/rna_define.c22
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h2
7 files changed, 97 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 54e077c624c..39a46948321 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -845,6 +845,7 @@ const char *RNA_property_description(PropertyRNA *prop);
PropertyType RNA_property_type(PropertyRNA *prop);
PropertySubType RNA_property_subtype(PropertyRNA *prop);
PropertyUnit RNA_property_unit(PropertyRNA *prop);
+PropertyScaleType RNA_property_ui_scale(PropertyRNA *prop);
int RNA_property_flag(PropertyRNA *prop);
int RNA_property_override_flag(PropertyRNA *prop);
int RNA_property_tags(PropertyRNA *prop);
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 17309d847bd..a31182b2f5a 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -388,6 +388,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value);
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description);
void RNA_def_property_ui_range(
PropertyRNA *prop, double min, double max, double step, int precision);
+void RNA_def_property_ui_scale_type(PropertyRNA *prop, PropertyScaleType scale_type);
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive);
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *updatefunc);
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 6cd3678017e..4a6d6dddec7 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -95,6 +95,32 @@ typedef enum PropertyUnit {
PROP_UNIT_TEMPERATURE = (11 << 16), /* C */
} PropertyUnit;
+/**
+ * Use values besides #PROP_SCALE_LINEAR
+ * so the movement of the mouse doesn't map linearly to the value of the slider.
+ *
+ * For some settings it's useful to space motion in a non-linear way, see T77868.
+ *
+ * NOTE: The scale types are available for all float sliders.
+ * For integer sliders they are only available if they use the visible value bar.
+ * Sliders with logarithmic scale and value bar must have a range > 0
+ * while logarithmic sliders without the value bar can have a range of >= 0.
+ */
+typedef enum PropertyScaleType {
+ /** Linear scale (default). */
+ PROP_SCALE_LINEAR = 0,
+ /**
+ * Logarithmic scale
+ * - Maximum range: `0 <= x < inf`
+ */
+ PROP_SCALE_LOG = 1,
+ /**
+ * Cubic scale.
+ * - Maximum range: `-inf < x < inf`
+ */
+ PROP_SCALE_CUBIC = 2,
+} PropertyScaleType;
+
#define RNA_SUBTYPE_UNIT(subtype) ((subtype)&0x00FF0000)
#define RNA_SUBTYPE_VALUE(subtype) ((subtype) & ~0x00FF0000)
#define RNA_SUBTYPE_UNIT_VALUE(subtype) ((subtype) >> 16)
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index b20d9218316..ef65a99c73b 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -684,6 +684,29 @@ static char *rna_def_property_get_func(
}
}
}
+
+ /* Check log scale sliders for negative range. */
+ if (prop->type == PROP_FLOAT) {
+ FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
+ /* NOTE: UI_BTYPE_NUM_SLIDER can't have a softmin of zero. */
+ if ((fprop->ui_scale_type == PROP_SCALE_LOG) && (fprop->hardmin < 0 || fprop->softmin < 0)) {
+ CLOG_ERROR(
+ &LOG, "\"%s.%s\", range for log scale < 0.", srna->identifier, prop->identifier);
+ DefRNA.error = true;
+ return NULL;
+ }
+ }
+ if (prop->type == PROP_INT) {
+ IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
+ /* Only UI_BTYPE_NUM_SLIDER is implemented and that one can't have a softmin of zero. */
+ if ((iprop->ui_scale_type == PROP_SCALE_LOG) &&
+ (iprop->hardmin <= 0 || iprop->softmin <= 0)) {
+ CLOG_ERROR(
+ &LOG, "\"%s.%s\", range for log scale <= 0.", srna->identifier, prop->identifier);
+ DefRNA.error = true;
+ return NULL;
+ }
+ }
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
@@ -3935,6 +3958,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
rna_function_string(iprop->getarray_ex),
rna_function_string(iprop->setarray_ex),
rna_function_string(iprop->range_ex));
+ rna_int_print(f, iprop->ui_scale_type);
+ fprintf(f, ", ");
rna_int_print(f, iprop->softmin);
fprintf(f, ", ");
rna_int_print(f, iprop->softmax);
@@ -3969,6 +3994,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
rna_function_string(fprop->getarray_ex),
rna_function_string(fprop->setarray_ex),
rna_function_string(fprop->range_ex));
+ rna_float_print(f, fprop->ui_scale_type);
+ fprintf(f, ", ");
rna_float_print(f, fprop->softmin);
fprintf(f, ", ");
rna_float_print(f, fprop->softmax);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 9b57096ec19..150a455f1c7 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1189,6 +1189,24 @@ PropertyUnit RNA_property_unit(PropertyRNA *prop)
return RNA_SUBTYPE_UNIT(RNA_property_subtype(prop));
}
+PropertyScaleType RNA_property_ui_scale(PropertyRNA *prop)
+{
+ PropertyRNA *rna_prop = rna_ensure_property(prop);
+
+ switch (rna_prop->type) {
+ case PROP_INT: {
+ IntPropertyRNA *iprop = (IntPropertyRNA *)rna_prop;
+ return iprop->ui_scale_type;
+ }
+ case PROP_FLOAT: {
+ FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_prop;
+ return fprop->ui_scale_type;
+ }
+ default:
+ return PROP_SCALE_LINEAR;
+ }
+}
+
int RNA_property_flag(PropertyRNA *prop)
{
return rna_ensure_property(prop)->flag;
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 2fdf7e5eaa7..9b9d561603b 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -1754,6 +1754,28 @@ void RNA_def_property_ui_range(
}
}
+void RNA_def_property_ui_scale_type(PropertyRNA *prop, PropertyScaleType ui_scale_type)
+{
+ StructRNA *srna = DefRNA.laststruct;
+
+ switch (prop->type) {
+ case PROP_INT: {
+ IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
+ iprop->ui_scale_type = ui_scale_type;
+ break;
+ }
+ case PROP_FLOAT: {
+ FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
+ fprop->ui_scale_type = ui_scale_type;
+ break;
+ }
+ default:
+ CLOG_ERROR(&LOG, "\"%s.%s\", invalid type for scale.", srna->identifier, prop->identifier);
+ DefRNA.error = true;
+ break;
+ }
+}
+
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
{
StructRNA *srna = DefRNA.laststruct;
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index 0c0260c889c..245730919b0 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -400,6 +400,7 @@ typedef struct IntPropertyRNA {
PropIntArraySetFuncEx setarray_ex;
PropIntRangeFuncEx range_ex;
+ PropertyScaleType ui_scale_type;
int softmin, softmax;
int hardmin, hardmax;
int step;
@@ -423,6 +424,7 @@ typedef struct FloatPropertyRNA {
PropFloatArraySetFuncEx setarray_ex;
PropFloatRangeFuncEx range_ex;
+ PropertyScaleType ui_scale_type;
float softmin, softmax;
float hardmin, hardmax;
float step;