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 20 /** \file 21 * \ingroup editors 22 */ 23 24 #pragma once 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct AnimData; 31 struct Depsgraph; 32 struct ID; 33 struct ListBase; 34 35 struct ARegion; 36 struct Main; 37 struct ReportList; 38 struct ScrArea; 39 struct SpaceLink; 40 struct View2D; 41 struct bContext; 42 struct wmKeyConfig; 43 44 struct Object; 45 struct Scene; 46 47 struct bDopeSheet; 48 49 struct FCurve; 50 struct FModifier; 51 struct bAction; 52 53 struct uiBlock; 54 struct uiLayout; 55 56 struct PointerRNA; 57 struct PropertyRNA; 58 59 /* ************************************************ */ 60 /* ANIMATION CHANNEL FILTERING */ 61 /* anim_filter.c */ 62 63 /* --------------- Context --------------------- */ 64 65 /* This struct defines a structure used for animation-specific 66 * 'context' information 67 */ 68 typedef struct bAnimContext { 69 /** data to be filtered for use in animation editor */ 70 void *data; 71 /** type of data eAnimCont_Types */ 72 short datatype; 73 74 /** editor->mode */ 75 short mode; 76 /** area->spacetype */ 77 short spacetype; 78 /** active region -> type (channels or main) */ 79 short regiontype; 80 81 /** editor host */ 82 struct ScrArea *area; 83 /** editor data */ 84 struct SpaceLink *sl; 85 /** region within editor */ 86 struct ARegion *region; 87 88 /** dopesheet data for editor (or which is being used) */ 89 struct bDopeSheet *ads; 90 91 /** Current Main */ 92 struct Main *bmain; 93 /** active scene */ 94 struct Scene *scene; 95 /** active scene layer */ 96 struct ViewLayer *view_layer; 97 /** active dependency graph */ 98 struct Depsgraph *depsgraph; 99 /** active object */ 100 struct Object *obact; 101 /** active set of markers */ 102 ListBase *markers; 103 104 /** pointer to current reports list */ 105 struct ReportList *reports; 106 107 /** Scale factor for height of channels (i.e. based on the size of keyframes). */ 108 float yscale_fac; 109 } bAnimContext; 110 111 /* Main Data container types */ 112 typedef enum eAnimCont_Types { 113 ANIMCONT_NONE = 0, /* invalid or no data */ 114 ANIMCONT_ACTION = 1, /* action (bAction) */ 115 ANIMCONT_SHAPEKEY = 2, /* shapekey (Key) */ 116 ANIMCONT_GPENCIL = 3, /* grease pencil (screen) */ 117 ANIMCONT_DOPESHEET = 4, /* dopesheet (bDopesheet) */ 118 ANIMCONT_FCURVES = 5, /* animation F-Curves (bDopesheet) */ 119 ANIMCONT_DRIVERS = 6, /* drivers (bDopesheet) */ 120 ANIMCONT_NLA = 7, /* nla (bDopesheet) */ 121 ANIMCONT_CHANNEL = 8, /* animation channel (bAnimListElem) */ 122 ANIMCONT_MASK = 9, /* mask dopesheet */ 123 ANIMCONT_TIMELINE = 10, /* "timeline" editor (bDopeSheet) */ 124 } eAnimCont_Types; 125 126 /* --------------- Channels -------------------- */ 127 128 /* This struct defines a structure used for quick and uniform access for 129 * channels of animation data 130 */ 131 typedef struct bAnimListElem { 132 struct bAnimListElem *next, *prev; 133 134 /** source data this elem represents */ 135 void *data; 136 /** (eAnim_ChannelType) one of the ANIMTYPE_* values */ 137 int type; 138 /** copy of elem's flags for quick access */ 139 int flag; 140 /** for un-named data, the index of the data in its collection */ 141 int index; 142 143 /** (eAnim_Update_Flags) tag the element for updating */ 144 char update; 145 /** tag the included data. Temporary always */ 146 char tag; 147 148 /** (eAnim_KeyType) type of motion data to expect */ 149 short datatype; 150 /** motion data - mostly F-Curves, but can be other types too */ 151 void *key_data; 152 153 /** 154 * \note 155 * id here is the "IdAdtTemplate"-style datablock (e.g. Object, Material, Texture, NodeTree) 156 * from which evaluation of the RNA-paths takes place. It's used to figure out how deep 157 * channels should be nested (e.g. for Textures/NodeTrees) in the tree, and allows property 158 * lookups (e.g. for sliders and for inserting keyframes) to work. If we had instead used 159 * bAction or something similar, none of this would be possible: although it's trivial 160 * to use an IdAdtTemplate type to find the source action a channel (e.g. F-Curve) comes from 161 * (i.e. in the AnimEditors, it *must* be the active action, as only that can be edited), 162 * it's impossible to go the other way (i.e. one action may be used in multiple places). 163 */ 164 /** ID block that channel is attached to */ 165 struct ID *id; 166 /** source of the animation data attached to ID block (for convenience) */ 167 struct AnimData *adt; 168 169 /** 170 * For list element which corresponds to a f-curve, this is an ID which 171 * owns the f-curve. 172 * 173 * For example, if the f-curve is coming from Action, this id will be set to 174 * action's ID. But if this is a f-curve which is a driver, then the owner 175 * is set to, for example, object. 176 * 177 * Note, that this is different from id above. The id above will be set to 178 * an object if the f-curve is coming from action associated with that 179 * object. */ 180 struct ID *fcurve_owner_id; 181 182 /** 183 * for per-element F-Curves 184 * (e.g. NLA Control Curves), the element that this represents (e.g. NlaStrip) */ 185 void *owner; 186 } bAnimListElem; 187 188 /** 189 * Some types for easier type-testing 190 * 191 * \note need to keep the order of these synchronized with the channels define code 192 * which is used for drawing and handling channel lists for. 193 */ 194 typedef enum eAnim_ChannelType { 195 ANIMTYPE_NONE = 0, 196 ANIMTYPE_ANIMDATA, 197 ANIMTYPE_SPECIALDATA__UNUSED, 198 199 ANIMTYPE_SUMMARY, 200 201 ANIMTYPE_SCENE, 202 ANIMTYPE_OBJECT, 203 ANIMTYPE_GROUP, 204 ANIMTYPE_FCURVE, 205 206 ANIMTYPE_NLACONTROLS, 207 ANIMTYPE_NLACURVE, 208 209 ANIMTYPE_FILLACTD, 210 ANIMTYPE_FILLDRIVERS, 211 212 ANIMTYPE_DSMAT, 213 ANIMTYPE_DSLAM, 214 ANIMTYPE_DSCAM, 215 ANIMTYPE_DSCACHEFILE, 216 ANIMTYPE_DSCUR, 217 ANIMTYPE_DSSKEY, 218 ANIMTYPE_DSWOR, 219 ANIMTYPE_DSNTREE, 220 ANIMTYPE_DSPART, 221 ANIMTYPE_DSMBALL, 222 ANIMTYPE_DSARM, 223 ANIMTYPE_DSMESH, 224 ANIMTYPE_DSTEX, 225 ANIMTYPE_DSLAT, 226 ANIMTYPE_DSLINESTYLE, 227 ANIMTYPE_DSSPK, 228 ANIMTYPE_DSGPENCIL, 229 ANIMTYPE_DSMCLIP, 230 ANIMTYPE_DSHAIR, 231 ANIMTYPE_DSPOINTCLOUD, 232 ANIMTYPE_DSVOLUME, 233 ANIMTYPE_DSSIMULATION, 234 235 ANIMTYPE_SHAPEKEY, 236 237 ANIMTYPE_GPDATABLOCK, 238 ANIMTYPE_GPLAYER, 239 240 ANIMTYPE_MASKDATABLOCK, 241 ANIMTYPE_MASKLAYER, 242 243 ANIMTYPE_NLATRACK, 244 ANIMTYPE_NLAACTION, 245 246 ANIMTYPE_PALETTE, 247 248 /* always as last item, the total number of channel types... */ 249 ANIMTYPE_NUM_TYPES, 250 } eAnim_ChannelType; 251 252 /* types of keyframe data in bAnimListElem */ 253 typedef enum eAnim_KeyType { 254 ALE_NONE = 0, /* no keyframe data */ 255 ALE_FCURVE, /* F-Curve */ 256 ALE_GPFRAME, /* Grease Pencil Frames */ 257 ALE_MASKLAY, /* Mask */ 258 ALE_NLASTRIP, /* NLA Strips */ 259 260 ALE_ALL, /* All channels summary */ 261 ALE_SCE, /* Scene summary */ 262 ALE_OB, /* Object summary */ 263 ALE_ACT, /* Action summary */ 264 ALE_GROUP, /* Action Group summary */ 265 } eAnim_KeyType; 266 267 /* Flags for specifying the types of updates (i.e. recalculation/refreshing) that 268 * needs to be performed to the data contained in a channel following editing. 269 * For use with ANIM_animdata_update() 270 */ 271 typedef enum eAnim_Update_Flags { 272 ANIM_UPDATE_DEPS = (1 << 0), /* referenced data and dependencies get refreshed */ 273 ANIM_UPDATE_ORDER = (1 << 1), /* keyframes need to be sorted */ 274 ANIM_UPDATE_HANDLES = (1 << 2), /* recalculate handles */ 275 } eAnim_Update_Flags; 276 277 /* used for most tools which change keyframes (flushed by ANIM_animdata_update) */ 278 #define ANIM_UPDATE_DEFAULT (ANIM_UPDATE_DEPS | ANIM_UPDATE_ORDER | ANIM_UPDATE_HANDLES) 279 #define ANIM_UPDATE_DEFAULT_NOHANDLES (ANIM_UPDATE_DEFAULT & ~ANIM_UPDATE_HANDLES) 280 281 /* ----------------- Filtering -------------------- */ 282 283 /* filtering flags - under what circumstances should a channel be returned */ 284 typedef enum eAnimFilter_Flags { 285 /** 286 * Data which channel represents is fits the dope-sheet filters 287 * (i.e. scene visibility criteria). 288 * 289 * XXX: it's hard to think of any examples where this *ISN'T* the case... 290 * perhaps becomes implicit?. 291 */ 292 ANIMFILTER_DATA_VISIBLE = (1 << 0), 293 /** channel is visible within the channel-list hierarchy 294 * (i.e. F-Curves within Groups in ActEdit) */ 295 ANIMFILTER_LIST_VISIBLE = (1 << 1), 296 /** channel has specifically been tagged as visible in Graph Editor (* Graph Editor Only) */ 297 ANIMFILTER_CURVE_VISIBLE = (1 << 2), 298 299 /** include summary channels and "expanders" (for drawing/mouse-selection in channel list) */ 300 ANIMFILTER_LIST_CHANNELS = (1 << 3), 301 302 /** for its type, channel should be "active" one */ 303 ANIMFILTER_ACTIVE = (1 << 4), 304 /** channel is a child of the active group (* Actions specialty) */ 305 ANIMFILTER_ACTGROUPED = (1 << 5), 306 307 /** channel must be selected/not-selected, but both must not be set together */ 308 ANIMFILTER_SEL = (1 << 6), 309 ANIMFILTER_UNSEL = (1 << 7), 310 311 /** editability status - must be editable to be included */ 312 ANIMFILTER_FOREDIT = (1 << 8), 313 /** only selected animchannels should be considerable as editable - mainly 314 * for Graph Editor's option for keys on select curves only */ 315 ANIMFILTER_SELEDIT = (1 << 9), 316 317 /** 318 * Flags used to enforce certain data types. 319 * 320 * \note The ones for curves and NLA tracks were redundant and have been removed for now. 321 */ 322 ANIMFILTER_ANIMDATA = (1 << 10), 323 324 /** duplicate entries for animation data attached to multi-user blocks must not occur */ 325 ANIMFILTER_NODUPLIS = (1 << 11), 326 327 /** for checking if we should keep some collapsed channel around (internal use only!) */ 328 ANIMFILTER_TMP_PEEK = (1 << 30), 329 330 /** Ignore ONLYSEL flag from #bDopeSheet.filterflag (internal use only!) */ 331 ANIMFILTER_TMP_IGNORE_ONLYSEL = (1u << 31), 332 } eAnimFilter_Flags; 333 334 /* ---------- Flag Checking Macros ------------ */ 335 /* XXX check on all of these flags again. */ 336 337 /* Dopesheet only */ 338 /* 'Scene' channels */ 339 #define SEL_SCEC(sce) (CHECK_TYPE_INLINE(sce, Scene *), ((sce->flag & SCE_DS_SELECTED))) 340 #define EXPANDED_SCEC(sce) (CHECK_TYPE_INLINE(sce, Scene *), ((sce->flag & SCE_DS_COLLAPSED) == 0)) 341 /* 'Sub-Scene' channels (flags stored in Data block) */ 342 #define FILTER_WOR_SCED(wo) (CHECK_TYPE_INLINE(wo, World *), (wo->flag & WO_DS_EXPAND)) 343 #define FILTER_LS_SCED(linestyle) ((linestyle->flag & LS_DS_EXPAND)) 344 /* 'Object' channels */ 345 #define SEL_OBJC(base) (CHECK_TYPE_INLINE(base, Base *), ((base->flag & SELECT))) 346 #define EXPANDED_OBJC(ob) \ 347 (CHECK_TYPE_INLINE(ob, Object *), (((ob)->nlaflag & OB_ADS_COLLAPSED) == 0)) 348 /* 'Sub-object' channels (flags stored in Data block) */ 349 #define FILTER_SKE_OBJD(key) (CHECK_TYPE_INLINE(key, Key *), ((key->flag & KEY_DS_EXPAND))) 350 #define FILTER_MAT_OBJD(ma) (CHECK_TYPE_INLINE(ma, Material *), ((ma->flag & MA_DS_EXPAND))) 351 #define FILTER_LAM_OBJD(la) (CHECK_TYPE_INLINE(la, Light *), ((la->flag & LA_DS_EXPAND))) 352 #define FILTER_CAM_OBJD(ca) (CHECK_TYPE_INLINE(ca, Camera *), ((ca->flag & CAM_DS_EXPAND))) 353 #define FILTER_CACHEFILE_OBJD(cf) \ 354 (CHECK_TYPE_INLINE(cf, CacheFile *), (((cf)->flag & CACHEFILE_DS_EXPAND))) 355 #define FILTER_CUR_OBJD(cu) (CHECK_TYPE_INLINE(cu, Curve *), ((cu->flag & CU_DS_EXPAND))) 356 #define FILTER_PART_OBJD(part) \ 357 (CHECK_TYPE_INLINE(part, ParticleSettings *), (((part)->flag & PART_DS_EXPAND))) 358 #define FILTER_MBALL_OBJD(mb) (CHECK_TYPE_INLINE(mb, MetaBall *), ((mb->flag2 & MB_DS_EXPAND))) 359 #define FILTER_ARM_OBJD(arm) (CHECK_TYPE_INLINE(arm, bArmature *), ((arm->flag & ARM_DS_EXPAND))) 360 #define FILTER_MESH_OBJD(me) (CHECK_TYPE_INLINE(me, Mesh *), ((me->flag & ME_DS_EXPAND))) 361 #define FILTER_LATTICE_OBJD(lt) (CHECK_TYPE_INLINE(lt, Lattice *), ((lt->flag & LT_DS_EXPAND))) 362 #define FILTER_SPK_OBJD(spk) (CHECK_TYPE_INLINE(spk, Speaker *), ((spk->flag & SPK_DS_EXPAND))) 363 #define FILTER_HAIR_OBJD(ha) (CHECK_TYPE_INLINE(ha, Hair *), ((ha->flag & HA_DS_EXPAND))) 364 #define FILTER_POINTS_OBJD(pt) (CHECK_TYPE_INLINE(pt, PointCloud *), ((pt->flag & PT_DS_EXPAND))) 365 #define FILTER_VOLUME_OBJD(vo) (CHECK_TYPE_INLINE(vo, Volume *), ((vo->flag & VO_DS_EXPAND))) 366 #define FILTER_SIMULATION_OBJD(sim) \ 367 (CHECK_TYPE_INLINE(sim, Simulation *), ((sim->flag & SIM_DS_EXPAND))) 368 /* Variable use expanders */ 369 #define FILTER_NTREE_DATA(ntree) \ 370 (CHECK_TYPE_INLINE(ntree, bNodeTree *), (((ntree)->flag & NTREE_DS_EXPAND))) 371 #define FILTER_TEX_DATA(tex) (CHECK_TYPE_INLINE(tex, Tex *), ((tex->flag & TEX_DS_EXPAND))) 372 373 /* 'Sub-object/Action' channels (flags stored in Action) */ 374 #define SEL_ACTC(actc) ((actc->flag & ACT_SELECTED)) 375 #define EXPANDED_ACTC(actc) ((actc->flag & ACT_COLLAPSED) == 0) 376 /* 'Sub-AnimData' channels */ 377 #define EXPANDED_DRVD(adt) ((adt->flag & ADT_DRIVERS_COLLAPSED) == 0) 378 379 /* Actions (also used for Dopesheet) */ 380 /* Action Channel Group */ 381 #define EDITABLE_AGRP(agrp) (((agrp)->flag & AGRP_PROTECTED) == 0) 382 #define EXPANDED_AGRP(ac, agrp) \ 383 (((!(ac) || ((ac)->spacetype != SPACE_GRAPH)) && ((agrp)->flag & AGRP_EXPANDED)) || \ 384 (((ac) && ((ac)->spacetype == SPACE_GRAPH)) && ((agrp)->flag & AGRP_EXPANDED_G))) 385 #define SEL_AGRP(agrp) (((agrp)->flag & AGRP_SELECTED) || ((agrp)->flag & AGRP_ACTIVE)) 386 /* F-Curve Channels */ 387 #define EDITABLE_FCU(fcu) ((fcu->flag & FCURVE_PROTECTED) == 0) 388 #define SEL_FCU(fcu) (fcu->flag & FCURVE_SELECTED) 389 390 /* ShapeKey mode only */ 391 #define EDITABLE_SHAPEKEY(kb) ((kb->flag & KEYBLOCK_LOCKED) == 0) 392 #define SEL_SHAPEKEY(kb) (kb->flag & KEYBLOCK_SEL) 393 394 /* Grease Pencil only */ 395 /* Grease Pencil datablock settings */ 396 #define EXPANDED_GPD(gpd) (gpd->flag & GP_DATA_EXPAND) 397 /* Grease Pencil Layer settings */ 398 #define EDITABLE_GPL(gpl) ((gpl->flag & GP_LAYER_LOCKED) == 0) 399 #define SEL_GPL(gpl) (gpl->flag & GP_LAYER_SELECT) 400 401 /* Mask Only */ 402 /* Grease Pencil datablock settings */ 403 #define EXPANDED_MASK(mask) (mask->flag & MASK_ANIMF_EXPAND) 404 /* Grease Pencil Layer settings */ 405 #define EDITABLE_MASK(masklay) ((masklay->flag & MASK_LAYERFLAG_LOCKED) == 0) 406 #define SEL_MASKLAY(masklay) (masklay->flag & SELECT) 407 408 /* NLA only */ 409 #define SEL_NLT(nlt) (nlt->flag & NLATRACK_SELECTED) 410 #define EDITABLE_NLT(nlt) ((nlt->flag & NLATRACK_PROTECTED) == 0) 411 412 /* Movie clip only */ 413 #define EXPANDED_MCLIP(clip) (clip->flag & MCLIP_DATA_EXPAND) 414 415 /* Palette only */ 416 #define EXPANDED_PALETTE(palette) (palette->flag & PALETTE_DATA_EXPAND) 417 418 /* AnimData - NLA mostly... */ 419 #define SEL_ANIMDATA(adt) (adt->flag & ADT_UI_SELECTED) 420 421 /* -------------- Channel Defines -------------- */ 422 423 /* channel heights */ 424 #define ACHANNEL_FIRST_TOP(ac) \ 425 (UI_view2d_scale_get_y(&(ac)->region->v2d) * -UI_TIME_SCRUB_MARGIN_Y - ACHANNEL_SKIP) 426 #define ACHANNEL_HEIGHT(ac) (0.8f * (ac)->yscale_fac * U.widget_unit) 427 #define ACHANNEL_SKIP (0.1f * U.widget_unit) 428 #define ACHANNEL_STEP(ac) (ACHANNEL_HEIGHT(ac) + ACHANNEL_SKIP) 429 /* Additional offset to give some room at the end. */ 430 #define ACHANNEL_TOT_HEIGHT(ac, item_amount) \ 431 (-ACHANNEL_FIRST_TOP(ac) + ACHANNEL_STEP(ac) * (item_amount + 1)) 432 433 /* channel widths */ 434 #define ACHANNEL_NAMEWIDTH (10 * U.widget_unit) 435 436 /* channel toggle-buttons */ 437 #define ACHANNEL_BUTTON_WIDTH (0.8f * U.widget_unit) 438 439 /* -------------- NLA Channel Defines -------------- */ 440 441 /* NLA channel heights */ 442 #define NLACHANNEL_FIRST_TOP(ac) \ 443 (UI_view2d_scale_get_y(&(ac)->region->v2d) * -UI_TIME_SCRUB_MARGIN_Y - NLACHANNEL_SKIP) 444 #define NLACHANNEL_HEIGHT(snla) \ 445 (((snla) && ((snla)->flag & SNLA_NOSTRIPCURVES)) ? (0.8f * U.widget_unit) : \ 446 (1.2f * U.widget_unit)) 447 #define NLACHANNEL_SKIP (0.1f * U.widget_unit) 448 #define NLACHANNEL_STEP(snla) (NLACHANNEL_HEIGHT(snla) + NLACHANNEL_SKIP) 449 /* Additional offset to give some room at the end. */ 450 #define NLACHANNEL_TOT_HEIGHT(ac, item_amount) \ 451 (-NLACHANNEL_FIRST_TOP(ac) + NLACHANNEL_STEP(((SpaceNla *)(ac)->sl)) * (item_amount + 1)) 452 453 /* channel widths */ 454 #define NLACHANNEL_NAMEWIDTH (10 * U.widget_unit) 455 456 /* channel toggle-buttons */ 457 #define NLACHANNEL_BUTTON_WIDTH (0.8f * U.widget_unit) 458 459 /* ---------------- API -------------------- */ 460 461 /* Obtain list of filtered Animation channels to operate on. 462 * Returns the number of channels in the list 463 */ 464 size_t ANIM_animdata_filter(bAnimContext *ac, 465 ListBase *anim_data, 466 eAnimFilter_Flags filter_mode, 467 void *data, 468 eAnimCont_Types datatype); 469 470 /* Obtain current anim-data context from Blender Context info. 471 * Returns whether the operation was successful. 472 */ 473 bool ANIM_animdata_get_context(const struct bContext *C, bAnimContext *ac); 474 475 /* Obtain current anim-data context (from Animation Editor) given 476 * that Blender Context info has already been set. 477 * Returns whether the operation was successful. 478 */ 479 bool ANIM_animdata_context_getdata(bAnimContext *ac); 480 481 /* Acts on bAnimListElem eAnim_Update_Flags */ 482 void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data); 483 484 void ANIM_animdata_freelist(ListBase *anim_data); 485 486 /* ************************************************ */ 487 /* ANIMATION CHANNELS LIST */ 488 /* anim_channels_*.c */ 489 490 /* ------------------------ Drawing TypeInfo -------------------------- */ 491 492 /* role or level of animchannel in the hierarchy */ 493 typedef enum eAnimChannel_Role { 494 /** datablock expander - a "composite" channel type */ 495 ACHANNEL_ROLE_EXPANDER = -1, 496 /** special purposes - not generally for hierarchy processing */ 497 /* ACHANNEL_ROLE_SPECIAL = 0, */ /* UNUSED */ 498 /** data channel - a channel representing one of the actual building blocks of channels */ 499 ACHANNEL_ROLE_CHANNEL = 1, 500 } eAnimChannel_Role; 501 502 /* flag-setting behavior */ 503 typedef enum eAnimChannels_SetFlag { 504 /** turn off */ 505 ACHANNEL_SETFLAG_CLEAR = 0, 506 /** turn on */ 507 ACHANNEL_SETFLAG_ADD = 1, 508 /** on->off, off->on */ 509 ACHANNEL_SETFLAG_INVERT = 2, 510 /** some on -> all off / all on */ 511 ACHANNEL_SETFLAG_TOGGLE = 3, 512 } eAnimChannels_SetFlag; 513 514 /* types of settings for AnimChannels */ 515 typedef enum eAnimChannel_Settings { 516 ACHANNEL_SETTING_SELECT = 0, 517 /** warning: for drawing UI's, need to check if this is off (maybe inverse this later) */ 518 ACHANNEL_SETTING_PROTECT = 1, 519 ACHANNEL_SETTING_MUTE = 2, 520 ACHANNEL_SETTING_EXPAND = 3, 521 /** only for Graph Editor */ 522 ACHANNEL_SETTING_VISIBLE = 4, 523 /** only for NLA Tracks */ 524 ACHANNEL_SETTING_SOLO = 5, 525 /** only for NLA Actions */ 526 ACHANNEL_SETTING_PINNED = 6, 527 ACHANNEL_SETTING_MOD_OFF = 7, 528 /** channel is pinned and always visible */ 529 ACHANNEL_SETTING_ALWAYS_VISIBLE = 8, 530 } eAnimChannel_Settings; 531 532 /* Drawing, mouse handling, and flag setting behavior... */ 533 typedef struct bAnimChannelType { 534 /* -- Type data -- */ 535 /* name of the channel type, for debugging */ 536 const char *channel_type_name; 537 /* "level" or role in hierarchy - for finding the active channel */ 538 eAnimChannel_Role channel_role; 539 540 /* -- Drawing -- */ 541 /* get RGB color that is used to draw the majority of the backdrop */ 542 void (*get_backdrop_color)(bAnimContext *ac, bAnimListElem *ale, float r_color[3]); 543 /* draw backdrop strip for channel */ 544 void (*draw_backdrop)(bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc); 545 /* get depth of indention (relative to the depth channel is nested at) */ 546 short (*get_indent_level)(bAnimContext *ac, bAnimListElem *ale); 547 /* get offset in pixels for the start of the channel (in addition to the indent depth) */ 548 short (*get_offset)(bAnimContext *ac, bAnimListElem *ale); 549 550 /* get name (for channel lists) */ 551 void (*name)(bAnimListElem *ale, char *name); 552 /* get RNA property+pointer for editing the name */ 553 bool (*name_prop)(bAnimListElem *ale, struct PointerRNA *ptr, struct PropertyRNA **prop); 554 /* get icon (for channel lists) */ 555 int (*icon)(bAnimListElem *ale); 556 557 /* -- Settings -- */ 558 /* check if the given setting is valid in the current context */ 559 bool (*has_setting)(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting); 560 /* get the flag used for this setting */ 561 int (*setting_flag)(bAnimContext *ac, eAnimChannel_Settings setting, bool *neg); 562 /* get the pointer to int/short where data is stored, 563 * with type being sizeof(ptr_data) which should be fine for runtime use... 564 * - assume that setting has been checked to be valid for current context 565 */ 566 void *(*setting_ptr)(bAnimListElem *ale, eAnimChannel_Settings setting, short *type); 567 } bAnimChannelType; 568 569 /* ------------------------ Drawing API -------------------------- */ 570 571 /* Get typeinfo for the given channel */ 572 const bAnimChannelType *ANIM_channel_get_typeinfo(bAnimListElem *ale); 573 574 /* Print debugging info about a given channel */ 575 void ANIM_channel_debug_print_info(bAnimListElem *ale, short indent_level); 576 577 /* Draw the given channel */ 578 void ANIM_channel_draw( 579 bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc, size_t channel_index); 580 /* Draw the widgets for the given channel */ 581 void ANIM_channel_draw_widgets(const struct bContext *C, 582 bAnimContext *ac, 583 bAnimListElem *ale, 584 struct uiBlock *block, 585 rctf *rect, 586 size_t channel_index); 587 588 /* ------------------------ Editing API -------------------------- */ 589 590 /* Check if some setting for a channel is enabled 591 * Returns: 1 = On, 0 = Off, -1 = Invalid 592 * 593 * - setting: eAnimChannel_Settings 594 */ 595 short ANIM_channel_setting_get(bAnimContext *ac, 596 bAnimListElem *ale, 597 eAnimChannel_Settings setting); 598 599 /* Change value of some setting for a channel 600 * - setting: eAnimChannel_Settings 601 * - mode: eAnimChannels_SetFlag 602 */ 603 void ANIM_channel_setting_set(bAnimContext *ac, 604 bAnimListElem *ale, 605 eAnimChannel_Settings setting, 606 eAnimChannels_SetFlag mode); 607 608 /* Flush visibility (for Graph Editor) changes up/down hierarchy for changes in the given setting 609 * - anim_data: list of the all the anim channels that can be chosen 610 * -> filtered using ANIMFILTER_CHANNELS only, since if we took VISIBLE too, 611 * then the channels under closed expanders get ignored... 612 * - ale_setting: the anim channel (not in the anim_data list directly, though occurring there) 613 * with the new state of the setting that we want flushed up/down the hierarchy 614 * - setting: type of setting to set 615 * - on: whether the visibility setting has been enabled or disabled 616 */ 617 void ANIM_flush_setting_anim_channels(bAnimContext *ac, 618 ListBase *anim_data, 619 bAnimListElem *ale_setting, 620 eAnimChannel_Settings setting, 621 eAnimChannels_SetFlag mode); 622 623 /* Select or deselect animation channels */ 624 void ANIM_anim_channels_select_set(bAnimContext *ac, eAnimChannels_SetFlag sel); 625 626 /* Toggle selection of animation channels */ 627 void ANIM_anim_channels_select_toggle(bAnimContext *ac); 628 629 /* Set the 'active' channel of type channel_type, in the given action */ 630 void ANIM_set_active_channel(bAnimContext *ac, 631 void *data, 632 eAnimCont_Types datatype, 633 eAnimFilter_Flags filter, 634 void *channel_data, 635 eAnim_ChannelType channel_type); 636 637 /* Delete the F-Curve from the given AnimData block (if possible), 638 * as appropriate according to animation context */ 639 void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, struct AnimData *adt, struct FCurve *fcu); 640 641 /* Unlink the action from animdata if it's empty. */ 642 bool ANIM_remove_empty_action_from_animdata(struct AnimData *adt); 643 644 /* ************************************************ */ 645 /* DRAWING API */ 646 /* anim_draw.c */ 647 648 /* ---------- Current Frame Drawing ---------------- */ 649 650 /* flags for Current Frame Drawing */ 651 typedef enum eAnimEditDraw_CurrentFrame { 652 /* plain time indicator with no special indicators */ 653 /* DRAWCFRA_PLAIN = 0, */ /* UNUSED */ 654 /* time indication in seconds or frames */ 655 DRAWCFRA_UNIT_SECONDS = (1 << 0), 656 /* draw indicator extra wide (for timeline) */ 657 DRAWCFRA_WIDE = (1 << 1), 658 } eAnimEditDraw_CurrentFrame; 659 660 /* main call to draw current-frame indicator in an Animation Editor */ 661 void ANIM_draw_cfra(const struct bContext *C, struct View2D *v2d, short flag); 662 663 /* ------------- Preview Range Drawing -------------- */ 664 665 /* main call to draw preview range curtains */ 666 void ANIM_draw_previewrange(const struct bContext *C, struct View2D *v2d, int end_frame_width); 667 668 /* -------------- Frame Range Drawing --------------- */ 669 670 /* main call to draw normal frame range indicators */ 671 void ANIM_draw_framerange(struct Scene *scene, struct View2D *v2d); 672 673 /* ************************************************* */ 674 /* F-MODIFIER TOOLS */ 675 676 /* ------------- UI Panel Drawing -------------- */ 677 678 /* draw a given F-Modifier for some layout/UI-Block */ 679 void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, 680 struct ID *fcurve_owner_id, 681 ListBase *modifiers, 682 struct FModifier *fcm); 683 684 /* ------------- Copy/Paste Buffer -------------- */ 685 686 /* free the copy/paste buffer */ 687 void ANIM_fmodifiers_copybuf_free(void); 688 689 /* copy the given F-Modifiers to the buffer, returning whether anything was copied or not 690 * assuming that the buffer has been cleared already with ANIM_fmodifiers_copybuf_free() 691 * - active: only copy the active modifier 692 */ 693 bool ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, bool active); 694 695 /* 'Paste' the F-Modifier(s) from the buffer to the specified list 696 * - replace: free all the existing modifiers to leave only the pasted ones 697 */ 698 bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, struct FCurve *curve); 699 700 /* ************************************************* */ 701 /* ASSORTED TOOLS */ 702 703 /* ------------ Animation F-Curves <-> Icons/Names Mapping ------------ */ 704 /* anim_ipo_utils.c */ 705 706 /* Get icon + name for channel-list displays for F-Curve */ 707 int getname_anim_fcurve(char *name, struct ID *id, struct FCurve *fcu); 708 709 /* Automatically determine a color for the nth F-Curve */ 710 void getcolor_fcurve_rainbow(int cur, int tot, float out[3]); 711 712 /* ----------------- NLA Drawing ----------------------- */ 713 /* NOTE: Technically, this is not in the animation module (it's in space_nla) 714 * but these are sometimes needed by various animation API's. 715 */ 716 717 /* Get color to use for NLA Action channel's background */ 718 void nla_action_get_color(struct AnimData *adt, struct bAction *act, float color[4]); 719 720 /* ----------------- NLA-Mapping ----------------------- */ 721 /* anim_draw.c */ 722 723 /* Obtain the AnimData block providing NLA-scaling for the given channel if applicable */ 724 struct AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale); 725 726 /* Apply/Unapply NLA mapping to all keyframes in the nominated F-Curve */ 727 void ANIM_nla_mapping_apply_fcurve(struct AnimData *adt, 728 struct FCurve *fcu, 729 bool restore, 730 bool only_keys); 731 732 /* ..... */ 733 734 /* Perform auto-blending/extend refreshes after some operations */ 735 /* NOTE: defined in space_nla/nla_edit.c, not in animation/ */ 736 void ED_nla_postop_refresh(bAnimContext *ac); 737 738 /* ------------- Unit Conversion Mappings ------------- */ 739 /* anim_draw.c */ 740 741 /* flags for conversion mapping */ 742 typedef enum eAnimUnitConv_Flags { 743 /* restore to original internal values */ 744 ANIM_UNITCONV_RESTORE = (1 << 0), 745 /* ignore handles (i.e. only touch main keyframes) */ 746 ANIM_UNITCONV_ONLYKEYS = (1 << 1), 747 /* only touch selected BezTriples */ 748 ANIM_UNITCONV_ONLYSEL = (1 << 2), 749 /* only touch selected vertices */ 750 ANIM_UNITCONV_SELVERTS = (1 << 3), 751 /* ANIM_UNITCONV_SKIPKNOTS = (1 << 4), */ /* UNUSED */ 752 /* Scale FCurve i a way it fits to -1..1 space */ 753 ANIM_UNITCONV_NORMALIZE = (1 << 5), 754 /* Only when normalization is used: use scale factor from previous run, 755 * prevents curves from jumping all over the place when tweaking them. 756 */ 757 ANIM_UNITCONV_NORMALIZE_FREEZE = (1 << 6), 758 } eAnimUnitConv_Flags; 759 760 /* Normalization flags from Space Graph passing to ANIM_unit_mapping_get_factor */ 761 short ANIM_get_normalization_flags(bAnimContext *ac); 762 763 /* Get unit conversion factor for given ID + F-Curve */ 764 float ANIM_unit_mapping_get_factor( 765 struct Scene *scene, struct ID *id, struct FCurve *fcu, short flag, float *r_offset); 766 767 /* ------------- Utility macros ----------------------- */ 768 769 /* provide access to Keyframe Type info in BezTriple 770 * NOTE: this is so that we can change it from being stored in 'hide' 771 */ 772 #define BEZKEYTYPE(bezt) ((bezt)->hide) 773 774 /* set/clear/toggle macro 775 * - channel - channel with a 'flag' member that we're setting 776 * - smode - 0=clear, 1=set, 2=invert 777 * - sflag - bitflag to set 778 */ 779 #define ACHANNEL_SET_FLAG(channel, smode, sflag) \ 780 { \ 781 if (smode == ACHANNEL_SETFLAG_INVERT) { \ 782 (channel)->flag ^= (sflag); \ 783 } \ 784 else if (smode == ACHANNEL_SETFLAG_ADD) { \ 785 (channel)->flag |= (sflag); \ 786 } \ 787 else { \ 788 (channel)->flag &= ~(sflag); \ 789 } \ 790 } \ 791 ((void)0) 792 793 /* set/clear/toggle macro, where the flag is negative 794 * - channel - channel with a 'flag' member that we're setting 795 * - smode - 0=clear, 1=set, 2=invert 796 * - sflag - bitflag to set 797 */ 798 #define ACHANNEL_SET_FLAG_NEG(channel, smode, sflag) \ 799 { \ 800 if (smode == ACHANNEL_SETFLAG_INVERT) { \ 801 (channel)->flag ^= (sflag); \ 802 } \ 803 else if (smode == ACHANNEL_SETFLAG_ADD) { \ 804 (channel)->flag &= ~(sflag); \ 805 } \ 806 else { \ 807 (channel)->flag |= (sflag); \ 808 } \ 809 } \ 810 ((void)0) 811 812 /* --------- anim_deps.c, animation updates -------- */ 813 814 void ANIM_id_update(struct Main *bmain, struct ID *id); 815 void ANIM_list_elem_update(struct Main *bmain, struct Scene *scene, bAnimListElem *ale); 816 817 /* data -> channels syncing */ 818 void ANIM_sync_animchannels_to_data(const struct bContext *C); 819 820 void ANIM_center_frame(struct bContext *C, int smooth_viewtx); 821 822 /* ************************************************* */ 823 /* OPERATORS */ 824 825 /* generic animation channels */ 826 void ED_operatortypes_animchannels(void); 827 void ED_keymap_animchannels(struct wmKeyConfig *keyconf); 828 829 /* generic time editing */ 830 void ED_operatortypes_anim(void); 831 void ED_keymap_anim(struct wmKeyConfig *keyconf); 832 833 /* space_graph */ 834 void ED_operatormacros_graph(void); 835 /* space_action */ 836 void ED_operatormacros_action(void); 837 838 /* ************************************************ */ 839 /* Animation Editor Exports */ 840 /* XXX: Should we be doing these here, or at all? */ 841 842 /* Action Editor - Action Management */ 843 struct AnimData *ED_actedit_animdata_from_context(struct bContext *C); 844 void ED_animedit_unlink_action(struct bContext *C, 845 struct ID *id, 846 struct AnimData *adt, 847 struct bAction *act, 848 struct ReportList *reports, 849 bool force_delete); 850 851 /* Drivers Editor - Utility to set up UI correctly */ 852 void ED_drivers_editor_init(struct bContext *C, struct ScrArea *area); 853 854 /* ************************************************ */ 855 856 typedef enum eAnimvizCalcRange { 857 /* Update motion paths at the current frame only. */ 858 ANIMVIZ_CALC_RANGE_CURRENT_FRAME, 859 860 /* Try to limit updates to a close neighborhood of the current frame. */ 861 ANIMVIZ_CALC_RANGE_CHANGED, 862 863 /* Update an entire range of the motion paths. */ 864 ANIMVIZ_CALC_RANGE_FULL, 865 } eAnimvizCalcRange; 866 867 struct Depsgraph *animviz_depsgraph_build(struct Main *bmain, 868 struct Scene *scene, 869 struct ViewLayer *view_layer, 870 struct ListBase *targets); 871 872 void animviz_calc_motionpaths(struct Depsgraph *depsgraph, 873 struct Main *bmain, 874 struct Scene *scene, 875 ListBase *targets, 876 eAnimvizCalcRange range, 877 bool restore); 878 879 void animviz_get_object_motionpaths(struct Object *ob, ListBase *targets); 880 881 #ifdef __cplusplus 882 } 883 #endif 884