diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-10 23:54:14 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-10 23:54:14 +0300 |
commit | 969b4673c76696c872874f032c5535a1daf1eb84 (patch) | |
tree | 1b7f93d3efe4465b577c4bdb8b49be6721aba90c /source/blender/makesrna/intern | |
parent | 0ef0caaedf215320a8822053d6d67ccc75d56b63 (diff) |
Python/RNA: added collection.move(from, to) for python defined
collection properties.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 4cc5ca6f9df..6bd99793933 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -2172,6 +2172,34 @@ int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) return 0; } +int RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int key, int pos) +{ + IDProperty *idprop; + + if((idprop=rna_idproperty_check(&prop, ptr))) { + IDProperty tmp, *array; + int len; + + len= idprop->len; + array= IDP_IDPArray(idprop); + + if(key >= 0 && key < len && pos >= 0 && pos < len && key != pos) { + memcpy(&tmp, &array[key], sizeof(IDProperty)); + if(pos < key) + memmove(array+pos+1, array+pos, sizeof(IDProperty)*(key - pos)); + else + memmove(array+key, array+key+1, sizeof(IDProperty)*(pos - key)); + memcpy(&array[pos], &tmp, sizeof(IDProperty)); + } + + return 1; + } + else if(prop->flag & PROP_IDPROPERTY) + return 1; + + return 0; +} + void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop) { IDProperty *idprop; |