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/editors/gpencil/gpencil_data.c | |
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/editors/gpencil/gpencil_data.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index ce1e397e91c..9a786755484 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -272,21 +272,11 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op) if (ELEM(NULL, gpd, gpl)) return OPERATOR_CANCELLED; - /* up or down? */ - if (direction == GP_LAYER_MOVE_UP) { - /* up */ - BLI_remlink(&gpd->layers, gpl); - BLI_insertlinkbefore(&gpd->layers, gpl->prev, gpl); - } - else { - /* down */ - BLI_remlink(&gpd->layers, gpl); - BLI_insertlinkafter(&gpd->layers, gpl->next, gpl); + BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */ + if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) { + WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); } - /* notifiers */ - WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - return OPERATOR_FINISHED; } @@ -782,23 +772,21 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op) for (LinkData *link = selected.first; link; link = link->next) { gps = link->data; BLI_remlink(&gpf->strokes, gps); - BLI_insertlinkafter(&gpf->strokes, gpf->strokes.last, gps); + BLI_addtail(&gpf->strokes, gps); } break; /* Bring Forward */ case GP_STROKE_MOVE_UP: for (LinkData *link = selected.last; link; link = link->prev) { gps = link->data; - BLI_remlink(&gpf->strokes, gps); - BLI_insertlinkafter(&gpf->strokes, gps->next, gps); + BLI_listbase_link_move(&gpf->strokes, gps, 1); } break; - /* Send Backward */ + /* Send Backward */ case GP_STROKE_MOVE_DOWN: for (LinkData *link = selected.first; link; link = link->next) { gps = link->data; - BLI_remlink(&gpf->strokes, gps); - BLI_insertlinkbefore(&gpf->strokes, gps->prev, gps); + BLI_listbase_link_move(&gpf->strokes, gps, -1); } break; /* Send to Back */ @@ -806,7 +794,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op) for (LinkData *link = selected.last; link; link = link->prev) { gps = link->data; BLI_remlink(&gpf->strokes, gps); - BLI_insertlinkbefore(&gpf->strokes, gpf->strokes.first, gps); + BLI_addhead(&gpf->strokes, gps); } break; default: |