forked from bartvdbraak/blender
Fix for [#33378] Grease pencil dopesheet fails on a few operations
Snapping operator in action editor for grease pencil and mask wasn't implemented. We could probably re-enabled/fix/cleanup more things in this area (e.g. use a custom poll func for operators not supporting gp/mask, instead of silently doing nothing), but this is for after 2.65 imho).
This commit is contained in:
parent
4f3fdb8d5a
commit
582a9d1c45
@ -49,6 +49,7 @@
|
||||
#include "ED_anim_api.h"
|
||||
#include "ED_gpencil.h"
|
||||
#include "ED_keyframes_edit.h"
|
||||
#include "ED_markers.h"
|
||||
|
||||
#include "gpencil_intern.h"
|
||||
|
||||
@ -460,11 +461,12 @@ void paste_gpdata(Scene *scene)
|
||||
/* undo and redraw stuff */
|
||||
BIF_undo_push("Paste Grease Pencil Frames");
|
||||
}
|
||||
#endif /* XXX disabled until Grease Pencil code stabilises again... */
|
||||
|
||||
/* -------------------------------------- */
|
||||
/* Snap Tools */
|
||||
|
||||
static short snap_gpf_nearest(bGPDframe *gpf, Scene *scene)
|
||||
static short snap_gpf_nearest(bGPDframe *gpf, Scene *UNUSED(scene))
|
||||
{
|
||||
if (gpf->flag & GP_FRAME_SELECT)
|
||||
gpf->framenum = (int)(floor(gpf->framenum + 0.5));
|
||||
@ -489,33 +491,32 @@ static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene)
|
||||
static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene)
|
||||
{
|
||||
if (gpf->flag & GP_FRAME_SELECT)
|
||||
gpf->framenum = (int)find_nearest_marker_time(&scene->markers, (float)gpf->framenum);
|
||||
gpf->framenum = (int)ED_markers_find_nearest_marker_time(&scene->markers, (float)gpf->framenum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* snap selected frames to ... */
|
||||
void snap_gplayer_frames(bGPDlayer *gpl, Scene *scene, short mode)
|
||||
void ED_gplayer_snap_frames(bGPDlayer *gpl, Scene *scene, short mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case 1: /* snap to nearest frame */
|
||||
case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */
|
||||
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearest);
|
||||
break;
|
||||
case 2: /* snap to current frame */
|
||||
case SNAP_KEYS_CURFRAME: /* snap to current frame */
|
||||
ED_gplayer_frames_looper(gpl, scene, snap_gpf_cframe);
|
||||
break;
|
||||
case 3: /* snap to nearest marker */
|
||||
case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */
|
||||
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearmarker);
|
||||
break;
|
||||
case 4: /* snap to nearest second */
|
||||
case SNAP_KEYS_NEARSEC: /* snap to nearest second */
|
||||
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearestsec);
|
||||
break;
|
||||
default: /* just in case */
|
||||
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /* XXX disabled until grease pencil code stabilises again */
|
||||
/* -------------------------------------- */
|
||||
/* Mirror Tools */
|
||||
|
||||
|
@ -97,12 +97,13 @@ void ED_gpencil_select_frame(struct bGPDlayer *gpl, int selx, short select_mode
|
||||
void ED_gplayer_frames_delete(struct bGPDlayer *gpl);
|
||||
void ED_gplayer_frames_duplicate(struct bGPDlayer *gpl);
|
||||
|
||||
void ED_gplayer_snap_frames(struct bGPDlayer *gpl, struct Scene *scene, short mode);
|
||||
|
||||
#if 0
|
||||
void free_gpcopybuf(void);
|
||||
void copy_gpdata(void);
|
||||
void paste_gpdata(void);
|
||||
|
||||
void snap_gplayer_frames(struct bGPDlayer *gpl, short mode);
|
||||
void mirror_gplayer_frames(struct bGPDlayer *gpl, short mode);
|
||||
#endif
|
||||
|
||||
|
@ -83,12 +83,13 @@ void ED_mask_select_frame(struct MaskLayer *masklay, int selx, short select_mod
|
||||
void ED_masklayer_frames_delete(struct MaskLayer *masklay);
|
||||
void ED_masklayer_frames_duplicate(struct MaskLayer *masklay);
|
||||
|
||||
void ED_masklayer_snap_frames(struct MaskLayer *masklay, struct Scene *scene, short mode);
|
||||
|
||||
#if 0
|
||||
void free_gpcopybuf(void);
|
||||
void copy_gpdata(void);
|
||||
void paste_gpdata(void);
|
||||
|
||||
void snap_masklayer_frames(struct MaskLayer *masklay, short mode);
|
||||
void mirror_masklayer_frames(struct MaskLayer *masklay, short mode);
|
||||
#endif
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "ED_anim_api.h"
|
||||
#include "ED_keyframes_edit.h"
|
||||
#include "ED_mask.h" /* own include */
|
||||
#include "ED_markers.h"
|
||||
|
||||
/* ***************************************** */
|
||||
/* NOTE ABOUT THIS FILE:
|
||||
@ -249,3 +250,57 @@ void ED_masklayer_frames_duplicate(MaskLayer *masklay)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
/* Snap Tools */
|
||||
|
||||
static short snap_masklayer_nearest(MaskLayerShape *masklay_shape, Scene *UNUSED(scene))
|
||||
{
|
||||
if (masklay_shape->flag & MASK_SHAPE_SELECT)
|
||||
masklay_shape->frame = (int)(floor(masklay_shape->frame + 0.5));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static short snap_masklayer_nearestsec(MaskLayerShape *masklay_shape, Scene *scene)
|
||||
{
|
||||
float secf = (float)FPS;
|
||||
if (masklay_shape->flag & MASK_SHAPE_SELECT)
|
||||
masklay_shape->frame = (int)(floor(masklay_shape->frame / secf + 0.5f) * secf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static short snap_masklayer_cframe(MaskLayerShape *masklay_shape, Scene *scene)
|
||||
{
|
||||
if (masklay_shape->flag & MASK_SHAPE_SELECT)
|
||||
masklay_shape->frame = (int)CFRA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static short snap_masklayer_nearmarker(MaskLayerShape *masklay_shape, Scene *scene)
|
||||
{
|
||||
if (masklay_shape->flag & MASK_SHAPE_SELECT)
|
||||
masklay_shape->frame = (int)ED_markers_find_nearest_marker_time(&scene->markers, (float)masklay_shape->frame);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* snap selected frames to ... */
|
||||
void ED_masklayer_snap_frames(MaskLayer *masklay, Scene *scene, short mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */
|
||||
ED_masklayer_frames_looper(masklay, scene, snap_masklayer_nearest);
|
||||
break;
|
||||
case SNAP_KEYS_CURFRAME: /* snap to current frame */
|
||||
ED_masklayer_frames_looper(masklay, scene, snap_masklayer_cframe);
|
||||
break;
|
||||
case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */
|
||||
ED_masklayer_frames_looper(masklay, scene, snap_masklayer_nearmarker);
|
||||
break;
|
||||
case SNAP_KEYS_NEARSEC: /* snap to nearest second */
|
||||
ED_masklayer_frames_looper(masklay, scene, snap_masklayer_nearestsec);
|
||||
break;
|
||||
default: /* just in case */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1412,15 +1412,20 @@ static void snap_action_keys(bAnimContext *ac, short mode)
|
||||
for (ale = anim_data.first; ale; ale = ale->next) {
|
||||
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
||||
|
||||
if (adt) {
|
||||
if (ale->type == ANIMTYPE_GPLAYER) {
|
||||
ED_gplayer_snap_frames(ale->data, ac->scene, mode);
|
||||
}
|
||||
else if (ale->type == ANIMTYPE_MASKLAYER) {
|
||||
ED_masklayer_snap_frames(ale->data, ac->scene, mode);
|
||||
}
|
||||
else if (adt) {
|
||||
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
|
||||
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
||||
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
|
||||
}
|
||||
//else if (ale->type == ACTTYPE_GPLAYER)
|
||||
// snap_gplayer_frames(ale->data, mode);
|
||||
else
|
||||
else {
|
||||
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_freelistN(&anim_data);
|
||||
@ -1436,11 +1441,7 @@ static int actkeys_snap_exec(bContext *C, wmOperator *op)
|
||||
/* get editor data */
|
||||
if (ANIM_animdata_get_context(C, &ac) == 0)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
/* XXX... */
|
||||
if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
|
||||
|
||||
/* get snapping mode */
|
||||
mode = RNA_enum_get(op->ptr, "type");
|
||||
|
||||
@ -1448,7 +1449,8 @@ static int actkeys_snap_exec(bContext *C, wmOperator *op)
|
||||
snap_action_keys(&ac, mode);
|
||||
|
||||
/* validate keyframes after editing */
|
||||
ANIM_editkeyframes_refresh(&ac);
|
||||
if (!ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
|
||||
ANIM_editkeyframes_refresh(&ac);
|
||||
|
||||
/* set notifier that keyframes have changed */
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user