Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mask/mask_editaction.c
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| /* NOTE ABOUT THIS FILE: | /* NOTE ABOUT THIS FILE: | ||||
| * This file contains code for editing Mask data in the Action Editor | * This file contains code for editing Mask data in the Action Editor | ||||
| * as a 'keyframes', so that a user can adjust the timing of Mask shapekeys. | * as a 'keyframes', so that a user can adjust the timing of Mask shapekeys. | ||||
| * Therefore, this file mostly contains functions for selecting Mask frames (shapekeys). | * Therefore, this file mostly contains functions for selecting Mask frames (shapekeys). | ||||
| */ | */ | ||||
| /* ***************************************** */ | /* ***************************************** */ | ||||
| /* Generics - Loopers */ | /* Generics - Loopers */ | ||||
| /* Loops over the mask-frames for a mask-layer, and applies the given callback */ | |||||
| bool ED_masklayer_frames_looper(MaskLayer *mask_layer, | bool ED_masklayer_frames_looper(MaskLayer *mask_layer, | ||||
| Scene *scene, | Scene *scene, | ||||
| bool (*mask_layer_shape_cb)(MaskLayerShape *, Scene *)) | bool (*mask_layer_shape_cb)(MaskLayerShape *, Scene *)) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| /* error checker */ | /* error checker */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| Show All 11 Lines | bool ED_masklayer_frames_looper(MaskLayer *mask_layer, | ||||
| /* nothing to return */ | /* nothing to return */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* ****************************************** */ | /* ****************************************** */ | ||||
| /* Data Conversion Tools */ | /* Data Conversion Tools */ | ||||
| /* make a listing all the mask-frames in a layer as cfraelems */ | |||||
| void ED_masklayer_make_cfra_list(MaskLayer *mask_layer, ListBase *elems, bool onlysel) | void ED_masklayer_make_cfra_list(MaskLayer *mask_layer, ListBase *elems, bool onlysel) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| CfraElem *ce; | CfraElem *ce; | ||||
| /* error checking */ | /* error checking */ | ||||
| if (ELEM(NULL, mask_layer, elems)) { | if (ELEM(NULL, mask_layer, elems)) { | ||||
| return; | return; | ||||
| Show All 11 Lines | if ((onlysel == false) || (mask_layer_shape->flag & MASK_SHAPE_SELECT)) { | ||||
| BLI_addtail(elems, ce); | BLI_addtail(elems, ce); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ***************************************** */ | /* ***************************************** */ | ||||
| /* Selection Tools */ | /* Selection Tools */ | ||||
| /* check if one of the frames in this layer is selected */ | |||||
| bool ED_masklayer_frame_select_check(const MaskLayer *mask_layer) | bool ED_masklayer_frame_select_check(const MaskLayer *mask_layer) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| /* error checking */ | /* error checking */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| Show All 25 Lines | case SELECT_SUBTRACT: | ||||
| mask_layer_shape->flag &= ~MASK_SHAPE_SELECT; | mask_layer_shape->flag &= ~MASK_SHAPE_SELECT; | ||||
| break; | break; | ||||
| case SELECT_INVERT: | case SELECT_INVERT: | ||||
| mask_layer_shape->flag ^= MASK_SHAPE_SELECT; | mask_layer_shape->flag ^= MASK_SHAPE_SELECT; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* set all/none/invert select (like above, but with SELECT_* modes) */ | |||||
| void ED_mask_select_frames(MaskLayer *mask_layer, short select_mode) | void ED_mask_select_frames(MaskLayer *mask_layer, short select_mode) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| /* error checking */ | /* error checking */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* handle according to mode */ | /* handle according to mode */ | ||||
| for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | ||||
| mask_layer_shape = mask_layer_shape->next) { | mask_layer_shape = mask_layer_shape->next) { | ||||
| mask_layer_shape_select(mask_layer_shape, select_mode); | mask_layer_shape_select(mask_layer_shape, select_mode); | ||||
| } | } | ||||
| } | } | ||||
| /* set all/none/invert select */ | |||||
| void ED_masklayer_frame_select_set(MaskLayer *mask_layer, short mode) | void ED_masklayer_frame_select_set(MaskLayer *mask_layer, short mode) | ||||
| { | { | ||||
| /* error checking */ | /* error checking */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* now call the standard function */ | /* now call the standard function */ | ||||
| ED_mask_select_frames(mask_layer, mode); | ED_mask_select_frames(mask_layer, mode); | ||||
| } | } | ||||
| /* select the frame in this layer that occurs on this frame (there should only be one at most) */ | |||||
| void ED_mask_select_frame(MaskLayer *mask_layer, int selx, short select_mode) | void ED_mask_select_frame(MaskLayer *mask_layer, int selx, short select_mode) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| mask_layer_shape = BKE_mask_layer_shape_find_frame(mask_layer, selx); | mask_layer_shape = BKE_mask_layer_shape_find_frame(mask_layer, selx); | ||||
| if (mask_layer_shape) { | if (mask_layer_shape) { | ||||
| mask_layer_shape_select(mask_layer_shape, select_mode); | mask_layer_shape_select(mask_layer_shape, select_mode); | ||||
| } | } | ||||
| } | } | ||||
| /* select the frames in this layer that occur within the bounds specified */ | |||||
| void ED_masklayer_frames_select_box(MaskLayer *mask_layer, float min, float max, short select_mode) | void ED_masklayer_frames_select_box(MaskLayer *mask_layer, float min, float max, short select_mode) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* only select those frames which are in bounds */ | /* only select those frames which are in bounds */ | ||||
| for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | ||||
| mask_layer_shape = mask_layer_shape->next) { | mask_layer_shape = mask_layer_shape->next) { | ||||
| if (IN_RANGE(mask_layer_shape->frame, min, max)) { | if (IN_RANGE(mask_layer_shape->frame, min, max)) { | ||||
| mask_layer_shape_select(mask_layer_shape, select_mode); | mask_layer_shape_select(mask_layer_shape, select_mode); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* select the frames in this layer that occur within the lasso/circle region specified */ | |||||
| void ED_masklayer_frames_select_region(KeyframeEditData *ked, | void ED_masklayer_frames_select_region(KeyframeEditData *ked, | ||||
| MaskLayer *mask_layer, | MaskLayer *mask_layer, | ||||
| short tool, | short tool, | ||||
| short select_mode) | short select_mode) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape; | MaskLayerShape *mask_layer_shape; | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| Show All 23 Lines | else if (tool == BEZT_OK_CHANNEL_CIRCLE) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ***************************************** */ | /* ***************************************** */ | ||||
| /* Frame Editing Tools */ | /* Frame Editing Tools */ | ||||
| /* Delete selected frames */ | |||||
| bool ED_masklayer_frames_delete(MaskLayer *mask_layer) | bool ED_masklayer_frames_delete(MaskLayer *mask_layer) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape, *mask_layer_shape_next; | MaskLayerShape *mask_layer_shape, *mask_layer_shape_next; | ||||
| bool changed = false; | bool changed = false; | ||||
| /* error checking */ | /* error checking */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* check for frames to delete */ | /* check for frames to delete */ | ||||
| for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | for (mask_layer_shape = mask_layer->splines_shapes.first; mask_layer_shape; | ||||
| mask_layer_shape = mask_layer_shape_next) { | mask_layer_shape = mask_layer_shape_next) { | ||||
| mask_layer_shape_next = mask_layer_shape->next; | mask_layer_shape_next = mask_layer_shape->next; | ||||
| if (mask_layer_shape->flag & MASK_SHAPE_SELECT) { | if (mask_layer_shape->flag & MASK_SHAPE_SELECT) { | ||||
| BKE_mask_layer_shape_unlink(mask_layer, mask_layer_shape); | BKE_mask_layer_shape_unlink(mask_layer, mask_layer_shape); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| } | } | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| /* Duplicate selected frames from given mask-layer */ | |||||
| void ED_masklayer_frames_duplicate(MaskLayer *mask_layer) | void ED_masklayer_frames_duplicate(MaskLayer *mask_layer) | ||||
| { | { | ||||
| MaskLayerShape *mask_layer_shape, *gpfn; | MaskLayerShape *mask_layer_shape, *gpfn; | ||||
| /* Error checking. */ | /* Error checking. */ | ||||
| if (mask_layer == NULL) { | if (mask_layer == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (mask_layer_shape->flag & MASK_SHAPE_SELECT) { | if (mask_layer_shape->flag & MASK_SHAPE_SELECT) { | ||||
| mask_layer_shape->frame = (int)ED_markers_find_nearest_marker_time( | mask_layer_shape->frame = (int)ED_markers_find_nearest_marker_time( | ||||
| &scene->markers, (float)mask_layer_shape->frame); | &scene->markers, (float)mask_layer_shape->frame); | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* snap selected frames to ... */ | |||||
| void ED_masklayer_snap_frames(MaskLayer *mask_layer, Scene *scene, short mode) | void ED_masklayer_snap_frames(MaskLayer *mask_layer, Scene *scene, short mode) | ||||
| { | { | ||||
| switch (mode) { | switch (mode) { | ||||
| case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */ | case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */ | ||||
| ED_masklayer_frames_looper(mask_layer, scene, snap_mask_layer_nearest); | ED_masklayer_frames_looper(mask_layer, scene, snap_mask_layer_nearest); | ||||
| break; | break; | ||||
| case SNAP_KEYS_CURFRAME: /* snap to current frame */ | case SNAP_KEYS_CURFRAME: /* snap to current frame */ | ||||
| ED_masklayer_frames_looper(mask_layer, scene, snap_mask_layer_cframe); | ED_masklayer_frames_looper(mask_layer, scene, snap_mask_layer_cframe); | ||||
| Show All 11 Lines | |||||