1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/render/render_view.c
* \ingroup edrend
*/
#include <string.h>
#include <stddef.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLF_api.h"
#include "DNA_scene_types.h"
#include "BKE_blender.h"
#include "BKE_context.h"
#include "BKE_image.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_screen.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_screen.h"
#include "wm_window.h"
#include "render_intern.h"
/*********************** utilities for finding areas *************************/
/* returns biggest area that is not uv/image editor. Note that it uses buttons */
/* window as the last possible alternative. */
static ScrArea *biggest_non_image_area(bContext *C)
{
bScreen *sc= CTX_wm_screen(C);
ScrArea *sa, *big= NULL;
int size, maxsize= 0, bwmaxsize= 0;
short foundwin= 0;
for(sa= sc->areabase.first; sa; sa= sa->next) {
if(sa->winx > 30 && sa->winy > 30) {
size= sa->winx*sa->winy;
if(sa->spacetype == SPACE_BUTS) {
if(foundwin == 0 && size > bwmaxsize) {
bwmaxsize= size;
big= sa;
}
}
else if(sa->spacetype != SPACE_IMAGE && size > maxsize) {
maxsize= size;
big= sa;
foundwin= 1;
}
}
}
return big;
}
static ScrArea *biggest_area(bContext *C)
{
bScreen *sc= CTX_wm_screen(C);
ScrArea *sa, *big= NULL;
int size, maxsize= 0;
for(sa= sc->areabase.first; sa; sa= sa->next) {
size= sa->winx*sa->winy;
if(size > maxsize) {
maxsize= size;
big= sa;
}
}
return big;
}
static ScrArea *find_area_showing_r_result(bContext *C, wmWindow **win)
{
wmWindowManager *wm= CTX_wm_manager(C);
ScrArea *sa = NULL;
SpaceImage *sima;
/* find an imagewindow showing render result */
for(*win=wm->windows.first; *win; *win= (*win)->next) {
for(sa= (*win)->screen->areabase.first; sa; sa= sa->next) {
if(sa->spacetype==SPACE_IMAGE) {
sima= sa->spacedata.first;
if(sima->image && sima->image->type==IMA_TYPE_R_RESULT)
break;
}
}
if(sa)
break;
}
return sa;
}
static ScrArea *find_area_image_empty(bContext *C)
{
bScreen *sc= CTX_wm_screen(C);
ScrArea *sa;
SpaceImage *sima;
/* find an imagewindow showing render result */
for(sa=sc->areabase.first; sa; sa= sa->next) {
if(sa->spacetype==SPACE_IMAGE) {
sima= sa->spacedata.first;
if(!sima->image)
break;
}
}
return sa;
}
/********************** open image editor for render *************************/
/* 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;
/* XXX some magic to calculate postition */
rect.xmin= mx + win->posx - sizex/2;
rect.ymin= my + 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= biggest_area(C);
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 */
;
}
}
}
/*************************** cancel render viewer **********************/
static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(op))
{
wmWindow *win= CTX_wm_window(C);
ScrArea *sa= CTX_wm_area(C);
SpaceImage *sima= sa->spacedata.first;
/* test if we have a temp screen in front */
if(CTX_wm_window(C)->screen->temp) {
wm_window_lower(CTX_wm_window(C));
return OPERATOR_FINISHED;
}
/* determine if render already shows */
else if(sima->flag & SI_PREVSPACE) {
sima->flag &= ~SI_PREVSPACE;
if(sima->flag & SI_FULLWINDOW) {
sima->flag &= ~SI_FULLWINDOW;
ED_screen_full_prevspace(C, sa);
}
else
ED_area_prevspace(C, sa);
return OPERATOR_FINISHED;
}
else if(sima->flag & SI_FULLWINDOW) {
sima->flag &= ~SI_FULLWINDOW;
ED_screen_full_toggle(C, win, sa);
return OPERATOR_FINISHED;
}
return OPERATOR_PASS_THROUGH;
}
void RENDER_OT_view_cancel(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= _("Cancel Render View");
ot->description= _("Cancel show render view");
ot->idname= "RENDER_OT_view_cancel";
/* api callbacks */
ot->exec= render_view_cancel_exec;
ot->poll= ED_operator_image_active;
}
/************************* show render viewer *****************/
static int render_view_show_invoke(bContext *C, wmOperator *UNUSED(op), 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, &winshow);
/* is there another window showing result? */
for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
if(win->screen->temp || (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.rendering) {
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);
}
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;
}
void RENDER_OT_view_show(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= _("Show/Hide Render View");
ot->description= _("Toggle show render view");
ot->idname= "RENDER_OT_view_show";
/* api callbacks */
ot->invoke= render_view_show_invoke;
ot->poll= ED_operator_screenactive;
}
|