diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-08-06 10:46:36 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-08-06 10:46:36 +0300 |
commit | 1ab75c1d494422270fa88bbf23cc42f7b203ed4b (patch) | |
tree | c70f4ef4118deb6efe01477438bddf800f503560 /source/blender | |
parent | bb8ce95b5ee79787d0a54cb59f522726d693dc7d (diff) |
Cleanup: use range2f in `ED_keylist_find_any_between`.
Diffstat (limited to 'source/blender')
4 files changed, 15 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_range.h b/source/blender/blenlib/BLI_range.h index ad4cd6c162e..e55f443769d 100644 --- a/source/blender/blenlib/BLI_range.h +++ b/source/blender/blenlib/BLI_range.h @@ -29,6 +29,11 @@ typedef struct Range2f { float max; } Range2f; +BLI_INLINE bool range2f_in_range(const Range2f *range, const float value) +{ + return IN_RANGE(value, range->min, range->max); +} + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/animation/keyframes_keylist.c b/source/blender/editors/animation/keyframes_keylist.c index 722edba0473..a869d8d6388 100644 --- a/source/blender/editors/animation/keyframes_keylist.c +++ b/source/blender/editors/animation/keyframes_keylist.c @@ -89,14 +89,11 @@ ActKeyColumn *ED_keylist_find_prev(const AnimKeylist *keylist, float cfra) /* TODO(jbakker): Should we change this to use `ED_keylist_find_next(keys, min_fra)` and only check * boundary of `max_fra`. */ -/* TODO(jbakker): Use const Range2f. */ -ActKeyColumn *ED_keylist_find_any_between(const AnimKeylist *keylist, - const float min_fra, - const float max_fra) +ActKeyColumn *ED_keylist_find_any_between(const AnimKeylist *keylist, const Range2f frame_range) { for (ActKeyColumn *ak = keylist->keys.root; ak; - ak = (ak->cfra < min_fra) ? ak->right : ak->left) { - if (IN_RANGE(ak->cfra, min_fra, max_fra)) { + ak = (ak->cfra < frame_range.min) ? ak->right : ak->left) { + if (range2f_in_range(&frame_range, ak->cfra)) { return ak; } } diff --git a/source/blender/editors/include/ED_keyframes_keylist.h b/source/blender/editors/include/ED_keyframes_keylist.h index 8ab2dff36e5..86741b67698 100644 --- a/source/blender/editors/include/ED_keyframes_keylist.h +++ b/source/blender/editors/include/ED_keyframes_keylist.h @@ -23,6 +23,8 @@ #pragma once +#include "BLI_range.h" + #ifdef __cplusplus extern "C" { #endif @@ -37,7 +39,6 @@ struct Scene; struct bAnimContext; struct bDopeSheet; struct bGPDlayer; -struct Range2f; /* ****************************** Base Structs ****************************** */ @@ -142,11 +143,10 @@ struct ActKeyColumn *ED_keylist_find_exact(const struct AnimKeylist *keylist, fl struct ActKeyColumn *ED_keylist_find_next(const struct AnimKeylist *keylist, float cfra); struct ActKeyColumn *ED_keylist_find_prev(const struct AnimKeylist *keylist, float cfra); struct ActKeyColumn *ED_keylist_find_any_between(const struct AnimKeylist *keylist, - float min_fra, - float max_fra); + const Range2f frame_range); bool ED_keylist_is_empty(const struct AnimKeylist *keylist); const struct ListBase /* ActKeyColumn */ *ED_keylist_listbase(const struct AnimKeylist *keylist); -bool ED_keylist_frame_range(const struct AnimKeylist *keylist, struct Range2f *r_frame_range); +bool ED_keylist_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_range); /* Key-data Generation --------------- */ diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 64ccca2c907..9dcfc626a50 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -170,10 +170,9 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac, /* half-size (for either side), but rounded up to nearest int (for easier targeting) */ key_hsize = roundf(key_hsize / 2.0f); - float xmin = UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize); - float xmax = UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize); - - const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, xmin, xmax); + const Range2f range = {UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize), + UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize)}; + const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, range); if (ak) { /* set the frame to use, and apply inverse-correction for NLA-mapping |