void WM_window_open_temp(bContext *C, rcti *position, int type) { wmWindow *win; ScrArea *sa; /* changes rect to fit within desktop */ wm_window_check_position(position); /* test if we have a temp screen already */ for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) if (win->screen->temp) break; /* add new window? */ if (win == NULL) { win = wm_window_new(C); win->posx = position->xmin; win->posy = position->ymin; } win->sizex = position->xmax - position->xmin; win->sizey = position->ymax - position->ymin; if (win->ghostwin) { wm_window_set_size(win, win->sizex, win->sizey); wm_window_raise(win); } /* add new screen? */ if (win->screen == NULL) win->screen = ED_screen_add(win, CTX_data_scene(C), "temp"); win->screen->temp = 1; /* make window active, and validate/resize */ CTX_wm_window_set(C, win); WM_check(C); /* ensure it shows the right spacetype editor */ sa = win->screen->areabase.first; CTX_wm_area_set(C, sa); if (type == WM_WINDOW_RENDER) { ED_area_newspace(C, sa, SPACE_IMAGE); } else { ED_area_newspace(C, sa, SPACE_USERPREF); } ED_screen_set(C, win->screen); if (sa->spacetype == SPACE_IMAGE) GHOST_SetTitle(win->ghostwin, IFACE_("Blender Render")); else if (ELEM(sa->spacetype, SPACE_OUTLINER, SPACE_USERPREF)) GHOST_SetTitle(win->ghostwin, IFACE_("Blender User Preferences")); else if (sa->spacetype == SPACE_FILE) GHOST_SetTitle(win->ghostwin, IFACE_("Blender File View")); else GHOST_SetTitle(win->ghostwin, "Blender"); }
static int render_view_show_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { wmWindow *wincur = CTX_wm_window(C); /* test if we have currently a temp screen active */ if (wincur->screen->temp) { wm_window_lower(wincur); } else { wmWindow *win, *winshow; ScrArea *sa = find_area_showing_r_result(C, CTX_data_scene(C), &winshow); /* is there another window on current scene showing result? */ for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) { bScreen *sc = win->screen; if ((sc->temp && ((ScrArea *)sc->areabase.first)->spacetype == SPACE_IMAGE) || (win == winshow && winshow != wincur)) { wm_window_raise(win); return OPERATOR_FINISHED; } } /* determine if render already shows */ if (sa) { /* but don't close it when rendering */ if (G.is_rendering == false) { SpaceImage *sima = sa->spacedata.first; if (sima->flag & SI_PREVSPACE) { sima->flag &= ~SI_PREVSPACE; if (sima->flag & SI_FULLWINDOW) { sima->flag &= ~SI_FULLWINDOW; ED_screen_full_prevspace(C, sa, false); } else if (sima->next) { /* workaround for case of double prevspace, render window * with a file browser on top of it (same as in ED_area_prevspace) */ if (sima->next->spacetype == SPACE_FILE && sima->next->next) ED_area_newspace(C, sa, sima->next->next->spacetype); else ED_area_newspace(C, sa, sima->next->spacetype); ED_area_tag_redraw(sa); } } } } else { render_view_open(C, event->x, event->y); } } return OPERATOR_FINISHED; }
/* new window uses x,y to set position */ void render_view_open(bContext *C, int mx, int my) { wmWindow *win = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); ScrArea *sa = NULL; SpaceImage *sima; int area_was_image = 0; if (scene->r.displaymode == R_OUTPUT_NONE) return; if (scene->r.displaymode == R_OUTPUT_WINDOW) { rcti rect; int sizex, sizey; sizex = 10 + (scene->r.xsch * scene->r.size) / 100; sizey = 40 + (scene->r.ysch * scene->r.size) / 100; /* arbitrary... miniature image window views don't make much sense */ if (sizex < 320) sizex = 320; if (sizey < 256) sizey = 256; /* some magic to calculate postition */ /* pixelsize: mouse coords are in U.pixelsize units :/ */ rect.xmin = (mx / U.pixelsize) + win->posx - sizex / 2; rect.ymin = (my / U.pixelsize) + win->posy - sizey / 2; rect.xmax = rect.xmin + sizex; rect.ymax = rect.ymin + sizey; /* changes context! */ WM_window_open_temp(C, &rect, WM_WINDOW_RENDER); sa = CTX_wm_area(C); } else if (scene->r.displaymode == R_OUTPUT_SCREEN) { if (CTX_wm_area(C) && CTX_wm_area(C)->spacetype == SPACE_IMAGE) area_was_image = 1; /* this function returns with changed context */ sa = ED_screen_full_newspace(C, CTX_wm_area(C), SPACE_IMAGE); } if (!sa) { sa = find_area_showing_r_result(C, &win); if (sa == NULL) sa = find_area_image_empty(C); /* if area found in other window, we make that one show in front */ if (win && win != CTX_wm_window(C)) wm_window_raise(win); if (sa == NULL) { /* find largest open non-image area */ sa = biggest_non_image_area(C); if (sa) { ED_area_newspace(C, sa, SPACE_IMAGE); sima = sa->spacedata.first; /* makes ESC go back to prev space */ sima->flag |= SI_PREVSPACE; } else { /* use any area of decent size */ sa = BKE_screen_find_big_area(CTX_wm_screen(C), -1, 0); if (sa->spacetype != SPACE_IMAGE) { // XXX newspace(sa, SPACE_IMAGE); sima = sa->spacedata.first; /* makes ESC go back to prev space */ sima->flag |= SI_PREVSPACE; } } } } sima = sa->spacedata.first; /* get the correct image, and scale it */ sima->image = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); /* if we're rendering to full screen, set appropriate hints on image editor * so it can restore properly on pressing esc */ if (sa->full) { sima->flag |= SI_FULLWINDOW; /* Tell the image editor to revert to previous space in space list on close * _only_ if it wasn't already an image editor when the render was invoked */ if (area_was_image == 0) sima->flag |= SI_PREVSPACE; else { /* Leave it alone so the image editor will just go back from * full screen to the original tiled setup */ } } }
/** * Uses `screen->temp` tag to define what to do, currently it limits * to only one "temp" window for render out, preferences, filewindow, etc... * * \param type: WM_WINDOW_RENDER, WM_WINDOW_USERPREFS... * \return the window or NULL. */ wmWindow *WM_window_open_temp(bContext *C, const rcti *rect_init, int type) { wmWindow *win_prev = CTX_wm_window(C); wmWindow *win; ScrArea *sa; Scene *scene = CTX_data_scene(C); const char *title; rcti rect = *rect_init; const short px_virtual = (short)wm_window_get_virtual_pixelsize(); /* changes rect to fit within desktop */ wm_window_check_position(&rect); /* test if we have a temp screen already */ for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) if (win->screen->temp) break; /* add new window? */ if (win == NULL) { win = wm_window_new(C); win->posx = rect.xmin; win->posy = rect.ymin; } /* multiply with virtual pixelsize, ghost handles native one (e.g. for retina) */ win->sizex = BLI_rcti_size_x(&rect) * px_virtual; win->sizey = BLI_rcti_size_y(&rect) * px_virtual; if (win->ghostwin) { wm_window_set_size(win, win->sizex, win->sizey); wm_window_raise(win); } if (win->screen == NULL) { /* add new screen */ win->screen = ED_screen_add(win, scene, "temp"); } else { /* switch scene for rendering */ if (win->screen->scene != scene) ED_screen_set_scene(C, win->screen, scene); } win->screen->temp = 1; /* make window active, and validate/resize */ CTX_wm_window_set(C, win); WM_check(C); /* It's possible `win->ghostwin == NULL`. * instead of attempting to cleanup here (in a half finished state), * finish setting up the screen, then free it at the end of the function, * to avoid having to take into account a partially-created window. */ /* ensure it shows the right spacetype editor */ sa = win->screen->areabase.first; CTX_wm_area_set(C, sa); if (type == WM_WINDOW_RENDER) { ED_area_newspace(C, sa, SPACE_IMAGE); } else { ED_area_newspace(C, sa, SPACE_USERPREF); } ED_screen_set(C, win->screen); ED_screen_refresh(CTX_wm_manager(C), win); /* test scale */ if (sa->spacetype == SPACE_IMAGE) title = IFACE_("Blender Render"); else if (ELEM(sa->spacetype, SPACE_OUTLINER, SPACE_USERPREF)) title = IFACE_("Blender User Preferences"); else if (sa->spacetype == SPACE_FILE) title = IFACE_("Blender File View"); else title = "Blender"; if (win->ghostwin) { GHOST_SetTitle(win->ghostwin, title); return win; } else { /* very unlikely! but opening a new window can fail */ wm_window_close(C, CTX_wm_manager(C), win); CTX_wm_window_set(C, win_prev); return NULL; } }