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 | |
parent | 0ef0caaedf215320a8822053d6d67ccc75d56b63 (diff) |
Python/RNA: added collection.move(from, to) for python defined
collection properties.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 89dd6a5c3e6..ae431beb1fe 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -742,6 +742,7 @@ void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr); int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key); void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop); +int RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int key, int pos); /* copy/reset */ int RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index); 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; |