[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19309] branches/blender2.5/blender/source /blender: F-Curve Modifiers: Basic GUI for Generator Modifier working

Joshua Leung aligorith at gmail.com
Mon Mar 16 12:11:44 CET 2009


Revision: 19309
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19309
Author:   aligorith
Date:     2009-03-16 12:11:44 +0100 (Mon, 16 Mar 2009)

Log Message:
-----------
F-Curve Modifiers: Basic GUI for Generator Modifier working

* Currently, this only works for the 'Expanded polynomial' mode, but this will be expanded to include the other modes too. Now you can modify the values and interactively see the graph in the view change. 

* Disabled the backdrops (modifier 'panels') temporarily, as ROUNDBOX UI elements currently swallow all events, which is not good.

Note: the code here still uses the old-style UI definition code since the new stuff is still under heavy construction. 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c
    branches/blender2.5/blender/source/blender/editors/space_graph/space_graph.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h	2009-03-16 10:12:52 UTC (rev 19308)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h	2009-03-16 11:11:44 UTC (rev 19309)
@@ -56,6 +56,8 @@
 	void (*copy_data)(struct FModifier *fcm, struct FModifier *src);
 		/* set settings for data that will be used for FCuModifier.data (memory already allocated using MEM_callocN) */
 	void (*new_data)(void *mdata);
+		/* verifies that the modifier settings are valid */
+	void (*verify_data)(struct FModifier *fcm);
 	
 	/* evaluation */
 		/* evaluate the modifier for the given time and 'accumulated' value */

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-03-16 10:12:52 UTC (rev 19308)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-03-16 11:11:44 UTC (rev 19309)
@@ -1114,6 +1114,7 @@
 	fcm_modname_relink, /* relink data */
 	fcm_modname_copy, /* copy data */
 	fcm_modname_new_data, /* new data */
+	fcm_modname_verify, /* verify */
 	fcm_modname_evaluate /* evaluate */
 };
 #endif
@@ -1163,6 +1164,45 @@
 	cp[1] = 1; // gradient
 }
 
+static void fcm_generator_verify (FModifier *fcm)
+{
+	FMod_Generator *data= (FMod_Generator *)fcm->data;
+	
+	/* requirements depend on mode */
+	switch (data->mode) {
+		case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */
+		{
+			/* arraysize needs to be order+1, so resize if not */
+			if (data->arraysize != (data->poly_order+1)) {
+				float *nc;
+				
+				/* make new coefficients array, and copy over as much data as can fit */
+				nc= MEM_callocN(sizeof(float)*(data->poly_order+1), "FMod_Generator_Coefs");
+				
+				if (data->coefficients) {
+					if (data->arraysize > (data->poly_order+1))
+						memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order+1));
+					else
+						memcpy(nc, data->coefficients, sizeof(float)*data->arraysize);
+				}	
+				
+				/* free the old data, and set the new */
+				if (data->coefficients) MEM_freeN(data->coefficients);
+				
+				data->coefficients= nc;
+				data->arraysize= data->poly_order+1;
+			}
+		}
+			break;
+		
+		// FIXME: add checks for all others		
+		case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */
+		{
+			
+		}
+			break;
+	}
+}
 
 static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
 {
@@ -1294,6 +1334,7 @@
 	fcm_generator_free, /* free data */
 	fcm_generator_copy, /* copy data */
 	fcm_generator_new_data, /* new data */
+	fcm_generator_verify, /* verify */
 	fcm_generator_evaluate /* evaluate */
 };
 
@@ -1378,6 +1419,7 @@
 	fcm_envelope_free, /* free data */
 	fcm_envelope_copy, /* copy data */
 	NULL, /* new data */
+	NULL /*fcm_envelope_verify*/, /* verify */
 	fcm_envelope_evaluate /* evaluate */
 };
 
@@ -1513,6 +1555,7 @@
 	NULL, /* free data */
 	NULL, /* copy data */
 	NULL, /* new data */
+	NULL /*fcm_cycles_verify*/, /* verify */
 	fcm_cycles_evaluate /* evaluate */
 };
 
@@ -1529,6 +1572,7 @@
 	NULL, /* free data */
 	NULL, /* copy data */
 	fcm_noise_new_data, /* new data */
+	NULL /*fcm_noise_verify*/, /* verify */
 	fcm_noise_evaluate /* evaluate */
 };
 #endif // XXX not yet implemented
@@ -1546,6 +1590,7 @@
 	NULL, /* free data */
 	NULL, /* copy data */
 	NULL, /* new data */
+	NULL /*fcm_filter_verify*/, /* verify */
 	fcm_filter_evaluate /* evaluate */
 };
 #endif // XXX not yet implemented
@@ -1600,6 +1645,7 @@
 	fcm_python_free, /* free data */
 	fcm_python_copy, /* copy data */
 	fcm_python_new_data, /* new data */
+	NULL /*fcm_python_verify*/, /* verify */
 	fcm_python_evaluate /* evaluate */
 };
 
@@ -1689,7 +1735,7 @@
 	BLI_addtail(&fcu->modifiers, fcm);
 	
 	/* add modifier's data */
-	fcm->data= MEM_callocN(fmi->size, "F-Curve Modifier Data");
+	fcm->data= MEM_callocN(fmi->size, fmi->structName);
 		
 	/* init custom settings if necessary */
 	if (fmi->new_data)	

Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c	2009-03-16 10:12:52 UTC (rev 19308)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c	2009-03-16 11:11:44 UTC (rev 19309)
@@ -223,51 +223,107 @@
 
 static void do_graph_region_modifier_buttons(bContext *C, void *arg, int event)
 {
-	switch(event) {
+	switch (event) {
 		case B_REDR:
-		case B_FMODIFIER_REDRAW:
+		case B_FMODIFIER_REDRAW: // XXX this should send depsgraph updates too
 			ED_area_tag_redraw(CTX_wm_area(C));
 			return; /* no notifier! */
 	}
 }
 
 /* macro for use here to draw background box and set height */
-#define DRAW_BACKDROP(height, h) \
+// XXX for now, roundbox has it's callback func set to NULL to not intercept events
+#define DRAW_BACKDROP(height) \
 	{ \
-		height= h; \
 		if (active) uiBlockSetCol(block, TH_BUT_ACTION); \
-			uiDefBut(block, ROUNDBOX, B_REDR, "", 10-8, *yco-height, width, height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, ""); \
+			but= uiDefBut(block, ROUNDBOX, B_REDR, "", 10-8, *yco-height, width, height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, ""); \
+			uiButSetFunc(but, NULL, NULL, NULL); \
 		if (active) uiBlockSetCol(block, TH_AUTO); \
 	}
 
+/* callback to verify modifier data */
+static void validate_fmodifier_cb (bContext *C, void *fcu_v, void *fcm_v)
+{
+	FModifier *fcm= (FModifier *)fcm_v;
+	FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
+	
+	/* call the verify callback on the modifier if applicable */
+	if (fmi && fmi->verify_data)
+		fmi->verify_data(fcm);
+}
+	
 /* draw settings for generator modifier */
 static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fcm, int *yco, short *height, short width, short active, int rb_col)
 {
 	FMod_Generator *data= (FMod_Generator *)fcm->data;
+	char gen_mode[]="Generator Type%t|Expanded Polynomial%x0|Factorised Polynomial%x1|Built-In Function%x2|Expression%x3";
+	//char fn_type[]="Built-In Function%t|Sin%x0|Cos%x1|Tan%x2|Square Root%x3|Natural Log%x4";
+	int cy= *yco - 30;
+	uiBut *but;
 	
+	/* set the height */
+	(*height) = 70;
 	switch (data->mode) {
 		case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */
+			(*height) += 20*(data->poly_order+1) + 35;
+			break;
+		case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* factorised polynomial */
+			(*height) += 25 * data->poly_order;
+			break;
+		case FCM_GENERATOR_FUNCTION: /* builtin function */
+			(*height) += 50; // xxx
+			break;
+		case FCM_GENERATOR_EXPRESSION: /* py-expression */
+			// xxx nothing to draw 
+			break;
+	}
+	
+	/* basic settings (backdrop + mode selector + some padding) */
+	//DRAW_BACKDROP((*height)); // XXX buggy...
+	but= uiDefButS(block, MENU, /*B_FMODIFIER_REDRAW*/B_REDR, gen_mode, 10,cy,width-30,19, &data->mode, 0, 0, 0, 0, "Selects type of generator algorithm.");
+	uiButSetFunc(but, validate_fmodifier_cb, fcu, fcm);
+	cy -= 35;
+	
+	/* now add settings for individual modifiers */
+	switch (data->mode) {
+		case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */
 		{
-			/* we overwrite cvalue with the sum of the polynomial */
-			float value= 0.0f, *cp = NULL;
+			float *cp = NULL;
+			char xval[32];
 			unsigned int i;
 			
-			/* draw backdrop */
-			DRAW_BACKDROP((*height), 96);
+			/* draw polynomial order selector */
+				// XXX this needs validation!
+			but= uiDefButS(block, NUM, B_FMODIFIER_REDRAW, "Poly Order: ", 10,cy,width-30,19, &data->poly_order, 1, 100, 0, 0, "'Order' of the Polynomial - for a polynomial with n terms, 'order' is n-1");
+			uiButSetFunc(but, validate_fmodifier_cb, fcu, fcm);
+			cy -= 35;
 			
-			/* for each coefficient, add to value, which we'll write to *cvalue in one go */
+			/* draw controls for each coefficient and a + sign at end of row */
 			cp= data->coefficients;
 			for (i=0; (i < data->arraysize) && (cp); i++, cp++) {
-			
+				/* coefficient */
+				uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 50, cy, 150, 20, cp, -FLT_MAX, FLT_MAX, 10, 3, "Coefficient for polynomial");
+				
+				/* 'x' param (and '+' if necessary) */
+				if (i == 0)
+					strcpy(xval, "");
+				else if (i == 1)
+					strcpy(xval, "x");
+				else
+					sprintf(xval, "x^%d", i);
+				uiDefBut(block, LABEL, 1, xval, 200, cy, 50, 20, NULL, 0.0, 0.0, 0, 0, "Power of x");
+				
+				if ( (i != (data->arraysize - 1)) || ((i==0) && data->arraysize==2) )
+					uiDefBut(block, LABEL, 1, "+", 300, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "Power of x");
+				
+				cy -= 20;
 			}
 		}
 			break;
 		
-#ifndef DISABLE_PYTHON
 		case FCM_GENERATOR_EXPRESSION: /* py-expression */
 			// TODO...
 			break;
-#endif /* DISABLE_PYTHON */
 	}
 }
 
@@ -286,10 +342,12 @@
 		uiBlockSetEmboss(block, UI_EMBOSSN);
 		
 		/* rounded header */
+#if 0 // XXX buggy...
 		if (active) uiBlockSetCol(block, TH_BUT_ACTION);
 			rb_col= (active)?-20:20;
-			uiDefBut(block, ROUNDBOX, B_REDR, "", 10-8, *yco-2, width, 24, NULL, 5.0, 0.0, 15.0, (float)(rb_col-20), ""); 
+			but= uiDefBut(block, ROUNDBOX, B_REDR, "", 10-8, *yco-2, width, 24, NULL, 5.0, 0.0, 15.0, (float)(rb_col-20), ""); 
 		if (active) uiBlockSetCol(block, TH_AUTO);
+#endif // XXX buggy
 		
 		/* expand */
 		uiDefIconButBitS(block, ICONTOG, FMODIFIER_FLAG_EXPANDED, B_REDR, ICON_TRIA_RIGHT,	10-7, *yco-1, 20, 20, &fcm->flag, 0.0, 0.0, 0, 0, "Modifier is expanded");
@@ -303,6 +361,7 @@
 		/* delete button */
 		but= uiDefIconBut(block, BUT, B_REDR, ICON_X, 10+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer");
 		//uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL);
+		
 		uiBlockSetEmboss(block, UI_EMBOSS);
 	}
 	
@@ -315,7 +374,8 @@
 				break;
 			
 			default: /* unknown type */
-				DRAW_BACKDROP(height, 96);
+				height= 96;
+				//DRAW_BACKDROP(height); // XXX buggy...
 				break;
 		}
 	}
@@ -330,11 +390,13 @@
 	FModifier *fcm;
 	uiBlock *block;
 	int yco= 190;
-
+	
 	block= uiBeginBlock(C, ar, "graph_panel_modifiers", UI_EMBOSS, UI_HELV);
 	if (uiNewPanel(C, ar, block, "Modifiers", "Graph", 340, 30, 318, 254)==0) return;
 	uiBlockSetHandleFunc(block, do_graph_region_modifier_buttons, NULL);
 	
+	uiNewPanelHeight(block, 204);
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list