diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2016-09-18 22:36:34 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2016-09-18 22:44:42 +0300 |
commit | 572bc1364ca9d978edf5aee991849dd4f8e56a52 (patch) | |
tree | 61e965068f2d6bc835ecb8bd0ffe29709c9f5c1d /source/blender/blenkernel/intern | |
parent | 6c28d3bac26b22049768824bef6ae9d0e82bb71f (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/freestyle.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 32 |
2 files changed, 19 insertions, 35 deletions
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) diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 430935a5fad..bd21215f91e 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -1343,33 +1343,25 @@ int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineSt return 0; } -static void move_modifier(ListBase *lb, LineStyleModifier *modifier, int direction) +/** + * Reinsert \a modifier in modifier list with an offset of \a direction. + * \return if position of \a modifier has changed. + */ +bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) { - BLI_remlink(lb, modifier); - if (direction > 0) - BLI_insertlinkbefore(lb, modifier->prev, modifier); - else - BLI_insertlinkafter(lb, modifier->next, modifier); + return BLI_listbase_link_move(&linestyle->color_modifiers, modifier, direction); } - -void BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) { - move_modifier(&linestyle->color_modifiers, modifier, direction); + return BLI_listbase_link_move(&linestyle->alpha_modifiers, modifier, direction); } - -void BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) { - move_modifier(&linestyle->alpha_modifiers, modifier, direction); + return BLI_listbase_link_move(&linestyle->thickness_modifiers, modifier, direction); } - -void BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) -{ - move_modifier(&linestyle->thickness_modifiers, modifier, direction); -} - -void BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) { - move_modifier(&linestyle->geometry_modifiers, modifier, direction); + return BLI_listbase_link_move(&linestyle->geometry_modifiers, modifier, direction); } void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase) |