Blender V4.5
screen_edit.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 <cmath>
10#include <cstring>
11
12#include "MEM_guardedalloc.h"
13
14#include "DNA_object_types.h"
15#include "DNA_scene_types.h"
16#include "DNA_userdef_types.h"
17
18#include "BLI_listbase.h"
19#include "BLI_rect.h"
20#include "BLI_string.h"
21#include "BLI_utildefines.h"
22
23#include "BKE_context.hh"
24#include "BKE_global.hh"
25#include "BKE_icons.h"
26#include "BKE_image.hh"
27#include "BKE_layer.hh"
28#include "BKE_lib_id.hh"
29#include "BKE_main.hh"
30#include "BKE_report.hh"
31#include "BKE_scene.hh"
32#include "BKE_screen.hh"
33#include "BKE_sound.h"
34#include "BKE_workspace.hh"
35
36#include "WM_api.hh"
37#include "WM_types.hh"
38
39#include "ED_clip.hh"
40#include "ED_node.hh"
41#include "ED_screen.hh"
42#include "ED_screen_types.hh"
43
44#include "RNA_access.hh"
45#include "RNA_enum_types.hh"
46
47#include "UI_interface.hh"
48
49#include "WM_message.hh"
50#include "WM_toolsystem.hh"
51
53
54#include "screen_intern.hh" /* own module include */
55
56/* adds no space data */
58 ScrVert *bottom_left,
59 ScrVert *top_left,
60 ScrVert *top_right,
61 ScrVert *bottom_right,
62 const eSpace_Type space_type)
63{
64 ScrArea *area = MEM_callocN<ScrArea>("addscrarea");
65
66 area->v1 = bottom_left;
67 area->v2 = top_left;
68 area->v3 = top_right;
69 area->v4 = bottom_right;
70 area->spacetype = space_type;
71
72 BLI_addtail(&area_map->areabase, area);
73
74 return area;
75}
77 ScrVert *left_bottom,
78 ScrVert *left_top,
79 ScrVert *right_top,
80 ScrVert *right_bottom,
81 const eSpace_Type space_type)
82{
83 return screen_addarea_ex(
84 AREAMAP_FROM_SCREEN(screen), left_bottom, left_top, right_top, right_bottom, space_type);
85}
86
87static void screen_delarea(bContext *C, bScreen *screen, ScrArea *area)
88{
89
90 ED_area_exit(C, area);
91
93
94 BLI_remlink(&screen->areabase, area);
95 MEM_freeN(area);
96}
97
99 bScreen *screen,
100 ScrArea *area,
101 const eScreenAxis dir_axis,
102 const float fac,
103 const bool merge)
104{
105 ScrArea *newa = nullptr;
106
107 if (area == nullptr) {
108 return nullptr;
109 }
110
111 rcti window_rect;
112 WM_window_rect_calc(win, &window_rect);
113
114 short split = screen_geom_find_area_split_point(area, &window_rect, dir_axis, fac);
115 if (split == 0) {
116 return nullptr;
117 }
118
119 /* NOTE(@ideasman42): regarding (fac > 0.5f) checks below.
120 * normally it shouldn't matter which is used since the copy should match the original
121 * however with viewport rendering and python console this isn't the case. */
122
123 if (dir_axis == SCREEN_AXIS_H) {
124 /* new vertices */
125 ScrVert *sv1 = screen_geom_vertex_add(screen, area->v1->vec.x, split);
126 ScrVert *sv2 = screen_geom_vertex_add(screen, area->v4->vec.x, split);
127
128 /* new edges */
129 screen_geom_edge_add(screen, area->v1, sv1);
130 screen_geom_edge_add(screen, sv1, area->v2);
131 screen_geom_edge_add(screen, area->v3, sv2);
132 screen_geom_edge_add(screen, sv2, area->v4);
133 screen_geom_edge_add(screen, sv1, sv2);
134
135 if (fac > 0.5f) {
136 /* new areas: top */
137 newa = screen_addarea(screen, sv1, area->v2, area->v3, sv2, eSpace_Type(area->spacetype));
138
139 /* area below */
140 area->v2 = sv1;
141 area->v3 = sv2;
142 }
143 else {
144 /* new areas: bottom */
145 newa = screen_addarea(screen, area->v1, sv1, sv2, area->v4, eSpace_Type(area->spacetype));
146
147 /* area above */
148 area->v1 = sv1;
149 area->v4 = sv2;
150 }
151
152 ED_area_data_copy(newa, area, true);
153 }
154 else {
155 /* new vertices */
156 ScrVert *sv1 = screen_geom_vertex_add(screen, split, area->v1->vec.y);
157 ScrVert *sv2 = screen_geom_vertex_add(screen, split, area->v2->vec.y);
158
159 /* new edges */
160 screen_geom_edge_add(screen, area->v1, sv1);
161 screen_geom_edge_add(screen, sv1, area->v4);
162 screen_geom_edge_add(screen, area->v2, sv2);
163 screen_geom_edge_add(screen, sv2, area->v3);
164 screen_geom_edge_add(screen, sv1, sv2);
165
166 if (fac > 0.5f) {
167 /* new areas: right */
168 newa = screen_addarea(screen, sv1, sv2, area->v3, area->v4, eSpace_Type(area->spacetype));
169
170 /* area left */
171 area->v3 = sv2;
172 area->v4 = sv1;
173 }
174 else {
175 /* new areas: left */
176 newa = screen_addarea(screen, area->v1, area->v2, sv2, sv1, eSpace_Type(area->spacetype));
177
178 /* area right */
179 area->v1 = sv1;
180 area->v2 = sv2;
181 }
182
183 ED_area_data_copy(newa, area, true);
184 }
185
186 /* remove double vertices en edges */
187 if (merge) {
189 }
192
193 return newa;
194}
195
196bScreen *screen_add(Main *bmain, const char *name, const rcti *rect)
197{
198 bScreen *screen = static_cast<bScreen *>(BKE_libblock_alloc(bmain, ID_SCR, name, 0));
199 screen->do_refresh = true;
201
202 ScrVert *sv1 = screen_geom_vertex_add(screen, rect->xmin, rect->ymin);
203 ScrVert *sv2 = screen_geom_vertex_add(screen, rect->xmin, rect->ymax - 1);
204 ScrVert *sv3 = screen_geom_vertex_add(screen, rect->xmax - 1, rect->ymax - 1);
205 ScrVert *sv4 = screen_geom_vertex_add(screen, rect->xmax - 1, rect->ymin);
206
207 screen_geom_edge_add(screen, sv1, sv2);
208 screen_geom_edge_add(screen, sv2, sv3);
209 screen_geom_edge_add(screen, sv3, sv4);
210 screen_geom_edge_add(screen, sv4, sv1);
211
212 /* dummy type, no spacedata */
213 screen_addarea(screen, sv1, sv2, sv3, sv4, SPACE_EMPTY);
214
215 return screen;
216}
217
219{
220 /* Free contents of 'to', is from blenkernel `screen.cc`. */
222
223 to->flag = from->flag;
224
225 BLI_duplicatelist(&to->vertbase, &from->vertbase);
226 BLI_duplicatelist(&to->edgebase, &from->edgebase);
227 BLI_duplicatelist(&to->areabase, &from->areabase);
229
230 ScrVert *s2 = static_cast<ScrVert *>(to->vertbase.first);
231 for (ScrVert *s1 = static_cast<ScrVert *>(from->vertbase.first); s1;
232 s1 = s1->next, s2 = s2->next)
233 {
234 s1->newv = s2;
235 }
236
237 LISTBASE_FOREACH (ScrEdge *, se, &to->edgebase) {
238 se->v1 = se->v1->newv;
239 se->v2 = se->v2->newv;
240 BKE_screen_sort_scrvert(&(se->v1), &(se->v2));
241 }
242
243 ScrArea *from_area = static_cast<ScrArea *>(from->areabase.first);
244 LISTBASE_FOREACH (ScrArea *, area, &to->areabase) {
245 area->v1 = area->v1->newv;
246 area->v2 = area->v2->newv;
247 area->v3 = area->v3->newv;
248 area->v4 = area->v4->newv;
249
250 BLI_listbase_clear(&area->spacedata);
251 BLI_listbase_clear(&area->regionbase);
252 BLI_listbase_clear(&area->actionzones);
253 BLI_listbase_clear(&area->handlers);
254
255 ED_area_data_copy(area, from_area, true);
256
257 from_area = from_area->next;
258 }
259
260 /* put at zero (needed?) */
261 LISTBASE_FOREACH (ScrVert *, s1, &from->vertbase) {
262 s1->newv = nullptr;
263 }
264}
265
266void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new)
267{
268 screen_new->winid = win->winid;
269 screen_new->do_refresh = true;
270 screen_new->do_draw = true;
271}
272
274{
275 if (sa_a == nullptr || sa_b == nullptr || sa_a == sa_b) {
276 return SCREEN_DIR_NONE;
277 }
278
279 short left_a = sa_a->v1->vec.x;
280 short right_a = sa_a->v3->vec.x;
281 short top_a = sa_a->v3->vec.y;
282 short bottom_a = sa_a->v1->vec.y;
283
284 short left_b = sa_b->v1->vec.x;
285 short right_b = sa_b->v3->vec.x;
286 short top_b = sa_b->v3->vec.y;
287 short bottom_b = sa_b->v1->vec.y;
288
289 /* How much these areas share a common edge. */
290 short overlapx = std::min(right_a, right_b) - std::max(left_a, left_b);
291 short overlapy = std::min(top_a, top_b) - std::max(bottom_a, bottom_b);
292
293 /* Minimum overlap required. */
294 const short minx = std::min({int(AREAJOINTOLERANCEX), right_a - left_a, right_b - left_b});
295 const short miny = std::min({int(AREAJOINTOLERANCEY), top_a - bottom_a, top_b - bottom_b});
296
297 if (top_a == bottom_b && overlapx >= minx) {
298 return eScreenDir(1); /* sa_a to bottom of sa_b = N */
299 }
300 if (bottom_a == top_b && overlapx >= minx) {
301 return eScreenDir(3); /* sa_a on top of sa_b = S */
302 }
303 if (left_a == right_b && overlapy >= miny) {
304 return eScreenDir(0); /* sa_a to right of sa_b = W */
305 }
306 if (right_a == left_b && overlapy >= miny) {
307 return eScreenDir(2); /* sa_a to left of sa_b = E */
308 }
309
310 return eScreenDir(-1);
311}
312
314 ScrArea *sa_a, ScrArea *sa_b, const eScreenDir dir, int *r_offset1, int *r_offset2)
315{
316 if (sa_a == nullptr || sa_b == nullptr) {
317 *r_offset1 = INT_MAX;
318 *r_offset2 = INT_MAX;
319 }
320 else if (dir == SCREEN_DIR_W) { /* West: sa on right and sa_b to the left. */
321 *r_offset1 = sa_b->v3->vec.y - sa_a->v2->vec.y;
322 *r_offset2 = sa_b->v4->vec.y - sa_a->v1->vec.y;
323 }
324 else if (dir == SCREEN_DIR_N) { /* North: sa below and sa_b above. */
325 *r_offset1 = sa_a->v2->vec.x - sa_b->v1->vec.x;
326 *r_offset2 = sa_a->v3->vec.x - sa_b->v4->vec.x;
327 }
328 else if (dir == SCREEN_DIR_E) { /* East: sa on left and sa_b to the right. */
329 *r_offset1 = sa_b->v2->vec.y - sa_a->v3->vec.y;
330 *r_offset2 = sa_b->v1->vec.y - sa_a->v4->vec.y;
331 }
332 else if (dir == SCREEN_DIR_S) { /* South: sa above and sa_b below. */
333 *r_offset1 = sa_a->v1->vec.x - sa_b->v2->vec.x;
334 *r_offset2 = sa_a->v4->vec.x - sa_b->v3->vec.x;
335 }
336 else {
338 *r_offset1 = INT_MAX;
339 *r_offset2 = INT_MAX;
340 }
341}
342
343/* Screen verts with horizontal position equal to from_x are moved to to_x. */
344static void screen_verts_halign(const wmWindow *win,
345 const bScreen *screen,
346 const short from_x,
347 const short to_x)
348{
349 ED_screen_verts_iter(win, screen, v1)
350 {
351 if (v1->vec.x == from_x) {
352 v1->vec.x = to_x;
353 }
354 }
355}
356
357/* Screen verts with vertical position equal to from_y are moved to to_y. */
358static void screen_verts_valign(const wmWindow *win,
359 const bScreen *screen,
360 const short from_y,
361 const short to_y)
362{
363 ED_screen_verts_iter(win, screen, v1)
364 {
365 if (v1->vec.y == from_y) {
366 v1->vec.y = to_y;
367 }
368 }
369}
370
371/* Test if two adjoining areas can be aligned by having their screen edges adjusted. */
373 ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2, eScreenDir dir)
374{
375 if (dir == SCREEN_DIR_NONE) {
376 return false;
377 }
378
379 int offset1;
380 int offset2;
381 area_getoffsets(sa1, sa2, dir, &offset1, &offset2);
382
384 if ((abs(offset1) >= tolerance) || (abs(offset2) >= tolerance)) {
385 /* Misalignment is too great. */
386 return false;
387 }
388
389 /* Areas that are _smaller_ than minimum sizes, sharing an edge to be moved. See #100772. */
390 if (SCREEN_DIR_IS_VERTICAL(dir)) {
391 const short xmin = std::min(sa1->v1->vec.x, sa2->v1->vec.x);
392 const short xmax = std::max(sa1->v3->vec.x, sa2->v3->vec.x);
393 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
394 if (ELEM(area, sa1, sa2)) {
395 continue;
396 }
397 if (area->v3->vec.x - area->v1->vec.x < tolerance &&
398 (area->v1->vec.x == xmin || area->v3->vec.x == xmax))
399 {
400 BKE_report(reports, RPT_ERROR, "A narrow vertical area interferes with this operation");
401 return false;
402 }
403 }
404 }
405 else {
406 const short ymin = std::min(sa1->v1->vec.y, sa2->v1->vec.y);
407 const short ymax = std::max(sa1->v3->vec.y, sa2->v3->vec.y);
408 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
409 if (ELEM(area, sa1, sa2)) {
410 continue;
411 }
412 if (area->v3->vec.y - area->v1->vec.y < tolerance &&
413 (area->v1->vec.y == ymin || area->v3->vec.y == ymax))
414 {
415 BKE_report(reports, RPT_ERROR, "A narrow horizontal area interferes with this operation");
416 return false;
417 }
418 }
419 }
420
421 return true;
422}
423
424/* Adjust all screen edges to allow joining two areas. 'dir' value is like area_getorientation().
425 */
428 bScreen *screen,
429 ScrArea *sa1,
430 ScrArea *sa2,
431 const eScreenDir dir)
432{
433 if (!screen_areas_can_align(reports, screen, sa1, sa2, dir)) {
434 return false;
435 }
436
437 wmWindow *win = CTX_wm_window(C);
438
439 if (SCREEN_DIR_IS_HORIZONTAL(dir)) {
440 /* horizontal join, use average for new top and bottom. */
441 int top = (sa1->v2->vec.y + sa2->v2->vec.y) / 2;
442 int bottom = (sa1->v4->vec.y + sa2->v4->vec.y) / 2;
443
444 /* Move edges exactly matching source top and bottom. */
445 screen_verts_valign(win, screen, sa1->v2->vec.y, top);
446 screen_verts_valign(win, screen, sa1->v4->vec.y, bottom);
447
448 /* Move edges exactly matching target top and bottom. */
449 screen_verts_valign(win, screen, sa2->v2->vec.y, top);
450 screen_verts_valign(win, screen, sa2->v4->vec.y, bottom);
451 }
452 else {
453 /* Vertical join, use averages for new left and right. */
454 int left = (sa1->v1->vec.x + sa2->v1->vec.x) / 2;
455 int right = (sa1->v3->vec.x + sa2->v3->vec.x) / 2;
456
457 /* Move edges exactly matching source left and right. */
458 screen_verts_halign(win, screen, sa1->v1->vec.x, left);
459 screen_verts_halign(win, screen, sa1->v3->vec.x, right);
460
461 /* Move edges exactly matching target left and right */
462 screen_verts_halign(win, screen, sa2->v1->vec.x, left);
463 screen_verts_halign(win, screen, sa2->v3->vec.x, right);
464 }
465
466 return true;
467}
468
469/* Simple join of two areas without any splitting. Will return false if not possible. */
471 bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2)
472{
473 const eScreenDir dir = area_getorientation(sa1, sa2);
474
475 /* Ensure that the area edges are exactly aligned. */
476 if (!screen_areas_align(C, reports, screen, sa1, sa2, dir)) {
477 return false;
478 }
479
480 if (dir == SCREEN_DIR_W) { /* sa1 to right of sa2 = West. */
481 sa1->v1 = sa2->v1; /* BL */
482 sa1->v2 = sa2->v2; /* TL */
483 screen_geom_edge_add(screen, sa1->v2, sa1->v3);
484 screen_geom_edge_add(screen, sa1->v1, sa1->v4);
485 }
486 else if (dir == SCREEN_DIR_N) { /* sa1 to bottom of sa2 = North. */
487 sa1->v2 = sa2->v2; /* TL */
488 sa1->v3 = sa2->v3; /* TR */
489 screen_geom_edge_add(screen, sa1->v1, sa1->v2);
490 screen_geom_edge_add(screen, sa1->v3, sa1->v4);
491 }
492 else if (dir == SCREEN_DIR_E) { /* sa1 to left of sa2 = East. */
493 sa1->v3 = sa2->v3; /* TR */
494 sa1->v4 = sa2->v4; /* BR */
495 screen_geom_edge_add(screen, sa1->v2, sa1->v3);
496 screen_geom_edge_add(screen, sa1->v1, sa1->v4);
497 }
498 else if (dir == SCREEN_DIR_S) { /* sa1 on top of sa2 = South. */
499 sa1->v1 = sa2->v1; /* BL */
500 sa1->v4 = sa2->v4; /* BR */
501 screen_geom_edge_add(screen, sa1->v1, sa1->v2);
502 screen_geom_edge_add(screen, sa1->v3, sa1->v4);
503 }
504
505 screen_delarea(C, screen, sa2);
507 /* Update preview thumbnail */
508 BKE_icon_changed(screen->id.icon_id);
509
510 return true;
511}
512
513/* Slice off and return new area. "Reverse" gives right/bottom, rather than left/top. */
515 bContext *C, bScreen *screen, ScrArea **area, int size, eScreenDir dir, bool reverse)
516{
517 const bool vertical = SCREEN_DIR_IS_VERTICAL(dir);
518 if (abs(size) < (vertical ? AREAJOINTOLERANCEX : AREAJOINTOLERANCEY)) {
519 return nullptr;
520 }
521
522 /* Measurement with ScrVerts because winx and winy might not be correct at this time. */
523 float fac = abs(size) / float(vertical ? ((*area)->v3->vec.x - (*area)->v1->vec.x) :
524 ((*area)->v3->vec.y - (*area)->v1->vec.y));
525 fac = (reverse == vertical) ? 1.0f - fac : fac;
526 ScrArea *newsa = area_split(
527 CTX_wm_window(C), screen, *area, vertical ? SCREEN_AXIS_V : SCREEN_AXIS_H, fac, true);
528
529 /* area_split always returns smallest of the two areas, so might have to swap. */
530 if (((fac > 0.5f) == vertical) != reverse) {
531 ScrArea *temp = *area;
532 *area = newsa;
533 newsa = temp;
534 }
535
536 return newsa;
537}
538
539/* Join any two neighboring areas. Might create new areas, kept if over min_remainder. */
542 bScreen *screen,
543 ScrArea *sa1,
544 ScrArea *sa2,
545 bool close_all_remainders)
546{
547 const eScreenDir dir = area_getorientation(sa1, sa2);
548 if (dir == SCREEN_DIR_NONE) {
549 return false;
550 }
551
552 int offset1;
553 int offset2;
554 area_getoffsets(sa1, sa2, dir, &offset1, &offset2);
555
556 /* Split Left/Top into new area if overhanging. */
557 ScrArea *side1 = screen_area_trim(C, screen, (offset1 > 0) ? &sa2 : &sa1, offset1, dir, false);
558
559 /* Split Right/Bottom into new area if overhanging. */
560 ScrArea *side2 = screen_area_trim(C, screen, (offset2 > 0) ? &sa1 : &sa2, offset2, dir, true);
561
562 /* The two areas now line up, so join them. */
563 screen_area_join_aligned(C, reports, screen, sa1, sa2);
564
565 if (close_all_remainders || offset1 < 0 || offset2 > 0) {
566 /* Close both if trimming `sa1`. */
567 screen_area_close(C, reports, screen, side1);
568 screen_area_close(C, reports, screen, side2);
569 }
570 else {
571 /* Force full rebuild. #130732 */
572 ED_area_tag_redraw(side1);
573 ED_area_tag_redraw(side2);
574 }
575
576 if (sa1 != CTX_wm_area(C)) {
577 /* Active area has changed so active region could be invalid. It is
578 * safe to set null and let it be set later by mouse position. #131751. */
579 screen->active_region = nullptr;
580 }
581
582 BKE_icon_changed(screen->id.icon_id);
583 return true;
584}
585
587{
588 return screen_area_join_ex(C, reports, screen, sa1, sa2, false);
589}
590
592{
593 if (area == nullptr) {
594 return false;
595 }
596
597 ScrArea *sa2 = nullptr;
598 float best_alignment = 0.0f;
599
600 LISTBASE_FOREACH (ScrArea *, neighbor, &screen->areabase) {
601 const eScreenDir dir = area_getorientation(area, neighbor);
602 /* Must at least partially share an edge and not be a global area. */
603 if ((dir != SCREEN_DIR_NONE) && (neighbor->global == nullptr)) {
604 /* Winx/Winy might not be updated yet, so get lengths from verts. */
605 const bool vertical = SCREEN_DIR_IS_VERTICAL(dir);
606 const int area_length = vertical ? (area->v3->vec.x - area->v1->vec.x) :
607 (area->v3->vec.y - area->v1->vec.y);
608 const int ar_length = vertical ? (neighbor->v3->vec.x - neighbor->v1->vec.x) :
609 (neighbor->v3->vec.y - neighbor->v1->vec.y);
610 /* Calculate the ratio of the lengths of the shared edges. */
611 float alignment = std::min(area_length, ar_length) / float(std::max(area_length, ar_length));
612 if (alignment > best_alignment) {
613 best_alignment = alignment;
614 sa2 = neighbor;
615 }
616 }
617 }
618
619 /* Join from neighbor into this area to close it. */
620 return screen_area_join_ex(C, reports, screen, sa2, area, true);
621}
622
623void screen_area_spacelink_add(const Scene *scene, ScrArea *area, eSpace_Type space_type)
624{
625 SpaceType *stype = BKE_spacetype_from_id(space_type);
626 SpaceLink *slink = stype->create(area, scene);
627
628 area->regionbase = slink->regionbase;
629
630 BLI_addhead(&area->spacedata, slink);
632}
633
634/* ****************** EXPORTED API TO OTHER MODULES *************************** */
635
636/* screen sets cursor based on active region */
637static void region_cursor_set_ex(wmWindow *win, ScrArea *area, ARegion *region, bool swin_changed)
638{
639 BLI_assert(WM_window_get_active_screen(win)->active_region == region);
640 if (win->tag_cursor_refresh || swin_changed ||
641 (region->runtime->type && region->runtime->type->event_cursor))
642 {
643 win->tag_cursor_refresh = false;
644 ED_region_cursor_set(win, area, region);
645 }
646}
647
648static void region_cursor_set(wmWindow *win, bool swin_changed)
649{
651
652 ED_screen_areas_iter (win, screen, area) {
653 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
654 if (region == screen->active_region) {
655 region_cursor_set_ex(win, area, region, swin_changed);
656 return;
657 }
658 }
659 }
660}
661
663{
664 wmWindow *win = CTX_wm_window(C);
665 bScreen *screen = CTX_wm_screen(C);
666
667 /* generic notes */
668 switch (note->category) {
669 case NC_WM:
670 if (note->data == ND_FILEREAD) {
671 screen->do_draw = true;
672 }
673 break;
674 case NC_WINDOW:
677 }
678 screen->do_draw = true;
679 break;
680 case NC_SCREEN:
681 if (note->action == NA_EDITED) {
684 }
685 screen->do_draw = screen->do_refresh = true;
686 }
687 break;
688 case NC_SCENE:
689 if (note->data == ND_MODE) {
690 region_cursor_set(win, true);
691 }
692 break;
693 }
694}
695
696static bool region_poll(const bContext *C,
697 const bScreen *screen,
698 const ScrArea *area,
699 const ARegion *region)
700{
701 if (!region->runtime->type) {
703 return false;
704 }
705 if (!region->runtime->type->poll) {
706 /* Show region by default. */
707 return true;
708 }
709
710 RegionPollParams params = {nullptr};
711 params.screen = screen;
712 params.area = area;
713 params.region = region;
714 params.context = C;
715
716 return region->runtime->type->poll(&params);
717}
718
719bool area_regions_poll(bContext *C, const bScreen *screen, ScrArea *area)
720{
721 bScreen *prev_screen = CTX_wm_screen(C);
722 ScrArea *prev_area = CTX_wm_area(C);
723 ARegion *prev_region = CTX_wm_region(C);
724
725 CTX_wm_screen_set(C, const_cast<bScreen *>(screen));
726 CTX_wm_area_set(C, area);
727
728 bool any_changed = false;
729 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
730 const int old_region_flag = region->flag;
731
732 region->flag &= ~RGN_FLAG_POLL_FAILED;
733
734 CTX_wm_region_set(C, region);
735 if (region_poll(C, screen, area, region) == false) {
736 region->flag |= RGN_FLAG_POLL_FAILED;
737 }
738 else if (region->runtime->type && region->runtime->type->on_poll_success) {
739 region->runtime->type->on_poll_success(C, region);
740 }
741
742 if (old_region_flag != region->flag) {
743 any_changed = true;
744
745 /* Enforce complete re-init. */
746 region->v2d.flag &= ~V2D_IS_INIT;
747
748 const bool is_hidden = region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_POLL_FAILED);
749 /* Don't re-init areas, caller is expected to handle that. In fact, this code might actually
750 * run as part of #ED_area_init(). */
751 const bool do_init = false;
752 ED_region_visibility_change_update_ex(C, area, region, is_hidden, do_init);
753 }
754 }
755
756 CTX_wm_screen_set(C, prev_screen);
757 CTX_wm_area_set(C, prev_area);
758 CTX_wm_region_set(C, prev_region);
759
760 return any_changed;
761}
762
766static bool screen_regions_poll(bContext *C, wmWindow *win, const bScreen *screen)
767{
768 wmWindow *prev_win = CTX_wm_window(C);
769 ScrArea *prev_area = CTX_wm_area(C);
770 ARegion *prev_region = CTX_wm_region(C);
771
772 CTX_wm_window_set(C, win);
773
774 bool any_changed = false;
775 ED_screen_areas_iter (win, screen, area) {
776 if (area_regions_poll(C, screen, area)) {
777 any_changed = true;
778 }
779 }
780
781 CTX_wm_window_set(C, prev_win);
782 CTX_wm_area_set(C, prev_area);
783 CTX_wm_region_set(C, prev_region);
784
785 return any_changed;
786}
787
795{
797
798 /* Exception for background mode, we only need the screen context. */
799 if (!G.background) {
800 if (screen->do_refresh) {
801 ED_screen_areas_iter (win, screen, area) {
802 /* Ensure all area and region types are set before polling, it depends on it (see #130583).
803 */
805 }
806 }
807
808 /* Returns true if a change was done that requires refreshing. */
809 if (screen_regions_poll(C, win, screen)) {
810 screen->do_refresh = true;
811 }
812
813 if (!screen->do_refresh) {
814 return;
815 }
816
817 /* Called even when creating the ghost window fails in #WM_window_open. */
818 if (win->ghostwin) {
819 /* Header size depends on DPI, let's verify. */
821 }
822
824
825 screen_geom_vertices_scale(win, screen);
826
827 ED_screen_areas_iter (win, screen, area) {
828 /* Set space-type and region callbacks, calls init() */
829 /* Sets sub-windows for regions, adds handlers. */
830 ED_area_init(C, win, area);
831 }
832
833 /* wake up animtimer */
834 if (screen->animtimer) {
835 WM_event_timer_sleep(wm, win, screen->animtimer, false);
836 }
837 }
838
839 if (G.debug & G_DEBUG_EVENTS) {
840 printf("%s: set screen\n", __func__);
841 }
842 screen->do_refresh = false;
843 /* Prevent multi-window errors. */
844 screen->winid = win->winid;
845
846 screen->context = reinterpret_cast<void *>(ed_screen_context);
847}
848
850{
852 /* Enforce full refresh. */
853 screen->do_refresh = true;
854 screen_refresh_if_needed(C, wm, win);
855}
856
858{
859 wmWindow *prev_ctx_win = CTX_wm_window(C);
860 BLI_SCOPED_DEFER([&]() { CTX_wm_window_set(C, prev_ctx_win); });
861
862 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
863 /* Region polls may need window/screen context. */
864 CTX_wm_window_set(C, win);
865
866 if (BKE_workspace_active_get(win->workspace_hook) == nullptr) {
867 BKE_workspace_active_set(win->workspace_hook,
868 static_cast<WorkSpace *>(bmain->workspaces.first));
869 }
870
871 ED_screen_refresh(C, wm, win);
872 if (win->eventstate) {
873 ED_screen_set_active_region(nullptr, win, win->eventstate->xy);
874 }
875 }
876
877 if (U.uiflag & USER_HEADER_FROM_PREF) {
878 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
880 }
881 }
882}
883
888
890{
891 ED_region_exit(C, region);
892 BKE_area_region_free(area->type, region);
893 BLI_freelinkN(&area->regionbase, region);
894}
895
896/* *********** exit calls are for closing running stuff ******** */
897
899{
901 wmWindow *win = CTX_wm_window(C);
902 ARegion *prevar = CTX_wm_region(C);
903
904 if (region->runtime->type && region->runtime->type->exit) {
905 region->runtime->type->exit(wm, region);
906 }
907
908 CTX_wm_region_set(C, region);
909
910 WM_event_remove_handlers(C, &region->runtime->handlers);
911 WM_event_modal_handler_region_replace(win, region, nullptr);
912
913 /* Stop panel animation in this region if there are any. */
914 LISTBASE_FOREACH (Panel *, panel, &region->panels) {
916 }
917
918 if (region->regiontype == RGN_TYPE_TEMPORARY) {
919 /* This may be a popup region such as a popover or splash screen.
920 * In the case of popups which spawn popups it's possible for
921 * the parent popup to be freed *before* a popup which created it.
922 * The child may have a reference to the freed parent unless cleared here, see: #122132.
923 *
924 * Having parent popups freed before the popups they spawn could be investigated although
925 * they're not technically nested as they're both stored in #Screen::regionbase. */
926 WM_event_ui_handler_region_popup_replace(win, region, nullptr);
927 }
928
929 WM_draw_region_free(region);
930 /* The region is not in a state that it can be visible in anymore. Reinitializing is needed. */
931 region->runtime->visible = false;
932
933 MEM_SAFE_FREE(region->runtime->headerstr);
934
935 if (region->runtime->regiontimer) {
936 WM_event_timer_remove(wm, win, region->runtime->regiontimer);
937 region->runtime->regiontimer = nullptr;
938 }
939
941
942 CTX_wm_region_set(C, prevar);
943}
944
946{
948 wmWindow *win = CTX_wm_window(C);
949 ScrArea *prevsa = CTX_wm_area(C);
950
951 if (area->type && area->type->exit) {
952 area->type->exit(wm, area);
953 }
954
955 CTX_wm_area_set(C, area);
956
957 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
958 ED_region_exit(C, region);
959 }
960
962 WM_event_modal_handler_area_replace(win, area, nullptr);
963
964 CTX_wm_area_set(C, prevsa);
965}
966
967void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
968{
970 wmWindow *prevwin = CTX_wm_window(C);
971
972 CTX_wm_window_set(C, window);
973
974 if (screen->animtimer) {
975 WM_event_timer_remove(wm, window, screen->animtimer);
976
978 Scene *scene = WM_window_get_active_scene(prevwin);
979 Scene *scene_eval = DEG_get_evaluated(depsgraph, scene);
980 BKE_sound_stop_scene(scene_eval);
981 }
982 screen->animtimer = nullptr;
983 screen->scrubbing = false;
984
985 screen->active_region = nullptr;
986
987 LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) {
988 ED_region_exit(C, region);
989 }
990 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
991 ED_area_exit(C, area);
992 }
993 /* Don't use ED_screen_areas_iter here, it skips hidden areas. */
994 LISTBASE_FOREACH (ScrArea *, area, &window->global_areas.areabase) {
995 ED_area_exit(C, area);
996 }
997
998 /* mark it available for use for other windows */
999 screen->winid = 0;
1000
1001 if (!WM_window_is_temp_screen(prevwin)) {
1002 /* use previous window if possible */
1003 CTX_wm_window_set(C, prevwin);
1004 }
1005 else {
1006 /* none otherwise */
1007 CTX_wm_window_set(C, nullptr);
1008 }
1009}
1010
1012{
1013 if (area->type && area->type->space_name_get) {
1014 return area->type->space_name_get(area);
1015 }
1016
1018 const EnumPropertyItem item = rna_enum_space_type_items[index];
1019 return item.name;
1020}
1021
1022int ED_area_icon(const ScrArea *area)
1023{
1024 if (area->type && area->type->space_icon_get) {
1025 return area->type->space_icon_get(area);
1026 }
1027
1029 const EnumPropertyItem item = rna_enum_space_type_items[index];
1030 return item.icon;
1031}
1032
1033/* *********************************** */
1034
1035/* case when on area-edge or in azones, or outside window */
1036static void screen_cursor_set(wmWindow *win, const int xy[2])
1037{
1038 const bScreen *screen = WM_window_get_active_screen(win);
1039 AZone *az = nullptr;
1040 ScrArea *area = nullptr;
1041
1042 LISTBASE_FOREACH (ScrArea *, area_iter, &screen->areabase) {
1043 az = ED_area_actionzone_find_xy(area_iter, xy);
1044 /* We used to exclude AZONE_REGION_SCROLL as those used
1045 * to overlap screen edges, but they no longer do so. */
1046 if (az) {
1047 area = area_iter;
1048 break;
1049 }
1050 }
1051
1052 if (area) {
1053 if (az->type == AZONE_AREA) {
1055 }
1056 else if (az->type == AZONE_REGION_SCROLL) {
1058 }
1059 else if (az->type == AZONE_REGION) {
1062 }
1063 else {
1065 }
1066 }
1067 }
1068 else {
1069 ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, xy[0], xy[1]);
1070
1071 if (actedge) {
1072 if (screen_geom_edge_is_horizontal(actedge)) {
1074 }
1075 else {
1077 }
1078 }
1079 else {
1081 }
1082 }
1083}
1084
1086{
1087 bScreen *screen = WM_window_get_active_screen(win);
1088 if (screen == nullptr) {
1089 return;
1090 }
1091
1092 ScrArea *area = nullptr;
1093 ARegion *region_prev = screen->active_region;
1094
1095 ED_screen_areas_iter (win, screen, area_iter) {
1096 if (xy[0] > (area_iter->totrct.xmin + BORDERPADDING) &&
1097 xy[0] < (area_iter->totrct.xmax - BORDERPADDING))
1098 {
1099 if (xy[1] > (area_iter->totrct.ymin + BORDERPADDING) &&
1100 xy[1] < (area_iter->totrct.ymax - BORDERPADDING))
1101 {
1102 if (ED_area_azones_update(area_iter, xy) == nullptr) {
1103 area = area_iter;
1104 break;
1105 }
1106 }
1107 }
1108 }
1109 if (area) {
1110 /* Make overlap active when mouse over. */
1111 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1112 if (ED_region_contains_xy(region, xy)) {
1113 screen->active_region = region;
1114 break;
1115 }
1116 }
1117 }
1118 else {
1119 screen->active_region = nullptr;
1120 }
1121
1122 if (region_prev != screen->active_region || !screen->active_region) {
1124 }
1125
1126 /* Check for redraw headers. */
1127 if (region_prev != screen->active_region) {
1128
1129 ED_screen_areas_iter (win, screen, area_iter) {
1130 bool do_draw = false;
1131
1132 LISTBASE_FOREACH (ARegion *, region, &area_iter->regionbase) {
1133 /* Call old area's deactivate if assigned. */
1134 if (region == region_prev && area_iter->type && area_iter->type->deactivate) {
1135 area_iter->type->deactivate(area_iter);
1136 }
1137
1138 if (region == region_prev && region != screen->active_region) {
1139 wmGizmoMap *gzmap = region_prev->runtime->gizmo_map;
1140 if (gzmap) {
1141 if (WM_gizmo_highlight_set(gzmap, nullptr)) {
1143 }
1144 }
1145 }
1146
1147 if (ELEM(region, region_prev, screen->active_region)) {
1148 do_draw = true;
1149 }
1150 }
1151
1152 if (do_draw) {
1153 LISTBASE_FOREACH (ARegion *, region, &area_iter->regionbase) {
1154 if (ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) {
1156 }
1157 }
1158 }
1159 }
1160
1161 /* Ensure test-motion values are never shared between regions. */
1162 const int mval[2] = {-1, -1};
1163 const bool use_cycle = !WM_cursor_test_motion_and_update(mval);
1164 UNUSED_VARS(use_cycle);
1165 }
1166
1167 /* Cursors, for time being set always on edges,
1168 * otherwise the active region doesn't switch. */
1169 if (screen->active_region == nullptr) {
1170 screen_cursor_set(win, xy);
1171 }
1172 else {
1173 /* Notifier invokes freeing the buttons... causing a bit too much redraws. */
1174 region_cursor_set_ex(win, area, screen->active_region, region_prev != screen->active_region);
1175
1176 if (region_prev != screen->active_region) {
1177 /* This used to be a notifier, but needs to be done immediate
1178 * because it can undo setting the right button as active due
1179 * to delayed notifier handling. */
1180 if (C) {
1182 }
1183 }
1184 }
1185}
1186
1188{
1189 wmWindow *win = CTX_wm_window(C);
1190 bScreen *screen = CTX_wm_screen(C);
1191 ScrArea *area = CTX_wm_area(C);
1192
1193 if (win && screen && area) {
1194 AZone *az = ED_area_actionzone_find_xy(area, win->eventstate->xy);
1195
1196 if (az && az->type == AZONE_REGION) {
1197 return 1;
1198 }
1199
1200 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1201 if (region == screen->active_region) {
1202 return 1;
1203 }
1204 }
1205 }
1206 return 0;
1207}
1208
1214 const rcti *rect,
1215 eSpace_Type space_type)
1216{
1217 ScrVert *bottom_left = screen_geom_vertex_add_ex(area_map, rect->xmin, rect->ymin);
1218 ScrVert *top_left = screen_geom_vertex_add_ex(area_map, rect->xmin, rect->ymax);
1219 ScrVert *top_right = screen_geom_vertex_add_ex(area_map, rect->xmax, rect->ymax);
1220 ScrVert *bottom_right = screen_geom_vertex_add_ex(area_map, rect->xmax, rect->ymin);
1221
1222 screen_geom_edge_add_ex(area_map, bottom_left, top_left);
1223 screen_geom_edge_add_ex(area_map, top_left, top_right);
1224 screen_geom_edge_add_ex(area_map, top_right, bottom_right);
1225 screen_geom_edge_add_ex(area_map, bottom_right, bottom_left);
1226
1227 return screen_addarea_ex(area_map, bottom_left, top_left, top_right, bottom_right, space_type);
1228}
1229
1230static void screen_area_set_geometry_rect(ScrArea *area, const rcti *rect)
1231{
1232 area->v1->vec.x = rect->xmin;
1233 area->v1->vec.y = rect->ymin;
1234 area->v2->vec.x = rect->xmin;
1235 area->v2->vec.y = rect->ymax;
1236 area->v3->vec.x = rect->xmax;
1237 area->v3->vec.y = rect->ymax;
1238 area->v4->vec.x = rect->xmax;
1239 area->v4->vec.y = rect->ymin;
1240}
1241
1243 bScreen *screen,
1244 const eSpace_Type space_type,
1245 GlobalAreaAlign align,
1246 const rcti *rect,
1247 const short height_cur,
1248 const short height_min,
1249 const short height_max)
1250{
1251 /* Full-screens shouldn't have global areas. Don't touch them. */
1252 if (screen->state == SCREENFULL) {
1253 return;
1254 }
1255
1256 ScrArea *area = nullptr;
1257 LISTBASE_FOREACH (ScrArea *, area_iter, &win->global_areas.areabase) {
1258 if (area_iter->spacetype == space_type) {
1259 area = area_iter;
1260 break;
1261 }
1262 }
1263
1264 if (area) {
1266 }
1267 else {
1268 area = screen_area_create_with_geometry(&win->global_areas, rect, space_type);
1270
1271 /* Data specific to global areas. */
1272 area->global = MEM_callocN<ScrGlobalAreaData>(__func__);
1273 area->global->size_max = height_max;
1274 area->global->size_min = height_min;
1275 area->global->align = align;
1276 }
1277
1278 if (area->global->cur_fixed_height != height_cur) {
1279 /* Refresh layout if size changes. */
1280 area->global->cur_fixed_height = height_cur;
1281 screen->do_refresh = true;
1282 }
1283}
1284
1286{
1287 return int(ceilf(ED_area_headersize() / UI_SCALE_FAC));
1288}
1289
1291{
1292 const blender::int2 win_size = WM_window_native_pixel_size(win);
1293 const short size = screen_global_header_size();
1294 rcti rect;
1295
1296 BLI_rcti_init(&rect, 0, win_size[0] - 1, 0, win_size[1] - 1);
1297 rect.ymin = rect.ymax - size;
1298
1300 win, screen, SPACE_TOPBAR, GLOBAL_AREA_ALIGN_TOP, &rect, size, size, size);
1301}
1302
1304{
1305 const blender::int2 win_size = WM_window_native_pixel_size(win);
1306 const short size_min = 1;
1307 const short size_max = 0.85f * screen_global_header_size();
1308 const short size = (screen->flag & SCREEN_COLLAPSE_STATUSBAR) ? size_min : size_max;
1309 rcti rect;
1310
1311 BLI_rcti_init(&rect, 0, win_size[0] - 1, 0, win_size[1] - 1);
1312 rect.ymax = rect.ymin + size_max;
1313
1315 win, screen, SPACE_STATUSBAR, GLOBAL_AREA_ALIGN_BOTTOM, &rect, size, size_min, size_max);
1316}
1317
1319{
1320 /* Update screen flags from height in window, this is weak and perhaps
1321 * global areas should just become part of the screen instead. */
1323
1325
1327 if (area->global->cur_fixed_height == area->global->size_min) {
1328 if (area->spacetype == SPACE_STATUSBAR) {
1330 }
1331 }
1332 }
1333}
1334
1336{
1337 /* Don't create global area for child and temporary windows. */
1339 if (!WM_window_is_main_top_level(win)) {
1340 if (win->global_areas.areabase.first) {
1341 screen->do_refresh = true;
1343 }
1344 return;
1345 }
1346
1349}
1350
1351/* -------------------------------------------------------------------- */
1352/* Screen changing */
1353
1355 bScreen *screen_old, bScreen *screen_new, Main *bmain, bContext *C, wmWindow *win)
1356{
1357 UNUSED_VARS_NDEBUG(bmain);
1358 BLI_assert(BLI_findindex(&bmain->screens, screen_new) != -1);
1359
1360 if (screen_old != screen_new) {
1361 wmTimer *wt = screen_old->animtimer;
1362
1363 /* Remove popup handlers (menus), while unlikely, it's possible an "error"
1364 * popup is displayed when switching screens, see: #144958. */
1366
1367 /* remove handlers referencing areas in old screen */
1368 LISTBASE_FOREACH (ScrArea *, area, &screen_old->areabase) {
1370 }
1371
1372 /* we put timer to sleep, so screen_exit has to think there's no timer */
1373 screen_old->animtimer = nullptr;
1374 if (wt) {
1375 WM_event_timer_sleep(CTX_wm_manager(C), win, wt, true);
1376 }
1377 ED_screen_exit(C, win, screen_old);
1378
1379 /* Same scene, "transfer" playback to new screen. */
1380 if (wt) {
1381 screen_new->animtimer = wt;
1382 }
1383 }
1384}
1385
1387{
1388 Scene *scene = WM_window_get_active_scene(win);
1390 WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, screen);
1391
1392 CTX_wm_window_set(C, win); /* stores C->wm.screen... hrmf */
1393
1395
1396 BKE_screen_view3d_scene_sync(screen, scene); /* sync new screen with scene data */
1399
1400 /* Makes button highlights work. */
1402}
1403
1405{
1406 Main *bmain = CTX_data_main(C);
1407 wmWindow *win = CTX_wm_window(C);
1409 WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, screen);
1410 bScreen *screen_old = CTX_wm_screen(C);
1411
1412 /* Get the actual layout/screen to be activated (guaranteed to be unused, even if that means
1413 * having to duplicate an existing one). */
1415 bmain, workspace, layout, layout, win);
1416 bScreen *screen_new = BKE_workspace_layout_screen_get(layout_new);
1417
1418 screen_change_prepare(screen_old, screen_new, bmain, C, win);
1419
1420 if (screen_old != screen_new) {
1421 WM_window_set_active_screen(win, workspace, screen_new);
1422 screen_change_update(C, win, screen_new);
1423
1424 return true;
1425 }
1426
1427 return false;
1428}
1429
1431 ViewLayer *view_layer,
1432 ScrArea *area,
1433 View3D *v3d)
1434{
1435 /* fix any cameras that are used in the 3d view but not in the scene */
1436 BKE_screen_view3d_sync(v3d, scene);
1437
1438 BKE_view_layer_synced_ensure(scene, view_layer);
1439 if (!v3d->camera || !BKE_view_layer_base_find(view_layer, v3d->camera)) {
1440 v3d->camera = BKE_view_layer_camera_find(scene, view_layer);
1441 // XXX if (screen == curscreen) handle_view3d_lock();
1442 if (!v3d->camera) {
1443 ListBase *regionbase;
1444
1445 /* regionbase is in different place depending if space is active */
1446 if (v3d == area->spacedata.first) {
1447 regionbase = &area->regionbase;
1448 }
1449 else {
1450 regionbase = &v3d->regionbase;
1451 }
1452
1453 LISTBASE_FOREACH (ARegion *, region, regionbase) {
1454 if (region->regiontype == RGN_TYPE_WINDOW) {
1455 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1456 if (rv3d->persp == RV3D_CAMOB) {
1457 rv3d->persp = RV3D_PERSP;
1458 }
1459 }
1460 }
1461 }
1462 }
1463}
1464
1466 wmWindow *win,
1467 Scene *scene,
1468 const bool refresh_toolsystem)
1469{
1470#if 0
1471 ViewLayer *view_layer_old = WM_window_get_active_view_layer(win);
1472#endif
1473
1474 /* Switch scene. */
1475 win->scene = scene;
1476 if (CTX_wm_window(C) == win) {
1477 CTX_data_scene_set(C, scene);
1478 }
1479
1480 /* Ensure the view layer name is updated. */
1482 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
1483
1484#if 0
1485 /* Mode Syncing. */
1486 if (view_layer_old) {
1487 WorkSpace *workspace = CTX_wm_workspace(C);
1488 Object *obact_new = BKE_view_layer_active_object_get(view_layer);
1489 UNUSED_VARS(obact_new);
1490 eObjectMode object_mode_old = workspace->object_mode;
1491 Object *obact_old = BKE_view_layer_active_object_get(view_layer_old);
1492 UNUSED_VARS(obact_old, object_mode_old);
1493 }
1494#endif
1495
1496 /* Update 3D view cameras. */
1497 const bScreen *screen = WM_window_get_active_screen(win);
1498 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
1499 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
1500 if (sl->spacetype == SPACE_VIEW3D) {
1501 View3D *v3d = (View3D *)sl;
1502 screen_set_3dview_camera(scene, view_layer, area, v3d);
1503 }
1504 }
1505 }
1506
1507 if (refresh_toolsystem) {
1509 }
1510}
1511
1513{
1514 bScreen *newscreen = nullptr;
1515 ScrArea *newsa = nullptr;
1516 SpaceLink *newsl;
1517
1518 if (!area || area->full == nullptr) {
1520 newsa = static_cast<ScrArea *>(newscreen->areabase.first);
1521 BLI_assert(newsa->spacetype == SPACE_EMPTY);
1522 }
1523
1524 if (!newsa) {
1525 newsa = area;
1526 }
1527
1528 BLI_assert(newsa);
1529 newsl = static_cast<SpaceLink *>(newsa->spacedata.first);
1530
1531 /* Tag the active space before changing, so we can identify it when user wants to go back. */
1532 if (newsl && (newsl->link_flag & SPACE_FLAG_TYPE_TEMPORARY) == 0) {
1534 }
1535
1536 ED_area_newspace(C, newsa, type, (newsl && newsl->link_flag & SPACE_FLAG_TYPE_TEMPORARY));
1537
1538 if (newscreen) {
1539 ED_screen_change(C, newscreen);
1540 }
1541
1542 return newsa;
1543}
1544
1546{
1547 BLI_assert(area->full);
1548
1549 if (area->flag & AREA_FLAG_STACKED_FULLSCREEN) {
1550 /* Stacked full-screen -> only go back to previous area and don't toggle out of full-screen. */
1551 ED_area_prevspace(C, area);
1552 }
1553 else {
1555 }
1556}
1557
1559{
1560 SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
1561
1562 /* In case nether functions below run. */
1563 ED_area_tag_redraw(area);
1564
1566 ED_area_prevspace(C, area);
1567 }
1568
1569 if (area->full) {
1571 }
1572}
1573
1575{
1576 wmWindow *win = CTX_wm_window(C);
1577 SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
1578 bScreen *screen = CTX_wm_screen(C);
1579 short state = (screen ? screen->state : short(SCREENMAXIMIZED));
1580
1581 /* If full-screen area has a temporary space (such as a file browser or full-screen render
1582 * overlaid on top of an existing setup) then return to the previous space. */
1583
1584 if (sl->next) {
1587 }
1588 else {
1589 ED_screen_state_toggle(C, win, area, state);
1590 }
1591 /* WARNING: 'area' may be freed */
1592 }
1593 /* otherwise just tile the area again */
1594 else {
1595 ED_screen_state_toggle(C, win, area, state);
1596 }
1597}
1598
1609 wmWindow *win,
1610 ScrArea *toggle_area,
1611 int state)
1612{
1613 Main *bmain = CTX_data_main(C);
1614 WorkSpace *workspace = WM_window_get_active_workspace(win);
1615
1616 /* change from SCREENNORMAL to new state */
1617 WorkSpaceLayout *layout_new;
1618 ScrArea *newa;
1619 char newname[MAX_ID_NAME - 2];
1620
1622
1623 bScreen *oldscreen = WM_window_get_active_screen(win);
1624
1625 oldscreen->state = state;
1626 SNPRINTF(newname, "%s-%s", oldscreen->id.name + 2, "nonnormal");
1627
1628 layout_new = ED_workspace_layout_add(bmain, workspace, win, newname);
1629
1630 bScreen *screen = BKE_workspace_layout_screen_get(layout_new);
1631 screen->state = state;
1632 screen->redraws_flag = oldscreen->redraws_flag;
1633 screen->temp = oldscreen->temp;
1634 screen->flag = oldscreen->flag;
1635
1636 /* timer */
1637 screen->animtimer = oldscreen->animtimer;
1638 oldscreen->animtimer = nullptr;
1639
1640 newa = (ScrArea *)screen->areabase.first;
1641
1642 /* swap area */
1643 if (toggle_area) {
1644 ED_area_data_swap(newa, toggle_area);
1645 newa->flag = toggle_area->flag; /* mostly for AREA_FLAG_WASFULLSCREEN */
1646 }
1647
1648 if (state == SCREENFULL) {
1649 /* temporarily hide global areas */
1650 LISTBASE_FOREACH (ScrArea *, glob_area, &win->global_areas.areabase) {
1651 glob_area->global->flag |= GLOBAL_AREA_IS_HIDDEN;
1652 }
1653 /* temporarily hide the side panels/header */
1654 LISTBASE_FOREACH (ARegion *, region, &newa->regionbase) {
1655 region->flagfullscreen = region->flag;
1656
1657 if (ELEM(region->regiontype,
1667 {
1668 region->flag |= RGN_FLAG_HIDDEN;
1669 }
1670 }
1671 }
1672
1673 if (toggle_area) {
1674 toggle_area->full = oldscreen;
1675 }
1676 newa->full = oldscreen;
1677
1678 ED_area_tag_refresh(newa);
1679
1680 return screen;
1681}
1682
1687
1689{
1691 WorkSpace *workspace = WM_window_get_active_workspace(win);
1692
1693 if (area) {
1694 /* ensure we don't have a button active anymore, can crash when
1695 * switching screens with tooltip open because region and tooltip
1696 * are no longer in the same screen */
1697 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1698 UI_blocklist_free(C, region);
1699 if (region->runtime->regiontimer) {
1700 WM_event_timer_remove(wm, nullptr, region->runtime->regiontimer);
1701 region->runtime->regiontimer = nullptr;
1702 }
1703 }
1704
1705 /* prevent hanging status prints */
1706 ED_area_status_text(area, nullptr);
1707 ED_workspace_status_text(C, nullptr);
1708 }
1709 bScreen *screen;
1710 if (area && area->full) {
1712 /* restoring back to SCREENNORMAL */
1713 screen = area->full; /* the old screen to restore */
1714 bScreen *oldscreen = WM_window_get_active_screen(win); /* the one disappearing */
1715
1716 BLI_assert(BKE_workspace_layout_screen_get(layout_old) != screen);
1718
1719 screen->state = SCREENNORMAL;
1720 screen->flag = oldscreen->flag;
1721
1722 /* Find old area we may have swapped dummy space data to. It's swapped back here. */
1723 ScrArea *fullsa = nullptr;
1724 LISTBASE_FOREACH (ScrArea *, old, &screen->areabase) {
1725 /* area to restore from is always first */
1726 if (old->full && !fullsa) {
1727 fullsa = old;
1728 }
1729
1730 /* clear full screen state */
1731 old->full = nullptr;
1732 }
1733
1734 area->full = nullptr;
1735
1736 if (state == SCREENFULL) {
1737 /* unhide global areas */
1738 LISTBASE_FOREACH (ScrArea *, glob_area, &win->global_areas.areabase) {
1739 glob_area->global->flag &= ~GLOBAL_AREA_IS_HIDDEN;
1740 }
1741 /* restore the old side panels/header visibility */
1742 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1743 region->flag = region->flagfullscreen;
1744 }
1745 }
1746
1747 if (fullsa) {
1748 ED_area_data_swap(fullsa, area);
1749 ED_area_tag_refresh(fullsa);
1750 }
1751
1752 /* animtimer back */
1753 screen->animtimer = oldscreen->animtimer;
1754 oldscreen->animtimer = nullptr;
1755
1756 ED_screen_change(C, screen);
1757
1758 BKE_workspace_layout_remove(CTX_data_main(C), workspace, layout_old);
1759
1760 /* After we've restored back to SCREENNORMAL, we have to wait with
1761 * screen handling as it uses the area coords which aren't updated yet.
1762 * Without doing so, the screen handling gets wrong area coords,
1763 * which in worst case can lead to crashes (see #43139) */
1764 screen->skip_handling = true;
1765 }
1766 else {
1767 ScrArea *toggle_area = area;
1768
1769 /* use random area when we have no active one, e.g. when the
1770 * mouse is outside of the window and we open a file browser */
1771 if (!toggle_area || toggle_area->global) {
1772 bScreen *oldscreen = WM_window_get_active_screen(win);
1773 toggle_area = static_cast<ScrArea *>(oldscreen->areabase.first);
1774 }
1775
1776 screen = screen_state_to_nonnormal(C, win, toggle_area, state);
1777
1778 ED_screen_change(C, screen);
1779 }
1780
1781 BLI_assert(CTX_wm_screen(C) == screen);
1782 BLI_assert(CTX_wm_area(C) == nullptr); /* May have been freed. */
1783
1784 /* Setting the area is only needed for Python scripts that call
1785 * operators in succession before returning to the main event loop.
1786 * Without this, scripts can't run any operators that require
1787 * an area after toggling full-screen for example (see: #89526).
1788 * NOTE: an old comment stated this was "bad code",
1789 * however it doesn't cause problems so leave as-is. */
1790 CTX_wm_area_set(C, static_cast<ScrArea *>(screen->areabase.first));
1791
1792 return static_cast<ScrArea *>(screen->areabase.first);
1793}
1794
1796 const char *title,
1797 const rcti *rect_unscaled,
1798 eSpace_Type space_type,
1799 int display_type,
1800 bool dialog)
1801{
1802 ScrArea *area = nullptr;
1803
1804 switch (display_type) {
1806 if (WM_window_open(C,
1807 title,
1808 rect_unscaled,
1809 int(space_type),
1810 false,
1811 dialog,
1812 true,
1814 nullptr,
1815 nullptr))
1816 {
1817 area = CTX_wm_area(C);
1818 }
1819 break;
1821 ScrArea *ctx_area = CTX_wm_area(C);
1822
1823 if (ctx_area != nullptr && ctx_area->full) {
1824 area = ctx_area;
1825 ED_area_newspace(C, ctx_area, space_type, true);
1827 ((SpaceLink *)area->spacedata.first)->link_flag |= SPACE_FLAG_TYPE_TEMPORARY;
1828 }
1829 else {
1830 area = ED_screen_full_newspace(C, ctx_area, int(space_type));
1831 ((SpaceLink *)area->spacedata.first)->link_flag |= SPACE_FLAG_TYPE_TEMPORARY;
1832 }
1833 break;
1834 }
1835 }
1836
1837 return area;
1838}
1839
1840void ED_screen_animation_timer(bContext *C, int redraws, int sync, int enable)
1841{
1842 bScreen *screen = CTX_wm_screen(C);
1844 wmWindow *win = CTX_wm_window(C);
1845 Scene *scene = CTX_data_scene(C);
1846 bScreen *stopscreen = ED_screen_animation_playing(wm);
1847
1848 if (stopscreen) {
1849 WM_event_timer_remove(wm, win, stopscreen->animtimer);
1850 stopscreen->animtimer = nullptr;
1851 }
1852
1853 if (enable) {
1854 ScreenAnimData *sad = MEM_callocN<ScreenAnimData>("ScreenAnimData");
1855
1856 screen->animtimer = WM_event_timer_add(wm, win, TIMER0, (1.0 / FPS));
1857
1858 sad->region = CTX_wm_region(C);
1859 sad->sfra = scene->r.cfra;
1860 /* Make sure that were are inside the scene or preview frame range. */
1861 CLAMP(scene->r.cfra, PSFRA, PEFRA);
1862 if (scene->r.cfra != sad->sfra) {
1863 sad->flag |= ANIMPLAY_FLAG_JUMPED;
1864 }
1865
1866 if (sad->flag & ANIMPLAY_FLAG_JUMPED) {
1868 }
1869
1870 sad->redraws = redraws;
1871 sad->flag |= (enable < 0) ? ANIMPLAY_FLAG_REVERSE : 0;
1872 sad->flag |= (sync == 0) ? ANIMPLAY_FLAG_NO_SYNC : (sync == 1) ? ANIMPLAY_FLAG_SYNC : 0;
1873
1874 ScrArea *area = CTX_wm_area(C);
1875
1876 char spacetype = -1;
1877
1878 if (area) {
1879 spacetype = area->spacetype;
1880 }
1881
1883
1884 screen->animtimer->customdata = sad;
1885 }
1886
1887 /* Notifier caught by top header, for button. */
1889}
1890
1891/* helper for screen_animation_play() - only to be used for TimeLine */
1893{
1894 ARegion *region_top_left = nullptr;
1895 int min = 10000;
1896
1897 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
1898 if (area->spacetype == SPACE_VIEW3D) {
1899 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1900 if (region->regiontype == RGN_TYPE_WINDOW) {
1901 if (region->winrct.xmin - region->winrct.ymin < min) {
1902 region_top_left = region;
1903 min = region->winrct.xmin - region->winrct.ymin;
1904 }
1905 }
1906 }
1907 }
1908 }
1909
1910 return region_top_left;
1911}
1912
1914{
1915 if (screen && screen->animtimer) {
1916 wmTimer *wt = screen->animtimer;
1917 ScreenAnimData *sad = static_cast<ScreenAnimData *>(wt->customdata);
1918
1919 sad->redraws = redraws;
1920 sad->region = nullptr;
1921 if (redraws & TIME_REGION) {
1922 sad->region = time_top_left_3dwindow(screen);
1923 }
1924 }
1925}
1926
1927void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
1928{
1930
1931 DEG_time_tag_update(bmain);
1932
1933 void *camera = BKE_scene_camera_switch_find(scene);
1934 if (camera && scene->camera != camera) {
1935 scene->camera = static_cast<Object *>(camera);
1936 /* are there cameras in the views that are not in the scene? */
1937 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
1938 BKE_screen_view3d_scene_sync(screen, scene);
1939 }
1941 }
1942
1943 ED_clip_update_frame(bmain, scene->r.cfra);
1944
1945 /* this function applies the changes too */
1947}
1948
1949bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene)
1950{
1951 const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0;
1952
1953 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
1954 switch (area->spacetype) {
1955 case SPACE_VIEW3D: {
1956 View3D *v3d;
1957
1958 if (!is_multiview) {
1959 continue;
1960 }
1961
1962 v3d = static_cast<View3D *>(area->spacedata.first);
1963 if (v3d->camera && v3d->stereo3d_camera == STEREO_3D_ID) {
1964 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
1965 if (region->regiondata && region->regiontype == RGN_TYPE_WINDOW) {
1966 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1967 if (rv3d->persp == RV3D_CAMOB) {
1968 return true;
1969 }
1970 }
1971 }
1972 }
1973 break;
1974 }
1975 case SPACE_IMAGE: {
1976 SpaceImage *sima;
1977
1978 /* images should always show in stereo, even if
1979 * the file doesn't have views enabled */
1980 sima = static_cast<SpaceImage *>(area->spacedata.first);
1981 if (sima->image && BKE_image_is_stereo(sima->image) &&
1982 (sima->iuser.flag & IMA_SHOW_STEREO))
1983 {
1984 return true;
1985 }
1986 break;
1987 }
1988 case SPACE_NODE: {
1989 SpaceNode *snode;
1990
1991 if (!is_multiview) {
1992 continue;
1993 }
1994
1995 snode = static_cast<SpaceNode *>(area->spacedata.first);
1996 if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) {
1997 return true;
1998 }
1999 break;
2000 }
2001 case SPACE_SEQ: {
2002 SpaceSeq *sseq;
2003
2004 if (!is_multiview) {
2005 continue;
2006 }
2007
2008 sseq = static_cast<SpaceSeq *>(area->spacedata.first);
2010 return true;
2011 }
2012
2013 break;
2014 }
2015 }
2016 }
2017
2018 return false;
2019}
2020
2022 const wmWindowManager *wm,
2023 wmWindow **r_window)
2024{
2025 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2026 if (WM_window_get_active_screen(win) == screen) {
2027 if (r_window) {
2028 *r_window = win;
2029 }
2030 return WM_window_get_active_scene(win);
2031 }
2032 }
2033
2034 /* Can by nullptr when accessing a screen that isn't active. */
2035 return nullptr;
2036}
2037
2039 const SpaceLink *sl,
2040 const bool only_visible)
2041{
2042 if (only_visible) {
2043 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
2044 if (area->spacedata.first == sl) {
2045 return area;
2046 }
2047 }
2048 }
2049 else {
2050 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
2051 if (BLI_findindex(&area->spacedata, sl) != -1) {
2052 return area;
2053 }
2054 }
2055 }
2056 return nullptr;
2057}
2058
2060{
2061 return ED_screen_scene_find_with_window(screen, wm, nullptr);
2062}
2063
2065{
2066 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2067 if (WM_window_get_active_screen(win) == screen) {
2068 return win;
2069 }
2070 }
2071 return nullptr;
2072}
WorkSpace * CTX_wm_workspace(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void CTX_wm_screen_set(bContext *C, bScreen *screen)
void CTX_data_scene_set(bContext *C, Scene *scene)
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_window_set(bContext *C, wmWindow *win)
Main * CTX_data_main(const bContext *C)
void CTX_wm_area_set(bContext *C, ScrArea *area)
void CTX_wm_region_set(bContext *C, ARegion *region)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
@ G_DEBUG_EVENTS
void BKE_icon_changed(int icon_id)
Definition icons.cc:204
bool BKE_image_is_stereo(const Image *ima)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_camera_find(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
void * BKE_libblock_alloc(Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
Definition lib_id.cc:1428
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
Object * BKE_scene_camera_switch_find(Scene *scene)
Definition scene.cc:2226
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2697
void BKE_screen_remove_unused_scredges(bScreen *screen)
Definition screen.cc:759
void BKE_screen_remove_double_scrverts(bScreen *screen)
Definition screen.cc:691
void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2)
Definition screen.cc:682
void BKE_screen_area_free(ScrArea *area)
Definition screen.cc:632
void BKE_screen_area_map_free(ScrAreaMap *area_map) ATTR_NONNULL()
Definition screen.cc:648
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:251
void BKE_screen_header_alignment_reset(bScreen *screen)
Definition screen.cc:1053
void BKE_area_region_free(SpaceType *st, ARegion *region)
Definition screen.cc:591
void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene)
Definition screen.cc:998
void BKE_screen_remove_double_scredges(bScreen *screen)
Definition screen.cc:743
void BKE_screen_view3d_sync(View3D *v3d, Scene *scene)
Definition screen.cc:980
void BKE_screen_free_data(bScreen *screen)
Definition screen.cc:659
void BKE_sound_stop_scene(struct Scene *scene)
WorkSpaceLayout * BKE_workspace_layout_find(const WorkSpace *workspace, const bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition workspace.cc:427
bScreen * BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout) GETTER_ATTRS
Definition workspace.cc:637
void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL()
Definition workspace.cc:397
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:612
WorkSpace * BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:561
void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS
Definition workspace.cc:565
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
#define BLI_SCOPED_DEFER(function_to_defer)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:414
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
#define CLAMP(a, b, c)
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_time_tag_update(Main *bmain)
Scene * DEG_get_input_scene(const Depsgraph *graph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1046
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1033
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ID_SCR
@ IMA_SHOW_STEREO
eObjectMode
Object is a sort of wrapper for general info.
#define PSFRA
@ R_MULTIVIEW
@ STEREO_3D_ID
#define FPS
#define PEFRA
@ SCREENFULL
@ SCREENMAXIMIZED
@ SCREENNORMAL
#define AREAMAP_FROM_SCREEN(screen)
@ GLOBAL_AREA_IS_HIDDEN
@ RGN_TYPE_TOOL_HEADER
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_UI
@ RGN_TYPE_TEMPORARY
@ RGN_TYPE_ASSET_SHELF_HEADER
@ RGN_TYPE_WINDOW
@ RGN_TYPE_ASSET_SHELF
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_FOOTER
@ RGN_TYPE_HEADER
@ RGN_TYPE_TOOLS
@ SCREEN_COLLAPSE_STATUSBAR
@ TIME_REGION
@ TIME_ALL_3D_WIN
@ TIME_ALL_ANIM_WIN
@ RGN_FLAG_HIDDEN
@ RGN_FLAG_POLL_FAILED
@ AREA_FLAG_STACKED_FULLSCREEN
GlobalAreaAlign
@ GLOBAL_AREA_ALIGN_BOTTOM
@ GLOBAL_AREA_ALIGN_TOP
@ SNODE_BACKDRAW
eSpace_Type
@ SPACE_ACTION
@ SPACE_STATUSBAR
@ SPACE_TOPBAR
@ SPACE_NODE
@ SPACE_NLA
@ SPACE_SEQ
@ SPACE_EMPTY
@ SPACE_IMAGE
@ SPACE_GRAPH
@ SPACE_VIEW3D
@ SEQ_VIEW_SEQUENCE_PREVIEW
@ SEQ_VIEW_PREVIEW
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
#define UI_SCALE_FAC
@ USER_HEADER_FROM_PREF
@ USER_TEMP_SPACE_DISPLAY_FULLSCREEN
@ USER_TEMP_SPACE_DISPLAY_WINDOW
@ V2D_IS_INIT
@ RV3D_CAMOB
@ RV3D_PERSP
void ED_clip_update_frame(const Main *mainp, int cfra)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:548
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:714
void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
Definition area.cc:2144
void ED_area_newspace(bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition area.cc:2693
WorkSpaceLayout * ED_workspace_layout_add(Main *bmain, WorkSpace *workspace, wmWindow *win, const char *name) ATTR_NONNULL()
void ED_region_cursor_set(wmWindow *win, ScrArea *area, ARegion *region)
Definition area.cc:2315
#define ED_screen_verts_iter(win, screen, vert_name)
Definition ED_screen.hh:291
void ED_area_and_region_types_init(ScrArea *area)
Definition area.cc:2127
bool ED_region_contains_xy(const ARegion *region, const int event_xy[2])
#define ED_screen_areas_iter(win, screen, area_name)
Definition ED_screen.hh:288
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:872
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:659
int ED_area_headersize()
Definition area.cc:3774
WorkSpaceLayout * ED_workspace_screen_change_ensure_unused_layout(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout_new, const WorkSpaceLayout *layout_fallback_base, wmWindow *win) ATTR_NONNULL()
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:743
AZone * ED_area_azones_update(ScrArea *area, const int mouse_xy[2])
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1040
void ED_region_visibility_change_update_ex(bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
Definition area.cc:2336
void ED_area_prevspace(bContext *C, ScrArea *area)
Definition area.cc:2860
@ ANIMPLAY_FLAG_JUMPED
@ ANIMPLAY_FLAG_NO_SYNC
@ ANIMPLAY_FLAG_REVERSE
@ ANIMPLAY_FLAG_SYNC
@ AZONE_REGION
@ AZONE_REGION_SCROLL
@ AZONE_AREA
@ AE_LEFT_TO_TOPRIGHT
@ AE_RIGHT_TO_TOPLEFT
static void split(const char *text, const char *seps, char ***str, int *count)
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
void UI_panel_stop_animation(const bContext *C, Panel *panel)
void UI_blocklist_free(const bContext *C, ARegion *region)
void UI_screen_free_active_but_highlight(const bContext *C, bScreen *screen)
void UI_popup_handlers_remove_all(bContext *C, ListBase *handlers)
@ WIN_ALIGN_LOCATION_CENTER
Definition WM_api.hh:362
@ WM_CAPABILITY_WINDOW_DECORATION_STYLES
Definition WM_api.hh:201
#define NC_WINDOW
Definition WM_types.hh:372
#define ND_FILEREAD
Definition WM_types.hh:409
#define NC_WM
Definition WM_types.hh:371
#define NC_SCREEN
Definition WM_types.hh:374
#define ND_MODE
Definition WM_types.hh:442
#define ND_ANIMPLAY
Definition WM_types.hh:421
#define NC_SCENE
Definition WM_types.hh:375
#define NA_EDITED
Definition WM_types.hh:581
ReportList * reports
Definition WM_types.hh:1025
#define ND_LAYOUTSET
Definition WM_types.hh:423
void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
Definition area.cc:2382
void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src)
Definition area.cc:2415
#define U
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define ceilf(x)
uint top
#define abs
#define printf(...)
#define MEM_SAFE_FREE(v)
#define MAX_ID_NAME
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
OrientationBounds merge(const OrientationBounds &cone_a, const OrientationBounds &cone_b)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static ulong state[N]
static int left
#define G(x, y, z)
VecBase< int32_t, 2 > int2
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:72
int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
int ED_area_icon(const ScrArea *area)
void ED_screen_global_areas_sync(wmWindow *win)
static ScrArea * screen_addarea_ex(ScrAreaMap *area_map, ScrVert *bottom_left, ScrVert *top_left, ScrVert *top_right, ScrVert *bottom_right, const eSpace_Type space_type)
int ED_screen_area_active(const bContext *C)
bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene)
wmWindow * ED_screen_window_find(const bScreen *screen, const wmWindowManager *wm)
static void screen_global_area_refresh(wmWindow *win, bScreen *screen, const eSpace_Type space_type, GlobalAreaAlign align, const rcti *rect, const short height_cur, const short height_min, const short height_max)
static void screen_set_3dview_camera(Scene *scene, ViewLayer *view_layer, ScrArea *area, View3D *v3d)
Scene * ED_screen_scene_find(const bScreen *screen, const wmWindowManager *wm)
static void screen_refresh_if_needed(bContext *C, wmWindowManager *wm, wmWindow *win)
static void screen_area_set_geometry_rect(ScrArea *area, const rcti *rect)
void screen_change_prepare(bScreen *screen_old, bScreen *screen_new, Main *bmain, bContext *C, wmWindow *win)
static bool screen_areas_can_align(ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2, eScreenDir dir)
static ScrArea * screen_area_create_with_geometry(ScrAreaMap *area_map, const rcti *rect, eSpace_Type space_type)
bool area_regions_poll(bContext *C, const bScreen *screen, ScrArea *area)
void ED_screen_ensure_updated(bContext *C, wmWindowManager *wm, wmWindow *win)
void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new)
ScrArea * ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const short state)
ScrArea * ED_screen_area_find_with_spacedata(const bScreen *screen, const SpaceLink *sl, const bool only_visible)
void area_getoffsets(ScrArea *sa_a, ScrArea *sa_b, const eScreenDir dir, int *r_offset1, int *r_offset2)
static void region_cursor_set(wmWindow *win, bool swin_changed)
void ED_screen_refresh(bContext *C, wmWindowManager *wm, wmWindow *win)
void ED_screen_full_restore(bContext *C, ScrArea *area)
static void screen_verts_halign(const wmWindow *win, const bScreen *screen, const short from_x, const short to_x)
static bool region_poll(const bContext *C, const bScreen *screen, const ScrArea *area, const ARegion *region)
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
ScrArea * ED_screen_full_newspace(bContext *C, ScrArea *area, int type)
static void screen_global_statusbar_area_refresh(wmWindow *win, bScreen *screen)
void ED_screen_do_listen(bContext *C, const wmNotifier *note)
void ED_screens_init(bContext *C, Main *bmain, wmWindowManager *wm)
static void screen_delarea(bContext *C, bScreen *screen, ScrArea *area)
bool screen_area_close(bContext *C, ReportList *reports, bScreen *screen, ScrArea *area)
void ED_screen_global_areas_refresh(wmWindow *win)
bool ED_screen_change(bContext *C, bScreen *screen)
Change the active screen.
bScreen * ED_screen_state_maximized_create(bContext *C)
void ED_screen_animation_timer(bContext *C, int redraws, int sync, int enable)
void ED_screen_restore_temp_type(bContext *C, ScrArea *area)
ScrArea * area_split(const wmWindow *win, bScreen *screen, ScrArea *area, const eScreenAxis dir_axis, const float fac, const bool merge)
void screen_change_update(bContext *C, wmWindow *win, bScreen *screen)
static void screen_verts_valign(const wmWindow *win, const bScreen *screen, const short from_y, const short to_y)
static bool screen_area_join_aligned(bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2)
void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
static bool screen_area_join_ex(bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2, bool close_all_remainders)
void ED_area_exit(bContext *C, ScrArea *area)
static ScrArea * screen_addarea(bScreen *screen, ScrVert *left_bottom, ScrVert *left_top, ScrVert *right_top, ScrVert *right_bottom, const eSpace_Type space_type)
static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen)
ScrArea * ED_screen_temp_space_open(bContext *C, const char *title, const rcti *rect_unscaled, eSpace_Type space_type, int display_type, bool dialog)
static bScreen * screen_state_to_nonnormal(bContext *C, wmWindow *win, ScrArea *toggle_area, int state)
void ED_screen_animation_timer_update(bScreen *screen, int redraws)
void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
blender::StringRefNull ED_area_name(const ScrArea *area)
void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
static void screen_cursor_set(wmWindow *win, const int xy[2])
static bool screen_areas_align(bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2, const eScreenDir dir)
void screen_data_copy(bScreen *to, bScreen *from)
static bool screen_regions_poll(bContext *C, wmWindow *win, const bScreen *screen)
void ED_screen_scene_change(bContext *C, wmWindow *win, Scene *scene, const bool refresh_toolsystem)
static ScrArea * screen_area_trim(bContext *C, bScreen *screen, ScrArea **area, int size, eScreenDir dir, bool reverse)
static ARegion * time_top_left_3dwindow(bScreen *screen)
void ED_region_remove(bContext *C, ScrArea *area, ARegion *region)
static int screen_global_header_size()
bScreen * screen_add(Main *bmain, const char *name, const rcti *rect)
void ED_region_exit(bContext *C, ARegion *region)
static void region_cursor_set_ex(wmWindow *win, ScrArea *area, ARegion *region, bool swin_changed)
void ED_screen_full_prevspace(bContext *C, ScrArea *area)
Scene * ED_screen_scene_find_with_window(const bScreen *screen, const wmWindowManager *wm, wmWindow **r_window)
int screen_area_join(bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2)
void screen_area_spacelink_add(const Scene *scene, ScrArea *area, eSpace_Type space_type)
ScrVert * screen_geom_vertex_add(bScreen *screen, short x, short y)
ScrEdge * screen_geom_edge_add_ex(ScrAreaMap *area_map, ScrVert *v1, ScrVert *v2)
ScrVert * screen_geom_vertex_add_ex(ScrAreaMap *area_map, short x, short y)
ScrEdge * screen_geom_find_active_scredge(const wmWindow *win, const bScreen *screen, const int mx, const int my)
ScrEdge * screen_geom_edge_add(bScreen *screen, ScrVert *v1, ScrVert *v2)
bool screen_geom_edge_is_horizontal(ScrEdge *se)
void screen_geom_vertices_scale(const wmWindow *win, bScreen *screen)
Main screen-layout calculation function.
short screen_geom_find_area_split_point(const ScrArea *area, const rcti *window_rect, const eScreenAxis dir_axis, float fac)
#define SCREEN_DIR_IS_HORIZONTAL(dir)
#define BORDERPADDING
AZone * ED_area_actionzone_find_xy(ScrArea *area, const int xy[2])
eScreenAxis
@ SCREEN_AXIS_V
@ SCREEN_AXIS_H
#define SCREEN_DIR_IS_VERTICAL(dir)
#define AREAJOINTOLERANCEX
eScreenDir
@ SCREEN_DIR_W
@ SCREEN_DIR_N
@ SCREEN_DIR_E
@ SCREEN_DIR_S
@ SCREEN_DIR_NONE
#define AREAJOINTOLERANCEY
#define min(a, b)
Definition sort.cc:36
ARegionRuntimeHandle * runtime
ListBase panels
AZEdge edge
const char * name
Definition RNA_types.hh:627
int icon_id
Definition DNA_ID.h:426
char name[66]
Definition DNA_ID.h:415
void * first
ListBase screens
Definition BKE_main.hh:261
ListBase workspaces
Definition BKE_main.hh:284
struct RenderData r
struct Object * camera
ListBase areabase
ListBase handlers
ScrVert * v2
ScrVert * v3
ListBase spacedata
struct SpaceType * type
bScreen * full
ScrVert * v1
struct ScrArea * next
ListBase regionbase
ScrGlobalAreaData * global
ScrVert * v4
struct ScrVert * next
struct ScrVert * newv
struct ImageUser iuser
struct Image * image
SpaceLink *(* create)(const ScrArea *area, const Scene *scene)
Definition BKE_screen.hh:93
int(* space_icon_get)(const ScrArea *area)
void(* exit)(wmWindowManager *wm, ScrArea *area)
blender::StringRefNull(* space_name_get)(const ScrArea *area)
struct Object * camera
char stereo3d_camera
ListBase regionbase
Wrapper for bScreen.
ListBase edgebase
short redraws_flag
ListBase regionbase
char skip_handling
ListBase vertbase
struct wmTimer * animtimer
ListBase areabase
struct ARegion * active_region
int ymin
int ymax
int xmin
int xmax
short y
short x
int xy[2]
Definition WM_types.hh:758
unsigned int data
Definition WM_types.hh:355
unsigned int action
Definition WM_types.hh:355
unsigned int category
Definition WM_types.hh:355
void * customdata
Definition WM_types.hh:962
struct wmMsgBus * message_bus
WindowManagerRuntimeHandle * runtime
struct wmEvent * eventstate
struct Scene * scene
ScrAreaMap global_areas
struct WorkSpaceInstanceHook * workspace_hook
void WM_cursor_set(wmWindow *win, int curs)
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:15
@ WM_CURSOR_Y_MOVE
Definition wm_cursors.hh:40
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:19
@ WM_CURSOR_X_MOVE
Definition wm_cursors.hh:39
int xy[2]
Definition wm_draw.cc:174
void WM_draw_region_free(ARegion *region)
Definition wm_draw.cc:1643
bool WM_cursor_test_motion_and_update(const int mval[2])
void WM_window_status_area_tag_redraw(wmWindow *win)
void WM_event_remove_area_handler(ListBase *handlers, void *area)
void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_ui_handler_region_popup_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
void WM_event_remove_handlers(bContext *C, ListBase *handlers)
void WM_event_add_mousemove(wmWindow *win)
@ TIMER0
bool WM_gizmo_highlight_set(wmGizmoMap *gzmap, wmGizmo *gz)
Definition wm_gizmo.cc:404
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
void WM_toolsystem_refresh_screen_window(wmWindow *win)
blender::int2 WM_window_native_pixel_size(const wmWindow *win)
void WM_window_ensure_active_view_layer(wmWindow *win)
bool WM_window_is_main_top_level(const wmWindow *win)
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
void WM_event_timer_sleep(wmWindowManager *wm, wmWindow *, wmTimer *timer, bool do_sleep)
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
void WM_window_set_dpi(const wmWindow *win)
Definition wm_window.cc:575
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)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
bool WM_window_is_temp_screen(const wmWindow *win)
void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
eWM_CapabilitiesFlag WM_capabilities_flag()
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
Scene * WM_window_get_active_scene(const wmWindow *win)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bScreen * WM_window_get_active_screen(const wmWindow *win)
void WM_window_decoration_style_apply(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:687