operator renaming for more consistent word ordering (_add/_remmove shold be last...
[blender.git] / source / blender / editors / animation / anim_ops.c
index f9247579c06a7d305f1eb660c4411b38f8f56d38..6c8a982b3235a635accbc94f49a7b1c215cc0f8d 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -41,6 +42,7 @@
 
 #include "BKE_context.h"
 #include "BKE_utildefines.h"
+#include "BKE_sound.h"
 
 #include "UI_interface.h"
 #include "UI_view2d.h"
 #include "WM_types.h"
 
 #include "ED_anim_api.h"
+#include "ED_keyframing.h"
 #include "ED_markers.h"
 #include "ED_screen.h"
 
+#include "anim_intern.h"
+
 /* ********************** frame change operator ***************************/
 
+/* Check if the operator can be run from the current context */
+static int change_frame_poll(bContext *C)
+{
+       ScrArea *curarea= CTX_wm_area(C);
+       
+       /* as long as there is an active area, and it isn't a Graph Editor 
+        * (since the Graph Editor has its own version which does extra stuff),
+        * we're fine
+        */
+       return ((curarea) && (curarea->spacetype != SPACE_IPO));
+}
+
 /* Set any flags that are necessary to indicate modal time-changing operation */
 static int change_frame_init(bContext *C, wmOperator *op)
 {
@@ -66,7 +83,7 @@ static int change_frame_init(bContext *C, wmOperator *op)
                return 0;
        
        if (curarea->spacetype == SPACE_TIME) {
-               SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
+               SpaceTime *stime= CTX_wm_space_time(C);
                
                /* timeline displays frame number only when dragging indicator */
                // XXX make this more in line with other anim editors?
@@ -80,14 +97,12 @@ static int change_frame_init(bContext *C, wmOperator *op)
 static void change_frame_apply(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
-       int cfra;
-       
-       /* get frame, and clamp to MINFRAME */
-       cfra= RNA_int_get(op->ptr, "frame");
        
-       if (cfra < MINFRAME) cfra= MINFRAME;
-       CFRA= cfra;
+       /* set the new frame number */
+       CFRA= RNA_int_get(op->ptr, "frame");
        
+       /* do updates */
+       sound_scrub(C);
        WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
 }
 
@@ -100,7 +115,7 @@ static void change_frame_exit(bContext *C, wmOperator *op)
                return;
        
        if (curarea->spacetype == SPACE_TIME) {
-               SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
+               SpaceTime *stime= CTX_wm_space_time(C);
                
                /* timeline displays frame number only when dragging indicator */
                // XXX make this more in line with other anim editors?
@@ -118,6 +133,7 @@ static int change_frame_exec(bContext *C, wmOperator *op)
        
        change_frame_apply(C, op);
        change_frame_exit(C, op);
+
        return OPERATOR_FINISHED;
 }
 
@@ -154,7 +170,7 @@ static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event)
        change_frame_apply(C, op);
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+       WM_event_add_modal_handler(C, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -171,13 +187,21 @@ static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        /* execute the events */
        switch (event->type) {
+               case ESCKEY:
+                       change_frame_exit(C, op);
+                       return OPERATOR_FINISHED;
+               
                case MOUSEMOVE:
                        RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
                        change_frame_apply(C, op);
                        break;
-                       
-               case LEFTMOUSE:
-                       if (event->val==0) {
+               
+               case LEFTMOUSE: 
+               case RIGHTMOUSE:
+                       /* we check for either mouse-button to end, as checking for ACTIONMOUSE (which is used to init 
+                        * the modal op) doesn't work for some reason
+                        */
+                       if (event->val==KM_RELEASE) {
                                change_frame_exit(C, op);
                                return OPERATOR_FINISHED;
                        }
@@ -189,20 +213,23 @@ static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event)
 
 void ANIM_OT_change_frame(wmOperatorType *ot)
 {
-       PropertyRNA *prop;
-
        /* identifiers */
        ot->name= "Change frame";
        ot->idname= "ANIM_OT_change_frame";
+       ot->description= "Interactively change the current frame number.";
        
        /* api callbacks */
        ot->exec= change_frame_exec;
        ot->invoke= change_frame_invoke;
        ot->cancel= change_frame_cancel;
        ot->modal= change_frame_modal;
+       ot->poll= change_frame_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_BLOCKING;
 
        /* rna */
-       prop= RNA_def_property(ot->srna, "frame", PROP_INT, PROP_NONE);
+       RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
 }
 
 /* ****************** set preview range operator ****************************/
@@ -233,14 +260,17 @@ static int previewrange_define_exec(bContext *C, wmOperator *op)
        scene->r.psfra= (int)floor(sfra + 0.5f);
        scene->r.pefra= (int)floor(efra + 0.5f);
        
+       /* send notifiers */
+       WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+       
        return OPERATOR_FINISHED;
 } 
 
-void ANIM_OT_previewrange_define(wmOperatorType *ot)
+void ANIM_OT_previewrange_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Preview Range";
-       ot->idname= "ANIM_OT_previewrange_define";
+       ot->idname= "ANIM_OT_previewrange_set";
        
        /* api callbacks */
        ot->invoke= WM_border_select_invoke;
@@ -249,13 +279,16 @@ void ANIM_OT_previewrange_define(wmOperatorType *ot)
        
        ot->poll= ED_operator_areaactive;
        
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
        /* rna */
                /* used to define frame range */
-       RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
-       RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
+       RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
                /* these are not used, but are needed by borderselect gesture operator stuff */
-       RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
-       RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
+       RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
 }
 
 /* ****************** clear preview range operator ****************************/
@@ -275,8 +308,6 @@ static int previewrange_clear_exec(bContext *C, wmOperator *op)
        
        ED_area_tag_redraw(curarea);
        
-       //BIF_undo_push("Clear Preview Range");
-       
        return OPERATOR_FINISHED;
 } 
 
@@ -288,6 +319,11 @@ void ANIM_OT_previewrange_clear(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= previewrange_clear_exec;
+       
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /* ****************** time display toggle operator ****************************/
@@ -304,31 +340,31 @@ static int toggle_time_exec(bContext *C, wmOperator *op)
        switch (curarea->spacetype) {
                case SPACE_TIME: /* TimeLine */
                {
-                       SpaceTime *stime= (SpaceTime *)CTX_wm_space_data(C);
+                       SpaceTime *stime= CTX_wm_space_time(C);
                        stime->flag ^= TIME_DRAWFRAMES;
                }
                        break;
                case SPACE_ACTION: /* Action Editor */
                {
-                       SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
+                       SpaceAction *saction= CTX_wm_space_action(C);
                        saction->flag ^= SACTION_DRAWTIME;
                }
                        break;
-               case SPACE_IPO: /* IPO Editor */
+               case SPACE_IPO: /* Graph Editor */
                {
-                       SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
+                       SpaceIpo *sipo= CTX_wm_space_graph(C);
                        sipo->flag ^= SIPO_DRAWTIME;
                }
                        break;
                case SPACE_NLA: /* NLA Editor */
                {
-                       SpaceNla *snla= (SpaceNla *)CTX_wm_space_data(C);
+                       SpaceNla *snla= CTX_wm_space_nla(C);
                        snla->flag ^= SNLA_DRAWTIME;
                }
                        break;
                case SPACE_SEQ: /* Sequencer */
                {
-                       SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
+                       SpaceSeq *sseq= CTX_wm_space_seq(C);
                        sseq->flag ^= SEQ_DRAWFRAMES;
                }
                        break;
@@ -342,36 +378,65 @@ static int toggle_time_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void ANIM_OT_toggle_time(wmOperatorType *ot)
+void ANIM_OT_time_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Toggle Frames/Seconds";
-       ot->idname= "ANIM_OT_toggle_time";
+       ot->idname= "ANIM_OT_time_toggle";
        
        /* api callbacks */
        ot->exec= toggle_time_exec;
+       
+       ot->poll= ED_operator_areaactive;
 }
 
 /* ************************** registration **********************************/
 
 void ED_operatortypes_anim(void)
 {
+       /* Animation Editors only -------------------------- */
        WM_operatortype_append(ANIM_OT_change_frame);
-       WM_operatortype_append(ANIM_OT_toggle_time);
+       WM_operatortype_append(ANIM_OT_time_toggle);
        
-       WM_operatortype_append(ANIM_OT_previewrange_define);
+       WM_operatortype_append(ANIM_OT_previewrange_set);
        WM_operatortype_append(ANIM_OT_previewrange_clear);
+       
+       /* Entire UI --------------------------------------- */
+       WM_operatortype_append(ANIM_OT_keyframe_insert);
+       WM_operatortype_append(ANIM_OT_keyframe_delete);
+       WM_operatortype_append(ANIM_OT_keyframe_insert_menu);
+       WM_operatortype_append(ANIM_OT_keyframe_delete_v3d);
+       WM_operatortype_append(ANIM_OT_keyframe_insert_button);
+       WM_operatortype_append(ANIM_OT_keyframe_delete_button);
+       
+       
+       WM_operatortype_append(ANIM_OT_driver_button_add);
+       WM_operatortype_append(ANIM_OT_driver_button_remove);
+       WM_operatortype_append(ANIM_OT_copy_driver_button);
+       WM_operatortype_append(ANIM_OT_paste_driver_button);
+       
+       WM_operatortype_append(ANIM_OT_copy_clipboard_button);
+
+       
+       WM_operatortype_append(ANIM_OT_keyingset_button_add);
+       WM_operatortype_append(ANIM_OT_keyingset_button_remove);
+       
+       WM_operatortype_append(ANIM_OT_keying_set_add);
+       WM_operatortype_append(ANIM_OT_keying_set_remove);
+       WM_operatortype_append(ANIM_OT_keying_set_path_add);
+       WM_operatortype_append(ANIM_OT_keying_set_path_remove);
 }
 
-void ED_keymap_anim(wmWindowManager *wm)
+void ED_keymap_anim(wmKeyConfig *keyconf)
 {
-       ListBase *keymap= WM_keymap_listbase(wm, "Animation", 0, 0);
+       wmKeyMap *keymap= WM_keymap_find(keyconf, "Animation", 0, 0);
        
-       WM_keymap_verify_item(keymap, "ANIM_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ANIM_OT_toggle_time", TKEY, KM_PRESS, KM_CTRL, 0);
+       /* frame management */
+               /* NOTE: 'ACTIONMOUSE' not 'LEFTMOUSE', as user may have swapped mouse-buttons */
+       WM_keymap_add_item(keymap, "ANIM_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "ANIM_OT_time_toggle", TKEY, KM_PRESS, KM_CTRL, 0);
        
-               /* preview range */
-       WM_keymap_verify_item(keymap, "ANIM_OT_previewrange_define", PKEY, KM_PRESS, KM_CTRL, 0);
+       /* preview range */
+       WM_keymap_verify_item(keymap, "ANIM_OT_previewrange_set", PKEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ANIM_OT_previewrange_clear", PKEY, KM_PRESS, KM_ALT, 0);
 }
-