[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23998] trunk/blender/source/blender: Graph Editor: Added 2D Cursor

Joshua Leung aligorith at gmail.com
Tue Oct 20 14:04:56 CEST 2009


Revision: 23998
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23998
Author:   aligorith
Date:     2009-10-20 14:04:56 +0200 (Tue, 20 Oct 2009)

Log Message:
-----------
Graph Editor: Added 2D Cursor

I've finally given in, and implemented a '2d-cursor' for the Graph Editor. This is simply represented as an additional horizontal line that meets with the current frame indicator, forming a cross-hair. It can be disabled from the View menu.

Currently, the only tool which takes this into account is the Snapping tools (Shift-S), where I've hooked up a tool I added some time ago. 

TODO:
- expose this cursor to the transform tools for scaling/rotation options...

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/animation/anim_ops.c
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_header.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/space_graph.c
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -156,7 +156,7 @@
 	glScalef(xscale, 1.0, 1.0);
 }
 
-/* General call for drawing current frame indicator in a */
+/* General call for drawing current frame indicator in animation editor */
 void ANIM_draw_cfra (const bContext *C, View2D *v2d, short flag)
 {
 	Scene *scene= CTX_data_scene(C);

Modified: trunk/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_ops.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/animation/anim_ops.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -62,6 +62,18 @@
 
 /* ********************** frame change operator ***************************/
 
+/* Check if the operator can be run from the current context */
+static int change_frame_poll(bContext *C)
+{
+	ScrArea *curarea= CTX_wm_area(C);
+	
+	/* as long as there is an active area, and it isn't a Graph Editor 
+	 * (since the Graph Editor has its own version which does extra stuff),
+	 * we're fine
+	 */
+	return ((curarea) && (curarea->spacetype != SPACE_IPO));
+}
+
 /* Set any flags that are necessary to indicate modal time-changing operation */
 static int change_frame_init(bContext *C, wmOperator *op)
 {
@@ -85,18 +97,12 @@
 static void change_frame_apply(bContext *C, wmOperator *op)
 {
 	Scene *scene= CTX_data_scene(C);
-	int cfra;
 	
-	/* get frame, and clamp to MINAFRAME 
-	 *	- not MINFRAME, since it's useful to be able to key a few-frames back
-	 */
-	cfra= RNA_int_get(op->ptr, "frame");
+	/* set the new frame number */
+	CFRA= RNA_int_get(op->ptr, "frame");
 	
-	if (cfra < MINAFRAME) cfra= MINAFRAME;
-	CFRA= cfra;
-	
+	/* do updates */
 	sound_scrub(C);
-
 	WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
 }
 
@@ -210,12 +216,14 @@
 	/* identifiers */
 	ot->name= "Change frame";
 	ot->idname= "ANIM_OT_change_frame";
+	ot->description= "Interactively change the current frame number.";
 	
 	/* api callbacks */
 	ot->exec= change_frame_exec;
 	ot->invoke= change_frame_invoke;
 	ot->cancel= change_frame_cancel;
 	ot->modal= change_frame_modal;
+	ot->poll= change_frame_poll;
 	
 	/* flags */
 	ot->flag= OPTYPE_BLOCKING;

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/armature/editarmature.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -5037,11 +5037,11 @@
 	
 	/*	Set the flags */
 	CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pchans) {
-		/* select pchan, only if selectable */
-		if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) {
-			if (sel==0) pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE);
-			else pchan->bone->flag |= BONE_SELECTED;
-		}
+		/* select pchan only if selectable, but deselect works always */
+		if (sel==0) 
+			pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE);
+		else if ((pchan->bone->flag & BONE_UNSELECTABLE)==0)
+			pchan->bone->flag |= BONE_SELECTED;
 	}
 	CTX_DATA_END;	
 
@@ -5313,21 +5313,7 @@
 			/* we have the object using the armature */
 			if (arm==ob->data) {
 				Object *cob;
-				//bAction  *act;
-				//bActionChannel *achan;
-				//bActionStrip *strip;
 				
-				/* Rename action channel if necessary */
-#if 0 // XXX old animation system
-				act = ob->action;
-				if (act && !act->id.lib) {
-					/*	Find the appropriate channel */
-					achan= get_action_channel(act, oldname);
-					if (achan) 
-						BLI_strncpy(achan->name, newname, MAXBONENAME);
-				}
-#endif // XXX old animation system
-		
 				/* Rename the pose channel, if it exists */
 				if (ob->pose) {
 					bPoseChannel *pchan = get_pose_channel(ob->pose, oldname);
@@ -5335,20 +5321,6 @@
 						BLI_strncpy(pchan->name, newname, MAXBONENAME);
 				}
 				
-				/* check all nla-strips too */
-#if 0 // XXX old animation system
-				for (strip= ob->nlastrips.first; strip; strip= strip->next) {
-					/* Rename action channel if necessary */
-					act = strip->act;
-					if (act && !act->id.lib) {
-						/*	Find the appropriate channel */
-						achan= get_action_channel(act, oldname);
-						if (achan) 
-							BLI_strncpy(achan->name, newname, MAXBONENAME);
-					}
-				}
-#endif // XXX old animation system
-				
 				/* Update any object constraints to use the new bone name */
 				for (cob= G.main->object.first; cob; cob= cob->id.next) {
 					if (cob->constraints.first)
@@ -5381,35 +5353,12 @@
 			}
 			
 			/* Fix animation data attached to this object */
+			// TODO: should we be using the database wide version instead (since drivers may break)
 			if (ob->adt) {
 				/* posechannels only... */
 				BKE_animdata_fix_paths_rename(&ob->id, ob->adt, "pose.pose_channels", oldname, newname);
 			}
 		}
-		
-		/* do entire db - ipo's for the drivers */
-#if 0 // XXX old animation system
-		for (ipo= G.main->ipo.first; ipo; ipo= ipo->id.next) {
-			IpoCurve *icu;
-			
-			/* check each curve's driver */
-			for (icu= ipo->curve.first; icu; icu= icu->next) {
-				IpoDriver *icd= icu->driver;
-				
-				if ((icd) && (icd->ob)) {
-					ob= icd->ob;
-					
-					if (icu->driver->type == IPO_DRIVER_TYPE_NORMAL) {
-						if (!strcmp(oldname, icd->name))
-							BLI_strncpy(icd->name, newname, MAXBONENAME);
-					}
-					else {
-						/* TODO: pydrivers need to be treated differently */
-					}
-				}
-			}			
-		}
-#endif // XXX old animation system
 	}
 }
 

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -1450,7 +1450,8 @@
 
 /* defines for snap keyframes tool */
 EnumPropertyItem prop_graphkeys_snap_types[] = {
-	{GRAPHKEYS_SNAP_CFRA, "CFRA", 0, "Current frame", ""},
+	{GRAPHKEYS_SNAP_CFRA, "CFRA", 0, "Current Frame", ""},
+	{GRAPHKEYS_SNAP_VALUE, "VALUE", 0, "Cursor Value", ""},
 	{GRAPHKEYS_SNAP_NEAREST_FRAME, "NEAREST_FRAME", 0, "Nearest Frame", ""}, // XXX as single entry?
 	{GRAPHKEYS_SNAP_NEAREST_SECOND, "NEAREST_SECOND", 0, "Nearest Second", ""}, // XXX as single entry?
 	{GRAPHKEYS_SNAP_NEAREST_MARKER, "NEAREST_MARKER", 0, "Nearest Marker", ""},
@@ -1481,6 +1482,10 @@
 		bed.list.first= (ac->markers) ? ac->markers->first : NULL;
 		bed.list.last= (ac->markers) ? ac->markers->last : NULL;
 	}
+	else if (mode == GRAPHKEYS_SNAP_VALUE) {
+		SpaceIpo *sipo= (SpaceIpo *)ac->sa->spacedata.first;
+		bed.f1= (sipo) ? sipo->cursorVal : 0.0f;
+	}
 	
 	/* snap keyframes */
 	for (ale= anim_data.first; ale; ale= ale->next) {

Modified: trunk/blender/source/blender/editors/space_graph/graph_header.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_header.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/space_graph/graph_header.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -81,6 +81,7 @@
 	uiItemS(layout);
 	
 	uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0);
+	uiItemR(layout, NULL, 0, &spaceptr, "show_cursor", 0);
 	uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0);
 	uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0);
 	
@@ -162,6 +163,7 @@
 {
 	uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
 	uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_CFRA);
+	uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_VALUE);
 	uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_FRAME);
 	uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_SECOND);
 	uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_MARKER);

Modified: trunk/blender/source/blender/editors/space_graph/graph_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_intern.h	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/space_graph/graph_intern.h	2009-10-20 12:04:56 UTC (rev 23998)
@@ -119,6 +119,7 @@
 	GRAPHKEYS_SNAP_NEAREST_SECOND,
 	GRAPHKEYS_SNAP_NEAREST_MARKER,	
 	GRAPHKEYS_SNAP_HORIZONTAL,
+	GRAPHKEYS_SNAP_VALUE,
 } eGraphKeys_Snap_Mode;
 
 /* defines for mirror keyframes 

Modified: trunk/blender/source/blender/editors/space_graph/graph_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_ops.c	2009-10-20 11:26:21 UTC (rev 23997)
+++ trunk/blender/source/blender/editors/space_graph/graph_ops.c	2009-10-20 12:04:56 UTC (rev 23998)
@@ -41,6 +41,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_context.h"
+#include "BKE_sound.h"
 #include "BKE_utildefines.h"
 
 #include "UI_interface.h"
@@ -57,13 +58,134 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
-/* ************************** poll callbacks **********************************/
+/* ************************** view-based operators **********************************/
+// XXX should these really be here?
 
+/* Set Cursor --------------------------------------------------------------------- */
+/* The 'cursor' in the Graph Editor consists of two parts:
+ *	1) Current Frame Indicator (as per ANIM_OT_change_frame)
+ *	2) Value Indicator (stored per Graph Editor instance)
+ */
 
+/* Set the new frame number */
+static void graphview_cursor_apply(bContext *C, wmOperator *op)
+{
+	Scene *scene= CTX_data_scene(C);
+	SpaceIpo *sipo= CTX_wm_space_graph(C);
+	
+	/* adjust the frame 
+	 * NOTE: sync this part of the code with ANIM_OT_change_frame
+	 */
+	CFRA= RNA_int_get(op->ptr, "frame");
+	sound_scrub(C);
+	
+	/* set the cursor value */
+	sipo->cursorVal= RNA_float_get(op->ptr, "value");
+	
+	/* send notifiers - notifiers for frame should force an update for both vars ok... */
+	WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+}
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list