shape key operators and buttons for reordering
authorCampbell Barton <ideasman42@gmail.com>
Wed, 21 Oct 2009 14:33:52 +0000 (14:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 21 Oct 2009 14:33:52 +0000 (14:33 +0000)
release/scripts/ui/buttons_data_mesh.py
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_shapekey.c

index 3c8f655f17aa4b794d52ab8db67ee238a8debf36..a11fb27e1f6aab45ccb4abb93511930ae3d13c4f 100644 (file)
@@ -125,6 +125,13 @@ class DATA_PT_shape_keys(DataButtonsPanel):
                subcol.itemO("object.shape_key_mirror", icon='ICON_MOD_MIRROR', text="")
 
                if kb:
+                       
+                       col.itemS()
+
+                       subcol = col.column(align=True)
+                       subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
+                       subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
+                       
                        col.itemS()
 
                        subcol = col.column(align=True)
index 8c206ce9d4b0b9675a1f1a9d3cc7b50084adf5d7..93bbc69eff8e3dc3339c26001648836db550617a 100644 (file)
@@ -182,6 +182,7 @@ void OBJECT_OT_shape_key_add(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_remove(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_clear(struct wmOperatorType *ot);
 void OBJECT_OT_shape_key_mirror(struct wmOperatorType *ot);
+void OBJECT_OT_shape_key_move(struct wmOperatorType *ot);
 
 /* object_group.c */
 void OBJECT_OT_group_add(struct wmOperatorType *ot);
index 624825a18ac4e074dc43b07af7c52e66007dd246..9e1811fe158bce0d2e880d08d8ef222e8ac4d895 100644 (file)
@@ -178,6 +178,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_shape_key_remove);
        WM_operatortype_append(OBJECT_OT_shape_key_clear);
        WM_operatortype_append(OBJECT_OT_shape_key_mirror);
+       WM_operatortype_append(OBJECT_OT_shape_key_move);
 
        WM_operatortype_append(LATTICE_OT_select_all_toggle);
        WM_operatortype_append(LATTICE_OT_make_regular);
index 61ea9ab44a0e7a579fbd1488a6b828fbb57d892f..53970596f55f162e0381912d5a055ffddb9acc62 100644 (file)
@@ -660,3 +660,63 @@ void OBJECT_OT_shape_key_mirror(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
+static int shape_key_move_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+       int type= RNA_enum_get(op->ptr, "type");
+       Key *key= ob_get_key(ob);
+
+       if(key) {
+               KeyBlock *kb, *kb_other;
+               kb= BLI_findlink(&key->block, ob->shapenr-1);
+
+               if(type==-1) {
+                       /* move back */
+                       if(kb->prev) {
+                               kb_other= kb->prev;
+                               BLI_remlink(&key->block, kb);
+                               BLI_insertlinkbefore(&key->block, kb_other, kb);
+                               ob->shapenr--;
+                       }
+               }
+               else {
+                       /* move next */
+                       if(kb->next) {
+                               kb_other= kb->next;
+                               BLI_remlink(&key->block, kb);
+                               BLI_insertlinkafter(&key->block, kb_other, kb);
+                               ob->shapenr++;
+                       }
+               }
+       }
+
+       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_shape_key_move(wmOperatorType *ot)
+{
+       static EnumPropertyItem slot_move[] = {
+               {-1, "UP", 0, "Up", ""},
+               {1, "DOWN", 0, "Down", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* identifiers */
+       ot->name= "Move Shape Key";
+       ot->idname= "OBJECT_OT_shape_key_move";
+
+       /* api callbacks */
+       ot->poll= shape_key_poll;
+       ot->exec= shape_key_move_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
+}
+