Blender  V2.93
ED_keyframes_edit.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "ED_anim_api.h" /* for enum eAnimFilter_Flags */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct BezTriple;
33 struct FCurve;
34 struct Scene;
35 struct bAnimContext;
36 struct bAnimListElem;
37 struct bDopeSheet;
38 
39 /* ************************************************ */
40 /* Common Macros and Defines */
41 
42 /* --------- Tool Flags ------------ */
43 
44 /* bezt validation */
46  /* Frame range */
49  /* Selection status */
51  /* Values (y-val) only */
54  /* For graph editor keyframes (2D tests) */
58  /* Only for keyframes a certain Dopesheet channel */
62 
63 /* ------------ */
64 
65 /* select modes */
66 typedef enum eEditKeyframes_Select {
67  /* SELECT_SUBTRACT for all, followed by SELECT_ADD for some */
68  SELECT_REPLACE = (1 << 0),
69  /* add ok keyframes to selection */
70  SELECT_ADD = (1 << 1),
71  /* remove ok keyframes from selection */
72  SELECT_SUBTRACT = (1 << 2),
73  /* flip ok status of keyframes based on key status */
74  SELECT_INVERT = (1 << 3),
76 
77 /* "selection map" building modes */
78 typedef enum eEditKeyframes_SelMap {
82 
83 /* snapping tools */
84 typedef enum eEditKeyframes_Snap {
93 
94 /* mirroring tools */
95 typedef enum eEditKeyframes_Mirror {
103 
104 /* use with BEZT_OK_REGION_LASSO */
105 typedef struct KeyframeEdit_LassoData {
107  const rctf *rectf_view;
108  const int (*mcoords)[2];
111 
112 /* use with BEZT_OK_REGION_CIRCLE */
113 typedef struct KeyframeEdit_CircleData {
115  const rctf *rectf_view;
116  float mval[2];
119 
120 /* ************************************************ */
121 /* Non-Destructive Editing API (keyframes_edit.c) */
122 
123 /* --- Defines for 'OK' polls + KeyframeEditData Flags --------- */
124 
125 /* which verts of a keyframe is active (after polling) */
126 typedef enum eKeyframeVertOk {
127  /* 'key' itself is ok */
128  KEYFRAME_OK_KEY = (1 << 0),
129  /* 'handle 1' is ok */
130  KEYFRAME_OK_H1 = (1 << 1),
131  /* 'handle 2' is ok */
132  KEYFRAME_OK_H2 = (1 << 2),
133  /* all flags */
136 
137 /* Flags for use during iteration */
138 typedef enum eKeyframeIterFlags {
139  /* consider handles in addition to key itself */
141 
142  /* Perform NLA time remapping (global -> strip) for the "f1" parameter
143  * (e.g. used for selection tools on summary tracks)
144  */
145  KED_F1_NLA_UNMAP = (1 << 1),
146 
147  /* Perform NLA time remapping (global -> strip) for the "f2" parameter */
148  KED_F2_NLA_UNMAP = (1 << 2),
149 
150  /* Set this when handles aren't visible by default and you want to perform additional checks to
151  * get the actual visibility state. E.g. in some cases handles are only drawn if either a handle
152  * or their control point is selected. The selection state will have to be checked in the
153  * iterator callbacks then. */
156 
157 /* --- Generic Properties for Keyframe Edit Tools ----- */
158 
159 typedef struct KeyframeEditData {
160  /* generic properties/data access */
164  struct Scene *scene;
166  void *data;
168  float f1, f2;
170  int i1, i2;
171 
172  /* current iteration data */
174  struct FCurve *fcu;
176  int curIndex;
178  float channel_y;
179 
180  /* flags */
186 
187 /* ------- Function Pointer Typedefs ---------------- */
188 
189 /* callback function that refreshes the F-Curve after use */
190 typedef void (*FcuEditFunc)(struct FCurve *fcu);
191 /* callback function that operates on the given BezTriple */
192 typedef short (*KeyframeEditFunc)(KeyframeEditData *ked, struct BezTriple *bezt);
193 
194 /* ------- Custom Data Type Defines ------------------ */
195 
196 /* Custom data for remapping one range to another in a fixed way */
197 typedef struct KeyframeEditCD_Remap {
198  float oldMin, oldMax; /* old range */
199  float newMin, newMax; /* new range */
201 
202 /* Paste options */
203 typedef enum eKeyPasteOffset {
204  /* paste keys starting at current frame */
206  /* paste keys ending at current frame */
208  /* paste keys relative to the current frame when copying */
210  /* paste keys from original time */
213 
214 typedef enum eKeyMergeMode {
215  /* overlay existing with new keys */
217  /* replace entire fcurve */
219  /* overwrite keys in pasted range */
221  /* overwrite keys in pasted range (use all keyframe start & end for range) */
224 
225 /* ---------------- Looping API --------------------- */
226 
227 /* functions for looping over keyframes */
228 /* function for working with F-Curve data only
229  * (i.e. when filters have been chosen to explicitly use this) */
231  struct FCurve *fcu,
232  KeyframeEditFunc key_ok,
233  KeyframeEditFunc key_cb,
234  FcuEditFunc fcu_cb);
235 /* function for working with any type (i.e. one of the known types) of animation channel
236  * - filterflag is bDopeSheet->flag (DOPESHEET_FILTERFLAG)
237  */
239  struct bDopeSheet *ads,
240  struct bAnimListElem *ale,
241  KeyframeEditFunc key_ok,
242  KeyframeEditFunc key_cb,
243  FcuEditFunc fcu_cb);
244 /* same as above, except bAnimListElem wrapper is not needed...
245  * - keytype is eAnim_KeyType
246  */
248  struct bDopeSheet *ads,
249  void *data,
250  int keytype,
251  KeyframeEditFunc key_ok,
252  KeyframeEditFunc key_cb,
253  FcuEditFunc fcu_cb);
254 
255 /* Calls callback_fn() for each keyframe in each fcurve in the filtered animation context.
256  * Assumes the callback updates keys. */
259  KeyframeEditFunc callback_fn);
260 
261 /* functions for making sure all keyframes are in good order */
263 
264 /* ----------- BezTriple Callback Getters ---------- */
265 
266 /* accessories */
268 
269 /* edit */
277 
278 /* -------- BezTriple Callbacks (Selection Map) ---------- */
279 
280 /* Get a callback to populate the selection settings map
281  * requires: ked->custom = char[] of length fcurve->totvert
282  */
284 
285 /* Change the selection status of the keyframe based on the map entry for this vert
286  * requires: ked->custom = char[] of length fcurve->totvert
287  */
288 short bezt_selmap_flush(KeyframeEditData *ked, struct BezTriple *bezt);
289 
290 /* ----------- BezTriple Callback (Assorted Utilities) ---------- */
291 
292 /* used to calculate the average location of all relevant BezTriples by summing their locations */
293 short bezt_calc_average(KeyframeEditData *ked, struct BezTriple *bezt);
294 
295 /* used to extract a set of cfra-elems from the keyframes */
296 short bezt_to_cfraelem(KeyframeEditData *ked, struct BezTriple *bezt);
297 
298 /* used to remap times from one range to another
299  * requires: ked->custom = KeyframeEditCD_Remap
300  */
301 void bezt_remap_times(KeyframeEditData *ked, struct BezTriple *bezt);
302 
303 /* ------ 1.5-D Region Testing Utilities (Lasso/Circle Select) ------- */
304 /* XXX: These are temporary,
305  * until we can unify GP/Mask Keyframe handling and standard FCurve Keyframe handling */
306 
307 bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const float xy[2]);
308 
309 bool keyframe_region_circle_test(const KeyframeEdit_CircleData *data_circle, const float xy[2]);
310 
311 /* ************************************************ */
312 /* Destructive Editing API (keyframes_general.c) */
313 
314 void delete_fcurve_key(struct FCurve *fcu, int index, bool do_recalc);
315 bool delete_fcurve_keys(struct FCurve *fcu);
316 void clear_fcurve_keys(struct FCurve *fcu);
317 void duplicate_fcurve_keys(struct FCurve *fcu);
318 
319 void clean_fcurve(struct bAnimContext *ac,
320  struct bAnimListElem *ale,
321  float thresh,
322  bool cleardefault);
323 bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max);
324 void smooth_fcurve(struct FCurve *fcu);
325 void sample_fcurve(struct FCurve *fcu);
326 
327 /* ----------- */
328 
329 void ANIM_fcurves_copybuf_free(void);
330 short copy_animedit_keys(struct bAnimContext *ac, ListBase *anim_data);
331 short paste_animedit_keys(struct bAnimContext *ac,
332  ListBase *anim_data,
333  const eKeyPasteOffset offset_mode,
334  const eKeyMergeMode merge_mode,
335  bool flip);
336 
337 /* ************************************************ */
338 
339 #ifdef __cplusplus
340 }
341 #endif
eAnimFilter_Flags
Definition: ED_anim_api.h:287
eEditKeyframes_Mirror
@ MIRROR_KEYS_VALUE
@ MIRROR_KEYS_YAXIS
@ MIRROR_KEYS_MARKER
@ MIRROR_KEYS_CURFRAME
@ MIRROR_KEYS_XAXIS
@ MIRROR_KEYS_TIME
short paste_animedit_keys(struct bAnimContext *ac, ListBase *anim_data, const eKeyPasteOffset offset_mode, const eKeyMergeMode merge_mode, bool flip)
KeyframeEditFunc ANIM_editkeyframes_select(short mode)
void bezt_remap_times(KeyframeEditData *ked, struct BezTriple *bezt)
struct KeyframeEdit_LassoData KeyframeEdit_LassoData
KeyframeEditFunc ANIM_editkeyframes_mirror(short mode)
void ANIM_editkeyframes_refresh(struct bAnimContext *ac)
void clean_fcurve(struct bAnimContext *ac, struct bAnimListElem *ale, float thresh, bool cleardefault)
KeyframeEditFunc ANIM_editkeyframes_keytype(short mode)
void clear_fcurve_keys(struct FCurve *fcu)
short bezt_to_cfraelem(KeyframeEditData *ked, struct BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_easing(short mode)
void(* FcuEditFunc)(struct FCurve *fcu)
KeyframeEditFunc ANIM_editkeyframes_ipo(short mode)
bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const float xy[2])
eKeyMergeMode
@ KEYFRAME_PASTE_MERGE_OVER_RANGE_ALL
@ KEYFRAME_PASTE_MERGE_OVER_RANGE
@ KEYFRAME_PASTE_MERGE_OVER
@ KEYFRAME_PASTE_MERGE_MIX
eKeyframeVertOk
@ KEYFRAME_OK_KEY
@ KEYFRAME_OK_H1
@ KEYFRAME_OK_H2
@ KEYFRAME_OK_ALL
void sample_fcurve(struct FCurve *fcu)
struct KeyframeEditData KeyframeEditData
eKeyPasteOffset
@ KEYFRAME_PASTE_OFFSET_NONE
@ KEYFRAME_PASTE_OFFSET_CFRA_END
@ KEYFRAME_PASTE_OFFSET_CFRA_RELATIVE
@ KEYFRAME_PASTE_OFFSET_CFRA_START
void delete_fcurve_key(struct FCurve *fcu, int index, bool do_recalc)
eEditKeyframes_Validate
@ BEZT_OK_CHANNEL_CIRCLE
@ BEZT_OK_FRAMERANGE
@ BEZT_OK_FRAME
@ BEZT_OK_VALUERANGE
@ BEZT_OK_SELECTED
@ BEZT_OK_REGION_LASSO
@ BEZT_OK_VALUE
@ BEZT_OK_REGION_CIRCLE
@ BEZT_OK_CHANNEL_LASSO
@ BEZT_OK_REGION
short bezt_calc_average(KeyframeEditData *ked, struct BezTriple *bezt)
short copy_animedit_keys(struct bAnimContext *ac, ListBase *anim_data)
void ANIM_animdata_keyframe_callback(struct bAnimContext *ac, eAnimFilter_Flags filter, KeyframeEditFunc callback_fn)
eKeyframeIterFlags
@ KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE
@ KED_F1_NLA_UNMAP
@ KEYFRAME_ITER_INCL_HANDLES
@ KED_F2_NLA_UNMAP
KeyframeEditFunc ANIM_editkeyframes_buildselmap(short mode)
short bezt_selmap_flush(KeyframeEditData *ked, struct BezTriple *bezt)
short(* KeyframeEditFunc)(KeyframeEditData *ked, struct BezTriple *bezt)
eEditKeyframes_Snap
@ SNAP_KEYS_CURFRAME
@ SNAP_KEYS_NEARFRAME
@ SNAP_KEYS_NEARMARKER
@ SNAP_KEYS_TIME
@ SNAP_KEYS_NEARSEC
@ SNAP_KEYS_HORIZONTAL
@ SNAP_KEYS_VALUE
void smooth_fcurve(struct FCurve *fcu)
struct KeyframeEditCD_Remap KeyframeEditCD_Remap
bool keyframe_region_circle_test(const KeyframeEdit_CircleData *data_circle, const float xy[2])
void ANIM_fcurves_copybuf_free(void)
struct KeyframeEdit_CircleData KeyframeEdit_CircleData
eEditKeyframes_SelMap
@ SELMAP_MORE
@ SELMAP_LESS
eEditKeyframes_Select
@ SELECT_INVERT
@ SELECT_SUBTRACT
@ SELECT_REPLACE
@ SELECT_ADD
KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
short ANIM_animchannel_keyframes_loop(KeyframeEditData *ked, struct bDopeSheet *ads, struct bAnimListElem *ale, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
KeyframeEditFunc ANIM_editkeyframes_snap(short mode)
bool delete_fcurve_keys(struct FCurve *fcu)
short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, struct FCurve *fcu, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
short ANIM_animchanneldata_keyframes_loop(KeyframeEditData *ked, struct bDopeSheet *ads, void *data, int keytype, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
void duplicate_fcurve_keys(struct FCurve *fcu)
bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max)
KeyframeEditFunc ANIM_editkeyframes_handles(short mode)
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
struct FCurve * fcu
eKeyframeIterFlags iterflags
struct Scene * scene
eKeyframeVertOk curflags