diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-13 17:29:57 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-13 17:29:57 +0300 |
commit | e2054b291c35cfd9b4e020b584ec465007ecd189 (patch) | |
tree | 220ccdbf9d5d8cd9af7fe816a795dad529892fa1 /source/blender | |
parent | d4fa68e448a1808c6ca5628840a8940aefe263b3 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 29 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 57 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fcurve.c | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 20 |
6 files changed, 80 insertions, 33 deletions
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 3a8e2e4f80e..f4693ae941e 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -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); diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index cf1b14d5e62..94b075c20c0 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -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 { diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index efef72913c9..a428c811061 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -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) diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index a72777726c2..b6b0bd3ae84 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -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; diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 12ecf15816a..5aa1e8e836f 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index e043db7d9d6..b934bdfc979 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -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); |