Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2016-09-18 22:36:34 +0300
committerJulian Eisel <eiseljulian@gmail.com>2016-09-18 22:44:42 +0300
commit572bc1364ca9d978edf5aee991849dd4f8e56a52 (patch)
tree61e965068f2d6bc835ecb8bd0ffe29709c9f5c1d /source/blender/editors
parent6c28d3bac26b22049768824bef6ae9d0e82bb71f (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')
-rw-r--r--source/blender/editors/armature/pose_group.c51
-rw-r--r--source/blender/editors/armature/pose_lib.c34
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c28
-rw-r--r--source/blender/editors/object/object_vgroup.c30
-rw-r--r--source/blender/editors/render/render_shading.c48
5 files changed, 66 insertions, 125 deletions
diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c
index 85bee023cef..85cff2e4df5 100644
--- a/source/blender/editors/armature/pose_group.c
+++ b/source/blender/editors/armature/pose_group.c
@@ -306,50 +306,31 @@ static int group_move_exec(bContext *C, wmOperator *op)
/* move bone group */
grpIndexA = pose->active_group;
- if (dir == 1) { /* up */
- void *prev = grp->prev;
-
- if (prev == NULL)
- return OPERATOR_FINISHED;
-
- BLI_remlink(&pose->agroups, grp);
- BLI_insertlinkbefore(&pose->agroups, prev, grp);
-
- grpIndexB = grpIndexA - 1;
- pose->active_group--;
- }
- else { /* down */
- void *next = grp->next;
-
- if (next == NULL)
- return OPERATOR_FINISHED;
-
- BLI_remlink(&pose->agroups, grp);
- BLI_insertlinkafter(&pose->agroups, next, grp);
-
- grpIndexB = grpIndexA + 1;
- pose->active_group++;
- }
+ if (BLI_listbase_link_move(&pose->agroups, grp, dir)) {
+ grpIndexB = grpIndexA + dir;
+ pose->active_group += dir;
+ /* fix changed bone group indices in bones (swap grpIndexA with grpIndexB) */
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ if (pchan->agrp_index == grpIndexB) {
+ pchan->agrp_index = grpIndexA;
+ }
+ else if (pchan->agrp_index == grpIndexA) {
+ pchan->agrp_index = grpIndexB;
+ }
+ }
- /* fix changed bone group indices in bones (swap grpIndexA with grpIndexB) */
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if (pchan->agrp_index == grpIndexB)
- pchan->agrp_index = grpIndexA;
- else if (pchan->agrp_index == grpIndexA)
- pchan->agrp_index = grpIndexB;
+ /* notifiers for updates */
+ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
}
- /* notifiers for updates */
- WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
-
return OPERATOR_FINISHED;
}
void POSE_OT_group_move(wmOperatorType *ot)
{
static EnumPropertyItem group_slot_move[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index b200aa2401b..4af7f3f8727 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -766,32 +766,18 @@ static int poselib_move_exec(bContext *C, wmOperator *op)
dir = RNA_enum_get(op->ptr, "direction");
/* move pose */
- if (dir == 1) { /* up */
- void *prev = marker->prev;
+ if (BLI_listbase_link_move(&act->markers, marker, dir)) {
+ act->active_marker = marker_index + dir + 1;
- if (prev == NULL)
- return OPERATOR_CANCELLED;
-
- BLI_remlink(&act->markers, marker);
- BLI_insertlinkbefore(&act->markers, prev, marker);
+ /* send notifiers for this - using keyframe editing notifiers, since action
+ * may be being shown in anim editors as active action
+ */
+ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
}
- else { /* down */
- void *next = marker->next;
-
- if (next == NULL)
- return OPERATOR_CANCELLED;
-
- BLI_remlink(&act->markers, marker);
- BLI_insertlinkafter(&act->markers, next, marker);
+ else {
+ return OPERATOR_CANCELLED;
}
- act->active_marker = marker_index - dir + 1;
-
- /* send notifiers for this - using keyframe editing notifiers, since action
- * may be being shown in anim editors as active action
- */
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
-
/* done */
return OPERATOR_FINISHED;
}
@@ -800,8 +786,8 @@ void POSELIB_OT_pose_move(wmOperatorType *ot)
{
PropertyRNA *prop;
static EnumPropertyItem pose_lib_pose_move[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};
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:
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index 3b7f518d36f..bd016b7fcfb 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -3633,7 +3633,8 @@ static int vgroup_move_exec(bContext *C, wmOperator *op)
Object *ob = ED_object_context(C);
bDeformGroup *def;
char *name_array;
- int dir = RNA_enum_get(op->ptr, "direction"), ret;
+ int dir = RNA_enum_get(op->ptr, "direction");
+ int ret = OPERATOR_FINISHED;
def = BLI_findlink(&ob->defbase, ob->actdef - 1);
if (!def) {
@@ -3642,36 +3643,25 @@ static int vgroup_move_exec(bContext *C, wmOperator *op)
name_array = vgroup_init_remap(ob);
- if (dir == 1) { /*up*/
- void *prev = def->prev;
+ if (BLI_listbase_link_move(&ob->defbase, def, dir)) {
+ ret = vgroup_do_remap(ob, name_array, op);
- BLI_remlink(&ob->defbase, def);
- BLI_insertlinkbefore(&ob->defbase, prev, def);
- }
- else { /*down*/
- void *next = def->next;
-
- BLI_remlink(&ob->defbase, def);
- BLI_insertlinkafter(&ob->defbase, next, def);
+ if (ret != OPERATOR_CANCELLED) {
+ DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
+ }
}
- ret = vgroup_do_remap(ob, name_array, op);
-
if (name_array) MEM_freeN(name_array);
- if (ret != OPERATOR_CANCELLED) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
- }
-
return ret;
}
void OBJECT_OT_vertex_group_move(wmOperatorType *ot)
{
static EnumPropertyItem vgroup_slot_move[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index 4796024646c..837573ad175 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -829,14 +829,10 @@ static int freestyle_module_move_exec(bContext *C, wmOperator *op)
FreestyleModuleConfig *module = ptr.data;
int dir = RNA_enum_get(op->ptr, "direction");
- if (dir == 1) {
- BKE_freestyle_module_move_up(&srl->freestyleConfig, module);
+ if (BKE_freestyle_module_move(&srl->freestyleConfig, module, dir)) {
+ DAG_id_tag_update(&scene->id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
}
- else {
- BKE_freestyle_module_move_down(&srl->freestyleConfig, module);
- }
- DAG_id_tag_update(&scene->id, 0);
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
}
@@ -844,8 +840,8 @@ static int freestyle_module_move_exec(bContext *C, wmOperator *op)
void SCENE_OT_freestyle_module_move(wmOperatorType *ot)
{
static EnumPropertyItem direction_items[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -993,14 +989,10 @@ static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
int dir = RNA_enum_get(op->ptr, "direction");
- if (dir == 1) {
- FRS_move_active_lineset_up(&srl->freestyleConfig);
- }
- else {
- FRS_move_active_lineset_down(&srl->freestyleConfig);
+ if (FRS_move_active_lineset(&srl->freestyleConfig, dir)) {
+ DAG_id_tag_update(&scene->id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
}
- DAG_id_tag_update(&scene->id, 0);
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
}
@@ -1008,8 +1000,8 @@ static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
{
static EnumPropertyItem direction_items[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -1350,6 +1342,7 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
LineStyleModifier *modifier = ptr.data;
int dir = RNA_enum_get(op->ptr, "direction");
+ bool changed = false;
if (!freestyle_linestyle_check_report(lineset, op->reports)) {
return OPERATOR_CANCELLED;
@@ -1357,23 +1350,26 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
switch (freestyle_get_modifier_type(&ptr)) {
case LS_MODIFIER_TYPE_COLOR:
- BKE_linestyle_color_modifier_move(lineset->linestyle, modifier, dir);
+ changed = BKE_linestyle_color_modifier_move(lineset->linestyle, modifier, dir);
break;
case LS_MODIFIER_TYPE_ALPHA:
- BKE_linestyle_alpha_modifier_move(lineset->linestyle, modifier, dir);
+ changed = BKE_linestyle_alpha_modifier_move(lineset->linestyle, modifier, dir);
break;
case LS_MODIFIER_TYPE_THICKNESS:
- BKE_linestyle_thickness_modifier_move(lineset->linestyle, modifier, dir);
+ changed = BKE_linestyle_thickness_modifier_move(lineset->linestyle, modifier, dir);
break;
case LS_MODIFIER_TYPE_GEOMETRY:
- BKE_linestyle_geometry_modifier_move(lineset->linestyle, modifier, dir);
+ changed = BKE_linestyle_geometry_modifier_move(lineset->linestyle, modifier, dir);
break;
default:
BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
- WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
+
+ if (changed) {
+ DAG_id_tag_update(&lineset->linestyle->id, 0);
+ WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
+ }
return OPERATOR_FINISHED;
}
@@ -1381,8 +1377,8 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
{
static EnumPropertyItem direction_items[] = {
- {1, "UP", 0, "Up", ""},
- {-1, "DOWN", 0, "Down", ""},
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL}
};