Revision: 21306
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21306
Author: aligorith
Date: 2009-07-02 06:47:36 +0200 (Thu, 02 Jul 2009)
Log Message:
-----------
NLA SoC: Separating F-Modifier UI drawing into its own file
* F-Modifier UI drawing/handling is now defined in a separate file so that it
will be more suitable for inclusion into the NLA Editor's buttons.
* Started removing F-Curve dependence from the modifier drawing code, which
wasn't strictly necessary
* Fixed F-Curve RNA wrapping to correctly use FPoints instead of the bulkier
BPoints. Although nobody was likely to have encountered bugs here yet, this
would almost certainly have contributed to some segfaults/data corruption along
the track.
Modified Paths:
--------------
branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h
branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_buttons.c
branches/soc-2009-aligorith/source/blender/makesrna/RNA_access.h
branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_fcurve.c
Added Paths:
-----------
branches/soc-2009-aligorith/source/blender/editors/animation/fmodifier_ui.c
Added:
branches/soc-2009-aligorith/source/blender/editors/animation/fmodifier_ui.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/animation/fmodifier_ui.c
(rev 0)
+++ branches/soc-2009-aligorith/source/blender/editors/animation/fmodifier_ui.c
2009-07-02 04:47:36 UTC (rev 21306)
@@ -0,0 +1,669 @@
+/**
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation, Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* User-Interface Stuff for F-Modifiers:
+ * This file defines the (C-Coded) templates + editing callbacks needed
+ * by the interface stuff or F-Modifiers, as used by F-Curves in the Graph
Editor,
+ * and NLA-Strips in the NLA Editor.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <float.h>
+
+#include "DNA_anim_types.h"
+#include "DNA_action_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_editVert.h"
+#include "BLI_rand.h"
+
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_fcurve.h"
+#include "BKE_object.h"
+#include "BKE_global.h"
+#include "BKE_nla.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_utildefines.h"
+
+#include "BIF_gl.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "ED_anim_api.h"
+#include "ED_keyframing.h"
+#include "ED_screen.h"
+#include "ED_types.h"
+#include "ED_util.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+// XXX! --------------------------------
+/* temporary definition for limits of float number buttons (FLT_MAX tends to
infinity with old system) */
+#define UI_FLT_MAX 10000.0f
+
+/* ********************************************** */
+
+#define B_REDR 1
+#define B_FMODIFIER_REDRAW 20
+
+/* macro for use here to draw background box and set height */
+// XXX for now, roundbox has it's callback func set to NULL to not intercept
events
+#define DRAW_BACKDROP(height) \
+ { \
+ uiDefBut(block, ROUNDBOX, B_REDR, "", -3, *yco-height, width+3,
height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, ""); \
+ }
+
+/* callback to verify modifier data */
+static void validate_fmodifier_cb (bContext *C, void *fcm_v, void *dummy)
+{
+ 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);
+}
+
+/* callback to set the active modifier */
+static void activate_fmodifier_cb (bContext *C, void *fcu_v, void *fcm_v)
+{
+ FCurve *fcu= (FCurve *)fcu_v;
+ FModifier *fcm= (FModifier *)fcm_v;
+
+ /* call API function to set the active modifier for active F-Curve */
+ fcurve_set_active_modifier(fcu, fcm);
+}
+
+/* callback to remove the given modifier */
+static void delete_fmodifier_cb (bContext *C, void *fcu_v, void *fcm_v)
+{
+ FCurve *fcu= (FCurve *)fcu_v;
+ FModifier *fcm= (FModifier *)fcm_v;
+
+ /* remove the given F-Modifier from the F-Curve */
+ fcurve_remove_modifier(fcu, fcm);
+}
+
+/* --------------- */
+
+/* draw settings for generator modifier */
+static void draw_modifier__generator(uiBlock *block, 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";
+ int cy= *yco - 30;
+ uiBut *but;
+
+ /* set the height */
+ (*height) = 90;
+ switch (data->mode) {
+ case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */
+ (*height) += 20*(data->poly_order+1) + 20;
+ break;
+ case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* factorised
polynomial */
+ (*height) += 20 * data->poly_order + 15;
+ break;
+ }
+
+ /* basic settings (backdrop + mode selector + some padding) */
+ DRAW_BACKDROP((*height));
+ uiBlockBeginAlign(block);
+ but= uiDefButI(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, fcm, NULL);
+ cy -= 20;
+
+ uiDefButBitI(block, TOG, FCM_GENERATOR_ADDITIVE,
B_FMODIFIER_REDRAW, "Additive", 10,cy,width-30,19, &data->flag, 0, 0, 0, 0,
"Values generated by this modifier are applied on top of the existing values
instead of overwriting them");
+ cy -= 35;
+ uiBlockEndAlign(block);
+
+ /* now add settings for individual modes */
+ switch (data->mode) {
+ case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */
+ {
+ float *cp = NULL;
+ char xval[32];
+ unsigned int i;
+
+ /* draw polynomial order selector */
+ but= uiDefButI(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, fcm, NULL);
+ 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 */
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "",
50, cy, 150, 20, cp, -UI_FLT_MAX, UI_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, "+", 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= uiDefButI(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, fcm, NULL);
+ 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, -UI_FLT_MAX, UI_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, -UI_FLT_MAX, UI_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;
+ }
+}
+
+/* --------------- */
+
+/* draw settings for noise modifier */
+static void draw_modifier__fn_generator(uiBlock *block, FModifier *fcm, int
*yco, short *height, short width, short active, int rb_col)
+{
+ FMod_FunctionGenerator *data= (FMod_FunctionGenerator *)fcm->data;
+ int cy= (*yco - 30), cy1= (*yco - 50), cy2= (*yco - 70);
+ char fn_type[]="Built-In Function%t|Sin%x0|Cos%x1|Tan%x2|Square
Root%x3|Natural Log%x4|Normalised Sin%x5";
+
+ /* set the height */
+ (*height) = 80;
+
+ /* basic settings (backdrop + some padding) */
+ DRAW_BACKDROP((*height));
+
+ uiDefButI(block, MENU, B_FMODIFIER_REDRAW, fn_type,
+ 3, cy, 300, 20, &data->type, 0, 0, 0, 0, "Type of
function used to generate values");
+
+
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Amplitude:",
+ 3, cy1, 150, 20, &data->amplitude, 0.000001, 10000.0,
0.01, 3, "Scale factor determining the maximum/minimum values.");
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Value Offset:",
+ 3, cy2, 150, 20, &data->value_offset, 0.0, 10000.0,
0.01, 3, "Constant factor to offset values by.");
+
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Phase Multiplier:",
+ 155, cy1, 150, 20, &data->phase_multiplier, 0.0,
100000.0, 0.1, 3, "Scale factor determining the 'speed' of the function.");
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Phase Offset:",
+ 155, cy2, 150, 20, &data->phase_offset, 0.0,
100000.0, 0.1, 3, "Constant factor to offset time by for function.");
+
+}
+
+/* --------------- */
+
+/* draw settings for cycles modifier */
+static void draw_modifier__cycles(uiBlock *block, FModifier *fcm, int *yco,
short *height, short width, short active, int rb_col)
+{
+ FMod_Cycles *data= (FMod_Cycles *)fcm->data;
+ char cyc_mode[]="Cycling Mode%t|No Cycles%x0|Repeat Motion%x1|Repeat
with Offset%x2|Repeat Mirrored%x3";
+ int cy= (*yco - 30), cy1= (*yco - 50), cy2= (*yco - 70);
+
+ /* set the height */
+ (*height) = 80;
+
+ /* basic settings (backdrop + some padding) */
+ DRAW_BACKDROP((*height));
+
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs