diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-09-16 16:07:23 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-09-16 16:11:45 +0300 |
commit | 19268fbad34211ee0ab9bde024a4649c76ce7a5c (patch) | |
tree | 46d2f0109a51de6ec5d641ee5a07e1a34852979d /source/blender/editors/armature/pose_lib.c | |
parent | 661a316c7273e11c05e2b5709cf083d01ca9a7de (diff) |
Added buttons to move a pose in a pose library up/down.
This will break the pose library preview add-on, since that add-on uses
file indices rather than pose names.
Diffstat (limited to 'source/blender/editors/armature/pose_lib.c')
-rw-r--r-- | source/blender/editors/armature/pose_lib.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index d9a3efa765c..2012237ed4e 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -733,6 +733,102 @@ void POSELIB_OT_pose_rename(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); } +static int poselib_move_exec(bContext *C, wmOperator *op) +{ + Object *ob = get_poselib_object(C); + bAction *act = (ob) ? ob->poselib : NULL; + TimeMarker *marker; + int marker_index; + int dir; + PropertyRNA *prop; + + /* check if valid poselib */ + if (act == NULL) { + BKE_report(op->reports, RPT_ERROR, "Object does not have pose lib data"); + return OPERATOR_CANCELLED; + } + + prop = RNA_struct_find_property(op->ptr, "pose"); + if (RNA_property_is_set(op->ptr, prop)) { + marker_index = RNA_property_enum_get(op->ptr, prop); + } + else { + marker_index = act->active_marker - 1; + } + + /* get index (and pointer) of pose to remove */ + marker = BLI_findlink(&act->markers, marker_index); + if (marker == NULL) { + BKE_reportf(op->reports, RPT_ERROR, "Invalid pose specified %d", marker_index); + return OPERATOR_CANCELLED; + } + + dir = RNA_enum_get(op->ptr, "direction"); + + /* move pose */ + if (dir == 1) { /* up */ + void *prev = marker->prev; + + if (prev == NULL) + return OPERATOR_FINISHED; + + BLI_remlink(&act->markers, marker); + BLI_insertlinkbefore(&act->markers, prev, marker); + } + else { /* down */ + void *next = marker->next; + + if (next == NULL) + return OPERATOR_FINISHED; + + BLI_remlink(&act->markers, marker); + BLI_insertlinkafter(&act->markers, next, marker); + } + + 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; +} + +void POSELIB_OT_pose_move(wmOperatorType *ot) +{ + PropertyRNA *prop; + static EnumPropertyItem pose_lib_pose_move[] = { + {1, "UP", 0, "Up", ""}, + {-1, "DOWN", 0, "Down", ""}, + {0, NULL, 0, NULL, NULL} + }; + + /* identifiers */ + ot->name = "PoseLib Move Pose"; + ot->idname = "POSELIB_OT_pose_move"; + ot->description = "Move the pose up or down in the active Pose Library"; + + /* api callbacks */ + ot->invoke = WM_menu_invoke; + ot->exec = poselib_move_exec; + ot->poll = has_poselib_pose_data_for_editing_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + prop = RNA_def_enum(ot->srna, "pose", DummyRNA_NULL_items, 0, "Pose", "The pose to move"); + RNA_def_enum_funcs(prop, poselib_stored_pose_itemf); + RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); + ot->prop = prop; + + RNA_def_enum(ot->srna, "direction", pose_lib_pose_move, 0, "Direction", "Direction to move, UP or DOWN"); +} + + + /* ************************************************************* */ /* Pose-Lib Browsing/Previewing Operator */ |