[Bf-blender-cvs] [19268fb] master: Added buttons to move a pose in a pose library up/down.

Sybren A. Stüvel noreply at git.blender.org
Fri Sep 16 15:24:38 CEST 2016


Commit: 19268fbad34211ee0ab9bde024a4649c76ce7a5c
Author: Sybren A. Stüvel
Date:   Fri Sep 16 15:07:23 2016 +0200
Branches: master
https://developer.blender.org/rB19268fbad34211ee0ab9bde024a4649c76ce7a5c

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.

===================================================================

M	release/scripts/startup/bl_ui/properties_data_armature.py
M	source/blender/editors/armature/armature_intern.h
M	source/blender/editors/armature/armature_ops.c
M	source/blender/editors/armature/pose_lib.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py
index 3c9e2eb..54942af 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -201,6 +201,10 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
 
             col.operator("poselib.action_sanitize", icon='HELP', text="")  # XXX: put in menu?
 
+            if pose_marker_active is not None:
+                col.operator("poselib.pose_move", icon='TRIA_UP', text="").direction = 'UP'
+                col.operator("poselib.pose_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
+
 
 # TODO: this panel will soon be deprecated too
 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h
index 02aefce..b39b4bd 100644
--- a/source/blender/editors/armature/armature_intern.h
+++ b/source/blender/editors/armature/armature_intern.h
@@ -201,6 +201,7 @@ void POSELIB_OT_action_sanitize(struct wmOperatorType *ot);
 void POSELIB_OT_pose_add(struct wmOperatorType *ot);
 void POSELIB_OT_pose_remove(struct wmOperatorType *ot);
 void POSELIB_OT_pose_rename(struct wmOperatorType *ot);
+void POSELIB_OT_pose_move(struct wmOperatorType *ot);
 
 void POSELIB_OT_browse_interactive(struct wmOperatorType *ot);
 void POSELIB_OT_apply_pose(struct wmOperatorType *ot);
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index ed5f96a5..5622cd0 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -151,6 +151,7 @@ void ED_operatortypes_armature(void)
 	WM_operatortype_append(POSELIB_OT_pose_add);
 	WM_operatortype_append(POSELIB_OT_pose_remove);
 	WM_operatortype_append(POSELIB_OT_pose_rename);
+	WM_operatortype_append(POSELIB_OT_pose_move);
 	
 	WM_operatortype_append(POSELIB_OT_new);
 	WM_operatortype_append(POSELIB_OT_unlink);
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index d9a3efa..2012237 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 */




More information about the Bf-blender-cvs mailing list