diff options
author | Dan Eicher <dan@eu.phorio.us> | 2012-05-15 01:32:35 +0400 |
---|---|---|
committer | Dan Eicher <dan@eu.phorio.us> | 2012-05-15 01:32:35 +0400 |
commit | 8f2c8480751ed9c1abaa56dc7b3b941605d42f76 (patch) | |
tree | 4e3bf1b0f0dcef0a4606db6a0f943cdc259de010 /source/blender/makesrna/intern/rna_sequencer_api.c | |
parent | 0de912b82d453ac7f886a794bd192be65a2b0aa9 (diff) |
SequenceElements.pop() -- added 'index' argument instead of just chopping off the last element
Diffstat (limited to 'source/blender/makesrna/intern/rna_sequencer_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_sequencer_api.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index 38a923f87e5..41c6f046c04 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -316,19 +316,34 @@ static StripElem *rna_SequenceElements_push(ID *id, Sequence *seq, const char *f return se; } -static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports) +static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports, int index) { + int i; Scene *scene = (Scene *)id; + StripElem *new_seq, *se; if (seq->len == 1) { BKE_report(reports, RPT_ERROR, "SequenceElements.pop: can not pop the last element"); return; } - /* just chop off the end ...what could possibly go wrong? */ - seq->strip->stripdata = MEM_reallocN(seq->strip->stripdata, sizeof(StripElem) * (seq->len - 1)); + if (seq->len <= index) { + BKE_report(reports, RPT_ERROR, "SequenceElements.pop: index out of range"); + return; + } + + new_seq = MEM_callocN(sizeof(StripElem) * (seq->len - 1), "SequenceElements_pop"); seq->len--; + for (i = 0, se = seq->strip->stripdata; i < seq->len; i++, se++) { + if (i == index) + se++; + BLI_strncpy(new_seq[i].name, se->name, sizeof(se->name)); + } + + MEM_freeN(seq->strip->stripdata); + seq->strip->stripdata = new_seq; + calc_sequence_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -379,6 +394,8 @@ void RNA_api_sequence_elements(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "pop", "rna_SequenceElements_pop"); RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); RNA_def_function_ui_description(func, "Pop an image off the collection"); + parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of image to remove", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); } void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop) |