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 | |
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')
-rw-r--r-- | source/blender/blenkernel/BKE_freestyle.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_linestyle.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/freestyle.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 32 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 38 | ||||
-rw-r--r-- | source/blender/editors/armature/pose_group.c | 51 | ||||
-rw-r--r-- | source/blender/editors/armature/pose_lib.c | 34 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 28 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 30 | ||||
-rw-r--r-- | source/blender/editors/render/render_shading.c | 48 | ||||
-rw-r--r-- | source/blender/freestyle/FRS_freestyle.h | 3 | ||||
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp | 22 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 |
14 files changed, 137 insertions, 185 deletions
diff --git a/source/blender/blenkernel/BKE_freestyle.h b/source/blender/blenkernel/BKE_freestyle.h index e10594634f0..50407f3bdfc 100644 --- a/source/blender/blenkernel/BKE_freestyle.h +++ b/source/blender/blenkernel/BKE_freestyle.h @@ -55,8 +55,7 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *con /* FreestyleConfig.modules */ FreestyleModuleConfig *BKE_freestyle_module_add(FreestyleConfig *config); bool BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf); -bool BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf); -bool BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +bool BKE_freestyle_module_move(FreestyleConfig *config, FreestyleModuleConfig *module_conf, int direction); /* FreestyleConfig.linesets */ FreestyleLineSet *BKE_freestyle_lineset_add(struct Main *bmain, FreestyleConfig *config, const char *name); diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h index e96ef4e7be3..af9bf58ce77 100644 --- a/source/blender/blenkernel/BKE_linestyle.h +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -73,10 +73,10 @@ int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyle int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); -void BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); -void BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); -void BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); -void BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase); char *BKE_linestyle_path_to_color_ramp(FreestyleLineStyle *linestyle, struct ColorBand *color_ramp); 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) diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 9dfa80006de..96349a7b066 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -69,6 +69,7 @@ void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnew void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1); void BLI_listbase_sort(struct ListBase *listbase, int (*cmp)(const void *, const void *)) ATTR_NONNULL(1, 2); void BLI_listbase_sort_r(ListBase *listbase, int (*cmp)(void *, const void *, const void *), void *thunk) ATTR_NONNULL(1, 2); +bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL(); void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1); int BLI_listbase_count_ex(const struct ListBase *listbase, const int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index ebee2c7941c..e72eff57ad9 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -342,6 +342,44 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) } } +/** + * Reinsert \a link relative to its current position but offset by \a step. Doesn't move + * item if new position would exceed list (could optionally move to head/tail). + * + * \param step: Absolute value defines step size, sign defines direction. E.g pass -1 + * to move \a link before previous, or 1 to move behind next. + * \return If position of \a link has changed. + */ +bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) +{ + Link *link = vlink; + Link *hook = link; + const bool is_up = step < 0; + + if (step == 0 || vlink == NULL) { + return false; + } + BLI_assert(BLI_findindex(listbase, link) != -1); + + /* find link to insert before/after */ + for (int i = 0; i < ABS(step); i++) { + hook = is_up ? hook->prev : hook->next; + if (!hook) { + return false; + } + } + + /* reinsert link */ + BLI_remlink(listbase, vlink); + if (is_up) { + BLI_insertlinkbefore(listbase, hook, vlink); + } + else { + BLI_insertlinkafter(listbase, hook, vlink); + } + return true; +} + /** * Removes and disposes of the entire contents of listbase using direct free(3). 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} }; diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h index 039a75a2f0f..a6382010ca7 100644 --- a/source/blender/freestyle/FRS_freestyle.h +++ b/source/blender/freestyle/FRS_freestyle.h @@ -63,8 +63,7 @@ void FRS_exit(void); void FRS_copy_active_lineset(struct FreestyleConfig *config); void FRS_paste_active_lineset(struct FreestyleConfig *config); void FRS_delete_active_lineset(struct FreestyleConfig *config); -void FRS_move_active_lineset_up(struct FreestyleConfig *config); -void FRS_move_active_lineset_down(struct FreestyleConfig *config); +bool FRS_move_active_lineset(struct FreestyleConfig *config, int direction); /* Testing */ struct Material *FRS_create_stroke_material(struct Main *bmain, struct FreestyleLineStyle *linestyle); diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 4d8c6a66d42..2af4447e4dc 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -730,24 +730,14 @@ void FRS_delete_active_lineset(FreestyleConfig *config) } } -void FRS_move_active_lineset_up(FreestyleConfig *config) -{ - FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - - if (lineset) { - BLI_remlink(&config->linesets, lineset); - BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset); - } -} - -void FRS_move_active_lineset_down(FreestyleConfig *config) +/** + * Reinsert the active lineset at an offset \a direction from current position. + * \return if position of active lineset has changed. + */ +bool FRS_move_active_lineset(FreestyleConfig *config, int direction) { FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - - if (lineset) { - BLI_remlink(&config->linesets, lineset); - BLI_insertlinkafter(&config->linesets, lineset->next, lineset); - } + return (lineset != NULL) && BLI_listbase_link_move(&config->linesets, lineset, direction); } // Testing diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 820465ee7d1..2893fabd145 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -916,7 +916,7 @@ int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value); int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop); void *RNA_property_enum_py_data_get(PropertyRNA *prop); -int RNA_property_enum_step(const struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int direction); +int RNA_property_enum_step(const struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step); PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value); |