Blender V5.3
render_view.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cstddef>
11#include <cstring>
12
13#include "BLI_listbase.hh"
14#include "BLI_rect.hh"
15
16#include "DNA_scene_types.h"
17#include "DNA_userdef_types.h"
18
19#include "BKE_context.hh"
20#include "BKE_global.hh"
21#include "BKE_image.hh"
22#include "BKE_recents.hh"
23#include "BKE_report.hh"
24#include "BKE_scene.hh"
25#include "BKE_screen.hh"
26
27#include "BLT_translation.hh"
28
29#include "WM_api.hh"
30#include "WM_types.hh"
31
32#include "ED_screen.hh"
33
34#include "wm_window.hh"
35
36#include "render_intern.hh"
37
38namespace blender {
39
40/* -------------------------------------------------------------------- */
43
50{
51 bScreen *screen = CTX_wm_screen(C);
52 ScrArea *big = nullptr;
53 int size, maxsize = 0, bwmaxsize = 0;
54 short foundwin = 0;
55
56 for (ScrArea &area : screen->areabase) {
57 if (area.winx > 30 && area.winy > 30) {
58 size = area.winx * area.winy;
59 if (!area.full && area.spacetype == SPACE_PROPERTIES) {
60 if (foundwin == 0 && size > bwmaxsize) {
61 bwmaxsize = size;
62 big = &area;
63 }
64 }
65 else if (area.spacetype != SPACE_IMAGE && size > maxsize) {
66 maxsize = size;
67 big = &area;
68 foundwin = 1;
69 }
70 }
71 }
72
73 return big;
74}
75
77{
79 ScrArea *area_render = nullptr;
80 wmWindow *win_render = nullptr;
81
82 /* find an image-window showing render result */
83 for (wmWindow &win : wm->windows) {
84 if (WM_window_get_active_scene(&win) != scene) {
85 continue;
86 }
87
88 const bScreen *screen = WM_window_get_active_screen(&win);
89 for (ScrArea &area : screen->areabase) {
90 if (area.spacetype == SPACE_IMAGE) {
91 SpaceImage *sima = area.spacedata.first_as<SpaceImage>();
92 if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
93 area_render = &area;
94 win_render = &win;
95 break;
96 }
97 }
98 }
99 if (area_render) {
100 break;
101 }
102 }
103
104 *r_win = win_render;
105 return area_render;
106}
107
109{
110 bScreen *screen = CTX_wm_screen(C);
111 ScrArea *area;
112 SpaceImage *sima;
113
114 /* find an image-window showing render result */
115 for (area = screen->areabase.first(); area; area = area->next) {
116 if (area->spacetype == SPACE_IMAGE) {
117 sima = area->spacedata.first_as<SpaceImage>();
118 if ((sima->mode == SI_MODE_VIEW) && !sima->image) {
119 break;
120 }
121 }
122 }
123
124 return area;
125}
126
128
129/* -------------------------------------------------------------------- */
132
133ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
134{
135 Main *bmain = CTX_data_main(C);
136 Scene *scene = CTX_data_scene(C);
137 ScrArea *area = nullptr;
138 SpaceImage *sima;
139 bool area_was_image = false;
140
141 if (U.render_display_type == USER_RENDER_DISPLAY_NONE) {
142 return nullptr;
143 }
144
145 if (U.render_display_type == USER_RENDER_DISPLAY_WINDOW) {
146 int sizex, sizey;
147 BKE_render_resolution(&scene->r, false, &sizex, &sizey);
148
149 sizex += 30 * UI_SCALE_FAC;
150 sizey += 60 * UI_SCALE_FAC;
151
152 /* arbitrary... miniature image window views don't make much sense */
153 sizex = std::max(sizex, 320);
154 sizey = std::max(sizey, 256);
155
157
158 const std::string key = "IMAGE_EDITOR";
159 const auto bounds = recents::Section("temp.window.dimensions").get<std::vector<float>>(key);
160
161 const bool bounds_valid = (bounds.size() == 4 && (bounds[1] - bounds[0] > 150.0f) &&
162 (bounds[3] - bounds[2] > 100.0f));
164 if (bounds_valid && mm_placement) {
165 mx = int(bounds[0] * UI_SCALE_FAC);
166 my = int(bounds[2] * UI_SCALE_FAC);
167 }
168
169 const rcti window_rect = {
170 /*xmin*/ mx,
171 /*xmax*/ mx + sizex,
172 /*ymin*/ my,
173 /*ymax*/ my + sizey,
174 };
175
176 /* changes context! */
178 IFACE_("Blender Render"),
179 &window_rect,
181 true,
182 false,
183 true,
185 nullptr,
186 nullptr);
187
188 if (win == nullptr) {
189 BKE_report(reports, RPT_ERROR, "Failed to open window!");
190 return nullptr;
191 }
192
193 win->runtime->recents_storage_key = key;
194
195 area = CTX_wm_area(C);
196 if (area->spacedata.is_single() == false) {
197 sima = area->spacedata.first_as<SpaceImage>();
198 sima->flag |= SI_PREVSPACE;
199 }
200 }
201 else if (U.render_display_type == USER_RENDER_DISPLAY_SCREEN) {
202 area = CTX_wm_area(C);
203
204 /* If the active screen is already in full-screen mode, skip this and
205 * unset the area, so that the full-screen area is just changed later. */
206 if (area && area->full) {
207 area = nullptr;
208 }
209 else {
210 if (area && area->spacetype == SPACE_IMAGE) {
211 area_was_image = true;
212 }
213
214 /* this function returns with changed context */
216 }
217 }
218
219 if (!area) {
220 wmWindow *win_show = nullptr;
221 area = find_area_showing_render_result(C, scene, &win_show);
222 if (area == nullptr) {
223 /* No need to set `win_show` as the area selected will be from the active window. */
224 area = find_area_image_empty(C);
225 }
226
227 /* if area found in other window, we make that one show in front */
228 if (win_show && win_show != CTX_wm_window(C)) {
229 wm_window_raise(win_show);
230 }
231
232 if (area == nullptr) {
233 /* find largest open non-image area */
235 if (area) {
236 ED_area_newspace(C, area, SPACE_IMAGE, true);
237 sima = area->spacedata.first_as<SpaceImage>();
238
239 /* Makes "Escape" go back to previous space. */
240 sima->flag |= SI_PREVSPACE;
241
242 /* We already had a full-screen here -> mark new space as a stacked full-screen. */
243 if (area->full) {
245 }
246 }
247 else {
248 /* use any area of decent size */
250 if (area->spacetype != SPACE_IMAGE) {
251 // XXX newspace(area, SPACE_IMAGE);
252 sima = area->spacedata.first_as<SpaceImage>();
253
254 /* Makes "Escape" go back to previous space. */
255 sima->flag |= SI_PREVSPACE;
256 }
257 }
258 }
259 }
260 sima = area->spacedata.first_as<SpaceImage>();
262
263 /* get the correct image, and scale it */
264 sima->image = BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
265
266 /* If we're rendering to full screen, set appropriate hints on image editor
267 * so it can restore properly on pressing escape. */
268 if (area->full) {
269 sima->flag |= SI_FULLWINDOW;
270
271 /* Tell the image editor to revert to previous space in space list on close
272 * _only_ if it wasn't already an image editor when the render was invoked */
273 if (area_was_image == 0) {
274 sima->flag |= SI_PREVSPACE;
275 }
276 else {
277 /* Leave it alone so the image editor will just go back from
278 * full screen to the original tiled setup */
279 }
280 }
281
282 if ((sima->flag & SI_PREVSPACE) && sima->next) {
283 SpaceLink *old_sl = sima->next;
285 }
286
287 return area;
288}
289
291
292/* -------------------------------------------------------------------- */
295
297{
298 wmWindow *win = CTX_wm_window(C);
299 ScrArea *area = CTX_wm_area(C);
300 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
301
302 /* ensure image editor full-screen and area full-screen states are in sync */
303 if ((sima->flag & SI_FULLWINDOW) && !area->full) {
304 sima->flag &= ~SI_FULLWINDOW;
305 }
306
307 /* determine if render already shows */
308 if (sima->flag & SI_PREVSPACE) {
309 sima->flag &= ~SI_PREVSPACE;
310
311 if (sima->flag & SI_FULLWINDOW) {
312 sima->flag &= ~SI_FULLWINDOW;
314 }
315 else {
316 ED_area_prevspace(C, area);
317 }
318
319 return OPERATOR_FINISHED;
320 }
321 if (sima->flag & SI_FULLWINDOW) {
322 sima->flag &= ~SI_FULLWINDOW;
324 return OPERATOR_FINISHED;
325 }
326 if (WM_window_is_temp_screen(win)) {
328 return OPERATOR_FINISHED;
329 }
330
332}
333
335{
336 /* identifiers */
337 ot->name = "Cancel Render View";
338 ot->description = "Cancel showing the render view";
339 ot->idname = "RENDER_OT_view_cancel";
340
341 /* API callbacks. */
344}
345
347
348/* -------------------------------------------------------------------- */
351
353{
354 wmWindow *wincur = CTX_wm_window(C);
355
356 /* test if we have currently a temp screen active */
357 if (WM_window_is_temp_screen(wincur)) {
358 wm_window_lower(wincur);
359 }
360 else {
361 wmWindow *win_show = nullptr;
363
364 /* is there another window on current scene showing result? */
365 for (wmWindow &win : CTX_wm_manager(C)->windows) {
366 const bScreen *screen = WM_window_get_active_screen(&win);
367
368 if ((WM_window_is_temp_screen(&win) &&
369 (screen->areabase.first())->spacetype == SPACE_IMAGE) ||
370 (&win == win_show && win_show != wincur))
371 {
372 wm_window_raise(&win);
373 return OPERATOR_FINISHED;
374 }
375 }
376
377 /* determine if render already shows */
378 if (area) {
379 /* but don't close it when rendering */
380 if (G.is_rendering == false) {
381 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
382
383 if (sima->flag & SI_PREVSPACE) {
384 sima->flag &= ~SI_PREVSPACE;
385
386 if (sima->flag & SI_FULLWINDOW) {
387 sima->flag &= ~SI_FULLWINDOW;
389 }
390 else {
391 ED_area_prevspace(C, area);
392 }
393 }
394 }
395 }
396 else {
397 render_view_open(C, event->xy[0], event->xy[1], op->reports);
398 }
399 }
400
401 return OPERATOR_FINISHED;
402}
403
405{
406 /* identifiers */
407 ot->name = "Show/Hide Render View";
408 ot->description = "Toggle show render view";
409 ot->idname = "RENDER_OT_view_show";
410
411 /* API callbacks. */
414}
415
417
418} // namespace blender
#define IFACE_(msgid)
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
#define C
Definition RandGen.cpp:29
T get(const std::string &item_key) const
Definition recents.cc:224
BMesh Iterators.
UserDef U
Definition blender.cc:58
static ScrArea * find_area_image_empty(bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void wm_window_lower(wmWindow *win)
static ScrArea * find_area_showing_render_result(bContext *C, Scene *scene, wmWindow **r_win)
ScrArea * ED_screen_full_newspace(bContext *C, ScrArea *area, int type)
ScrArea * ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, eScreen_State state)
void ED_area_prevspace(bContext *C, ScrArea *area)
Definition area.cc:3111
wmWindow * WM_window_open(bContext *C, const char *title, const rcti *rect_unscaled, int space_type, bool toplevel, bool dialog, bool temp, eWindowAlignment alignment, void(*area_setup_fn)(bScreen *screen, ScrArea *area, void *user_data), void *area_setup_user_data)
void ED_area_newspace(bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition area.cc:2929
wmWindow * CTX_wm_window(const bContext *C)
ScrArea * render_view_open(bContext *C, int mx, int my, ReportList *reports)
@ WIN_ALIGN_ABSOLUTE
Definition WM_api.hh:484
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
Global G
Definition blender.cc:57
Scene * WM_window_get_active_scene(const wmWindow *win)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
wmWindowManager * CTX_wm_manager(const bContext *C)
void wm_window_close_request(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:483
void wm_window_raise(wmWindow *win)
static ScrArea * biggest_non_image_area(bContext *C)
@ WM_CAPABILITY_MULTIMONITOR_PLACEMENT
Definition WM_api.hh:251
void ED_screen_full_prevspace(bContext *C, ScrArea *area)
Main * CTX_data_main(const bContext *C)
void RENDER_OT_view_cancel(wmOperatorType *ot)
eWM_CapabilitiesFlag WM_capabilities_flag()
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:1189
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
bool ED_operator_image_active(bContext *C)
bScreen * WM_window_get_active_screen(const wmWindow *win)
void RENDER_OT_view_show(wmOperatorType *ot)
void WM_window_dpi_set_userdef(const wmWindow *win)
Definition wm_window.cc:737
static wmOperatorStatus render_view_cancel_exec(bContext *C, wmOperator *)
bool WM_window_is_temp_screen(const wmWindow *win)
@ AREA_FLAG_STACKED_FULLSCREEN
bool ED_operator_screenactive(bContext *C)
@ USER_RENDER_DISPLAY_WINDOW
@ USER_RENDER_DISPLAY_SCREEN
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
struct RenderData r
struct ScrArea * next
ListBaseT< SpaceLink > spacedata
eSpace_Link_Flag link_flag
eSpaceImage_Mode mode
eSpaceImage_Flag flag
ListBaseT< struct ScrArea > areabase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
bke::WindowRuntime * runtime