From 572bc1364ca9d978edf5aee991849dd4f8e56a52 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Sun, 18 Sep 2016 21:36:34 +0200 Subject: BLI_listbase: Add/use utility to move link (BLI_listbase_link_move) We were calling BLI_remlink and then BLI_insertlinkbefore/after quite often. BLI_listbase_link_move simplifies code a bit and makes it easier to follow. It also returns if link position has changed which can be used to avoid unnecessary updates. Added it to a number of list reorder operators for now and made use of return value. Behavior shouldn't be changed. Also some minor cleanup. --- source/blender/blenkernel/intern/freestyle.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'source/blender/blenkernel/intern/freestyle.c') diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c index 3a15be5a09d..21fc1674dc5 100644 --- a/source/blender/blenkernel/intern/freestyle.c +++ b/source/blender/blenkernel/intern/freestyle.c @@ -151,22 +151,14 @@ bool BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig return true; } -bool BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf) -{ - if (BLI_findindex(&config->modules, module_conf) == -1) - return false; - BLI_remlink(&config->modules, module_conf); - BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf); - return true; -} - -bool BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +/** + * Reinsert \a module_conf offset by \a direction from current position. + * \return if position of \a module_conf changed. + */ +bool BKE_freestyle_module_move(FreestyleConfig *config, FreestyleModuleConfig *module_conf, int direction) { - if (BLI_findindex(&config->modules, module_conf) == -1) - return false; - BLI_remlink(&config->modules, module_conf); - BLI_insertlinkafter(&config->modules, module_conf->next, module_conf); - return true; + return ((BLI_findindex(&config->modules, module_conf) > -1) && + (BLI_listbase_link_move(&config->modules, module_conf, direction) == true)); } void BKE_freestyle_lineset_unique_name(FreestyleConfig *config, FreestyleLineSet *lineset) -- cgit v1.2.3