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-18 13:58:18 +0300
committerJoshua Leung <aligorith@gmail.com>2009-03-18 13:58:18 +0300
commit43d4e3fa7efca3ae2cedfd35fa344bf2ef298a7f (patch)
treec1d535aeb889a116ced221744d6bc0bbd828e4d6 /source/blender/editors
parentaeb2225a287e68d8ee03861bec112ce3459a468a (diff)
Graph Editor: F-Curves which can only take integral values are now drawn stair-stepped using the sampling code.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c18
-rw-r--r--source/blender/editors/space_graph/graph_draw.c12
-rw-r--r--source/blender/editors/space_graph/graph_edit.c13
-rw-r--r--source/blender/editors/space_graph/graph_select.c1
-rw-r--r--source/blender/editors/transform/transform.h1
-rw-r--r--source/blender/editors/transform/transform_conversions.c17
6 files changed, 45 insertions, 17 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 0ec2070902c..cfb143b407b 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -252,6 +252,17 @@ static void validate_fmodifier_cb (bContext *C, void *fcu_v, void *fcm_v)
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 @@ static void graph_panel_modifier_draw(uiBlock *block, FCurve *fcu, FModifier *fc
/* 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);
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index 44ff7e63673..f7f47760057 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -546,7 +546,7 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
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 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
/* 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 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
*/
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 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
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) ) {
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 43a3b3628ad..4036452649c 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -1438,6 +1438,7 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
bAnimContext ac;
bAnimListElem *ale;
FCurve *fcu;
+ FModifier *fcm;
short type;
/* get editor data */
@@ -1454,13 +1455,17 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
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);
diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c
index e4cb2f64071..96173bf8ca5 100644
--- a/source/blender/editors/space_graph/graph_select.c
+++ b/source/blender/editors/space_graph/graph_select.c
@@ -613,6 +613,7 @@ static short findnearest_fcurve_vert (bAnimContext *ac, int mval[2], FCurve **fc
}
/* 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)) )
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 0b9066962b4..d32efd2b591 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -347,6 +347,7 @@ typedef struct TransInfo {
#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
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 6a94dc68d3e..82ce0a3d042 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -3047,7 +3047,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
/* 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
* gets copied to the actual data at td2d->loc2d (bezt->vec[n])
@@ -3094,6 +3094,8 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, Object *nob, fl
if (ishandle)
td->flag |= TD_NOTIMESNAP;
+ if (intvals)
+ td->flag |= TD_INTVALUES;
Mat3One(td->mtx);
Mat3One(td->smtx);
@@ -3204,6 +3206,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
for (ale= anim_data.first; ale; ale= ale->next) {
Object *nob= NULL; //ANIM_nla_mapping_get(&ac, ale); // XXX we don't handle NLA mapping here yet
FCurve *fcu= (FCurve *)ale->key_data;
+ short intvals= (fcu->flag & FCURVE_INT_VALUES);
/* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse (if applicable) */
bezt= fcu->bezt;
@@ -3218,7 +3221,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
if (bezt->f1 & SELECT) {
hdata = initTransDataCurveHandes(td, bezt);
- bezt_to_transdata(td++, td2d++, nob, bezt->vec[0], bezt->vec[1], 1, 1);
+ bezt_to_transdata(td++, td2d++, nob, bezt->vec[0], bezt->vec[1], 1, 1, intvals);
}
else
h1= 0;
@@ -3227,7 +3230,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
if (bezt->f3 & SELECT) {
if (hdata==NULL)
hdata = initTransDataCurveHandes(td, bezt);
- bezt_to_transdata(td++, td2d++, nob, bezt->vec[2], bezt->vec[1], 1, 1);
+ bezt_to_transdata(td++, td2d++, nob, bezt->vec[2], bezt->vec[1], 1, 1, intvals);
}
else
h2= 0;
@@ -3243,7 +3246,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
hdata = initTransDataCurveHandes(td, bezt);
}
- bezt_to_transdata(td++, td2d++, nob, bezt->vec[1], bezt->vec[1], 1, 0);
+ bezt_to_transdata(td++, td2d++, nob, bezt->vec[1], bezt->vec[1], 1, 0, intvals);
}
/* special hack (must be done after initTransDataCurveHandes(), as that stores handle settings to restore...):
@@ -3489,7 +3492,11 @@ void flushTransGraphData(TransInfo *t)
//else
td2d->loc2d[0]= td2d->loc[0];
- td2d->loc2d[1]= td2d->loc[1];
+ /* if int-values only, truncate to integers */
+ if (td->flag & TD_INTVALUES)
+ td2d->loc2d[1]= (float)((int)td2d->loc[1]);
+ else
+ td2d->loc2d[1]= td2d->loc[1];
}
}