[Bf-blender-cvs] [73ef27f1561] master: Cleanup: keyframing return arguments
Campbell Barton
noreply at git.blender.org
Fri Mar 6 07:05:51 CET 2020
Commit: 73ef27f15611ccb254816e199f8c74103b3d5172
Author: Campbell Barton
Date: Fri Mar 6 16:45:56 2020 +1100
Branches: master
https://developer.blender.org/rB73ef27f15611ccb254816e199f8c74103b3d5172
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.
===================================================================
M source/blender/editors/animation/anim_channels_defines.c
M source/blender/editors/animation/drivers.c
M source/blender/editors/animation/keyframing.c
M source/blender/editors/animation/keyingsets.c
M source/blender/editors/include/ED_keyframing.h
M source/blender/editors/space_action/action_edit.c
M source/blender/editors/space_graph/graph_edit.c
M source/blender/editors/transform/transform_convert.c
M source/blender/makesrna/intern/rna_animation_api.c
M source/blender/python/intern/bpy_rna_anim.c
===================================================================
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,
/* ***
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list