2.5
[blender-staging.git] / source / blender / editors / screen / screen_ops.c
index d06259d1487e0e9c1f3c956be1f086f406d187fc..c991a63e762c4786c91deb67b52079e6c009e99b 100644 (file)
@@ -47,6 +47,7 @@
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_mesh.h"
 #include "BKE_multires.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
@@ -217,14 +218,14 @@ int ED_operator_uvedit(bContext *C)
        EditMesh *em= NULL;
 
        if(obedit && obedit->type==OB_MESH)
-               em= EM_GetEditMesh((Mesh *)obedit->data);
+               em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
        if(em && (em->faces.first) && (CustomData_has_layer(&em->fdata, CD_MTFACE))) {
-               EM_EndEditMesh(obedit->data, em);
+               BKE_mesh_end_editmesh(obedit->data, em);
                return 1;
        }
 
-       EM_EndEditMesh(obedit->data, em);
+       BKE_mesh_end_editmesh(obedit->data, em);
        return 0;
 }
 
@@ -234,14 +235,14 @@ int ED_operator_uvmap(bContext *C)
        EditMesh *em= NULL;
 
        if(obedit && obedit->type==OB_MESH)
-               em= EM_GetEditMesh((Mesh *)obedit->data);
+               em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
        if(em && (em->faces.first)) {
-               EM_EndEditMesh(obedit->data, em);
+               BKE_mesh_end_editmesh(obedit->data, em);
                return 1;
        }
 
-       EM_EndEditMesh(obedit->data, em);
+       BKE_mesh_end_editmesh(obedit->data, em);
        return 0;
 }
 
@@ -1572,19 +1573,21 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
        wmOperator *lastop;
-       uiMenuItem *head;
+       uiPopupMenu *pup;
+       uiLayout *layout;
        int items, i;
        
        items= BLI_countlist(&wm->operators);
        if(items==0)
                return OPERATOR_CANCELLED;
        
-       head= uiPupMenuBegin(op->type->name, 0);
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
 
        for (i=items-1, lastop= wm->operators.last; lastop; lastop= lastop->prev, i--)
-               uiMenuItemIntO(head, lastop->type->name, 0, op->type->idname, "index", i);
+               uiItemIntO(layout, lastop->type->name, 0, op->type->idname, "index", i);
 
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        return OPERATOR_CANCELLED;
 }
@@ -1622,44 +1625,6 @@ void SCREEN_OT_repeat_history(wmOperatorType *ot)
 
 /* ********************** redo operator ***************************** */
 
-static void redo_last_cb(bContext *C, void *arg_op, void *arg2)
-{
-       wmOperator *lastop= arg_op;
-       
-       if(lastop) {
-               ED_undo_pop(C);
-               WM_operator_repeat(C, lastop);
-       }
-       
-}
-
-static uiBlock *ui_block_create_redo_last(bContext *C, ARegion *ar, void *arg_op)
-{
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *op= arg_op;
-       PointerRNA ptr;
-       uiBlock *block;
-       int height;
-       
-       block= uiBeginBlock(C, ar, "redo_last_popup", UI_EMBOSS, UI_HELV);
-       uiBlockClearFlag(block, UI_BLOCK_LOOP);
-       uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
-       uiBlockSetFunc(block, redo_last_cb, arg_op, NULL);
-
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       height= uiDefAutoButsRNA(C, block, &ptr);
-
-       uiPopupBoundsBlock(block, 4.0f, 0, 0);
-       uiEndBlock(C, block);
-
-       return block;
-}
-
 static int redo_last_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
@@ -1670,10 +1635,8 @@ static int redo_last_invoke(bContext *C, wmOperator *op, wmEvent *event)
                if((lastop->type->flag & OPTYPE_REGISTER) && (lastop->type->flag & OPTYPE_UNDO))
                        break;
        
-       if(!lastop)
-               return OPERATOR_CANCELLED;
-
-       uiPupBlock(C, ui_block_create_redo_last, lastop);
+       if(lastop)
+               WM_operator_redo_popup(C, lastop);
 
        return OPERATOR_CANCELLED;
 }
@@ -1852,27 +1815,28 @@ static void testfunc(bContext *C, void *argv, int arg)
        printf("arg %d\n", arg);
 }
 
-static void newlevel1(bContext *C, uiMenuItem *head, void *arg)
+static void newlevel1(bContext *C, uiLayout *layout, void *arg)
 {
-       uiMenuFunc(head, testfunc, NULL);
+       uiLayoutFunc(layout, testfunc, NULL);
        
-       uiMenuItemVal(head, "First", ICON_PROP_ON, 1);
-       uiMenuItemVal(head, "Second", ICON_PROP_CON, 2);
-       uiMenuItemVal(head, "Third", ICON_SMOOTHCURVE, 3);
-       uiMenuItemVal(head, "Fourth", ICON_SHARPCURVE, 4);      
+       uiItemV(layout, "First", ICON_PROP_ON, 1);
+       uiItemV(layout, "Second", ICON_PROP_CON, 2);
+       uiItemV(layout, "Third", ICON_SMOOTHCURVE, 3);
+       uiItemV(layout, "Fourth", ICON_SHARPCURVE, 4);  
 }
 
 static int testing123(bContext *C, wmOperator *op, wmEvent *event)
 {
-       uiMenuItem *head= uiPupMenuBegin("Hello world", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Hello world", 0);
+       uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiMenuContext(head, WM_OP_EXEC_DEFAULT);
-       uiMenuItemO(head, ICON_PROP_ON, "SCREEN_OT_region_flip");
-       uiMenuItemO(head, ICON_PROP_CON, "SCREEN_OT_screen_full_area");
-       uiMenuItemO(head, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit");
-       uiMenuLevel(head, "Submenu", newlevel1);
+       uiLayoutContext(layout, WM_OP_EXEC_DEFAULT);
+       uiItemO(layout, NULL, ICON_PROP_ON, "SCREEN_OT_region_flip");
+       uiItemO(layout, NULL, ICON_PROP_CON, "SCREEN_OT_screen_full_area");
+       uiItemO(layout, NULL, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit");
+       uiItemMenuF(layout, "Submenu", 0, newlevel1);
        
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        /* this operator is only for a menu, not used further */
        return OPERATOR_CANCELLED;
@@ -1895,17 +1859,65 @@ void SCREEN_OT_region_flip(wmOperatorType *ot)
 
 }
 
-/* ****************** anim player, typically with timer ***************** */
+/* ****************** anim player, with timer ***************** */
 
-static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
+static int match_region_with_redraws(int spacetype, int regiontype, int redraws)
+{
+       if(regiontype==RGN_TYPE_WINDOW) {
+
+               switch (spacetype) {
+                       case SPACE_VIEW3D:
+                               if(redraws & TIME_ALL_3D_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_IPO:
+                       case SPACE_ACTION:
+                       case SPACE_NLA:
+                               if(redraws & TIME_ALL_ANIM_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_TIME:
+                               /* if only 1 window or 3d windows, we do timeline too */
+                               if(redraws & (TIME_ALL_ANIM_WIN|TIME_REGION|TIME_ALL_3D_WIN))
+                                       return 1;
+                               break;
+                       case SPACE_BUTS:
+                               if(redraws & TIME_ALL_BUTS_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_SEQ:
+                               if(redraws & (TIME_SEQ|TIME_ALL_ANIM_WIN))
+                                       return 1;
+                               break;
+                       case SPACE_IMAGE:
+                               if(redraws & TIME_ALL_IMAGE_WIN)
+                                       return 1;
+                               break;
+                               
+               }
+       }
+       else if(regiontype==RGN_TYPE_UI) {
+               if(redraws & TIME_ALL_BUTS_WIN)
+                       return 1;
+       }
+       else if(regiontype==RGN_TYPE_HEADER) {
+               if(spacetype==SPACE_TIME)
+                       return 1;
+       }
+       return 0;
+}
+
+static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
 {
        bScreen *screen= CTX_wm_screen(C);
        
        if(screen->animtimer==event->customdata) {
                Scene *scene= CTX_data_scene(C);
+               wmTimer *wt= screen->animtimer;
+               ScreenAnimData *sad= wt->customdata;
+               ScrArea *sa;
                
                if(scene->audio.flag & AUDIO_SYNC) {
-                       wmTimer *wt= screen->animtimer;
                        int step = floor(wt->duration * FPS);
                        scene->r.cfra += step;
                        wt->duration -= ((float)step)/FPS;
@@ -1922,13 +1934,65 @@ static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
                                scene->r.cfra= scene->r.sfra;
                }
 
-               WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+               /* since we follow drawflags, we can't send notifier but tag regions ourselves */
+               ED_update_for_newframe(C, 1);
+               
+               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                       ARegion *ar;
+                       for(ar= sa->regionbase.first; ar; ar= ar->next) {
+                               if(ar==sad->ar)
+                                       ED_region_tag_redraw(ar);
+                               else
+                                       if(match_region_with_redraws(sa->spacetype, ar->regiontype, sad->redraws))
+                                               ED_region_tag_redraw(ar);
+                       }
+               }
+               
+               //WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
                
                return OPERATOR_FINISHED;
        }
        return OPERATOR_PASS_THROUGH;
 }
 
+static void SCREEN_OT_animation_step(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Animation Step";
+       ot->idname= "SCREEN_OT_animation_step";
+       
+       /* api callbacks */
+       ot->invoke= screen_animation_step;
+       
+       ot->poll= ED_operator_screenactive;
+       
+}
+
+/* ****************** anim player, starts or ends timer ***************** */
+
+/* toggle operator */
+static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
+{
+       bScreen *screen= CTX_wm_screen(C);
+       
+       if(screen->animtimer) {
+               ED_screen_animation_timer(C, 0, 0);
+       }
+       else {
+               /* todo: RNA properties to define play types */
+               ED_screen_animation_timer(C, TIME_REGION|TIME_ALL_3D_WIN, 1);
+               
+               if(screen->animtimer) {
+                       wmTimer *wt= screen->animtimer;
+                       ScreenAnimData *sad= wt->customdata;
+                       
+                       sad->ar= CTX_wm_region(C);
+               }
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
 void SCREEN_OT_animation_play(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1940,6 +2004,7 @@ void SCREEN_OT_animation_play(wmOperatorType *ot)
        
        ot->poll= ED_operator_screenactive;
        
+       
 }
 
 /* ************** border select operator (template) ***************************** */
@@ -2015,7 +2080,7 @@ static ScrArea *biggest_non_image_area(bContext *C)
        short foundwin= 0;
        
        for(sa= sc->areabase.first; sa; sa= sa->next) {
-               if(sa->winx > 10 && sa->winy > 10) {
+               if(sa->winx > 30 && sa->winy > 30) {
                        size= sa->winx*sa->winy;
                        if(sa->spacetype == SPACE_BUTS) {
                                if(foundwin == 0 && size > bwmaxsize) {
@@ -2436,6 +2501,7 @@ void ED_operatortypes_screen(void)
        
        /*frame changes*/
        WM_operatortype_append(SCREEN_OT_frame_offset);
+       WM_operatortype_append(SCREEN_OT_animation_step);
        WM_operatortype_append(SCREEN_OT_animation_play);
        
        /* render */
@@ -2454,7 +2520,7 @@ void ED_keymap_screen(wmWindowManager *wm)
        ListBase *keymap= WM_keymap_listbase(wm, "Screen", 0, 0);
        
        /* standard timers */
-       WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", TIMER0, KM_ANY, KM_ANY, 0);
+       WM_keymap_add_item(keymap, "SCREEN_OT_animation_step", TIMER0, KM_ANY, KM_ANY, 0);
        
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, 0, 0)->ptr, "modifier", 0);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "modifier", 1);
@@ -2482,6 +2548,9 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "SCREEN_OT_region_flip", F5KEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0);
+       
+       RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", F7KEY, KM_PRESS, 0, 0)->ptr, "filename", "test.py");
+       WM_keymap_verify_item(keymap, "SCRIPT_OT_python_run_ui_scripts", F8KEY, KM_PRESS, 0, 0);
 
        /* files */
        WM_keymap_add_item(keymap, "FILE_OT_exec", RETKEY, KM_PRESS, 0, 0);
@@ -2497,12 +2566,13 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "SCREEN_OT_render_view_cancel", ESCKEY, KM_PRESS, 0, 0);
        
-       /* frame offsets */
+       /* frame offsets & play */
        keymap= WM_keymap_listbase(wm, "Frames", 0, 0);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 10);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -10);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -1);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
+       WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT, 0);
        
 }