Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Sat, 20 Jan 2018 13:55:08 +0000 (00:55 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 20 Jan 2018 13:55:08 +0000 (00:55 +1100)
1  2 
source/blender/editors/screen/screen_ops.c

index 3f52d232a39db43907d1b2438a63e0b6f3ab7ef6,e43f95f788b48407337f5ea413c85b19aa569cef..d0cdf77d3cc63dd3e6b9f9d158c9ef0911d2b86f
  #include "DNA_meta_types.h"
  #include "DNA_mask_types.h"
  #include "DNA_node_types.h"
 +#include "DNA_workspace_types.h"
  #include "DNA_userdef_types.h"
  
  #include "BKE_context.h"
  #include "BKE_customdata.h"
  #include "BKE_global.h"
 +#include "BKE_icons.h"
  #include "BKE_main.h"
  #include "BKE_object.h"
  #include "BKE_report.h"
@@@ -63,7 -61,6 +63,7 @@@
  #include "BKE_editmesh.h"
  #include "BKE_sound.h"
  #include "BKE_mask.h"
 +#include "BKE_workspace.h"
  
  #include "WM_api.h"
  #include "WM_types.h"
@@@ -574,8 -571,8 +574,8 @@@ int ED_operator_mask(bContext *C
                        case SPACE_IMAGE:
                        {
                                SpaceImage *sima = sa->spacedata.first;
 -                              Scene *scene = CTX_data_scene(C);
 -                              return ED_space_image_check_show_maskedit(scene, sima);
 +                              ViewLayer *view_layer = CTX_data_view_layer(C);
 +                              return ED_space_image_check_show_maskedit(view_layer, sima);
                        }
                }
        }
        return false;
  }
  
 +int ED_operator_camera(bContext *C)
 +{
 +      struct Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
 +      return (cam != NULL);
 +}
 +
  /* *************************** action zone operator ************************** */
  
  /* operator state vars used:  
@@@ -986,17 -977,13 +986,17 @@@ static void SCREEN_OT_area_swap(wmOpera
  /* operator callback */
  static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event)
  {
 -      wmWindow *newwin, *win;
 -      bScreen *newsc, *sc;
 +      wmWindow *newwin, *win = CTX_wm_window(C);
 +      Scene *scene;
 +      WorkSpace *workspace = WM_window_get_active_workspace(win);
 +      WorkSpaceLayout *layout_old = WM_window_get_active_layout(win);
 +      WorkSpaceLayout *layout_new;
 +      bScreen *newsc;
        ScrArea *sa;
        rcti rect;
        
        win = CTX_wm_window(C);
 -      sc = CTX_wm_screen(C);
 +      scene = CTX_data_scene(C);
        sa = CTX_wm_area(C);
        
        /* XXX hrmf! */
        }
  
        *newwin->stereo3d_format = *win->stereo3d_format;
 -      
 +
 +      newwin->scene = scene;
 +
 +      WM_window_set_active_workspace(newwin, workspace);
        /* allocs new screen and adds to newly created window, using window size */
 -      newsc = ED_screen_add(newwin, CTX_data_scene(C), sc->id.name + 2);
 -      newwin->screen = newsc;
 -      
 +      layout_new = ED_workspace_layout_add(workspace, newwin, BKE_workspace_layout_name_get(layout_old));
 +      newsc = BKE_workspace_layout_screen_get(layout_new);
 +      WM_window_set_active_layout(newwin, workspace, layout_new);
 +
        /* copy area to new screen */
        ED_area_data_copy((ScrArea *)newsc->areabase.first, sa, true);
  
@@@ -1281,8 -1264,6 +1281,8 @@@ static void area_move_apply_do
                        }
                }
                WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); /* redraw everything */
 +              /* Update preview thumbnail */
 +              BKE_icon_changed(sc->id.icon_id);
        }
  }
  
@@@ -1576,9 -1557,7 +1576,9 @@@ static int area_split_apply(bContext *C
                ED_area_tag_redraw(sd->narea);
  
                WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
 -              
 +              /* Update preview thumbnail */
 +              BKE_icon_changed(sc->id.icon_id);
 +
                return 1;
        }
        
@@@ -1607,6 -1586,12 +1607,12 @@@ static void area_split_exit(bContext *C
        removedouble_scredges(CTX_wm_screen(C));
  }
  
+ static void area_split_preview_update_cursor(bContext *C, wmOperator *op)
+ {
+       wmWindow *win = CTX_wm_window(C);
+       int dir = RNA_enum_get(op->ptr, "direction");
+       WM_cursor_set(win, (dir == 'v') ? CURSOR_X_MOVE : CURSOR_Y_MOVE);
+ }
  
  /* UI callback, adds new handler */
  static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                sd->draw_callback = WM_draw_cb_activate(win, area_split_draw_cb, op);
                /* add temp handler for edge move or cancel */
                WM_event_add_modal_handler(C, op);
-               
+               area_split_preview_update_cursor(C, op);
                return OPERATOR_RUNNING_MODAL;
                
        }
@@@ -1747,14 -1733,15 +1754,15 @@@ static void area_split_cancel(bContext 
  static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
  {
        sAreaSplitData *sd = (sAreaSplitData *)op->customdata;
-       float fac;
-       int dir;
-       
+       PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction");
+       bool update_factor = false;
        /* execute the events */
        switch (event->type) {
                case MOUSEMOVE:
-                       dir = RNA_enum_get(op->ptr, "direction");
-                       
+               {
+                       const int dir = RNA_property_enum_get(op->ptr, prop_dir);
                        sd->delta = (dir == 'v') ? event->x - sd->origval : event->y - sd->origval;
                        if (sd->previewmode == 0)
                                area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, sd->do_snap);
                                }
                                /* area context not set */
                                sd->sarea = BKE_screen_find_area_xy(CTX_wm_screen(C), SPACE_TYPE_ANY, event->x, event->y);
-                               
                                if (sd->sarea) {
                                        ED_area_tag_redraw(sd->sarea);
-                                       if (dir == 'v') {
-                                               sd->origsize = sd->sarea->winx;
-                                               sd->origmin = sd->sarea->totrct.xmin;
-                                       }
-                                       else {
-                                               sd->origsize = sd->sarea->winy;
-                                               sd->origmin = sd->sarea->totrct.ymin;
-                                       }
-                                       if (sd->do_snap) {
-                                               ScrArea *sa = sd->sarea;
-                                               sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 1;
-                                               int snap_loc = area_snap_calc_location(
-                                                       CTX_wm_screen(C), sd->delta, sd->origval, dir, sd->origmin + sd->origsize, -sd->origmin);
-                                               sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 0;
-                                               fac = snap_loc - sd->origmin;
-                                       }
-                                       else {
-                                               fac = (dir == 'v') ? event->x - sd->origmin : event->y - sd->origmin;
-                                       }
-                                       RNA_float_set(op->ptr, "factor", fac / (float)sd->origsize);
+                                       update_factor = true;
                                }
  
 -                              CTX_wm_window(C)->screen->do_draw = true;
 -
 +                              CTX_wm_screen(C)->do_draw = true;
                        }
                        break;
-                       
+               }
                case LEFTMOUSE:
                        if (sd->previewmode) {
                                area_split_apply(C, op);
                case MIDDLEMOUSE:
                case TABKEY:
                        if (sd->previewmode == 0) {
+                               /* pass */
                        }
                        else {
-                               dir = RNA_enum_get(op->ptr, "direction");
-                               
                                if (event->val == KM_PRESS) {
                                        if (sd->sarea) {
+                                               int dir = RNA_property_enum_get(op->ptr, prop_dir);
+                                               RNA_property_enum_set(op->ptr, prop_dir, (dir == 'v') ? 'h' : 'v');
+                                               area_split_preview_update_cursor(C, op);
+                                               update_factor = true;
                                                ED_area_tag_redraw(sd->sarea);
-                                               
-                                               if (dir == 'v') {
-                                                       RNA_enum_set(op->ptr, "direction", 'h');
-                                                       WM_cursor_set(CTX_wm_window(C), CURSOR_X_MOVE);
-                                               }
-                                               else {
-                                                       RNA_enum_set(op->ptr, "direction", 'v');
-                                                       WM_cursor_set(CTX_wm_window(C), CURSOR_Y_MOVE);
-                                               }
                                        }
                                }
                        }
  
                case LEFTCTRLKEY:
                        sd->do_snap = event->val == KM_PRESS;
+                       update_factor = true;
                        break;
        }
-       
+       if (update_factor) {
+               const int dir = RNA_property_enum_get(op->ptr, prop_dir);
+               float fac;
+               if (dir == 'v') {
+                       sd->origsize = sd->sarea->winx;
+                       sd->origmin = sd->sarea->totrct.xmin;
+               }
+               else {
+                       sd->origsize = sd->sarea->winy;
+                       sd->origmin = sd->sarea->totrct.ymin;
+               }
+               if (sd->do_snap) {
+                       ScrArea *sa = sd->sarea;
+                       sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 1;
+                       int snap_loc = area_snap_calc_location(
+                               CTX_wm_screen(C), sd->delta, sd->origval, dir, sd->origmin + sd->origsize, -sd->origmin);
+                       sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 0;
+                       fac = snap_loc - sd->origmin;
+               }
+               else {
+                       fac = (dir == 'v') ? event->x - sd->origmin : event->y - sd->origmin;
+               }
+               RNA_float_set(op->ptr, "factor", fac / (float)sd->origsize);
+       }
        return OPERATOR_RUNNING_MODAL;
  }
  
@@@ -2157,11 -2147,12 +2167,11 @@@ static void areas_do_frame_follow(bCont
        bScreen *scr = CTX_wm_screen(C);
        Scene *scene = CTX_data_scene(C);
        wmWindowManager *wm = CTX_wm_manager(C);
 -      wmWindow *window;
 -      for (window = wm->windows.first; window; window = window->next) {
 -              ScrArea *sa;
 -              for (sa = window->screen->areabase.first; sa; sa = sa->next) {
 -                      ARegion *ar;
 -                      for (ar = sa->regionbase.first; ar; ar = ar->next) {
 +      for (wmWindow *window = wm->windows.first; window; window = window->next) {
 +              const bScreen *screen = WM_window_get_active_screen(window);
 +
 +              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                      for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
                                /* do follow here if editor type supports it */
                                if ((scr->redraws_flag & TIME_FOLLOW)) {
                                        if ((ar->regiontype == RGN_TYPE_WINDOW &&
@@@ -2460,16 -2451,64 +2470,16 @@@ static void SCREEN_OT_marker_jump(wmOpe
  
  /* ************** switch screen operator ***************************** */
  
 -static bool screen_set_is_ok(bScreen *screen, bScreen *screen_prev)
 -{
 -      return ((screen->winid == 0) &&
 -              /* in typical usage these should have a nonzero winid
 -               * (all temp screens should be used, or closed & freed). */
 -              (screen->temp == false) &&
 -              (screen->state == SCREENNORMAL) &&
 -              (screen != screen_prev) &&
 -              (screen->id.name[2] != '.' || !(U.uiflag & USER_HIDE_DOT)));
 -}
 -
  /* function to be called outside UI context, or for redo */
  static int screen_set_exec(bContext *C, wmOperator *op)
  {
 -      Main *bmain = CTX_data_main(C);
 -      bScreen *screen = CTX_wm_screen(C);
 -      bScreen *screen_prev = screen;
 -      
 -      ScrArea *sa = CTX_wm_area(C);
 -      int tot = BLI_listbase_count(&bmain->screen);
 +      WorkSpace *workspace = CTX_wm_workspace(C);
        int delta = RNA_int_get(op->ptr, "delta");
 -      
 -      /* temp screens are for userpref or render display */
 -      if (screen->temp || (sa && sa->full && sa->full->temp)) {
 -              return OPERATOR_CANCELLED;
 -      }
 -      
 -      if (delta == 1) {
 -              while (tot--) {
 -                      screen = screen->id.next;
 -                      if (screen == NULL) screen = bmain->screen.first;
 -                      if (screen_set_is_ok(screen, screen_prev)) {
 -                              break;
 -                      }
 -              }
 -      }
 -      else if (delta == -1) {
 -              while (tot--) {
 -                      screen = screen->id.prev;
 -                      if (screen == NULL) screen = bmain->screen.last;
 -                      if (screen_set_is_ok(screen, screen_prev)) {
 -                              break;
 -                      }
 -              }
 -      }
 -      else {
 -              screen = NULL;
 -      }
 -      
 -      if (screen && screen_prev != screen) {
 -              /* return to previous state before switching screens */
 -              if (sa && sa->full) {
 -                      ED_screen_full_restore(C, sa); /* may free 'screen_prev' */
 -              }
 -              
 -              ED_screen_set(C, screen);
 +
 +      if (ED_workspace_layout_cycle(workspace, delta, C)) {
                return OPERATOR_FINISHED;
        }
 +
        return OPERATOR_CANCELLED;
  }
  
@@@ -3272,7 -3311,7 +3282,7 @@@ static int header_toggle_menus_exec(bCo
        sa->flag = sa->flag ^ HEADER_NO_PULLDOWN;
  
        ED_area_tag_redraw(sa);
 -      WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);  
 +      WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
  
        return OPERATOR_FINISHED;
  }
@@@ -3456,8 -3495,6 +3466,8 @@@ static int screen_animation_step(bConte
        if (screen->animtimer && screen->animtimer == event->customdata) {
                Main *bmain = CTX_data_main(C);
                Scene *scene = CTX_data_scene(C);
 +              ViewLayer *view_layer = CTX_data_view_layer(C);
 +              struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
                wmTimer *wt = screen->animtimer;
                ScreenAnimData *sad = wt->customdata;
                wmWindowManager *wm = CTX_wm_manager(C);
                }
                
                /* since we follow drawflags, we can't send notifier but tag regions ourselves */
 -              ED_update_for_newframe(bmain, scene, 1);
 +              ED_update_for_newframe(bmain, scene, view_layer, depsgraph);
  
                for (window = wm->windows.first; window; window = window->next) {
 -                      for (sa = window->screen->areabase.first; sa; sa = sa->next) {
 +                      const bScreen *win_screen = WM_window_get_active_screen(window);
 +
 +                      for (sa = win_screen->areabase.first; sa; sa = sa->next) {
                                ARegion *ar;
                                for (ar = sa->regionbase.first; ar; ar = ar->next) {
                                        bool redraw = false;
@@@ -3647,11 -3682,11 +3657,11 @@@ static void SCREEN_OT_animation_step(wm
  /* find window that owns the animation timer */
  bScreen *ED_screen_animation_playing(const wmWindowManager *wm)
  {
 -      wmWindow *win;
 +      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +              bScreen *screen = WM_window_get_active_screen(win);
  
 -      for (win = wm->windows.first; win; win = win->next) {
 -              if (win->screen->animtimer || win->screen->scrubbing) {
 -                      return win->screen;
 +              if (screen->animtimer || screen->scrubbing) {
 +                      return screen;
                }
        }
  
  
  bScreen *ED_screen_animation_no_scrub(const wmWindowManager *wm)
  {
 -      wmWindow *win;
 +      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +              bScreen *screen = WM_window_get_active_screen(win);
  
 -      for (win = wm->windows.first; win; win = win->next) {
 -              if (win->screen->animtimer) {
 -                      return win->screen;
 +              if (screen->animtimer) {
 +                      return screen;
                }
        }
  
@@@ -3898,13 -3933,11 +3908,13 @@@ static void SCREEN_OT_userpref_show(str
  static int screen_new_exec(bContext *C, wmOperator *UNUSED(op))
  {
        wmWindow *win = CTX_wm_window(C);
 -      bScreen *sc = CTX_wm_screen(C);
 -      
 -      sc = ED_screen_duplicate(win, sc);
 -      WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, sc);
 -      
 +      WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
 +      WorkSpaceLayout *layout_old = BKE_workspace_active_layout_get(win->workspace_hook);
 +      WorkSpaceLayout *layout_new;
 +
 +      layout_new = ED_workspace_layout_duplicate(workspace, layout_old, win);
 +      WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTBROWSE, layout_new);
 +
        return OPERATOR_FINISHED;
  }
  
@@@ -3925,11 -3958,9 +3935,11 @@@ static void SCREEN_OT_new(wmOperatorTyp
  static int screen_delete_exec(bContext *C, wmOperator *UNUSED(op))
  {
        bScreen *sc = CTX_wm_screen(C);
 -      
 -      WM_event_add_notifier(C, NC_SCREEN | ND_SCREENDELETE, sc);
 -      
 +      WorkSpace *workspace = CTX_wm_workspace(C);
 +      WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, sc);
 +
 +      WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTDELETE, layout);
 +
        return OPERATOR_FINISHED;
  }
  
@@@ -3944,6 -3975,95 +3954,6 @@@ static void SCREEN_OT_delete(wmOperator
        ot->exec = screen_delete_exec;
  }
  
 -/********************* new scene operator *********************/
 -
 -static int scene_new_exec(bContext *C, wmOperator *op)
 -{
 -      Scene *newscene, *scene = CTX_data_scene(C);
 -      Main *bmain = CTX_data_main(C);
 -      int type = RNA_enum_get(op->ptr, "type");
 -
 -      if (type == SCE_COPY_NEW) {
 -              newscene = BKE_scene_add(bmain, DATA_("Scene"));
 -      }
 -      else { /* different kinds of copying */
 -              newscene = BKE_scene_copy(bmain, scene, type);
 -
 -              /* these can't be handled in blenkernel currently, so do them here */
 -              if (type == SCE_COPY_LINK_DATA) {
 -                      ED_object_single_users(bmain, newscene, false, true);
 -              }
 -              else if (type == SCE_COPY_FULL) {
 -                      ED_editors_flush_edits(C, false);
 -                      ED_object_single_users(bmain, newscene, true, true);
 -              }
 -      }
 -      
 -      ED_screen_set_scene(C, CTX_wm_screen(C), newscene);
 -      
 -      WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, newscene);
 -      
 -      return OPERATOR_FINISHED;
 -}
 -
 -static void SCENE_OT_new(wmOperatorType *ot)
 -{
 -      static const EnumPropertyItem type_items[] = {
 -              {SCE_COPY_NEW, "NEW", 0, "New", "Add new scene"},
 -              {SCE_COPY_EMPTY, "EMPTY", 0, "Copy Settings", "Make a copy without any objects"},
 -              {SCE_COPY_LINK_OB, "LINK_OBJECTS", 0, "Link Objects", "Link to the objects from the current scene"},
 -              {SCE_COPY_LINK_DATA, "LINK_OBJECT_DATA", 0, "Link Object Data", "Copy objects linked to data from the current scene"},
 -              {SCE_COPY_FULL, "FULL_COPY", 0, "Full Copy", "Make a full copy of the current scene"},
 -              {0, NULL, 0, NULL, NULL}};
 -      
 -      /* identifiers */
 -      ot->name = "New Scene";
 -      ot->description = "Add new scene by type";
 -      ot->idname = "SCENE_OT_new";
 -      
 -      /* api callbacks */
 -      ot->exec = scene_new_exec;
 -      ot->invoke = WM_menu_invoke;
 -      
 -      /* flags */
 -      ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 -      
 -      /* properties */
 -      ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
 -}
 -
 -/********************* delete scene operator *********************/
 -
 -static int scene_delete_exec(bContext *C, wmOperator *UNUSED(op))
 -{
 -      Scene *scene = CTX_data_scene(C);
 -
 -      if (ED_screen_delete_scene(C, scene) == false) {
 -              return OPERATOR_CANCELLED;
 -      }
 -
 -      if (G.debug & G_DEBUG)
 -              printf("scene delete %p\n", scene);
 -
 -      WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
 -
 -      return OPERATOR_FINISHED;
 -}
 -
 -static void SCENE_OT_delete(wmOperatorType *ot)
 -{
 -      /* identifiers */
 -      ot->name = "Delete Scene";
 -      ot->description = "Delete active scene";
 -      ot->idname = "SCENE_OT_delete";
 -      
 -      /* api callbacks */
 -      ot->exec = scene_delete_exec;
 -      
 -      /* flags */
 -      ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 -}
 -
  /* ***************** region alpha blending ***************** */
  
  /* implementation note: a disappearing region needs at least 1 last draw with 100% backbuffer
@@@ -4214,11 -4334,13 +4224,11 @@@ void ED_operatortypes_screen(void
        WM_operatortype_append(SCREEN_OT_animation_step);
        WM_operatortype_append(SCREEN_OT_animation_play);
        WM_operatortype_append(SCREEN_OT_animation_cancel);
 -      
 +
        /* new/delete */
        WM_operatortype_append(SCREEN_OT_new);
        WM_operatortype_append(SCREEN_OT_delete);
 -      WM_operatortype_append(SCENE_OT_new);
 -      WM_operatortype_append(SCENE_OT_delete);
 -      
 +
        /* tools shared by more space types */
        WM_operatortype_append(ED_OT_undo);
        WM_operatortype_append(ED_OT_undo_push);