From 73ef27f15611ccb254816e199f8c74103b3d5172 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Mar 2020 16:45:56 +1100 Subject: Cleanup: keyframing return arguments - Use 'int' for counters instead of short. - Use 'bool' instead of a counter when only a change is being detected. - Use typed enum for keying set flags. - Include in comments when a negate error code may be returned. --- .../editors/animation/anim_channels_defines.c | 14 +-- source/blender/editors/animation/drivers.c | 31 ++--- source/blender/editors/animation/keyframing.c | 126 +++++++++++---------- source/blender/editors/animation/keyingsets.c | 62 +++++----- source/blender/editors/include/ED_keyframing.h | 44 +++---- source/blender/editors/space_action/action_edit.c | 6 +- source/blender/editors/space_graph/graph_edit.c | 6 +- .../blender/editors/transform/transform_convert.c | 10 +- 8 files changed, 160 insertions(+), 139 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 1af5721bffd..95165e35fd9 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -4357,7 +4357,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi ListBase nla_cache = {NULL, NULL}; PointerRNA id_ptr, ptr; PropertyRNA *prop; - short flag = 0; + eInsertKeyFlags flag = 0; bool done = false; float cfra; @@ -4371,8 +4371,8 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi /* get current frame and apply NLA-mapping to it (if applicable) */ cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - /* get flags for keyframing */ - flag = ANIM_get_keyframing_flags(scene, 1); + /* Get flags for keyframing. */ + flag = ANIM_get_keyframing_flags(scene, true); /* try to resolve the path stored in the F-Curve */ if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) { @@ -4411,7 +4411,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi ListBase nla_cache = {NULL, NULL}; PointerRNA id_ptr, ptr; PropertyRNA *prop; - short flag = 0; + eInsertKeyFlags flag = 0; bool done = false; float cfra; @@ -4426,7 +4426,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi cfra = BKE_nla_tweakedit_remap(key->adt, (float)CFRA, NLATIME_CONVERT_UNMAP); /* get flags for keyframing */ - flag = ANIM_get_keyframing_flags(scene, 1); + flag = ANIM_get_keyframing_flags(scene, true); /* try to resolve the path stored in the F-Curve */ if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) { @@ -4472,7 +4472,7 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; - short flag = 0; + eInsertKeyFlags flag = 0; bool done = false; float cfra; @@ -4480,7 +4480,7 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, cfra = (float)CFRA; /* get flags for keyframing */ - flag = ANIM_get_keyframing_flags(scene, 1); + flag = ANIM_get_keyframing_flags(scene, true); /* Get pointer and property from the slider - * this should all match up with the NlaStrip required. */ diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index 64f7fe034dc..1af85e00045 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -421,7 +421,8 @@ int ANIM_add_driver_with_target(ReportList *reports, /* --------------------------------- */ -/* Main Driver Management API calls: +/** + * Main Driver Management API calls: * Add a new driver for the specified property on the given ID block */ int ANIM_add_driver( @@ -1098,15 +1099,15 @@ static int add_driver_button_invoke(bContext *C, wmOperator *op, const wmEvent * /* 1) Create a new "empty" driver for this property */ char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); short flags = CREATEDRIVER_WITH_DEFAULT_DVAR; - short success = 0; + bool changed = false; if (path) { - success += ANIM_add_driver( - op->reports, ptr.owner_id, path, index, flags, DRIVER_TYPE_PYTHON); + changed |= (ANIM_add_driver( + op->reports, ptr.owner_id, path, index, flags, DRIVER_TYPE_PYTHON) != 0); MEM_freeN(path); } - if (success) { + if (changed) { /* send updates */ UI_context_update_anim_flag(C); DEG_id_tag_update(ptr.owner_id, ID_RECALC_COPY_ON_WRITE); @@ -1144,7 +1145,7 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr = {NULL}; PropertyRNA *prop = NULL; - short success = 0; + bool changed = false; int index; const bool all = RNA_boolean_get(op->ptr, "all"); @@ -1159,20 +1160,20 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op) char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); if (path) { - success = ANIM_remove_driver(op->reports, ptr.owner_id, path, index, 0); + changed = ANIM_remove_driver(op->reports, ptr.owner_id, path, index, 0); MEM_freeN(path); } } - if (success) { + if (changed) { /* send updates */ UI_context_update_anim_flag(C); DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_driver_button_remove(wmOperatorType *ot) @@ -1234,7 +1235,7 @@ static int copy_driver_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr = {NULL}; PropertyRNA *prop = NULL; - short success = 0; + bool changed = false; int index; /* try to create driver using property retrieved from UI */ @@ -1245,7 +1246,7 @@ static int copy_driver_button_exec(bContext *C, wmOperator *op) if (path) { /* only copy the driver for the button that this was involved for */ - success = ANIM_copy_driver(op->reports, ptr.owner_id, path, index, 0); + changed = ANIM_copy_driver(op->reports, ptr.owner_id, path, index, 0); UI_context_update_anim_flag(C); @@ -1254,7 +1255,7 @@ static int copy_driver_button_exec(bContext *C, wmOperator *op) } /* since we're just copying, we don't really need to do anything else...*/ - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_copy_driver_button(wmOperatorType *ot) @@ -1278,7 +1279,7 @@ static int paste_driver_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr = {NULL}; PropertyRNA *prop = NULL; - short success = 0; + bool changed = false; int index; /* try to create driver using property retrieved from UI */ @@ -1289,7 +1290,7 @@ static int paste_driver_button_exec(bContext *C, wmOperator *op) if (path) { /* only copy the driver for the button that this was involved for */ - success = ANIM_paste_driver(op->reports, ptr.owner_id, path, index, 0); + changed = ANIM_paste_driver(op->reports, ptr.owner_id, path, index, 0); UI_context_update_anim_flag(C); @@ -1304,7 +1305,7 @@ static int paste_driver_button_exec(bContext *C, wmOperator *op) } /* since we're just copying, we don't really need to do anything else...*/ - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_paste_driver_button(wmOperatorType *ot) diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index c8ef4fe2965..c80cfd77cf4 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -87,7 +87,7 @@ static KeyingSet *keyingset_get_from_op_with_error(wmOperator *op, /* Keyframing Setting Wrangling */ /* Get the active settings for keyframing settings from context (specifically the given scene) */ -short ANIM_get_keyframing_flags(Scene *scene, short incl_mode) +eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_mode) { eInsertKeyFlags flag = INSERTKEY_NOFLAGS; @@ -110,7 +110,7 @@ short ANIM_get_keyframing_flags(Scene *scene, short incl_mode) } /* only if including settings from the autokeying mode... */ - if (incl_mode) { + if (use_autokey_mode) { /* keyframing mode - only replace existing keyframes */ if (IS_AUTOKEY_MODE(scene, EDITKEYS)) { flag |= INSERTKEY_REPLACE; @@ -1328,7 +1328,9 @@ static bool insert_keyframe_fcurve_value(Main *bmain, } } -/* Main Keyframing API call: +/** + * Main Keyframing API call + * * Use this when validation of necessary animation data is necessary, since it may not exist yet. * * The flag argument is used for special settings that alter the behavior of @@ -1336,18 +1338,20 @@ static bool insert_keyframe_fcurve_value(Main *bmain, * and extra keyframe filtering. * * index of -1 keys all array indices + * + * \return The number of key-frames inserted. */ -short insert_keyframe(Main *bmain, - ReportList *reports, - ID *id, - bAction *act, - const char group[], - const char rna_path[], - int array_index, - float cfra, - eBezTriple_KeyframeType keytype, - ListBase *nla_cache, - eInsertKeyFlags flag) +int insert_keyframe(Main *bmain, + ReportList *reports, + ID *id, + bAction *act, + const char group[], + const char rna_path[], + int array_index, + float cfra, + eBezTriple_KeyframeType keytype, + ListBase *nla_cache, + eInsertKeyFlags flag) { PointerRNA id_ptr, ptr; PropertyRNA *prop = NULL; @@ -1570,13 +1574,16 @@ static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt) } } -short delete_keyframe(Main *bmain, - ReportList *reports, - ID *id, - bAction *act, - const char rna_path[], - int array_index, - float cfra) +/** + * \return The number of key-frames deleted. + */ +int delete_keyframe(Main *bmain, + ReportList *reports, + ID *id, + bAction *act, + const char rna_path[], + int array_index, + float cfra) { AnimData *adt = BKE_animdata_from_id(id); PointerRNA id_ptr, ptr; @@ -1667,20 +1674,23 @@ short delete_keyframe(Main *bmain, /* ************************************************** */ /* KEYFRAME CLEAR */ -/* Main Keyframing API call: +/** + * Main Keyframing API call: * Use this when validation of necessary animation data isn't necessary as it * already exists. It will clear the current buttons fcurve(s). * * The flag argument is used for special settings that alter the behavior of * the keyframe deletion. These include the quick refresh options. + * + * \return The number of f-curves removed. */ -static short clear_keyframe(Main *bmain, - ReportList *reports, - ID *id, - bAction *act, - const char rna_path[], - int array_index, - eInsertKeyFlags UNUSED(flag)) +static int clear_keyframe(Main *bmain, + ReportList *reports, + ID *id, + bAction *act, + const char rna_path[], + int array_index, + eInsertKeyFlags UNUSED(flag)) { AnimData *adt = BKE_animdata_from_id(id); PointerRNA id_ptr, ptr; @@ -1804,7 +1814,7 @@ static int insert_key_exec(bContext *C, wmOperator *op) bool ob_edit_mode = false; float cfra = (float)CFRA; // XXX for now, don't bother about all the yucky offset crap - short success; + int success; KeyingSet *ks = keyingset_get_from_op_with_error(op, op->type->prop, scene); if (ks == NULL) { @@ -2008,7 +2018,7 @@ static int delete_key_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); float cfra = (float)CFRA; // XXX for now, don't bother about all the yucky offset crap - short success; + int success; KeyingSet *ks = keyingset_get_from_op_with_error(op, op->type->prop, scene); if (ks == NULL) { @@ -2367,13 +2377,13 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) char *path; uiBut *but; float cfra = (float)CFRA; - short success = 0; + bool changed = false; int index; const bool all = RNA_boolean_get(op->ptr, "all"); eInsertKeyFlags flag = INSERTKEY_NOFLAGS; /* flags for inserting keyframes */ - flag = ANIM_get_keyframing_flags(scene, 1); + flag = ANIM_get_keyframing_flags(scene, true); /* try to insert keyframe using property retrieved from UI */ if (!(but = UI_context_active_but_prop_get(C, &ptr, &prop, &index))) { @@ -2391,7 +2401,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) FCurve *fcu = list_find_fcurve(&strip->fcurves, RNA_property_identifier(prop), index); if (fcu) { - success = insert_keyframe_direct( + changed = insert_keyframe_direct( op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0); } else { @@ -2408,7 +2418,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) fcu = rna_get_fcurve_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special); if (fcu && driven) { - success = insert_keyframe_direct( + changed = insert_keyframe_direct( op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, INSERTKEY_DRIVER); } } @@ -2445,17 +2455,17 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) index = -1; } - success = insert_keyframe(bmain, - op->reports, - ptr.owner_id, - NULL, - group, - path, - index, - cfra, - ts->keyframe_type, - NULL, - flag); + changed = (insert_keyframe(bmain, + op->reports, + ptr.owner_id, + NULL, + group, + path, + index, + cfra, + ts->keyframe_type, + NULL, + flag) != 0); MEM_freeN(path); } @@ -2484,7 +2494,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) } } - if (success) { + if (changed) { ID *id = ptr.owner_id; AnimData *adt = BKE_animdata_from_id(id); if (adt->action != NULL) { @@ -2499,7 +2509,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL); } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_keyframe_insert_button(wmOperatorType *ot) @@ -2530,7 +2540,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); char *path; float cfra = (float)CFRA; // XXX for now, don't bother about all the yucky offset crap - short success = 0; + bool changed = false; int index; const bool all = RNA_boolean_get(op->ptr, "all"); @@ -2573,7 +2583,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) if (found) { /* delete the key at the index (will sanity check + do recalc afterwards) */ delete_fcurve_key(fcu, i, 1); - success = true; + changed = true; } } } @@ -2588,7 +2598,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) index = -1; } - success = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra); + changed = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra) != 0; MEM_freeN(path); } else if (G.debug & G_DEBUG) { @@ -2600,7 +2610,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop); } - if (success) { + if (changed) { /* send updates */ UI_context_update_anim_flag(C); @@ -2608,7 +2618,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_keyframe_delete_button(wmOperatorType *ot) @@ -2637,7 +2647,7 @@ static int clear_key_button_exec(bContext *C, wmOperator *op) PropertyRNA *prop = NULL; Main *bmain = CTX_data_main(C); char *path; - short success = 0; + bool changed = false; int index; const bool all = RNA_boolean_get(op->ptr, "all"); @@ -2656,7 +2666,7 @@ static int clear_key_button_exec(bContext *C, wmOperator *op) index = -1; } - success += clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, 0); + changed |= (clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, 0) != 0); MEM_freeN(path); } else if (G.debug & G_DEBUG) { @@ -2667,7 +2677,7 @@ static int clear_key_button_exec(bContext *C, wmOperator *op) printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop); } - if (success) { + if (changed) { /* send updates */ UI_context_update_anim_flag(C); @@ -2675,7 +2685,7 @@ static int clear_key_button_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_keyframe_clear_button(wmOperatorType *ot) @@ -3025,7 +3035,7 @@ bool ED_autokeyframe_property( if (autokeyframe_cfra_can_key(scene, id)) { ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; - short flag = ANIM_get_keyframing_flags(scene, 1); + const eInsertKeyFlags flag = ANIM_get_keyframing_flags(scene, true); /* Note: We use rnaindex instead of fcu->array_index, * because a button may control all items of an array at once. diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 6b33c100a8f..d2e542772c2 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -109,7 +109,8 @@ static bool keyingset_poll_activePath_edit(bContext *C) static int add_default_keyingset_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - short flag = 0, keyingflag = 0; + eKS_Settings flag = 0; + eInsertKeyFlags keyingflag = 0; /* validate flags * - absolute KeyingSets should be created by default @@ -117,7 +118,7 @@ static int add_default_keyingset_exec(bContext *C, wmOperator *UNUSED(op)) flag |= KEYINGSET_ABSOLUTE; /* 2nd arg is 0 to indicate that we don't want to include autokeying mode related settings */ - keyingflag = ANIM_get_keyframing_flags(scene, 0); + keyingflag = ANIM_get_keyframing_flags(scene, false); /* call the API func, and set the active keyingset index */ BKE_keyingset_add(&scene->keyingsets, NULL, NULL, flag, keyingflag); @@ -289,7 +290,7 @@ static int add_keyingset_button_exec(bContext *C, wmOperator *op) PropertyRNA *prop = NULL; PointerRNA ptr = {NULL}; char *path = NULL; - short success = 0; + bool changed = false; int index = 0, pflag = 0; const bool all = RNA_boolean_get(op->ptr, "all"); @@ -304,14 +305,15 @@ static int add_keyingset_button_exec(bContext *C, wmOperator *op) * - add a new one if it doesn't exist */ if (scene->active_keyingset == 0) { - short flag = 0, keyingflag = 0; + eKS_Settings flag = 0; + eInsertKeyFlags keyingflag = 0; /* validate flags * - absolute KeyingSets should be created by default */ flag |= KEYINGSET_ABSOLUTE; - keyingflag |= ANIM_get_keyframing_flags(scene, 0); + keyingflag |= ANIM_get_keyframing_flags(scene, false); if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) { keyingflag |= INSERTKEY_XYZ2RGB; @@ -350,14 +352,14 @@ static int add_keyingset_button_exec(bContext *C, wmOperator *op) /* add path to this setting */ BKE_keyingset_add_path(ks, ptr.owner_id, NULL, path, index, pflag, KSP_GROUP_KSNAME); ks->active_path = BLI_listbase_count(&ks->paths); - success = 1; + changed = true; /* free the temp path created */ MEM_freeN(path); } } - if (success) { + if (changed) { /* send updates */ WM_event_add_notifier(C, NC_SCENE | ND_KEYINGSET, NULL); @@ -365,7 +367,7 @@ static int add_keyingset_button_exec(bContext *C, wmOperator *op) BKE_reportf(op->reports, RPT_INFO, "Property added to Keying Set: '%s'", ks->name); } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_keyingset_button_add(wmOperatorType *ot) @@ -395,7 +397,7 @@ static int remove_keyingset_button_exec(bContext *C, wmOperator *op) PropertyRNA *prop = NULL; PointerRNA ptr = {NULL}; char *path = NULL; - short success = 0; + bool changed = false; int index = 0; /* try to add to keyingset using property retrieved from UI */ @@ -431,7 +433,7 @@ static int remove_keyingset_button_exec(bContext *C, wmOperator *op) if (ksp) { BKE_keyingset_free_path(ks, ksp); - success = 1; + changed = true; } /* free temp path used */ @@ -439,7 +441,7 @@ static int remove_keyingset_button_exec(bContext *C, wmOperator *op) } } - if (success) { + if (changed) { /* send updates */ WM_event_add_notifier(C, NC_SCENE | ND_KEYINGSET, NULL); @@ -447,7 +449,7 @@ static int remove_keyingset_button_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_INFO, "Property removed from Keying Set"); } - return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void ANIM_OT_keyingset_button_remove(wmOperatorType *ot) @@ -931,14 +933,15 @@ void ANIM_relative_keyingset_add_source(ListBase *dsources, ID *id, StructRNA *s /* KeyingSet Operations (Insert/Delete Keyframes) ------------ */ -/* Given a KeyingSet and context info, validate Keying Set's paths. +/** + * Given a KeyingSet and context info, validate Keying Set's paths. * This is only really necessary with relative/built-in KeyingSets * where their list of paths is dynamically generated based on the * current context info. * * Returns 0 if succeeded, otherwise an error code: eModifyKey_Returns */ -short ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) +eModifyKey_Returns ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) { /* sanity check */ if (ks == NULL) { @@ -990,12 +993,12 @@ short ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) } /* Determine which keying flags apply based on the override flags */ -static short keyingset_apply_keying_flags(const short base_flags, - const short overrides, - const short own_flags) +static eInsertKeyFlags keyingset_apply_keying_flags(const eInsertKeyFlags base_flags, + const eInsertKeyFlags overrides, + const eInsertKeyFlags own_flags) { /* Pass through all flags by default (i.e. even not explicitly listed ones). */ - short result = base_flags; + eInsertKeyFlags result = base_flags; /* The logic for whether a keying flag applies is as follows: * - If the flag in question is set in "overrides", that means that the @@ -1025,7 +1028,9 @@ static short keyingset_apply_keying_flags(const short base_flags, * Given a KeyingSet and context info (if required), * modify keyframes for the channels specified by the KeyingSet. * This takes into account many of the different combinations of using KeyingSets. - * Returns the number of channels that keyframes were added to + * + * \returns the number of channels that key-frames were added or + * #eModifyKey_Returns (a negative number). */ int ANIM_apply_keyingset( bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra) @@ -1035,9 +1040,10 @@ int ANIM_apply_keyingset( ReportList *reports = CTX_wm_reports(C); KS_Path *ksp; ListBase nla_cache = {NULL, NULL}; - const short base_kflags = ANIM_get_keyframing_flags(scene, 1); + const eInsertKeyFlags base_kflags = ANIM_get_keyframing_flags(scene, true); const char *groupname = NULL; - short kflag = 0, success = 0; + eInsertKeyFlags kflag = 0; + int success = 0; char keytype = scene->toolsettings->keyframe_type; /* sanity checks */ @@ -1055,17 +1061,19 @@ int ANIM_apply_keyingset( } /* if relative Keying Sets, poll and build up the paths */ - success = ANIM_validate_keyingset(C, dsources, ks); - - if (success != 0) { - /* return error code if failed */ - return success; + { + const eModifyKey_Returns error = ANIM_validate_keyingset(C, dsources, ks); + if (error != 0) { + BLI_assert(error < 0); + /* return error code if failed */ + return error; + } } /* apply the paths as specified in the KeyingSet now */ for (ksp = ks->paths.first; ksp; ksp = ksp->next) { int arraylen, i; - short kflag2; + eInsertKeyFlags kflag2; /* skip path if no ID pointer is specified */ if (ksp->id == NULL) { diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index 7baaaf63d6a..2f81e28b496 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -56,9 +56,9 @@ struct NlaKeyframingContext; /* ************ Keyframing Management **************** */ /* Get the active settings for keyframing settings from context (specifically the given scene) - * - incl_mode: include settings from keyframing mode in the result (i.e. replace only) + * - use_autokey_mode: include settings from keyframing mode in the result (i.e. replace only). */ -short ANIM_get_keyframing_flags(struct Scene *scene, short incl_mode); +eInsertKeyFlags ANIM_get_keyframing_flags(struct Scene *scene, const bool use_autokey_mode); /* -------- */ @@ -129,28 +129,28 @@ bool insert_keyframe_direct(struct ReportList *reports, * Use this to create any necessary animation data, and then insert a keyframe * using the current value being keyframed, in the relevant place. Returns success. */ -short insert_keyframe(struct Main *bmain, - struct ReportList *reports, - struct ID *id, - struct bAction *act, - const char group[], - const char rna_path[], - int array_index, - float cfra, - eBezTriple_KeyframeType keytype, - struct ListBase *nla_cache, - eInsertKeyFlags flag); +int insert_keyframe(struct Main *bmain, + struct ReportList *reports, + struct ID *id, + struct bAction *act, + const char group[], + const char rna_path[], + int array_index, + float cfra, + eBezTriple_KeyframeType keytype, + struct ListBase *nla_cache, + eInsertKeyFlags flag); /* Main Keyframing API call: * Use this to delete keyframe on current frame for relevant channel. * Will perform checks just in case. */ -short delete_keyframe(struct Main *bmain, - struct ReportList *reports, - struct ID *id, - struct bAction *act, - const char rna_path[], - int array_index, - float cfra); +int delete_keyframe(struct Main *bmain, + struct ReportList *reports, + struct ID *id, + struct bAction *act, + const char rna_path[], + int array_index, + float cfra); /* ************ Keying Sets ********************** */ @@ -225,7 +225,9 @@ typedef enum eModifyKey_Returns { /* poll the current KeyingSet, updating it's set of paths * (if "builtin"/"relative") for context changes */ -short ANIM_validate_keyingset(struct bContext *C, ListBase *dsources, struct KeyingSet *ks); +eModifyKey_Returns ANIM_validate_keyingset(struct bContext *C, + ListBase *dsources, + struct KeyingSet *ks); /* use the specified KeyingSet to add/remove various Keyframes on the specified frame */ int ANIM_apply_keyingset(struct bContext *C, diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 98e2bde499e..a1d8b9d0b2e 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -707,7 +707,7 @@ static void insert_action_keys(bAnimContext *ac, short mode) ReportList *reports = ac->reports; Scene *scene = ac->scene; ToolSettings *ts = scene->toolsettings; - short flag = 0; + eInsertKeyFlags flag; /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | @@ -721,8 +721,8 @@ static void insert_action_keys(bAnimContext *ac, short mode) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* init keyframing flag */ - flag = ANIM_get_keyframing_flags(scene, 1); + /* Init keyframing flag. */ + flag = ANIM_get_keyframing_flags(scene, true); /* insert keyframes */ for (ale = anim_data.first; ale; ale = ale->next) { diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index aea9308afdb..623d7e287d2 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -610,7 +610,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) SpaceGraph *sipo = (SpaceGraph *)ac->sl; Scene *scene = ac->scene; ToolSettings *ts = scene->toolsettings; - short flag = 0; + eInsertKeyFlags flag = 0; /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | @@ -639,8 +639,8 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) return; } - /* init keyframing flag */ - flag = ANIM_get_keyframing_flags(scene, 1); + /* Init key-framing flag. */ + flag = ANIM_get_keyframing_flags(scene, true); /* insert keyframes */ if (mode & GRAPHKEYS_INSERTKEY_CURSOR) { diff --git a/source/blender/editors/transform/transform_convert.c b/source/blender/editors/transform/transform_convert.c index 97a61ab9d9e..55f08d501ec 100644 --- a/source/blender/editors/transform/transform_convert.c +++ b/source/blender/editors/transform/transform_convert.c @@ -1424,10 +1424,10 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); ListBase dsources = {NULL, NULL}; float cfra = (float)CFRA; // xxx this will do for now - short flag = 0; + eInsertKeyFlags flag = 0; - /* get flags used for inserting keyframes */ - flag = ANIM_get_keyframing_flags(scene, 1); + /* Get flags used for inserting keyframes. */ + flag = ANIM_get_keyframing_flags(scene, true); /* add datasource override for the object */ ANIM_relative_keyingset_add_source(&dsources, id, NULL, NULL); @@ -1566,14 +1566,14 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); ListBase nla_cache = {NULL, NULL}; float cfra = (float)CFRA; - short flag = 0; + eInsertKeyFlags flag = 0; /* flag is initialized from UserPref keyframing settings * - special exception for targetless IK - INSERTKEY_MATRIX keyframes should get * visual keyframes even if flag not set, as it's not that useful otherwise * (for quick animation recording) */ - flag = ANIM_get_keyframing_flags(scene, 1); + flag = ANIM_get_keyframing_flags(scene, true); if (targetless_ik) { flag |= INSERTKEY_MATRIX; -- cgit v1.2.3