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
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-03-16 14:43:02 +0300
committerJoshua Leung <aligorith@gmail.com>2009-03-16 14:43:02 +0300
commit133e8827b7e9b76e61e405c6eeac88126a106b09 (patch)
tree3bc5962e774edbb2db5318cf710fc3f3a5210088 /source/blender
parentae0f349346941983727a5af7dd503efeb9361154 (diff)
F-Curve Modifiers - Generator: Finishing off most of UI
* Finished code for Expanded Polynomial and Factorised Polynomial UI's. * Started UI code for 'Builtin Function' mode. There are still 4 controls to add there to use something other than simple mapping * Finished/fixed up verification code for these so that values get initialised ok.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/fcurve.c52
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c59
2 files changed, 101 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index e977310ecc8..570af95f267 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1184,23 +1184,65 @@ static void fcm_generator_verify (FModifier *fcm)
memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order+1));
else
memcpy(nc, data->coefficients, sizeof(float)*data->arraysize);
+
+ /* free the old data */
+ MEM_freeN(data->coefficients);
}
- /* free the old data, and set the new */
- if (data->coefficients) MEM_freeN(data->coefficients);
-
+ /* set the new data */
data->coefficients= nc;
data->arraysize= data->poly_order+1;
}
}
break;
- // FIXME: add checks for all others
case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */
{
-
+ /* arraysize needs to be 2*order, so resize if not */
+ if (data->arraysize != (data->poly_order * 2)) {
+ float *nc;
+
+ /* make new coefficients array, and copy over as much data as can fit */
+ nc= MEM_callocN(sizeof(float)*(data->poly_order*2), "FMod_Generator_Coefs");
+
+ if (data->coefficients) {
+ if (data->arraysize > (data->poly_order * 2))
+ memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order * 2));
+ else
+ memcpy(nc, data->coefficients, sizeof(float)*data->arraysize);
+
+ /* free the old data */
+ MEM_freeN(data->coefficients);
+ }
+
+ /* set the new data */
+ data->coefficients= nc;
+ data->arraysize= data->poly_order * 2;
+ }
}
break;
+
+ case FCM_GENERATOR_FUNCTION: /* builtin function */
+ {
+ /* arraysize needs to be 4*/
+ if (data->arraysize != 4) {
+ float *nc;
+
+ /* free the old data */
+ if (data->coefficients)
+ MEM_freeN(data->coefficients);
+
+ /* make new coefficients array, and init using default values */
+ nc= data->coefficients= MEM_callocN(sizeof(float)*4, "FMod_Generator_Coefs");
+ data->arraysize= 4;
+
+ nc[0]= 1.0f;
+ nc[1]= 1.0f;
+ nc[2]= 0.0f;
+ nc[3]= 0.0f;
+ }
+ }
+ break;
}
}
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index a860c25a563..2484dee03a3 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -257,7 +257,7 @@ static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fc
{
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";
+ 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;
@@ -268,7 +268,7 @@ static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fc
(*height) += 20*(data->poly_order+1) + 35;
break;
case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* factorised polynomial */
- (*height) += 25 * data->poly_order;
+ (*height) += 20 * data->poly_order;
break;
case FCM_GENERATOR_FUNCTION: /* builtin function */
(*height) += 50; // xxx
@@ -280,7 +280,7 @@ static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fc
/* 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.");
+ but= uiDefButS(block, MENU, B_FMODIFIER_REDRAW, 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;
@@ -293,12 +293,13 @@ static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fc
unsigned int i;
/* 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;
/* draw controls for each coefficient and a + sign at end of row */
+ uiDefBut(block, LABEL, 1, "y = ", 0, cy, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
+
cp= data->coefficients;
for (i=0; (i < data->arraysize) && (cp); i++, cp++) {
/* coefficient */
@@ -314,13 +315,61 @@ static void _draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fc
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");
+ uiDefBut(block, LABEL, 1, "+", 250, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
cy -= 20;
}
}
break;
+ case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* factorised polynomial expression */
+ {
+ float *cp = NULL;
+ unsigned int i;
+
+ /* draw polynomial order selector */
+ 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;
+
+ /* draw controls for each pair of coefficients */
+ uiDefBut(block, LABEL, 1, "y = ", 0, cy, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
+
+ cp= data->coefficients;
+ for (i=0; (i < data->poly_order) && (cp); i++, cp+=2) {
+ /* opening bracket */
+ uiDefBut(block, LABEL, 1, "(", 40, cy, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
+
+ /* coefficients */
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 50, cy, 100, 20, cp, -FLT_MAX, FLT_MAX, 10, 3, "Coefficient of x");
+
+ uiDefBut(block, LABEL, 1, "x + ", 150, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
+
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 180, cy, 100, 20, cp+1, -FLT_MAX, FLT_MAX, 10, 3, "Second coefficient");
+
+ /* closing bracket and '+' sign */
+ if ( (i != (data->poly_order - 1)) || ((i==0) && data->poly_order==2) )
+ uiDefBut(block, LABEL, 1, ") ×", 280, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
+ else
+ uiDefBut(block, LABEL, 1, ")", 280, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
+
+ cy -= 20;
+ }
+ }
+ break;
+
+ case FCM_GENERATOR_FUNCTION: /* built-in function */
+ {
+
+ /* draw function selector */
+ but= uiDefButS(block, MENU, B_FMODIFIER_REDRAW, fn_type, 10,cy,width-30,19, &data->func_type, 0, 0, 0, 0, "Built-In Function to use");
+ uiButSetFunc(but, validate_fmodifier_cb, fcu, fcm);
+ cy -= 35;
+
+ // TODO: finish adding buttons...
+ }
+ break;
+
case FCM_GENERATOR_EXPRESSION: /* py-expression */
// TODO...
break;