bugfix [#25588] Not work fcurve.keyframe_points.add
The problem was flag-enums were being treated as regular enums, a default value of 0 was using the first enum item, whereas with flag enums we want to be able to use 0 as a default value to specify all flags are off.
This commit is contained in:
@@ -86,6 +86,7 @@ PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont, const char *iden
|
||||
PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description);
|
||||
|
||||
PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
|
||||
PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
|
||||
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc);
|
||||
|
||||
PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax);
|
||||
|
||||
@@ -2023,7 +2023,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
|
||||
switch(prop->type) {
|
||||
case PROP_ENUM: {
|
||||
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
|
||||
int i, defaultfound= 0;
|
||||
int i, defaultfound= 0, totflag= 0;
|
||||
|
||||
if(eprop->item) {
|
||||
fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
|
||||
@@ -2035,16 +2035,31 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
|
||||
rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
|
||||
rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
|
||||
|
||||
if(eprop->item[i].identifier[0])
|
||||
if(eprop->defaultvalue == eprop->item[i].value)
|
||||
defaultfound= 1;
|
||||
if(eprop->item[i].identifier[0]) {
|
||||
if(prop->flag & PROP_ENUM_FLAG) {
|
||||
totflag |= eprop->item[i].value;
|
||||
}
|
||||
else {
|
||||
if(eprop->defaultvalue == eprop->item[i].value) {
|
||||
defaultfound= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
|
||||
|
||||
if(!defaultfound) {
|
||||
fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
|
||||
DefRNA.error= 1;
|
||||
if(prop->flag & PROP_ENUM_FLAG) {
|
||||
if(eprop->defaultvalue & ~totflag) {
|
||||
fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default includes unused bits (%d).\n", srna->identifier, errnest, prop->identifier, eprop->defaultvalue & ~totflag);
|
||||
DefRNA.error= 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!defaultfound) {
|
||||
fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
|
||||
DefRNA.error= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -481,8 +481,7 @@ static void rna_def_ID(BlenderRNA *brna)
|
||||
func= RNA_def_function(srna, "update", "rna_ID_update");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
RNA_def_function_ui_description(func, "Tag the id to update its display data.");
|
||||
parm= RNA_def_enum(func, "refresh", update_flag_items, 0, "", "Type of updates to perform.");
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform.");
|
||||
}
|
||||
|
||||
static void rna_def_library(BlenderRNA *brna)
|
||||
|
||||
@@ -1393,20 +1393,36 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value)
|
||||
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
|
||||
eprop->defaultvalue= value;
|
||||
|
||||
for(i=0; i<eprop->totitem; i++) {
|
||||
if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
|
||||
defaultfound= 1;
|
||||
}
|
||||
|
||||
if(!defaultfound && eprop->totitem) {
|
||||
if(value == 0) {
|
||||
eprop->defaultvalue= eprop->item[0].value;
|
||||
if(prop->flag & PROP_ENUM_FLAG) {
|
||||
/* check all bits are accounted for */
|
||||
int totflag= 0;
|
||||
for(i=0; i<eprop->totitem; i++) {
|
||||
if(eprop->item[i].identifier[0]) {
|
||||
totflag |= eprop->item[i].value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
|
||||
|
||||
if(eprop->defaultvalue & ~totflag) {
|
||||
fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default includes unused bits (%d).\n", srna->identifier, prop->identifier, eprop->defaultvalue & ~totflag);
|
||||
DefRNA.error= 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=0; i<eprop->totitem; i++) {
|
||||
if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
|
||||
defaultfound= 1;
|
||||
}
|
||||
|
||||
if(!defaultfound && eprop->totitem) {
|
||||
if(value == 0) {
|
||||
eprop->defaultvalue= eprop->item[0].value;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
|
||||
DefRNA.error= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -2212,6 +2228,27 @@ PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, co
|
||||
return prop;
|
||||
}
|
||||
|
||||
/* same as above but sets 'PROP_ENUM_FLAG' before setting the default value */
|
||||
PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value,
|
||||
const char *ui_name, const char *ui_description)
|
||||
{
|
||||
ContainerRNA *cont= cont_;
|
||||
PropertyRNA *prop;
|
||||
|
||||
if(!items) {
|
||||
printf("RNA_def_enum_flag: items not allowed to be NULL.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
|
||||
if(items) RNA_def_property_enum_items(prop, items);
|
||||
RNA_def_property_enum_default(prop, default_value);
|
||||
RNA_def_property_ui_text(prop, ui_name, ui_description);
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
|
||||
{
|
||||
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
|
||||
|
||||
@@ -1333,8 +1333,7 @@ static void rna_def_fcurve_keyframe_points(BlenderRNA *brna, PropertyRNA *cprop)
|
||||
parm= RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "", "Y Value of this keyframe point", -FLT_MAX, FLT_MAX);
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
|
||||
parm= RNA_def_enum(func, "options", keyframe_flag_items, 0, "", "Keyframe options.");
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
RNA_def_enum_flag(func, "options", keyframe_flag_items, 0, "", "Keyframe options.");
|
||||
|
||||
parm= RNA_def_pointer(func, "keyframe", "Keyframe", "", "Newly created keyframe");
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
@@ -93,8 +93,7 @@ static void rna_generic_op_invoke(FunctionRNA *func, int flag)
|
||||
}
|
||||
|
||||
if(flag & WM_GEN_INVOKE_RETURN) {
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
|
||||
RNA_def_function_return(func, parm);
|
||||
}
|
||||
}
|
||||
@@ -146,8 +145,8 @@ void RNA_api_operator(StructRNA *srna)
|
||||
|
||||
/* utility, not for registering */
|
||||
func= RNA_def_function(srna, "report", "rna_Operator_report");
|
||||
parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
|
||||
@@ -167,8 +166,7 @@ void RNA_api_operator(StructRNA *srna)
|
||||
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
|
||||
RNA_def_pointer(func, "context", "Context", "", "");
|
||||
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* check */
|
||||
@@ -187,8 +185,7 @@ void RNA_api_operator(StructRNA *srna)
|
||||
RNA_def_pointer(func, "context", "Context", "", "");
|
||||
RNA_def_pointer(func, "event", "Event", "", "");
|
||||
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
func= RNA_def_function(srna, "modal", NULL); /* same as invoke */
|
||||
@@ -197,8 +194,7 @@ void RNA_api_operator(StructRNA *srna)
|
||||
RNA_def_pointer(func, "context", "Context", "", "");
|
||||
RNA_def_pointer(func, "event", "Event", "", "");
|
||||
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* draw */
|
||||
@@ -215,8 +211,8 @@ void RNA_api_macro(StructRNA *srna)
|
||||
|
||||
/* utility, not for registering */
|
||||
func= RNA_def_function(srna, "report", "rna_Operator_report");
|
||||
parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
|
||||
parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user