SHIFT+S snap to frame for both Action and NLA window.
authorTon Roosendaal <ton@blender.org>
Sat, 29 Oct 2005 21:27:07 +0000 (21:27 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 29 Oct 2005 21:27:07 +0000 (21:27 +0000)
source/blender/include/BIF_editaction.h
source/blender/include/BIF_editnla.h
source/blender/include/BSE_editipo.h
source/blender/src/editaction.c
source/blender/src/editipo_mods.c
source/blender/src/editnla.c
source/blender/src/header_action.c
source/blender/src/header_nla.c

index 47ffb3fea0018439982824f66812c823eaeee524..3ca0bbdb1f847f3a4d733a9b965cba0bdb281ba8 100644 (file)
@@ -71,6 +71,7 @@ void transform_actionchannel_keys(int mode, int dummy);
 void transform_meshchannel_keys(char mode, struct Key *key);
 struct Key *get_action_mesh_key(void);
 int get_nearest_key_num(struct Key *key, short *mval, float *x);
+void set_snap_actionchannels(void);
 
 /* Handles */
 void sethandles_meshchannel_keys(int code, struct Key *key);
index b9ccfc60379cec770153054415a1735b312daa99..1b62de6a3171ef4113a373d90b004a35dbe5ad15 100644 (file)
@@ -52,6 +52,7 @@ void shift_nlastrips_up(void);
 void shift_nlastrips_down(void);
 void reset_action_strips(int val);
 void synchronize_action_strips(void);
+void snap_action_strips(void);
 
 
 #endif
index 4b3dbc283c4ab20e6997cbc184365485262ebbb6..729e49e2e8defa7fdccbbeed3ae442cf14651b52 100644 (file)
@@ -132,6 +132,7 @@ void sampledata_to_ipocurve(float *data, int sfra, int efra, struct IpoCurve *ic
 void ipo_record(void);    
 
 void sethandles_ipo_keys(struct Ipo *ipo, int code);
+void snap_ipo_keys(struct Ipo *ipo);
 void setipotype_ipo(struct Ipo *ipo, int code);
 void set_ipo_key_selection(struct Ipo *ipo, int sel);
 int is_ipo_key_selected(struct Ipo *ipo);
index 0ba59b073377d400e0c9111c1a94d997e1db45e6..bd7e978daec1f9fc1bc23d946fb42c440bff50cc 100644 (file)
@@ -1542,6 +1542,7 @@ void delete_actionchannel_keys(void)
        allqueue(REDRAWNLA, 0);
 
 }
+
 static void delete_actionchannels (void)
 {
        bConstraintChannel *conchan=NULL, *nextconchan;
@@ -1641,7 +1642,8 @@ void sethandles_actionchannel_keys(int code)
        allqueue(REDRAWNLA, 0);
 }
 
-void set_ipotype_actionchannels(int ipotype) {
+void set_ipotype_actionchannels(int ipotype) 
+{
 
        bAction *act; 
        bActionChannel *chan;
@@ -1687,6 +1689,35 @@ void set_ipotype_actionchannels(int ipotype) {
        allqueue(REDRAWNLA, 0);
 }
 
+void set_snap_actionchannels(void) 
+{
+       
+       bAction *act; 
+       bActionChannel *chan;
+       
+       /* Get the selected action, exit if none are selected 
+               */
+       act = G.saction->action;
+       if (!act)
+               return;
+       
+       /* Loop through the channels */
+       for (chan = act->chanbase.first; chan; chan=chan->next){
+               if (chan->ipo) {
+                       snap_ipo_keys(chan->ipo);
+               }
+       }
+       
+       /* Clean up and redraw stuff */
+       remake_action_ipos (act);
+       BIF_undo_push("Snap Ipo Action channel");
+       allspace(REMAKEIPO, 0);
+       allqueue(REDRAWACTION, 0);
+       allqueue(REDRAWIPO, 0);
+       allqueue(REDRAWNLA, 0);
+}
+
+
 static void select_all_keys_frames(bAction *act, short *mval, 
                                                        short *mvalo, int selectmode) {
        
@@ -2152,11 +2183,15 @@ void winqreadactionspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        
                case SKEY: 
                        if (mval[0]>=ACTWIDTH) {
-                               if (key) {
-                                       transform_meshchannel_keys('s', key);
+                               if(G.qual & LR_SHIFTKEY) {
+                                       if(okee("Snap to frame"))
+                                               set_snap_actionchannels();
                                }
-                               else if (act) {
-                                       transform_actionchannel_keys ('s', 0);
+                               else {
+                                       if (key)
+                                               transform_meshchannel_keys('s', key);
+                                       else if (act)
+                                               transform_actionchannel_keys ('s', 0);
                                }
                        }
                        break;
index 468e49b3ec8b541d51df33663647ab55804947ef..fc890a8bd9f5d673bf369c9cc5c1f067cef3fcb7 100644 (file)
@@ -549,8 +549,18 @@ void sethandles_ipo_keys(Ipo *ipo, int code)
                }
                break;
        }
+}
 
+static int snap_bezier(BezTriple *bezt)
+{
+       if(bezt->f2 & SELECT)
+               bezt->vec[1][0]= (float)(floor(bezt->vec[1][0]+0.5));
+       return 0;
+}
 
+void snap_ipo_keys(Ipo *ipo)
+{
+       ipo_keys_bezier_loop(ipo, snap_bezier, calchandles_ipocurve);
 }
 
 static void ipo_curves_auto_horiz(void)
index 790494d9d4493fad59038a581264692310764b3c..00857d3c841bd8d5f52a5a71e73cd3af32d9a419 100644 (file)
@@ -230,6 +230,24 @@ void reset_action_strips(int val)
        allqueue (REDRAWNLA, 0);
 }
 
+void snap_action_strips(void)
+{
+       Base *base;
+       bActionStrip *strip;
+       
+       for (base=G.scene->base.first; base; base=base->next) {
+               for (strip = base->object->nlastrips.last; strip; strip=strip->prev) {
+                       if (strip->flag & ACTSTRIP_SELECT) {
+                               strip->start= floor(strip->start+0.5);
+                       }
+               }
+       }
+       BIF_undo_push("Snap NLA strips");
+       allqueue (REDRAWVIEW3D, 0);
+       allqueue (REDRAWACTION, 0);
+       allqueue (REDRAWNLA, 0);
+}
+
 void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
@@ -334,6 +352,10 @@ void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(val==2)
                                        reset_action_strips(2);
                        }
+                       else if(G.qual & LR_SHIFTKEY) {
+                               if(okee("Snap Strips to Frame"))
+                                       snap_action_strips();
+                       }
                        else {
                                if (mval[0]>=NLAWIDTH)
                                        transform_nlachannel_keys ('s', 0);
index 55617c0bed5a9c3746b4bebf65c52d05fdbd07f2..cd3628ef8573d92fa7936954c16832de1a968a16 100644 (file)
@@ -91,6 +91,7 @@
 #define ACTMENU_KEY_DUPLICATE     0
 #define ACTMENU_KEY_DELETE        1
 #define ACTMENU_KEY_BAKE          2
+#define ACTMENU_KEY_SNAP          3
 
 #define ACTMENU_KEY_TRANSFORM_MOVE     0
 #define ACTMENU_KEY_TRANSFORM_SCALE    1
@@ -607,6 +608,9 @@ static void do_action_keymenu(void *arg, int event)
                case ACTMENU_KEY_BAKE:
                        bake_action_with_client (G.saction->action, OBACT, 0.01);
                        break;
+               case ACTMENU_KEY_SNAP:
+                       set_snap_actionchannels();
+                       break;
        }
 }
 
@@ -620,9 +624,12 @@ static uiBlock *action_keymenu(void *arg_unused)
        uiBlockSetButmFunc(block, do_action_keymenu, NULL);
        
        uiDefIconTextBlockBut(block, action_keymenu_transformmenu, 
-                                       NULL, ICON_RIGHTARROW_THIN, 
-                                       "Transform", 0, yco-=20, 120, 20, "");
-                                                 
+                                                 NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
+       
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
+                                        "Snap to Frame|Shift S", 0, yco-=20, 
+                                        menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_KEY_SNAP, "");
+       
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
                                        menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 
@@ -630,6 +637,7 @@ static uiBlock *action_keymenu(void *arg_unused)
                                        "Duplicate|Shift D", 0, yco-=20, 
                                        menuwidth, 19, NULL, 0.0, 0.0, 0, 
                                        ACTMENU_KEY_DUPLICATE, "");
+       
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
                                        "Delete|X", 0, yco-=20, 
                                        menuwidth, 19, NULL, 0.0, 0.0, 0, 
index 1f885c672152d4447e202ed132acc5b2e94d560d..636334e2e9a1c80b9a7f0d55db6ff73a86b0acee 100644 (file)
@@ -273,6 +273,9 @@ static void do_nla_stripmenu(void *arg, int event)
        case 9: /* reset start/end of action */
                reset_action_strips(2);
                break;
+       case 10: /* snap to frame */
+               snap_action_strips();
+               break;
        }
 }
 
@@ -288,6 +291,7 @@ static uiBlock *nla_stripmenu(void *arg_unused)
        uiDefIconTextBlockBut(block, nla_strip_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Strip Size|ALT S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Action Start/End|ALT S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
+       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Snap to Frame|Shift S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
        
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");