Refactor: remove KEYFRAME_OK_CHECKS macro

No functional changes.

This PR just replaces the `KEYFRAME_OK_CHECKS` macro with a function
`keyframe_ok_checks`.

The motivation for this is to remove the confusing use of nested macros.

Since the actual check has to be passed in, this new function takes a function as an argument.

Pull Request: https://projects.blender.org/blender/blender/pulls/118914
This commit is contained in:
Christoph Lendenfeld
2024-03-01 12:05:00 +01:00
committed by Christoph Lendenfeld
parent bf6f9ea2da
commit c28e1bb482
2 changed files with 72 additions and 87 deletions

View File

@@ -14,6 +14,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_function_ref.hh"
#include "BLI_lasso_2d.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
@@ -486,62 +487,53 @@ void ANIM_editkeyframes_refresh(bAnimContext *ac)
/* BezTriple Validation Callbacks */
/* ------------------------ */
/* Some macros to make this easier... */
/* run the given check on the 3 handles:
* - Check should be a macro, which takes the handle index as its single arg,
* which it substitutes later.
* - Requires that a var, of type short, is named 'ok',
* and has been initialized to 0.
*/
#define KEYFRAME_OK_CHECKS(check) \
{ \
CHECK_TYPE(ok, short); \
if (check(1)) { \
ok |= KEYFRAME_OK_KEY; \
} \
if (ked && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) { \
/* Only act on visible items, so check handle visibility state. */ \
const bool handles_visible = ((ked->iterflags & KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE) ? \
BEZT_ISSEL_ANY(bezt) : \
true); \
if (handles_visible) { \
if (check(0)) { \
ok |= KEYFRAME_OK_H1; \
} \
if (check(2)) { \
ok |= KEYFRAME_OK_H2; \
} \
} \
} \
} \
(void)0
static short keyframe_ok_checks(
KeyframeEditData *ked,
BezTriple *bezt,
blender::FunctionRef<bool(KeyframeEditData *ked, BezTriple *bezt, const int index)> check)
{
short ok = 0;
if (check(ked, bezt, 1)) {
ok |= KEYFRAME_OK_KEY;
}
if (ked && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES))
{ /* Only act on visible items, so check handle visibility state. */
const bool handles_visible = ((ked->iterflags & KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE) ?
BEZT_ISSEL_ANY(bezt) :
true);
if (handles_visible) {
if (check(ked, bezt, 0)) {
ok |= KEYFRAME_OK_H1;
}
if (check(ked, bezt, 2)) {
ok |= KEYFRAME_OK_H2;
}
}
}
return ok;
}
/* ------------------------ */
static short ok_bezier_frame(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
/* frame is stored in f1 property (this float accuracy check may need to be dropped?) */
#define KEY_CHECK_OK(_index) IS_EQF(bezt->vec[_index][0], ked->f1)
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return IS_EQF(bezt->vec[index][0], ked->f1);
});
/* return ok flags */
return ok;
}
static short ok_bezier_framerange(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return (bezt->vec[index][0] > ked->f1) && (bezt->vec[index][0] < ked->f2);
});
/* frame range is stored in float properties */
#define KEY_CHECK_OK(_index) ((bezt->vec[_index][0] > ked->f1) && (bezt->vec[_index][0] < ked->f2))
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
}
@@ -558,48 +550,43 @@ static short ok_bezier_selected(KeyframeEditData * /*ked*/, BezTriple *bezt)
static short ok_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
/* Value is stored in f1 property:
* - This float accuracy check may need to be dropped?
* - Should value be stored in f2 instead
* so that we won't have conflicts when using f1 for frames too?
*/
#define KEY_CHECK_OK(_index) IS_EQF(bezt->vec[_index][1], ked->f1)
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return IS_EQF(bezt->vec[index][1], ked->f1);
});
/* return ok flags */
return ok;
}
static short ok_bezier_valuerange(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
/* value range is stored in float properties */
#define KEY_CHECK_OK(_index) ((bezt->vec[_index][1] > ked->f1) && (bezt->vec[_index][1] < ked->f2))
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return (bezt->vec[index][1] > ked->f1) && (bezt->vec[index][1] < ked->f2);
});
/* return ok flags */
return ok;
}
static short ok_bezier_region(KeyframeEditData *ked, BezTriple *bezt)
{
/* rect is stored in data property (it's of type rectf, but may not be set) */
if (ked->data) {
short ok = 0;
#define KEY_CHECK_OK(_index) BLI_rctf_isect_pt_v(static_cast<rctf *>(ked->data), bezt->vec[_index])
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
if (!ked->data) {
return 0;
}
return 0;
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return BLI_rctf_isect_pt_v(static_cast<rctf *>(ked->data), bezt->vec[index]);
});
return ok;
}
bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const float xy[2])
@@ -622,18 +609,17 @@ bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const
static short ok_bezier_region_lasso(KeyframeEditData *ked, BezTriple *bezt)
{
/* check for lasso customdata (KeyframeEdit_LassoData) */
if (ked->data) {
short ok = 0;
#define KEY_CHECK_OK(_index) \
keyframe_region_lasso_test(static_cast<KeyframeEdit_LassoData *>(ked->data), bezt->vec[_index])
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
if (!ked->data) {
return 0;
}
return 0;
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return keyframe_region_lasso_test(static_cast<KeyframeEdit_LassoData *>(ked->data),
bezt->vec[index]);
});
return ok;
}
static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt)
@@ -682,18 +668,17 @@ bool keyframe_region_circle_test(const KeyframeEdit_CircleData *data_circle, con
static short ok_bezier_region_circle(KeyframeEditData *ked, BezTriple *bezt)
{
/* check for circle select customdata (KeyframeEdit_CircleData) */
if (ked->data) {
short ok = 0;
#define KEY_CHECK_OK(_index) \
keyframe_region_circle_test(static_cast<KeyframeEdit_CircleData *>(ked->data), bezt->vec[_index])
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
if (!ked->data) {
return 0;
}
return 0;
const short ok = keyframe_ok_checks(
ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
return keyframe_region_circle_test(static_cast<KeyframeEdit_CircleData *>(ked->data),
bezt->vec[index]);
});
return ok;
}
static short ok_bezier_channel_circle(KeyframeEditData *ked, BezTriple *bezt)

View File

@@ -571,7 +571,7 @@ static void initialize_box_select_key_editing_data(const bool incl_handles,
r_ked->iterflags |= KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE;
}
/* Enable handles selection. (used in keyframes_edit.cc > KEYFRAME_OK_CHECKS macro) */
/* Enable handles selection. (used in keyframes_edit.cc > keyframe_ok_checks function) */
if (incl_handles) {
r_ked->iterflags |= KEYFRAME_ITER_INCL_HANDLES;
*r_mapping_flag = 0;