[Bf-blender-cvs] [3c7b8f0] soc-2014-shapekey: A much better shapekey-movement idea

Grigory Revzin noreply at git.blender.org
Tue May 13 14:07:25 CEST 2014


Commit: 3c7b8f00865b677880098a9e46efc2e97fa93e3c
Author: Grigory Revzin
Date:   Thu May 1 16:25:56 2014 +0400
https://developer.blender.org/rB3c7b8f00865b677880098a9e46efc2e97fa93e3c

A much better shapekey-movement idea

Removed place at index and updated Shape Key Move instead to do the same
thing and not break existing Python access to Shape Key move.

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/key.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/object/object_shapekey.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 631fc53..3eac5e8 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -264,10 +264,10 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
             col.separator()
 
             sub = col.column(align=True)
-            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").steps = -5
-            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").steps = -1
-            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").steps = 1
-            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").steps = 5
+            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'TOP'
+            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
+            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'BOTTOM'
 
             split = layout.split(percentage=0.4)
             row = split.row()
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index f441c4e..3dcd46e 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -99,15 +99,16 @@ void    BKE_key_convert_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos)[
 void    BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3]);
 
 /* other management */
-/* moves a shape key to new_index. safe, clamps index to key->totkey, updates reference keys and active shape */
-void	BKE_key_move(Object *ob, KeyBlock *key_block, int new_index);
+/* moves a shape key to new_index. safe, clamps index to key->totkey, updates reference keys and 
+ * the object's active shape index */
+void	BKE_keyblock_move(Object *ob, KeyBlock *key_block, int new_index);
 
 /* basic key math */
-float (*BKE_key_math_deltas(KeyBlock *a, KeyBlock *basis))[3];
-float (*BKE_key_math_deltas_mult(KeyBlock *a, KeyBlock *basis, float mult))[3]; 
+float	(*BKE_keyblock_math_deltas(KeyBlock *a, KeyBlock *basis))[3];
+float	(*BKE_keyblock_math_deltas_mult(KeyBlock *a, KeyBlock *basis, float mult))[3];
 
-void	BKE_key_math_add(KeyBlock *r, KeyBlock *a, KeyBlock* basis, float mult);
-void	BKE_key_math_interp(KeyBlock *r, KeyBlock *a, float mult);
+void	BKE_keyblock_math_add(KeyBlock *r, KeyBlock *a, KeyBlock* basis, float mult);
+void	BKE_keyblock_math_interp(KeyBlock *r, KeyBlock *a, float mult);
 
 
 /* key.c */
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 560b0c3..11665ad 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -2042,7 +2042,7 @@ void BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3])
 	}
 }
 
-void BKE_key_move(Object *ob, KeyBlock *key_block, int new_index) 
+void BKE_keyblock_move(Object *ob, KeyBlock *key_block, int new_index) 
 {
 	Key *key = BKE_key_from_object(ob);
 	KeyBlock *kb;
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index c4c0371..fd6b9a1 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -246,7 +246,6 @@ void OBJECT_OT_shape_key_clear(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_retime(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_mirror(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_move(struct wmOperatorType *ot);
-void OBJECT_OT_shape_key_place_at_index(struct wmOperatorType *ot);
 
 /* object_group.c */
 void OBJECT_OT_group_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index a6a0a7a..a8f0774 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -216,7 +216,6 @@ void ED_operatortypes_object(void)
 	WM_operatortype_append(OBJECT_OT_shape_key_retime);
 	WM_operatortype_append(OBJECT_OT_shape_key_mirror);
 	WM_operatortype_append(OBJECT_OT_shape_key_move);
-	WM_operatortype_append(OBJECT_OT_shape_key_place_at_index);
 
 	WM_operatortype_append(LATTICE_OT_select_all);
 	WM_operatortype_append(LATTICE_OT_select_more);
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index e66d14d..7b3ca66 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -491,15 +491,38 @@ static int shape_key_move_poll(bContext *C)
 }
 
 
+static EnumPropertyItem slot_move[] = {
+	{ -2, "TOP", 0, "Top of the list", "" },
+	{ -1, "UP", 0, "Up", "" },
+	{ 1, "DOWN", 0, "Down", "" },
+	{ 2, "BOTTOM", 0, "Bottom of the list", "" },
+	{ 0, NULL, 0, NULL, NULL }
+};
+
 static int shape_key_move_exec(bContext *C, wmOperator *op)
 {
 	Object *ob = ED_object_context(C);
 
-	int steps = RNA_int_get(op->ptr, "steps");
+	int type = RNA_enum_get(op->ptr, "type");
 	int act_index = ob->shapenr - 1;
+	int new_index;
 	Key *key = BKE_key_from_object(ob);
+	KeyBlock *kb = BKE_keyblock_from_object(ob);
+
+	if (IN_RANGE_INCL(type, -1, 1)){
+		new_index = act_index + type;
+	}
+	else if (type == 2) {
+		new_index = key->totkey - 1;
+	}
+	else if (type == -2) {
+		if (act_index == 1 || act_index == 0)
+			new_index = 0; /* replace the ref key only if we're at the top already */
+		else
+			new_index = 1;
+	}
 
-	BKE_key_move(ob, BKE_keyblock_from_object(ob), act_index + steps); 
+	BKE_keyblock_move(ob, kb, new_index);
 
 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -521,39 +544,5 @@ void OBJECT_OT_shape_key_move(wmOperatorType *ot)
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-	//RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
-	RNA_def_int(ot->srna, "steps", 1, -INT_MAX, INT_MAX, "Direction", "Move the shape key up or down?", -1, 1);
-}
-
-
-static int shape_key_place_exec(bContext *C, wmOperator *op)
-{
-	Object *ob = ED_object_context(C);
-	int act_index = ob->shapenr - 1;
-	int new_index = RNA_int_get(op->ptr, "index");
-	Key *key = BKE_key_from_object(ob);
-
-	BKE_key_move(ob, BLI_findlink(&key->block, act_index), RNA_int_get(op->ptr, "index"));
-
-	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
-
-	return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_shape_key_place_at_index(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Place Shape Key At Index";
-	ot->idname = "OBJECT_OT_shape_key_place_at_index";
-	ot->description = "Place a shape key at a given position in the list";
-
-	/* api callbacks */
-	ot->poll = shape_key_move_poll;
-	ot->exec = shape_key_place_exec;
-
-	/* flags */
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-	RNA_def_int(ot->srna, "index", 1, -INT_MAX, INT_MAX, "New Shape Index", "The desired position of the shape key", 0, INT_MAX);
+	RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
 }




More information about the Bf-blender-cvs mailing list