From ba26adee0c5caa6d4f3ffbda9c7038e807e3f9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 16 Mar 2020 16:16:35 +0100 Subject: Fix T61234 Mirroring Grease Pencil keyframes in the Dopesheet fails `ANIM_animdata_update()` did not sort grease pencil frames. A pre-existing comment stated this wouldn't be necessary as `posttrans_gpd_clean()` already does this. However, this is only applicable when the change is performed via the transform system. The mirror operator doesn't call `posttrans_gpd_clean()`, invalidating the assumption in the comment. I moved the sorting code into `BKE_gpencil_layer_frames_sort()`, which is now called from both `ANIM_animdata_update()` and `posttrans_gpd_clean()`. --- source/blender/blenkernel/intern/gpencil.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source/blender/blenkernel/intern/gpencil.c') diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index c587e433e7f..c0b40721ccc 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1120,6 +1120,32 @@ void BKE_gpencil_layer_mask_sort_all(bGPdata *gpd) } } +static int gpencil_cb_cmp_frame(void *thunk, const void *a, const void *b) +{ + const bGPDframe *frame_a = a; + const bGPDframe *frame_b = b; + + if (frame_a->framenum < frame_b->framenum) { + return -1; + } + if (frame_a->framenum > frame_b->framenum) { + return 1; + } + if (thunk != NULL) { + *((bool *)thunk) = true; + } + /* Sort selected last. */ + if ((frame_a->flag & GP_FRAME_SELECT) && ((frame_b->flag & GP_FRAME_SELECT) == 0)) { + return 1; + } + return 0; +} + +void BKE_gpencil_layer_frames_sort(struct bGPDlayer *gpl, bool *r_has_duplicate_frames) +{ + BLI_listbase_sort_r(&gpl->frames, gpencil_cb_cmp_frame, r_has_duplicate_frames); +} + /* get the active gp-layer for editing */ bGPDlayer *BKE_gpencil_layer_active_get(bGPdata *gpd) { -- cgit v1.2.3