diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_rna.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 124 |
1 files changed, 106 insertions, 18 deletions
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index abded187b33..b1b7965286f 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -36,7 +36,7 @@ #include "rna_internal.h" -EnumPropertyItem rna_enum_property_type_items[] = { +const EnumPropertyItem rna_enum_property_type_items[] = { {PROP_BOOLEAN, "BOOLEAN", 0, "Boolean", ""}, {PROP_INT, "INT", 0, "Integer", ""}, {PROP_FLOAT, "FLOAT", 0, "Float", ""}, @@ -50,7 +50,7 @@ EnumPropertyItem rna_enum_property_type_items[] = { /* XXX Keep in sync with bpy_props.c's property_subtype_xxx_items ??? * Currently it is not... */ -EnumPropertyItem rna_enum_property_subtype_items[] = { +const EnumPropertyItem rna_enum_property_subtype_items[] = { {PROP_NONE, "NONE", 0, "None", ""}, /* strings */ @@ -90,7 +90,7 @@ EnumPropertyItem rna_enum_property_subtype_items[] = { {0, NULL, 0, NULL, NULL} }; -EnumPropertyItem rna_enum_property_unit_items[] = { +const EnumPropertyItem rna_enum_property_unit_items[] = { {PROP_UNIT_NONE, "NONE", 0, "None", ""}, {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""}, {PROP_UNIT_AREA, "AREA", 0, "Area", ""}, @@ -330,6 +330,16 @@ static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Function, internal->link); } +static void rna_Struct_property_tags_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + /* here ptr->data should always be the same as iter->parent.type */ + StructRNA *srna = (StructRNA *)ptr->data; + const EnumPropertyItem *tag_defines = RNA_struct_property_tag_defines(srna); + unsigned int tag_count = tag_defines ? RNA_enum_items_count(tag_defines) : 0; + + rna_iterator_array_begin(iter, (void *)tag_defines, sizeof(EnumPropertyItem), tag_count, 0, NULL); +} + /* Builtin properties iterator re-uses the Struct properties iterator, only * difference is that we need to set the ptr data to the type of the struct * whose properties we want to iterate over. */ @@ -603,6 +613,34 @@ static int rna_Property_is_library_editable_flag_get(PointerRNA *ptr) return (prop->flag & PROP_LIB_EXCEPTION) != 0; } +static int rna_Property_tags_get(PointerRNA *ptr) +{ + return RNA_property_tags(ptr->data); +} + +static const EnumPropertyItem *rna_Property_tags_itemf( + bContext *UNUSED(C), PointerRNA *ptr, + PropertyRNA *UNUSED(prop), bool *r_free) +{ + PropertyRNA *this_prop = (PropertyRNA *)ptr->data; + const StructRNA *srna = RNA_property_pointer_type(ptr, this_prop); + EnumPropertyItem *prop_tags; + EnumPropertyItem tmp = {0, "", 0, "", ""}; + int totitem = 0; + + for (const EnumPropertyItem *struct_tags = RNA_struct_property_tag_defines(srna); + struct_tags != NULL && struct_tags->identifier != NULL; + struct_tags++) + { + memcpy(&tmp, struct_tags, sizeof(tmp)); + RNA_enum_item_add(&prop_tags, &totitem, &tmp); + } + RNA_enum_item_end(&prop_tags, &totitem); + *r_free = true; + + return prop_tags; +} + static int rna_Property_array_length_get(PointerRNA *ptr) { PropertyRNA *prop = (PropertyRNA *)ptr->data; @@ -610,6 +648,22 @@ static int rna_Property_array_length_get(PointerRNA *ptr) return prop->totarraylength; } +static void rna_Property_array_dimensions_get(PointerRNA *ptr, int dimensions[RNA_MAX_ARRAY_DIMENSION]) +{ + PropertyRNA *prop = (PropertyRNA *)ptr->data; + rna_idproperty_check(&prop, ptr); + + if (prop->arraydimension > 1) { + for (int i = RNA_MAX_ARRAY_DIMENSION; i--; ) { + dimensions[i] = (i >= prop->arraydimension) ? 0 : prop->arraylength[i]; + } + } + else { + memset(dimensions, 0, sizeof(*dimensions) * RNA_MAX_ARRAY_DIMENSION); + dimensions[0] = prop->totarraylength; + } +} + static int rna_Property_is_registered_get(PointerRNA *ptr) { PropertyRNA *prop = (PropertyRNA *)ptr->data; @@ -808,7 +862,7 @@ static int rna_StringProperty_max_length_get(PointerRNA *ptr) return ((StringPropertyRNA *)prop)->maxlength; } -static EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C, PointerRNA *ptr, +static const EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop_parent, bool *r_free) { PropertyRNA *prop = (PropertyRNA *)ptr->data; @@ -854,7 +908,7 @@ static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, Point { PropertyRNA *prop = (PropertyRNA *)ptr->data; /* EnumPropertyRNA *eprop; *//* UNUSED */ - EnumPropertyItem *item = NULL; + const EnumPropertyItem *item = NULL; int totitem; bool free; @@ -983,21 +1037,32 @@ static int rna_Function_use_self_type_get(PointerRNA *ptr) /* Blender RNA */ +static int rna_struct_is_publc(CollectionPropertyIterator *UNUSED(iter), void *data) +{ + StructRNA *srna = data; + + return !(srna->flag & STRUCT_PUBLIC_NAMESPACE); +} + + static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { - rna_iterator_listbase_begin(iter, &((BlenderRNA *)ptr->data)->structs, NULL); + BlenderRNA *brna = ptr->data; + rna_iterator_listbase_begin(iter, &brna->structs, rna_struct_is_publc); } /* optional, for faster lookups */ static int rna_BlenderRNA_structs_length(PointerRNA *ptr) { - return BLI_listbase_count(&((BlenderRNA *)ptr->data)->structs); + BlenderRNA *brna = ptr->data; + BLI_assert(brna->structs_len == BLI_listbase_count(&brna->structs)); + return brna->structs_len; } static int rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) { - StructRNA *srna = BLI_findlink(&((BlenderRNA *)ptr->data)->structs, index); - - if (srna) { + BlenderRNA *brna = ptr->data; + StructRNA *srna = index < brna->structs_len ? BLI_findlink(&brna->structs, index) : NULL; + if (srna != NULL) { RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); return true; } @@ -1007,12 +1072,11 @@ static int rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, Pointer } static int rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { - StructRNA *srna = ((BlenderRNA *)ptr->data)->structs.first; - for (; srna; srna = srna->cont.next) { - if (key[0] == srna->identifier[0] && STREQ(key, srna->identifier)) { - RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); - return true; - } + BlenderRNA *brna = ptr->data; + StructRNA *srna = BLI_ghash_lookup(brna->structs_map, (void *)key); + if (srna != NULL) { + RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); + return true; } return false; @@ -1086,13 +1150,21 @@ static void rna_def_struct(BlenderRNA *brna) "rna_iterator_listbase_end", "rna_Struct_functions_get", NULL, NULL, NULL, NULL); RNA_def_property_ui_text(prop, "Functions", ""); + + prop = RNA_def_property(srna, "property_tags", PROP_COLLECTION, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "EnumPropertyItem"); + RNA_def_property_collection_funcs(prop, "rna_Struct_property_tags_begin", "rna_iterator_array_next", + "rna_iterator_array_end", "rna_iterator_array_get", + NULL, NULL, NULL, NULL); + RNA_def_property_ui_text(prop, "Property Tags", "Tags that properties can use to influence behavior"); } static void rna_def_property(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - static EnumPropertyItem subtype_items[] = { + static const EnumPropertyItem subtype_items[] = { {PROP_NONE, "NONE", 0, "None", ""}, {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""}, {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""}, @@ -1116,6 +1188,9 @@ static void rna_def_property(BlenderRNA *brna) {PROP_LAYER_MEMBER, "LAYER_MEMBERSHIP", 0, "Layer Membership", ""}, {0, NULL, 0, NULL, NULL} }; + EnumPropertyItem dummy_prop_tags[] = { + {0, NULL, 0, NULL, NULL} + }; srna = RNA_def_struct(brna, "Property", NULL); RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition"); @@ -1240,6 +1315,13 @@ static void rna_def_property(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_Property_is_library_editable_flag_get", NULL); RNA_def_property_ui_text(prop, "Library Editable", "Property is editable from linked instances (changes not saved)"); + + prop = RNA_def_property(srna, "tags", PROP_ENUM, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_enum_items(prop, dummy_prop_tags); + RNA_def_property_enum_funcs(prop, "rna_Property_tags_get", NULL, "rna_Property_tags_itemf"); + RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG); + RNA_def_property_ui_text(prop, "Tags", "Subset of tags (defined in parent struct) that are set for this property"); } static void rna_def_function(BlenderRNA *brna) @@ -1344,6 +1426,12 @@ static void rna_def_number_property(StructRNA *srna, PropertyType type) RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL, NULL); RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited"); + prop = RNA_def_property(srna, "array_dimensions", PROP_INT, PROP_UNSIGNED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_array(prop, RNA_MAX_ARRAY_DIMENSION); + RNA_def_property_int_funcs(prop, "rna_Property_array_dimensions_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Array Dimensions", "Length of each dimension of the array"); + prop = RNA_def_property(srna, "is_array", PROP_BOOLEAN, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_NumberProperty_is_array_get", NULL); @@ -1410,7 +1498,7 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) PropertyRNA *prop; /* the itemf func is used instead, keep blender happy */ - static EnumPropertyItem default_dummy_items[] = { + static const EnumPropertyItem default_dummy_items[] = { {PROP_NONE, "DUMMY", 0, "Dummy", ""}, {0, NULL, 0, NULL, NULL} }; |