From 1c6aacf0e4992e610829510d43c3fc57b220b5e8 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 21:47:59 -0700 Subject: [PATCH 1/6] added functions --- scripts/startup/bl_ui/space_graph.py | 1 + .../editors/animation/keyframes_general.c | 25 ++++ .../editors/include/ED_keyframes_edit.h | 1 + .../editors/space_graph/graph_intern.h | 1 + .../blender/editors/space_graph/graph_ops.c | 1 + .../editors/space_graph/graph_slider_ops.c | 125 ++++++++++++++++++ 6 files changed, 154 insertions(+) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 999a9e3cef7..cfb44281229 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -330,6 +330,7 @@ class GRAPH_MT_slider(Menu): layout.operator("graph.blend_to_neighbor", text="Blend to Neighbor") layout.operator("graph.blend_to_default", text="Blend to Default Value") layout.operator("graph.ease", text="Ease") + layout.operator("graph.scale_to_right", text="Scale to Right") layout.operator("graph.gaussian_smooth", text="Smooth") diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index f1848e4cc42..90c9542a8b0 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,6 +491,31 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ +void scale_to_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) +{ + const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); + const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); + + const float key_x_range = right_key->vec[1][0] - left_key->vec[1][0]; + + /* Happens if there is only 1 key on the FCurve. Needs to be skipped because it + * would be a divide by 0. */ + if (IS_EQF(key_x_range, 0.0f)) { + return; + } + + /* The factor goes from 0 to 1, but for this tool it needs to go from -1 to 1. */ + const float long_factor = factor * 2 - 1; + + for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { + const float delta = fcu->bezt[i].vec[1][1] - right_key->vec[1][1]; + const float key_y_value = fcu->bezt[i].vec[1][1] + delta * long_factor; + move_key(&fcu->bezt[i], key_y_value); + } +} + +/* ---------------- */ + void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { const BezTriple *left_bezt = fcurve_segment_start_get(fcu, segment->start_index); diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 69f103c6cba..d27a6d76109 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -437,6 +437,7 @@ void smooth_fcurve_segment(struct FCurve *fcu, int kernel_size, double *kernel); void ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); +void scale_to_right_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max); void blend_to_default_fcurve(struct PointerRNA *id_ptr, struct FCurve *fcu, float factor); /** diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 7128f805a23..a1433d8abae 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -114,6 +114,7 @@ void GRAPH_OT_clean(struct wmOperatorType *ot); void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot); void GRAPH_OT_breakdown(struct wmOperatorType *ot); void GRAPH_OT_ease(struct wmOperatorType *ot); +void GRAPH_OT_scale_to_right(struct wmOperatorType *ot); void GRAPH_OT_decimate(struct wmOperatorType *ot); void GRAPH_OT_blend_to_default(struct wmOperatorType *ot); void GRAPH_OT_gaussian_smooth(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index b64884da06c..2e4c974bb02 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -463,6 +463,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_blend_to_neighbor); WM_operatortype_append(GRAPH_OT_breakdown); WM_operatortype_append(GRAPH_OT_ease); + WM_operatortype_append(GRAPH_OT_scale_to_right); WM_operatortype_append(GRAPH_OT_blend_to_default); WM_operatortype_append(GRAPH_OT_gaussian_smooth); WM_operatortype_append(GRAPH_OT_euler_filter); diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 184bd8329e8..c6ade37f53f 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1060,6 +1060,131 @@ void GRAPH_OT_ease(wmOperatorType *ot) 1.0f); } +/* -------------------------------------------------------------------- */ +/** \name Scale to Right Operator + * \{ */ + +static void scale_to_right_graph_keys(bAnimContext *ac, const float factor) +{ + ListBase anim_data = {NULL, NULL}; + + ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype); + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { + FCurve *fcu = (FCurve *)ale->key_data; + ListBase segments = find_fcurve_segments(fcu); + + LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { + scale_to_right_fcurve_segment(fcu, segment, factor); + } + + ale->update |= ANIM_UPDATE_DEFAULT; + BLI_freelistN(&segments); + } + + ANIM_animdata_update(ac, &anim_data); + ANIM_animdata_freelist(&anim_data); +} + +static void scale_to_right_draw_status_header(bContext *C, tGraphSliderOp *gso) +{ + char status_str[UI_MAX_DRAW_STR]; + char mode_str[32]; + char slider_string[UI_MAX_DRAW_STR]; + + ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR); + + strcpy(mode_str, TIP_("Scale to Right Keys")); + + if (hasNumInput(&gso->num)) { + char str_ofs[NUM_STR_REP_LEN]; + + outputNumInput(&gso->num, str_ofs, &gso->scene->unit); + + BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, str_ofs); + } + else { + BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, slider_string); + } + + ED_workspace_status_text(C, status_str); +} + +static void scale_to_right_modal_update(bContext *C, wmOperator *op) +{ + tGraphSliderOp *gso = op->customdata; + + scale_to_right_draw_status_header(C, gso); + + /* Reset keyframes to the state at invoke. */ + reset_bezts(gso); + const float factor = slider_factor_get_and_remember(op); + scale_to_right_graph_keys(&gso->ac, factor); + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); +} + +static int scale_to_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + const int invoke_result = graph_slider_invoke(C, op, event); + + if (invoke_result == OPERATOR_CANCELLED) { + return invoke_result; + } + + tGraphSliderOp *gso = op->customdata; + gso->modal_update = scale_to_right_modal_update; + gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); + scale_to_right_draw_status_header(C, gso); + + return invoke_result; +} + +static int scale_to_right_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + + /* Get editor data. */ + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + const float factor = RNA_float_get(op->ptr, "factor"); + + scale_to_right_graph_keys(&ac, factor); + + /* Set notifier that keyframes have changed. */ + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_scale_to_right(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Scale to Right Keyframes"; + ot->idname = "GRAPH_OT_scale_to_right"; + ot->description = "Increase or decrease the value of selected keys \n\ + in relationship to the right neighboring one"; + + /* API callbacks. */ + ot->invoke = scale_to_right_invoke; + ot->modal = graph_slider_modal; + ot->exec = scale_to_right_exec; + ot->poll = graphop_editable_keyframes_poll; + + /* Flags. */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_float_factor(ot->srna, + "factor", + 0.5f, + -FLT_MAX, + FLT_MAX, + "Curve Bend", + "Control the bend of the curve", + 0.0f, + 1.0f); +} + /** \} */ /* -------------------------------------------------------------------- */ /** \name Gauss Smooth Operator -- 2.30.2 From 804e81721f8efaa037e15c01ceb4181312fc91ad Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 22:05:57 -0700 Subject: [PATCH 2/6] took awa the "to" in the names --- scripts/startup/bl_ui/space_graph.py | 2 +- .../editors/animation/keyframes_general.c | 2 +- .../editors/include/ED_keyframes_edit.h | 2 +- .../editors/space_graph/graph_intern.h | 2 +- .../blender/editors/space_graph/graph_ops.c | 2 +- .../editors/space_graph/graph_slider_ops.c | 36 +++++++++---------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index cfb44281229..0e738c721b5 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -330,7 +330,7 @@ class GRAPH_MT_slider(Menu): layout.operator("graph.blend_to_neighbor", text="Blend to Neighbor") layout.operator("graph.blend_to_default", text="Blend to Default Value") layout.operator("graph.ease", text="Ease") - layout.operator("graph.scale_to_right", text="Scale to Right") + layout.operator("graph.scale_right", text="Scale Right") layout.operator("graph.gaussian_smooth", text="Smooth") diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 90c9542a8b0..b4eeeb5a2e4 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,7 +491,7 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ -void scale_to_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) +void scale_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index d27a6d76109..8d2c6fc1730 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -437,7 +437,7 @@ void smooth_fcurve_segment(struct FCurve *fcu, int kernel_size, double *kernel); void ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); -void scale_to_right_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); +void scale_right_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max); void blend_to_default_fcurve(struct PointerRNA *id_ptr, struct FCurve *fcu, float factor); /** diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index a1433d8abae..2c9c41ae840 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -114,7 +114,7 @@ void GRAPH_OT_clean(struct wmOperatorType *ot); void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot); void GRAPH_OT_breakdown(struct wmOperatorType *ot); void GRAPH_OT_ease(struct wmOperatorType *ot); -void GRAPH_OT_scale_to_right(struct wmOperatorType *ot); +void GRAPH_OT_scale_right(struct wmOperatorType *ot); void GRAPH_OT_decimate(struct wmOperatorType *ot); void GRAPH_OT_blend_to_default(struct wmOperatorType *ot); void GRAPH_OT_gaussian_smooth(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 2e4c974bb02..9fe346f9218 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -463,7 +463,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_blend_to_neighbor); WM_operatortype_append(GRAPH_OT_breakdown); WM_operatortype_append(GRAPH_OT_ease); - WM_operatortype_append(GRAPH_OT_scale_to_right); + WM_operatortype_append(GRAPH_OT_scale_right); WM_operatortype_append(GRAPH_OT_blend_to_default); WM_operatortype_append(GRAPH_OT_gaussian_smooth); WM_operatortype_append(GRAPH_OT_euler_filter); diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index c6ade37f53f..5a7a98ac997 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1061,10 +1061,10 @@ void GRAPH_OT_ease(wmOperatorType *ot) } /* -------------------------------------------------------------------- */ -/** \name Scale to Right Operator +/** \name Scale Right Operator * \{ */ -static void scale_to_right_graph_keys(bAnimContext *ac, const float factor) +static void scale_right_graph_keys(bAnimContext *ac, const float factor) { ListBase anim_data = {NULL, NULL}; @@ -1074,7 +1074,7 @@ static void scale_to_right_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { - scale_to_right_fcurve_segment(fcu, segment, factor); + scale_right_fcurve_segment(fcu, segment, factor); } ale->update |= ANIM_UPDATE_DEFAULT; @@ -1085,7 +1085,7 @@ static void scale_to_right_graph_keys(bAnimContext *ac, const float factor) ANIM_animdata_freelist(&anim_data); } -static void scale_to_right_draw_status_header(bContext *C, tGraphSliderOp *gso) +static void scale_right_draw_status_header(bContext *C, tGraphSliderOp *gso) { char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; @@ -1093,7 +1093,7 @@ static void scale_to_right_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR); - strcpy(mode_str, TIP_("Scale to Right Keys")); + strcpy(mode_str, TIP_("Scale Right Keys")); if (hasNumInput(&gso->num)) { char str_ofs[NUM_STR_REP_LEN]; @@ -1109,20 +1109,20 @@ static void scale_to_right_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_workspace_status_text(C, status_str); } -static void scale_to_right_modal_update(bContext *C, wmOperator *op) +static void scale_right_modal_update(bContext *C, wmOperator *op) { tGraphSliderOp *gso = op->customdata; - scale_to_right_draw_status_header(C, gso); + scale_right_draw_status_header(C, gso); /* Reset keyframes to the state at invoke. */ reset_bezts(gso); const float factor = slider_factor_get_and_remember(op); - scale_to_right_graph_keys(&gso->ac, factor); + scale_right_graph_keys(&gso->ac, factor); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } -static int scale_to_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) +static int scale_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) { const int invoke_result = graph_slider_invoke(C, op, event); @@ -1131,14 +1131,14 @@ static int scale_to_right_invoke(bContext *C, wmOperator *op, const wmEvent *eve } tGraphSliderOp *gso = op->customdata; - gso->modal_update = scale_to_right_modal_update; + gso->modal_update = scale_right_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); - scale_to_right_draw_status_header(C, gso); + scale_right_draw_status_header(C, gso); return invoke_result; } -static int scale_to_right_exec(bContext *C, wmOperator *op) +static int scale_right_exec(bContext *C, wmOperator *op) { bAnimContext ac; @@ -1149,7 +1149,7 @@ static int scale_to_right_exec(bContext *C, wmOperator *op) const float factor = RNA_float_get(op->ptr, "factor"); - scale_to_right_graph_keys(&ac, factor); + scale_right_graph_keys(&ac, factor); /* Set notifier that keyframes have changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -1157,18 +1157,18 @@ static int scale_to_right_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void GRAPH_OT_scale_to_right(wmOperatorType *ot) +void GRAPH_OT_scale_right(wmOperatorType *ot) { /* Identifiers. */ - ot->name = "Scale to Right Keyframes"; - ot->idname = "GRAPH_OT_scale_to_right"; + ot->name = "Scale Right Keyframes"; + ot->idname = "GRAPH_OT_scale_right"; ot->description = "Increase or decrease the value of selected keys \n\ in relationship to the right neighboring one"; /* API callbacks. */ - ot->invoke = scale_to_right_invoke; + ot->invoke = scale_right_invoke; ot->modal = graph_slider_modal; - ot->exec = scale_to_right_exec; + ot->exec = scale_right_exec; ot->poll = graphop_editable_keyframes_poll; /* Flags. */ -- 2.30.2 From e55f38f298ea82b1abbff8df5642e789f061e992 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 3 Apr 2023 10:50:05 -0700 Subject: [PATCH 3/6] fixed some formating --- source/blender/editors/animation/keyframes_general.c | 2 +- source/blender/editors/space_graph/graph_slider_ops.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index b4eeeb5a2e4..41b72c20b05 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -505,7 +505,7 @@ void scale_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float } /* The factor goes from 0 to 1, but for this tool it needs to go from -1 to 1. */ - const float long_factor = factor * 2 - 1; + const float long_factor = factor * 2 - 1; for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { const float delta = fcu->bezt[i].vec[1][1] - right_key->vec[1][1]; diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 5a7a98ac997..abcfd01f02d 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1162,7 +1162,8 @@ void GRAPH_OT_scale_right(wmOperatorType *ot) /* Identifiers. */ ot->name = "Scale Right Keyframes"; ot->idname = "GRAPH_OT_scale_right"; - ot->description = "Increase or decrease the value of selected keys \n\ + ot->description = + "Increase or decrease the value of selected keys \n\ in relationship to the right neighboring one"; /* API callbacks. */ -- 2.30.2 From 18199f1afe392fb20d32dda857f7fdc4ed69f5c5 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 10 Apr 2023 17:01:51 -0700 Subject: [PATCH 4/6] took away not necesary lines of code --- source/blender/editors/animation/keyframes_general.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 41b72c20b05..274a65b72f1 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -493,17 +493,8 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor void scale_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { - const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); - const float key_x_range = right_key->vec[1][0] - left_key->vec[1][0]; - - /* Happens if there is only 1 key on the FCurve. Needs to be skipped because it - * would be a divide by 0. */ - if (IS_EQF(key_x_range, 0.0f)) { - return; - } - /* The factor goes from 0 to 1, but for this tool it needs to go from -1 to 1. */ const float long_factor = factor * 2 - 1; -- 2.30.2 From 333b93393635644165329ad3c6d6acfdf95cb7d5 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 17 Apr 2023 22:38:39 -0700 Subject: [PATCH 5/6] Converted the slider to bidirectional --- source/blender/editors/animation/keyframes_general.c | 5 +---- source/blender/editors/space_graph/graph_slider_ops.c | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 274a65b72f1..58bef0847ff 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -495,12 +495,9 @@ void scale_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float { const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); - /* The factor goes from 0 to 1, but for this tool it needs to go from -1 to 1. */ - const float long_factor = factor * 2 - 1; - for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { const float delta = fcu->bezt[i].vec[1][1] - right_key->vec[1][1]; - const float key_y_value = fcu->bezt[i].vec[1][1] + delta * long_factor; + const float key_y_value = fcu->bezt[i].vec[1][1] + delta * factor; move_key(&fcu->bezt[i], key_y_value); } } diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index abcfd01f02d..dfcb0ee8140 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1134,6 +1134,8 @@ static int scale_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) gso->modal_update = scale_right_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); scale_right_draw_status_header(C, gso); + ED_slider_is_bidirectional_set(gso->slider, true); + ED_slider_factor_set(gso->slider, 0.0f); return invoke_result; } -- 2.30.2 From be961b3c634310ddb9b3597b9d20d3fda94d3077 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Thu, 20 Apr 2023 20:43:28 -0700 Subject: [PATCH 6/6] changed name to "Scale from Right" --- scripts/startup/bl_ui/space_graph.py | 2 +- .../editors/animation/keyframes_general.c | 2 +- .../editors/include/ED_keyframes_edit.h | 2 +- .../editors/space_graph/graph_intern.h | 2 +- .../blender/editors/space_graph/graph_ops.c | 2 +- .../editors/space_graph/graph_slider_ops.c | 40 +++++++++---------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 0e738c721b5..f6948dabb8d 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -330,7 +330,7 @@ class GRAPH_MT_slider(Menu): layout.operator("graph.blend_to_neighbor", text="Blend to Neighbor") layout.operator("graph.blend_to_default", text="Blend to Default Value") layout.operator("graph.ease", text="Ease") - layout.operator("graph.scale_right", text="Scale Right") + layout.operator("graph.scale_from_right", text="Scale from Right") layout.operator("graph.gaussian_smooth", text="Smooth") diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 58bef0847ff..b7a728086ad 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,7 +491,7 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ -void scale_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) +void scale_from_right_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 8d2c6fc1730..78d3d4752f5 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -437,7 +437,7 @@ void smooth_fcurve_segment(struct FCurve *fcu, int kernel_size, double *kernel); void ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); -void scale_right_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); +void scale_from_right_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max); void blend_to_default_fcurve(struct PointerRNA *id_ptr, struct FCurve *fcu, float factor); /** diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 2c9c41ae840..312a1d0f0d9 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -114,7 +114,7 @@ void GRAPH_OT_clean(struct wmOperatorType *ot); void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot); void GRAPH_OT_breakdown(struct wmOperatorType *ot); void GRAPH_OT_ease(struct wmOperatorType *ot); -void GRAPH_OT_scale_right(struct wmOperatorType *ot); +void GRAPH_OT_scale_from_right(struct wmOperatorType *ot); void GRAPH_OT_decimate(struct wmOperatorType *ot); void GRAPH_OT_blend_to_default(struct wmOperatorType *ot); void GRAPH_OT_gaussian_smooth(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 9fe346f9218..f364e362db3 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -463,7 +463,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_blend_to_neighbor); WM_operatortype_append(GRAPH_OT_breakdown); WM_operatortype_append(GRAPH_OT_ease); - WM_operatortype_append(GRAPH_OT_scale_right); + WM_operatortype_append(GRAPH_OT_scale_from_right); WM_operatortype_append(GRAPH_OT_blend_to_default); WM_operatortype_append(GRAPH_OT_gaussian_smooth); WM_operatortype_append(GRAPH_OT_euler_filter); diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index dfcb0ee8140..b0b98ed65f0 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1061,10 +1061,10 @@ void GRAPH_OT_ease(wmOperatorType *ot) } /* -------------------------------------------------------------------- */ -/** \name Scale Right Operator +/** \name Scale from Right Operator * \{ */ -static void scale_right_graph_keys(bAnimContext *ac, const float factor) +static void scale_from_right_graph_keys(bAnimContext *ac, const float factor) { ListBase anim_data = {NULL, NULL}; @@ -1074,7 +1074,7 @@ static void scale_right_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { - scale_right_fcurve_segment(fcu, segment, factor); + scale_from_right_fcurve_segment(fcu, segment, factor); } ale->update |= ANIM_UPDATE_DEFAULT; @@ -1085,7 +1085,7 @@ static void scale_right_graph_keys(bAnimContext *ac, const float factor) ANIM_animdata_freelist(&anim_data); } -static void scale_right_draw_status_header(bContext *C, tGraphSliderOp *gso) +static void scale_from_right_draw_status_header(bContext *C, tGraphSliderOp *gso) { char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; @@ -1093,7 +1093,7 @@ static void scale_right_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR); - strcpy(mode_str, TIP_("Scale Right Keys")); + strcpy(mode_str, TIP_("Scale from Right Keys")); if (hasNumInput(&gso->num)) { char str_ofs[NUM_STR_REP_LEN]; @@ -1109,20 +1109,20 @@ static void scale_right_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_workspace_status_text(C, status_str); } -static void scale_right_modal_update(bContext *C, wmOperator *op) +static void scale_from_right_modal_update(bContext *C, wmOperator *op) { tGraphSliderOp *gso = op->customdata; - scale_right_draw_status_header(C, gso); + scale_from_right_draw_status_header(C, gso); /* Reset keyframes to the state at invoke. */ reset_bezts(gso); const float factor = slider_factor_get_and_remember(op); - scale_right_graph_keys(&gso->ac, factor); + scale_from_right_graph_keys(&gso->ac, factor); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } -static int scale_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) +static int scale_from_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) { const int invoke_result = graph_slider_invoke(C, op, event); @@ -1131,16 +1131,16 @@ static int scale_right_invoke(bContext *C, wmOperator *op, const wmEvent *event) } tGraphSliderOp *gso = op->customdata; - gso->modal_update = scale_right_modal_update; + gso->modal_update = scale_from_right_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); - scale_right_draw_status_header(C, gso); + scale_from_right_draw_status_header(C, gso); ED_slider_is_bidirectional_set(gso->slider, true); ED_slider_factor_set(gso->slider, 0.0f); return invoke_result; } -static int scale_right_exec(bContext *C, wmOperator *op) +static int scale_from_right_exec(bContext *C, wmOperator *op) { bAnimContext ac; @@ -1151,7 +1151,7 @@ static int scale_right_exec(bContext *C, wmOperator *op) const float factor = RNA_float_get(op->ptr, "factor"); - scale_right_graph_keys(&ac, factor); + scale_from_right_graph_keys(&ac, factor); /* Set notifier that keyframes have changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -1159,19 +1159,19 @@ static int scale_right_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void GRAPH_OT_scale_right(wmOperatorType *ot) +void GRAPH_OT_scale_from_right(wmOperatorType *ot) { /* Identifiers. */ - ot->name = "Scale Right Keyframes"; - ot->idname = "GRAPH_OT_scale_right"; + ot->name = "Scale from Right Keyframes"; + ot->idname = "GRAPH_OT_scale_from_right"; ot->description = "Increase or decrease the value of selected keys \n\ in relationship to the right neighboring one"; /* API callbacks. */ - ot->invoke = scale_right_invoke; + ot->invoke = scale_from_right_invoke; ot->modal = graph_slider_modal; - ot->exec = scale_right_exec; + ot->exec = scale_from_right_exec; ot->poll = graphop_editable_keyframes_poll; /* Flags. */ @@ -1179,12 +1179,12 @@ void GRAPH_OT_scale_right(wmOperatorType *ot) RNA_def_float_factor(ot->srna, "factor", - 0.5f, + 0.0f, -FLT_MAX, FLT_MAX, "Curve Bend", "Control the bend of the curve", - 0.0f, + -1.0f, 1.0f); } -- 2.30.2