[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23891] trunk/blender/source/blender: ShapeKey Editor (sub-mode of DopeSheet Editor)

Joshua Leung aligorith at gmail.com
Fri Oct 16 14:08:47 CEST 2009


Revision: 23891
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23891
Author:   aligorith
Date:     2009-10-16 14:08:47 +0200 (Fri, 16 Oct 2009)

Log Message:
-----------
ShapeKey Editor (sub-mode of DopeSheet Editor)

Special priority request from Durian team to get this sub-editor of the DopeSheet Editor restored. Originally I was kindof planning to drop it, but obviously it still has a role!

It now supports all the modern features that the DopeSheet supports, complete with selection, muting, locking, DopeSheet summary, and all the other tools that you know and love from the other views. 

Also, this no longer uses the old hacky sliders that 2.4x used (instead it uses RNA-based ones), so should function just the same as other DopeSheet views).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_key.h
    trunk/blender/source/blender/blenkernel/intern/key.c
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/animation/anim_channels_edit.c
    trunk/blender/source/blender/editors/animation/anim_filter.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/makesdna/DNA_key_types.h

Modified: trunk/blender/source/blender/blenkernel/BKE_key.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_key.h	2009-10-16 10:49:54 UTC (rev 23890)
+++ trunk/blender/source/blender/blenkernel/BKE_key.h	2009-10-16 12:08:47 UTC (rev 23891)
@@ -65,6 +65,7 @@
 struct KeyBlock *ob_get_keyblock(struct Object *ob);
 struct KeyBlock *key_get_keyblock(struct Key *key, int index);
 struct KeyBlock *key_get_named_keyblock(struct Key *key, const char name[]);
+char *key_get_curValue_rnaPath(struct Key *key, struct KeyBlock *kb);
 // needed for the GE
 void do_rel_key(int start, int end, int tot, char *basispoin, struct Key *key, int mode);
 

Modified: trunk/blender/source/blender/blenkernel/intern/key.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/key.c	2009-10-16 10:49:54 UTC (rev 23890)
+++ trunk/blender/source/blender/blenkernel/intern/key.c	2009-10-16 12:08:47 UTC (rev 23891)
@@ -35,6 +35,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_blenlib.h"
+
 #include "DNA_anim_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_key_types.h"
@@ -57,7 +59,7 @@
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
 
-#include "BLI_blenlib.h"
+#include "RNA_access.h"
 
 
 #ifdef HAVE_CONFIG_H
@@ -1489,3 +1491,24 @@
 	
 	return NULL;
 }
+
+/* Get RNA-Path for 'value' setting of the given ShapeKey 
+ * NOTE: the user needs to free the returned string once they're finishe with it
+ */
+char *key_get_curValue_rnaPath(Key *key, KeyBlock *kb)
+{
+	PointerRNA ptr;
+	PropertyRNA *prop;
+	
+	/* sanity checks */
+	if ELEM(NULL, key, kb)
+		return NULL;
+	
+	/* create the RNA pointer */
+	RNA_pointer_create(key, &RNA_ShapeKey, kb, &ptr);
+	/* get pointer to the property too */
+	prop= RNA_struct_find_property(&ptr, "value");
+	
+	/* return the path */
+	return RNA_path_from_ID_to_property(&ptr, prop);
+}

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2009-10-16 10:49:54 UTC (rev 23890)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2009-10-16 12:08:47 UTC (rev 23891)
@@ -1386,7 +1386,7 @@
 	
 	switch (setting) {
 		case ACHANNEL_SETTING_EXPAND: /* expanded */
-			return KEYBLOCK_DS_EXPAND;
+			return KEY_DS_EXPAND;
 			
 		case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
 			return ADT_NLA_EVAL_OFF;
@@ -1737,29 +1737,92 @@
 
 
 /* ShapeKey Entry  ------------------------------------------- */
-// XXX ... this is currently obsolete...
 
-#if 0
-static void dummy_olddraw_shapekeys ()
+/* name for ShapeKey */
+static void acf_shapekey_name(bAnimListElem *ale, char *name)
 {
-	case ANIMTYPE_SHAPEKEY: /* shapekey channel */
-	{
-		KeyBlock *kb = (KeyBlock *)ale->data;
+	KeyBlock *kb= (KeyBlock *)ale->data;
+	
+	/* just copy the name... */
+	if (kb && name) {
+		/* if the KeyBlock had a name, use it, otherwise use the index */
+		if (kb->name[0])
+			strcpy(name, kb->name);
+		else
+			sprintf(name, "Key %d", ale->index);
+	}
+}
+
+/* check if some setting exists for this channel */
+static short acf_shapekey_setting_valid(bAnimContext *ac, bAnimListElem *ale, int setting)
+{
+	switch (setting) {
+		case ACHANNEL_SETTING_SELECT: /* selected */
+		case ACHANNEL_SETTING_MUTE: /* muted */
+		case ACHANNEL_SETTING_PROTECT: /* protected */
+			return 1;
+			
+		/* nothing else is supported */
+		default:
+			return 0;
+	}
+}
+
+/* get the appropriate flag(s) for the setting when it is valid  */
+static int acf_shapekey_setting_flag(int setting, short *neg)
+{
+	/* clear extra return data first */
+	*neg= 0;
+	
+	switch (setting) {
+		case ACHANNEL_SETTING_MUTE: /* mute */
+			return KEYBLOCK_MUTE;
 		
-		indent = 0;
-		special = -1;
+		case ACHANNEL_SETTING_SELECT: /* selected */
+			return KEYBLOCK_SEL;
 		
-		offset= (ale->id) ? 21 : 0;
+		case ACHANNEL_SETTING_PROTECT: /* locked */
+			return KEYBLOCK_LOCKED;
 		
-		if (kb->name[0] == '\0')
-			sprintf(name, "Key %d", ale->index);
-		else
-			strcpy(name, kb->name);
+		default: /* unsupported */
+			return 0;
 	}
-		break;
 }
-#endif
 
+/* get pointer to the setting */
+static void *acf_shapekey_setting_ptr(bAnimListElem *ale, int setting, short *type)
+{
+	KeyBlock *kb= (KeyBlock *)ale->data;
+	
+	/* clear extra return data first */
+	*type= 0;
+	
+	switch (setting) {
+		case ACHANNEL_SETTING_SELECT: /* selected */
+		case ACHANNEL_SETTING_MUTE: /* muted */
+		case ACHANNEL_SETTING_PROTECT: /* protected */
+			GET_ACF_FLAG_PTR(kb->flag)
+		
+		default: /* unsupported */
+			return NULL;
+	}
+}
+
+/* shapekey expander type define */
+static bAnimChannelType ACF_SHAPEKEY= 
+{
+	acf_generic_channel_backdrop,	/* backdrop */
+	acf_generic_indention_0,		/* indent level */
+	acf_generic_basic_offset,		/* offset */
+	
+	acf_shapekey_name,				/* name */
+	NULL,							/* icon */
+	
+	acf_shapekey_setting_valid,		/* has setting */
+	acf_shapekey_setting_flag,		/* flag for setting */
+	acf_shapekey_setting_ptr		/* pointer for setting */
+};
+
 /* Grease Pencil entries  ------------------------------------------- */
 // XXX ... this is currently not restored yet
 
@@ -1923,7 +1986,7 @@
 		animchannelTypeInfo[type++]= &ACF_DSMBALL;		/* MetaBall Channel */
 		animchannelTypeInfo[type++]= &ACF_DSARM;		/* Armature Channel */
 		
-		animchannelTypeInfo[type++]= NULL;				/* ShapeKey */ // XXX this is no longer used for now...
+		animchannelTypeInfo[type++]= &ACF_SHAPEKEY;		/* ShapeKey */
 		
 			// XXX not restored yet
 		animchannelTypeInfo[type++]= NULL;				/* Grease Pencil Datablock */ 
@@ -2237,8 +2300,58 @@
 	}
 }
 
+/* callback for shapekey widget sliders - insert keyframes */
+static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, void *kb_poin)
+{
+	Key *key= (Key *)key_poin;
+	KeyBlock *kb= (KeyBlock *)kb_poin;
+	char *rna_path= key_get_curValue_rnaPath(key, kb);
+	
+	Scene *scene= CTX_data_scene(C);
+	PointerRNA id_ptr, ptr;
+	PropertyRNA *prop;
+	short flag=0, done=0;
+	float cfra;
+	
+	/* get current frame */
+	// NOTE: this will do for now...
+	cfra= (float)CFRA;
+	
+	/* get flags for keyframing */
+	if (IS_AUTOKEY_FLAG(INSERTNEEDED))
+		flag |= INSERTKEY_NEEDED;
+	if (IS_AUTOKEY_FLAG(AUTOMATKEY))
+		flag |= INSERTKEY_MATRIX;
+	if (IS_AUTOKEY_MODE(scene, EDITKEYS))
+		flag |= INSERTKEY_REPLACE;
+	
+	
+	/* get RNA pointer, and resolve the path */
+	RNA_id_pointer_create((ID *)key, &id_ptr);
+	
+	/* try to resolve the path stored in the F-Curve */
+	if (RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop)) {
+		/* find or create new F-Curve */
+		// XXX is the group name for this ok?
+		bAction *act= verify_adt_action((ID *)key, 1);
+		FCurve *fcu= verify_fcurve(act, NULL, rna_path, 0, 1);
+		
+		/* set the special 'replace' flag if on a keyframe */
+		if (fcurve_frame_has_keyframe(fcu, cfra, 0))
+			flag |= INSERTKEY_REPLACE;
+		
+		/* insert a keyframe for this F-Curve */
+		done= insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
+		
+		if (done)
+			WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN_EDIT, NULL);
+	}
+	
+	/* free the path */
+	if (rna_path)
+		MEM_freeN(rna_path);
+}
 
-
 /* Draw a widget for some setting */
 static void draw_setting_widget (bAnimContext *ac, bAnimListElem *ale, bAnimChannelType *acf, uiBlock *block, int xpos, int ypos, int setting)
 {
@@ -2445,7 +2558,7 @@
 		 *	  and wouldn't be able to auto-keyframe...
 		 *	- slider should start before the toggles (if they're visible) to keep a clean line down the side
 		 */
-		if ((draw_sliders) && (ale->type == ANIMTYPE_FCURVE)) {
+		if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_SHAPEKEY)) {
 			/* adjust offset */
 			offset += SLIDER_WIDTH;
 			
@@ -2453,20 +2566,49 @@
 			uiBlockSetEmboss(block, UI_EMBOSS);
 			
 			if (ale->id) { /* Slider using RNA Access -------------------- */
-				FCurve *fcu= (FCurve *)ale->data;
 				PointerRNA id_ptr, ptr;
 				PropertyRNA *prop;
+				char *rna_path = NULL;
+				int array_index = 0;
+				short free_path = 0;
 				
-				/* get RNA pointer, and resolve the path */
-				RNA_id_pointer_create(ale->id, &id_ptr);
+				/* get destination info */
+				if (ale->type == ANIMTYPE_FCURVE) {
+					FCurve *fcu= (FCurve *)ale->data;
+					
+					rna_path= fcu->rna_path;
+					array_index= fcu->array_index;
+				}
+				else if (ale->type == ANIMTYPE_SHAPEKEY) {
+					KeyBlock *kb= (KeyBlock *)ale->data;
+					Key *key= (Key *)ale->id;
+					
+					rna_path= key_get_curValue_rnaPath(key, kb);
+					free_path= 1;
+				}
 				
-				/* try to resolve the path */
-				if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
-					uiBut *but;
+				/* only if RNA-Path found */
+				if (rna_path) {
+					/* get RNA pointer, and resolve the path */
+					RNA_id_pointer_create(ale->id, &id_ptr);
 					
-					/* create the slider button, and assign relevant callback to ensure keyframes are inserted... */
-					but= uiDefAutoButR(block, &ptr, prop, fcu->array_index, "", 0, (int)v2d->cur.xmax-offset, ymid, SLIDER_WIDTH, (int)ymaxc-yminc);
-					uiButSetFunc(but, achannel_setting_slider_cb, ale->id, fcu);
+					/* try to resolve the path */
+					if (RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop)) {
+						uiBut *but;
+						
+						/* create the slider button, and assign relevant callback to ensure keyframes are inserted... */
+						but= uiDefAutoButR(block, &ptr, prop, array_index, "", 0, (int)v2d->cur.xmax-offset, ymid, SLIDER_WIDTH, (int)ymaxc-yminc);
+						
+						/* assign keyframing function according to slider type */
+						if (ale->type == ANIMTYPE_SHAPEKEY)
+							uiButSetFunc(but, achannel_setting_slider_shapekey_cb, ale->id, ale->data);
+						else
+							uiButSetFunc(but, achannel_setting_slider_cb, ale->id, ale->data);
+					}
+					
+					/* free the path if necessary */
+					if (free_path)
+						MEM_freeN(rna_path);
 				}
 			}
 			else { /* Special Slider for stuff without RNA Access ---------- */

Modified: trunk/blender/source/blender/editors/animation/anim_channels_edit.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_edit.c	2009-10-16 10:49:54 UTC (rev 23890)
+++ trunk/blender/source/blender/editors/animation/anim_channels_edit.c	2009-10-16 12:08:47 UTC (rev 23891)
@@ -238,6 +238,10 @@
 					if (ale->flag & FCURVE_SELECTED)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list