diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-04-17 19:03:41 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-04-17 19:07:08 +0300 |
commit | 75f82ac7223719b400c1a137cafe3027cd3a2536 (patch) | |
tree | a770e55f194573df092c9544a972be3159922329 /source/blender/makesrna | |
parent | fad7c065c213347685ee6c3d5884e55123ca8efb (diff) |
Update/improve handling of 'overridable' status of properties.
Main new thing in this commit is ability for real IDProps (aka custom
properties) to be set as overridable or not, they are not by default.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 39 |
2 files changed, 33 insertions, 9 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index d991e28a648..5947324826e 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -890,7 +890,8 @@ bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index); bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop); /* without lib check, only checks the flag */ bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop); bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop); -bool RNA_property_overridable(PointerRNA *ptr, PropertyRNA *prop); +bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop); +bool RNA_property_overridable_static_set(PointerRNA *ptr, PropertyRNA *prop, const bool is_overridable); bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop); bool RNA_property_comparable(PointerRNA *ptr, PropertyRNA *prop); bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop); /* slow, use with care */ diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index f7733957de9..a9a83c6d37b 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1852,7 +1852,7 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop) return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 && (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) && - (!id->override_static || RNA_property_overridable(ptr, prop))))); + (!id->override_static || RNA_property_overridable_get(ptr, prop))))); } /** @@ -1885,7 +1885,7 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char * } return false; } - if (id->override_static != NULL && !RNA_property_overridable(ptr, prop)) { + if (id->override_static != NULL && !RNA_property_overridable_get(ptr, prop)) { if (!(*r_info)[0]) { *r_info = N_("Can't edit this property from an override data-block."); } @@ -1966,13 +1966,34 @@ bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop) /** \note Does not take into account editable status, this has to be checked separately * (using RNA_property_edtiable_flag() usually). */ -bool RNA_property_overridable(PointerRNA *UNUSED(ptr), PropertyRNA *prop) +bool RNA_property_overridable_get(PointerRNA *UNUSED(ptr), PropertyRNA *prop) { - prop = rna_ensure_property(prop); + if (prop->magic == RNA_MAGIC) { + /* If this is a RNA-defined property (real or 'virtual' IDProp), we want to use RNA prop flag. */ + return !(prop->flag & PROP_NO_COMPARISON) && (prop->flag & PROP_OVERRIDABLE_STATIC); + } + else { + /* If this is a real 'pure' IDProp (aka custom property), we want to use the IDProp flag. */ + return !(prop->flag & PROP_NO_COMPARISON) && (((IDProperty *)prop)->flag & IDP_FLAG_OVERRIDABLE_STATIC); + } +} + +/* Should only be used for custom properties */ +bool RNA_property_overridable_static_set(PointerRNA *UNUSED(ptr), PropertyRNA *prop, const bool is_overridable) +{ + /* Only works for pure custom properties IDProps. */ + if (prop->magic != RNA_MAGIC) { + IDProperty *idprop = (IDProperty *)prop; + + idprop->flag = is_overridable ? (idprop->flag | IDP_FLAG_OVERRIDABLE_STATIC) : + (idprop->flag & ~IDP_FLAG_OVERRIDABLE_STATIC); + return true; + } - return !(prop->flag & PROP_NO_COMPARISON) && (prop->flag & PROP_OVERRIDABLE_STATIC); + return false; } + bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop) { char *rna_path = RNA_path_from_ID_to_property(ptr, prop); @@ -7286,7 +7307,7 @@ static int rna_property_override_diff( bool override_changed = false; int diff_flags = flags; - if (!RNA_property_overridable(ptr_a, prop_a)) { + if (!RNA_property_overridable_get(ptr_a, prop_a)) { diff_flags &= ~RNA_OVERRIDE_COMPARE_CREATE; } const int diff = override_diff( @@ -7472,7 +7493,7 @@ bool RNA_struct_override_matches( continue; } - if (ignore_non_overridable && !RNA_property_overridable(ptr_local, prop_local)) { + if (ignore_non_overridable && !RNA_property_overridable_get(ptr_local, prop_local)) { continue; } @@ -7500,6 +7521,8 @@ bool RNA_struct_override_matches( continue; } +// printf("Override Checking %s\n", rna_path); + if (ignore_overridden && BKE_override_static_property_find(override, rna_path) != NULL) { MEM_SAFE_FREE(rna_path); continue; @@ -7731,7 +7754,7 @@ eRNAOverrideStatus RNA_property_override_status(PointerRNA *ptr, PropertyRNA *pr return override_status; } - if (RNA_property_overridable(ptr, prop) && RNA_property_editable_flag(ptr, prop)) { + if (RNA_property_overridable_get(ptr, prop) && RNA_property_editable_flag(ptr, prop)) { override_status |= RNA_OVERRIDE_STATUS_OVERRIDABLE; } |