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/makesrna/intern/rna_define.c | |
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/makesrna/intern/rna_define.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 57 |
1 files changed, 47 insertions, 10 deletions
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; |