Blender  V2.93
render_view.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stddef.h>
25 #include <string.h>
26 
27 #include "BLI_listbase.h"
28 #include "BLI_utildefines.h"
29 
30 #include "DNA_scene_types.h"
31 #include "DNA_userdef_types.h"
32 
33 #include "BKE_context.h"
34 #include "BKE_global.h"
35 #include "BKE_image.h"
36 #include "BKE_main.h"
37 #include "BKE_report.h"
38 #include "BKE_screen.h"
39 
40 #include "BLT_translation.h"
41 
42 #include "WM_api.h"
43 #include "WM_types.h"
44 
45 #include "ED_screen.h"
46 #include "UI_interface.h"
47 
48 #include "wm_window.h"
49 
50 #include "render_intern.h"
51 
52 /*********************** utilities for finding areas *************************/
53 
54 /* returns biggest area that is not uv/image editor. Note that it uses buttons */
55 /* window as the last possible alternative. */
56 /* would use BKE_screen_find_big_area(...) but this is too specific */
58 {
59  bScreen *screen = CTX_wm_screen(C);
60  ScrArea *area, *big = NULL;
61  int size, maxsize = 0, bwmaxsize = 0;
62  short foundwin = 0;
63 
64  for (area = screen->areabase.first; area; area = area->next) {
65  if (area->winx > 30 && area->winy > 30) {
66  size = area->winx * area->winy;
67  if (!area->full && area->spacetype == SPACE_PROPERTIES) {
68  if (foundwin == 0 && size > bwmaxsize) {
69  bwmaxsize = size;
70  big = area;
71  }
72  }
73  else if (area->spacetype != SPACE_IMAGE && size > maxsize) {
74  maxsize = size;
75  big = area;
76  foundwin = 1;
77  }
78  }
79  }
80 
81  return big;
82 }
83 
85 {
87  ScrArea *area = NULL;
88  SpaceImage *sima;
89 
90  /* find an imagewindow showing render result */
91  for (*win = wm->windows.first; *win; *win = (*win)->next) {
92  if (WM_window_get_active_scene(*win) == scene) {
93  const bScreen *screen = WM_window_get_active_screen(*win);
94 
95  for (area = screen->areabase.first; area; area = area->next) {
96  if (area->spacetype == SPACE_IMAGE) {
97  sima = area->spacedata.first;
98  if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
99  break;
100  }
101  }
102  }
103  if (area) {
104  break;
105  }
106  }
107  }
108 
109  return area;
110 }
111 
113 {
114  bScreen *screen = CTX_wm_screen(C);
115  ScrArea *area;
116  SpaceImage *sima;
117 
118  /* find an imagewindow showing render result */
119  for (area = screen->areabase.first; area; area = area->next) {
120  if (area->spacetype == SPACE_IMAGE) {
121  sima = area->spacedata.first;
122  if ((sima->mode == SI_MODE_VIEW) && !sima->image) {
123  break;
124  }
125  }
126  }
127 
128  return area;
129 }
130 
131 /********************** open image editor for render *************************/
132 
133 /* new window uses x,y to set position */
134 ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
135 {
136  Main *bmain = CTX_data_main(C);
138  wmWindow *win = NULL;
139  ScrArea *area = NULL;
140  SpaceImage *sima;
141  bool area_was_image = false;
142 
143  if (U.render_display_type == USER_RENDER_DISPLAY_NONE) {
144  return NULL;
145  }
146 
147  if (U.render_display_type == USER_RENDER_DISPLAY_WINDOW) {
148  int sizex = 30 * UI_DPI_FAC + (scene->r.xsch * scene->r.size) / 100;
149  int sizey = 60 * UI_DPI_FAC + (scene->r.ysch * scene->r.size) / 100;
150 
151  /* arbitrary... miniature image window views don't make much sense */
152  if (sizex < 320) {
153  sizex = 320;
154  }
155  if (sizey < 256) {
156  sizey = 256;
157  }
158 
159  /* changes context! */
160  if (WM_window_open(C,
161  IFACE_("Blender Render"),
162  mx,
163  my,
164  sizex,
165  sizey,
166  SPACE_IMAGE,
167  false,
168  true,
170  BKE_report(reports, RPT_ERROR, "Failed to open window!");
171  return NULL;
172  }
173 
174  area = CTX_wm_area(C);
175  if (BLI_listbase_is_single(&area->spacedata) == false) {
176  sima = area->spacedata.first;
177  sima->flag |= SI_PREVSPACE;
178  }
179  }
180  else if (U.render_display_type == USER_RENDER_DISPLAY_SCREEN) {
181  area = CTX_wm_area(C);
182 
183  /* if the active screen is already in fullscreen mode, skip this and
184  * unset the area, so that the fullscreen area is just changed later */
185  if (area && area->full) {
186  area = NULL;
187  }
188  else {
189  if (area && area->spacetype == SPACE_IMAGE) {
190  area_was_image = true;
191  }
192 
193  /* this function returns with changed context */
195  }
196  }
197 
198  if (!area) {
200  if (area == NULL) {
202  }
203 
204  /* if area found in other window, we make that one show in front */
205  if (win && win != CTX_wm_window(C)) {
206  wm_window_raise(win);
207  }
208 
209  if (area == NULL) {
210  /* find largest open non-image area */
212  if (area) {
214  sima = area->spacedata.first;
215 
216  /* makes ESC go back to prev space */
217  sima->flag |= SI_PREVSPACE;
218 
219  /* we already had a fullscreen here -> mark new space as a stacked fullscreen */
220  if (area->full) {
222  }
223  }
224  else {
225  /* use any area of decent size */
227  if (area->spacetype != SPACE_IMAGE) {
228  // XXX newspace(area, SPACE_IMAGE);
229  sima = area->spacedata.first;
230 
231  /* makes ESC go back to prev space */
232  sima->flag |= SI_PREVSPACE;
233  }
234  }
235  }
236  }
237  sima = area->spacedata.first;
239 
240  /* get the correct image, and scale it */
241  sima->image = BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
242 
243  /* If we're rendering to full screen, set appropriate hints on image editor
244  * so it can restore properly on pressing escape. */
245  if (area->full) {
246  sima->flag |= SI_FULLWINDOW;
247 
248  /* Tell the image editor to revert to previous space in space list on close
249  * _only_ if it wasn't already an image editor when the render was invoked */
250  if (area_was_image == 0) {
251  sima->flag |= SI_PREVSPACE;
252  }
253  else {
254  /* Leave it alone so the image editor will just go back from
255  * full screen to the original tiled setup */
256  }
257  }
258 
259  if ((sima->flag & SI_PREVSPACE) && sima->next) {
260  SpaceLink *old_sl = sima->next;
262  }
263 
264  return area;
265 }
266 
267 /*************************** cancel render viewer **********************/
268 
270 {
271  wmWindow *win = CTX_wm_window(C);
273  SpaceImage *sima = area->spacedata.first;
274 
275  /* ensure image editor fullscreen and area fullscreen states are in sync */
276  if ((sima->flag & SI_FULLWINDOW) && !area->full) {
277  sima->flag &= ~SI_FULLWINDOW;
278  }
279 
280  /* determine if render already shows */
281  if (sima->flag & SI_PREVSPACE) {
282  sima->flag &= ~SI_PREVSPACE;
283 
284  if (sima->flag & SI_FULLWINDOW) {
285  sima->flag &= ~SI_FULLWINDOW;
287  }
288  else {
290  }
291 
292  return OPERATOR_FINISHED;
293  }
294  if (sima->flag & SI_FULLWINDOW) {
295  sima->flag &= ~SI_FULLWINDOW;
297  return OPERATOR_FINISHED;
298  }
299  if (WM_window_is_temp_screen(win)) {
301  return OPERATOR_FINISHED;
302  }
303 
304  return OPERATOR_PASS_THROUGH;
305 }
306 
308 {
309  /* identifiers */
310  ot->name = "Cancel Render View";
311  ot->description = "Cancel show render view";
312  ot->idname = "RENDER_OT_view_cancel";
313 
314  /* api callbacks */
317 }
318 
319 /************************* show render viewer *****************/
320 
321 static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
322 {
323  wmWindow *wincur = CTX_wm_window(C);
324 
325  /* test if we have currently a temp screen active */
326  if (WM_window_is_temp_screen(wincur)) {
327  wm_window_lower(wincur);
328  }
329  else {
330  wmWindow *win, *winshow;
332 
333  /* is there another window on current scene showing result? */
334  for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) {
335  const bScreen *screen = WM_window_get_active_screen(win);
336 
337  if ((WM_window_is_temp_screen(win) &&
338  ((ScrArea *)screen->areabase.first)->spacetype == SPACE_IMAGE) ||
339  (win == winshow && winshow != wincur)) {
340  wm_window_raise(win);
341  return OPERATOR_FINISHED;
342  }
343  }
344 
345  /* determine if render already shows */
346  if (area) {
347  /* but don't close it when rendering */
348  if (G.is_rendering == false) {
349  SpaceImage *sima = area->spacedata.first;
350 
351  if (sima->flag & SI_PREVSPACE) {
352  sima->flag &= ~SI_PREVSPACE;
353 
354  if (sima->flag & SI_FULLWINDOW) {
355  sima->flag &= ~SI_FULLWINDOW;
357  }
358  else {
360  }
361  }
362  }
363  }
364  else {
365  render_view_open(C, event->x, event->y, op->reports);
366  }
367  }
368 
369  return OPERATOR_FINISHED;
370 }
371 
373 {
374  /* identifiers */
375  ot->name = "Show/Hide Render View";
376  ot->description = "Toggle show render view";
377  ot->idname = "RENDER_OT_view_show";
378 
379  /* api callbacks */
382 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
struct Image * BKE_image_ensure_viewer(struct Main *bmain, int type, const char *name)
Definition: image.c:3162
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
struct ScrArea struct ScrArea * BKE_screen_find_big_area(struct bScreen *screen, const int spacetype, const short min)
Definition: screen.c:983
void void BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
Definition: BLI_listbase.h:120
#define UNUSED(x)
#define IFACE_(msgid)
@ IMA_TYPE_R_RESULT
@ SCREENMAXIMIZED
@ AREA_FLAG_STACKED_FULLSCREEN
@ SI_FULLWINDOW
@ SI_PREVSPACE
@ SPACE_PROPERTIES
@ SPACE_IMAGE
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
@ SI_MODE_VIEW
#define SPACE_TYPE_ANY
@ USER_RENDER_DISPLAY_NONE
@ USER_RENDER_DISPLAY_SCREEN
@ USER_RENDER_DISPLAY_WINDOW
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void ED_screen_full_prevspace(struct bContext *C, ScrArea *area)
Definition: screen_edit.c:1168
bool ED_operator_image_active(struct bContext *C)
Definition: screen_ops.c:329
bool ED_operator_screenactive(struct bContext *C)
Definition: screen_ops.c:133
struct ScrArea * ED_screen_state_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *area, const short state)
Definition: screen_edit.c:1324
void ED_area_prevspace(struct bContext *C, ScrArea *area)
Definition: area.c:2515
void ED_area_newspace(struct bContext *C, ScrArea *area, int type, const bool skip_region_exit)
Definition: area.c:2375
ScrArea * ED_screen_full_newspace(struct bContext *C, ScrArea *area, int type)
Definition: screen_edit.c:1139
#define C
Definition: RandGen.cpp:39
#define UI_DPI_FAC
Definition: UI_interface.h:309
@ WIN_ALIGN_LOCATION_CENTER
Definition: WM_api.h:177
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
short type
Scene scene
static void area(int d1, int d2, int e1, int e2, float weights[2])
ScrArea * render_view_open(bContext *C, int mx, int my, ReportList *reports)
Definition: render_view.c:134
void RENDER_OT_view_cancel(struct wmOperatorType *ot)
Definition: render_view.c:307
static ScrArea * find_area_image_empty(bContext *C)
Definition: render_view.c:112
void RENDER_OT_view_show(struct wmOperatorType *ot)
Definition: render_view.c:372
static ScrArea * find_area_showing_r_result(bContext *C, Scene *scene, wmWindow **win)
Definition: render_view.c:84
static ScrArea * biggest_non_image_area(bContext *C)
Definition: render_view.c:57
static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(op))
Definition: render_view.c:269
static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: render_view.c:321
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct RenderData r
SpaceLink * next
struct Image * image
ListBase areabase
int y
Definition: WM_types.h:581
int x
Definition: WM_types.h:581
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct wmWindow * next
#define G(x, y, z)
wmOperatorType * ot
Definition: wm_files.c:3156
void wm_window_raise(wmWindow *win)
Definition: wm_window.c:1866
void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition: wm_window.c:389
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2372
bool WM_window_is_temp_screen(const wmWindow *win)
Definition: wm_window.c:2383
wmWindow * WM_window_open(bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type, bool dialog, bool temp, WindowAlignment alignment)
Definition: wm_window.c:764
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2249
void wm_window_lower(wmWindow *win)
Definition: wm_window.c:1861