From 3364a5bea6c977069210c3325111dc28051ee1cb Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Thu, 4 Nov 2021 21:35:28 +0000 Subject: Cleanup: move code in graph_slider_ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Future operators can use the same code, so it is moved up to disassociate it from decimate No functional changes Reviewed by: Sybren A. Stüvel Differential Revision: https://developer.blender.org/D12489 Ref: D12489 --- .../blender/editors/space_graph/graph_slider_ops.c | 68 +++++++++++----------- 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'source/blender/editors/space_graph') diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index f669a7e193d..14a8f73a3a4 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -53,7 +53,10 @@ (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_SEL | \ ANIMFILTER_NODUPLIS) -/* ------------------- */ +/* ******************** GRAPH SLIDER OPERATORS ************************* */ +/* This file contains a collection of operators to modify keyframes in the graph editor. All + * operators are modal and use a slider that allows the user to define a percentage to modify the + * operator. */ /* This data type is only used for modal operation. */ typedef struct tGraphSliderOp { @@ -78,16 +81,6 @@ typedef struct tBeztCopyData { BezTriple *bezt; } tBeztCopyData; -typedef enum tDecimModes { - DECIM_RATIO = 1, - DECIM_ERROR, -} tDecimModes; - -/* ******************** GRAPH SLIDER OPERATORS ************************* */ -/* This file contains a collection of operators to modify keyframes in the graph editor. All - * operators are modal and use a slider that allows the user to define a percentage to modify the - * operator. */ - /* ******************** Utility Functions ************************* */ /* Construct a list with the original bezt arrays so we can restore them during modal operation. @@ -130,30 +123,6 @@ static void store_original_bezt_arrays(tGraphSliderOp *gso) ANIM_animdata_freelist(&anim_data); } -/* ******************** Decimate Keyframes Operator ************************* */ - -static void decimate_graph_keys(bAnimContext *ac, float remove_ratio, float error_sq_max) -{ - ListBase anim_data = {NULL, NULL}; - bAnimListElem *ale; - - /* Filter data. */ - ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype); - - /* Loop through filtered data and clean curves. */ - for (ale = anim_data.first; ale; ale = ale->next) { - if (!decimate_fcurve(ale, remove_ratio, error_sq_max)) { - /* The selection contains unsupported keyframe types! */ - WM_report(RPT_WARNING, "Decimate: Skipping non linear/bezier keyframes!"); - } - - ale->update |= ANIM_UPDATE_DEFAULT; - } - - ANIM_animdata_update(ac, &anim_data); - ANIM_animdata_freelist(&anim_data); -} - /* Overwrite the current bezts arrays with the original data. */ static void reset_bezts(tGraphSliderOp *gso) { @@ -192,6 +161,35 @@ static void reset_bezts(tGraphSliderOp *gso) ANIM_animdata_freelist(&anim_data); } +/* ******************** Decimate Keyframes Operator ************************* */ + +typedef enum tDecimModes { + DECIM_RATIO = 1, + DECIM_ERROR, +} tDecimModes; + +static void decimate_graph_keys(bAnimContext *ac, float remove_ratio, float error_sq_max) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + + /* Filter data. */ + ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype); + + /* Loop through filtered data and clean curves. */ + for (ale = anim_data.first; ale; ale = ale->next) { + if (!decimate_fcurve(ale, remove_ratio, error_sq_max)) { + /* The selection contains unsupported keyframe types! */ + WM_report(RPT_WARNING, "Decimate: Skipping non linear/bezier keyframes!"); + } + + ale->update |= ANIM_UPDATE_DEFAULT; + } + + ANIM_animdata_update(ac, &anim_data); + ANIM_animdata_freelist(&anim_data); +} + static void decimate_exit(bContext *C, wmOperator *op) { tGraphSliderOp *gso = op->customdata; -- cgit v1.2.3