[Bf-committers] [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

Campbell Barton ideasman42 at gmail.com
Wed Jun 6 08:04:23 CEST 2012


This should really use 1-2 memcpy calls rather then looping over
elements and calling strcpy.
The original width and height are currently not copied - and if any
new elements are added we'd have to remember to add them here too.

On Mon, May 14, 2012 at 11:32 PM, Dan Eicher <dan.eicher at gmail.com> wrote:
> 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)
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs



-- 
- Campbell


More information about the Bf-committers mailing list