diff options
Diffstat (limited to 'source/blender/editors/gpencil/editaction_gpencil.c')
-rw-r--r-- | source/blender/editors/gpencil/editaction_gpencil.c | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c index d2b1eba7d86..752b8a74f4f 100644 --- a/source/blender/editors/gpencil/editaction_gpencil.c +++ b/source/blender/editors/gpencil/editaction_gpencil.c @@ -56,7 +56,9 @@ /* Generics - Loopers */ /* Loops over the gp-frames for a gp-layer, and applies the given callback */ -bool ED_gplayer_frames_looper(bGPDlayer *gpl, Scene *scene, short (*gpf_cb)(bGPDframe *, Scene *)) +bool ED_gpencil_layer_frames_looper(bGPDlayer *gpl, + Scene *scene, + short (*gpf_cb)(bGPDframe *, Scene *)) { /* error checker */ if (gpl == NULL) { @@ -79,7 +81,7 @@ bool ED_gplayer_frames_looper(bGPDlayer *gpl, Scene *scene, short (*gpf_cb)(bGPD /* Data Conversion Tools */ /* make a listing all the gp-frames in a layer as cfraelems */ -void ED_gplayer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel) +void ED_gpencil_layer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel) { CfraElem *ce; @@ -105,7 +107,7 @@ void ED_gplayer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel) /* Selection Tools */ /* check if one of the frames in this layer is selected */ -bool ED_gplayer_frame_select_check(bGPDlayer *gpl) +bool ED_gpencil_layer_frame_select_check(bGPDlayer *gpl) { /* error checking */ if (gpl == NULL) { @@ -124,7 +126,7 @@ bool ED_gplayer_frame_select_check(bGPDlayer *gpl) } /* helper function - select gp-frame based on SELECT_* mode */ -static void gpframe_select(bGPDframe *gpf, short select_mode) +static void gpencil_frame_select(bGPDframe *gpf, short select_mode) { if (gpf == NULL) { return; @@ -153,12 +155,12 @@ void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode) /* handle according to mode */ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - gpframe_select(gpf, select_mode); + gpencil_frame_select(gpf, select_mode); } } /* set all/none/invert select */ -void ED_gplayer_frame_select_set(bGPDlayer *gpl, short mode) +void ED_gpencil_layer_frame_select_set(bGPDlayer *gpl, short mode) { /* error checking */ if (gpl == NULL) { @@ -181,12 +183,12 @@ void ED_gpencil_select_frame(bGPDlayer *gpl, int selx, short select_mode) gpf = BKE_gpencil_layer_frame_find(gpl, selx); if (gpf) { - gpframe_select(gpf, select_mode); + gpencil_frame_select(gpf, select_mode); } } /* select the frames in this layer that occur within the bounds specified */ -void ED_gplayer_frames_select_box(bGPDlayer *gpl, float min, float max, short select_mode) +void ED_gpencil_layer_frames_select_box(bGPDlayer *gpl, float min, float max, short select_mode) { if (gpl == NULL) { return; @@ -195,16 +197,16 @@ void ED_gplayer_frames_select_box(bGPDlayer *gpl, float min, float max, short se /* only select those frames which are in bounds */ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { if (IN_RANGE(gpf->framenum, min, max)) { - gpframe_select(gpf, select_mode); + gpencil_frame_select(gpf, select_mode); } } } /* select the frames in this layer that occur within the lasso/circle region specified */ -void ED_gplayer_frames_select_region(KeyframeEditData *ked, - bGPDlayer *gpl, - short tool, - short select_mode) +void ED_gpencil_layer_frames_select_region(KeyframeEditData *ked, + bGPDlayer *gpl, + short tool, + short select_mode) { if (gpl == NULL) { return; @@ -222,13 +224,13 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked, if (tool == BEZT_OK_CHANNEL_LASSO) { /* Lasso */ if (keyframe_region_lasso_test(ked->data, pt)) { - gpframe_select(gpf, select_mode); + gpencil_frame_select(gpf, select_mode); } } else if (tool == BEZT_OK_CHANNEL_CIRCLE) { /* Circle */ if (keyframe_region_circle_test(ked->data, pt)) { - gpframe_select(gpf, select_mode); + gpencil_frame_select(gpf, select_mode); } } } @@ -238,7 +240,7 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked, /* Frame Editing Tools */ /* Delete selected frames */ -bool ED_gplayer_frames_delete(bGPDlayer *gpl) +bool ED_gpencil_layer_frames_delete(bGPDlayer *gpl) { bool changed = false; @@ -259,7 +261,7 @@ bool ED_gplayer_frames_delete(bGPDlayer *gpl) } /* Duplicate selected frames from given gp-layer */ -void ED_gplayer_frames_duplicate(bGPDlayer *gpl) +void ED_gpencil_layer_frames_duplicate(bGPDlayer *gpl) { /* error checking */ if (gpl == NULL) { @@ -282,10 +284,12 @@ void ED_gplayer_frames_duplicate(bGPDlayer *gpl) } } -/* Set keyframe type for selected frames from given gp-layer - * \param type: The type of keyframe (eBezTriple_KeyframeType) to set selected frames to +/** + * Set keyframe type for selected frames from given gp-layer + * + * \param type: The type of keyframe (#eBezTriple_KeyframeType) to set selected frames to. */ -void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type) +void ED_gpencil_layer_frames_keytype_set(bGPDlayer *gpl, short type) { if (gpl == NULL) { return; @@ -311,20 +315,20 @@ void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type) */ /* globals for copy/paste data (like for other copy/paste buffers) */ -static ListBase gp_anim_copybuf = {NULL, NULL}; -static int gp_anim_copy_firstframe = 999999999; -static int gp_anim_copy_lastframe = -999999999; -static int gp_anim_copy_cfra = 0; +static ListBase gpencil_anim_copybuf = {NULL, NULL}; +static int gpencil_anim_copy_firstframe = 999999999; +static int gpencil_anim_copy_lastframe = -999999999; +static int gpencil_anim_copy_cfra = 0; /* This function frees any MEM_calloc'ed copy/paste buffer data */ void ED_gpencil_anim_copybuf_free(void) { - BKE_gpencil_free_layers(&gp_anim_copybuf); - BLI_listbase_clear(&gp_anim_copybuf); + BKE_gpencil_free_layers(&gpencil_anim_copybuf); + BLI_listbase_clear(&gpencil_anim_copybuf); - gp_anim_copy_firstframe = 999999999; - gp_anim_copy_lastframe = -999999999; - gp_anim_copy_cfra = 0; + gpencil_anim_copy_firstframe = 999999999; + gpencil_anim_copy_lastframe = -999999999; + gpencil_anim_copy_cfra = 0; } /* This function adds data to the copy/paste buffer, freeing existing data first @@ -361,11 +365,11 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) BLI_addtail(&copied_frames, new_frame); /* extend extents for keyframes encountered */ - if (gpf->framenum < gp_anim_copy_firstframe) { - gp_anim_copy_firstframe = gpf->framenum; + if (gpf->framenum < gpencil_anim_copy_firstframe) { + gpencil_anim_copy_firstframe = gpf->framenum; } - if (gpf->framenum > gp_anim_copy_lastframe) { - gp_anim_copy_lastframe = gpf->framenum; + if (gpf->framenum > gpencil_anim_copy_lastframe) { + gpencil_anim_copy_lastframe = gpf->framenum; } } } @@ -373,7 +377,7 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) /* create a new layer in buffer if there were keyframes here */ if (BLI_listbase_is_empty(&copied_frames) == false) { bGPDlayer *new_layer = MEM_callocN(sizeof(bGPDlayer), "GPCopyPasteLayer"); - BLI_addtail(&gp_anim_copybuf, new_layer); + BLI_addtail(&gpencil_anim_copybuf, new_layer); /* move over copied frames */ BLI_movelisttolist(&new_layer->frames, &copied_frames); @@ -385,13 +389,13 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) } /* in case 'relative' paste method is used */ - gp_anim_copy_cfra = CFRA; + gpencil_anim_copy_cfra = CFRA; /* clean up */ ANIM_animdata_freelist(&anim_data); /* check if anything ended up in the buffer */ - if (ELEM(NULL, gp_anim_copybuf.first, gp_anim_copybuf.last)) { + if (ELEM(NULL, gpencil_anim_copybuf.first, gpencil_anim_copybuf.last)) { BKE_report(ac->reports, RPT_ERROR, "No keyframes copied to keyframes copy/paste buffer"); return false; } @@ -412,26 +416,26 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) int offset = 0; /* check if buffer is empty */ - if (BLI_listbase_is_empty(&gp_anim_copybuf)) { + if (BLI_listbase_is_empty(&gpencil_anim_copybuf)) { BKE_report(ac->reports, RPT_ERROR, "No data in buffer to paste"); return false; } /* check if single channel in buffer (disregard names if so) */ - if (gp_anim_copybuf.first == gp_anim_copybuf.last) { + if (gpencil_anim_copybuf.first == gpencil_anim_copybuf.last) { no_name = true; } /* methods of offset (eKeyPasteOffset) */ switch (offset_mode) { case KEYFRAME_PASTE_OFFSET_CFRA_START: - offset = (CFRA - gp_anim_copy_firstframe); + offset = (CFRA - gpencil_anim_copy_firstframe); break; case KEYFRAME_PASTE_OFFSET_CFRA_END: - offset = (CFRA - gp_anim_copy_lastframe); + offset = (CFRA - gpencil_anim_copy_lastframe); break; case KEYFRAME_PASTE_OFFSET_CFRA_RELATIVE: - offset = (CFRA - gp_anim_copy_cfra); + offset = (CFRA - gpencil_anim_copy_cfra); break; case KEYFRAME_PASTE_OFFSET_NONE: offset = 0; @@ -451,7 +455,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) bGPDframe *gpfs, *gpf; /* find suitable layer from buffer to use to paste from */ - for (gpls = gp_anim_copybuf.first; gpls; gpls = gpls->next) { + for (gpls = gpencil_anim_copybuf.first; gpls; gpls = gpls->next) { /* check if layer name matches */ if ((no_name) || STREQ(gpls->info, gpld->info)) { break; @@ -507,7 +511,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) /* -------------------------------------- */ /* Snap Tools */ -static short snap_gpf_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene)) +static short gpencil_frame_snap_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene)) { #if 0 /* note: gpf->framenum is already an int! */ if (gpf->flag & GP_FRAME_SELECT) { @@ -517,7 +521,7 @@ static short snap_gpf_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene)) return 0; } -static short snap_gpf_nearestsec(bGPDframe *gpf, Scene *scene) +static short gpencil_frame_snap_nearestsec(bGPDframe *gpf, Scene *scene) { float secf = (float)FPS; if (gpf->flag & GP_FRAME_SELECT) { @@ -526,7 +530,7 @@ static short snap_gpf_nearestsec(bGPDframe *gpf, Scene *scene) return 0; } -static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene) +static short gpencil_frame_snap_cframe(bGPDframe *gpf, Scene *scene) { if (gpf->flag & GP_FRAME_SELECT) { gpf->framenum = (int)CFRA; @@ -534,7 +538,7 @@ static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene) return 0; } -static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene) +static short gpencil_frame_snap_nearmarker(bGPDframe *gpf, Scene *scene) { if (gpf->flag & GP_FRAME_SELECT) { gpf->framenum = (int)ED_markers_find_nearest_marker_time(&scene->markers, @@ -544,20 +548,20 @@ static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene) } /* snap selected frames to ... */ -void ED_gplayer_snap_frames(bGPDlayer *gpl, Scene *scene, short mode) +void ED_gpencil_layer_snap_frames(bGPDlayer *gpl, Scene *scene, short mode) { switch (mode) { case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */ - ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearest); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_snap_nearest); break; case SNAP_KEYS_CURFRAME: /* snap to current frame */ - ED_gplayer_frames_looper(gpl, scene, snap_gpf_cframe); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_snap_cframe); break; case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */ - ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearmarker); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_snap_nearmarker); break; case SNAP_KEYS_NEARSEC: /* snap to nearest second */ - ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearestsec); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_snap_nearestsec); break; default: /* just in case */ break; @@ -567,7 +571,7 @@ void ED_gplayer_snap_frames(bGPDlayer *gpl, Scene *scene, short mode) /* -------------------------------------- */ /* Mirror Tools */ -static short mirror_gpf_cframe(bGPDframe *gpf, Scene *scene) +static short gpencil_frame_mirror_cframe(bGPDframe *gpf, Scene *scene) { int diff; @@ -579,7 +583,7 @@ static short mirror_gpf_cframe(bGPDframe *gpf, Scene *scene) return 0; } -static short mirror_gpf_yaxis(bGPDframe *gpf, Scene *UNUSED(scene)) +static short gpencil_frame_mirror_yaxis(bGPDframe *gpf, Scene *UNUSED(scene)) { int diff; @@ -591,7 +595,7 @@ static short mirror_gpf_yaxis(bGPDframe *gpf, Scene *UNUSED(scene)) return 0; } -static short mirror_gpf_xaxis(bGPDframe *gpf, Scene *UNUSED(scene)) +static short gpencil_frame_mirror_xaxis(bGPDframe *gpf, Scene *UNUSED(scene)) { int diff; @@ -604,7 +608,7 @@ static short mirror_gpf_xaxis(bGPDframe *gpf, Scene *UNUSED(scene)) return 0; } -static short mirror_gpf_marker(bGPDframe *gpf, Scene *scene) +static short gpencil_frame_mirror_marker(bGPDframe *gpf, Scene *scene) { static TimeMarker *marker; static short initialized = 0; @@ -646,25 +650,25 @@ static short mirror_gpf_marker(bGPDframe *gpf, Scene *scene) /* mirror selected gp-frames on... */ // TODO: mirror over a specific time -void ED_gplayer_mirror_frames(bGPDlayer *gpl, Scene *scene, short mode) +void ED_gpencil_layer_mirror_frames(bGPDlayer *gpl, Scene *scene, short mode) { switch (mode) { case MIRROR_KEYS_CURFRAME: /* mirror over current frame */ - ED_gplayer_frames_looper(gpl, scene, mirror_gpf_cframe); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_mirror_cframe); break; case MIRROR_KEYS_YAXIS: /* mirror over frame 0 */ - ED_gplayer_frames_looper(gpl, scene, mirror_gpf_yaxis); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_mirror_yaxis); break; case MIRROR_KEYS_XAXIS: /* mirror over value 0 */ - ED_gplayer_frames_looper(gpl, scene, mirror_gpf_xaxis); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_mirror_xaxis); break; case MIRROR_KEYS_MARKER: /* mirror over marker */ - mirror_gpf_marker(NULL, scene); - ED_gplayer_frames_looper(gpl, scene, mirror_gpf_marker); - mirror_gpf_marker(NULL, scene); + gpencil_frame_mirror_marker(NULL, scene); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_mirror_marker); + gpencil_frame_mirror_marker(NULL, scene); break; default: /* just in case */ - ED_gplayer_frames_looper(gpl, scene, mirror_gpf_yaxis); + ED_gpencil_layer_frames_looper(gpl, scene, gpencil_frame_mirror_yaxis); break; } } |