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

Log Message:
-----------
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.

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

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c       
2009-03-16 11:38:42 UTC (rev 19310)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c       
2009-03-16 11:43:02 UTC (rev 19311)
@@ -1184,23 +1184,65 @@
                                                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;
+                       break;  
        }
 }
 

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 11:38:42 UTC (rev 19310)
+++ 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c  
    2009-03-16 11:43:02 UTC (rev 19311)
@@ -257,7 +257,7 @@
 {
        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 @@
                        (*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 @@
        
        /* 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 @@
                        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 @@
                                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, ") \xD7", 
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;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to