[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19327] branches/blender2.5/blender/source /blender: Graph Editor: F-Curves which can only take integral values are now drawn stair-stepped using the sampling code .
Joshua Leung
aligorith at gmail.com
Wed Mar 18 11:58:19 CET 2009
Revision: 19327
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19327
Author: aligorith
Date: 2009-03-18 11:58:18 +0100 (Wed, 18 Mar 2009)
Log Message:
-----------
Graph Editor: F-Curves which can only take integral values are now drawn stair-stepped using the sampling code.
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/graph_edit.c
branches/blender2.5/blender/source/blender/editors/space_graph/graph_select.c
branches/blender2.5/blender/source/blender/editors/transform/transform.h
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h 2009-03-18 10:58:18 UTC (rev 19327)
@@ -94,13 +94,15 @@
/* ---------------------- */
-struct FModifier *fcurve_active_modifier(struct FCurve *fcu);
struct FModifier *fcurve_add_modifier(struct FCurve *fcu, int type);
void fcurve_copy_modifiers(ListBase *dst, ListBase *src);
void fcurve_remove_modifier(struct FCurve *fcu, struct FModifier *fcm);
void fcurve_free_modifiers(struct FCurve *fcu);
void fcurve_bake_modifiers(struct FCurve *fcu, int start, int end);
+struct FModifier *fcurve_find_active_modifier(struct FCurve *fcu);
+void fcurve_set_active_modifier(struct FCurve *fcu, struct FModifier *fcm);
+
/* ************** F-Curves API ******************** */
/* -------- Data Managemnt -------- */
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -1892,7 +1892,7 @@
}
/* Find the active F-Curve Modifier */
-FModifier *fcurve_active_modifier (FCurve *fcu)
+FModifier *fcurve_find_active_modifier (FCurve *fcu)
{
FModifier *fcm;
@@ -1910,6 +1910,24 @@
return NULL;
}
+/* Set the active F-Curve Modifier */
+void fcurve_set_active_modifier (FCurve *fcu, FModifier *fcm)
+{
+ FModifier *fm;
+
+ /* sanity checks */
+ if ELEM(NULL, fcu, fcu->modifiers.first)
+ return NULL;
+
+ /* deactivate all, and set current one active */
+ for (fm= fcu->modifiers.first; fm; fm= fm->next)
+ fm->flag &= ~FMODIFIER_FLAG_ACTIVE;
+
+ /* make given modifier active */
+ if (fcm)
+ fcm->flag |= FMODIFIER_FLAG_ACTIVE;
+}
+
/* ***************************** F-Curve - Evaluation ********************************* */
/* Evaluate and return the value of the given F-Curve at the specified frame ("evaltime")
@@ -1946,6 +1964,12 @@
}
}
+ /* if curve can only have integral values, perform truncation (i.e. drop the decimal part)
+ * here so that the curve can be sampled correctly
+ */
+ if (fcu->flag & FCURVE_INT_VALUES)
+ cvalue= (float)((int)cvalue);
+
/* return evaluated value */
return cvalue;
}
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-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -252,6 +252,17 @@
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)
{
@@ -492,12 +503,13 @@
/* name */
if (fmi)
- uiDefBut(block, LABEL, 1, fmi->name, 10+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "F-Curve Modifier Type");
+ but= uiDefBut(block, LABEL, 1, fmi->name, 10+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "F-Curve Modifier Type. Click to make modifier active one.");
else
- uiDefBut(block, LABEL, 1, "<Unknown Modifier>", 10+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "F-Curve Modifier Type");
+ but= uiDefBut(block, LABEL, 1, "<Unknown Modifier>", 10+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "F-Curve Modifier Type. Click to make modifier active one.");
+ uiButSetFunc(but, activate_fmodifier_cb, fcu, fcm);
/* 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");
+ but= uiDefIconBut(block, BUT, B_REDR, ICON_X, 10+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete F-Curve Modifier.");
uiButSetFunc(but, delete_fmodifier_cb, fcu, fcm);
uiBlockSetEmboss(block, UI_EMBOSS);
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -546,7 +546,7 @@
v1[0]= v2d->cur.xmin;
/* y-value depends on the interpolation */
- if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo==BEZT_IPO_CONST) || (fcu->totvert==1)) {
+ if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (prevbezt->ipo==BEZT_IPO_CONST) || (fcu->totvert==1)) {
/* just extend across the first keyframe's value */
v1[1]= prevbezt->vec[1][1];
}
@@ -575,7 +575,7 @@
/* draw curve between first and last keyframe (if there are enough to do so) */
while (b--) {
- if ((fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo==BEZT_IPO_CONST)) {
+ if (prevbezt->ipo==BEZT_IPO_CONST) {
/* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
v1[0]= prevbezt->vec[1][0];
v1[1]= prevbezt->vec[1][1];
@@ -710,7 +710,7 @@
*/
for (ale=anim_data.first; ale; ale=ale->next) {
FCurve *fcu= (FCurve *)ale->key_data;
- FModifier *fcm= fcurve_active_modifier(fcu);
+ FModifier *fcm= fcurve_find_active_modifier(fcu);
//Object *nob= ANIM_nla_mapping_get(ac, ale);
/* map keyframes for drawing if scaled F-Curve */
@@ -746,8 +746,10 @@
glEnable(GL_BLEND);
/* draw F-Curve */
- if (fcu->modifiers.first) {
- /* draw a curve affected by modifiers by sampling its points */
+ if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) {
+ /* draw a curve affected by modifiers or only allowed to have integer values
+ * by sampling it at various small-intervals over the visible region
+ */
draw_fcurve_curve(fcu, sipo, &ar->v2d, grid);
}
else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) {
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -1438,6 +1438,7 @@
bAnimContext ac;
bAnimListElem *ale;
FCurve *fcu;
+ FModifier *fcm;
short type;
/* get editor data */
@@ -1454,14 +1455,18 @@
if (fcu == NULL)
return OPERATOR_CANCELLED;
-
/* get type of modifier to add */
type= RNA_enum_get(op->ptr, "type");
- /* add F-Modifier of specified type to active F-Curve */
- fcurve_add_modifier(fcu, type);
+ /* add F-Modifier of specified type to active F-Curve, and make it the active one */
+ fcm= fcurve_add_modifier(fcu, type);
+ if (fcm)
+ fcurve_set_active_modifier(fcu, fcm);
+ else {
+ BKE_report(op->reports, RPT_ERROR, "Modifier couldn't be added. See console for details.");
+ return OPERATOR_CANCELLED;
+ }
-
/* validate keyframes after editing */
ANIM_editkeyframes_refresh(&ac);
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_select.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_select.c 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_select.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -613,6 +613,7 @@
}
/* handles - only do them if they're visible */
+ // XXX also need to check for int-values only?
if ((sipo->flag & SIPO_NOHANDLES)==0) {
/* first handle only visible if previous segment had handles */
if ( (!prevbezt && (bezt1->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) )
Modified: branches/blender2.5/blender/source/blender/editors/transform/transform.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.h 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.h 2009-03-18 10:58:18 UTC (rev 19327)
@@ -347,6 +347,7 @@
#define TD_BEZTRIPLE (1 << 12) /* if this is a bez triple, we need to restore the handles, if this is set transdata->misc.hdata needs freeing */
#define TD_NO_LOC (1 << 13) /* when this is set, don't apply translation changes to this element */
#define TD_NOTIMESNAP (1 << 14) /* for Graph Editor autosnap, indicates that point should not undergo autosnapping */
+#define TD_INTVALUES (1 << 15) /* for Graph Editor - curves that can only have int-values need their keyframes tagged with this */
/* transsnap->status */
#define SNAP_ON 1
Modified: branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c 2009-03-18 03:52:17 UTC (rev 19326)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c 2009-03-18 10:58:18 UTC (rev 19327)
@@ -3047,7 +3047,7 @@
/* Helper function for createTransGraphEditData, which is reponsible for associating
* source data with transform data
*/
-static void bezt_to_transdata (TransData *td, TransData2D *td2d, Object *nob, float *loc, float *cent, short selected, short ishandle)
+static void bezt_to_transdata (TransData *td, TransData2D *td2d, Object *nob, float *loc, float *cent, short selected, short ishandle, short intvals)
{
/* New location from td gets dumped onto the old-location of td2d, which then
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list