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:
authorSybren A. Stüvel <sybren@blender.org>2020-10-16 17:07:50 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-10-16 17:09:20 +0300
commitdf4a93aca0a7c6f00370b1aad7439526434e30ce (patch)
tree2ad42c4a0aa767bb5dd2c3e6cef8cc601191b5d2 /source/blender/editors/space_graph/graph_edit.c
parent342be27daac8b868c709062c8a23bc50f20fe393 (diff)
Cleanup: Animation, split up frame jump operator
Split up `GRAPH_OT_frame_jump` exec function and added some local variables to give names to the cryptic `ked.f1`, `ked.f2`, and `ked.i1`. No functional changes.
Diffstat (limited to 'source/blender/editors/space_graph/graph_edit.c')
-rw-r--r--source/blender/editors/space_graph/graph_edit.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 9fe6b4e06f6..3ec68971dea 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -2738,34 +2738,27 @@ static bool graphkeys_framejump_poll(bContext *C)
return graphop_visible_keyframes_poll(C);
}
-/* snap current-frame indicator to 'average time' of selected keyframe */
-static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op))
+static KeyframeEditData sum_selected_keyframes(bAnimContext *ac)
{
- bAnimContext ac;
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
KeyframeEditData ked;
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0) {
- return OPERATOR_CANCELLED;
- }
-
/* init edit data */
memset(&ked, 0, sizeof(KeyframeEditData));
/* loop over action data, averaging values */
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
- ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
for (ale = anim_data.first; ale; ale = ale->next) {
- AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
- short mapping_flag = ANIM_get_normalization_flags(&ac);
+ AnimData *adt = ANIM_nla_mapping_get(ac, ale);
+ short mapping_flag = ANIM_get_normalization_flags(ac);
KeyframeEditData current_ked;
float offset;
float unit_scale = ANIM_unit_mapping_get_factor(
- ac.scene, ale->id, ale->key_data, mapping_flag | ANIM_UNITCONV_ONLYKEYS, &offset);
+ ac->scene, ale->id, ale->key_data, mapping_flag | ANIM_UNITCONV_ONLYKEYS, &offset);
memset(&current_ked, 0, sizeof(current_ked));
@@ -2786,24 +2779,43 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op))
ANIM_animdata_freelist(&anim_data);
+ return ked;
+}
+
+/* snap current-frame indicator to 'average time' of selected keyframe */
+static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ bAnimContext ac;
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0) {
+ return OPERATOR_CANCELLED;
+ }
+
+ const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
+ const float sum_time = keyframe_sum.f1;
+ const float sum_value = keyframe_sum.f2;
+ const int num_keyframes = keyframe_sum.i1;
+
+ if (num_keyframes == 0) {
+ return OPERATOR_FINISHED;
+ }
+
/* set the new current frame and cursor values, based on the average time and value */
- if (ked.i1) {
- SpaceGraph *sipo = (SpaceGraph *)ac.sl;
- Scene *scene = ac.scene;
+ SpaceGraph *sipo = (SpaceGraph *)ac.sl;
+ Scene *scene = ac.scene;
- /* take the average values, rounding to the nearest int as necessary for int results */
- if (sipo->mode == SIPO_MODE_DRIVERS) {
- /* Drivers Mode - Affects cursor (float) */
- sipo->cursorTime = ked.f1 / (float)ked.i1;
- sipo->cursorVal = ked.f2 / (float)ked.i1;
- }
- else {
- /* Animation Mode - Affects current frame (int) */
- CFRA = round_fl_to_int(ked.f1 / ked.i1);
- SUBFRA = 0.f;
- sipo->cursorVal = ked.f2 / (float)ked.i1;
- }
+ /* take the average values, rounding to the nearest int as necessary for int results */
+ if (sipo->mode == SIPO_MODE_DRIVERS) {
+ /* Drivers Mode - Affects cursor (float) */
+ sipo->cursorTime = sum_time / (float)num_keyframes;
+ }
+ else {
+ /* Animation Mode - Affects current frame (int) */
+ CFRA = round_fl_to_int(sum_time / num_keyframes);
+ SUBFRA = 0.f;
}
+ sipo->cursorVal = sum_value / (float)num_keyframes;
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);