[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12494] trunk/blender/source/blender: == " Extend" Transform Mode for Action + NLA Editors ==

Joshua Leung aligorith at gmail.com
Tue Nov 6 12:41:09 CET 2007


Revision: 12494
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12494
Author:   aligorith
Date:     2007-11-06 12:41:09 +0100 (Tue, 06 Nov 2007)

Log Message:
-----------
== "Extend" Transform Mode for Action + NLA Editors ==

Peach Request:
Now the Action and NLA editors have the "Extend" transform mode first seen in the Sequence Editor. Just use the EKEY to start transforming.

It works like Grab, except it only moves the keyframes/side of NLA-strip that was on the same side of the current-frame marker as the mouse was when transform started.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_transform.h
    trunk/blender/source/blender/src/editaction.c
    trunk/blender/source/blender/src/editnla.c
    trunk/blender/source/blender/src/header_action.c
    trunk/blender/source/blender/src/header_nla.c
    trunk/blender/source/blender/src/transform.c
    trunk/blender/source/blender/src/transform_conversions.c

Modified: trunk/blender/source/blender/include/BIF_transform.h
===================================================================
--- trunk/blender/source/blender/include/BIF_transform.h	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/include/BIF_transform.h	2007-11-06 11:41:09 UTC (rev 12494)
@@ -58,6 +58,7 @@
 #define TFM_TIME_TRANSLATE	19	
 #define TFM_TIME_SLIDE		20
 #define	TFM_TIME_SCALE		21
+#define TFM_TIME_EXTEND		22
 
 /* TRANSFORM CONTEXTS */
 #define CTX_NONE			0

Modified: trunk/blender/source/blender/src/editaction.c
===================================================================
--- trunk/blender/source/blender/src/editaction.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/editaction.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -739,6 +739,12 @@
 			Transform();
 		}
 			break;
+		case 'e':
+		{
+			initTransform(TFM_TIME_EXTEND, CTX_NONE);
+			Transform();
+		}
+		break;
 	}
 }
 
@@ -2645,7 +2651,12 @@
 					duplicate_action_keys();
 			}
 			break;
-
+			
+		case EKEY:
+			if (mval[0] >= ACTWIDTH) 
+				transform_action_keys('e', 0);
+			break;
+		
 		case GKEY:
 			if (G.qual & LR_CTRLKEY) {
 				transform_markers('g', 0);

Modified: trunk/blender/source/blender/src/editnla.c
===================================================================
--- trunk/blender/source/blender/src/editnla.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/editnla.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -995,6 +995,12 @@
 			Transform();
 		}
 			break;
+		case 'e':
+		{
+			initTransform(TFM_TIME_EXTEND, CTX_NONE);
+			Transform();
+		}
+			break;
 	}
 }
 
@@ -1791,6 +1797,13 @@
 				
 				break;
 				
+			case EKEY:
+				if (mval[0] >= NLAWIDTH) {
+					transform_nlachannel_keys ('e', 0);
+					update_for_newframe_muted();
+				}
+				break;
+				
 			case GKEY:
 				if (mval[0]>=NLAWIDTH) {
 					if (G.qual & LR_CTRLKEY) {

Modified: trunk/blender/source/blender/src/header_action.c
===================================================================
--- trunk/blender/source/blender/src/header_action.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/header_action.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -114,7 +114,6 @@
 enum {
 	ACTMENU_KEY_DUPLICATE = 0,
 	ACTMENU_KEY_DELETE,
-	ACTMENU_KEY_BAKE,
 	ACTMENU_KEY_CLEAN
 };
 
@@ -128,7 +127,8 @@
 enum {
 	ACTMENU_KEY_TRANSFORM_MOVE  = 0,
 	ACTMENU_KEY_TRANSFORM_SCALE,
-	ACTMENU_KEY_TRANSFORM_SLIDE
+	ACTMENU_KEY_TRANSFORM_SLIDE,
+	ACTMENU_KEY_TRANSFORM_EXTEND
 };
 
 enum {
@@ -594,6 +594,9 @@
 		case ACTMENU_KEY_TRANSFORM_SLIDE:
 			transform_action_keys('t', 0);
 			break;
+		case ACTMENU_KEY_TRANSFORM_EXTEND:
+			transform_action_keys('e', 0);
+			break;
 	}
 
 	scrarea_queue_winredraw(curarea);
@@ -612,6 +615,9 @@
 					 "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
 					 ACTMENU_KEY_TRANSFORM_MOVE, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
+					 "Grab/Extend from Frame|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
+					 ACTMENU_KEY_TRANSFORM_EXTEND, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
 					 "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
 					 ACTMENU_KEY_TRANSFORM_SCALE, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 

Modified: trunk/blender/source/blender/src/header_nla.c
===================================================================
--- trunk/blender/source/blender/src/header_nla.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/header_nla.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -269,13 +269,17 @@
 {
 	switch(event) {
 	case 0: /* grab/move */
-		transform_nlachannel_keys ('g', 0);
-			update_for_newframe_muted();
+		transform_nlachannel_keys('g', 0);
+		update_for_newframe_muted();
 		break;
 	case 1: /* scale */
-		transform_nlachannel_keys ('s', 0);
-			update_for_newframe_muted();
+		transform_nlachannel_keys('s', 0);
+		update_for_newframe_muted();
 		break;
+	case 2: /* extend */
+		transform_nlachannel_keys('e', 0);
+		update_for_newframe_muted();
+		break;
 	}
 	allqueue(REDRAWVIEW3D, 0);
 }
@@ -289,8 +293,10 @@
 	uiBlockSetButmFunc(block, do_nla_strip_transformmenu, NULL);
 	
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G",		0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Extend from Frame|E",	0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale|S",		0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
-
+	
+	
 	uiBlockSetDirection(block, UI_RIGHT);
 	uiTextBoundsBlock(block, 60);
 	return block;

Modified: trunk/blender/source/blender/src/transform.c
===================================================================
--- trunk/blender/source/blender/src/transform.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/transform.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -938,6 +938,7 @@
 
 	/* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
 	/* EVIL2: we gave as argument also texture space context bit... was cleared */
+	/* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
 	mode = Trans.mode;
 	
 	calculatePropRatio(&Trans);
@@ -1004,6 +1005,10 @@
 	case TFM_TIME_SCALE:
 		initTimeScale(&Trans);
 		break;
+	case TFM_TIME_EXTEND: 
+		/* now that transdata has been made, do like for TFM_TIME_TRANSLATE */
+		initTimeTranslate(&Trans);
+		break;
 	}
 }
 

Modified: trunk/blender/source/blender/src/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/src/transform_conversions.c	2007-11-06 11:36:01 UTC (rev 12493)
+++ trunk/blender/source/blender/src/transform_conversions.c	2007-11-06 11:41:09 UTC (rev 12494)
@@ -113,6 +113,7 @@
 #include "BIF_toolbox.h"
 
 #include "BSE_view.h"
+#include "BSE_drawipo.h"
 #include "BSE_edit.h"
 #include "BSE_editipo.h"
 #include "BSE_editipo_types.h"
@@ -2049,7 +2050,48 @@
 
 /* ********************* ACTION/NLA EDITOR ****************** */
 
+/* This function tests if a point is on the "mouse" side of the cursor/frame-marking */
+static short FrameOnMouseSide(char side, float frame, float cframe)
+{
+	/* both sides, so it doesn't matter */
+	if (side == 'B') return 1;
+	
+	/* only on the named side */
+	if (side == 'R')
+		return (frame >= cframe) ? 1 : 0;
+	else
+		return (frame <= cframe) ? 1 : 0;
+}
 
+/* fully select selected beztriples, but only include if it's on the right side of cfra */
+static int count_ipo_keys(Ipo *ipo, char side, float cfra)
+{
+	IpoCurve *icu;
+	BezTriple *bezt;
+	int i, count = 0;
+	
+	if (ipo == NULL)
+		return count;
+	
+	/* only include points that occur on the right side of cfra */
+	for (icu= ipo->curve.first; icu; icu= icu->next) {
+		for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
+			if (bezt->f2) {
+				/* fully select the other two keys */
+				bezt->f1 |= 1;
+				bezt->f3 |= 1;
+				
+				/* increment by 3, as there are 3 points (3 * x-coordinates) that need transform */
+				if (FrameOnMouseSide(side, bezt->vec[1][0], cfra))
+					count += 3;
+			}
+		}
+	}
+	
+	return count;
+}
+
+/* This function assigns the information to transdata */
 static void TimeToTransData(TransData *td, float *time, Object *ob)
 {
 	/* memory is calloc'ed, so that should zero everything nicely for us */
@@ -2065,9 +2107,12 @@
 
 /* This function advances the address to which td points to, so it must return
  * the new address so that the next time new transform data is added, it doesn't
- * overwrite the existing ones...  i.e.   td = IpoToTransData(td, ipo, ob);
+ * overwrite the existing ones...  i.e.   td = IpoToTransData(td, ipo, ob, side, cfra);
+ *
+ * The 'side' argument is needed for the extend mode. 'B' = both sides, 'R'/'L' mean only data
+ * on the named side are used. 
  */
-static TransData *IpoToTransData(TransData *td, Ipo *ipo, Object *ob)
+static TransData *IpoToTransData(TransData *td, Ipo *ipo, Object *ob, char side, float cfra)
 {
 	IpoCurve *icu;
 	BezTriple *bezt;
@@ -2077,18 +2122,21 @@
 		return td;
 	
 	for (icu= ipo->curve.first; icu; icu= icu->next) {
-		/* only add selected keyframes (for now, proportional edit is not enabled) */
 		for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
+			/* only add selected keyframes (for now, proportional edit is not enabled) */
 			if (BEZSELECTED(bezt)) {
-				/* each control point needs to be added separetely */
-				TimeToTransData(td, bezt->vec[0], ob);
-				td++;
-				
-				TimeToTransData(td, bezt->vec[1], ob);
-				td++;
-				
-				TimeToTransData(td, bezt->vec[2], ob);
-				td++;
+				/* only add if on the right 'side' of the current frame */
+				if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
+					/* each control point needs to be added separetely */
+					TimeToTransData(td, bezt->vec[0], ob);
+					td++;
+					
+					TimeToTransData(td, bezt->vec[1], ob);
+					td++;
+					
+					TimeToTransData(td, bezt->vec[2], ob);
+					td++;
+				}
 			}	
 		}
 	}
@@ -2108,6 +2156,8 @@
 	int filter;
 	
 	int count=0;
+	float cfra;
+	char side;
 	
 	/* determine what type of data we are operating on */
 	data = get_action_context(&datatype);
@@ -2120,10 +2170,31 @@
 	/* is the action scaled? if so, the it should belong to the active object */
 	if (NLA_ACTION_SCALED)
 		ob= OBACT;
+		
+	/* which side of the current frame should be allowed */
+	if (t->mode == TFM_TIME_EXTEND) {
+		/* only side on which mouse is gets transformed */
+		float xmouse, ymouse;
+		
+		areamouseco_to_ipoco(G.v2d, t->imval, &xmouse, &ymouse);
+		side = (xmouse > CFRA) ? 'R' : 'L';
+	}
+	else {
+		/* normal transform - both sides of current frame are considered */
+		side = 'B';
+	}
 	
+	/* convert current-frame to action-time (slightly less accurate, espcially under
+	 * higher scaling ratios, but is faster than converting all points) 
+	 */
+	if (ob) 
+		cfra = get_action_frame(ob, CFRA);
+	else
+		cfra = CFRA;
+	
 	/* loop 1: fully select ipo-keys and count how many BezTriples are selected */
 	for (ale= act_data.first; ale; ale= ale->next)
-		count += fullselect_ipo_keys(ale->key_data);
+		count += count_ipo_keys(ale->key_data, side, cfra);
 	
 	/* stop if trying to build list if nothing selected */
 	if (count == 0) {
@@ -2143,7 +2214,7 @@
 	for (ale= act_data.first; ale; ale= ale->next) {
 		Ipo *ipo= (Ipo *)ale->key_data;
 		
-		td= IpoToTransData(td, ipo, ob);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list