| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2008 Blender Foundation | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup spgraph | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <float.h>
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | #include <math.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_lasso_2d.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_anim_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "DNA_screen_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | #include "DNA_space_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | #include "BKE_fcurve.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-23 13:25:31 +00:00
										 |  |  | #include "BKE_nla.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "UI_view2d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_anim_api.h"
 | 
					
						
							|  |  |  | #include "ED_keyframes_edit.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-08 12:51:36 +00:00
										 |  |  | #include "ED_markers.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-14 10:28:41 +10:00
										 |  |  | #include "ED_select_utils.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-03 12:04:05 +00:00
										 |  |  | #include "graph_intern.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************** */ | 
					
						
							|  |  |  | /* KEYFRAMES STUFF */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* temp info for caching handle vertices close */ | 
					
						
							|  |  |  | typedef struct tNearestVertInfo { | 
					
						
							|  |  |  |   struct tNearestVertInfo *next, *prev; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   FCurve *fcu; /* F-Curve that keyframe comes from */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   BezTriple *bezt; /* keyframe to consider */ | 
					
						
							|  |  |  |   FPoint *fpt;     /* sample point to consider */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   short hpoint; /* the handle index that we hit (eHandleIndex) */ | 
					
						
							|  |  |  |   short sel;    /* whether the handle is selected or not */ | 
					
						
							|  |  |  |   int dist;     /* distance from mouse to vert */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   eAnim_ChannelType ctype; /* type of animation channel this FCurve comes from */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   float frame; /* frame that point was on when it matched (global time) */ | 
					
						
							|  |  |  | } tNearestVertInfo; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Tags for the type of graph vert that we have */ | 
					
						
							|  |  |  | typedef enum eGraphVertIndex { | 
					
						
							|  |  |  |   NEAREST_HANDLE_LEFT = -1, | 
					
						
							|  |  |  |   NEAREST_HANDLE_KEY, | 
					
						
							|  |  |  |   NEAREST_HANDLE_RIGHT, | 
					
						
							|  |  |  | } eGraphVertIndex; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Tolerance for absolute radius (in pixels) of the vert from the cursor to use */ | 
					
						
							|  |  |  | /* TODO: perhaps this should depend a bit on the size that the user set the vertices to be? */ | 
					
						
							|  |  |  | #define GVERTSEL_TOL (10 * U.pixelsize)
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ....... */ | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* check if its ok to select a handle */ | 
					
						
							|  |  |  | /* XXX also need to check for int-values only? */ | 
					
						
							|  |  |  | static bool fcurve_handle_sel_check(SpaceGraph *sipo, BezTriple *bezt) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (sipo->flag & SIPO_NOHANDLES) { | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if ((sipo->flag & SIPO_SELVHANDLESONLY) && BEZT_ISSEL_ANY(bezt) == 0) { | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2018-07-03 15:44:56 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* check if the given vertex is within bounds or not */ | 
					
						
							|  |  |  | /* TODO: should we return if we hit something? */ | 
					
						
							|  |  |  | static void nearest_fcurve_vert_store(ListBase *matches, | 
					
						
							|  |  |  |                                       View2D *v2d, | 
					
						
							|  |  |  |                                       FCurve *fcu, | 
					
						
							|  |  |  |                                       eAnim_ChannelType ctype, | 
					
						
							|  |  |  |                                       BezTriple *bezt, | 
					
						
							|  |  |  |                                       FPoint *fpt, | 
					
						
							|  |  |  |                                       short hpoint, | 
					
						
							|  |  |  |                                       const int mval[2], | 
					
						
							|  |  |  |                                       float unit_scale, | 
					
						
							|  |  |  |                                       float offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Keyframes or Samples? */ | 
					
						
							|  |  |  |   if (bezt) { | 
					
						
							|  |  |  |     int screen_co[2], dist; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* convert from data-space to screen coordinates
 | 
					
						
							|  |  |  |      * NOTE: hpoint+1 gives us 0,1,2 respectively for each handle, | 
					
						
							|  |  |  |      *  needed to access the relevant vertex coordinates in the 3x3 | 
					
						
							|  |  |  |      *  'vec' matrix | 
					
						
							| 
									
										
										
										
											2013-09-02 23:32:21 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (UI_view2d_view_to_region_clip(v2d, | 
					
						
							|  |  |  |                                       bezt->vec[hpoint + 1][0], | 
					
						
							|  |  |  |                                       (bezt->vec[hpoint + 1][1] + offset) * unit_scale, | 
					
						
							|  |  |  |                                       &screen_co[0], | 
					
						
							|  |  |  |                                       &screen_co[1]) && | 
					
						
							|  |  |  |         /* check if distance from mouse cursor to vert in screen space is within tolerance */ | 
					
						
							|  |  |  |         ((dist = len_v2v2_int(mval, screen_co)) <= GVERTSEL_TOL)) { | 
					
						
							|  |  |  |       tNearestVertInfo *nvi = (tNearestVertInfo *)matches->last; | 
					
						
							|  |  |  |       bool replace = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       /* If there is already a point for the F-Curve,
 | 
					
						
							|  |  |  |        * check if this point is closer than that was. */ | 
					
						
							|  |  |  |       if ((nvi) && (nvi->fcu == fcu)) { | 
					
						
							|  |  |  |         /* replace if we are closer, or if equal and that one wasn't selected but we are... */ | 
					
						
							|  |  |  |         if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZT_ISSEL_ANY(bezt))) { | 
					
						
							|  |  |  |           replace = 1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       /* add new if not replacing... */ | 
					
						
							|  |  |  |       if (replace == 0) { | 
					
						
							|  |  |  |         nvi = MEM_callocN(sizeof(tNearestVertInfo), "Nearest Graph Vert Info - Bezt"); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       /* store values */ | 
					
						
							|  |  |  |       nvi->fcu = fcu; | 
					
						
							|  |  |  |       nvi->ctype = ctype; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       nvi->bezt = bezt; | 
					
						
							|  |  |  |       nvi->hpoint = hpoint; | 
					
						
							|  |  |  |       nvi->dist = dist; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       nvi->frame = bezt->vec[1][0]; /* currently in global time... */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       nvi->sel = BEZT_ISSEL_ANY(bezt); /* XXX... should this use the individual verts instead? */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       /* add to list of matches if appropriate... */ | 
					
						
							|  |  |  |       if (replace == 0) { | 
					
						
							|  |  |  |         BLI_addtail(matches, nvi); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (fpt) { | 
					
						
							|  |  |  |     /* TODO... */ | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* helper for find_nearest_fcurve_vert() - build the list of nearest matches */ | 
					
						
							|  |  |  | static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], ListBase *matches) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-16 10:16:16 +11:00
										 |  |  |   SpaceGraph *sipo = (SpaceGraph *)ac->sl; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   View2D *v2d = &ac->region->v2d; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   short mapping_flag = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get curves to search through
 | 
					
						
							|  |  |  |    * - if the option to only show keyframes that belong to selected F-Curves is enabled, | 
					
						
							|  |  |  |    *   include the 'only selected' flag... | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (sipo->flag & | 
					
						
							|  |  |  |       SIPO_SELCUVERTSONLY) { /* FIXME: this should really be check for by the filtering code... */ | 
					
						
							|  |  |  |     filter |= ANIMFILTER_SEL; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-10-29 18:10:52 +00:00
										 |  |  |   mapping_flag |= ANIM_get_normalization_flags(ac); | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale->key_data; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							| 
									
										
										
										
											2015-04-13 15:57:46 +02:00
										 |  |  |     float offset; | 
					
						
							|  |  |  |     float unit_scale = ANIM_unit_mapping_get_factor( | 
					
						
							|  |  |  |         ac->scene, ale->id, fcu, mapping_flag, &offset); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* apply NLA mapping to all the keyframes */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (adt) { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (fcu->bezt) { | 
					
						
							|  |  |  |       BezTriple *bezt1 = fcu->bezt, *prevbezt = NULL; | 
					
						
							|  |  |  |       int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       for (i = 0; i < fcu->totvert; i++, prevbezt = bezt1, bezt1++) { | 
					
						
							|  |  |  |         /* keyframe */ | 
					
						
							|  |  |  |         nearest_fcurve_vert_store(matches, | 
					
						
							|  |  |  |                                   v2d, | 
					
						
							|  |  |  |                                   fcu, | 
					
						
							|  |  |  |                                   ale->type, | 
					
						
							|  |  |  |                                   bezt1, | 
					
						
							|  |  |  |                                   NULL, | 
					
						
							|  |  |  |                                   NEAREST_HANDLE_KEY, | 
					
						
							|  |  |  |                                   mval, | 
					
						
							|  |  |  |                                   unit_scale, | 
					
						
							|  |  |  |                                   offset); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |         /* handles - only do them if they're visible */ | 
					
						
							|  |  |  |         if (fcurve_handle_sel_check(sipo, bezt1) && (fcu->totvert > 1)) { | 
					
						
							|  |  |  |           /* first handle only visible if previous segment had handles */ | 
					
						
							|  |  |  |           if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || | 
					
						
							|  |  |  |               (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { | 
					
						
							|  |  |  |             nearest_fcurve_vert_store(matches, | 
					
						
							|  |  |  |                                       v2d, | 
					
						
							|  |  |  |                                       fcu, | 
					
						
							|  |  |  |                                       ale->type, | 
					
						
							|  |  |  |                                       bezt1, | 
					
						
							|  |  |  |                                       NULL, | 
					
						
							|  |  |  |                                       NEAREST_HANDLE_LEFT, | 
					
						
							|  |  |  |                                       mval, | 
					
						
							|  |  |  |                                       unit_scale, | 
					
						
							|  |  |  |                                       offset); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           /* second handle only visible if this segment is bezier */ | 
					
						
							|  |  |  |           if (bezt1->ipo == BEZT_IPO_BEZ) { | 
					
						
							|  |  |  |             nearest_fcurve_vert_store(matches, | 
					
						
							|  |  |  |                                       v2d, | 
					
						
							|  |  |  |                                       fcu, | 
					
						
							|  |  |  |                                       ale->type, | 
					
						
							|  |  |  |                                       bezt1, | 
					
						
							|  |  |  |                                       NULL, | 
					
						
							|  |  |  |                                       NEAREST_HANDLE_RIGHT, | 
					
						
							|  |  |  |                                       mval, | 
					
						
							|  |  |  |                                       unit_scale, | 
					
						
							|  |  |  |                                       offset); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-01-22 23:51:31 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-09-25 10:52:29 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     else if (fcu->fpt) { | 
					
						
							|  |  |  |       /* TODO; do this for samples too */ | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 15:12:14 +00:00
										 |  |  |     /* un-apply NLA mapping from all the keyframes */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (adt) { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* free channels */ | 
					
						
							| 
									
										
										
										
											2014-05-19 00:24:45 +10:00
										 |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* helper for find_nearest_fcurve_vert() - get the best match to use */ | 
					
						
							|  |  |  | static tNearestVertInfo *get_best_nearest_fcurve_vert(ListBase *matches) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   tNearestVertInfo *nvi = NULL; | 
					
						
							|  |  |  |   short found = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* abort if list is empty */ | 
					
						
							|  |  |  |   if (BLI_listbase_is_empty(matches)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* if list only has 1 item, remove it from the list and return */ | 
					
						
							|  |  |  |   if (BLI_listbase_is_single(matches)) { | 
					
						
							|  |  |  |     /* need to remove from the list, otherwise it gets freed and then we can't return it */ | 
					
						
							|  |  |  |     return BLI_pophead(matches); | 
					
						
							| 
									
										
										
										
											2017-10-16 21:58:51 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* try to find the first selected F-Curve vert, then take the one after it */ | 
					
						
							|  |  |  |   for (nvi = matches->first; nvi; nvi = nvi->next) { | 
					
						
							|  |  |  |     /* which mode of search are we in: find first selected, or find vert? */ | 
					
						
							|  |  |  |     if (found) { | 
					
						
							|  |  |  |       /* Just take this vert now that we've found the selected one
 | 
					
						
							|  |  |  |        * - We'll need to remove this from the list | 
					
						
							|  |  |  |        *   so that it can be returned to the original caller. | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       BLI_remlink(matches, nvi); | 
					
						
							|  |  |  |       return nvi; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-03 17:30:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* if vert is selected, we've got what we want... */ | 
					
						
							|  |  |  |     if (nvi->sel) { | 
					
						
							|  |  |  |       found = 1; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* if we're still here, this means that we failed to find anything appropriate in the first pass,
 | 
					
						
							|  |  |  |    * so just take the first item now... | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   return BLI_pophead(matches); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Find the nearest vertices (either a handle or the keyframe) | 
					
						
							|  |  |  |  * that are nearest to the mouse cursor (in area coordinates) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note the match info found must still be freed. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static tNearestVertInfo *find_nearest_fcurve_vert(bAnimContext *ac, const int mval[2]) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ListBase matches = {NULL, NULL}; | 
					
						
							|  |  |  |   tNearestVertInfo *nvi; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* step 1: get the nearest verts */ | 
					
						
							|  |  |  |   get_nearest_fcurve_verts_list(ac, mval, &matches); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* step 2: find the best vert */ | 
					
						
							|  |  |  |   nvi = get_best_nearest_fcurve_vert(&matches); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   BLI_freelistN(&matches); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* return the best vert found */ | 
					
						
							|  |  |  |   return nvi; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Deselect All Operator ***************************** */ | 
					
						
							|  |  |  | /* This operator works in one of three ways:
 | 
					
						
							|  |  |  |  * 1) (de)select all (AKEY) - test if select all or deselect all | 
					
						
							|  |  |  |  * 2) invert all (CTRL-IKEY) - invert selection of all keyframes | 
					
						
							|  |  |  |  * 3) (de)select all - no testing is done; only for use internal tools as normal function... | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-23 19:36:24 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Deselects keyframes in the Graph Editor
 | 
					
						
							|  |  |  |  * - This is called by the deselect all operator, as well as other ones! | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * - test: check if select or deselect all | 
					
						
							|  |  |  |  * - sel: how to select keyframes | 
					
						
							|  |  |  |  *   0 = deselect | 
					
						
							|  |  |  |  *   1 = select | 
					
						
							|  |  |  |  *   2 = invert | 
					
						
							|  |  |  |  * - do_channels: whether to affect selection status of channels | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channels) | 
					
						
							| 
									
										
										
										
											2014-03-09 16:20:04 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   SpaceGraph *sipo = (SpaceGraph *)ac->sl; | 
					
						
							|  |  |  |   KeyframeEditData ked = {{NULL}}; | 
					
						
							|  |  |  |   KeyframeEditFunc test_cb, sel_cb; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* determine type-based settings */ | 
					
						
							|  |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* filter data */ | 
					
						
							|  |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* init BezTriple looping data */ | 
					
						
							|  |  |  |   test_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* See if we should be selecting or deselecting */ | 
					
						
							|  |  |  |   if (test) { | 
					
						
							|  |  |  |     for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |       if (ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, test_cb, NULL)) { | 
					
						
							|  |  |  |         sel = SELECT_SUBTRACT; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-03-09 16:20:04 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* convert sel to selectmode, and use that to get editor */ | 
					
						
							|  |  |  |   sel_cb = ANIM_editkeyframes_select(sel); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Now set the flags */ | 
					
						
							|  |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale->key_data; | 
					
						
							| 
									
										
										
										
											2014-03-09 16:20:04 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* Keyframes First */ | 
					
						
							|  |  |  |     ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, sel_cb, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* affect channel selection status? */ | 
					
						
							|  |  |  |     if (do_channels) { | 
					
						
							|  |  |  |       /* Only change selection of channel when the visibility of keyframes
 | 
					
						
							|  |  |  |        * doesn't depend on this. */ | 
					
						
							|  |  |  |       if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { | 
					
						
							|  |  |  |         /* deactivate the F-Curve, and deselect if deselecting keyframes.
 | 
					
						
							|  |  |  |          * otherwise select the F-Curve too since we've selected all the keyframes | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         if (sel == SELECT_SUBTRACT) { | 
					
						
							|  |  |  |           fcu->flag &= ~FCURVE_SELECTED; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           fcu->flag |= FCURVE_SELECTED; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       /* always deactivate all F-Curves if we perform batch ops for selection */ | 
					
						
							|  |  |  |       fcu->flag &= ~FCURVE_ACTIVE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Cleanup */ | 
					
						
							|  |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							| 
									
										
										
										
											2014-03-09 16:20:04 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 19:36:24 +12:00
										 |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_deselectall_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   bAnimListElem *ale_active = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   /* get editor data */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* find active F-Curve, and preserve this for later
 | 
					
						
							|  |  |  |    * or else it becomes annoying with the current active | 
					
						
							|  |  |  |    * curve keeps fading out even while you're editing it | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   ale_active = get_active_fcurve_channel(&ac); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* 'standard' behavior - check if selected, then apply relevant selection */ | 
					
						
							|  |  |  |   const int action = RNA_enum_get(op->ptr, "action"); | 
					
						
							|  |  |  |   switch (action) { | 
					
						
							|  |  |  |     case SEL_TOGGLE: | 
					
						
							|  |  |  |       deselect_graph_keys(&ac, 1, SELECT_ADD, true); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case SEL_SELECT: | 
					
						
							|  |  |  |       deselect_graph_keys(&ac, 0, SELECT_ADD, true); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case SEL_DESELECT: | 
					
						
							|  |  |  |       deselect_graph_keys(&ac, 0, SELECT_SUBTRACT, true); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case SEL_INVERT: | 
					
						
							|  |  |  |       deselect_graph_keys(&ac, 0, SELECT_INVERT, true); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       BLI_assert(0); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-03-05 22:26:45 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* restore active F-Curve... */ | 
					
						
							|  |  |  |   if (ale_active) { | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale_active->data; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* all others should not be disabled, so we should be able to just set this directly...
 | 
					
						
							|  |  |  |      * - selection needs to be set too, or else this won't work... | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     fcu->flag |= (FCURVE_SELECTED | FCURVE_ACTIVE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     MEM_freeN(ale_active); | 
					
						
							|  |  |  |     ale_active = NULL; | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* set notifier that things have changed */ | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_all(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select All"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_all"; | 
					
						
							|  |  |  |   ot->description = "Toggle selection of all keyframes"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = graphkeys_deselectall_exec; | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  |   /* flags */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-16 15:32:09 +11:00
										 |  |  |   /* properties */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   WM_operator_properties_select_all(ot); | 
					
						
							| 
									
										
										
										
											2014-12-09 16:53:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Box Select Operator **************************** */ | 
					
						
							|  |  |  | /* This operator currently works in one of three ways:
 | 
					
						
							|  |  |  |  * -> BKEY     - 1) all keyframes within region are selected (validation with BEZT_OK_REGION) | 
					
						
							|  |  |  |  * -> ALT-BKEY - depending on which axis of the region was larger... | 
					
						
							|  |  |  |  *    -> 2) x-axis, so select all frames within frame range (validation with BEZT_OK_FRAMERANGE) | 
					
						
							|  |  |  |  *    -> 3) y-axis, so select all frames within channels that region included | 
					
						
							|  |  |  |  *          (validation with BEZT_OK_VALUERANGE). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The selection backend is also reused for the Lasso and Circle select operators. | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  | static rctf initialize_box_select_coords(const bAnimContext *ac, const rctf *rectf_view) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const View2D *v2d = &ac->region->v2d; | 
					
						
							|  |  |  |   rctf rectf; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Convert mouse coordinates to frame ranges and
 | 
					
						
							|  |  |  |    * channel coordinates corrected for view pan/zoom. */ | 
					
						
							|  |  |  |   UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   return rectf; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  | static ListBase initialize_box_select_anim_data(const SpaceGraph *sipo, bAnimContext *ac) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2020-11-17 10:58:40 +01:00
										 |  |  |   if (sipo->flag & SIPO_SELCUVERTSONLY) { | 
					
						
							|  |  |  |     filter |= ANIMFILTER_FOREDIT | ANIMFILTER_SELEDIT; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   return anim_data; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  | static void initialize_box_select_key_editing_data(const SpaceGraph *sipo, | 
					
						
							|  |  |  |                                                    const bool incl_handles, | 
					
						
							|  |  |  |                                                    const short mode, | 
					
						
							|  |  |  |                                                    bAnimContext *ac, | 
					
						
							|  |  |  |                                                    void *data, | 
					
						
							|  |  |  |                                                    rctf *scaled_rectf, | 
					
						
							|  |  |  |                                                    KeyframeEditData *r_ked, | 
					
						
							|  |  |  |                                                    int *r_mapping_flag) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   memset(r_ked, 0, sizeof(KeyframeEditData)); | 
					
						
							|  |  |  |   switch (mode) { | 
					
						
							|  |  |  |     case BEZT_OK_REGION_LASSO: { | 
					
						
							|  |  |  |       KeyframeEdit_LassoData *data_lasso = data; | 
					
						
							|  |  |  |       data_lasso->rectf_scaled = scaled_rectf; | 
					
						
							|  |  |  |       r_ked->data = data_lasso; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     case BEZT_OK_REGION_CIRCLE: { | 
					
						
							|  |  |  |       KeyframeEdit_CircleData *data_circle = data; | 
					
						
							|  |  |  |       data_circle->rectf_scaled = scaled_rectf; | 
					
						
							|  |  |  |       r_ked->data = data_circle; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       r_ked->data = scaled_rectf; | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   if (sipo->flag & SIPO_SELVHANDLESONLY) { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     r_ked->iterflags |= KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE; | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Enable handles selection. (used in keyframes_edit.c > KEYFRAME_OK_CHECKS macro) */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (incl_handles) { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     r_ked->iterflags |= KEYFRAME_ITER_INCL_HANDLES; | 
					
						
							|  |  |  |     *r_mapping_flag = 0; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     *r_mapping_flag = ANIM_UNITCONV_ONLYKEYS; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   *r_mapping_flag |= ANIM_get_normalization_flags(ac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Box Select only selects keyframes, as overshooting handles often get caught too,
 | 
					
						
							|  |  |  |  * which means that they may be inadvertently moved as well. However, incl_handles overrides | 
					
						
							|  |  |  |  * this, and allow handles to be considered independently too. | 
					
						
							|  |  |  |  * Also, for convenience, handles should get same status as keyframe (if it was within bounds). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void box_select_graphkeys(bAnimContext *ac, | 
					
						
							|  |  |  |                                  const rctf *rectf_view, | 
					
						
							|  |  |  |                                  short mode, | 
					
						
							|  |  |  |                                  short selectmode, | 
					
						
							|  |  |  |                                  bool incl_handles, | 
					
						
							|  |  |  |                                  void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const rctf rectf = initialize_box_select_coords(ac, rectf_view); | 
					
						
							|  |  |  |   SpaceGraph *sipo = (SpaceGraph *)ac->sl; | 
					
						
							|  |  |  |   ListBase anim_data = initialize_box_select_anim_data(sipo, ac); | 
					
						
							|  |  |  |   rctf scaled_rectf; | 
					
						
							|  |  |  |   KeyframeEditData ked; | 
					
						
							|  |  |  |   int mapping_flag; | 
					
						
							|  |  |  |   initialize_box_select_key_editing_data( | 
					
						
							|  |  |  |       sipo, incl_handles, mode, ac, data, &scaled_rectf, &ked, &mapping_flag); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Get beztriple editing/validation funcs.  */ | 
					
						
							|  |  |  |   const KeyframeEditFunc select_cb = ANIM_editkeyframes_select(selectmode); | 
					
						
							|  |  |  |   const KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(mode); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Try selecting the keyframes. */ | 
					
						
							|  |  |  |   bAnimListElem *ale = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* First loop over data, doing box select. try selecting keys only. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale->key_data; | 
					
						
							|  |  |  |     float offset; | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     const float unit_scale = ANIM_unit_mapping_get_factor( | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |         ac->scene, ale->id, fcu, mapping_flag, &offset); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     /* Apply NLA mapping to all the keyframes, since it's easier than trying to
 | 
					
						
							|  |  |  |      * guess when a callback might use something different. | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     if (adt) { | 
					
						
							|  |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     scaled_rectf.xmin = rectf.xmin; | 
					
						
							|  |  |  |     scaled_rectf.xmax = rectf.xmax; | 
					
						
							|  |  |  |     scaled_rectf.ymin = rectf.ymin / unit_scale - offset; | 
					
						
							|  |  |  |     scaled_rectf.ymax = rectf.ymax / unit_scale - offset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     /* Set horizontal range (if applicable).
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |      * NOTE: these values are only used for x-range and y-range but not region | 
					
						
							|  |  |  |      *      (which uses ked.data, i.e. rectf) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (mode != BEZT_OK_VALUERANGE) { | 
					
						
							|  |  |  |       ked.f1 = rectf.xmin; | 
					
						
							|  |  |  |       ked.f2 = rectf.xmax; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       ked.f1 = rectf.ymin; | 
					
						
							|  |  |  |       ked.f2 = rectf.ymax; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     /* Firstly, check if any keyframes will be hit by this. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, ok_cb, NULL)) { | 
					
						
							|  |  |  |       /* select keyframes that are in the appropriate places */ | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* Only change selection of channel when the visibility of keyframes
 | 
					
						
							|  |  |  |        * doesn't depend on this. */ | 
					
						
							|  |  |  |       if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { | 
					
						
							|  |  |  |         /* select the curve too now that curve will be touched */ | 
					
						
							|  |  |  |         if (selectmode == SELECT_ADD) { | 
					
						
							|  |  |  |           fcu->flag |= FCURVE_SELECTED; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     /* Un-apply NLA mapping from all the keyframes. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (adt) { | 
					
						
							|  |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Cleanup. */ | 
					
						
							| 
									
										
										
										
											2014-05-19 00:24:45 +10:00
										 |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (RNA_boolean_get(op->ptr, "tweak")) { | 
					
						
							|  |  |  |     tNearestVertInfo *under_mouse = find_nearest_fcurve_vert(&ac, event->mval); | 
					
						
							|  |  |  |     bool mouse_is_over_element = under_mouse != NULL; | 
					
						
							|  |  |  |     if (under_mouse) { | 
					
						
							|  |  |  |       MEM_freeN(under_mouse); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     if (mouse_is_over_element) { | 
					
						
							|  |  |  |       return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   return WM_gesture_box_invoke(C, op, event); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_box_select_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   rcti rect; | 
					
						
							|  |  |  |   rctf rect_fl; | 
					
						
							|  |  |  |   short mode = 0; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  |   /* get editor data */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); | 
					
						
							|  |  |  |   const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; | 
					
						
							|  |  |  |   if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | 
					
						
							|  |  |  |     deselect_graph_keys(&ac, 1, SELECT_SUBTRACT, true); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* 'include_handles' from the operator specifies whether to include handles in the selection. */ | 
					
						
							|  |  |  |   const bool incl_handles = RNA_boolean_get(op->ptr, "include_handles"); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Get settings from operator. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   WM_operator_properties_border_to_rcti(op, &rect); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Selection 'mode' depends on whether box_select region only matters on one axis. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (RNA_boolean_get(op->ptr, "axis_range")) { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |     /* Mode depends on which axis of the range is larger to determine which axis to use
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |      * - Checking this in region-space is fine, as it's fundamentally still going to be a | 
					
						
							|  |  |  |      *   different rect size. | 
					
						
							|  |  |  |      * - The frame-range select option is favored over the channel one (x over y), | 
					
						
							|  |  |  |      *   as frame-range one is often used for tweaking timing when "blocking", | 
					
						
							|  |  |  |      *   while channels is not that useful. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if ((BLI_rcti_size_x(&rect)) >= (BLI_rcti_size_y(&rect))) { | 
					
						
							|  |  |  |       mode = BEZT_OK_FRAMERANGE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       mode = BEZT_OK_VALUERANGE; | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   else { | 
					
						
							|  |  |  |     mode = BEZT_OK_REGION; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   BLI_rctf_rcti_copy(&rect_fl, &rect); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Apply box_select action. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   box_select_graphkeys(&ac, &rect_fl, mode, selectmode, incl_handles, NULL); | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Send notifier that keyframe selection has changed. */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_box(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-04-05 11:47:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Identifiers. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->name = "Box Select"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_box"; | 
					
						
							|  |  |  |   ot->description = "Select all keyframes within the specified region"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* API callbacks. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->invoke = graphkeys_box_select_invoke; | 
					
						
							|  |  |  |   ot->exec = graphkeys_box_select_exec; | 
					
						
							|  |  |  |   ot->modal = WM_gesture_box_modal; | 
					
						
							|  |  |  |   ot->cancel = WM_gesture_box_cancel; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Flags. */ | 
					
						
							| 
									
										
										
										
											2015-08-22 02:47:32 +12:00
										 |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Properties. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->prop = RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", ""); | 
					
						
							| 
									
										
										
										
											2020-02-17 20:55:23 +11:00
										 |  |  |   RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PropertyRNA *prop; | 
					
						
							|  |  |  |   prop = RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                          "include_handles", | 
					
						
							|  |  |  |                          true, | 
					
						
							|  |  |  |                          "Include Handles", | 
					
						
							|  |  |  |                          "Are handles tested individually against the selection criteria"); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 20:55:23 +11:00
										 |  |  |   prop = RNA_def_boolean( | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       ot->srna, "tweak", 0, "Tweak", "Operator has been activated using a tweak event"); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   WM_operator_properties_gesture_box(ot); | 
					
						
							|  |  |  |   WM_operator_properties_select_operation_simple(ot); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ------------------- */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_lassoselect_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   KeyframeEdit_LassoData data_lasso = {0}; | 
					
						
							|  |  |  |   rcti rect; | 
					
						
							|  |  |  |   rctf rect_fl; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   bool incl_handles; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Get editor data. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   data_lasso.rectf_view = &rect_fl; | 
					
						
							| 
									
										
										
										
											2020-05-04 19:50:06 +10:00
										 |  |  |   data_lasso.mcoords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcoords_len); | 
					
						
							|  |  |  |   if (data_lasso.mcoords == NULL) { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); | 
					
						
							|  |  |  |   const short selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; | 
					
						
							|  |  |  |   if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | 
					
						
							|  |  |  |     deselect_graph_keys(&ac, 0, SELECT_SUBTRACT, true); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     SpaceGraph *sipo = (SpaceGraph *)ac.sl; | 
					
						
							|  |  |  |     if (selectmode == SELECT_ADD) { | 
					
						
							|  |  |  |       incl_handles = ((sipo->flag & SIPO_SELVHANDLESONLY) || (sipo->flag & SIPO_NOHANDLES)) == 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       incl_handles = (sipo->flag & SIPO_NOHANDLES) == 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Get settings from operator. */ | 
					
						
							| 
									
										
										
										
											2020-05-04 19:50:06 +10:00
										 |  |  |   BLI_lasso_boundbox(&rect, data_lasso.mcoords, data_lasso.mcoords_len); | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   BLI_rctf_rcti_copy(&rect_fl, &rect); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Apply box_select action. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   box_select_graphkeys(&ac, &rect_fl, BEZT_OK_REGION_LASSO, selectmode, incl_handles, &data_lasso); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-04 19:50:06 +10:00
										 |  |  |   MEM_freeN((void *)data_lasso.mcoords); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Send notifier that keyframe selection has changed. */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_lasso(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Identifiers. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->name = "Lasso Select"; | 
					
						
							|  |  |  |   ot->description = "Select keyframe points using lasso selection"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_lasso"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* API callbacks. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->invoke = WM_gesture_lasso_invoke; | 
					
						
							|  |  |  |   ot->modal = WM_gesture_lasso_modal; | 
					
						
							|  |  |  |   ot->exec = graphkeys_lassoselect_exec; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->cancel = WM_gesture_lasso_cancel; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Flags. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->flag = OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Properties. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   WM_operator_properties_gesture_lasso(ot); | 
					
						
							|  |  |  |   WM_operator_properties_select_operation_simple(ot); | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ------------------- */ | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graph_circle_select_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   bool incl_handles = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   KeyframeEdit_CircleData data = {0}; | 
					
						
							|  |  |  |   rctf rect_fl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   float x = RNA_int_get(op->ptr, "x"); | 
					
						
							|  |  |  |   float y = RNA_int_get(op->ptr, "y"); | 
					
						
							|  |  |  |   float radius = RNA_int_get(op->ptr, "radius"); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Get editor data. */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"), | 
					
						
							|  |  |  |                                               WM_gesture_is_modal_first(op->customdata)); | 
					
						
							|  |  |  |   const short selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; | 
					
						
							|  |  |  |   if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | 
					
						
							|  |  |  |     deselect_graph_keys(&ac, 0, SELECT_SUBTRACT, true); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   data.mval[0] = x; | 
					
						
							|  |  |  |   data.mval[1] = y; | 
					
						
							|  |  |  |   data.radius_squared = radius * radius; | 
					
						
							|  |  |  |   data.rectf_view = &rect_fl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rect_fl.xmin = x - radius; | 
					
						
							|  |  |  |   rect_fl.xmax = x + radius; | 
					
						
							|  |  |  |   rect_fl.ymin = y - radius; | 
					
						
							|  |  |  |   rect_fl.ymax = y + radius; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     SpaceGraph *sipo = (SpaceGraph *)ac.sl; | 
					
						
							|  |  |  |     if (selectmode == SELECT_ADD) { | 
					
						
							|  |  |  |       incl_handles = ((sipo->flag & SIPO_SELVHANDLESONLY) || (sipo->flag & SIPO_NOHANDLES)) == 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       incl_handles = (sipo->flag & SIPO_NOHANDLES) == 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Apply box_select action. */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   box_select_graphkeys(&ac, &rect_fl, BEZT_OK_REGION_CIRCLE, selectmode, incl_handles, &data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 16:35:42 +01:00
										 |  |  |   /* Send notifier that keyframe selection has changed. */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_circle(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->name = "Circle Select"; | 
					
						
							|  |  |  |   ot->description = "Select keyframe points using circle selection"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_circle"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->invoke = WM_gesture_circle_invoke; | 
					
						
							|  |  |  |   ot->modal = WM_gesture_circle_modal; | 
					
						
							|  |  |  |   ot->exec = graph_circle_select_exec; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->cancel = WM_gesture_circle_cancel; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  |   /* flags */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->flag = OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* properties */ | 
					
						
							|  |  |  |   WM_operator_properties_gesture_circle(ot); | 
					
						
							|  |  |  |   WM_operator_properties_select_operation_simple(ot); | 
					
						
							| 
									
										
										
										
											2010-02-07 11:50:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Column Select Operator **************************** */ | 
					
						
							|  |  |  | /* This operator works in one of four ways:
 | 
					
						
							|  |  |  |  * - 1) select all keyframes in the same frame as a selected one  (KKEY) | 
					
						
							|  |  |  |  * - 2) select all keyframes in the same frame as the current frame marker (CTRL-KKEY) | 
					
						
							|  |  |  |  * - 3) select all keyframes in the same frame as a selected markers (SHIFT-KKEY) | 
					
						
							|  |  |  |  * - 4) select all keyframes that occur between selected markers (ALT-KKEY) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* defines for column-select mode */ | 
					
						
							|  |  |  | static const EnumPropertyItem prop_column_select_types[] = { | 
					
						
							|  |  |  |     {GRAPHKEYS_COLUMNSEL_KEYS, "KEYS", 0, "On Selected Keyframes", ""}, | 
					
						
							|  |  |  |     {GRAPHKEYS_COLUMNSEL_CFRA, "CFRA", 0, "On Current Frame", ""}, | 
					
						
							|  |  |  |     {GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN, "MARKERS_COLUMN", 0, "On Selected Markers", ""}, | 
					
						
							|  |  |  |     {GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN, | 
					
						
							|  |  |  |      "MARKERS_BETWEEN", | 
					
						
							|  |  |  |      0, | 
					
						
							|  |  |  |      "Between Min/Max Selected Markers", | 
					
						
							|  |  |  |      ""}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {0, NULL, 0, NULL, NULL}, | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ------------------- */ | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Selects all visible keyframes between the specified markers */ | 
					
						
							|  |  |  | /* TODO, this is almost an _exact_ duplicate of a function of the same name in action_select.c
 | 
					
						
							|  |  |  |  * should de-duplicate - campbell */ | 
					
						
							|  |  |  | static void markers_selectkeys_between(bAnimContext *ac) | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   KeyframeEditFunc ok_cb, select_cb; | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   KeyframeEditData ked = {{NULL}}; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   float min, max; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get extreme markers */ | 
					
						
							|  |  |  |   ED_markers_get_minmax(ac->markers, 1, &min, &max); | 
					
						
							|  |  |  |   min -= 0.5f; | 
					
						
							|  |  |  |   max += 0.5f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get editing funcs + data */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   select_cb = ANIM_editkeyframes_select(SELECT_ADD); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ked.f1 = min; | 
					
						
							|  |  |  |   ked.f2 = max; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   /* filter data */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* select keys in-between */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |     if (adt) { | 
					
						
							|  |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							|  |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |       ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   /* Cleanup */ | 
					
						
							| 
									
										
										
										
											2014-05-19 00:24:45 +10:00
										 |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Selects all visible keyframes in the same frames as the specified elements */ | 
					
						
							|  |  |  | static void columnselect_graph_keys(bAnimContext *ac, short mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   Scene *scene = ac->scene; | 
					
						
							|  |  |  |   CfraElem *ce; | 
					
						
							|  |  |  |   KeyframeEditFunc select_cb, ok_cb; | 
					
						
							|  |  |  |   KeyframeEditData ked; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* initialize keyframe editing data */ | 
					
						
							|  |  |  |   memset(&ked, 0, sizeof(KeyframeEditData)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* build list of columns */ | 
					
						
							|  |  |  |   switch (mode) { | 
					
						
							|  |  |  |     case GRAPHKEYS_COLUMNSEL_KEYS: /* list of selected keys */ | 
					
						
							|  |  |  |       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							|  |  |  |       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |         ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_to_cfraelem, NULL); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ANIM_animdata_freelist(&anim_data); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case GRAPHKEYS_COLUMNSEL_CFRA: /* current frame */ | 
					
						
							|  |  |  |       /* make a single CfraElem for storing this */ | 
					
						
							|  |  |  |       ce = MEM_callocN(sizeof(CfraElem), "cfraElem"); | 
					
						
							|  |  |  |       BLI_addtail(&ked.list, ce); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ce->cfra = (float)CFRA; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN: /* list of selected markers */ | 
					
						
							|  |  |  |       ED_markers_make_cfra_list(ac->markers, &ked.list, SELECT); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     default: /* invalid option */ | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* set up BezTriple edit callbacks */ | 
					
						
							|  |  |  |   select_cb = ANIM_editkeyframes_select(SELECT_ADD); | 
					
						
							|  |  |  |   ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAME); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* loop through all of the keys and select additional keyframes
 | 
					
						
							|  |  |  |    * based on the keys found to be selected above | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							|  |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* loop over cfraelems (stored in the KeyframeEditData->list)
 | 
					
						
							|  |  |  |      * - we need to do this here, as we can apply fewer NLA-mapping conversions | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     for (ce = ked.list.first; ce; ce = ce->next) { | 
					
						
							|  |  |  |       /* set frame for validation callback to refer to */ | 
					
						
							|  |  |  |       ked.f1 = BKE_nla_tweakedit_remap(adt, ce->cfra, NLATIME_CONVERT_UNMAP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* select elements with frame number matching cfraelem */ | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* free elements */ | 
					
						
							|  |  |  |   BLI_freelistN(&ked.list); | 
					
						
							|  |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int graphkeys_columnselect_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   short mode; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   /* get editor data */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* action to take depends on the mode */ | 
					
						
							|  |  |  |   mode = RNA_enum_get(op->ptr, "mode"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mode == GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN) { | 
					
						
							|  |  |  |     markers_selectkeys_between(&ac); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     columnselect_graph_keys(&ac, mode); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* set notifier that keyframe selection has changed */ | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GRAPH_OT_select_column(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select All"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_column"; | 
					
						
							|  |  |  |   ot->description = "Select all keyframes on the specified frame(s)"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = graphkeys_columnselect_exec; | 
					
						
							|  |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* props */ | 
					
						
							|  |  |  |   ot->prop = RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", ""); | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Select Linked Operator *********************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int graphkeys_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED); | 
					
						
							|  |  |  |   KeyframeEditFunc sel_cb = ANIM_editkeyframes_select(SELECT_ADD); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   /* get editor data */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* loop through all of the keys and select additional keyframes based on these */ | 
					
						
							|  |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							|  |  |  |   ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale->key_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* check if anything selected? */ | 
					
						
							|  |  |  |     if (ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, ok_cb, NULL)) { | 
					
						
							|  |  |  |       /* select every keyframe in this curve then */ | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, sel_cb, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Cleanup */ | 
					
						
							|  |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* set notifier that keyframe selection has changed */ | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_linked(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   /* identifiers */ | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   ot->name = "Select Linked"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_linked"; | 
					
						
							|  |  |  |   ot->description = "Select keyframes occurring in the same F-Curves as selected ones"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = graphkeys_select_linked_exec; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   /* flags */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Select More/Less Operators *********************** */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* Common code to perform selection */ | 
					
						
							|  |  |  | static void select_moreless_graph_keys(bAnimContext *ac, short mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   KeyframeEditData ked; | 
					
						
							|  |  |  |   KeyframeEditFunc build_cb; | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* init selmap building data */ | 
					
						
							|  |  |  |   build_cb = ANIM_editkeyframes_buildselmap(mode); | 
					
						
							|  |  |  |   memset(&ked, 0, sizeof(KeyframeEditData)); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* loop through all of the keys and select additional keyframes based on these */ | 
					
						
							|  |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							|  |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     FCurve *fcu = (FCurve *)ale->key_data; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* only continue if F-Curve has keyframes */ | 
					
						
							|  |  |  |     if (fcu->bezt == NULL) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* build up map of whether F-Curve's keyframes should be selected or not */ | 
					
						
							|  |  |  |     ked.data = MEM_callocN(fcu->totvert, "selmap graphEdit"); | 
					
						
							|  |  |  |     ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, build_cb, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* based on this map, adjust the selection status of the keyframes */ | 
					
						
							|  |  |  |     ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_selmap_flush, NULL); | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* free the selmap used here */ | 
					
						
							|  |  |  |     MEM_freeN(ked.data); | 
					
						
							|  |  |  |     ked.data = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Cleanup */ | 
					
						
							|  |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ----------------- */ | 
					
						
							| 
									
										
										
										
											2010-02-08 18:00:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_select_more_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2010-02-08 18:00:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   bAnimContext ac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* get editor data */ | 
					
						
							|  |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* perform select changes */ | 
					
						
							|  |  |  |   select_moreless_graph_keys(&ac, SELMAP_MORE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* set notifier that keyframe selection has changed */ | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-02-08 18:00:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_more(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select More"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_more"; | 
					
						
							|  |  |  |   ot->description = "Select keyframes beside already selected ones"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = graphkeys_select_more_exec; | 
					
						
							|  |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ----------------- */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_select_less_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get editor data */ | 
					
						
							|  |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* perform select changes */ | 
					
						
							|  |  |  |   select_moreless_graph_keys(&ac, SELMAP_LESS); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* set notifier that keyframe selection has changed */ | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GRAPH_OT_select_less(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select Less"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_less"; | 
					
						
							|  |  |  |   ot->description = "Deselect keyframes on ends of selection islands"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = graphkeys_select_less_exec; | 
					
						
							|  |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Select Left/Right Operator ************************* */ | 
					
						
							|  |  |  | /* Select keyframes left/right of the current frame indicator */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* defines for left-right select tool */ | 
					
						
							|  |  |  | static const EnumPropertyItem prop_graphkeys_leftright_select_types[] = { | 
					
						
							|  |  |  |     {GRAPHKEYS_LRSEL_TEST, "CHECK", 0, "Check if Select Left or Right", ""}, | 
					
						
							| 
									
										
										
										
											2020-12-13 13:12:56 -08:00
										 |  |  |     {GRAPHKEYS_LRSEL_LEFT, "LEFT", 0, "Before Current Frame", ""}, | 
					
						
							|  |  |  |     {GRAPHKEYS_LRSEL_RIGHT, "RIGHT", 0, "After Current Frame", ""}, | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     {0, NULL, 0, NULL, NULL}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void graphkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode) | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							|  |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   KeyframeEditFunc ok_cb, select_cb; | 
					
						
							|  |  |  |   KeyframeEditData ked = {{NULL}}; | 
					
						
							|  |  |  |   Scene *scene = ac->scene; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* if select mode is replace, deselect all keyframes (and channels) first */ | 
					
						
							|  |  |  |   if (select_mode == SELECT_REPLACE) { | 
					
						
							|  |  |  |     select_mode = SELECT_ADD; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* - deselect all other keyframes, so that just the newly selected remain
 | 
					
						
							|  |  |  |      * - channels aren't deselected, since we don't re-select any as a consequence | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     deselect_graph_keys(ac, 0, SELECT_SUBTRACT, false); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* set callbacks and editing data */ | 
					
						
							|  |  |  |   ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); | 
					
						
							|  |  |  |   select_cb = ANIM_editkeyframes_select(select_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (leftright == GRAPHKEYS_LRSEL_LEFT) { | 
					
						
							|  |  |  |     ked.f1 = MINAFRAMEF; | 
					
						
							|  |  |  |     ked.f2 = (float)(CFRA + 0.1f); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     ked.f1 = (float)(CFRA - 0.1f); | 
					
						
							|  |  |  |     ked.f2 = MAXFRAMEF; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* filter data */ | 
					
						
							|  |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* select keys */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (adt) { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							|  |  |  |       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* Cleanup */ | 
					
						
							|  |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ----------------- */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_select_leftright_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							|  |  |  |   short leftright = RNA_enum_get(op->ptr, "mode"); | 
					
						
							|  |  |  |   short selectmode; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get editor data */ | 
					
						
							|  |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* select mode is either replace (deselect all, then add) or add/extend */ | 
					
						
							|  |  |  |   if (RNA_boolean_get(op->ptr, "extend")) { | 
					
						
							|  |  |  |     selectmode = SELECT_INVERT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     selectmode = SELECT_REPLACE; | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* if "test" mode is set, we don't have any info to set this with */ | 
					
						
							|  |  |  |   if (leftright == GRAPHKEYS_LRSEL_TEST) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* do the selecting now */ | 
					
						
							|  |  |  |   graphkeys_select_leftright(&ac, leftright, selectmode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* set notifier that keyframe selection (and channels too) have changed */ | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   bAnimContext ac; | 
					
						
							|  |  |  |   short leftright = RNA_enum_get(op->ptr, "mode"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* get editor data */ | 
					
						
							|  |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* handle mode-based testing */ | 
					
						
							|  |  |  |   if (leftright == GRAPHKEYS_LRSEL_TEST) { | 
					
						
							|  |  |  |     Scene *scene = ac.scene; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     ARegion *region = ac.region; | 
					
						
							|  |  |  |     View2D *v2d = ®ion->v2d; | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     float x; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |     /* determine which side of the current frame mouse is on */ | 
					
						
							|  |  |  |     x = UI_view2d_region_to_view_x(v2d, event->mval[0]); | 
					
						
							|  |  |  |     if (x < CFRA) { | 
					
						
							|  |  |  |       RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_LEFT); | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |       RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_RIGHT); | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* perform selection */ | 
					
						
							|  |  |  |   return graphkeys_select_leftright_exec(C, op); | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | void GRAPH_OT_select_leftright(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select Left/Right"; | 
					
						
							|  |  |  |   ot->idname = "GRAPH_OT_select_leftright"; | 
					
						
							|  |  |  |   ot->description = "Select keyframes to the left or the right of the current frame"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* api callbacks  */ | 
					
						
							|  |  |  |   ot->invoke = graphkeys_select_leftright_invoke; | 
					
						
							|  |  |  |   ot->exec = graphkeys_select_leftright_exec; | 
					
						
							|  |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  |   /* id-props */ | 
					
						
							|  |  |  |   ot->prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "mode", prop_graphkeys_leftright_select_types, GRAPHKEYS_LRSEL_TEST, "Mode", ""); | 
					
						
							|  |  |  |   RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 11:35:57 +02:00
										 |  |  | /* ******************** Mouse-Click Select Operator *********************** */ | 
					
						
							|  |  |  | /* This operator works in one of three ways:
 | 
					
						
							|  |  |  |  * - 1) keyframe under mouse - no special modifiers | 
					
						
							|  |  |  |  * - 2) all keyframes on the same side of current frame indicator as mouse - ALT modifier | 
					
						
							|  |  |  |  * - 3) column select all keyframes in frame under mouse - CTRL modifier | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In addition to these basic options, the SHIFT modifier can be used to toggle the | 
					
						
							|  |  |  |  * selection mode between replacing the selection (without) and inverting the selection (with). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | /* option 1) select keyframe directly under mouse */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  | static int mouse_graph_keys(bAnimContext *ac, | 
					
						
							|  |  |  |                             const int mval[2], | 
					
						
							|  |  |  |                             eEditKeyframes_Select select_mode, | 
					
						
							|  |  |  |                             const bool deselect_all, | 
					
						
							|  |  |  |                             const bool curves_only, | 
					
						
							|  |  |  |                             bool wait_to_deselect_others) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-16 10:16:16 +11:00
										 |  |  |   SpaceGraph *sipo = (SpaceGraph *)ac->sl; | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   tNearestVertInfo *nvi; | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   BezTriple *bezt = NULL; | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   bool run_modal = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |   /* find the beztriple that we're selecting, and the handle that was clicked on */ | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   nvi = find_nearest_fcurve_vert(ac, mval); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   if (select_mode != SELECT_REPLACE) { | 
					
						
							|  |  |  |     /* The modal execution to delay deselecting other items is only needed for normal click
 | 
					
						
							|  |  |  |      * selection, i.e. for SELECT_REPLACE. */ | 
					
						
							|  |  |  |     wait_to_deselect_others = false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sipo->runtime.flag &= ~(SIPO_RUNTIME_FLAG_TWEAK_HANDLES_LEFT | | 
					
						
							|  |  |  |                           SIPO_RUNTIME_FLAG_TWEAK_HANDLES_RIGHT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const bool already_selected = | 
					
						
							|  |  |  |       (nvi != NULL) && (((nvi->hpoint == NEAREST_HANDLE_KEY) && (nvi->bezt->f2 & SELECT)) || | 
					
						
							|  |  |  |                         ((nvi->hpoint == NEAREST_HANDLE_LEFT) && (nvi->bezt->f1 & SELECT)) || | 
					
						
							|  |  |  |                         ((nvi->hpoint == NEAREST_HANDLE_RIGHT) && (nvi->bezt->f3 & SELECT))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (wait_to_deselect_others && nvi && already_selected) { | 
					
						
							|  |  |  |     run_modal = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-30 17:17:34 +02:00
										 |  |  |   /* For replacing selection, if we have something to select, we have to clear existing selection.
 | 
					
						
							|  |  |  |    * The same goes if we found nothing to select, and deselect_all is true | 
					
						
							|  |  |  |    * (deselect on nothing behavior). */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   else if ((nvi != NULL && select_mode == SELECT_REPLACE) || (nvi == NULL && deselect_all)) { | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |     /* reset selection mode */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |     select_mode = SELECT_ADD; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-15 12:02:44 +00:00
										 |  |  |     /* deselect all other keyframes (+ F-Curves too) */ | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  |     deselect_graph_keys(ac, 0, SELECT_SUBTRACT, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  |     /* deselect other channels too, but only only do this if
 | 
					
						
							|  |  |  |      * selection of channel when the visibility of keyframes | 
					
						
							|  |  |  |      * doesn't depend on this | 
					
						
							| 
									
										
										
										
											2010-01-22 23:51:31 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { | 
					
						
							| 
									
										
										
											
												Cleanup: Animation, simplify channel selection code
Split up `ANIM_deselect_anim_channels()` into
`ANIM_anim_channels_select_set()` and
`ANIM_anim_channels_select_toggle()`.
`ANIM_anim_channels_select_set()` is equivalent to the old
`ANIM_deselect_anim_channels(..., false, ACHANNEL_SETFLAG_xxx)`.
`ANIM_anim_channels_select_toggle()` is equivalent to the old
`ANIM_deselect_anim_channels(..., true, ACHANNEL_SETFLAG_ADD)`.
`ANIM_deselect_anim_channels(..., true, ACHANNEL_SETFLAG_CLEAR)` was
also called once. The `true` parameter suggested the "toggle" behaviour
was intended, but the `ACHANNEL_SETFLAG_CLEAR` argument prevented any
toggling. This is now replaced with `ANIM_anim_channels_select_set(ac,
ACHANNEL_SETFLAG_CLEAR)` to make this explicit.
No functional changes, just a cleanup in order to better understand how
the selection works.
											
										 
											2020-10-13 14:43:19 +02:00
										 |  |  |       ANIM_anim_channels_select_set(ac, ACHANNEL_SETFLAG_CLEAR); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 17:17:34 +02:00
										 |  |  |   if (nvi == NULL) { | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |     return deselect_all ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-30 17:17:34 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   /* if points can be selected on this F-Curve */ | 
					
						
							|  |  |  |   /* TODO: what about those with no keyframes? */ | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |   bool something_was_selected = false; | 
					
						
							| 
									
										
										
										
											2019-04-30 16:26:31 +02:00
										 |  |  |   if (!curves_only && ((nvi->fcu->flag & FCURVE_PROTECTED) == 0)) { | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |     /* only if there's keyframe */ | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |     if (nvi->bezt) { | 
					
						
							| 
									
										
										
										
											2020-03-04 21:45:40 +11:00
										 |  |  |       bezt = nvi->bezt; /* Used to check `bezt` selection is set. */ | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |       if (select_mode == SELECT_INVERT) { | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |         if (nvi->hpoint == NEAREST_HANDLE_KEY) { | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |           bezt->f2 ^= SELECT; | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |           something_was_selected = (bezt->f2 & SELECT); | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |         else if (nvi->hpoint == NEAREST_HANDLE_LEFT) { | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |           /* toggle selection */ | 
					
						
							|  |  |  |           bezt->f1 ^= SELECT; | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |           something_was_selected = (bezt->f1 & SELECT); | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           /* toggle selection */ | 
					
						
							|  |  |  |           bezt->f3 ^= SELECT; | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |           something_was_selected = (bezt->f3 & SELECT); | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |         if (nvi->hpoint == NEAREST_HANDLE_KEY) { | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |           bezt->f2 |= SELECT; | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         else if (nvi->hpoint == NEAREST_HANDLE_LEFT) { | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |           bezt->f1 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |           bezt->f3 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |         something_was_selected = true; | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-10-07 08:27:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 12:27:43 +01:00
										 |  |  |       if (!run_modal && BEZT_ISSEL_ANY(bezt)) { | 
					
						
							|  |  |  |         const bool may_activate = !already_selected || | 
					
						
							|  |  |  |                                   BKE_fcurve_active_keyframe_index(nvi->fcu) == | 
					
						
							|  |  |  |                                       FCURVE_ACTIVE_KEYFRAME_NONE; | 
					
						
							|  |  |  |         if (may_activate) { | 
					
						
							|  |  |  |           BKE_fcurve_active_keyframe_set(nvi->fcu, bezt); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-07 08:27:58 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |     else if (nvi->fpt) { | 
					
						
							|  |  |  |       /* TODO: need to handle sample points */ | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   else { | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |     KeyframeEditFunc select_cb; | 
					
						
							|  |  |  |     KeyframeEditData ked; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  |     /* initialize keyframe editing data */ | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |     memset(&ked, 0, sizeof(KeyframeEditData)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |     /* set up BezTriple edit callbacks */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |     select_cb = ANIM_editkeyframes_select(select_mode); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |     /* select all keyframes */ | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |     ANIM_fcurve_keyframes_loop(&ked, nvi->fcu, NULL, select_cb, NULL); | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-22 23:51:31 +00:00
										 |  |  |   /* only change selection of channel when the visibility of keyframes doesn't depend on this */ | 
					
						
							|  |  |  |   if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { | 
					
						
							|  |  |  |     /* select or deselect curve? */ | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |     if (bezt) { | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  |       /* take selection status from item that got hit, to prevent flip/flop on channel
 | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |        * selection status when shift-selecting (i.e. "SELECT_INVERT") points | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (BEZT_ISSEL_ANY(bezt)) { | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |         nvi->fcu->flag |= FCURVE_SELECTED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |         nvi->fcu->flag &= ~FCURVE_SELECTED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-22 00:18:34 +10:00
										 |  |  |       /* Didn't hit any channel,
 | 
					
						
							|  |  |  |        * so just apply that selection mode to the curve's selection status. */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (select_mode == SELECT_INVERT) { | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |         nvi->fcu->flag ^= FCURVE_SELECTED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else if (select_mode == SELECT_ADD) { | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |         nvi->fcu->flag |= FCURVE_SELECTED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-12-15 15:59:10 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-02-09 10:33:05 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |   /* Set active F-Curve when something was actually selected (so not on a deselect), except when
 | 
					
						
							|  |  |  |    * dragging the selected keys. Needs to be called with (sipo->flag & SIPO_SELCUVERTSONLY), | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  |    * otherwise the active flag won't be set T26452. */ | 
					
						
							| 
									
										
										
										
											2020-10-23 17:39:29 +02:00
										 |  |  |   if (!run_modal && (nvi->fcu->flag & FCURVE_SELECTED) && something_was_selected) { | 
					
						
							| 
									
										
										
										
											2020-10-07 08:27:58 -05:00
										 |  |  |     /* NOTE: Sync the filter flags with findnearest_fcurve_vert. */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |     int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2015-04-05 12:17:14 +12:00
										 |  |  |     ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nvi->fcu, nvi->ctype); | 
					
						
							| 
									
										
										
										
											2011-03-10 23:55:22 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   if (nvi->hpoint == NEAREST_HANDLE_LEFT) { | 
					
						
							|  |  |  |     sipo->runtime.flag |= SIPO_RUNTIME_FLAG_TWEAK_HANDLES_LEFT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (nvi->hpoint == NEAREST_HANDLE_RIGHT) { | 
					
						
							|  |  |  |     sipo->runtime.flag |= SIPO_RUNTIME_FLAG_TWEAK_HANDLES_RIGHT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   /* free temp sample data for filtering */ | 
					
						
							|  |  |  |   MEM_freeN(nvi); | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return run_modal ? OPERATOR_RUNNING_MODAL : OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | /* Option 2) Selects all the keyframes on either side of the current frame
 | 
					
						
							|  |  |  |  * (depends on which side the mouse is on) */ | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  | /* (see graphkeys_select_leftright) */ | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Option 3) Selects all visible keyframes in the same frame as the mouse click */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  | static int graphkeys_mselect_column(bAnimContext *ac, | 
					
						
							|  |  |  |                                     const int mval[2], | 
					
						
							|  |  |  |                                     eEditKeyframes_Select select_mode, | 
					
						
							|  |  |  |                                     bool wait_to_deselect_others) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   ListBase anim_data = {NULL, NULL}; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   bAnimListElem *ale; | 
					
						
							|  |  |  |   int filter; | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   bool run_modal = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |   KeyframeEditFunc select_cb, ok_cb; | 
					
						
							|  |  |  |   KeyframeEditData ked; | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   tNearestVertInfo *nvi; | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   float selx = (float)ac->scene->r.cfra; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   /* find the beztriple that we're selecting, and the handle that was clicked on */ | 
					
						
							|  |  |  |   nvi = find_nearest_fcurve_vert(ac, mval); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   /* check if anything to select */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (nvi == NULL) { | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   /* get frame number on which elements should be selected */ | 
					
						
							|  |  |  |   /* TODO: should we restrict to integer frames only? */ | 
					
						
							| 
									
										
										
										
											2017-10-24 16:27:21 +13:00
										 |  |  |   selx = nvi->frame; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   if (select_mode != SELECT_REPLACE) { | 
					
						
							|  |  |  |     /* Doesn't need to deselect anything -> Pass. */ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (wait_to_deselect_others && (nvi->bezt->f2 & SELECT)) { | 
					
						
							|  |  |  |     run_modal = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* If select mode is replace (and we don't do delayed deselection on mouse release), deselect all
 | 
					
						
							|  |  |  |    * keyframes first. */ | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |     /* reset selection mode to add to selection */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |     select_mode = SELECT_ADD; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-15 12:02:44 +00:00
										 |  |  |     /* - deselect all other keyframes, so that just the newly selected remain
 | 
					
						
							|  |  |  |      * - channels aren't deselected, since we don't re-select any as a consequence | 
					
						
							| 
									
										
										
										
											2010-01-22 23:51:31 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  |     deselect_graph_keys(ac, 0, SELECT_SUBTRACT, false); | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  |   /* initialize keyframe editing data */ | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |   memset(&ked, 0, sizeof(KeyframeEditData)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* set up BezTriple edit callbacks */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   select_cb = ANIM_editkeyframes_select(select_mode); | 
					
						
							|  |  |  |   ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAME); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* loop through all of the keys and select additional keyframes
 | 
					
						
							|  |  |  |    * based on the keys found to be selected above | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |   for (ale = anim_data.first; ale; ale = ale->next) { | 
					
						
							|  |  |  |     AnimData *adt = ANIM_nla_mapping_get(ac, ale); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |     /* set frame for validation callback to refer to */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (adt) { | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |       ked.f1 = BKE_nla_tweakedit_remap(adt, selx, NLATIME_CONVERT_UNMAP); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2012-05-08 20:18:33 +00:00
										 |  |  |       ked.f1 = selx; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 05:04:23 +00:00
										 |  |  |     /* select elements with frame number matching cfra */ | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |     ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* free elements */ | 
					
						
							| 
									
										
										
										
											2010-03-09 07:09:38 +00:00
										 |  |  |   MEM_freeN(nvi); | 
					
						
							| 
									
										
										
										
											2010-04-02 12:02:39 +00:00
										 |  |  |   BLI_freelistN(&ked.list); | 
					
						
							| 
									
										
										
										
											2014-05-19 00:24:45 +10:00
										 |  |  |   ANIM_animdata_freelist(&anim_data); | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return run_modal ? OPERATOR_RUNNING_MODAL : OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* handle clicking */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  | static int graphkeys_clickselect_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bAnimContext ac; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* get editor data */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ANIM_animdata_get_context(C, &ac) == 0) { | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |     return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* select mode is either replace (deselect all, then add) or add/extend */ | 
					
						
							| 
									
										
										
										
											2019-04-30 16:26:31 +02:00
										 |  |  |   const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE; | 
					
						
							|  |  |  |   const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   /* See #WM_operator_properties_generic_select() for a detailed description of the how and why of
 | 
					
						
							|  |  |  |    * this. */ | 
					
						
							|  |  |  |   const bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others"); | 
					
						
							|  |  |  |   int mval[2]; | 
					
						
							|  |  |  |   int ret_val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mval[0] = RNA_int_get(op->ptr, "mouse_x"); | 
					
						
							|  |  |  |   mval[1] = RNA_int_get(op->ptr, "mouse_y"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* figure out action to take */ | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |   if (RNA_boolean_get(op->ptr, "column")) { | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |     /* select all keyframes in the same frame as the one that was under the mouse */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |     ret_val = graphkeys_mselect_column(&ac, mval, selectmode, wait_to_deselect_others); | 
					
						
							| 
									
										
										
										
											2009-04-12 08:17:46 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (RNA_boolean_get(op->ptr, "curves")) { | 
					
						
							| 
									
										
										
										
											2011-02-14 02:50:52 +00:00
										 |  |  |     /* select all keyframes in the same F-Curve as the one under the mouse */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |     ret_val = mouse_graph_keys(&ac, mval, selectmode, deselect_all, true, wait_to_deselect_others); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* select keyframe under mouse */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |     ret_val = mouse_graph_keys( | 
					
						
							|  |  |  |         &ac, mval, selectmode, deselect_all, false, wait_to_deselect_others); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   /* set notifier that keyframe selection (and also channel selection in some cases) has
 | 
					
						
							|  |  |  |    * changed */ | 
					
						
							| 
									
										
										
										
											2018-01-25 10:10:21 -02:00
										 |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-28 15:39:39 +00:00
										 |  |  |   /* for tweak grab to work */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   return ret_val | OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-29 17:11:40 +00:00
										 |  |  | void GRAPH_OT_clickselect(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-08 14:02:18 +00:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  |   /* identifiers */ | 
					
						
							| 
									
										
										
										
											2018-06-27 17:07:02 +02:00
										 |  |  |   ot->name = "Select Keyframes"; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->idname = "GRAPH_OT_clickselect"; | 
					
						
							|  |  |  |   ot->description = "Select keyframes by clicking on them"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 05:48:46 +00:00
										 |  |  |   /* callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  |   ot->poll = graphop_visible_keyframes_poll; | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   ot->exec = graphkeys_clickselect_exec; | 
					
						
							|  |  |  |   ot->invoke = WM_generic_select_invoke; | 
					
						
							|  |  |  |   ot->modal = WM_generic_select_modal; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 05:48:46 +00:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 14:02:18 +00:00
										 |  |  |   /* properties */ | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   WM_operator_properties_generic_select(ot); | 
					
						
							|  |  |  |   prop = RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                          "extend", | 
					
						
							|  |  |  |                          0, | 
					
						
							|  |  |  |                          "Extend Select", | 
					
						
							|  |  |  |                          "Toggle keyframe selection instead of leaving newly selected " | 
					
						
							|  |  |  |                          "keyframes only"); /* SHIFTKEY */ | 
					
						
							| 
									
										
										
										
											2012-08-08 14:02:18 +00:00
										 |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 16:26:31 +02:00
										 |  |  |   prop = RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                          "deselect_all", | 
					
						
							|  |  |  |                          false, | 
					
						
							|  |  |  |                          "Deselect On Nothing", | 
					
						
							|  |  |  |                          "Deselect all when nothing under the cursor"); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 16:46:15 +01:00
										 |  |  |   prop = RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                          "column", | 
					
						
							|  |  |  |                          0, | 
					
						
							|  |  |  |                          "Column Select", | 
					
						
							|  |  |  |                          "Select all keyframes that occur on the same frame as the one under " | 
					
						
							|  |  |  |                          "the mouse"); /* ALTKEY */ | 
					
						
							| 
									
										
										
										
											2012-08-08 14:02:18 +00:00
										 |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  |   prop = RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                          "curves", | 
					
						
							|  |  |  |                          0, | 
					
						
							|  |  |  |                          "Only Curves", | 
					
						
							| 
									
										
										
										
											2012-08-08 14:02:18 +00:00
										 |  |  |                          "Select all the keyframes in the curve"); /* CTRLKEY + ALTKEY */ | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2009-01-26 23:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************** */ |