Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2006-11-07 21:34:32 +0300
committerTon Roosendaal <ton@blender.org>2006-11-07 21:34:32 +0300
commit2e93510a6b137487c89d35f09065f9f1cad81c72 (patch)
tree648f6383668fbbe2219f1e584982f506d1b95fab /source
parenta221ddcf9bb44d81037fa1cff3fddb70e4e3f521 (diff)
Patch #5028. by Joshua Leung (aligorith)
Key snapping in Action Window, cleanup and added option to snap to current frame.
Diffstat (limited to 'source')
-rw-r--r--source/blender/include/BIF_editaction.h4
-rw-r--r--source/blender/include/BSE_editipo.h2
-rw-r--r--source/blender/src/editaction.c91
-rw-r--r--source/blender/src/editipo_mods.c23
-rw-r--r--source/blender/src/header_action.c2
5 files changed, 95 insertions, 27 deletions
diff --git a/source/blender/include/BIF_editaction.h b/source/blender/include/BIF_editaction.h
index 2644ad01092..2e882942d02 100644
--- a/source/blender/include/BIF_editaction.h
+++ b/source/blender/include/BIF_editaction.h
@@ -77,7 +77,9 @@ 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);
+void snap_keys_to_frame(void);
+
+/* channel/strip operations */
void up_sel_action(void);
void down_sel_action(void);
void top_sel_action(void);
diff --git a/source/blender/include/BSE_editipo.h b/source/blender/include/BSE_editipo.h
index 2f98c047dc9..b60cd98b80c 100644
--- a/source/blender/include/BSE_editipo.h
+++ b/source/blender/include/BSE_editipo.h
@@ -135,7 +135,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 snap_ipo_keys(struct Ipo *ipo, short snaptype);
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);
diff --git a/source/blender/src/editaction.c b/source/blender/src/editaction.c
index 6858d2329bd..3561300f72f 100644
--- a/source/blender/src/editaction.c
+++ b/source/blender/src/editaction.c
@@ -1997,41 +1997,91 @@ void set_extendtype_actionchannels(int extendtype)
allqueue(REDRAWNLA, 0);
}
-void set_snap_actionchannels(void)
+static void set_snap_actionchannels(bAction *act, short snaptype)
{
-
- bAction *act;
+ /* snapping function for action channels*/
bActionChannel *chan;
bConstraintChannel *conchan;
- /* 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->flag & ACHAN_HIDDEN)==0) {
if (chan->ipo) {
- snap_ipo_keys(chan->ipo);
+ snap_ipo_keys(chan->ipo, snaptype);
}
/* constraint channels */
for (conchan=chan->constraintChannels.first; conchan; conchan= conchan->next) {
if (conchan->ipo) {
- snap_ipo_keys(conchan->ipo);
+ snap_ipo_keys(conchan->ipo, snaptype);
}
}
}
}
-
- /* 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 set_snap_meshchannels(Key *key, short snaptype)
+{
+ /* snapping function for mesh channels */
+ if(key->ipo) {
+ snap_ipo_keys(key->ipo, snaptype);
+ }
+}
+
+
+void snap_keys_to_frame()
+{
+ /* This function is the generic entry-point for snapping keyframes
+ * to a frame(s). It passes the work off to sub-functions for the
+ * different types in the action editor.
+ */
+
+ SpaceAction *saction;
+ bAction *act;
+ Key *key;
+ short event;
+
+ /* get data */
+ saction= curarea->spacedata.first;
+ if (!saction) return;
+ act = saction->action;
+ key = get_action_mesh_key();
+
+ /* find the type of snapping to do */
+ event = pupmenu("Snap Frames To%t|Nearest Frame%x1|Current Frame%x2");
+
+ /* handle events */
+ switch (event) {
+ case 1: /* snap to nearest frame */
+ if (act)
+ set_snap_actionchannels(act, event);
+ else
+ set_snap_meshchannels(key, event);
+
+ /* Clean up and redraw stuff */
+ remake_action_ipos (act);
+ BIF_undo_push("Snap To Nearest Frame");
+ allspace(REMAKEIPO, 0);
+ allqueue(REDRAWACTION, 0);
+ allqueue(REDRAWIPO, 0);
+ allqueue(REDRAWNLA, 0);
+
+ break;
+ case 2: /* snap to current frame */
+ if (act)
+ set_snap_actionchannels(act, event);
+ else
+ set_snap_meshchannels(key, event);
+
+ /* Clean up and redraw stuff */
+ remake_action_ipos (act);
+ BIF_undo_push("Snap To Current Frame");
+ allspace(REMAKEIPO, 0);
+ allqueue(REDRAWACTION, 0);
+ allqueue(REDRAWIPO, 0);
+ allqueue(REDRAWNLA, 0);
+
+ break;
+ }
}
@@ -2517,8 +2567,7 @@ void winqreadactionspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
case SKEY:
if (mval[0]>=ACTWIDTH) {
if(G.qual & LR_SHIFTKEY) {
- if(okee("Snap to frame"))
- set_snap_actionchannels();
+ snap_keys_to_frame();
}
else {
if (key)
diff --git a/source/blender/src/editipo_mods.c b/source/blender/src/editipo_mods.c
index 39a05573145..581d293b079 100644
--- a/source/blender/src/editipo_mods.c
+++ b/source/blender/src/editipo_mods.c
@@ -555,16 +555,33 @@ void sethandles_ipo_keys(Ipo *ipo, int code)
}
}
-static int snap_bezier(BezTriple *bezt)
+static int snap_bezier_nearest(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)
+static int snap_bezier_cframe(BezTriple *bezt)
{
- ipo_keys_bezier_loop(ipo, snap_bezier, calchandles_ipocurve);
+ if(bezt->f2 & SELECT)
+ bezt->vec[1][0]= (float)CFRA;
+ return 0;
+}
+
+void snap_ipo_keys(Ipo *ipo, short snaptype)
+{
+ switch (snaptype) {
+ case 1: /* snap to nearest */
+ ipo_keys_bezier_loop(ipo, snap_bezier_nearest, calchandles_ipocurve);
+ break;
+ case 2: /* snap to current frame */
+ ipo_keys_bezier_loop(ipo, snap_bezier_cframe, calchandles_ipocurve);
+ break;
+ default: /* just in case */
+ ipo_keys_bezier_loop(ipo, snap_bezier_nearest, calchandles_ipocurve);
+ break;
+ }
}
static void ipo_curves_auto_horiz(void)
diff --git a/source/blender/src/header_action.c b/source/blender/src/header_action.c
index 2109d915cda..5ab3d4d3657 100644
--- a/source/blender/src/header_action.c
+++ b/source/blender/src/header_action.c
@@ -778,7 +778,7 @@ static void do_action_keymenu(void *arg, int event)
bake_action_with_client (G.saction->action, OBACT, 0.01);
break;
case ACTMENU_KEY_SNAP:
- set_snap_actionchannels();
+ snap_keys_to_frame();
break;
}
}