Revision: 26666
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26666
Author:   aligorith
Date:     2010-02-07 12:50:03 +0100 (Sun, 07 Feb 2010)

Log Message:
-----------
DopeSheet and Graph Editors: Select More/Less Operators

This commit introduces the Select More/Less Operators (Ctrl +/-) for keyframes. 
This works like the ones for curves, by only selecting/deselecting keyframes 
lying in the same F-Curve. Inter F-Curve selection is not done by this 
operator. That is the job for another one. 

This is especially useful for F-Curves set in the 0-1-0 pattern (i.e. 3 
keyframes forming localised peaks), where the peaks can be selected by clicking 
on them individually, and immediately surrounding '0' values are selected too 
using "Select More".

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_dopesheet.py
    trunk/blender/release/scripts/ui/space_graph.py
    trunk/blender/source/blender/editors/animation/keyframes_edit.c
    trunk/blender/source/blender/editors/include/ED_keyframes_edit.h
    trunk/blender/source/blender/editors/space_action/action_intern.h
    trunk/blender/source/blender/editors/space_action/action_ops.c
    trunk/blender/source/blender/editors/space_action/action_select.c
    trunk/blender/source/blender/editors/space_graph/graph_intern.h
    trunk/blender/source/blender/editors/space_graph/graph_ops.c
    trunk/blender/source/blender/editors/space_graph/graph_select.c

Modified: trunk/blender/release/scripts/ui/space_dopesheet.py
===================================================================
--- trunk/blender/release/scripts/ui/space_dopesheet.py 2010-02-07 11:17:19 UTC 
(rev 26665)
+++ trunk/blender/release/scripts/ui/space_dopesheet.py 2010-02-07 11:50:03 UTC 
(rev 26666)
@@ -119,7 +119,11 @@
         layout.operator("action.select_column", text="Columns on Selected 
Markers").mode = 'MARKERS_COLUMN'
         layout.operator("action.select_column", text="Between Selected 
Markers").mode = 'MARKERS_BETWEEN'
 
+        layout.separator()
+        layout.operator("action.select_more")
+        layout.operator("action.select_less")
 
+
 class DOPESHEET_MT_channel(bpy.types.Menu):
     bl_label = "Channel"
 

Modified: trunk/blender/release/scripts/ui/space_graph.py
===================================================================
--- trunk/blender/release/scripts/ui/space_graph.py     2010-02-07 11:17:19 UTC 
(rev 26665)
+++ trunk/blender/release/scripts/ui/space_graph.py     2010-02-07 11:50:03 UTC 
(rev 26666)
@@ -122,7 +122,11 @@
         layout.operator("graph.select_column", text="Columns on Selected 
Markers").mode = 'MARKERS_COLUMN'
         layout.operator("graph.select_column", text="Between Selected 
Markers").mode = 'MARKERS_BETWEEN'
 
+        layout.separator()
+        layout.operator("graph.select_more")
+        layout.operator("graph.select_less")
 
+
 class GRAPH_MT_channel(bpy.types.Menu):
     bl_label = "Channel"
 

Modified: trunk/blender/source/blender/editors/animation/keyframes_edit.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframes_edit.c     
2010-02-07 11:17:19 UTC (rev 26665)
+++ trunk/blender/source/blender/editors/animation/keyframes_edit.c     
2010-02-07 11:50:03 UTC (rev 26666)
@@ -90,19 +90,22 @@
 short ANIM_fcurve_keys_bezier_loop(BeztEditData *bed, FCurve *fcu, 
BeztEditFunc bezt_ok, BeztEditFunc bezt_cb, FcuEditFunc fcu_cb) 
 {
     BezTriple *bezt;
-       int b;
        
        /* sanity check */
        if (ELEM(NULL, fcu, fcu->bezt))
                return 0;
        
+       /* set the F-Curve into the editdata so that it can be accessed */
+       bed->fcu= fcu;
+       bed->curIndex= 0;
+       
        /* if function to apply to bezier curves is set, then loop through 
executing it on beztriples */
     if (bezt_cb) {
                /* if there's a validation func, include that check in the loop 
                 * (this is should be more efficient than checking for it in 
every loop)
                 */
                if (bezt_ok) {
-                       for (b=0, bezt=fcu->bezt; b < fcu->totvert; b++, 
bezt++) {
+                       for (bed->curIndex=0, bezt=fcu->bezt; bed->curIndex < 
fcu->totvert; bed->curIndex++, bezt++) {
                                /* Only operate on this BezTriple if it 
fullfills the criteria of the validation func */
                                if (bezt_ok(bed, bezt)) {
                                        /* Exit with return-code '1' if 
function returns positive
@@ -113,7 +116,7 @@
                        }
                }
                else {
-                       for (b=0, bezt=fcu->bezt; b < fcu->totvert; b++, 
bezt++) {
+                       for (bed->curIndex=0, bezt=fcu->bezt; bed->curIndex < 
fcu->totvert; bed->curIndex++, bezt++) {
                                /* Exit with return-code '1' if function 
returns positive
                                 * This is useful if finding if some BezTriple 
satisfies a condition.
                                 */
@@ -121,6 +124,10 @@
                        }
                }
     }
+       
+       /* unset the F-Curve from the editdata now that it's done */
+       bed->fcu= NULL;
+       bed->curIndex= 0;
 
     /* if fcu_cb (F-Curve post-editing callback) has been specified then 
execute it */
     if (fcu_cb)
@@ -786,6 +793,8 @@
 }
 
 /* Queries if the handle should be set to 'free' or 'align' */
+// NOTE: this was used for the 'toggle free/align' option
+//             currently this isn't used, but may be restored later
 static short bezier_isfree(BeztEditData *bed, BezTriple *bezt) 
 {
        if ((bezt->f1 & SELECT) && (bezt->h1)) return 1;
@@ -951,3 +960,123 @@
                        return select_bezier_add;
        }
 }
+
+/* ******************************************* */
+/* Selection Maps */
+
+/* Selection maps are simply fancy names for char arrays that store on/off
+ * info for whether the selection status. The main purpose for these is to
+ * allow extra info to be tagged to the keyframes without influencing their
+ * values or having to be removed later.
+ */
+
+/* ----------- */
+
+static short selmap_build_bezier_more(BeztEditData *bed, BezTriple *bezt)
+{
+       FCurve *fcu= bed->fcu;
+       char *map= bed->data;
+       int i= bed->curIndex;
+       
+       /* if current is selected, just make sure it stays this way */
+       if (BEZSELECTED(bezt)) {
+               map[i]= 1;
+               return 0;
+       }
+       
+       /* if previous is selected, that means that selection should extend 
across */
+       if (i > 0) {
+               BezTriple *prev= bezt - 1;
+               
+               if (BEZSELECTED(prev)) {
+                       map[i]= 1;
+                       return 0;
+               }
+       }
+       
+       /* if next is selected, that means that selection should extend across 
*/
+       if (i < (fcu->totvert-1)) {
+               BezTriple *next= bezt + 1;
+               
+               if (BEZSELECTED(next)) {
+                       map[i]= 1;
+                       return 0;
+               }
+       }
+       
+       return 0;
+}
+
+static short selmap_build_bezier_less(BeztEditData *bed, BezTriple *bezt)
+{
+       FCurve *fcu= bed->fcu;
+       char *map= bed->data;
+       int i= bed->curIndex;
+       
+       /* if current is selected, check the left/right keyframes
+        * since it might need to be deselected (but otherwise no)
+        */
+       if (BEZSELECTED(bezt)) {
+               /* if previous is not selected, we're on the tip of an iceberg 
*/
+               if (i > 0) {
+                       BezTriple *prev= bezt - 1;
+                       
+                       if (BEZSELECTED(prev) == 0)
+                               return 0;
+               }
+               else if (i == 0) {
+                       /* current keyframe is selected at an endpoint, so 
should get deselected */
+                       return 0;
+               }
+               
+               /* if next is not selected, we're on the tip of an iceberg */
+               if (i < (fcu->totvert-1)) {
+                       BezTriple *next= bezt + 1;
+                       
+                       if (BEZSELECTED(next) == 0)
+                               return 0;
+               }
+               else if (i == (fcu->totvert-1)) {
+                       /* current keyframe is selected at an endpoint, so 
should get deselected */
+                       return 0;
+               }
+               
+               /* if we're still here, that means that keyframe should remain 
untouched */
+               map[i]= 1;
+       }
+       
+       return 0;
+}
+
+/* Get callback for building selection map */
+BeztEditFunc ANIM_editkeyframes_buildselmap(short mode)
+{
+       switch (mode) {
+               case SELMAP_LESS: /* less */
+                       return selmap_build_bezier_less;
+               
+               case SELMAP_MORE: /* more */
+               default:
+                       return selmap_build_bezier_more;
+       }
+}
+
+/* ----------- */
+
+/* flush selection map values to the given beztriple */
+short bezt_selmap_flush(BeztEditData *bed, BezTriple *bezt)
+{
+       char *map= bed->data;
+       short on= map[bed->curIndex];
+       
+       /* select or deselect based on whether the map allows it or not */
+       if (on) {
+               BEZ_SEL(bezt);
+       }
+       else {
+               BEZ_DESEL(bezt);
+       }
+       
+       return 0;
+}
+

Modified: trunk/blender/source/blender/editors/include/ED_keyframes_edit.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_keyframes_edit.h    
2010-02-07 11:17:19 UTC (rev 26665)
+++ trunk/blender/source/blender/editors/include/ED_keyframes_edit.h    
2010-02-07 11:50:03 UTC (rev 26666)
@@ -58,7 +58,7 @@
 
 /* ------------ */
 
-/* select tools */
+/* select modes */
 typedef enum eEditKeyframes_Select {
        SELECT_REPLACE  =       (1<<0),
        SELECT_ADD              =       (1<<1),
@@ -66,6 +66,12 @@
        SELECT_INVERT   =       (1<<4),
 } eEditKeyframes_Select;
 
+/* "selection map" building modes */
+typedef enum eEditKeyframes_SelMap {
+       SELMAP_MORE     = 0,
+       SELMAP_LESS,
+} eEditKeyframes_SelMap;
+
 /* snapping tools */
 typedef enum eEditKeyframes_Snap {
        SNAP_KEYS_CURFRAME = 1,
@@ -91,11 +97,16 @@
 /* --- Generic Properties for Bezier Edit Tools ----- */
 
 typedef struct BeztEditData {
+               /* generic properties/data access */
        ListBase list;                          /* temp list for storing custom 
list of data to check */
        struct Scene *scene;            /* pointer to current scene - many 
tools need access to cfra/etc.  */
        void *data;                                     /* pointer to custom 
data - usually 'Object' but also 'rectf', but could be other types too */
        float f1, f2;                           /* storage of times/values as 
'decimals' */
        int i1, i2;                                     /* storage of 
times/values/flags as 'whole' numbers */
+       
+               /* current iteration data */
+       struct FCurve *fcu;                     /* F-Curve that is being 
iterated over */
+       int curIndex;                           /* index of current keyframe 
being iterated over */
 } BeztEditData;
 
 /* ------- Function Pointer Typedefs ---------------- */
@@ -143,6 +154,18 @@
 BeztEditFunc ANIM_editkeyframes_ipo(short mode);
 BeztEditFunc ANIM_editkeyframes_keytype(short mode);
 
+/* -------- BezTriple Callbacks (Selection Map) ---------- */
+
+/* Get a callback to populate the selection settings map  
+ * requires: bed->custom = char[] of length fcurve->totvert 
+ */
+BeztEditFunc ANIM_editkeyframes_buildselmap(short mode);
+
+/* Change the selection status of the keyframe based on the map entry for this 
vert
+ * requires: bed->custom = char[] of length fcurve->totvert
+ */
+short bezt_selmap_flush(BeztEditData *bed, struct BezTriple *bezt);
+
 /* ----------- BezTriple Callback (Assorted Utilities) ---------- */
 
 /* used to calculate the the average location of all relevant BezTriples by 
summing their locations */

Modified: trunk/blender/source/blender/editors/space_action/action_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_intern.h   
2010-02-07 11:17:19 UTC (rev 26665)
+++ trunk/blender/source/blender/editors/space_action/action_intern.h   
2010-02-07 11:50:03 UTC (rev 26666)
@@ -56,6 +56,8 @@
 void ACTION_OT_select_all_toggle(struct wmOperatorType *ot);
 void ACTION_OT_select_border(struct wmOperatorType *ot);
 void ACTION_OT_select_column(struct wmOperatorType *ot);
+void ACTION_OT_select_more(struct wmOperatorType *ot);
+void ACTION_OT_select_less(struct wmOperatorType *ot);
 void ACTION_OT_clickselect(struct wmOperatorType *ot);
 
 /* defines for left-right select tool */

Modified: trunk/blender/source/blender/editors/space_action/action_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_ops.c      
2010-02-07 11:17:19 UTC (rev 26665)
+++ trunk/blender/source/blender/editors/space_action/action_ops.c      
2010-02-07 11:50:03 UTC (rev 26666)
@@ -67,6 +67,8 @@
        WM_operatortype_append(ACTION_OT_select_all_toggle);
        WM_operatortype_append(ACTION_OT_select_border);
        WM_operatortype_append(ACTION_OT_select_column);
+       WM_operatortype_append(ACTION_OT_select_more);
+       WM_operatortype_append(ACTION_OT_select_less);
        
                /* editing */
        WM_operatortype_append(ACTION_OT_snap);
@@ -122,6 +124,11 @@

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to