From 93deb27dd4b4e12f118cd74ca5c70a485c19e81b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 28 Mar 2013 20:58:14 +0000 Subject: fix [#34804] Only timeline_markers[0] is selectable if multiple markers at same frame also add macros for looping on listbases as if they were circular lists which is handy for cycling over items. --- source/blender/blenlib/BLI_listbase.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source/blender/blenlib/BLI_listbase.h') diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 54cd687eeac..41968f1ebd6 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -75,6 +75,37 @@ void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src); /* create a generic list node containing link to provided data */ struct LinkData *BLI_genericNodeN(void *data); +/** + * Does a full loop on the list, with any value acting as first + * (handy for cycling items) + * + * \code{.c} + * + * LISTBASE_CIRCULAR_FORWARD_BEGIN (listbase, item, item_init) { + * ...operate on marker... + * } + * LISTBASE_CIRCULAR_FORWARD_END (listbase, item, item_init); + * + * \endcode + */ +#define LISTBASE_CIRCULAR_FORWARD_BEGIN(lb, lb_iter, lb_init) \ +if ((lb)->first && (lb_init || (lb_init = (lb)->first))) { \ + lb_iter = lb_init; \ + do { +#define LISTBASE_CIRCULAR_FORWARD_END(lb, lb_iter, lb_init) \ + } while ((lb_iter = (lb_iter)->next ? (lb_iter)->next : (lb)->first), \ + (lb_iter != lb_init)); \ +} + +#define LISTBASE_CIRCULAR_BACKWARD_BEGIN(lb, lb_iter, lb_init) \ +if ((lb)->last && (lb_init || (lb_init = (lb)->last))) { \ + lb_iter = lb_init; \ + do { +#define LISTBASE_CIRCULAR_BACKWARD_END(lb, lb_iter, lb_init) \ + } while ((lb_iter = (lb_iter)->prev ? (lb_iter)->prev : (lb)->last), \ + (lb_iter != lb_init)); \ +} + #ifdef __cplusplus } #endif -- cgit v1.2.3