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:
authorCampbell Barton <ideasman42@gmail.com>2011-06-23 09:58:44 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-06-23 09:58:44 +0400
commitf51140969707a3aeea4c681b4548ae51df2f7593 (patch)
tree699077b02987503454613cf1b77b9ef82c45ca5e /source/blender/makesrna
parentfb1ded6572eb87b31034e720cabe239dbfa7abc7 (diff)
fix [#27726] Driven properties not checked for legal UI bounds
The rna set function clamps to the property range however properties with range functions were ignored when set by python or the animation system. Now call the range function for ints and floats when setting.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/makesrna.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index f3f539feb99..2c62316780d 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -644,6 +644,25 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
return func;
}
+/* defined min/max variables to be used by rna_clamp_value() */
+static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
+{
+ if(prop->type == PROP_FLOAT) {
+ FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
+ if(fprop->range) {
+ fprintf(f, " float prop_clamp_min, prop_clamp_max;\n");
+ fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(fprop->range));
+ }
+ }
+ else if(prop->type == PROP_INT) {
+ IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
+ if(iprop->range) {
+ fprintf(f, " int prop_clamp_min, prop_clamp_max;\n");
+ fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(iprop->range));
+ }
+ }
+}
+
static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
{
if(prop->type == PROP_INT) {
@@ -652,8 +671,13 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
if(array) fprintf(f, "CLAMPIS(values[i], ");
else fprintf(f, "CLAMPIS(value, ");
- rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
- rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
+ if(iprop->range) {
+ fprintf(f, "prop_clamp_min, prop_clamp_max);");
+ }
+ else {
+ rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
+ rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
+ }
return;
}
}
@@ -663,8 +687,13 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
if(array) fprintf(f, "CLAMPIS(values[i], ");
else fprintf(f, "CLAMPIS(value, ");
- rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
- rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
+ if(fprop->range) {
+ fprintf(f, "prop_clamp_min, prop_clamp_max);");
+ }
+ else {
+ rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
+ rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
+ }
return;
}
}
@@ -762,6 +791,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
}
else {
rna_print_data_get(f, dp);
+ rna_clamp_value_range(f, prop);
if(prop->flag & PROP_DYNAMIC) {
char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set_length");
@@ -833,6 +863,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
fprintf(f, " data->%s |= value;\n", dp->dnaname);
}
else {
+ rna_clamp_value_range(f, prop);
fprintf(f, " data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
rna_clamp_value(f, prop, 0);
}