[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46643] trunk/blender/source/blender/ makesrna/intern/rna_sequencer_api.c: SequenceElements.pop() -- added 'index ' argument instead of just chopping off the last element

Dan Eicher dan.eicher at gmail.com
Mon May 14 23:32:37 CEST 2012


Revision: 46643
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46643
Author:   dna
Date:     2012-05-14 21:32:35 +0000 (Mon, 14 May 2012)
Log Message:
-----------
SequenceElements.pop() -- added 'index' argument instead of just chopping off the last element

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_sequencer_api.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_sequencer_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_sequencer_api.c	2012-05-14 20:59:08 UTC (rev 46642)
+++ trunk/blender/source/blender/makesrna/intern/rna_sequencer_api.c	2012-05-14 21:32:35 UTC (rev 46643)
@@ -316,19 +316,34 @@
 	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 @@
 	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)




More information about the Bf-blender-cvs mailing list