2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2008 Blender Foundation
20 * Contributor(s): Joshua Leung
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file blender/editors/space_action/action_select.c
35 #include "MEM_guardedalloc.h"
37 #include "BLI_blenlib.h"
38 #include "BLI_dlrbTree.h"
39 #include "BLI_lasso.h"
40 #include "BLI_utildefines.h"
42 #include "DNA_anim_types.h"
43 #include "DNA_gpencil_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_mask_types.h"
48 #include "RNA_access.h"
49 #include "RNA_define.h"
51 #include "BKE_fcurve.h"
53 #include "BKE_context.h"
55 #include "UI_view2d.h"
57 #include "ED_anim_api.h"
58 #include "ED_gpencil.h"
60 #include "ED_keyframes_draw.h"
61 #include "ED_keyframes_edit.h"
62 #include "ED_markers.h"
63 #include "ED_screen.h"
68 #include "action_intern.h"
71 /* ************************************************************************** */
74 /* ******************** Deselect All Operator ***************************** */
75 /* This operator works in one of three ways:
76 * 1) (de)select all (AKEY) - test if select all or deselect all
77 * 2) invert all (CTRL-IKEY) - invert selection of all keyframes
78 * 3) (de)select all - no testing is done; only for use internal tools as normal function...
81 /* Deselects keyframes in the action editor
82 * - This is called by the deselect all operator, as well as other ones!
84 * - test: check if select or deselect all
85 * - sel: how to select keyframes (SELECT_*)
87 static void deselect_action_keys(bAnimContext *ac, short test, short sel)
89 ListBase anim_data = {NULL, NULL};
93 KeyframeEditData ked = {{NULL}};
94 KeyframeEditFunc test_cb, sel_cb;
96 /* determine type-based settings */
97 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
98 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS);
100 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
103 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
105 /* init BezTriple looping data */
106 test_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
108 /* See if we should be selecting or deselecting */
110 for (ale = anim_data.first; ale; ale = ale->next) {
111 if (ale->type == ANIMTYPE_GPLAYER) {
112 if (ED_gplayer_frame_select_check(ale->data)) {
113 sel = SELECT_SUBTRACT;
117 else if (ale->type == ANIMTYPE_MASKLAYER) {
118 if (ED_masklayer_frame_select_check(ale->data)) {
119 sel = SELECT_SUBTRACT;
124 if (ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, test_cb, NULL)) {
125 sel = SELECT_SUBTRACT;
132 /* convert sel to selectmode, and use that to get editor */
133 sel_cb = ANIM_editkeyframes_select(sel);
135 /* Now set the flags */
136 for (ale = anim_data.first; ale; ale = ale->next) {
137 if (ale->type == ANIMTYPE_GPLAYER)
138 ED_gplayer_frame_select_set(ale->data, sel);
139 else if (ale->type == ANIMTYPE_MASKLAYER)
140 ED_masklayer_frame_select_set(ale->data, sel);
142 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, sel_cb, NULL);
146 ANIM_animdata_freelist(&anim_data);
149 /* ------------------- */
151 static int actkeys_deselectall_exec(bContext *C, wmOperator *op)
155 /* get editor data */
156 if (ANIM_animdata_get_context(C, &ac) == 0)
157 return OPERATOR_CANCELLED;
159 /* 'standard' behavior - check if selected, then apply relevant selection */
160 if (RNA_boolean_get(op->ptr, "invert"))
161 deselect_action_keys(&ac, 0, SELECT_INVERT);
163 deselect_action_keys(&ac, 1, SELECT_ADD);
165 /* set notifier that keyframe selection have changed */
166 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
168 return OPERATOR_FINISHED;
171 void ACTION_OT_select_all_toggle(wmOperatorType *ot)
174 ot->name = "Select All";
175 ot->idname = "ACTION_OT_select_all_toggle";
176 ot->description = "Toggle selection of all keyframes";
179 ot->exec = actkeys_deselectall_exec;
180 ot->poll = ED_operator_action_active;
183 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
186 ot->prop = RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
187 RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
190 /* ******************** Border Select Operator **************************** */
191 /* This operator currently works in one of three ways:
192 * -> BKEY - 1) all keyframes within region are selected (ACTKEYS_BORDERSEL_ALLKEYS)
193 * -> ALT-BKEY - depending on which axis of the region was larger...
194 * -> 2) x-axis, so select all frames within frame range (ACTKEYS_BORDERSEL_FRAMERANGE)
195 * -> 3) y-axis, so select all frames within channels that region included (ACTKEYS_BORDERSEL_CHANNELS)
198 /* defines for borderselect mode */
200 ACTKEYS_BORDERSEL_ALLKEYS = 0,
201 ACTKEYS_BORDERSEL_FRAMERANGE,
202 ACTKEYS_BORDERSEL_CHANNELS,
203 } /*eActKeys_BorderSelect_Mode*/;
206 static void borderselect_action(bAnimContext *ac, const rcti rect, short mode, short selectmode)
208 ListBase anim_data = {NULL, NULL};
212 KeyframeEditData ked;
213 KeyframeEditFunc ok_cb, select_cb;
214 View2D *v2d = &ac->ar->v2d;
216 float ymin = 0, ymax = (float)(-ACHANNEL_HEIGHT_HALF);
218 /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */
219 UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin);
220 UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax);
223 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS);
224 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
226 /* get beztriple editing/validation funcs */
227 select_cb = ANIM_editkeyframes_select(selectmode);
229 if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS))
230 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
234 /* init editing data */
235 memset(&ked, 0, sizeof(KeyframeEditData));
237 /* loop over data, doing border select */
238 for (ale = anim_data.first; ale; ale = ale->next) {
239 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
241 /* get new vertical minimum extent of channel */
242 ymin = ymax - ACHANNEL_STEP;
244 /* set horizontal range (if applicable) */
245 if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS)) {
246 /* if channel is mapped in NLA, apply correction */
248 ked.iterflags &= ~(KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP);
249 ked.f1 = BKE_nla_tweakedit_remap(adt, rectf.xmin, NLATIME_CONVERT_UNMAP);
250 ked.f2 = BKE_nla_tweakedit_remap(adt, rectf.xmax, NLATIME_CONVERT_UNMAP);
253 ked.iterflags |= (KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP); /* for summary tracks */
259 /* perform vertical suitability check (if applicable) */
260 if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) ||
261 !((ymax < rectf.ymin) || (ymin > rectf.ymax)))
263 /* loop over data selecting */
265 case ANIMTYPE_GPDATABLOCK:
267 bGPdata *gpd = ale->data;
269 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
270 ED_gplayer_frames_select_border(gpl, rectf.xmin, rectf.xmax, selectmode);
274 case ANIMTYPE_GPLAYER:
275 ED_gplayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
277 case ANIMTYPE_MASKDATABLOCK:
279 Mask *mask = ale->data;
281 for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
282 ED_masklayer_frames_select_border(masklay, rectf.xmin, rectf.xmax, selectmode);
286 case ANIMTYPE_MASKLAYER:
287 ED_masklayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
290 ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
295 /* set minimum extent to be the maximum of the next channel */
300 ANIM_animdata_freelist(&anim_data);
303 /* ------------------- */
305 static int actkeys_borderselect_exec(bContext *C, wmOperator *op)
309 short mode = 0, selectmode = 0;
313 /* get editor data */
314 if (ANIM_animdata_get_context(C, &ac) == 0)
315 return OPERATOR_CANCELLED;
317 /* clear all selection if not extending selection */
318 extend = RNA_boolean_get(op->ptr, "extend");
320 deselect_action_keys(&ac, 1, SELECT_SUBTRACT);
322 /* get settings from operator */
323 WM_operator_properties_border_to_rcti(op, &rect);
325 gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
326 if (gesture_mode == GESTURE_MODAL_SELECT)
327 selectmode = SELECT_ADD;
329 selectmode = SELECT_SUBTRACT;
331 /* selection 'mode' depends on whether borderselect region only matters on one axis */
332 if (RNA_boolean_get(op->ptr, "axis_range")) {
333 /* mode depends on which axis of the range is larger to determine which axis to use
334 * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size
335 * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often
336 * used for tweaking timing when "blocking", while channels is not that useful...
338 if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect))
339 mode = ACTKEYS_BORDERSEL_FRAMERANGE;
341 mode = ACTKEYS_BORDERSEL_CHANNELS;
344 mode = ACTKEYS_BORDERSEL_ALLKEYS;
346 /* apply borderselect action */
347 borderselect_action(&ac, rect, mode, selectmode);
349 /* set notifier that keyframe selection have changed */
350 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
352 return OPERATOR_FINISHED;
355 void ACTION_OT_select_border(wmOperatorType *ot)
358 ot->name = "Border Select";
359 ot->idname = "ACTION_OT_select_border";
360 ot->description = "Select all keyframes within the specified region";
363 ot->invoke = WM_border_select_invoke;
364 ot->exec = actkeys_borderselect_exec;
365 ot->modal = WM_border_select_modal;
366 ot->cancel = WM_border_select_cancel;
368 ot->poll = ED_operator_action_active;
371 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
374 WM_operator_properties_gesture_border(ot, true);
376 ot->prop = RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
379 /* ******************** Region Select Operators ***************************** */
380 /* "Region Select" operators include the Lasso and Circle Select operators.
381 * These two ended up being lumped together, as it was easier in the
382 * original Graph Editor implementation of these to do it this way.
385 static void region_select_action_keys(bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, void *data)
387 ListBase anim_data = {NULL, NULL};
391 KeyframeEditData ked;
392 KeyframeEditFunc ok_cb, select_cb;
393 View2D *v2d = &ac->ar->v2d;
394 rctf rectf, scaled_rectf;
395 float ymin = 0, ymax = (float)(-ACHANNEL_HEIGHT_HALF);
397 /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */
398 UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf);
401 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS);
402 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
404 /* get beztriple editing/validation funcs */
405 select_cb = ANIM_editkeyframes_select(selectmode);
406 ok_cb = ANIM_editkeyframes_ok(mode);
408 /* init editing data */
409 memset(&ked, 0, sizeof(KeyframeEditData));
410 if (mode == BEZT_OK_CHANNEL_LASSO) {
411 KeyframeEdit_LassoData *data_lasso = data;
412 data_lasso->rectf_scaled = &scaled_rectf;
413 ked.data = data_lasso;
415 else if (mode == BEZT_OK_CHANNEL_CIRCLE) {
416 KeyframeEdit_CircleData *data_circle = data;
417 data_circle->rectf_scaled = &scaled_rectf;
421 ked.data = &scaled_rectf;
424 /* loop over data, doing region select */
425 for (ale = anim_data.first; ale; ale = ale->next) {
426 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
428 /* get new vertical minimum extent of channel */
429 ymin = ymax - ACHANNEL_STEP;
431 /* compute midpoint of channel (used for testing if the key is in the region or not) */
432 ked.channel_y = ymin + ACHANNEL_HEIGHT_HALF;
434 /* if channel is mapped in NLA, apply correction
435 * - Apply to the bounds being checked, not all the keyframe points,
436 * to avoid having scaling everything
437 * - Save result to the scaled_rect, which is all that these operators
441 ked.iterflags &= ~(KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP);
442 ked.f1 = BKE_nla_tweakedit_remap(adt, rectf.xmin, NLATIME_CONVERT_UNMAP);
443 ked.f2 = BKE_nla_tweakedit_remap(adt, rectf.xmax, NLATIME_CONVERT_UNMAP);
446 ked.iterflags |= (KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP); /* for summary tracks */
451 /* Update values for scaled_rectf - which is used to compute the mapping in the callbacks
452 * NOTE: Since summary tracks need late-binding remapping, the callbacks may overwrite these
453 * with the properly remapped ked.f1/f2 values, when needed
455 scaled_rectf.xmin = ked.f1;
456 scaled_rectf.xmax = ked.f2;
457 scaled_rectf.ymin = ymin;
458 scaled_rectf.ymax = ymax;
460 /* perform vertical suitability check (if applicable) */
461 if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) ||
462 !((ymax < rectf.ymin) || (ymin > rectf.ymax)))
464 /* loop over data selecting */
466 case ANIMTYPE_GPDATABLOCK:
468 bGPdata *gpd = ale->data;
470 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
471 ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode);
475 case ANIMTYPE_GPLAYER:
477 ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode);
480 case ANIMTYPE_MASKDATABLOCK:
482 Mask *mask = ale->data;
484 for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
485 ED_masklayer_frames_select_region(&ked, masklay, mode, selectmode);
489 case ANIMTYPE_MASKLAYER:
491 ED_masklayer_frames_select_region(&ked, ale->data, mode, selectmode);
495 ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
500 /* set minimum extent to be the maximum of the next channel */
505 ANIM_animdata_freelist(&anim_data);
508 /* ----------------------------------- */
510 static int actkeys_lassoselect_exec(bContext *C, wmOperator *op)
514 KeyframeEdit_LassoData data_lasso;
521 /* get editor data */
522 if (ANIM_animdata_get_context(C, &ac) == 0)
523 return OPERATOR_CANCELLED;
525 data_lasso.rectf_view = &rect_fl;
526 data_lasso.mcords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcords_tot);
527 if (data_lasso.mcords == NULL)
528 return OPERATOR_CANCELLED;
530 /* clear all selection if not extending selection */
531 extend = RNA_boolean_get(op->ptr, "extend");
533 deselect_action_keys(&ac, 1, SELECT_SUBTRACT);
535 if (!RNA_boolean_get(op->ptr, "deselect"))
536 selectmode = SELECT_ADD;
538 selectmode = SELECT_SUBTRACT;
540 /* get settings from operator */
541 BLI_lasso_boundbox(&rect, data_lasso.mcords, data_lasso.mcords_tot);
542 BLI_rctf_rcti_copy(&rect_fl, &rect);
544 /* apply borderselect action */
545 region_select_action_keys(&ac, &rect_fl, BEZT_OK_CHANNEL_LASSO, selectmode, &data_lasso);
547 MEM_freeN((void *)data_lasso.mcords);
549 /* send notifier that keyframe selection has changed */
550 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
552 return OPERATOR_FINISHED;
555 void ACTION_OT_select_lasso(wmOperatorType *ot)
558 ot->name = "Lasso Select";
559 ot->description = "Select keyframe points using lasso selection";
560 ot->idname = "ACTION_OT_select_lasso";
563 ot->invoke = WM_gesture_lasso_invoke;
564 ot->modal = WM_gesture_lasso_modal;
565 ot->exec = actkeys_lassoselect_exec;
566 ot->poll = ED_operator_action_active;
567 ot->cancel = WM_gesture_lasso_cancel;
570 ot->flag = OPTYPE_UNDO;
573 RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
574 RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Deselect rather than select items");
575 RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection instead of deselecting everything first");
578 /* ------------------- */
580 static int action_circle_select_exec(bContext *C, wmOperator *op)
583 const int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
584 const short selectmode = (gesture_mode == GESTURE_MODAL_SELECT) ? SELECT_ADD : SELECT_SUBTRACT;
586 KeyframeEdit_CircleData data = {0};
589 float x = RNA_int_get(op->ptr, "x");
590 float y = RNA_int_get(op->ptr, "y");
591 float radius = RNA_int_get(op->ptr, "radius");
593 /* get editor data */
594 if (ANIM_animdata_get_context(C, &ac) == 0)
595 return OPERATOR_CANCELLED;
599 data.radius_squared = radius * radius;
600 data.rectf_view = &rect_fl;
602 rect_fl.xmin = x - radius;
603 rect_fl.xmax = x + radius;
604 rect_fl.ymin = y - radius;
605 rect_fl.ymax = y + radius;
607 /* apply region select action */
608 region_select_action_keys(&ac, &rect_fl, BEZT_OK_CHANNEL_CIRCLE, selectmode, &data);
610 /* send notifier that keyframe selection has changed */
611 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
613 return OPERATOR_FINISHED;
616 void ACTION_OT_select_circle(wmOperatorType *ot)
618 ot->name = "Circle Select";
619 ot->description = "Select keyframe points using circle selection";
620 ot->idname = "ACTION_OT_select_circle";
622 ot->invoke = WM_gesture_circle_invoke;
623 ot->modal = WM_gesture_circle_modal;
624 ot->exec = action_circle_select_exec;
625 ot->poll = ED_operator_action_active;
626 ot->cancel = WM_gesture_circle_cancel;
629 ot->flag = OPTYPE_UNDO;
631 RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
632 RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
633 RNA_def_int(ot->srna, "radius", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
634 RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
637 /* ******************** Column Select Operator **************************** */
638 /* This operator works in one of four ways:
639 * - 1) select all keyframes in the same frame as a selected one (KKEY)
640 * - 2) select all keyframes in the same frame as the current frame marker (CTRL-KKEY)
641 * - 3) select all keyframes in the same frame as a selected markers (SHIFT-KKEY)
642 * - 4) select all keyframes that occur between selected markers (ALT-KKEY)
645 /* defines for column-select mode */
646 static EnumPropertyItem prop_column_select_types[] = {
647 {ACTKEYS_COLUMNSEL_KEYS, "KEYS", 0, "On Selected Keyframes", ""},
648 {ACTKEYS_COLUMNSEL_CFRA, "CFRA", 0, "On Current Frame", ""},
649 {ACTKEYS_COLUMNSEL_MARKERS_COLUMN, "MARKERS_COLUMN", 0, "On Selected Markers", ""},
650 {ACTKEYS_COLUMNSEL_MARKERS_BETWEEN, "MARKERS_BETWEEN", 0, "Between Min/Max Selected Markers", ""},
651 {0, NULL, 0, NULL, NULL}
654 /* ------------------- */
656 /* Selects all visible keyframes between the specified markers */
657 /* TODO, this is almost an _exact_ duplicate of a function of the same name in graph_select.c
658 * should de-duplicate - campbell */
659 static void markers_selectkeys_between(bAnimContext *ac)
661 ListBase anim_data = {NULL, NULL};
665 KeyframeEditFunc ok_cb, select_cb;
666 KeyframeEditData ked = {{NULL}};
669 /* get extreme markers */
670 ED_markers_get_minmax(ac->markers, 1, &min, &max);
674 /* get editing funcs + data */
675 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
676 select_cb = ANIM_editkeyframes_select(SELECT_ADD);
682 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
683 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
685 /* select keys in-between */
686 for (ale = anim_data.first; ale; ale = ale->next) {
687 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
690 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
691 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
692 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
694 else if (ale->type == ANIMTYPE_GPLAYER) {
695 ED_gplayer_frames_select_border(ale->data, min, max, SELECT_ADD);
697 else if (ale->type == ANIMTYPE_MASKLAYER) {
698 ED_masklayer_frames_select_border(ale->data, min, max, SELECT_ADD);
701 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
706 ANIM_animdata_freelist(&anim_data);
710 /* Selects all visible keyframes in the same frames as the specified elements */
711 static void columnselect_action_keys(bAnimContext *ac, short mode)
713 ListBase anim_data = {NULL, NULL};
717 Scene *scene = ac->scene;
719 KeyframeEditFunc select_cb, ok_cb;
720 KeyframeEditData ked = {{NULL}};
722 /* initialize keyframe editing data */
724 /* build list of columns */
726 case ACTKEYS_COLUMNSEL_KEYS: /* list of selected keys */
727 if (ac->datatype == ANIMCONT_GPENCIL) {
728 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE);
729 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
731 for (ale = anim_data.first; ale; ale = ale->next)
732 ED_gplayer_make_cfra_list(ale->data, &ked.list, 1);
735 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/);
736 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
738 for (ale = anim_data.first; ale; ale = ale->next)
739 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_to_cfraelem, NULL);
741 ANIM_animdata_freelist(&anim_data);
744 case ACTKEYS_COLUMNSEL_CFRA: /* current frame */
745 /* make a single CfraElem for storing this */
746 ce = MEM_callocN(sizeof(CfraElem), "cfraElem");
747 BLI_addtail(&ked.list, ce);
749 ce->cfra = (float)CFRA;
752 case ACTKEYS_COLUMNSEL_MARKERS_COLUMN: /* list of selected markers */
753 ED_markers_make_cfra_list(ac->markers, &ked.list, SELECT);
756 default: /* invalid option */
760 /* set up BezTriple edit callbacks */
761 select_cb = ANIM_editkeyframes_select(SELECT_ADD);
762 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAME);
764 /* loop through all of the keys and select additional keyframes
765 * based on the keys found to be selected above
767 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
768 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE);
770 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/);
771 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
773 for (ale = anim_data.first; ale; ale = ale->next) {
774 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
776 /* loop over cfraelems (stored in the KeyframeEditData->list)
777 * - we need to do this here, as we can apply fewer NLA-mapping conversions
779 for (ce = ked.list.first; ce; ce = ce->next) {
780 /* set frame for validation callback to refer to */
782 ked.f1 = BKE_nla_tweakedit_remap(adt, ce->cfra, NLATIME_CONVERT_UNMAP);
786 /* select elements with frame number matching cfraelem */
787 if (ale->type == ANIMTYPE_GPLAYER)
788 ED_gpencil_select_frame(ale->data, ce->cfra, SELECT_ADD);
789 else if (ale->type == ANIMTYPE_MASKLAYER)
790 ED_mask_select_frame(ale->data, ce->cfra, SELECT_ADD);
792 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
797 BLI_freelistN(&ked.list);
798 ANIM_animdata_freelist(&anim_data);
801 /* ------------------- */
803 static int actkeys_columnselect_exec(bContext *C, wmOperator *op)
808 /* get editor data */
809 if (ANIM_animdata_get_context(C, &ac) == 0)
810 return OPERATOR_CANCELLED;
812 /* action to take depends on the mode */
813 mode = RNA_enum_get(op->ptr, "mode");
815 if (mode == ACTKEYS_COLUMNSEL_MARKERS_BETWEEN)
816 markers_selectkeys_between(&ac);
818 columnselect_action_keys(&ac, mode);
820 /* set notifier that keyframe selection have changed */
821 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
823 return OPERATOR_FINISHED;
826 void ACTION_OT_select_column(wmOperatorType *ot)
829 ot->name = "Select All";
830 ot->idname = "ACTION_OT_select_column";
831 ot->description = "Select all keyframes on the specified frame(s)";
834 ot->exec = actkeys_columnselect_exec;
835 ot->poll = ED_operator_action_active;
838 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
841 ot->prop = RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
844 /* ******************** Select Linked Operator *********************** */
846 static int actkeys_select_linked_exec(bContext *C, wmOperator *UNUSED(op))
850 ListBase anim_data = {NULL, NULL};
854 KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
855 KeyframeEditFunc sel_cb = ANIM_editkeyframes_select(SELECT_ADD);
857 /* get editor data */
858 if (ANIM_animdata_get_context(C, &ac) == 0)
859 return OPERATOR_CANCELLED;
861 /* loop through all of the keys and select additional keyframes based on these */
862 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
863 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
865 for (ale = anim_data.first; ale; ale = ale->next) {
866 FCurve *fcu = (FCurve *)ale->key_data;
868 /* check if anything selected? */
869 if (ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, ok_cb, NULL)) {
870 /* select every keyframe in this curve then */
871 ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, sel_cb, NULL);
876 ANIM_animdata_freelist(&anim_data);
878 /* set notifier that keyframe selection has changed */
879 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
881 return OPERATOR_FINISHED;
884 void ACTION_OT_select_linked(wmOperatorType *ot)
887 ot->name = "Select Linked";
888 ot->idname = "ACTION_OT_select_linked";
889 ot->description = "Select keyframes occurring in the same F-Curves as selected ones";
892 ot->exec = actkeys_select_linked_exec;
893 ot->poll = ED_operator_action_active;
896 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
899 /* ******************** Select More/Less Operators *********************** */
901 /* Common code to perform selection */
902 static void select_moreless_action_keys(bAnimContext *ac, short mode)
904 ListBase anim_data = {NULL, NULL};
908 KeyframeEditData ked = {{NULL}};
909 KeyframeEditFunc build_cb;
912 /* init selmap building data */
913 build_cb = ANIM_editkeyframes_buildselmap(mode);
915 /* loop through all of the keys and select additional keyframes based on these */
916 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
917 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
919 for (ale = anim_data.first; ale; ale = ale->next) {
920 FCurve *fcu = (FCurve *)ale->key_data;
922 /* only continue if F-Curve has keyframes */
923 if (fcu->bezt == NULL)
926 /* build up map of whether F-Curve's keyframes should be selected or not */
927 ked.data = MEM_callocN(fcu->totvert, "selmap actEdit more");
928 ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, build_cb, NULL);
930 /* based on this map, adjust the selection status of the keyframes */
931 ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_selmap_flush, NULL);
933 /* free the selmap used here */
939 ANIM_animdata_freelist(&anim_data);
942 /* ----------------- */
944 static int actkeys_select_more_exec(bContext *C, wmOperator *UNUSED(op))
948 /* get editor data */
949 if (ANIM_animdata_get_context(C, &ac) == 0)
950 return OPERATOR_CANCELLED;
952 /* perform select changes */
953 select_moreless_action_keys(&ac, SELMAP_MORE);
955 /* set notifier that keyframe selection has changed */
956 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
958 return OPERATOR_FINISHED;
961 void ACTION_OT_select_more(wmOperatorType *ot)
964 ot->name = "Select More";
965 ot->idname = "ACTION_OT_select_more";
966 ot->description = "Select keyframes beside already selected ones";
969 ot->exec = actkeys_select_more_exec;
970 ot->poll = ED_operator_action_active;
973 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
976 /* ----------------- */
978 static int actkeys_select_less_exec(bContext *C, wmOperator *UNUSED(op))
982 /* get editor data */
983 if (ANIM_animdata_get_context(C, &ac) == 0)
984 return OPERATOR_CANCELLED;
986 /* perform select changes */
987 select_moreless_action_keys(&ac, SELMAP_LESS);
989 /* set notifier that keyframe selection has changed */
990 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
992 return OPERATOR_FINISHED;
995 void ACTION_OT_select_less(wmOperatorType *ot)
998 ot->name = "Select Less";
999 ot->idname = "ACTION_OT_select_less";
1000 ot->description = "Deselect keyframes on ends of selection islands";
1003 ot->exec = actkeys_select_less_exec;
1004 ot->poll = ED_operator_action_active;
1007 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1010 /* ******************** Select Left/Right Operator ************************* */
1011 /* Select keyframes left/right of the current frame indicator */
1013 /* defines for left-right select tool */
1014 static EnumPropertyItem prop_actkeys_leftright_select_types[] = {
1015 {ACTKEYS_LRSEL_TEST, "CHECK", 0, "Check if Select Left or Right", ""},
1016 {ACTKEYS_LRSEL_LEFT, "LEFT", 0, "Before current frame", ""},
1017 {ACTKEYS_LRSEL_RIGHT, "RIGHT", 0, "After current frame", ""},
1018 {0, NULL, 0, NULL, NULL}
1021 /* --------------------------------- */
1023 static void actkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode)
1025 ListBase anim_data = {NULL, NULL};
1029 KeyframeEditFunc ok_cb, select_cb;
1030 KeyframeEditData ked = {{NULL}};
1031 Scene *scene = ac->scene;
1033 /* if select mode is replace, deselect all keyframes (and channels) first */
1034 if (select_mode == SELECT_REPLACE) {
1035 select_mode = SELECT_ADD;
1037 /* - deselect all other keyframes, so that just the newly selected remain
1038 * - channels aren't deselected, since we don't re-select any as a consequence
1040 deselect_action_keys(ac, 0, SELECT_SUBTRACT);
1043 /* set callbacks and editing data */
1044 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
1045 select_cb = ANIM_editkeyframes_select(select_mode);
1047 if (leftright == ACTKEYS_LRSEL_LEFT) {
1048 ked.f1 = MINAFRAMEF;
1049 ked.f2 = (float)(CFRA + 0.1f);
1052 ked.f1 = (float)(CFRA - 0.1f);
1057 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
1058 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS);
1060 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1061 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1064 for (ale = anim_data.first; ale; ale = ale->next) {
1065 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
1068 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
1069 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
1070 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
1072 else if (ale->type == ANIMTYPE_GPLAYER)
1073 ED_gplayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode);
1074 else if (ale->type == ANIMTYPE_MASKLAYER)
1075 ED_masklayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode);
1077 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
1080 /* Sync marker support */
1081 if (select_mode == SELECT_ADD) {
1082 SpaceAction *saction = (SpaceAction *)ac->sl;
1084 if ((saction) && (saction->flag & SACTION_MARKERS_MOVE)) {
1085 ListBase *markers = ED_animcontext_get_markers(ac);
1088 for (marker = markers->first; marker; marker = marker->next) {
1089 if (((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) ||
1090 ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA)))
1092 marker->flag |= SELECT;
1095 marker->flag &= ~SELECT;
1102 ANIM_animdata_freelist(&anim_data);
1105 /* ----------------- */
1107 static int actkeys_select_leftright_exec(bContext *C, wmOperator *op)
1110 short leftright = RNA_enum_get(op->ptr, "mode");
1113 /* get editor data */
1114 if (ANIM_animdata_get_context(C, &ac) == 0)
1115 return OPERATOR_CANCELLED;
1117 /* select mode is either replace (deselect all, then add) or add/extend */
1118 if (RNA_boolean_get(op->ptr, "extend"))
1119 selectmode = SELECT_INVERT;
1121 selectmode = SELECT_REPLACE;
1123 /* if "test" mode is set, we don't have any info to set this with */
1124 if (leftright == ACTKEYS_LRSEL_TEST)
1125 return OPERATOR_CANCELLED;
1127 /* do the selecting now */
1128 actkeys_select_leftright(&ac, leftright, selectmode);
1130 /* set notifier that keyframe selection (and channels too) have changed */
1131 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | ND_ANIMCHAN | NA_SELECTED, NULL);
1133 return OPERATOR_FINISHED;
1136 static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1139 short leftright = RNA_enum_get(op->ptr, "mode");
1141 /* get editor data */
1142 if (ANIM_animdata_get_context(C, &ac) == 0)
1143 return OPERATOR_CANCELLED;
1145 /* handle mode-based testing */
1146 if (leftright == ACTKEYS_LRSEL_TEST) {
1147 Scene *scene = ac.scene;
1148 ARegion *ar = ac.ar;
1149 View2D *v2d = &ar->v2d;
1152 /* determine which side of the current frame mouse is on */
1153 x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
1155 RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_LEFT);
1157 RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
1160 /* perform selection */
1161 return actkeys_select_leftright_exec(C, op);
1164 void ACTION_OT_select_leftright(wmOperatorType *ot)
1169 ot->name = "Select Left/Right";
1170 ot->idname = "ACTION_OT_select_leftright";
1171 ot->description = "Select keyframes to the left or the right of the current frame";
1174 ot->invoke = actkeys_select_leftright_invoke;
1175 ot->exec = actkeys_select_leftright_exec;
1176 ot->poll = ED_operator_action_active;
1179 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1182 ot->prop = RNA_def_enum(ot->srna, "mode", prop_actkeys_leftright_select_types, ACTKEYS_LRSEL_TEST, "Mode", "");
1183 RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
1185 prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
1186 RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1189 /* ******************** Mouse-Click Select Operator *********************** */
1190 /* This operator works in one of three ways:
1191 * - 1) keyframe under mouse - no special modifiers
1192 * - 2) all keyframes on the same side of current frame indicator as mouse - ALT modifier
1193 * - 3) column select all keyframes in frame under mouse - CTRL modifier
1194 * - 4) all keyframes in channel under mouse - CTRL+ALT modifiers
1196 * In addition to these basic options, the SHIFT modifier can be used to toggle the
1197 * selection mode between replacing the selection (without) and inverting the selection (with).
1200 /* ------------------- */
1202 /* option 1) select keyframe directly under mouse */
1203 static void actkeys_mselect_single(bAnimContext *ac, bAnimListElem *ale, short select_mode, float selx)
1205 KeyframeEditData ked = {{NULL}};
1206 KeyframeEditFunc select_cb, ok_cb;
1208 /* get functions for selecting keyframes */
1209 select_cb = ANIM_editkeyframes_select(select_mode);
1210 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAME);
1212 ked.iterflags |= KED_F1_NLA_UNMAP;
1214 /* select the nominated keyframe on the given frame */
1215 if (ale->type == ANIMTYPE_GPLAYER) {
1216 ED_gpencil_select_frame(ale->data, selx, select_mode);
1218 else if (ale->type == ANIMTYPE_MASKLAYER) {
1219 ED_mask_select_frame(ale->data, selx, select_mode);
1222 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK) &&
1223 (ale->type == ANIMTYPE_SUMMARY) && (ale->datatype == ALE_ALL))
1225 ListBase anim_data = {NULL, NULL};
1228 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
1229 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1231 for (ale = anim_data.first; ale; ale = ale->next) {
1232 if (ale->type == ANIMTYPE_GPLAYER) {
1233 ED_gpencil_select_frame(ale->data, selx, select_mode);
1235 else if (ale->type == ANIMTYPE_MASKLAYER) {
1236 ED_mask_select_frame(ale->data, selx, select_mode);
1240 ANIM_animdata_freelist(&anim_data);
1243 ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
1248 /* Option 2) Selects all the keyframes on either side of the current frame (depends on which side the mouse is on) */
1249 /* (see actkeys_select_leftright) */
1251 /* Option 3) Selects all visible keyframes in the same frame as the mouse click */
1252 static void actkeys_mselect_column(bAnimContext *ac, short select_mode, float selx)
1254 ListBase anim_data = {NULL, NULL};
1258 KeyframeEditFunc select_cb, ok_cb;
1259 KeyframeEditData ked = {{NULL}};
1261 /* set up BezTriple edit callbacks */
1262 select_cb = ANIM_editkeyframes_select(select_mode);
1263 ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAME);
1265 /* loop through all of the keys and select additional keyframes
1266 * based on the keys found to be selected above
1268 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK))
1269 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
1271 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS);
1272 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1274 for (ale = anim_data.first; ale; ale = ale->next) {
1275 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
1277 /* set frame for validation callback to refer to */
1279 ked.f1 = BKE_nla_tweakedit_remap(adt, selx, NLATIME_CONVERT_UNMAP);
1283 /* select elements with frame number matching cfra */
1284 if (ale->type == ANIMTYPE_GPLAYER)
1285 ED_gpencil_select_frame(ale->key_data, selx, select_mode);
1286 else if (ale->type == ANIMTYPE_MASKLAYER)
1287 ED_mask_select_frame(ale->key_data, selx, select_mode);
1289 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
1293 BLI_freelistN(&ked.list);
1294 ANIM_animdata_freelist(&anim_data);
1297 /* option 4) select all keyframes in same channel */
1298 static void actkeys_mselect_channel_only(bAnimContext *ac, bAnimListElem *ale, short select_mode)
1300 KeyframeEditFunc select_cb;
1302 /* get functions for selecting keyframes */
1303 select_cb = ANIM_editkeyframes_select(select_mode);
1305 /* select all keyframes in this channel */
1306 if (ale->type == ANIMTYPE_GPLAYER) {
1307 ED_gpencil_select_frames(ale->data, select_mode);
1309 else if (ale->type == ANIMTYPE_MASKLAYER) {
1310 ED_mask_select_frames(ale->data, select_mode);
1313 if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK) &&
1314 (ale->type == ANIMTYPE_SUMMARY) && (ale->datatype == ALE_ALL))
1316 ListBase anim_data = {NULL, NULL};
1319 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
1320 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1322 for (ale = anim_data.first; ale; ale = ale->next) {
1323 if (ale->type == ANIMTYPE_GPLAYER) {
1324 ED_gpencil_select_frames(ale->data, select_mode);
1326 else if (ale->type == ANIMTYPE_MASKLAYER) {
1327 ED_mask_select_frames(ale->data, select_mode);
1331 ANIM_animdata_freelist(&anim_data);
1334 ANIM_animchannel_keyframes_loop(NULL, ac->ads, ale, NULL, select_cb, NULL);
1339 /* ------------------- */
1341 static void mouse_action_keys(bAnimContext *ac, const int mval[2], short select_mode, bool column, bool same_channel)
1343 ListBase anim_data = {NULL, NULL};
1344 DLRBT_Tree anim_keys;
1348 View2D *v2d = &ac->ar->v2d;
1349 bDopeSheet *ads = NULL;
1352 float frame = 0.0f; /* frame of keyframe under mouse - NLA corrections not applied/included */
1353 float selx = 0.0f; /* frame of keyframe under mouse */
1357 /* get dopesheet info */
1358 if (ac->datatype == ANIMCONT_DOPESHEET)
1361 /* use View2D to determine the index of the channel (i.e a row in the list) where keyframe was */
1362 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
1363 UI_view2d_listview_view_to_cell(v2d, 0, ACHANNEL_STEP, 0, (float)ACHANNEL_HEIGHT_HALF, x, y, NULL, &channel_index);
1365 /* x-range to check is +/- 7 (in screen/region-space) on either side of mouse click (size of keyframe icon) */
1366 UI_view2d_region_to_view(v2d, mval[0] - 7, mval[1], &rectf.xmin, &rectf.ymin);
1367 UI_view2d_region_to_view(v2d, mval[0] + 7, mval[1], &rectf.xmax, &rectf.ymax);
1370 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
1371 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1373 /* try to get channel */
1374 ale = BLI_findlink(&anim_data, channel_index);
1376 /* channel not found */
1377 printf("Error: animation channel (index = %d) not found in mouse_action_keys()\n", channel_index);
1378 ANIM_animdata_freelist(&anim_data);
1382 /* found match - must return here... */
1383 AnimData *adt = ANIM_nla_mapping_get(ac, ale);
1384 ActKeyColumn *ak, *akn = NULL;
1386 /* make list of keyframes */
1387 BLI_dlrbTree_init(&anim_keys);
1389 if (ale->key_data) {
1390 switch (ale->datatype) {
1393 Scene *scene = (Scene *)ale->key_data;
1394 scene_to_keylist(ads, scene, &anim_keys, NULL);
1399 Object *ob = (Object *)ale->key_data;
1400 ob_to_keylist(ads, ob, &anim_keys, NULL);
1405 bAction *act = (bAction *)ale->key_data;
1406 action_to_keylist(adt, act, &anim_keys, NULL);
1411 FCurve *fcu = (FCurve *)ale->key_data;
1412 fcurve_to_keylist(adt, fcu, &anim_keys, NULL);
1417 else if (ale->type == ANIMTYPE_SUMMARY) {
1418 /* dopesheet summary covers everything */
1419 summary_to_keylist(ac, &anim_keys, NULL);
1421 else if (ale->type == ANIMTYPE_GROUP) {
1422 // TODO: why don't we just give groups key_data too?
1423 bActionGroup *agrp = (bActionGroup *)ale->data;
1424 agroup_to_keylist(adt, agrp, &anim_keys, NULL);
1426 else if (ale->type == ANIMTYPE_GPLAYER) {
1427 // TODO: why don't we just give gplayers key_data too?
1428 bGPDlayer *gpl = (bGPDlayer *)ale->data;
1429 gpl_to_keylist(ads, gpl, &anim_keys);
1431 else if (ale->type == ANIMTYPE_MASKLAYER) {
1432 // TODO: why don't we just give masklayers key_data too?
1433 MaskLayer *masklay = (MaskLayer *)ale->data;
1434 mask_to_keylist(ads, masklay, &anim_keys);
1437 /* start from keyframe at root of BST, traversing until we find one within the range that was clicked on */
1438 for (ak = anim_keys.root; ak; ak = akn) {
1439 if (IN_RANGE(ak->cfra, rectf.xmin, rectf.xmax)) {
1440 /* set the frame to use, and apply inverse-correction for NLA-mapping
1441 * so that the frame will get selected by the selection functions without
1442 * requiring to map each frame once again...
1444 selx = BKE_nla_tweakedit_remap(adt, ak->cfra, NLATIME_CONVERT_UNMAP);
1449 else if (ak->cfra < rectf.xmin)
1455 /* remove active channel from list of channels for separate treatment (since it's needed later on) */
1456 BLI_remlink(&anim_data, ale);
1458 /* cleanup temporary lists */
1459 BLI_dlrbTree_free(&anim_keys);
1461 /* free list of channels, since it's not used anymore */
1462 ANIM_animdata_freelist(&anim_data);
1465 /* for replacing selection, firstly need to clear existing selection */
1466 if (select_mode == SELECT_REPLACE) {
1467 /* reset selection mode for next steps */
1468 select_mode = SELECT_ADD;
1470 /* deselect all keyframes */
1471 deselect_action_keys(ac, 0, SELECT_SUBTRACT);
1473 /* highlight channel clicked on */
1474 if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET)) {
1475 /* deselect all other channels first */
1476 ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
1478 /* Highlight Action-Group or F-Curve? */
1479 if (ale && ale->data) {
1480 if (ale->type == ANIMTYPE_GROUP) {
1481 bActionGroup *agrp = ale->data;
1483 agrp->flag |= AGRP_SELECTED;
1484 ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
1486 else if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
1487 FCurve *fcu = ale->data;
1489 fcu->flag |= FCURVE_SELECTED;
1490 ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, fcu, ale->type);
1494 else if (ac->datatype == ANIMCONT_GPENCIL) {
1495 /* deselect all other channels first */
1496 ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
1498 /* Highlight GPencil Layer */
1499 if ((ale && ale->data) && (ale->type == ANIMTYPE_GPLAYER)) {
1500 bGPDlayer *gpl = ale->data;
1502 gpl->flag |= GP_LAYER_SELECT;
1503 //gpencil_layer_setactive(gpd, gpl);
1506 else if (ac->datatype == ANIMCONT_MASK) {
1507 /* deselect all other channels first */
1508 ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
1510 /* Highlight GPencil Layer */
1511 if ((ale && ale->data) && (ale->type == ANIMTYPE_MASKLAYER)) {
1512 MaskLayer *masklay = ale->data;
1514 masklay->flag |= MASK_LAYERFLAG_SELECT;
1515 //gpencil_layer_setactive(gpd, gpl);
1520 /* only select keyframes if we clicked on a valid channel and hit something */
1523 /* apply selection to keyframes */
1525 /* select all keyframes in the same frame as the one we hit on the active channel
1526 * [T41077]: "frame" not "selx" here (i.e. no NLA corrections yet) as the code here
1527 * does that itself again as it needs to work on multiple datablocks
1529 actkeys_mselect_column(ac, select_mode, frame);
1531 else if (same_channel) {
1532 /* select all keyframes in the active channel */
1533 actkeys_mselect_channel_only(ac, ale, select_mode);
1536 /* select the nominated keyframe on the given frame */
1537 actkeys_mselect_single(ac, ale, select_mode, selx);
1541 /* free this channel */
1546 /* handle clicking */
1547 static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1550 /* ARegion *ar; */ /* UNUSED */
1552 bool column, channel;
1554 /* get editor data */
1555 if (ANIM_animdata_get_context(C, &ac) == 0)
1556 return OPERATOR_CANCELLED;
1558 /* get useful pointers from animation context data */
1559 /* ar = ac.ar; */ /* UNUSED */
1561 /* select mode is either replace (deselect all, then add) or add/extend */
1562 if (RNA_boolean_get(op->ptr, "extend"))
1563 selectmode = SELECT_INVERT;
1565 selectmode = SELECT_REPLACE;
1567 /* column selection */
1568 column = RNA_boolean_get(op->ptr, "column");
1569 channel = RNA_boolean_get(op->ptr, "channel");
1571 /* select keyframe(s) based upon mouse position*/
1572 mouse_action_keys(&ac, event->mval, selectmode, column, channel);
1574 /* set notifier that keyframe selection (and channels too) have changed */
1575 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | ND_ANIMCHAN | NA_SELECTED, NULL);
1577 /* for tweak grab to work */
1578 return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
1581 void ACTION_OT_clickselect(wmOperatorType *ot)
1586 ot->name = "Mouse Select Keys";
1587 ot->idname = "ACTION_OT_clickselect";
1588 ot->description = "Select keyframes by clicking on them";
1591 ot->invoke = actkeys_clickselect_invoke;
1592 ot->poll = ED_operator_action_active;
1595 ot->flag = OPTYPE_UNDO;
1598 prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select",
1599 "Toggle keyframe selection instead of leaving newly selected keyframes only"); // SHIFTKEY
1600 RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1602 prop = RNA_def_boolean(ot->srna, "column", 0, "Column Select",
1603 "Select all keyframes that occur on the same frame as the one under the mouse"); // ALTKEY
1604 RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1606 prop = RNA_def_boolean(ot->srna, "channel", 0, "Only Channel",
1607 "Select all the keyframes in the channel under the mouse"); // CTRLKEY + ALTKEY
1608 RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1611 /* ************************************************************************** */