Blender V4.5
area.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 <cstdio>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "DNA_userdef_types.h"
16
17#include "BLI_linklist.h"
18#include "BLI_listbase.h"
19#include "BLI_rand.hh"
20#include "BLI_string.h"
21#include "BLI_string_utils.hh"
22#include "BLI_utildefines.h"
23
24#include "BKE_context.hh"
25#include "BKE_global.hh"
26#include "BKE_screen.hh"
27#include "BKE_workspace.hh"
28
29#include "RNA_access.hh"
30
31#include "WM_api.hh"
32#include "WM_message.hh"
33#include "WM_toolsystem.hh"
34#include "WM_types.hh"
35
36#include "ED_asset_shelf.hh"
37#include "ED_buttons.hh"
38#include "ED_screen.hh"
39#include "ED_screen_types.hh"
40#include "ED_space_api.hh"
41#include "ED_time_scrub_ui.hh"
42
43#include "GPU_framebuffer.hh"
44#include "GPU_immediate.hh"
45#include "GPU_immediate_util.hh"
46#include "GPU_matrix.hh"
47#include "GPU_state.hh"
48
49#include "BLF_api.hh"
50
51#include "IMB_metadata.hh"
52
53#include "UI_interface.hh"
54#include "UI_interface_icons.hh"
55#include "UI_resources.hh"
56#include "UI_view2d.hh"
57
58#include "screen_intern.hh"
59
68
69/* general area and region code */
70
71static void region_draw_emboss(const ARegion *region, const rcti *scirct, int sides)
72{
73 /* translate scissor rect to region space */
74 rcti rect{};
75 rect.xmin = scirct->xmin - region->winrct.xmin;
76 rect.xmax = scirct->xmax - region->winrct.xmin;
77 rect.ymin = scirct->ymin - region->winrct.ymin;
78 rect.ymax = scirct->ymax - region->winrct.ymin;
79
80 /* Set transparent line. */
82
83 float color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
85
89 immUniformColor4fv(color);
90
92
93 /* right */
94 if (sides & REGION_EMBOSS_RIGHT) {
95 immVertex2f(pos, rect.xmax, rect.ymax);
96 immVertex2f(pos, rect.xmax, rect.ymin);
97 }
98
99 /* bottom */
100 if (sides & REGION_EMBOSS_BOTTOM) {
101 immVertex2f(pos, rect.xmax, rect.ymin);
102 immVertex2f(pos, rect.xmin, rect.ymin);
103 }
104
105 /* left */
106 if (sides & REGION_EMBOSS_LEFT) {
107 immVertex2f(pos, rect.xmin, rect.ymin);
108 immVertex2f(pos, rect.xmin, rect.ymax);
109 }
110
111 /* top */
112 if (sides & REGION_EMBOSS_TOP) {
113 immVertex2f(pos, rect.xmin, rect.ymax);
114 immVertex2f(pos, rect.xmax, rect.ymax);
115 }
116
117 immEnd();
119
121}
122
123void ED_region_pixelspace(const ARegion *region)
124{
127}
128
130{
131 ARegion *region = params->region;
132 const wmNotifier *notifier = params->notifier;
133
134 /* generic notes first */
135 switch (notifier->category) {
136 case NC_WM:
137 if (notifier->data == ND_FILEREAD) {
138 ED_region_tag_redraw(region);
139 }
140 break;
141 case NC_WINDOW:
142 ED_region_tag_redraw(region);
143 break;
144 }
145
146 if (region->runtime->type && region->runtime->type->listener) {
147 region->runtime->type->listener(params);
148 }
149
150 LISTBASE_FOREACH (uiBlock *, block, &region->runtime->uiblocks) {
151 UI_block_listen(block, params);
152 }
153
154 LISTBASE_FOREACH (uiList *, list, &region->ui_lists) {
155 if (list->type && list->type->listener) {
156 list->type->listener(list, params);
157 }
158 }
159}
160
162{
163 /* no generic notes? */
164 if (params->area->type && params->area->type->listener) {
165 params->area->type->listener(params);
166 }
167}
168
170{
171 /* no generic notes? */
172 if (area->type && area->type->refresh) {
173 area->type->refresh(C, area);
174 }
175 area->do_refresh = false;
176}
177
181static void area_draw_azone_fullscreen(short /*x1*/, short /*y1*/, short x2, short y2, float alpha)
182{
183 UI_icon_draw_ex(x2 - U.widget_unit,
184 y2 - U.widget_unit,
185 ICON_FULLSCREEN_EXIT,
187 min_ff(alpha, 0.75f),
188 0.0f,
189 nullptr,
190 false,
192}
193
197static void area_draw_azone(short /*x1*/, short /*y1*/, short /*x2*/, short /*y2*/)
198{
199 /* No drawing needed since all corners are action zone, and visually distinguishable. */
200}
201
205static void draw_azone_arrow(float x1, float y1, float x2, float y2, AZEdge edge)
206{
207 const float size = 0.2f * U.widget_unit;
208 const float l = 1.0f; /* arrow length */
209 const float s = 0.25f; /* arrow thickness */
210 const float hl = l / 2.0f;
211 const float points[6][2] = {
212 {0, -hl}, {l, hl}, {l - s, hl + s}, {0, s + s - hl}, {s - l, hl + s}, {-l, hl}};
213 const float center[2] = {(x1 + x2) / 2, (y1 + y2) / 2};
214
215 int axis;
216 int sign;
217 switch (edge) {
219 axis = 0;
220 sign = 1;
221 break;
223 axis = 0;
224 sign = -1;
225 break;
227 axis = 1;
228 sign = 1;
229 break;
231 axis = 1;
232 sign = -1;
233 break;
234 default:
235 BLI_assert(0);
236 return;
237 }
238
241
244 immUniformColor4f(0.8f, 0.8f, 0.8f, 0.4f);
245
247 for (int i = 0; i < 6; i++) {
248 if (axis == 0) {
249 immVertex2f(pos, center[0] + points[i][0] * size, center[1] + points[i][1] * sign * size);
250 }
251 else {
252 immVertex2f(pos, center[0] + points[i][1] * sign * size, center[1] + points[i][0] * size);
253 }
254 }
255 immEnd();
256
259}
260
261static void region_draw_azone_tab_arrow(ScrArea *area, ARegion *region, AZone *az)
262{
264
265 /* add code to draw region hidden as 'too small' */
266 switch (az->edge) {
269 break;
272 break;
275 break;
278 break;
279 }
280
281 /* Workaround for different color spaces between normal areas and the ones using GPUViewports. */
282 float alpha = WM_region_use_viewport(area, region) ? 0.6f : 0.4f;
283 const float color[4] = {0.05f, 0.05f, 0.05f, alpha};
284 rctf rect{};
285 /* Hit size is a bit larger than visible background. */
286 rect.xmin = float(az->x1) + U.pixelsize;
287 rect.xmax = float(az->x2) - U.pixelsize;
288 rect.ymin = float(az->y1) + U.pixelsize;
289 rect.ymax = float(az->y2) - U.pixelsize;
290 UI_draw_roundbox_aa(&rect, true, 4.0f, color);
291
292 draw_azone_arrow(float(az->x1), float(az->y1), float(az->x2), float(az->y2), az->edge);
293}
294
296{
298}
299
300static void region_draw_azones(ScrArea *area, ARegion *region)
301{
302 if (!area) {
303 return;
304 }
305
306 GPU_line_width(1.0f);
308
310 GPU_matrix_translate_2f(-region->winrct.xmin, -region->winrct.ymin);
311
312 LISTBASE_FOREACH (AZone *, az, &area->actionzones) {
313 /* test if action zone is over this region */
314 rcti azrct;
315 BLI_rcti_init(&azrct, az->x1, az->x2, az->y1, az->y2);
316
317 if (BLI_rcti_isect(&region->runtime->drawrct, &azrct, nullptr)) {
318 if (az->type == AZONE_AREA) {
319 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
320 }
321 else if (az->type == AZONE_REGION) {
322 if (az->region && !(az->region->flag & RGN_FLAG_POLL_FAILED)) {
323 /* only display tab or icons when the region is hidden */
324 if (az->region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
325 region_draw_azone_tab_arrow(area, region, az);
326 }
327 }
328 }
329 else if (az->type == AZONE_FULLSCREEN) {
330 if (az->alpha > 0.0f) {
331 area_draw_azone_fullscreen(az->x1, az->y1, az->x2, az->y2, az->alpha);
332 }
333 }
334 }
335 if (!IS_EQF(az->alpha, 0.0f) && ELEM(az->type, AZONE_FULLSCREEN, AZONE_REGION_SCROLL)) {
337 }
338 }
339
341
343}
344
345static void region_draw_status_text(ScrArea * /*area*/, ARegion *region)
346{
347 float header_color[4];
348 UI_GetThemeColor4fv(TH_HEADER, header_color);
349
350 /* Clear the region from the buffer. */
351 GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
352
353 /* Fill with header color. */
354 if (header_color[3] > 0.0f) {
355 const rctf rect = {0.0f, float(region->winx), 0.0f, float(region->winy)};
356 UI_draw_roundbox_4fv(&rect, true, 0.0f, header_color);
357 }
358
359 const int fontid = BLF_set_default();
360 const float x = 12.0f * UI_SCALE_FAC;
361 const float y = 0.4f * UI_UNIT_Y;
363
364 if (header_color[3] < 0.3f) {
365 /* Draw a background behind the text for extra contrast. */
366 const float width = BLF_width(fontid, region->runtime->headerstr, BLF_DRAW_STR_DUMMY_MAX);
367 const float pad = 5.0f * UI_SCALE_FAC;
368 const float x1 = x - pad;
369 const float x2 = x + width + pad;
370 const float y1 = 3.0f * UI_SCALE_FAC;
371 const float y2 = region->winy - (4.0f * UI_SCALE_FAC);
372 float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
375 const rctf rect = {x1, x2, y1, y2};
376 UI_draw_roundbox_4fv(&rect, true, 4.0f * UI_SCALE_FAC, color);
377 }
378
379 UI_FontThemeColor(fontid, TH_TEXT);
380 BLF_position(fontid, x, y, 0.0f);
381 BLF_draw(fontid, region->runtime->headerstr, BLF_DRAW_STR_DUMMY_MAX);
382}
383
385 /* Follow wmMsgNotifyFn spec */
386 bContext * /*C*/,
387 wmMsgSubscribeKey * /*msg_key*/,
388 wmMsgSubscribeValue *msg_val)
389{
390 ARegion *region = static_cast<ARegion *>(msg_val->owner);
391 ED_region_tag_redraw(region);
392
393 /* This avoids _many_ situations where header/properties control display settings.
394 * the common case is space properties in the header */
396 while (region && region->prev) {
397 region = region->prev;
398 }
399 for (; region; region = region->next) {
401 ED_region_tag_redraw(region);
402 }
403 }
404 }
405}
406
408 /* Follow wmMsgNotifyFn spec */
409 bContext * /*C*/,
410 wmMsgSubscribeKey * /*msg_key*/,
411 wmMsgSubscribeValue *msg_val)
412{
413 ScrArea *area = static_cast<ScrArea *>(msg_val->user_data);
415}
416
418{
419 wmMsgBus *mbus = params->message_bus;
420 WorkSpace *workspace = params->workspace;
421 ARegion *region = params->region;
422
424 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
425 msg_sub_value_region_tag_redraw.owner = region;
426 msg_sub_value_region_tag_redraw.user_data = region;
427 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
429 mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
430}
431
433{
434 wmMsgBus *mbus = params->message_bus;
435 WorkSpace *workspace = params->workspace;
436 ARegion *region = params->region;
437
439 const char *panel_category_tool = "Tool";
440 const char *category = UI_panel_category_active_get(region, false);
441
442 bool update_region = false;
443 if (category && STREQ(category, panel_category_tool)) {
444 update_region = true;
445 }
446 else {
447 /* Check if a tool category panel is pinned and visible in another category. */
448 LISTBASE_FOREACH (Panel *, panel, &region->panels) {
449 if (UI_panel_is_active(panel) && panel->flag & PNL_PIN &&
450 STREQ(panel->type->category, panel_category_tool))
451 {
452 update_region = true;
453 break;
454 }
455 }
456 }
457
458 if (update_region) {
459 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
460 msg_sub_value_region_tag_redraw.owner = region;
461 msg_sub_value_region_tag_redraw.user_data = region;
462 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
464 mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
465 }
466}
467
474static bool area_is_pseudo_minimized(const ScrArea *area)
475{
476 return (area->winx < 3) || (area->winy < 3);
477}
478
480{
481 /* This is optional, only needed for dynamically sized regions. */
482 ScrArea *area = CTX_wm_area(C);
483 ARegionType *at = region->runtime->type;
484
485 if (!at->layout) {
486 return;
487 }
488
489 if (at->do_lock || (area && area_is_pseudo_minimized(area))) {
490 return;
491 }
492
493 region->runtime->do_draw |= RGN_DRAWING;
494
495 UI_SetTheme(area ? area->spacetype : 0, at->regionid);
496 at->layout(C, region);
497
498 /* Clear temporary update flag. */
500}
501
503{
504 using namespace blender;
505 wmWindow *win = CTX_wm_window(C);
506 ScrArea *area = CTX_wm_area(C);
507 ARegionType *at = region->runtime->type;
508
509 /* see BKE_spacedata_draw_locks() */
510 if (at->do_lock) {
511 return;
512 }
513
514 region->runtime->do_draw |= RGN_DRAWING;
515
516 /* Set viewport, scissor, ortho and region->runtime->drawrct. */
517 wmPartialViewport(&region->runtime->drawrct, &region->winrct, &region->runtime->drawrct);
518
520
521 UI_SetTheme(area ? area->spacetype : 0, at->regionid);
522
523 if (area && area_is_pseudo_minimized(area)) {
525 return;
526 }
527 /* optional header info instead? */
528 if (region->runtime->headerstr) {
529 region_draw_status_text(area, region);
530 }
531 else if (at->draw) {
532 at->draw(C, region);
533 }
534
535 /* XXX test: add convention to end regions always in pixel space,
536 * for drawing of borders/gestures etc */
537 ED_region_pixelspace(region);
538
539 /* Remove sRGB override by rebinding the framebuffer. */
540 GPUFrameBuffer *fb = GPU_framebuffer_active_get();
542
544
545 region_draw_azones(area, region);
546
547 /* for debugging unneeded area redraws and partial redraw */
548 if (G.debug_value == 888) {
554 immUniformColor4f(rng.get_float(), rng.get_float(), rng.get_float(), 0.1f);
556 region->runtime->drawrct.xmin - region->winrct.xmin,
557 region->runtime->drawrct.ymin - region->winrct.ymin,
558 region->runtime->drawrct.xmax - region->winrct.xmin,
559 region->runtime->drawrct.ymax - region->winrct.ymin);
562 }
563
564 region->runtime->drawrct = rcti{};
565
567
568 if (area) {
569 const bScreen *screen = WM_window_get_active_screen(win);
570
571 /* Only region emboss for top-bar */
572 if ((screen->state != SCREENFULL) && ED_area_is_global(area)) {
574 }
575 else if ((region->regiontype == RGN_TYPE_WINDOW) && (region->alignment == RGN_ALIGN_QSPLIT)) {
576
577 /* draw separating lines between the quad views */
578
579 float color[4] = {0.0f, 0.0f, 0.0f, 0.8f};
585 GPU_line_width(1.0f);
587 0,
588 0,
589 region->winrct.xmax - region->winrct.xmin + 1,
590 region->winrct.ymax - region->winrct.ymin + 1);
592 }
593 }
594
595 /* We may want to detach message-subscriptions from drawing. */
596 {
597 WorkSpace *workspace = CTX_wm_workspace(C);
600 Scene *scene = CTX_data_scene(C);
601 wmMsgBus *mbus = wm->message_bus;
602 WM_msgbus_clear_by_owner(mbus, region);
603
604 /* Cheat, always subscribe to this space type properties.
605 *
606 * This covers most cases and avoids copy-paste similar code for each space type.
607 */
609 {
610 SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
611
612 PointerRNA ptr = RNA_pointer_create_discrete(&screen->id, &RNA_Space, sl);
613
614 /* All properties for this space type. */
615 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
616 msg_sub_value_region_tag_redraw.owner = region;
617 msg_sub_value_region_tag_redraw.user_data = region;
618 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
619 WM_msg_subscribe_rna(mbus, &ptr, nullptr, &msg_sub_value_region_tag_redraw, __func__);
620 }
621
622 wmRegionMessageSubscribeParams message_subscribe_params{};
623 message_subscribe_params.context = C;
624 message_subscribe_params.message_bus = mbus;
625 message_subscribe_params.workspace = workspace;
626 message_subscribe_params.scene = scene;
627 message_subscribe_params.screen = screen;
628 message_subscribe_params.area = area;
629 message_subscribe_params.region = region;
630 ED_region_message_subscribe(&message_subscribe_params);
631 }
632}
633
634/* **********************************
635 * maybe silly, but let's try for now
636 * to keep these tags protected
637 * ********************************** */
638
640{
641 /* don't tag redraw while drawing, it shouldn't happen normally
642 * but python scripts can cause this to happen indirectly */
643 if (region && !(region->runtime->do_draw & RGN_DRAWING)) {
644 /* zero region means full region redraw */
645 region->runtime->do_draw &= ~(RGN_DRAW_PARTIAL | RGN_DRAW_NO_REBUILD |
647 region->runtime->do_draw |= RGN_DRAW;
648 region->runtime->drawrct = rcti{};
649 }
650}
651
653{
654 if (region) {
655 region->runtime->do_draw_paintcursor = RGN_DRAW;
656 }
657}
658
660{
661 if (region && !(region->runtime->do_draw & (RGN_DRAWING | RGN_DRAW))) {
662 region->runtime->do_draw &= ~(RGN_DRAW_PARTIAL | RGN_DRAW_EDITOR_OVERLAYS);
663 region->runtime->do_draw |= RGN_DRAW_NO_REBUILD;
664 region->runtime->drawrct = rcti{};
665 }
666}
667
669{
670 if (region) {
671 region->runtime->do_draw |= RGN_REFRESH_UI;
672 }
673}
674
676{
677 if (region && !(region->runtime->do_draw & (RGN_DRAWING | RGN_DRAW))) {
678 if (region->runtime->do_draw & RGN_DRAW_PARTIAL) {
679 ED_region_tag_redraw(region);
680 }
681 else {
682 region->runtime->do_draw |= RGN_DRAW_EDITOR_OVERLAYS;
683 }
684 }
685}
686
687void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
688{
689 if (region && !(region->runtime->do_draw & RGN_DRAWING)) {
690 if (region->runtime->do_draw & RGN_DRAW_PARTIAL) {
691 /* Partial redraw already set, expand region. */
692 BLI_rcti_union(&region->runtime->drawrct, rct);
693 if (rebuild) {
694 region->runtime->do_draw &= ~RGN_DRAW_NO_REBUILD;
695 }
696 }
697 else if (region->runtime->do_draw & (RGN_DRAW | RGN_DRAW_NO_REBUILD)) {
698 /* Full redraw already requested. */
699 if (rebuild) {
700 region->runtime->do_draw &= ~RGN_DRAW_NO_REBUILD;
701 }
702 }
703 else {
704 /* No redraw set yet, set partial region. */
705 region->runtime->drawrct = *rct;
706 region->runtime->do_draw |= RGN_DRAW_PARTIAL;
707 if (!rebuild) {
708 region->runtime->do_draw |= RGN_DRAW_NO_REBUILD;
709 }
710 }
711 }
712}
713
715{
716 if (area) {
717 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
718 ED_region_tag_redraw(region);
719 }
720 }
721}
722
724{
725 if (area) {
726 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
728 }
729 }
730}
731
732void ED_area_tag_redraw_regiontype(ScrArea *area, int regiontype)
733{
734 if (area) {
735 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
736 if (region->regiontype == regiontype) {
737 ED_region_tag_redraw(region);
738 }
739 }
740 }
741}
742
744{
745 if (area) {
746 area->do_refresh = true;
747 }
748}
749
751{
752 if (!area || (area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
753 return;
754 }
755
757
758 /* Floating regions don't affect other regions, so the following can be skipped. */
759 if (changed_region->alignment == RGN_ALIGN_FLOAT) {
760 return;
761 }
762
763 /* Tag the following regions for redraw, since the size change of this region may affect the
764 * available space for them. */
765 for (ARegion *following_region = changed_region->next; following_region;
766 following_region = following_region->next)
767 {
768 /* Overlapping and non-overlapping regions don't affect each others space. So layout changes
769 * of one don't require redrawing the other. */
770 if (changed_region->overlap != following_region->overlap) {
771 continue;
772 }
773 /* Floating regions don't affect space of other regions. */
774 if (following_region->alignment == RGN_ALIGN_FLOAT) {
775 continue;
776 }
777 ED_region_tag_redraw(following_region);
778 }
779}
780
781/* *************************************************************** */
782
783int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
784{
785 int dist;
786
787 /* regions in regions. */
788 if (scale_region->alignment & RGN_SPLIT_PREV) {
789 const int align = RGN_ALIGN_ENUM_FROM_MASK(scale_region->alignment);
790
791 if (ELEM(align, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
792 ARegion *region = scale_region->prev;
793 dist = region->winy + scale_region->winy - U.pixelsize;
794 }
795 else /* if (ELEM(align, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) */ {
796 ARegion *region = scale_region->prev;
797 dist = region->winx + scale_region->winx - U.pixelsize;
798 }
799 }
800 else {
802 dist = BLI_rcti_size_x(&area->totrct);
803 }
804 else { /* AE_BOTTOM_TO_TOPLEFT, AE_TOP_TO_BOTTOMRIGHT */
805 dist = BLI_rcti_size_y(&area->totrct);
806 }
807
808 /* Subtract the width of regions on opposite side
809 * prevents dragging regions into other opposite regions. */
810 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
811 if (region == scale_region) {
812 continue;
813 }
814
815 if (scale_region->alignment == RGN_ALIGN_LEFT && region->alignment == RGN_ALIGN_RIGHT) {
816 dist -= region->winx;
817 }
818 else if (scale_region->alignment == RGN_ALIGN_RIGHT && region->alignment == RGN_ALIGN_LEFT) {
819 dist -= region->winx;
820 }
821 else if (scale_region->alignment == RGN_ALIGN_TOP &&
822 (region->alignment == RGN_ALIGN_BOTTOM || ELEM(region->regiontype,
827 {
828 dist -= region->winy;
829 }
830 else if (scale_region->alignment == RGN_ALIGN_BOTTOM &&
831 (region->alignment == RGN_ALIGN_TOP || ELEM(region->regiontype,
836 {
837 dist -= region->winy;
838 }
839 }
840 }
841
842 dist /= UI_SCALE_FAC;
843 return dist;
844}
845
846const char *ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region)
847{
848 /* Only the properties editor has a search string for now. */
849 if (area->spacetype == SPACE_PROPERTIES) {
850 SpaceProperties *sbuts = static_cast<SpaceProperties *>(area->spacedata.first);
851 if (region->regiontype == RGN_TYPE_WINDOW) {
852 return ED_buttons_search_string_get(sbuts);
853 }
854 }
855
856 return nullptr;
857}
858
860{
862
863 const char *search_filter = ED_area_region_search_filter_get(area, region);
864 SET_FLAG_FROM_TEST(region->flag,
865 region->regiontype == RGN_TYPE_WINDOW && search_filter &&
866 search_filter[0] != '\0',
868}
869
870/* *************************************************************** */
871
872void ED_area_status_text(ScrArea *area, const char *str)
873{
874 /* happens when running transform operators in background mode */
875 if (area == nullptr) {
876 return;
877 }
878
879 ARegion *ar = nullptr;
880
881 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
882 if (region->regiontype == RGN_TYPE_HEADER && region->runtime->visible) {
883 ar = region;
884 }
885 else if (region->regiontype == RGN_TYPE_TOOL_HEADER && region->runtime->visible) {
886 /* Prefer tool header when we also have a header. */
887 ar = region;
888 break;
889 }
890 }
891
892 if (ar) {
893 if (str) {
894 if (ar->runtime->headerstr == nullptr) {
895 ar->runtime->headerstr = MEM_malloc_arrayN<char>(UI_MAX_DRAW_STR, "headerprint");
896 }
897 BLI_strncpy(ar->runtime->headerstr, str, UI_MAX_DRAW_STR);
898 BLI_str_rstrip(ar->runtime->headerstr);
899 }
900 else {
901 MEM_SAFE_FREE(ar->runtime->headerstr);
902 }
904 }
905}
906
907/* *************************************************************** */
908
909static void ed_workspace_status_item(WorkSpace *workspace,
910 std::string text,
911 const int icon,
912 const float space_factor = 0.0f,
913 const bool inverted = false)
914{
915 /* Can be nullptr when running operators in background mode. */
916 if (workspace == nullptr) {
917 return;
918 }
919
921 item.text = std::move(text);
922 item.icon = icon;
923 item.space_factor = space_factor;
924 item.inverted = inverted;
925 workspace->runtime->status.append(std::move(item));
926}
927
928static void ed_workspace_status_space(WorkSpace *workspace, const float space_factor)
929{
930 ed_workspace_status_item(workspace, {}, ICON_NONE, space_factor);
931}
932
942
943/* -------------------------------------------------------------------- */
946
947static constexpr float STATUS_BEFORE_TEXT = 0.17f;
948static constexpr float STATUS_AFTER_TEXT = 0.90f;
949static constexpr float STATUS_MOUSE_ICON_PAD = -0.68f;
950
951static void ed_workspace_status_text_item(WorkSpace *workspace, std::string text)
952{
953 if (!text.empty()) {
955 ed_workspace_status_item(workspace, std::move(text), ICON_NONE);
957 }
958}
959
961 const int icon,
962 const bool inverted = false)
963{
964 if (icon) {
965 ed_workspace_status_item(workspace, {}, icon, 0.0f, inverted);
966 if (icon >= ICON_MOUSE_LMB && icon <= ICON_MOUSE_MMB_SCROLL) {
967 /* Negative space after narrow mice icons. */
969 }
970 }
971}
972
974
975/* -------------------------------------------------------------------- */
978
979void WorkspaceStatus::item(std::string text, const int icon1, const int icon2)
980{
981 ed_workspace_status_icon_item(workspace_, icon1);
982 ed_workspace_status_icon_item(workspace_, icon2);
983 ed_workspace_status_text_item(workspace_, std::move(text));
984}
985
986void WorkspaceStatus::range(std::string text, const int icon1, const int icon2)
987{
988 ed_workspace_status_item(workspace_, {}, icon1);
989 ed_workspace_status_item(workspace_, "-", ICON_NONE);
990 ed_workspace_status_space(workspace_, -0.5f);
991 ed_workspace_status_item(workspace_, {}, icon2);
992 ed_workspace_status_text_item(workspace_, std::move(text));
993}
994
995void WorkspaceStatus::item_bool(std::string text,
996 const bool inverted,
997 const int icon1,
998 const int icon2)
999{
1000 ed_workspace_status_icon_item(workspace_, icon1, inverted);
1001 ed_workspace_status_icon_item(workspace_, icon2, inverted);
1002 ed_workspace_status_text_item(workspace_, std::move(text));
1003}
1004
1005void WorkspaceStatus::opmodal(std::string text,
1006 const wmOperatorType *ot,
1007 const int propvalue,
1008 const bool inverted)
1009{
1010 wmKeyMap *keymap = WM_keymap_active(wm_, ot->modalkeymap);
1011 if (keymap) {
1012 const wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(keymap, propvalue);
1013 if (kmi) {
1014#ifdef WITH_HEADLESS
1015 int icon = 0;
1016#else
1017 int icon = UI_icon_from_event_type(kmi->type, kmi->val);
1018#endif
1019 if (kmi->shift == KM_MOD_HELD) {
1020 ed_workspace_status_item(workspace_, {}, ICON_EVENT_SHIFT, 0.0f, inverted);
1021 }
1022 if (kmi->ctrl == KM_MOD_HELD) {
1023 ed_workspace_status_item(workspace_, {}, ICON_EVENT_CTRL, 0.0f, inverted);
1024 }
1025 if (kmi->alt == KM_MOD_HELD) {
1026 ed_workspace_status_item(workspace_, {}, ICON_EVENT_ALT, 0.0f, inverted);
1027 }
1028 if (kmi->oskey == KM_MOD_HELD) {
1029 ed_workspace_status_item(workspace_, {}, ICON_EVENT_OS, 0.0f, inverted);
1030 }
1031 if (!ELEM(kmi->hyper, KM_NOTHING, KM_ANY)) {
1032 ed_workspace_status_item(workspace_, {}, ICON_EVENT_HYPER, 0.0f, inverted);
1033 }
1034 ed_workspace_status_icon_item(workspace_, icon, inverted);
1035 ed_workspace_status_text_item(workspace_, std::move(text));
1036 }
1037 }
1038}
1039
1041{
1042 WorkspaceStatus status(C);
1043 status.item(str ? str : "", ICON_NONE);
1044}
1045
1047
1048/* ************************************************************ */
1049
1050static void area_azone_init(const wmWindow *win, const bScreen *screen, ScrArea *area)
1051{
1052 /* reinitialize entirely, regions and full-screen add azones too */
1053 BLI_freelistN(&area->actionzones);
1054
1055 if (screen->state != SCREENNORMAL) {
1056 return;
1057 }
1058
1059 if (U.app_flag & USER_APP_LOCK_CORNER_SPLIT) {
1060 return;
1061 }
1062
1063 if (ED_area_is_global(area)) {
1064 return;
1065 }
1066
1067 if (screen->temp) {
1068 return;
1069 }
1070
1071 /* Use a taller zone on the left side, the height of
1072 * the header, to make them easier to hit. The others
1073 * on the right are shorter to not interfere with
1074 * scroll bars. */
1075
1076 const float coords[4][4] = {
1077 /* Bottom-left. */
1078 {area->totrct.xmin - U.pixelsize,
1079 area->totrct.ymin - U.pixelsize,
1080 area->totrct.xmin + UI_AZONESPOTW,
1081 float(area->totrct.ymin + ED_area_headersize())},
1082 /* Bottom-right. */
1083 {area->totrct.xmax - UI_AZONESPOTW,
1084 area->totrct.ymin - U.pixelsize,
1085 area->totrct.xmax + U.pixelsize,
1086 area->totrct.ymin + UI_AZONESPOTH},
1087 /* Top-left. */
1088 {area->totrct.xmin - U.pixelsize,
1089 float(area->totrct.ymax - ED_area_headersize()),
1090 area->totrct.xmin + UI_AZONESPOTW,
1091 area->totrct.ymax + U.pixelsize},
1092 /* Top-right. */
1093 {area->totrct.xmax - UI_AZONESPOTW,
1094 area->totrct.ymax - UI_AZONESPOTH,
1095 area->totrct.xmax + U.pixelsize,
1096 area->totrct.ymax + U.pixelsize},
1097 };
1098
1099 for (int i = 0; i < 4; i++) {
1100 /* can't click on bottom corners on OS X, already used for resizing */
1101#ifdef __APPLE__
1102 if (!WM_window_is_fullscreen(win) &&
1103 ((coords[i][0] == 0 && coords[i][1] == 0) ||
1104 (coords[i][0] == WM_window_native_pixel_x(win) && coords[i][1] == 0)))
1105 {
1106 continue;
1107 }
1108#else
1109 (void)win;
1110#endif
1111
1112 /* set area action zones */
1113 AZone *az = MEM_callocN<AZone>("actionzone");
1114 BLI_addtail(&(area->actionzones), az);
1115 az->type = AZONE_AREA;
1116 az->x1 = coords[i][0];
1117 az->y1 = coords[i][1];
1118 az->x2 = coords[i][2];
1119 az->y2 = coords[i][3];
1120 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1121 }
1122}
1123
1124static void fullscreen_azone_init(ScrArea *area, ARegion *region)
1125{
1126 if (ED_area_is_global(area) || (region->regiontype != RGN_TYPE_WINDOW)) {
1127 return;
1128 }
1129
1130 AZone *az = MEM_callocN<AZone>("fullscreen action zone");
1131 BLI_addtail(&(area->actionzones), az);
1132 az->type = AZONE_FULLSCREEN;
1133 az->region = region;
1134 az->alpha = 0.0f;
1135
1136 if (U.uiflag2 & USER_REGION_OVERLAP) {
1137 const rcti *rect_visible = ED_region_visible_rect(region);
1138 az->x2 = region->winrct.xmin + rect_visible->xmax;
1139 az->y2 = region->winrct.ymin + rect_visible->ymax;
1140 }
1141 else {
1142 az->x2 = region->winrct.xmax;
1143 az->y2 = region->winrct.ymax;
1144 }
1145 az->x1 = az->x2 - AZONEFADEOUT;
1146 az->y1 = az->y2 - AZONEFADEOUT;
1147
1148 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1149}
1150
1156static bool region_background_is_transparent(const ScrArea *area, const ARegion *region)
1157{
1158 /* Ensure the right theme is active, may not be the case on startup, for example. */
1159 bThemeState theme_state;
1160 UI_Theme_Store(&theme_state);
1161 UI_SetTheme(area->spacetype, region->regiontype);
1162
1163 uchar back[4];
1165
1166 UI_Theme_Restore(&theme_state);
1167
1168 return back[3] < 50;
1169}
1170
1171static void region_azone_edge(const ScrArea *area, AZone *az, const ARegion *region)
1172{
1173 /* Narrow regions like headers need a smaller hit-space that
1174 * does not interfere with content. */
1175 const bool is_narrow = RGN_TYPE_IS_HEADER_ANY(region->regiontype);
1176 const bool transparent = !is_narrow && region->overlap &&
1178
1179 /* Only scale the padding inside the region, not outside. */
1180 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
1181 (BLI_rcti_size_y(&region->v2d.mask) + 1);
1182
1183 /* Different padding inside and outside the region. */
1184 const int pad_out = (is_narrow ? 2.0f : 3.0f) * UI_SCALE_FAC;
1185 const int pad_in = (is_narrow ? 1.0f : (transparent ? 8.0f : 4.0f)) * UI_SCALE_FAC / aspect;
1186
1187 switch (az->edge) {
1189 az->x1 = region->winrct.xmin;
1190 az->y1 = region->winrct.ymax + pad_out;
1191 az->x2 = region->winrct.xmax;
1192 az->y2 = region->winrct.ymax - pad_in;
1193 break;
1195 az->x1 = region->winrct.xmin;
1196 az->y1 = region->winrct.ymin + pad_out;
1197 az->x2 = region->winrct.xmax;
1198 az->y2 = region->winrct.ymin - pad_in;
1199 break;
1201 az->x1 = region->winrct.xmin - pad_out;
1202 az->y1 = region->winrct.ymin;
1203 az->x2 = region->winrct.xmin + pad_in;
1204 az->y2 = region->winrct.ymax;
1205 break;
1207 az->x1 = region->winrct.xmax - pad_in;
1208 az->y1 = region->winrct.ymin;
1209 az->x2 = region->winrct.xmax + pad_out;
1210 az->y2 = region->winrct.ymax;
1211 break;
1212 }
1213 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1214}
1215
1216/* region already made zero sized, in shape of edge */
1217static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region)
1218{
1219 float edge_offset = 1.0f;
1220 const float tab_size_x = 1.0f * U.widget_unit;
1221 const float tab_size_y = 0.5f * U.widget_unit;
1222
1223 switch (az->edge) {
1224 case AE_TOP_TO_BOTTOMRIGHT: {
1225 int add = (region->winrct.ymax == area->totrct.ymin) ? 1 : 0;
1226 az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x);
1227 az->y1 = region->winrct.ymax - U.pixelsize;
1228 az->x2 = region->winrct.xmax - (edge_offset * tab_size_x);
1229 az->y2 = region->winrct.ymax - add + tab_size_y;
1230 break;
1231 }
1233 az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x);
1234 az->y1 = region->winrct.ymin - tab_size_y;
1235 az->x2 = region->winrct.xmax - (edge_offset * tab_size_x);
1236 az->y2 = region->winrct.ymin + U.pixelsize;
1237 break;
1239 az->x1 = region->winrct.xmin - tab_size_y;
1240 az->y1 = region->winrct.ymax - ((edge_offset + 1.0f) * tab_size_x);
1241 az->x2 = region->winrct.xmin + U.pixelsize;
1242 az->y2 = region->winrct.ymax - (edge_offset * tab_size_x);
1243 break;
1245 az->x1 = region->winrct.xmax - U.pixelsize;
1246 az->y1 = region->winrct.ymax - ((edge_offset + 1.0f) * tab_size_x);
1247 az->x2 = region->winrct.xmax + tab_size_y;
1248 az->y2 = region->winrct.ymax - (edge_offset * tab_size_x);
1249 break;
1250 }
1251 /* rect needed for mouse pointer test */
1252 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1253}
1254
1255static bool region_azone_edge_poll(const ScrArea *area,
1256 const ARegion *region,
1257 const bool is_fullscreen)
1258{
1259 if (region->flag & RGN_FLAG_POLL_FAILED) {
1260 return false;
1261 }
1262
1263 /* Don't use edge if the region hides with previous region which is now hidden. See #116196. */
1264 if ((region->alignment & (RGN_SPLIT_PREV | RGN_ALIGN_HIDE_WITH_PREV) && region->prev) &&
1266 {
1267 return false;
1268 }
1269
1270 const bool is_hidden = (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1271
1272 if (is_hidden && is_fullscreen) {
1273 return false;
1274 }
1275 if (!is_hidden && ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) {
1276 return false;
1277 }
1278 if (!is_hidden && region->regiontype == RGN_TYPE_NAV_BAR && area->spacetype == SPACE_PROPERTIES)
1279 {
1280 return false;
1281 }
1282
1283 if (is_hidden && (U.app_flag & USER_APP_HIDE_REGION_TOGGLE)) {
1284 return false;
1285 }
1286
1287 if (!is_hidden && (U.app_flag & USER_APP_LOCK_EDGE_RESIZE)) {
1288 return false;
1289 }
1290
1291 return true;
1292}
1293
1295 ARegion *region,
1296 AZEdge edge,
1297 const bool is_fullscreen)
1298{
1299 const bool is_hidden = (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1300
1301 if (!region_azone_edge_poll(area, region, is_fullscreen)) {
1302 return;
1303 }
1304
1305 AZone *az = MEM_callocN<AZone>("actionzone");
1306 BLI_addtail(&(area->actionzones), az);
1307 az->type = AZONE_REGION;
1308 az->region = region;
1309 az->edge = edge;
1310
1311 if (is_hidden) {
1312 region_azone_tab_plus(area, az, region);
1313 }
1314 else {
1315 region_azone_edge(area, az, region);
1316 }
1317}
1318
1320 ARegion *region,
1321 AZScrollDirection direction)
1322{
1323 AZone *az = MEM_callocN<AZone>(__func__);
1324
1325 BLI_addtail(&area->actionzones, az);
1327 az->region = region;
1328 az->direction = direction;
1329
1330 if (direction == AZ_SCROLL_VERT) {
1331 az->region->v2d.alpha_vert = 0;
1332 }
1333 else if (direction == AZ_SCROLL_HOR) {
1334 az->region->v2d.alpha_hor = 0;
1335 }
1336
1337 /* No need to specify rect for scrollbar az. For intersection we'll test against the area around
1338 * the region's scroller instead, in `area_actionzone_get_rect`. */
1339}
1340
1342{
1343 const View2D *v2d = &region->v2d;
1344
1345 if (v2d->scroll & V2D_SCROLL_VERTICAL) {
1347 }
1348 if (v2d->scroll & V2D_SCROLL_HORIZONTAL) {
1350 }
1351}
1352
1353/* *************************************************************** */
1355 ARegion *region,
1356 const int alignment,
1357 const bool is_fullscreen)
1358{
1359
1360 /* edge code (t b l r) is along which area edge azone will be drawn */
1361 if (alignment == RGN_ALIGN_TOP) {
1362 region_azone_edge_init(area, region, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
1363 }
1364 else if (alignment == RGN_ALIGN_BOTTOM) {
1365 region_azone_edge_init(area, region, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
1366 }
1367 else if (alignment == RGN_ALIGN_RIGHT) {
1368 region_azone_edge_init(area, region, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
1369 }
1370 else if (alignment == RGN_ALIGN_LEFT) {
1371 region_azone_edge_init(area, region, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
1372 }
1373}
1374
1375static void region_azones_add(const bScreen *screen, ScrArea *area, ARegion *region)
1376{
1377 const bool is_fullscreen = screen->state == SCREENFULL;
1378
1379 /* Only display tab or icons when the header region is hidden
1380 * (not the tool header - they overlap). */
1381 if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
1382 return;
1383 }
1384
1385 region_azones_add_edge(area, region, RGN_ALIGN_ENUM_FROM_MASK(region->alignment), is_fullscreen);
1386
1387 /* For a split region also continue the azone edge from the next region if this region is aligned
1388 * with the next */
1389 if ((region->alignment & RGN_SPLIT_PREV) && region->prev) {
1391 area, region, RGN_ALIGN_ENUM_FROM_MASK(region->prev->alignment), is_fullscreen);
1392 }
1393
1394 if (is_fullscreen) {
1395 fullscreen_azone_init(area, region);
1396 }
1397
1398 region_azones_scrollbars_init(area, region);
1399}
1400
1401/* dir is direction to check, not the splitting edge direction! */
1402static int rct_fits(const rcti *rect, const eScreenAxis dir_axis, int size)
1403{
1404 if (dir_axis == SCREEN_AXIS_H) {
1405 return BLI_rcti_size_x(rect) + 1 - size;
1406 }
1407 /* Vertical. */
1408 return BLI_rcti_size_y(rect) + 1 - size;
1409}
1410
1411/* *************************************************************** */
1412
1413/* region should be overlapping */
1414/* function checks if some overlapping region was defined before - on same place */
1415static void region_overlap_fix(ScrArea *area, ARegion *region)
1416{
1417 /* find overlapping previous region on same place */
1418 ARegion *region_iter;
1419 int align1 = 0;
1420 const int align = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
1421 for (region_iter = region->prev; region_iter; region_iter = region_iter->prev) {
1422 if (region_iter->flag & (RGN_FLAG_POLL_FAILED | RGN_FLAG_HIDDEN)) {
1423 continue;
1424 }
1425 if (!region_iter->overlap || (region_iter->alignment & RGN_SPLIT_PREV)) {
1426 continue;
1427 }
1428
1429 const int align_iter = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
1430 if (ELEM(align_iter, RGN_ALIGN_FLOAT)) {
1431 continue;
1432 }
1433
1434 align1 = align_iter;
1435 if (BLI_rcti_isect(&region_iter->winrct, &region->winrct, nullptr)) {
1436 if (align1 != align) {
1437 /* Left overlapping right or vice-versa, forbid this! */
1438 region->flag |= RGN_FLAG_TOO_SMALL;
1439 return;
1440 }
1441 /* Else, we have our previous region on same side. */
1442 break;
1443 }
1444 }
1445
1446 /* Guard against flags slipping through that would have to be masked out in usages below. */
1447 BLI_assert(align1 == RGN_ALIGN_ENUM_FROM_MASK(align1));
1448
1449 /* translate or close */
1450 if (region_iter) {
1451 if (align1 == RGN_ALIGN_LEFT) {
1452 if (region->winrct.xmax + region_iter->winx > area->winx - U.widget_unit) {
1453 region->flag |= RGN_FLAG_TOO_SMALL;
1454 return;
1455 }
1456 BLI_rcti_translate(&region->winrct, region_iter->winx, 0);
1457 }
1458 else if (align1 == RGN_ALIGN_RIGHT) {
1459 if (region->winrct.xmin - region_iter->winx < U.widget_unit) {
1460 region->flag |= RGN_FLAG_TOO_SMALL;
1461 return;
1462 }
1463 BLI_rcti_translate(&region->winrct, -region_iter->winx, 0);
1464 }
1465 }
1466
1467 /* At this point, 'region' is in its final position and still open.
1468 * Make a final check it does not overlap any previous 'other side' region. */
1469 for (region_iter = region->prev; region_iter; region_iter = region_iter->prev) {
1470 if (region_iter->flag & (RGN_FLAG_POLL_FAILED | RGN_FLAG_HIDDEN)) {
1471 continue;
1472 }
1473 if (!region_iter->overlap || (region_iter->alignment & RGN_SPLIT_PREV)) {
1474 continue;
1475 }
1476
1477 const int align_iter = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
1478 if (ELEM(align_iter, RGN_ALIGN_FLOAT)) {
1479 continue;
1480 }
1481
1482 if ((align_iter != align) && BLI_rcti_isect(&region_iter->winrct, &region->winrct, nullptr)) {
1483 /* Left overlapping right or vice-versa, forbid this! */
1484 region->flag |= RGN_FLAG_TOO_SMALL;
1485 return;
1486 }
1487 }
1488}
1489
1490bool ED_region_is_overlap(int spacetype, int regiontype)
1491{
1492 if (regiontype == RGN_TYPE_HUD) {
1493 return true;
1494 }
1495 if (U.uiflag2 & USER_REGION_OVERLAP) {
1496 if (spacetype == SPACE_NODE) {
1497 if (ELEM(regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI)) {
1498 return true;
1499 }
1500 }
1501 else if (spacetype == SPACE_VIEW3D) {
1502 if (regiontype == RGN_TYPE_HEADER) {
1503 /* Do not treat as overlapped if no transparency. */
1504 bTheme *theme = UI_GetTheme();
1505 return theme->space_view3d.header[3] != 255;
1506 }
1507 if (ELEM(regiontype,
1515 {
1516 return true;
1517 }
1518 }
1519 else if (spacetype == SPACE_IMAGE) {
1520 if (ELEM(regiontype,
1528 {
1529 return true;
1530 }
1531 }
1532 }
1533
1534 return false;
1535}
1536
1538 ScrArea *area, ARegion *region, rcti *remainder, rcti *overlap_remainder, int quad)
1539{
1540 using namespace blender::ed;
1541 rcti *remainder_prev = remainder;
1542
1543 if (region == nullptr) {
1544 return;
1545 }
1546
1547 int prev_winx = region->winx;
1548 int prev_winy = region->winy;
1549
1550 /* no returns in function, winrct gets set in the end again */
1551 BLI_rcti_init(&region->winrct, 0, 0, 0, 0);
1552
1553 /* for test; allow split of previously defined region */
1554 if (region->alignment & RGN_SPLIT_PREV) {
1555 if (region->prev) {
1556 remainder = &region->prev->winrct;
1557 }
1558 }
1559
1560 int alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
1561
1562 /* set here, assuming userpref switching forces to call this again */
1563 region->overlap = ED_region_is_overlap(area->spacetype, region->regiontype);
1564
1565 /* clear state flags first */
1567 /* user errors */
1568 if ((region->next == nullptr) && !ELEM(alignment, RGN_ALIGN_QSPLIT, RGN_ALIGN_FLOAT)) {
1569 alignment = RGN_ALIGN_NONE;
1570 }
1571
1572 /* If both the #ARegion.sizex/y and the #ARegionType.prefsizex/y are 0, the region is tagged as
1573 * too small, even before the layout for dynamically sized regions is created.
1574 * #wm_draw_window_offscreen() allows the layout to be created despite the #RGN_FLAG_TOO_SMALL
1575 * flag being set. But there may still be regions that don't have a separate #ARegionType.layout
1576 * callback. For those, set a default #ARegionType.prefsizex/y so they can become visible. */
1577 if ((region->flag & RGN_FLAG_DYNAMIC_SIZE) && !(region->runtime->type->layout)) {
1578 if ((region->sizex == 0) && (region->runtime->type->prefsizex == 0)) {
1579 region->runtime->type->prefsizex = AREAMINX;
1580 }
1581 if ((region->sizey == 0) && (region->runtime->type->prefsizey == 0)) {
1582 region->runtime->type->prefsizey = HEADERY;
1583 }
1584 }
1585
1586 /* `prefsizex/y`, taking into account DPI. */
1587 int prefsizex = UI_SCALE_FAC *
1588 ((region->sizex > 1) ? region->sizex + 0.5f : region->runtime->type->prefsizex);
1589 int prefsizey;
1590
1591 if (region->regiontype == RGN_TYPE_HEADER) {
1592 prefsizey = ED_area_headersize();
1593 }
1594 else if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
1595 prefsizey = ED_area_headersize();
1596 }
1597 else if (region->regiontype == RGN_TYPE_FOOTER) {
1598 prefsizey = ED_area_footersize();
1599 }
1600 else if (region->regiontype == RGN_TYPE_ASSET_SHELF) {
1601 prefsizey = region->sizey > 1 ? (UI_SCALE_FAC * (region->sizey + 0.5f)) :
1603 }
1604 else if (region->regiontype == RGN_TYPE_ASSET_SHELF_HEADER) {
1606 }
1607 else if (ED_area_is_global(area)) {
1608 prefsizey = ED_region_global_size_y();
1609 }
1610 else {
1611 prefsizey = UI_SCALE_FAC *
1612 (region->sizey > 1 ? region->sizey + 0.5f : region->runtime->type->prefsizey);
1613 }
1614
1615 if (region->flag & (RGN_FLAG_POLL_FAILED | RGN_FLAG_HIDDEN)) {
1616 /* hidden is user flag */
1617 }
1618 else if (alignment == RGN_ALIGN_FLOAT) {
1625 const int size_min[2] = {UI_UNIT_X, UI_UNIT_Y};
1626 rcti overlap_remainder_margin = *overlap_remainder;
1627
1628 BLI_rcti_resize(&overlap_remainder_margin,
1629 max_ii(0, BLI_rcti_size_x(overlap_remainder) - UI_UNIT_X / 2),
1630 max_ii(0, BLI_rcti_size_y(overlap_remainder) - UI_UNIT_Y / 2));
1631 region->winrct.xmin = overlap_remainder_margin.xmin + region->runtime->offset_x;
1632 region->winrct.ymin = overlap_remainder_margin.ymin + region->runtime->offset_y;
1633 region->winrct.xmax = region->winrct.xmin + prefsizex - 1;
1634 region->winrct.ymax = region->winrct.ymin + prefsizey - 1;
1635
1636 BLI_rcti_isect(&region->winrct, &overlap_remainder_margin, &region->winrct);
1637
1638 if (BLI_rcti_size_x(&region->winrct) != prefsizex - 1) {
1639 region->flag |= RGN_FLAG_SIZE_CLAMP_X;
1640 }
1641 if (BLI_rcti_size_y(&region->winrct) != prefsizey - 1) {
1642 region->flag |= RGN_FLAG_SIZE_CLAMP_Y;
1643 }
1644
1645 /* We need to use a test that won't have been previously clamped. */
1646 rcti winrct_test{};
1647 winrct_test.xmin = region->winrct.xmin;
1648 winrct_test.ymin = region->winrct.ymin;
1649 winrct_test.xmax = region->winrct.xmin + size_min[0];
1650 winrct_test.ymax = region->winrct.ymin + size_min[1];
1651
1652 BLI_rcti_isect(&winrct_test, &overlap_remainder_margin, &winrct_test);
1653 if (BLI_rcti_size_x(&winrct_test) < size_min[0] || BLI_rcti_size_y(&winrct_test) < size_min[1])
1654 {
1655 region->flag |= RGN_FLAG_TOO_SMALL;
1656 }
1657 }
1658 else if (rct_fits(remainder, SCREEN_AXIS_V, 1) < 0 || rct_fits(remainder, SCREEN_AXIS_H, 1) < 0)
1659 {
1660 /* remainder is too small for any usage */
1661 region->flag |= RGN_FLAG_TOO_SMALL;
1662 }
1663 else if (alignment == RGN_ALIGN_NONE) {
1664 /* typically last region */
1665 region->winrct = *remainder;
1666 BLI_rcti_init(remainder, 0, 0, 0, 0);
1667 }
1668 else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
1669 rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
1670
1671 if ((prefsizey == 0) || (rct_fits(winrct, SCREEN_AXIS_V, prefsizey) < (U.pixelsize * -2))) {
1672 region->flag |= RGN_FLAG_TOO_SMALL;
1673 }
1674 else {
1675 int fac = rct_fits(winrct, SCREEN_AXIS_V, prefsizey);
1676
1677 if (fac < 0) {
1678 prefsizey += fac;
1679 }
1680
1681 region->winrct = *winrct;
1682
1683 if (alignment == RGN_ALIGN_TOP) {
1684 region->winrct.ymin = region->winrct.ymax - prefsizey + 1;
1685 winrct->ymax = region->winrct.ymin - 1;
1686 }
1687 else {
1688 region->winrct.ymax = region->winrct.ymin + prefsizey - 1;
1689 winrct->ymin = region->winrct.ymax + 1;
1690 }
1691 BLI_rcti_sanitize(winrct);
1692 }
1693 }
1694 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
1695 rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
1696
1697 if ((prefsizex == 0) || (rct_fits(winrct, SCREEN_AXIS_H, prefsizex) < 0)) {
1698 region->flag |= RGN_FLAG_TOO_SMALL;
1699 }
1700 else {
1701 int fac = rct_fits(winrct, SCREEN_AXIS_H, prefsizex);
1702
1703 if (fac < 0) {
1704 prefsizex += fac;
1705 }
1706
1707 region->winrct = *winrct;
1708
1709 if (alignment == RGN_ALIGN_RIGHT) {
1710 region->winrct.xmin = region->winrct.xmax - prefsizex + 1;
1711 winrct->xmax = region->winrct.xmin - 1;
1712 }
1713 else {
1714 region->winrct.xmax = region->winrct.xmin + prefsizex - 1;
1715 winrct->xmin = region->winrct.xmax + 1;
1716 }
1717 BLI_rcti_sanitize(winrct);
1718 }
1719 }
1720 else if (ELEM(alignment, RGN_ALIGN_VSPLIT, RGN_ALIGN_HSPLIT)) {
1721 /* Percentage subdiv. */
1722 region->winrct = *remainder;
1723
1724 if (alignment == RGN_ALIGN_HSPLIT) {
1725 if (rct_fits(remainder, SCREEN_AXIS_H, prefsizex) > 4) {
1726 region->winrct.xmax = BLI_rcti_cent_x(remainder);
1727 remainder->xmin = region->winrct.xmax + 1;
1728 }
1729 else {
1730 BLI_rcti_init(remainder, 0, 0, 0, 0);
1731 }
1732 }
1733 else {
1734 if (rct_fits(remainder, SCREEN_AXIS_V, prefsizey) > 4) {
1735 region->winrct.ymax = BLI_rcti_cent_y(remainder);
1736 remainder->ymin = region->winrct.ymax + 1;
1737 }
1738 else {
1739 BLI_rcti_init(remainder, 0, 0, 0, 0);
1740 }
1741 }
1742 }
1743 else if (alignment == RGN_ALIGN_QSPLIT) {
1744 region->winrct = *remainder;
1745
1746 /* test if there's still 4 regions left */
1747 if (quad == 0) {
1748 ARegion *region_test = region->next;
1749 int count = 1;
1750
1751 while (region_test) {
1752 region_test->alignment = RGN_ALIGN_QSPLIT;
1753 region_test = region_test->next;
1754 count++;
1755 }
1756
1757 if (count != 4) {
1758 /* let's stop adding regions */
1759 BLI_rcti_init(remainder, 0, 0, 0, 0);
1760 if (G.debug & G_DEBUG) {
1761 printf("region quadsplit failed\n");
1762 }
1763 }
1764 else {
1765 quad = 1;
1766 }
1767 }
1768 if (quad) {
1769 if (quad == 1) { /* left bottom */
1770 region->winrct.xmax = BLI_rcti_cent_x(remainder);
1771 region->winrct.ymax = BLI_rcti_cent_y(remainder);
1772 }
1773 else if (quad == 2) { /* left top */
1774 region->winrct.xmax = BLI_rcti_cent_x(remainder);
1775 region->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1776 }
1777 else if (quad == 3) { /* right bottom */
1778 region->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1779 region->winrct.ymax = BLI_rcti_cent_y(remainder);
1780 }
1781 else { /* right top */
1782 region->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1783 region->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1784 BLI_rcti_init(remainder, 0, 0, 0, 0);
1785 }
1786
1787 /* Fix any negative dimensions. This can happen when a quad split 3d view gets too small.
1788 * (see #72200). */
1789 BLI_rcti_sanitize(&region->winrct);
1790
1791 quad++;
1792 }
1793 }
1794
1795 /* for speedup */
1796 region->winx = BLI_rcti_size_x(&region->winrct) + 1;
1797 region->winy = BLI_rcti_size_y(&region->winrct) + 1;
1798
1799 /* If region opened normally, we store this for hide/reveal usage. */
1800 /* Prevent rounding errors for UI_SCALE_FAC multiply and divide. */
1801 if (region->winx > 1) {
1802 region->sizex = (region->winx + 0.5f) / UI_SCALE_FAC;
1803 }
1804 if (region->winy > 1) {
1805 region->sizey = (region->winy + 0.5f) / UI_SCALE_FAC;
1806 }
1807
1808 /* exception for multiple overlapping regions on same spot */
1809 if (region->overlap && (alignment != RGN_ALIGN_FLOAT)) {
1810 region_overlap_fix(area, region);
1811 }
1812
1813 /* Set `region->winrct` for action-zones. */
1814 if (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1815 region->winrct = (region->overlap) ? *overlap_remainder : *remainder;
1816
1817 switch (alignment) {
1818 case RGN_ALIGN_TOP:
1819 region->winrct.ymin = region->winrct.ymax;
1820 break;
1821 case RGN_ALIGN_BOTTOM:
1822 region->winrct.ymax = region->winrct.ymin;
1823 break;
1824 case RGN_ALIGN_RIGHT:
1825 region->winrct.xmin = region->winrct.xmax;
1826 break;
1827 case RGN_ALIGN_LEFT:
1828 region->winrct.xmax = region->winrct.xmin;
1829 break;
1830 default:
1831 /* prevent winrct to be valid */
1832 region->winrct.xmax = region->winrct.xmin;
1833 break;
1834 }
1835
1836 /* Size on one axis is now 0, the other axis may still be invalid (negative) though. */
1837 BLI_rcti_sanitize(&region->winrct);
1838 }
1839
1840 /* restore prev-split exception */
1841 if (region->alignment & RGN_SPLIT_PREV) {
1842 if (region->prev) {
1843 remainder = remainder_prev;
1844 region->prev->winx = BLI_rcti_size_x(&region->prev->winrct) + 1;
1845 region->prev->winy = BLI_rcti_size_y(&region->prev->winrct) + 1;
1846 }
1847 }
1848
1849 /* After non-overlapping region, all following overlapping regions
1850 * fit within the remaining space again. */
1851 if (!region->overlap) {
1852 *overlap_remainder = *remainder;
1853 }
1854
1856
1857 region_rect_recursive(area, region->next, remainder, overlap_remainder, quad);
1858
1859 /* Tag for redraw if size changes. */
1860 if (region->winx != prev_winx || region->winy != prev_winy) {
1861 /* 3D View needs a full rebuild in case a progressive render runs. Rest can live with
1862 * no-rebuild (e.g. Outliner) */
1863 if (area->spacetype == SPACE_VIEW3D) {
1864 ED_region_tag_redraw(region);
1865 }
1866 else {
1868 }
1869 }
1870
1871 /* Clear, initialize on demand. */
1872 region->runtime->visible_rect = rcti{};
1873}
1874
1875static void area_calc_totrct(const bScreen *screen, ScrArea *area, const rcti *window_rect)
1876{
1877 short px = short(std::max(float(U.border_width) * UI_SCALE_FAC, UI_SCALE_FAC));
1878
1879 area->totrct.xmin = area->v1->vec.x;
1880 area->totrct.xmax = area->v4->vec.x;
1881 area->totrct.ymin = area->v1->vec.y;
1882 area->totrct.ymax = area->v2->vec.y;
1883
1884 /* Scale down totrct by the border size on all sides not at window edges. */
1885 if (!ED_area_is_global(area) && screen->state != SCREENFULL &&
1886 !(screen->temp && BLI_listbase_is_single(&screen->areabase)))
1887 {
1888 if (area->totrct.xmin > window_rect->xmin) {
1889 area->totrct.xmin += px;
1890 }
1891 if (area->totrct.xmax < (window_rect->xmax - 1)) {
1892 area->totrct.xmax -= px;
1893 }
1894
1895 if (area->totrct.ymin > window_rect->ymin + 1) {
1896 area->totrct.ymin += px;
1897 }
1898 else {
1899 /* Minimum padding at bottom edge. #144921 */
1900 const short px_min = short(U.pixelsize * 2.0f);
1901 area->totrct.ymin += px_min;
1902 }
1903
1904 if (area->totrct.ymax < (window_rect->ymax - 1)) {
1905 area->totrct.ymax -= px;
1906 }
1907 else if (!BLI_listbase_is_single(&screen->areabase) || screen->state == SCREENMAXIMIZED) {
1908 /* Small gap below Top Bar. */
1909 area->totrct.ymax -= U.pixelsize;
1910 }
1911 }
1912 /* Although the following asserts are correct they lead to a very unstable Blender.
1913 * And the asserts would fail even in 2.7x
1914 * (they were added in 2.8x as part of the top-bar commit).
1915 * For more details see #54864. */
1916#if 0
1917 BLI_assert(area->totrct.xmin >= 0);
1918 BLI_assert(area->totrct.xmax >= 0);
1919 BLI_assert(area->totrct.ymin >= 0);
1920 BLI_assert(area->totrct.ymax >= 0);
1921#endif
1922
1923 /* for speedup */
1924 area->winx = BLI_rcti_size_x(&area->totrct) + 1;
1925 area->winy = BLI_rcti_size_y(&area->totrct) + 1;
1926}
1927
1932{
1933 bool hidden = (region->flag & (RGN_FLAG_POLL_FAILED | RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) !=
1934 0;
1935
1936 if ((region->alignment & (RGN_SPLIT_PREV | RGN_ALIGN_HIDE_WITH_PREV)) && region->prev) {
1937 hidden = hidden || (region->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1938 }
1939
1940 region->runtime->visible = !hidden;
1941}
1942
1947 wmWindowManager *wm, ScrArea *area, ARegion *region, ListBase *handlers, int flag)
1948{
1949 BLI_assert(region ? (&region->runtime->handlers == handlers) : (&area->handlers == handlers));
1950
1951 /* NOTE: add-handler checks if it already exists. */
1952
1953 /* XXX: it would be good to have bound-box checks for some of these. */
1954 if (flag & ED_KEYMAP_UI) {
1955 wmKeyMap *keymap = WM_keymap_ensure(
1956 wm->defaultconf, "User Interface", SPACE_EMPTY, RGN_TYPE_WINDOW);
1957 WM_event_add_keymap_handler(handlers, keymap);
1958
1961
1962 /* user interface widgets */
1963 UI_region_handlers_add(handlers);
1964 }
1965 if (flag & ED_KEYMAP_GIZMO) {
1966 BLI_assert(region && ELEM(region->runtime->type->regionid, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW));
1967 if (region) {
1968 /* Anything else is confusing, only allow this. */
1969 BLI_assert(&region->runtime->handlers == handlers);
1970 if (region->runtime->gizmo_map == nullptr) {
1972 params.spaceid = area->spacetype;
1973 params.regionid = region->runtime->type->regionid;
1974 region->runtime->gizmo_map = WM_gizmomap_new_from_type(&params);
1975 }
1976 WM_gizmomap_add_handlers(region, region->runtime->gizmo_map);
1977 }
1978 }
1979 if (flag & ED_KEYMAP_VIEW2D) {
1980 /* 2d-viewport handling+manipulation */
1981 wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "View2D", SPACE_EMPTY, RGN_TYPE_WINDOW);
1982 WM_event_add_keymap_handler(handlers, keymap);
1983 }
1984 if (flag & ED_KEYMAP_ANIMATION) {
1985 wmKeyMap *keymap;
1986
1987 /* time-markers */
1988 keymap = WM_keymap_ensure(wm->defaultconf, "Markers", SPACE_EMPTY, RGN_TYPE_WINDOW);
1990
1991 /* time-scrub */
1992 keymap = WM_keymap_ensure(wm->defaultconf, "Time Scrub", SPACE_EMPTY, RGN_TYPE_WINDOW);
1994
1995 /* frame changing and timeline operators (for time spaces) */
1996 keymap = WM_keymap_ensure(wm->defaultconf, "Animation", SPACE_EMPTY, RGN_TYPE_WINDOW);
1997 WM_event_add_keymap_handler(handlers, keymap);
1998 }
1999 if (flag & ED_KEYMAP_TOOL) {
2000 if (flag & ED_KEYMAP_GIZMO) {
2003 }
2004 else {
2006 &region->runtime->handlers, WM_event_get_keymap_from_toolsystem, area);
2007 }
2008 }
2009 if (flag & ED_KEYMAP_FRAMES) {
2010 /* frame changing/jumping (for all spaces) */
2011 wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Frames", SPACE_EMPTY, RGN_TYPE_WINDOW);
2012 WM_event_add_keymap_handler(handlers, keymap);
2013 }
2014 if (flag & ED_KEYMAP_HEADER) {
2015 /* standard keymap for headers regions */
2016 wmKeyMap *keymap = WM_keymap_ensure(
2017 wm->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2018 WM_event_add_keymap_handler(handlers, keymap);
2019 }
2020 if (flag & ED_KEYMAP_FOOTER) {
2021 /* standard keymap for footer regions */
2022 wmKeyMap *keymap = WM_keymap_ensure(
2023 wm->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2024 WM_event_add_keymap_handler(handlers, keymap);
2025 }
2026 if (flag & ED_KEYMAP_NAVBAR) {
2027 /* standard keymap for Navigation bar regions */
2028 wmKeyMap *keymap = WM_keymap_ensure(
2029 wm->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2030 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
2031 }
2033 /* standard keymap for asset shelf regions */
2034 wmKeyMap *keymap = WM_keymap_ensure(
2035 wm->defaultconf, "Asset Shelf", SPACE_EMPTY, RGN_TYPE_WINDOW);
2036 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
2037 }
2038
2039 /* Keep last because of LMB/RMB handling, see: #57527. */
2040 if (flag & ED_KEYMAP_GPENCIL) {
2041 /* grease pencil */
2042 {
2043 wmKeyMap *keymap = WM_keymap_ensure(
2044 wm->defaultconf, "Grease Pencil", SPACE_EMPTY, RGN_TYPE_WINDOW);
2045 WM_event_add_keymap_handler(handlers, keymap);
2046 }
2047 }
2048}
2049
2051{
2052 if (!(area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
2053 return;
2054 }
2055 const bScreen *screen = WM_window_get_active_screen(win);
2056
2057 rcti window_rect;
2058 WM_window_screen_rect_calc(win, &window_rect);
2059 area_calc_totrct(screen, area, &window_rect);
2060
2061 /* region rect sizes */
2062 rcti rect = area->totrct;
2063 rcti overlap_rect = rect;
2065 area, static_cast<ARegion *>(area->regionbase.first), &rect, &overlap_rect, 0);
2066
2067 /* Dynamically sized regions may have changed region sizes, so we have to force azone update. */
2068 area_azone_init(win, screen, area);
2069
2070 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2071 if (region->flag & RGN_FLAG_POLL_FAILED) {
2072 continue;
2073 }
2075
2076 /* region size may have changed, init does necessary adjustments */
2077 if (region->runtime->type->init) {
2078 region->runtime->type->init(wm, region);
2079 }
2080
2081 /* Some AZones use View2D data which is only updated in region init, so call that first! */
2082 region_azones_add(screen, area, region);
2083 }
2084 ED_area_azones_update(area, win->eventstate->xy);
2085
2087}
2088
2090{
2091 return area_getorientation(a, b) != -1;
2092}
2093
2097static void area_init_type_fallback(ScrArea *area, eSpace_Type space_type)
2098{
2099 BLI_assert(area->type == nullptr);
2100 area->spacetype = space_type;
2101 area->type = BKE_spacetype_from_id(area->spacetype);
2102
2103 SpaceLink *sl = nullptr;
2104 LISTBASE_FOREACH (SpaceLink *, sl_iter, &area->spacedata) {
2105 if (sl_iter->spacetype == space_type) {
2106 sl = sl_iter;
2107 break;
2108 }
2109 }
2110 if (sl) {
2111 SpaceLink *sl_old = static_cast<SpaceLink *>(area->spacedata.first);
2112 if (LIKELY(sl != sl_old)) {
2113 BLI_remlink(&area->spacedata, sl);
2114 BLI_addhead(&area->spacedata, sl);
2115
2116 /* swap regions */
2117 sl_old->regionbase = area->regionbase;
2118 area->regionbase = sl->regionbase;
2120 }
2121 }
2122 else {
2123 screen_area_spacelink_add(nullptr, area, space_type);
2124 }
2125}
2126
2128{
2129 area->type = BKE_spacetype_from_id(area->spacetype);
2130
2131 if (area->type == nullptr) {
2133 BLI_assert(area->type != nullptr);
2134 }
2135
2136 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2137 region->runtime->type = BKE_regiontype_from_id(area->type, region->regiontype);
2138 /* Invalid region types may be stored in files (e.g. for new files), but they should be handled
2139 * on file read already, see #BKE_screen_area_blend_read_lib(). */
2140 BLI_assert_msg(region->runtime->type != nullptr, "Region type not valid for this space type");
2141 }
2142}
2143
2144void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
2145{
2147 WorkSpace *workspace = WM_window_get_active_workspace(win);
2149 const Scene *scene = WM_window_get_active_scene(win);
2150 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
2151
2152 if (ED_area_is_global(area) && (area->global->flag & GLOBAL_AREA_IS_HIDDEN)) {
2153 return;
2154 }
2155
2156 rcti window_rect;
2157 WM_window_screen_rect_calc(win, &window_rect);
2158
2160
2161 /* area sizes */
2162 area_calc_totrct(screen, area, &window_rect);
2163
2164 area_regions_poll(C, screen, area);
2165
2166 /* region rect sizes */
2167 rcti rect = area->totrct;
2168 rcti overlap_rect = rect;
2170 area, static_cast<ARegion *>(area->regionbase.first), &rect, &overlap_rect, 0);
2172
2173 /* default area handlers */
2174 ed_default_handlers(wm, area, nullptr, &area->handlers, area->type->keymapflag);
2175 /* checks spacedata, adds own handlers */
2176 if (area->type->init) {
2177 area->type->init(wm, area);
2178 }
2179
2180 /* clear all azones, add the area triangle widgets */
2181 area_azone_init(win, screen, area);
2182
2183 /* region windows, default and own handlers */
2184 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2186
2187 if (region->runtime->visible) {
2188 /* default region handlers */
2190 wm, area, region, &region->runtime->handlers, region->runtime->type->keymapflag);
2191 /* own handlers */
2192 if (region->runtime->type->init) {
2193 region->runtime->type->init(wm, region);
2194 }
2195 }
2196 else {
2197 /* prevent uiblocks to run */
2198 UI_blocklist_free(nullptr, region);
2199 }
2200
2201 /* Some AZones use View2D data which is only updated in region init, so call that first! */
2202 region_azones_add(screen, area, region);
2203 }
2204
2205 /* Avoid re-initializing tools while resizing areas & regions. */
2206 if ((G.moving & G_TRANSFORM_WM) == 0) {
2207 if ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) {
2208 if (WM_toolsystem_refresh_screen_area(workspace, scene, view_layer, area) ||
2209 /* When the tool is null it may not be initialized.
2210 * This happens when switching to a new area, see: #126990.
2211 *
2212 * NOTE(@ideasman42): There is a possible down-side here: when refreshing
2213 * tools results in a null value, refreshing won't be skipped here as intended.
2214 * As it happens, spaces that use tools will practically always have a default tool. */
2215 (area->runtime.tool == nullptr))
2216 {
2217 /* Only re-initialize as needed to prevent redundant updates as they
2218 * can cause gizmos to flicker when the flag is set continuously, see: #126525. */
2220 }
2221 }
2222 else {
2223 area->runtime.tool = nullptr;
2224 area->runtime.is_tool_set = true;
2225 }
2226 }
2227}
2228
2230{
2231 area->flag |= AREA_FLAG_OFFSCREEN;
2232 area->type = BKE_spacetype_from_id(area->spacetype);
2233 /* Off screen areas are only ever created at run-time,
2234 * so there is no reason for the type to be unknown. */
2235 BLI_assert(area->type != nullptr);
2236
2237 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2238 region->runtime->type = BKE_regiontype_from_id(area->type, region->regiontype);
2239 }
2240}
2241
2243{
2244 ScrArea *area = MEM_callocN<ScrArea>(__func__);
2245 area->spacetype = space_type;
2246
2248 area_offscreen_init(area);
2249
2250 return area;
2251}
2252
2254{
2255 if (area->type && area->type->exit) {
2256 area->type->exit(wm, area);
2257 }
2258
2259 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2260 if (region->runtime->type && region->runtime->type->exit) {
2261 region->runtime->type->exit(wm, region);
2262 }
2263
2264 WM_event_modal_handler_region_replace(win, region, nullptr);
2265 WM_draw_region_free(region);
2266 region->runtime->visible = false;
2267
2268 MEM_SAFE_FREE(region->runtime->headerstr);
2269
2270 if (region->runtime->regiontimer) {
2271 WM_event_timer_remove(wm, win, region->runtime->regiontimer);
2272 region->runtime->regiontimer = nullptr;
2273 }
2274
2275 if (wm->message_bus) {
2276 WM_msgbus_clear_by_owner(wm->message_bus, region);
2277 }
2278 }
2279
2280 WM_event_modal_handler_area_replace(win, area, nullptr);
2281}
2282
2284{
2285 area_offscreen_exit(wm, win, area);
2286
2288 MEM_freeN(area);
2289}
2290
2291static void region_update_rect(ARegion *region)
2292{
2293 region->winx = BLI_rcti_size_x(&region->winrct) + 1;
2294 region->winy = BLI_rcti_size_y(&region->winrct) + 1;
2295
2296 /* v2d mask is used to subtract scrollbars from a 2d view. Needs initialize here. */
2297 BLI_rcti_init(&region->v2d.mask, 0, region->winx - 1, 0, region->winy - 1);
2298}
2299
2301{
2302 region_update_rect(region);
2303}
2304
2306{
2308
2309 /* refresh can be called before window opened */
2311
2312 region_update_rect(region);
2313}
2314
2316{
2317 if (region != nullptr) {
2318 if ((region->runtime->gizmo_map != nullptr) &&
2319 WM_gizmomap_cursor_set(region->runtime->gizmo_map, win))
2320 {
2321 return;
2322 }
2323 if (area && region->runtime->type && region->runtime->type->cursor) {
2324 region->runtime->type->cursor(win, area, region);
2325 return;
2326 }
2327 }
2328
2329 if (WM_cursor_set_from_tool(win, area, region)) {
2330 return;
2331 }
2332
2334}
2335
2337 bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
2338{
2339 if (is_hidden) {
2340 WM_event_remove_handlers(C, &region->runtime->handlers);
2341 /* Needed to close any open pop-overs which would otherwise remain open,
2342 * crashing on attempting to refresh. See: #93410.
2343 *
2344 * When #ED_area_init frees buttons via #UI_blocklist_free a nullptr context
2345 * is passed, causing the free not to remove menus or their handlers. */
2347 }
2348
2349 if (do_init) {
2350 ED_area_init(C, CTX_wm_window(C), area);
2351 ED_area_tag_redraw(area);
2352 }
2353}
2354
2356{
2357 const bool is_hidden = region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_POLL_FAILED);
2358 const bool do_init = true;
2359 ED_region_visibility_change_update_ex(C, area, region, is_hidden, do_init);
2360}
2361
2362void region_toggle_hidden(bContext *C, ARegion *region, const bool do_fade)
2363{
2364 ScrArea *area = CTX_wm_area(C);
2365
2366 region->flag ^= RGN_FLAG_HIDDEN;
2367
2368 if (do_fade && region->overlap) {
2369 /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */
2371 }
2372 else {
2374 }
2375}
2376
2378{
2379 region_toggle_hidden(C, region, true);
2380}
2381
2382void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
2383{
2384 const char spacetype = area_dst->spacetype;
2385 const short flag_copy = HEADER_NO_PULLDOWN;
2386
2387 area_dst->spacetype = area_src->spacetype;
2388 area_dst->type = area_src->type;
2389
2390 area_dst->flag = (area_dst->flag & ~flag_copy) | (area_src->flag & flag_copy);
2391
2392 /* area */
2393 if (do_free) {
2395 }
2396 BKE_spacedata_copylist(&area_dst->spacedata, &area_src->spacedata);
2397
2398 /* NOTE: SPACE_EMPTY is possible on new screens. */
2399
2400 /* regions */
2401 if (do_free) {
2402 SpaceType *st = BKE_spacetype_from_id(spacetype);
2403 LISTBASE_FOREACH (ARegion *, region, &area_dst->regionbase) {
2404 BKE_area_region_free(st, region);
2405 }
2406 BLI_freelistN(&area_dst->regionbase);
2407 }
2408 SpaceType *st = BKE_spacetype_from_id(area_src->spacetype);
2409 LISTBASE_FOREACH (ARegion *, region, &area_src->regionbase) {
2410 ARegion *newar = BKE_area_region_copy(st, region);
2411 BLI_addtail(&area_dst->regionbase, newar);
2412 }
2413}
2414
2415void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src)
2416{
2417 std::swap(area_dst->spacetype, area_src->spacetype);
2418 std::swap(area_dst->type, area_src->type);
2419
2420 std::swap(area_dst->spacedata, area_src->spacedata);
2421 std::swap(area_dst->regionbase, area_src->regionbase);
2422}
2423
2424/* -------------------------------------------------------------------- */
2427
2436 struct {
2447};
2448
2450{
2451 for (int index = 0; index < RGN_TYPE_NUM; index++) {
2452 r_align_info->by_type[index].alignment = -1;
2453 /* Default to true, when it doesn't exist - it's effectively hidden. */
2454 r_align_info->by_type[index].hidden = true;
2455 }
2456
2457 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2458 if (region->flag & RGN_FLAG_POLL_FAILED) {
2459 continue;
2460 }
2461
2462 const int index = region->regiontype;
2463 if (uint(index) < RGN_TYPE_NUM) {
2464 r_align_info->by_type[index].alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
2465 r_align_info->by_type[index].hidden = (region->flag & RGN_FLAG_HIDDEN) != 0;
2466 }
2467 }
2468}
2469
2478 const RegionTypeAlignInfo *region_align_info, const short fallback)
2479{
2480 const short header_alignment = region_align_info->by_type[RGN_TYPE_HEADER].alignment;
2481 const short tool_header_alignment = region_align_info->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2482
2483 const bool header_hidden = region_align_info->by_type[RGN_TYPE_HEADER].hidden;
2484 const bool tool_header_hidden = region_align_info->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2485
2486 if ((tool_header_alignment != -1) &&
2487 /* If tool-header is hidden, use header alignment. */
2488 ((tool_header_hidden == false) ||
2489 /* Don't prioritize the tool-header if both are hidden (behave as if both are visible).
2490 * Without this, switching to a space with headers hidden will flip the alignment
2491 * upon switching to a space with visible headers. */
2492 (header_hidden && tool_header_hidden)))
2493 {
2494 return tool_header_alignment;
2495 }
2496 if (header_alignment != -1) {
2497 return header_alignment;
2498 }
2499 return fallback;
2500}
2501
2524static void region_align_info_to_area_for_headers(const RegionTypeAlignInfo *region_align_info_src,
2525 const RegionTypeAlignInfo *region_align_info_dst,
2526 ARegion *region_by_type[RGN_TYPE_NUM])
2527{
2528 /* Abbreviate access. */
2529 const short header_alignment_src = region_align_info_src->by_type[RGN_TYPE_HEADER].alignment;
2530 const short tool_header_alignment_src =
2531 region_align_info_src->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2532
2533 const bool tool_header_hidden_src = region_align_info_src->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2534
2535 const short primary_header_alignment_src = region_alignment_from_header_and_tool_header_state(
2536 region_align_info_src, -1);
2537
2538 /* Neither alignments are usable, don't sync. */
2539 if (primary_header_alignment_src == -1) {
2540 return;
2541 }
2542
2543 const short header_alignment_dst = region_align_info_dst->by_type[RGN_TYPE_HEADER].alignment;
2544 const short tool_header_alignment_dst =
2545 region_align_info_dst->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2546 const short footer_alignment_dst = region_align_info_dst->by_type[RGN_TYPE_FOOTER].alignment;
2547
2548 const bool tool_header_hidden_dst = region_align_info_dst->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2549
2550 /* New synchronized alignments to set (or ignore when left as -1). */
2551 short header_alignment_sync = -1;
2552 short tool_header_alignment_sync = -1;
2553 short footer_alignment_sync = -1;
2554
2555 /* Both source/destination areas have same region configurations regarding headers.
2556 * Simply copy the values. */
2557 if (((header_alignment_src != -1) == (header_alignment_dst != -1)) &&
2558 ((tool_header_alignment_src != -1) == (tool_header_alignment_dst != -1)) &&
2559 (tool_header_hidden_src == tool_header_hidden_dst))
2560 {
2561 if (header_alignment_dst != -1) {
2562 header_alignment_sync = header_alignment_src;
2563 }
2564 if (tool_header_alignment_dst != -1) {
2565 tool_header_alignment_sync = tool_header_alignment_src;
2566 }
2567 }
2568 else {
2569 /* Not an exact match, check the space selector isn't moving. */
2570 const short primary_header_alignment_dst = region_alignment_from_header_and_tool_header_state(
2571 region_align_info_dst, -1);
2572
2573 if (primary_header_alignment_src != primary_header_alignment_dst) {
2574 if ((header_alignment_dst != -1) && (tool_header_alignment_dst != -1)) {
2575 if (header_alignment_dst == tool_header_alignment_dst) {
2576 /* Apply to both. */
2577 tool_header_alignment_sync = primary_header_alignment_src;
2578 header_alignment_sync = primary_header_alignment_src;
2579 }
2580 else {
2581 /* Keep on opposite sides. */
2582 tool_header_alignment_sync = primary_header_alignment_src;
2583 header_alignment_sync = (tool_header_alignment_sync == RGN_ALIGN_BOTTOM) ?
2586 }
2587 }
2588 else {
2589 /* Apply what we can to regions that exist. */
2590 if (header_alignment_dst != -1) {
2591 header_alignment_sync = primary_header_alignment_src;
2592 }
2593 if (tool_header_alignment_dst != -1) {
2594 tool_header_alignment_sync = primary_header_alignment_src;
2595 }
2596 }
2597 }
2598 }
2599
2600 if (footer_alignment_dst != -1) {
2601 if ((header_alignment_dst != -1) && (header_alignment_dst == footer_alignment_dst)) {
2602 /* Apply to both. */
2603 footer_alignment_sync = primary_header_alignment_src;
2604 }
2605 else {
2606 /* Keep on opposite sides. */
2607 footer_alignment_sync = (primary_header_alignment_src == RGN_ALIGN_BOTTOM) ?
2610 }
2611 }
2612
2613 /* Finally apply synchronized flags. */
2614 if (header_alignment_sync != -1) {
2615 ARegion *region = region_by_type[RGN_TYPE_HEADER];
2616 if (region != nullptr) {
2617 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(header_alignment_sync) |
2619 }
2620 }
2621
2622 if (tool_header_alignment_sync != -1) {
2623 ARegion *region = region_by_type[RGN_TYPE_TOOL_HEADER];
2624 if (region != nullptr) {
2625 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(tool_header_alignment_sync) |
2627 }
2628 }
2629
2630 if (footer_alignment_sync != -1) {
2631 ARegion *region = region_by_type[RGN_TYPE_FOOTER];
2632 if (region != nullptr) {
2633 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(footer_alignment_sync) |
2635 }
2636 }
2637}
2638
2640 ScrArea *area, const RegionTypeAlignInfo region_align_info_src[RGN_TYPE_NUM])
2641{
2642 ARegion *region_by_type[RGN_TYPE_NUM] = {nullptr};
2643 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
2644 const int index = region->regiontype;
2645 if (uint(index) < RGN_TYPE_NUM) {
2646 region_by_type[index] = region;
2647 }
2648 }
2649
2650 RegionTypeAlignInfo region_align_info_dst;
2651 region_align_info_from_area(area, &region_align_info_dst);
2652
2653 if ((region_by_type[RGN_TYPE_HEADER] != nullptr) ||
2654 (region_by_type[RGN_TYPE_TOOL_HEADER] != nullptr))
2655 {
2657 region_align_info_src, &region_align_info_dst, region_by_type);
2658 }
2659
2660 /* Note that we could support other region types. */
2661}
2662
2664
2665/* *********** Space switching code *********** */
2666
2668{
2669 ScrArea *tmp = MEM_callocN<ScrArea>(__func__);
2670 wmWindow *win = CTX_wm_window(C);
2671
2672 ED_area_exit(C, sa1);
2673 ED_area_exit(C, sa2);
2674
2675 ED_area_data_copy(tmp, sa1, false);
2676 ED_area_data_copy(sa1, sa2, true);
2677 ED_area_data_copy(sa2, tmp, true);
2678 ED_area_init(C, win, sa1);
2679 ED_area_init(C, win, sa2);
2680
2682 MEM_delete(tmp);
2683
2684 /* tell WM to refresh, cursor types etc */
2686
2687 ED_area_tag_redraw(sa1);
2689 ED_area_tag_redraw(sa2);
2691}
2692
2693void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_region_exit)
2694{
2695 wmWindow *win = CTX_wm_window(C);
2696 SpaceType *st = BKE_spacetype_from_id(type);
2697
2698 if (area->spacetype != type) {
2699 SpaceLink *slold = static_cast<SpaceLink *>(area->spacedata.first);
2700 /* store area->type->exit callback */
2701 void (*area_exit)(wmWindowManager *, ScrArea *) = area->type ? area->type->exit : nullptr;
2702 /* When the user switches between space-types from the type-selector,
2703 * changing the header-type is jarring (especially when using Ctrl-MouseWheel).
2704 *
2705 * However, add-on install for example, forces the header to the top which shouldn't
2706 * be applied back to the previous space type when closing - see: #57724
2707 *
2708 * Newly-created windows won't have any space data, use the alignment
2709 * the space type defaults to in this case instead
2710 * (needed for preferences to have space-type on bottom).
2711 */
2712
2713 bool sync_header_alignment = false;
2714 RegionTypeAlignInfo region_align_info[RGN_TYPE_NUM];
2715 if ((slold != nullptr) && (slold->link_flag & SPACE_FLAG_TYPE_TEMPORARY) == 0) {
2716 region_align_info_from_area(area, region_align_info);
2717 sync_header_alignment = true;
2718 }
2719
2720 /* in some cases (opening temp space) we don't want to
2721 * call area exit callback, so we temporarily unset it */
2722 if (skip_region_exit && area->type) {
2723 area->type->exit = nullptr;
2724 }
2725
2726 ED_area_exit(C, area);
2727
2728 /* restore old area exit callback */
2729 if (skip_region_exit && area->type) {
2730 area->type->exit = area_exit;
2731 }
2732
2733 area->spacetype = type;
2734 area->type = st;
2735
2736 /* If st->create may be called, don't use context until then. The
2737 * area->type->context() callback has changed but data may be invalid
2738 * (e.g. with properties editor) until space-data is properly created */
2739
2740 /* check previously stored space */
2741 SpaceLink *sl = nullptr;
2742 LISTBASE_FOREACH (SpaceLink *, sl_iter, &area->spacedata) {
2743 if (sl_iter->spacetype == type) {
2744 sl = sl_iter;
2745 break;
2746 }
2747 }
2748
2749 /* old spacedata... happened during work on 2.50, remove */
2750 if (sl && BLI_listbase_is_empty(&sl->regionbase)) {
2751 st->free(sl);
2752 BLI_freelinkN(&area->spacedata, sl);
2753 if (slold == sl) {
2754 slold = nullptr;
2755 }
2756 sl = nullptr;
2757 }
2758
2759 if (sl) {
2760 /* swap regions */
2761 slold->regionbase = area->regionbase;
2762 area->regionbase = sl->regionbase;
2764 /* SPACE_FLAG_TYPE_WAS_ACTIVE is only used to go back to a previously active space that is
2765 * overlapped by temporary ones. It's now properly activated, so the flag should be cleared
2766 * at this point. */
2768
2769 /* put in front of list */
2770 BLI_remlink(&area->spacedata, sl);
2771 BLI_addhead(&area->spacedata, sl);
2772 }
2773 else {
2774 /* new space */
2775 if (st) {
2776 /* Don't get scene from context here which may depend on space-data. */
2777 Scene *scene = WM_window_get_active_scene(win);
2778 sl = st->create(area, scene);
2779 BLI_addhead(&area->spacedata, sl);
2780
2781 /* swap regions */
2782 if (slold) {
2783 slold->regionbase = area->regionbase;
2784 }
2785 area->regionbase = sl->regionbase;
2787 }
2788 }
2789
2790 /* Sync header alignment. */
2791 if (sync_header_alignment) {
2792 region_align_info_to_area(area, region_align_info);
2793 }
2794
2795 ED_area_init(C, win, area);
2796
2797 /* tell WM to refresh, cursor types etc */
2799
2800 /* send space change notifier */
2802
2803 ED_area_tag_refresh(area);
2804 }
2805
2806 /* Set area space subtype if applicable. */
2807 if (st && st->space_subtype_item_extend != nullptr) {
2808 if (area->butspacetype_subtype == -1) {
2809 /* Indication (probably from space_type_set_or_cycle) to ignore the
2810 * area's current subtype and use last-used, as saved in the space. */
2811 area->butspacetype_subtype = st->space_subtype_get(area);
2812 }
2813 st->space_subtype_set(area, area->butspacetype_subtype);
2814 }
2815
2816 /* Whether setting a subtype or not we need to clear this value. Not just unneeded
2817 * but can interfere with the next change. Operations can change the type without
2818 * specifying a subtype (assumed zero) and we don't want to use the old subtype. */
2819 area->butspacetype_subtype = 0;
2820
2821 if (BLI_listbase_is_single(&CTX_wm_screen(C)->areabase)) {
2822 /* If there is only one area update the window title. */
2824 }
2825
2826 /* See #WM_capabilities_flag code-comments for details on the background check. */
2827 if (!G.background) {
2828 /* If window decoration styles are supported, send a notification to re-apply them. */
2831 }
2832 }
2833
2834 /* also redraw when re-used */
2835 ED_area_tag_redraw(area);
2836}
2837
2839{
2840 SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
2841
2842 /* First toggle to the next temporary space in the list. */
2843 for (SpaceLink *sl_iter = sl->next; sl_iter; sl_iter = sl_iter->next) {
2844 if (sl_iter->link_flag & SPACE_FLAG_TYPE_TEMPORARY) {
2845 return sl_iter;
2846 }
2847 }
2848
2849 /* No temporary space, find the item marked as last active. */
2850 for (SpaceLink *sl_iter = sl->next; sl_iter; sl_iter = sl_iter->next) {
2851 if (sl_iter->link_flag & SPACE_FLAG_TYPE_WAS_ACTIVE) {
2852 return sl_iter;
2853 }
2854 }
2855
2856 /* If neither is found, we can just return to the regular previous one. */
2857 return sl->next;
2858}
2859
2861{
2862 SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
2863 SpaceLink *prevspace = sl ? area_get_prevspace(area) : nullptr;
2864
2865 if (prevspace) {
2866 /* Specify that we want last-used if there are subtypes. */
2867 area->butspacetype_subtype = -1;
2868 ED_area_newspace(C, area, prevspace->spacetype, false);
2869 /* We've exited the space, so it can't be considered temporary anymore. */
2871 }
2872 else {
2873 /* no change */
2874 return;
2875 }
2876 /* If this is a stacked full-screen, changing to previous area exits it (meaning we're still in a
2877 * full-screen, but not in a stacked one). */
2879
2880 ED_area_tag_redraw(area);
2881
2882 /* send space change notifier */
2884}
2885
2886int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
2887{
2888 ScrArea *area = CTX_wm_area(C);
2889 bScreen *screen = CTX_wm_screen(C);
2890 int xco = 0.4 * U.widget_unit;
2891
2892 PointerRNA areaptr = RNA_pointer_create_discrete(&(screen->id), &RNA_Area, area);
2893
2894 uiDefButR(block,
2896 0,
2897 "",
2898 xco,
2899 yco,
2900 1.6 * U.widget_unit,
2901 U.widget_unit,
2902 &areaptr,
2903 "ui_type",
2904 0,
2905 0.0f,
2906 0.0f,
2907 "");
2908
2909 return xco + 1.7 * U.widget_unit;
2910}
2911
2912/************************ standard UI regions ************************/
2913
2914static ThemeColorID region_background_color_id(const bContext * /*C*/, const ARegion *region)
2915{
2916 switch (region->regiontype) {
2917 case RGN_TYPE_HEADER:
2919 return TH_HEADER;
2920 case RGN_TYPE_PREVIEW:
2921 return TH_PREVIEW_BACK;
2922 default:
2923 return TH_BACK;
2924 }
2925}
2926
2927void ED_region_clear(const bContext *C, const ARegion *region, const int /*ThemeColorID*/ colorid)
2928{
2929 if (region->overlap) {
2930 /* view should be in pixelspace */
2932
2933 float back[4];
2934 UI_GetThemeColor4fv(colorid, back);
2935 GPU_clear_color(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
2936 }
2937 else {
2938 UI_ThemeClearColor(colorid);
2939 }
2940}
2941
2943{
2944 /* view should be in pixelspace */
2946
2947 GPU_clear_color(0, 0, 0, 0);
2948}
2949
2950BLI_INLINE bool streq_array_any(const char *s, const char *arr[])
2951{
2952 for (uint i = 0; arr[i]; i++) {
2953 if (STREQ(arr[i], s)) {
2954 return true;
2955 }
2956 }
2957 return false;
2958}
2959
2969static void ed_panel_draw(const bContext *C,
2970 ARegion *region,
2971 ListBase *lb,
2972 PanelType *pt,
2973 Panel *panel,
2974 int w,
2975 int em,
2976 char *unique_panel_str,
2977 const char *search_filter,
2978 wmOperatorCallContext op_context)
2979{
2980 const uiStyle *style = UI_style_get_dpi();
2981
2982 /* Draw panel. */
2984 if (unique_panel_str) {
2985 /* Instanced panels should have already been added at this point. */
2986 BLI_string_join(block_name, sizeof(block_name), pt->idname, unique_panel_str);
2987 }
2988 else {
2989 STRNCPY(block_name, pt->idname);
2990 }
2991 uiBlock *block = UI_block_begin(C, region, block_name, blender::ui::EmbossType::Emboss);
2992
2993 bool open;
2994 panel = UI_panel_begin(region, lb, block, pt, panel, &open);
2995 panel->runtime->layout_panels.clear();
2996
2997 const bool search_filter_active = search_filter != nullptr && search_filter[0] != '\0';
2998
2999 /* bad fixed values */
3000 int xco, yco, h = 0;
3001 int headerend = w - UI_UNIT_X;
3002
3004 if (pt->draw_header_preset && !(pt->flag & PANEL_TYPE_NO_HEADER)) {
3005 /* for preset menu */
3006 panel->layout = UI_block_layout(block,
3009 0,
3010 (UI_UNIT_Y * 1.1f) + style->panelspace,
3011 UI_UNIT_Y,
3012 1,
3013 0,
3014 style);
3015
3016 uiLayoutSetOperatorContext(panel->layout, op_context);
3017
3018 pt->draw_header_preset(C, panel);
3019
3020 UI_block_apply_search_filter(block, search_filter);
3021 UI_block_layout_resolve(block, &xco, &yco);
3022 UI_block_translate(block, headerend - xco, 0);
3023 panel->layout = nullptr;
3024 }
3025
3026 if (pt->draw_header && !(pt->flag & PANEL_TYPE_NO_HEADER)) {
3027 int labelx, labely;
3028 UI_panel_label_offset(block, &labelx, &labely);
3029
3030 /* Unusual case: Use expanding layout (buttons stretch to available width). */
3031 if (pt->flag & PANEL_TYPE_HEADER_EXPAND) {
3032 uiLayout *layout = UI_block_layout(block,
3035 labelx,
3036 labely,
3037 headerend - 2 * style->panelspace,
3038 1,
3039 0,
3040 style);
3041 panel->layout = &layout->row(false);
3042 }
3043 /* Regular case: Normal panel with fixed size buttons. */
3044 else {
3045 panel->layout = UI_block_layout(
3046 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style);
3047 }
3048
3049 uiLayoutSetOperatorContext(panel->layout, op_context);
3050
3051 pt->draw_header(C, panel);
3052
3053 UI_block_apply_search_filter(block, search_filter);
3054 UI_block_layout_resolve(block, &xco, &yco);
3055 panel->labelofs = xco - labelx;
3056 panel->layout = nullptr;
3057 }
3058 else {
3059 panel->labelofs = 0;
3060 }
3062
3063 if (open || search_filter_active) {
3064 short panelContext;
3065
3066 /* panel context can either be toolbar region or normal panels region */
3067 if (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) {
3068 panelContext = UI_LAYOUT_VERT_BAR;
3069 }
3070 else if (region->regiontype == RGN_TYPE_TOOLS) {
3071 panelContext = UI_LAYOUT_TOOLBAR;
3072 }
3073 else {
3074 panelContext = UI_LAYOUT_PANEL;
3075 }
3076
3077 panel->layout = UI_block_layout(
3078 block,
3080 panelContext,
3081 (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) ? 0 : style->panelspace,
3082 0,
3083 (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) ? 0 : w - 2 * style->panelspace,
3084 em,
3085 0,
3086 style);
3087
3088 uiLayoutSetOperatorContext(panel->layout, op_context);
3089
3090 pt->draw(C, panel);
3091
3092 const bool ends_with_layout_panel_header = uiLayoutEndsWithPanelHeader(*panel->layout);
3093
3094 UI_block_apply_search_filter(block, search_filter);
3095 UI_block_layout_resolve(block, &xco, &yco);
3096 panel->layout = nullptr;
3097
3098 if (yco != 0) {
3099 h = -yco;
3100 h += style->panelspace;
3101 if (!ends_with_layout_panel_header) {
3102 /* Last layout panel header ends together with the panel. */
3103 h += style->panelspace;
3104 }
3105 }
3106 }
3107
3108 UI_block_end(C, block);
3109
3110 /* Draw child panels. */
3111 if (open || search_filter_active) {
3112 LISTBASE_FOREACH (LinkData *, link, &pt->children) {
3113 PanelType *child_pt = static_cast<PanelType *>(link->data);
3114 Panel *child_panel = UI_panel_find_by_type(&panel->children, child_pt);
3115
3116 if (child_pt->draw && (!child_pt->poll || child_pt->poll(C, child_pt))) {
3118 region,
3119 &panel->children,
3120 child_pt,
3121 child_panel,
3122 w,
3123 em,
3124 unique_panel_str,
3125 search_filter,
3126 op_context);
3127 }
3128 }
3129 }
3130
3131 UI_panel_end(panel, w, h);
3132}
3133
3137static bool panel_add_check(const bContext *C,
3138 const WorkSpace *workspace,
3139 const char *contexts[],
3140 const char *category_override,
3141 PanelType *panel_type)
3142{
3143 /* Only add top level panels. */
3144 if (panel_type->parent) {
3145 return false;
3146 }
3147 /* Check the category override first. */
3148 if (category_override) {
3149 if (!STREQ(panel_type->category, category_override)) {
3150 return false;
3151 }
3152 }
3153
3154 /* Verify context. */
3155 if (contexts != nullptr && panel_type->context[0]) {
3156 if (!streq_array_any(panel_type->context, contexts)) {
3157 return false;
3158 }
3159 }
3160
3161 /* If we're tagged, only use compatible. */
3162 if (panel_type->owner_id[0]) {
3163 if (!BKE_workspace_owner_id_check(workspace, panel_type->owner_id)) {
3164 return false;
3165 }
3166 }
3167
3168 if (LIKELY(panel_type->draw)) {
3169 if (panel_type->poll && !panel_type->poll(C, panel_type)) {
3170 return false;
3171 }
3172 }
3173
3174 return true;
3175}
3176
3177static bool region_uses_category_tabs(const ScrArea *area, const ARegion *region)
3178{
3179 /* XXX, should use some better check? */
3180 /* For now also has hardcoded check for clip editor until it supports actual toolbar. */
3181 return ((1 << region->regiontype) & RGN_TYPE_HAS_CATEGORY_MASK) ||
3182 (region->regiontype == RGN_TYPE_TOOLS && area->spacetype == SPACE_CLIP);
3183}
3184
3186 LinkNode *panel_types_stack,
3187 bool *use_category_tabs)
3188{
3190
3191 /* gather unique categories */
3192 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
3193 PanelType *pt = static_cast<PanelType *>(pt_link->link);
3194 if (pt->category[0]) {
3195 if (!UI_panel_category_find(region, pt->category)) {
3196 UI_panel_category_add(region, pt->category);
3197 }
3198 }
3199 }
3200
3201 if (UI_panel_category_is_visible(region)) {
3202 return UI_panel_category_active_get(region, true);
3203 }
3204
3205 *use_category_tabs = false;
3206 return nullptr;
3207}
3208
3210 const PanelType *panel_type,
3211 const int max_width)
3212{
3213 /* With a background, we want some extra padding. */
3214 return UI_panel_should_show_background(region, panel_type) ?
3215 max_width - UI_PANEL_MARGIN_X * 2.0f :
3216 max_width;
3217}
3218
3220 ARegion *region,
3221 ListBase *paneltypes,
3222 wmOperatorCallContext op_context,
3223 const char *contexts[],
3224 const char *category_override)
3225{
3226 /* collect panels to draw */
3227 WorkSpace *workspace = CTX_wm_workspace(C);
3228 LinkNode *panel_types_stack = nullptr;
3229 LISTBASE_FOREACH_BACKWARD (PanelType *, pt, paneltypes) {
3230 if (panel_add_check(C, workspace, contexts, category_override, pt)) {
3231 BLI_linklist_prepend_alloca(&panel_types_stack, pt);
3232 }
3233 }
3234
3235 region->runtime->category = nullptr;
3236
3237 ScrArea *area = CTX_wm_area(C);
3238 View2D *v2d = &region->v2d;
3239
3240 bool use_category_tabs = (category_override == nullptr) &&
3241 region_uses_category_tabs(area, region);
3242 /* offset panels for small vertical tab area */
3243 const char *category = nullptr;
3244 const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH;
3245 int margin_x = 0;
3246 const bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE;
3247 bool update_tot_size = true;
3248
3249 /* only allow scrolling in vertical direction */
3251 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
3252 v2d->scroll &= ~V2D_SCROLL_BOTTOM;
3253
3254 if (region->alignment & RGN_ALIGN_LEFT) {
3255 region->v2d.scroll &= ~V2D_SCROLL_RIGHT;
3256 region->v2d.scroll |= V2D_SCROLL_LEFT;
3257 }
3258 else {
3259 region->v2d.scroll &= ~V2D_SCROLL_LEFT;
3260 region->v2d.scroll |= V2D_SCROLL_RIGHT;
3261 }
3262
3263 /* collect categories */
3264 if (use_category_tabs) {
3265 category = region_panels_collect_categories(region, panel_types_stack, &use_category_tabs);
3266 }
3267 if (use_category_tabs) {
3268 margin_x = category_tabs_width;
3269 }
3270
3271 const int max_panel_width = BLI_rctf_size_x(&v2d->cur) - margin_x;
3272 /* Works out to 10 * UI_UNIT_X or 20 * UI_UNIT_X. */
3273 const int em = (region->runtime->type->prefsizex) ? 10 : 20;
3274
3275 /* create panels */
3276 UI_panels_begin(C, region);
3277
3278 /* Get search string for property search. */
3279 const char *search_filter = ED_area_region_search_filter_get(area, region);
3280
3281 /* set view2d view matrix - UI_block_begin() stores it */
3283
3284 bool has_instanced_panel = false;
3285 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
3286 PanelType *pt = static_cast<PanelType *>(pt_link->link);
3287
3288 if (pt->flag & PANEL_TYPE_INSTANCED) {
3289 has_instanced_panel = true;
3290 continue;
3291 }
3292 Panel *panel = UI_panel_find_by_type(&region->panels, pt);
3293
3294 if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
3295 if ((panel == nullptr) || ((panel->flag & PNL_PIN) == 0)) {
3296 continue;
3297 }
3298 }
3299 const int width = panel_draw_width_from_max_width_get(region, pt, max_panel_width);
3300
3301 if (panel && UI_panel_is_dragging(panel)) {
3302 /* Prevent View2d.tot rectangle size changes while dragging panels. */
3303 update_tot_size = false;
3304 }
3305
3307 C, region, &region->panels, pt, panel, width, em, nullptr, search_filter, op_context);
3308 }
3309
3310 /* Draw "poly-instantiated" panels that don't have a 1 to 1 correspondence with their types. */
3311 if (has_instanced_panel) {
3312 LISTBASE_FOREACH (Panel *, panel, &region->panels) {
3313 if (panel->type == nullptr) {
3314 continue; /* Some panels don't have a type. */
3315 }
3316 if (!(panel->type->flag & PANEL_TYPE_INSTANCED)) {
3317 continue;
3318 }
3319 if (use_category_tabs && panel->type->category[0] && !STREQ(category, panel->type->category))
3320 {
3321 continue;
3322 }
3323 if (!panel_add_check(C, workspace, contexts, category_override, panel->type)) {
3324 continue;
3325 }
3326
3327 const int width = panel_draw_width_from_max_width_get(region, panel->type, max_panel_width);
3328
3329 if (UI_panel_is_dragging(panel)) {
3330 /* Prevent View2d.tot rectangle size changes while dragging panels. */
3331 update_tot_size = false;
3332 }
3333
3334 /* Use a unique identifier for instanced panels, otherwise an old block for a different
3335 * panel of the same type might be found. */
3336 char unique_panel_str[INSTANCED_PANEL_UNIQUE_STR_SIZE];
3337 UI_list_panel_unique_str(panel, unique_panel_str);
3339 region,
3340 &region->panels,
3341 panel->type,
3342 panel,
3343 width,
3344 em,
3345 unique_panel_str,
3346 search_filter,
3347 op_context);
3348 }
3349 }
3350
3351 /* align panels and return size */
3352 int x, y;
3353 UI_panels_end(C, region, &x, &y);
3354
3355 /* before setting the view */
3356 if (region_layout_based) {
3357 /* XXX, only single panel support at the moment.
3358 * Can't use x/y values calculated above because they're not using the real height of panels,
3359 * instead they calculate offsets for the next panel to start drawing. */
3360 Panel *panel = static_cast<Panel *>(region->panels.last);
3361 if (panel != nullptr) {
3362 const int size_dyn[2] = {
3363 int(UI_UNIT_X * (UI_panel_is_closed(panel) ? 8 : 14) / UI_SCALE_FAC),
3364 int(UI_panel_size_y(panel) / UI_SCALE_FAC),
3365 };
3366 /* region size is layout based and needs to be updated */
3367 if ((region->sizex != size_dyn[0]) || (region->sizey != size_dyn[1])) {
3368 region->sizex = size_dyn[0];
3369 region->sizey = size_dyn[1];
3370 ED_area_tag_region_size_update(area, region);
3371 }
3372 y = fabsf(region->sizey * UI_SCALE_FAC - 1);
3373 }
3374 }
3375 else {
3376 /* We always keep the scroll offset -
3377 * so the total view gets increased with the scrolled away part. */
3378 if (v2d->cur.ymax < -FLT_EPSILON) {
3379 /* Clamp to lower view boundary */
3380 if (v2d->tot.ymin < -v2d->winy) {
3381 y = min_ii(y, 0);
3382 }
3383 else {
3384 y = min_ii(y, v2d->cur.ymin);
3385 }
3386 }
3387
3388 y = -y;
3389 }
3390
3391 UI_blocklist_update_view_for_buttons(C, &region->runtime->uiblocks);
3392
3393 if (update_tot_size) {
3394 /* this also changes the 'cur' */
3395 UI_view2d_totRect_set(v2d, x, y);
3396 }
3397
3398 if (use_category_tabs) {
3399 region->runtime->category = category;
3400 }
3401}
3402
3404{
3406 C, region, &region->runtime->type->paneltypes, WM_OP_INVOKE_REGION_WIN, nullptr, nullptr);
3407}
3408
3410{
3411 View2D *v2d = &region->v2d;
3412
3413 if (region->alignment != RGN_ALIGN_FLOAT) {
3415 region,
3416 (region->runtime->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK :
3417 TH_BACK);
3418 }
3419
3420 /* reset line width for drawing tabs */
3421 GPU_line_width(1.0f);
3422
3423 /* set the view */
3425
3426 /* View2D matrix might have changed due to dynamic sized regions. */
3427 UI_blocklist_update_window_matrix(C, &region->runtime->uiblocks);
3428
3429 /* draw panels */
3430 UI_panels_draw(C, region);
3431
3432 /* restore view matrix */
3434
3435 /* Set in layout. */
3436 if (region->runtime->category) {
3437 UI_panel_category_draw_all(region, region->runtime->category);
3438 }
3439
3440 /* scrollers */
3441 bool use_mask = false;
3442 rcti mask;
3443 if (region->runtime->category &&
3446 {
3447 use_mask = true;
3449 mask.xmax -= round_fl_to_int(UI_view2d_scale_get_x(&region->v2d) *
3451 }
3452 UI_view2d_scrollers_draw(v2d, use_mask ? &mask : nullptr);
3453}
3454
3456 ARegion *region,
3457 wmOperatorCallContext op_context,
3458 const char *contexts[])
3459{
3460 /* TODO: remove? */
3462 C, region, &region->runtime->type->paneltypes, op_context, contexts, nullptr);
3463 ED_region_panels_draw(C, region);
3464}
3465
3466void ED_region_panels(const bContext *C, ARegion *region)
3467{
3468 /* TODO: remove? */
3469 ED_region_panels_layout(C, region);
3470 ED_region_panels_draw(C, region);
3471}
3472
3474{
3475 UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_PANELS_UI, region->winx, region->winy);
3476
3477 /* Place scroll bars to the left if left-aligned, right if right-aligned. */
3478 if (region->alignment & RGN_ALIGN_LEFT) {
3479 region->v2d.scroll &= ~V2D_SCROLL_RIGHT;
3480 region->v2d.scroll |= V2D_SCROLL_LEFT;
3481 }
3482 else if (region->alignment & RGN_ALIGN_RIGHT) {
3483 region->v2d.scroll &= ~V2D_SCROLL_LEFT;
3484 region->v2d.scroll |= V2D_SCROLL_RIGHT;
3485 }
3486
3487 wmKeyMap *keymap = WM_keymap_ensure(
3488 wm->defaultconf, "View2D Buttons List", SPACE_EMPTY, RGN_TYPE_WINDOW);
3489 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
3490}
3491
3499 ARegion *region,
3500 const uiStyle *style,
3501 Panel *panel,
3502 PanelType *panel_type,
3503 const char *search_filter)
3504{
3505 uiBlock *block = UI_block_begin(C, region, panel_type->idname, blender::ui::EmbossType::Emboss);
3506 UI_block_set_search_only(block, true);
3507
3508 /* Skip panels that give meaningless search results. */
3509 if (panel_type->flag & PANEL_TYPE_NO_SEARCH) {
3510 return false;
3511 }
3512
3513 if (panel == nullptr) {
3514 bool open; /* Dummy variable. */
3515 panel = UI_panel_begin(region, &region->panels, block, panel_type, panel, &open);
3516 }
3517
3518 /* Build the layouts. Because they are only used for search,
3519 * they don't need any of the proper style or layout information. */
3520 if (panel->type->draw_header_preset != nullptr) {
3521 panel->layout = UI_block_layout(
3522 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, 0, 0, 0, 0, 0, style);
3523 panel_type->draw_header_preset(C, panel);
3524 }
3525 if (panel->type->draw_header != nullptr) {
3526 panel->layout = UI_block_layout(
3527 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, 0, 0, 0, 0, 0, style);
3528 panel_type->draw_header(C, panel);
3529 }
3530 if (LIKELY(panel->type->draw != nullptr)) {
3531 panel->layout = UI_block_layout(
3532 block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 0, 0, 0, style);
3533 panel_type->draw(C, panel);
3534 }
3535
3536 UI_block_layout_free(block);
3537
3538 /* We could check after each layout to increase the likelihood of returning early,
3539 * but that probably wouldn't make much of a difference anyway. */
3540 if (UI_block_apply_search_filter(block, search_filter)) {
3541 return true;
3542 }
3543
3544 LISTBASE_FOREACH (LinkData *, link, &panel_type->children) {
3545 PanelType *panel_type_child = static_cast<PanelType *>(link->data);
3546 if (!panel_type_child->poll || panel_type_child->poll(C, panel_type_child)) {
3547 /* Search for the existing child panel here because it might be an instanced
3548 * child panel with a custom data field that will be needed to build the layout. */
3549 Panel *child_panel = UI_panel_find_by_type(&panel->children, panel_type_child);
3550 if (panel_property_search(C, region, style, child_panel, panel_type_child, search_filter)) {
3551 return true;
3552 }
3553 }
3554 }
3555
3556 return false;
3557}
3558
3560 ARegion *region,
3561 ListBase *paneltypes,
3562 const char *contexts[],
3563 const char *category_override)
3564{
3565 ScrArea *area = CTX_wm_area(C);
3566 WorkSpace *workspace = CTX_wm_workspace(C);
3567 const uiStyle *style = UI_style_get_dpi();
3568 const char *search_filter = ED_area_region_search_filter_get(area, region);
3569
3570 LinkNode *panel_types_stack = nullptr;
3571 LISTBASE_FOREACH_BACKWARD (PanelType *, pt, paneltypes) {
3572 if (panel_add_check(C, workspace, contexts, category_override, pt)) {
3573 BLI_linklist_prepend_alloca(&panel_types_stack, pt);
3574 }
3575 }
3576
3577 const char *category = nullptr;
3578 bool use_category_tabs = (category_override == nullptr) &&
3579 region_uses_category_tabs(area, region);
3580 if (use_category_tabs) {
3581 category = region_panels_collect_categories(region, panel_types_stack, &use_category_tabs);
3582 }
3583
3584 /* Run property search for each panel, stopping if a result is found. */
3585 bool has_result = true;
3586 bool has_instanced_panel = false;
3587 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
3588 PanelType *panel_type = static_cast<PanelType *>(pt_link->link);
3589 /* Note that these checks are duplicated from #ED_region_panels_layout_ex. */
3590 if (panel_type->flag & PANEL_TYPE_INSTANCED) {
3591 has_instanced_panel = true;
3592 continue;
3593 }
3594
3595 if (use_category_tabs) {
3596 if (panel_type->category[0] && !STREQ(category, panel_type->category)) {
3597 continue;
3598 }
3599 }
3600
3601 /* We start property search with an empty panel list, so there's
3602 * no point in trying to find an existing panel with this type. */
3603 has_result = panel_property_search(C, region, style, nullptr, panel_type, search_filter);
3604 if (has_result) {
3605 break;
3606 }
3607 }
3608
3609 /* Run property search for instanced panels (created in the layout calls of previous panels). */
3610 if (!has_result && has_instanced_panel) {
3611 LISTBASE_FOREACH (Panel *, panel, &region->panels) {
3612 /* Note that these checks are duplicated from #ED_region_panels_layout_ex. */
3613 if (panel->type == nullptr || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
3614 continue;
3615 }
3616 if (use_category_tabs) {
3617 if (panel->type->category[0] && !STREQ(category, panel->type->category)) {
3618 continue;
3619 }
3620 }
3621
3622 has_result = panel_property_search(C, region, style, panel, panel->type, search_filter);
3623 if (has_result) {
3624 break;
3625 }
3626 }
3627 }
3628
3629 /* Free the panels and blocks, as they are only used for search. */
3630 UI_blocklist_free(C, region);
3631 UI_panels_free_instanced(C, region);
3633
3634 return has_result;
3635}
3636
3638{
3639 const uiStyle *style = UI_style_get_dpi();
3640 bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE;
3641
3642 /* Height of buttons and scaling needed to achieve it. */
3643 const int buttony = min_ii(UI_UNIT_Y, region->winy - 2 * UI_SCALE_FAC);
3644 const float buttony_scale = buttony / float(UI_UNIT_Y);
3645
3646 /* Vertically center buttons. */
3647 int xco = int(UI_HEADER_OFFSET);
3648 int yco = buttony + (region->winy - buttony) / 2;
3649 int maxco = xco;
3650
3651 /* set view2d view matrix for scrolling (without scrollers) */
3652 UI_view2d_view_ortho(&region->v2d);
3653
3654 /* draw all headers types */
3655 LISTBASE_FOREACH (HeaderType *, ht, &region->runtime->type->headertypes) {
3656 if (ht->poll && !ht->poll(C, ht)) {
3657 continue;
3658 }
3659
3660 uiBlock *block = UI_block_begin(C, region, ht->idname, blender::ui::EmbossType::Emboss);
3661 uiLayout *layout = UI_block_layout(
3662 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, buttony, 1, 0, style);
3663
3664 if (buttony_scale != 1.0f) {
3665 uiLayoutSetScaleY(layout, buttony_scale);
3666 }
3667
3668 Header header = {nullptr};
3669 if (ht->draw) {
3670 header.type = ht;
3671 header.layout = layout;
3672 ht->draw(C, &header);
3673 if (ht->next) {
3674 layout->separator();
3675 }
3676
3677 /* for view2d */
3678 xco = uiLayoutGetWidth(layout);
3679 maxco = std::max(xco, maxco);
3680 }
3681
3682 UI_block_layout_resolve(block, &xco, &yco);
3683
3684 /* for view2d */
3685 maxco = std::max(xco, maxco);
3686
3687 int new_sizex = (maxco + UI_HEADER_OFFSET) / UI_SCALE_FAC;
3688
3689 if (region_layout_based && (region->sizex != new_sizex)) {
3690 /* region size is layout based and needs to be updated */
3691 ScrArea *area = CTX_wm_area(C);
3692
3693 region->sizex = new_sizex;
3694 ED_area_tag_region_size_update(area, region);
3695 }
3696
3697 UI_block_end(C, block);
3698
3699 /* In most cases there is only ever one header, it never makes sense to draw more than one
3700 * header in the same region, this results in overlapping buttons, see: #60195. */
3701 break;
3702 }
3703
3704 if (!region_layout_based) {
3705 maxco += UI_HEADER_OFFSET;
3706 }
3707
3708 /* Always as last. */
3709 UI_view2d_totRect_set(&region->v2d, maxco, region->winy);
3710
3711 /* Restore view matrix. */
3713}
3714
3715static void region_draw_blocks_in_view2d(const bContext *C, const ARegion *region)
3716{
3717 UI_view2d_view_ortho(&region->v2d);
3718
3719 /* View2D matrix might have changed due to dynamic sized regions. */
3720 UI_blocklist_update_window_matrix(C, &region->runtime->uiblocks);
3721
3722 /* draw blocks */
3723 UI_blocklist_draw(C, &region->runtime->uiblocks);
3724
3725 /* restore view matrix */
3727}
3728
3730{
3731 /* clear */
3732 ED_region_clear(C, region, region_background_color_id(C, region));
3734}
3735
3737 const ARegion *region,
3738 const uiButtonSectionsAlign align)
3739{
3740 const ThemeColorID bgcolorid = region_background_color_id(C, region);
3741
3742 /* Clear and draw button sections background when using region overlap. Otherwise clear using the
3743 * background color like normal. */
3744 if (region->overlap) {
3746 UI_region_button_sections_draw(region, bgcolorid, align);
3747 }
3748 else {
3749 ED_region_clear(C, region, bgcolorid);
3750 }
3752}
3753
3754void ED_region_header(const bContext *C, ARegion *region)
3755{
3756 /* TODO: remove? */
3757 ED_region_header_layout(C, region);
3758 ED_region_header_draw(C, region);
3759}
3760
3762 ARegion *region,
3763 const uiButtonSectionsAlign align)
3764{
3765 ED_region_header_layout(C, region);
3767}
3768
3770{
3771 UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_HEADER, region->winx, region->winy);
3772}
3773
3775{
3776 /* Accommodate widget and padding. */
3777 return U.widget_unit + int(UI_SCALE_FAC * HEADER_PADDING_Y);
3778}
3779
3781{
3782 return ED_area_headersize();
3783}
3784
3786{
3789}
3791{
3794}
3796{
3799}
3800
3802{
3803 return area->global != nullptr;
3804}
3805
3806ScrArea *ED_area_find_under_cursor(const bContext *C, int spacetype, const int event_xy[2])
3807{
3808 bScreen *screen = CTX_wm_screen(C);
3809 wmWindow *win = CTX_wm_window(C);
3810
3811 ScrArea *area = nullptr;
3812
3813 if (win->parent) {
3814 /* If active window is a child, check itself first. */
3815 area = BKE_screen_find_area_xy(screen, spacetype, event_xy);
3816 }
3817
3818 if (!area) {
3819 /* Check all windows except the active one. */
3820 int event_xy_other[2];
3821 wmWindow *win_other = WM_window_find_under_cursor(win, event_xy, event_xy_other);
3822 if (win_other && win_other != win) {
3823 win = win_other;
3824 screen = WM_window_get_active_screen(win);
3825 area = BKE_screen_find_area_xy(screen, spacetype, event_xy_other);
3826 }
3827 }
3828
3829 if (!area && !win->parent) {
3830 /* If active window is a parent window, check itself last. */
3831 area = BKE_screen_find_area_xy(screen, spacetype, event_xy);
3832 }
3833
3834 return area;
3835}
3836
3838{
3839 ScrArea *global_area = static_cast<ScrArea *>(win->global_areas.areabase.first);
3840
3841 if (!global_area) {
3842 return static_cast<ScrArea *>(screen->areabase.first);
3843 }
3844 if ((global_area->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
3845 return global_area;
3846 }
3847 /* Find next visible area. */
3848 return ED_screen_areas_iter_next(screen, global_area);
3849}
3851{
3852 if (area->global == nullptr) {
3853 return area->next;
3854 }
3855
3856 for (ScrArea *area_iter = area->next; area_iter; area_iter = area_iter->next) {
3857 if ((area_iter->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
3858 return area_iter;
3859 }
3860 }
3861 /* No visible next global area found, start iterating over layout areas. */
3862 return static_cast<ScrArea *>(screen->areabase.first);
3863}
3864
3866{
3867 return ED_area_headersize(); /* same size as header */
3868}
3869
3871 const char *text_array[],
3872 const float fill_color[4],
3873 const bool full_redraw)
3874{
3875 const int header_height = UI_UNIT_Y;
3876 const uiStyle *style = UI_style_get_dpi();
3877 int fontid = style->widget.uifont_id;
3878 int scissor[4];
3879 int num_lines = 0;
3880
3881 /* background box */
3882 rcti rect = *ED_region_visible_rect(region);
3883
3884 /* Needed in case scripts leave the font size at an unexpected value, see: #102213. */
3885 BLF_size(fontid, style->widget.points * UI_SCALE_FAC);
3886
3887 /* Box fill entire width or just around text. */
3888 if (!full_redraw) {
3889 const char **text = &text_array[0];
3890 while (*text) {
3891 rect.xmax = min_ii(rect.xmax,
3892 rect.xmin + BLF_width(fontid, *text, BLF_DRAW_STR_DUMMY_MAX) +
3893 1.2f * U.widget_unit);
3894 text++;
3895 num_lines++;
3896 }
3897 }
3898 /* Just count the line number. */
3899 else {
3900 const char **text = &text_array[0];
3901 while (*text) {
3902 text++;
3903 num_lines++;
3904 }
3905 }
3906
3907 rect.ymin = rect.ymax - header_height * num_lines;
3908
3909 /* setup scissor */
3910 GPU_scissor_get(scissor);
3911 GPU_scissor(rect.xmin, rect.ymin, BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
3912
3917 immUniformColor4fv(fill_color);
3918 immRectf(pos, rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
3921
3922 /* text */
3924 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
3925 BLF_enable(fontid, BLF_CLIPPING);
3926 int offset = num_lines - 1;
3927 {
3928 const char **text = &text_array[0];
3929 while (*text) {
3930 BLF_position(fontid,
3931 rect.xmin + 0.6f * U.widget_unit,
3932 rect.ymin + 0.3f * U.widget_unit + offset * header_height,
3933 0.0f);
3935 text++;
3936 offset--;
3937 }
3938 }
3939
3940 BLF_disable(fontid, BLF_CLIPPING);
3941
3942 /* restore scissor as it was before */
3943 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
3944}
3945
3947 const char *text,
3948 const float fill_color[4],
3949 const bool full_redraw)
3950{
3951 const char *text_array[2] = {text, nullptr};
3952 ED_region_info_draw_multiline(region, text_array, fill_color, full_redraw);
3953}
3954
3958
3959static void metadata_panel_draw_field(const char *field, const char *value, void *ctx_v)
3960{
3962 uiLayout *row = &ctx->layout->row(false);
3963 row->label(field, ICON_NONE);
3964 row->label(value, ICON_NONE);
3965}
3966
3968{
3970 ctx.layout = layout;
3972}
3973
3974void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, float y0)
3975{
3976 /* the image is located inside (x0, y0), (x0+1, y0+1) as set by view2d */
3977 int x1, y1, x2, y2;
3978 UI_view2d_view_to_region(&region->v2d, x0, y0, &x1, &y1);
3979 UI_view2d_view_to_region(&region->v2d, x0 + 1.0f, y0 + 1.0f, &x2, &y2);
3980
3983
3984 float gridcolor[4];
3985 UI_GetThemeColor4fv(TH_GRID, gridcolor);
3986
3988 /* To fake alpha-blending, color shading is reduced when alpha is nearing 0. */
3989 immUniformThemeColorBlendShade(TH_BACK, TH_GRID, gridcolor[3], 20 * gridcolor[3]);
3990 immRectf(pos, x1, y1, x2, y2);
3992
3993 /* gridsize adapted to zoom level */
3994 float gridsize = 0.5f * (zoomx + zoomy);
3995 float gridstep = 1.0f / 32.0f;
3996 if (gridsize <= 0.0f) {
3997 return;
3998 }
3999
4000 if (gridsize < 1.0f) {
4001 while (gridsize < 1.0f) {
4002 gridsize *= 4.0f;
4003 gridstep *= 4.0f;
4004 }
4005 }
4006 else {
4007 while (gridsize >= 4.0f) {
4008 gridsize /= 4.0f;
4009 gridstep /= 4.0f;
4010 }
4011 }
4012
4013 float blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
4014 CLAMP(blendfac, 0.0f, 1.0f);
4015
4016 int count_fine = 1.0f / gridstep;
4017 int count_large = 1.0f / (4.0f * gridstep);
4018
4019 if (count_fine > 0) {
4023
4025 immBegin(GPU_PRIM_LINES, 4 * count_fine + 4 * count_large);
4026
4027 float theme_color[3];
4028 UI_GetThemeColorShade3fv(TH_GRID, int(20.0f * (1.0f - blendfac)), theme_color);
4029 float fac = 0.0f;
4030
4031 /* the fine resolution level */
4032 for (int i = 0; i < count_fine; i++) {
4033 immAttr3fv(color, theme_color);
4034 immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
4035 immAttr3fv(color, theme_color);
4036 immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
4037 immAttr3fv(color, theme_color);
4038 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
4039 immAttr3fv(color, theme_color);
4040 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
4041 fac += gridstep;
4042 }
4043
4044 if (count_large > 0) {
4045 UI_GetThemeColor3fv(TH_GRID, theme_color);
4046 fac = 0.0f;
4047
4048 /* the large resolution level */
4049 for (int i = 0; i < count_large; i++) {
4050 immAttr3fv(color, theme_color);
4051 immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
4052 immAttr3fv(color, theme_color);
4053 immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
4054 immAttr3fv(color, theme_color);
4055 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
4056 immAttr3fv(color, theme_color);
4057 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
4058 fac += 4.0f * gridstep;
4059 }
4060 }
4061
4062 immEnd();
4064 }
4065}
4066
4067/* If the area has overlapping regions, it returns visible rect for Region *region */
4068/* rect gets returned in local region coordinates */
4069static void region_visible_rect_calc(ARegion *region, rcti *rect)
4070{
4071 ARegion *region_iter = region;
4072
4073 /* allow function to be called without area */
4074 while (region_iter->prev) {
4075 region_iter = region_iter->prev;
4076 }
4077
4078 *rect = region->winrct;
4079
4080 /* check if a region overlaps with the current one */
4081 for (; region_iter; region_iter = region_iter->next) {
4082 if (region != region_iter && region_iter->overlap) {
4083 if (BLI_rcti_isect(rect, &region_iter->winrct, nullptr)) {
4084 int alignment = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
4085
4086 if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
4087 /* Overlap left, also check 1 pixel offset (2 regions on one side). */
4088 if (abs(rect->xmin - region_iter->winrct.xmin) < 2) {
4089 rect->xmin = region_iter->winrct.xmax;
4090 }
4091
4092 /* Overlap right. */
4093 if (abs(rect->xmax - region_iter->winrct.xmax) < 2) {
4094 rect->xmax = region_iter->winrct.xmin;
4095 }
4096 }
4097 else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
4098 /* Same logic as above for vertical regions. */
4099 if (abs(rect->ymin - region_iter->winrct.ymin) < 2) {
4100 rect->ymin = region_iter->winrct.ymax;
4101 }
4102 if (abs(rect->ymax - region_iter->winrct.ymax) < 2) {
4103 rect->ymax = region_iter->winrct.ymin;
4104 }
4105 }
4106 else if (alignment == RGN_ALIGN_FLOAT) {
4107 /* Skip floating. */
4108 }
4109 else {
4110 BLI_assert_msg(0, "Region overlap with unknown alignment");
4111 }
4112 }
4113 }
4114 }
4115 BLI_rcti_translate(rect, -region->winrct.xmin, -region->winrct.ymin);
4116}
4117
4119{
4120 rcti *rect = &region->runtime->visible_rect;
4121 if (rect->xmin == 0 && rect->ymin == 0 && rect->xmax == 0 && rect->ymax == 0) {
4122 region_visible_rect_calc(region, rect);
4123 }
4124 return rect;
4125}
4126
4127/* Cache display helpers */
4128
4130{
4131 /* Local coordinate visible rect inside region, to accommodate overlapping ui. */
4132 const rcti *rect_visible = ED_region_visible_rect(region);
4133 const int region_bottom = rect_visible->ymin;
4134
4137 immUniformColor4ub(128, 128, 255, 64);
4138 immRectf(pos, 0, region_bottom, region->winx, region_bottom + 8 * UI_SCALE_FAC);
4140}
4141
4142void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
4143{
4144 using namespace blender;
4145 const uiStyle *style = UI_style_get();
4146 int fontid = style->widget.uifont_id;
4147
4148 /* Format frame number. */
4149 char numstr[32];
4150 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
4151 SNPRINTF(numstr, "%d", framenr);
4152
4153 float2 text_dims = {0.0f, 0.0f};
4154 BLF_width_and_height(fontid, numstr, sizeof(numstr), &text_dims.x, &text_dims.y);
4155 float padding = 3.0f * UI_SCALE_FAC;
4156
4157 /* Rounded corner background box. */
4158 float4 bg_color;
4159 UI_GetThemeColorShade4fv(TH_CFRAME, -5, bg_color);
4160 float4 outline_color;
4161 UI_GetThemeColorShade4fv(TH_CFRAME, 5, outline_color);
4162
4163 rctf rect{};
4164 rect.xmin = x - text_dims.x / 2 - padding;
4165 rect.xmax = x + text_dims.x / 2 + padding;
4166 rect.ymin = y;
4167 rect.ymax = y + text_dims.y + padding * 2;
4170 &rect, bg_color, nullptr, 1.0f, outline_color, U.pixelsize, 3 * UI_SCALE_FAC);
4171
4172 /* Text label. */
4174 BLF_position(fontid, x - text_dims.x * 0.5f, y + padding, 0.0f);
4175 BLF_draw(fontid, numstr, sizeof(numstr));
4176}
4177
4179 ARegion *region, const int num_segments, const int *points, const int sfra, const int efra)
4180{
4181 if (num_segments) {
4182 /* Local coordinate visible rect inside region, to accommodate overlapping ui. */
4183 const rcti *rect_visible = ED_region_visible_rect(region);
4184 const int region_bottom = rect_visible->ymin;
4185
4188 immUniformColor4ub(128, 128, 255, 128);
4189
4190 for (int a = 0; a < num_segments; a++) {
4191 float x1 = float(points[a * 2] - sfra) / (efra - sfra + 1) * region->winx;
4192 float x2 = float(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * region->winx;
4193
4194 immRectf(pos, x1, region_bottom, x2, region_bottom + 8 * UI_SCALE_FAC);
4195 /* TODO(merwin): use primitive restart to draw multiple rects more efficiently */
4196 }
4197
4199 }
4200}
4201
4203{
4204 ARegion *region = params->region;
4205 const bContext *C = params->context;
4206 wmMsgBus *mbus = params->message_bus;
4207
4208 if (region->runtime->gizmo_map != nullptr) {
4209 WM_gizmomap_message_subscribe(C, region->runtime->gizmo_map, region, mbus);
4210 }
4211
4212 if (!BLI_listbase_is_empty(&region->runtime->uiblocks)) {
4213 UI_region_message_subscribe(region, mbus);
4214 }
4215
4216 if (region->runtime->type->message_subscribe != nullptr) {
4217 region->runtime->type->message_subscribe(params);
4218 }
4219}
4220
4222{
4223 /* Use a larger value because toggling scrollbars can jump in size. */
4224 const int snap_match_threshold = 16;
4225 if (region->runtime->type->snap_size != nullptr) {
4226 const int snap_size_x = region->runtime->type->snap_size(region, region->sizex, 0);
4227 const int snap_size_y = region->runtime->type->snap_size(region, region->sizey, 1);
4228 return (((abs(region->sizex - snap_size_x) <= snap_match_threshold) << 0) |
4229 ((abs(region->sizey - snap_size_y) <= snap_match_threshold) << 1));
4230 }
4231 return 0;
4232}
4233
4234bool ED_region_snap_size_apply(ARegion *region, int snap_flag)
4235{
4236 bool changed = false;
4237 if (region->runtime->type->snap_size != nullptr) {
4238 if (snap_flag & (1 << 0)) {
4239 short snap_size = region->runtime->type->snap_size(region, region->sizex, 0);
4240 if (snap_size != region->sizex) {
4241 region->sizex = snap_size;
4242 changed = true;
4243 }
4244 }
4245 if (snap_flag & (1 << 1)) {
4246 short snap_size = region->runtime->type->snap_size(region, region->sizey, 1);
4247 if (snap_size != region->sizey) {
4248 region->sizey = snap_size;
4249 changed = true;
4250 }
4251 }
4252 }
4253 return changed;
4254}
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)
Scene * CTX_data_scene(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
@ G_DEBUG
@ G_TRANSFORM_WM
void BKE_spacedata_copylist(ListBase *lb_dst, ListBase *lb_src)
Definition screen.cc:400
#define BKE_ST_MAXNAME
Definition BKE_screen.hh:72
void BKE_spacedata_freelist(ListBase *lb)
Definition screen.cc:299
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
void BKE_screen_area_free(ScrArea *area)
Definition screen.cc:632
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:251
ARegionType * BKE_regiontype_from_id(const SpaceType *st, int regionid)
Definition screen.cc:261
void BKE_area_region_free(SpaceType *st, ARegion *region)
Definition screen.cc:591
@ PANEL_TYPE_NO_HEADER
@ PANEL_TYPE_INSTANCED
@ PANEL_TYPE_LAYOUT_VERT_BAR
@ PANEL_TYPE_NO_SEARCH
@ PANEL_TYPE_HEADER_EXPAND
ARegion * BKE_area_region_copy(const SpaceType *st, const ARegion *region)
Definition screen.cc:344
void BKE_area_region_panels_free(ListBase *panels)
Definition screen.cc:579
void BKE_workspace_status_clear(WorkSpace *workspace)
Definition workspace.cc:648
bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
Definition workspace.cc:535
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:612
int BLF_set_default()
void BLF_size(int fontid, float size)
Definition blf.cc:440
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:906
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition blf.cc:792
@ BLF_CLIPPING
Definition BLF_api.hh:434
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:468
void BLF_disable(int fontid, int option)
Definition blf.cc:329
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:582
void BLF_enable(int fontid, int option)
Definition blf.cc:320
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:805
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:385
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#define BLI_INLINE
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
#define LISTBASE_FOREACH_BACKWARD(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
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 BLI_INLINE bool BLI_listbase_is_single(const ListBase *lb)
MINLINE int round_fl_to_int(float a)
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:198
bool BLI_rcti_is_valid(const struct rcti *rect)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:566
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:414
void BLI_rcti_resize(struct rcti *rect, int x, int y)
Definition rct.cc:621
void BLI_rcti_sanitize(struct rcti *rect)
Definition rct.cc:446
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:194
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.h:181
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:202
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:206
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.h:177
void BLI_str_rstrip(char *str) ATTR_NONNULL(1)
Definition string.cc:990
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define BLI_string_join(...)
unsigned char uchar
unsigned int uint
#define CLAMP(a, b, c)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define IS_EQF(a, b)
#define STREQ(a, b)
#define LIKELY(x)
#define HEADERY
#define RGN_ALIGN_ENUM_FROM_MASK(align)
@ PNL_PIN
@ SCREENFULL
@ SCREENMAXIMIZED
@ SCREENNORMAL
#define AREAMINX
@ RGN_DRAW_NO_REBUILD
@ RGN_DRAW_PARTIAL
@ RGN_DRAWING
@ RGN_DRAW
@ RGN_REFRESH_UI
@ RGN_DRAW_EDITOR_OVERLAYS
@ GLOBAL_AREA_IS_HIDDEN
@ RGN_TYPE_CHANNELS
@ RGN_TYPE_TOOL_HEADER
@ RGN_TYPE_UI
@ RGN_TYPE_ASSET_SHELF_HEADER
@ RGN_TYPE_WINDOW
@ RGN_TYPE_ASSET_SHELF
@ RGN_TYPE_HUD
@ RGN_TYPE_PREVIEW
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_FOOTER
@ RGN_TYPE_HEADER
@ RGN_TYPE_TOOLS
@ RGN_TYPE_TOOL_PROPS
#define RGN_TYPE_HAS_CATEGORY_MASK
#define HEADER_PADDING_Y
@ RGN_FLAG_SEARCH_FILTER_UPDATE
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_SIZE_CLAMP_X
@ RGN_FLAG_HIDDEN
@ RGN_FLAG_SIZE_CLAMP_Y
@ RGN_FLAG_POLL_FAILED
@ RGN_FLAG_TOO_SMALL
@ RGN_FLAG_SEARCH_FILTER_ACTIVE
#define RGN_TYPE_NUM
@ AREA_FLAG_ACTIVE_TOOL_UPDATE
@ AREA_FLAG_OFFSCREEN
@ AREA_FLAG_REGION_SIZE_UPDATE
@ AREA_FLAG_STACKED_FULLSCREEN
@ AREA_FLAG_ACTIONZONES_UPDATE
@ HEADER_NO_PULLDOWN
#define RGN_TYPE_IS_HEADER_ANY(regiontype)
#define RGN_ALIGN_FLAG_FROM_MASK(align)
@ RGN_ALIGN_HIDE_WITH_PREV
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_ALIGN_TOP
@ RGN_ALIGN_RIGHT
@ RGN_SPLIT_PREV
@ RGN_ALIGN_HSPLIT
@ RGN_ALIGN_VSPLIT
@ RGN_ALIGN_NONE
@ RGN_ALIGN_FLOAT
@ RGN_ALIGN_QSPLIT
eSpace_Type
@ SPACE_CLIP
@ SPACE_NODE
@ SPACE_PROPERTIES
@ SPACE_EMPTY
@ SPACE_IMAGE
@ SPACE_VIEW3D
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
@ USER_REGION_OVERLAP
@ USER_APP_HIDE_REGION_TOGGLE
@ USER_APP_LOCK_CORNER_SPLIT
@ USER_APP_LOCK_EDGE_RESIZE
@ V2D_SCROLL_LEFT
@ V2D_SCROLL_HORIZONTAL
@ V2D_SCROLL_RIGHT
@ V2D_SCROLL_BOTTOM
@ V2D_SCROLL_VERTICAL
@ V2D_LOCKOFS_X
@ V2D_LOCKOFS_Y
@ V2D_KEEPOFS_Y
@ V2D_KEEPOFS_X
const char * ED_buttons_search_string_get(SpaceProperties *sbuts)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:714
@ ED_KEYMAP_NAVBAR
Definition ED_screen.hh:749
@ ED_KEYMAP_ASSET_SHELF
Definition ED_screen.hh:750
@ ED_KEYMAP_UI
Definition ED_screen.hh:740
@ ED_KEYMAP_ANIMATION
Definition ED_screen.hh:744
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:746
@ ED_KEYMAP_TOOL
Definition ED_screen.hh:742
@ ED_KEYMAP_GPENCIL
Definition ED_screen.hh:748
@ ED_KEYMAP_GIZMO
Definition ED_screen.hh:741
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:743
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:745
@ ED_KEYMAP_FOOTER
Definition ED_screen.hh:747
bool ED_area_is_global(const ScrArea *area)
Definition area.cc:3801
int ED_area_headersize()
Definition area.cc:3774
void ED_region_visibility_change_update_animated(bContext *C, ScrArea *area, ARegion *region)
void ED_area_exit(bContext *C, ScrArea *area)
AZone * ED_area_azones_update(ScrArea *area, const int mouse_xy[2])
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:384
AZScrollDirection
@ AZ_SCROLL_HOR
@ AZ_SCROLL_VERT
@ AZONE_REGION
@ AZONE_FULLSCREEN
@ AZONE_REGION_SCROLL
@ AZONE_AREA
@ AE_LEFT_TO_TOPRIGHT
@ AE_RIGHT_TO_TOPLEFT
@ AE_BOTTOM_TO_TOPLEFT
@ AE_TOP_TO_BOTTOMRIGHT
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
#define REGION_DRAW_POST_PIXEL
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_clear_color(float red, float green, float blue, float alpha)
void immEnd()
void immUnbindProgram()
void immUniformColor4f(float r, float g, float b, float a)
void immVertex2f(uint attr_id, float x, float y)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int offset)
void immAttr3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void GPU_matrix_identity_set()
void GPU_matrix_push()
void GPU_matrix_pop()
void GPU_matrix_translate_2f(float x, float y)
@ GPU_PRIM_TRI_FAN
@ GPU_PRIM_LINES
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_FLAT_COLOR
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_line_width(float width)
Definition gpu_state.cc:166
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:193
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:268
@ GPU_FETCH_FLOAT
void GPU_vertformat_clear(GPUVertFormat *)
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
void IMB_metadata_foreach(const ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
Definition metadata.cc:87
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
void UI_region_button_sections_draw(const ARegion *region, int colorid, uiButtonSectionsAlign align)
void UI_blocklist_update_window_matrix(const bContext *C, const ListBase *lb)
bool UI_panel_is_closed(const Panel *panel)
#define UI_UNIT_Y
void UI_draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
#define UI_AZONESPOTW
PanelCategoryDyn * UI_panel_category_find(const ARegion *region, const char *idname)
#define INSTANCED_PANEL_UNIQUE_STR_SIZE
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, blender::ui::EmbossType emboss)
void UI_blocklist_free(const bContext *C, ARegion *region)
Panel * UI_panel_find_by_type(ListBase *lb, const PanelType *pt)
void UI_draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
void UI_blocklist_update_view_for_buttons(const bContext *C, const ListBase *lb)
void UI_panel_header_buttons_begin(Panel *panel)
void UI_panels_free_instanced(const bContext *C, ARegion *region)
const uiStyle * UI_style_get_dpi()
bool UI_panel_category_is_visible(const ARegion *region)
void UI_block_listen(const uiBlock *block, const wmRegionListenerParams *listener_params)
void UI_block_translate(uiBlock *block, float x, float y)
Definition interface.cc:390
void UI_draw_roundbox_corner_set(int type)
#define UI_PANEL_MARGIN_X
void UI_panels_begin(const bContext *C, ARegion *region)
Panel * UI_panel_begin(ARegion *region, ListBase *lb, uiBlock *block, PanelType *pt, Panel *panel, bool *r_open)
@ UI_CNR_BOTTOM_LEFT
@ UI_CNR_BOTTOM_RIGHT
@ UI_CNR_ALL
@ UI_CNR_TOP_LEFT
@ UI_CNR_TOP_RIGHT
int UI_panel_size_y(const Panel *panel)
void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
#define UI_HEADER_OFFSET
void UI_region_message_subscribe(ARegion *region, wmMsgBus *mbus)
bool UI_panel_is_active(const Panel *panel)
const uiStyle * UI_style_get()
bool UI_panel_should_show_background(const ARegion *region, const PanelType *panel_type)
void UI_panel_category_clear_all(ARegion *region)
#define UI_PANEL_CATEGORY_MARGIN_WIDTH
void UI_blocklist_free_inactive(const bContext *C, ARegion *region)
void UI_blocklist_draw(const bContext *C, const ListBase *lb)
void UI_panel_label_offset(const uiBlock *block, int *r_x, int *r_y)
int UI_icon_from_event_type(short event_type, short event_value)
uiButtonSectionsAlign
void UI_panel_end(Panel *panel, int width, int height)
void UI_panel_header_buttons_end(Panel *panel)
bool UI_panel_is_dragging(const Panel *panel)
void UI_panels_draw(const bContext *C, ARegion *region)
#define UI_UNIT_X
@ UI_BTYPE_MENU
uiBut * uiDefButR(uiBlock *block, int type, int retval, std::optional< blender::StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, blender::StringRefNull propname, int index, float min, float max, std::optional< blender::StringRef > tip)
void UI_draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void UI_list_panel_unique_str(Panel *panel, char *r_name)
void UI_panel_category_add(ARegion *region, const char *name)
void UI_region_handlers_add(ListBase *handlers)
void UI_block_end(const bContext *C, uiBlock *block)
void UI_block_set_search_only(uiBlock *block, bool search_only)
const char * UI_panel_category_active_get(ARegion *region, bool set_fallback)
#define UI_AZONESPOTH
void UI_region_free_active_but_all(bContext *C, ARegion *region)
#define UI_NO_ICON_OVERLAY_TEXT
void UI_icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false)
bool UI_block_apply_search_filter(uiBlock *block, const char *search_filter)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
@ UI_LAYOUT_VERTICAL
@ UI_LAYOUT_HORIZONTAL
uiLayout * UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int size, int em, int padding, const uiStyle *style)
@ UI_LAYOUT_PANEL
@ UI_LAYOUT_VERT_BAR
@ UI_LAYOUT_TOOLBAR
@ UI_LAYOUT_HEADER
int uiLayoutGetWidth(uiLayout *layout)
void UI_block_layout_free(uiBlock *block)
void UI_block_layout_resolve(uiBlock *block, int *r_x, int *r_y)
void uiLayoutSetOperatorContext(uiLayout *layout, wmOperatorCallContext opcontext)
bool uiLayoutEndsWithPanelHeader(const uiLayout &layout)
#define UI_MAX_DRAW_STR
void UI_Theme_Store(bThemeState *theme_state)
void UI_Theme_Restore(const bThemeState *theme_state)
void UI_GetThemeColor3fv(int colorid, float col[3])
ThemeColorID
@ TH_HEADER
@ TH_GRID
@ TH_BACK
@ TH_EDITOR_BORDER
@ TH_PREVIEW_BACK
@ TH_CFRAME
@ TH_HEADER_TEXT_HI
@ TH_TEXT
@ TH_TEXT_HI
void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
void UI_ThemeClearColor(int colorid)
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
bTheme * UI_GetTheme()
void UI_FontThemeColor(int fontid, int colorid)
void UI_SetTheme(int spacetype, int regionid)
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1503
void UI_view2d_view_restore(const bContext *C)
Definition view2d.cc:1162
void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
Definition view2d.cc:221
void UI_view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1036
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
void UI_view2d_mask_from_win(const View2D *v2d, rcti *r_mask)
Definition view2d.cc:109
@ V2D_COMMONVIEW_HEADER
Definition UI_view2d.hh:39
@ V2D_COMMONVIEW_PANELS_UI
Definition UI_view2d.hh:41
void UI_view2d_view_to_region(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
Definition view2d.cc:1722
float UI_view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1920
@ WM_CAPABILITY_WINDOW_DECORATION_STYLES
Definition WM_api.hh:201
#define WM_TOOLSYSTEM_SPACE_MASK
#define NC_WINDOW
Definition WM_types.hh:372
#define ND_FILEREAD
Definition WM_types.hh:409
#define ND_SPACE_CHANGED
Definition WM_types.hh:535
#define NC_WM
Definition WM_types.hh:371
@ KM_NOTHING
Definition WM_types.hh:307
@ KM_ANY
Definition WM_types.hh:306
wmOperatorCallContext
Definition WM_types.hh:236
@ WM_OP_INVOKE_REGION_WIN
Definition WM_types.hh:239
#define NC_SPACE
Definition WM_types.hh:389
#define KM_MOD_HELD
Definition WM_types.hh:323
ScrArea * ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area)
Definition area.cc:3850
void ED_area_do_mgs_subscribe_for_tool_header(const wmRegionMessageSubscribeParams *params)
Definition area.cc:417
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:714
int ED_region_snap_size_test(const ARegion *region)
Definition area.cc:4221
static constexpr float STATUS_MOUSE_ICON_PAD
Definition area.cc:949
bool ED_region_property_search(const bContext *C, ARegion *region, ListBase *paneltypes, const char *contexts[], const char *category_override)
Definition area.cc:3559
void ED_region_tag_refresh_ui(ARegion *region)
Definition area.cc:668
void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
Definition area.cc:2144
void ED_area_do_mgs_subscribe_for_tool_ui(const wmRegionMessageSubscribeParams *params)
Definition area.cc:432
void ED_region_update_rect(ARegion *region)
Definition area.cc:2300
ScrArea * ED_screen_areas_iter_first(const wmWindow *win, const bScreen *screen)
Definition area.cc:3837
BLI_INLINE bool streq_array_any(const char *s, const char *arr[])
Definition area.cc:2950
static bool panel_add_check(const bContext *C, const WorkSpace *workspace, const char *contexts[], const char *category_override, PanelType *panel_type)
Definition area.cc:3137
void ED_region_cursor_set(wmWindow *win, ScrArea *area, ARegion *region)
Definition area.cc:2315
const char * ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region)
Definition area.cc:846
void ED_region_clear(const bContext *C, const ARegion *region, const int colorid)
Definition area.cc:2927
void ED_region_do_listen(wmRegionListenerParams *params)
Definition area.cc:129
int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
Definition area.cc:783
static void region_evaulate_visibility(ARegion *region)
Definition area.cc:1931
int ED_area_global_size_y(const ScrArea *area)
Definition area.cc:3785
void ED_region_search_filter_update(const ScrArea *area, ARegion *region)
Definition area.cc:859
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2377
static void area_calc_totrct(const bScreen *screen, ScrArea *area, const rcti *window_rect)
Definition area.cc:1875
static int panel_draw_width_from_max_width_get(const ARegion *region, const PanelType *panel_type, const int max_width)
Definition area.cc:3209
static void region_draw_blocks_in_view2d(const bContext *C, const ARegion *region)
Definition area.cc:3715
static bool region_uses_category_tabs(const ScrArea *area, const ARegion *region)
Definition area.cc:3177
static SpaceLink * area_get_prevspace(ScrArea *area)
Definition area.cc:2838
static void area_azone_tag_update(ScrArea *area)
Definition area.cc:295
int ED_area_global_min_size_y(const ScrArea *area)
Definition area.cc:3790
RegionEmbossSide
Definition area.cc:60
@ REGION_EMBOSS_BOTTOM
Definition area.cc:63
@ REGION_EMBOSS_ALL
Definition area.cc:65
@ REGION_EMBOSS_TOP
Definition area.cc:62
@ REGION_EMBOSS_LEFT
Definition area.cc:61
@ REGION_EMBOSS_RIGHT
Definition area.cc:64
ScrArea * ED_area_find_under_cursor(const bContext *C, int spacetype, const int event_xy[2])
Definition area.cc:3806
static void area_azone_init(const wmWindow *win, const bScreen *screen, ScrArea *area)
Definition area.cc:1050
void ED_area_and_region_types_init(ScrArea *area)
Definition area.cc:2127
void ED_region_floating_init(ARegion *region)
Definition area.cc:2305
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:872
static void region_draw_azones(ScrArea *area, ARegion *region)
Definition area.cc:300
void ED_area_tag_redraw_no_rebuild(ScrArea *area)
Definition area.cc:723
int ED_area_global_max_size_y(const ScrArea *area)
Definition area.cc:3795
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3466
void ED_region_do_msg_notify_tag_redraw(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
Definition area.cc:384
void region_toggle_hidden(bContext *C, ARegion *region, const bool do_fade)
Definition area.cc:2362
static void ed_workspace_status_icon_item(WorkSpace *workspace, const int icon, const bool inverted=false)
Definition area.cc:960
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3754
static void region_overlap_fix(ScrArea *area, ARegion *region)
Definition area.cc:1415
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4118
static void area_offscreen_exit(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2253
static void ed_workspace_status_space(WorkSpace *workspace, const float space_factor)
Definition area.cc:928
void ED_area_do_listen(wmSpaceTypeListenerParams *params)
Definition area.cc:161
static bool panel_property_search(const bContext *C, ARegion *region, const uiStyle *style, Panel *panel, PanelType *panel_type, const char *search_filter)
Definition area.cc:3498
static const char * region_panels_collect_categories(ARegion *region, LinkNode *panel_types_stack, bool *use_category_tabs)
Definition area.cc:3185
void ED_region_cache_draw_cached_segments(ARegion *region, const int num_segments, const int *points, const int sfra, const int efra)
Definition area.cc:4178
static void region_align_info_from_area(ScrArea *area, RegionTypeAlignInfo *r_align_info)
Definition area.cc:2449
void ED_region_header_init(ARegion *region)
Definition area.cc:3769
static constexpr float STATUS_AFTER_TEXT
Definition area.cc:948
void ED_region_header_with_button_sections(const bContext *C, ARegion *region, const uiButtonSectionsAlign align)
Definition area.cc:3761
bool ED_area_is_global(const ScrArea *area)
Definition area.cc:3801
void ED_region_cache_draw_background(ARegion *region)
Definition area.cc:4129
void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
Definition area.cc:2667
void ED_region_header_draw_with_button_sections(const bContext *C, const ARegion *region, const uiButtonSectionsAlign align)
Definition area.cc:3736
static void region_draw_emboss(const ARegion *region, const rcti *scirct, int sides)
Definition area.cc:71
static void ed_workspace_status_text_item(WorkSpace *workspace, std::string text)
Definition area.cc:951
void ED_region_pixelspace(const ARegion *region)
Definition area.cc:123
void ED_area_offscreen_free(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2283
void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
Definition area.cc:2382
void ED_region_header_draw(const bContext *C, ARegion *region)
Definition area.cc:3729
static void region_azone_edge_init(ScrArea *area, ARegion *region, AZEdge edge, const bool is_fullscreen)
Definition area.cc:1294
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:659
int ED_area_headersize()
Definition area.cc:3774
ScrArea * ED_area_offscreen_create(wmWindow *win, eSpace_Type space_type)
Definition area.cc:2242
void ED_area_tag_redraw_regiontype(ScrArea *area, int regiontype)
Definition area.cc:732
bool ED_area_has_shared_border(ScrArea *a, ScrArea *b)
Definition area.cc:2089
void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, wmOperatorCallContext op_context, const char *contexts[], const char *category_override)
Definition area.cc:3219
static void region_azone_edge(const ScrArea *area, AZone *az, const ARegion *region)
Definition area.cc:1171
bool ED_region_snap_size_apply(ARegion *region, int snap_flag)
Definition area.cc:4234
bool ED_region_is_overlap(int spacetype, int regiontype)
Definition area.cc:1490
static void metadata_panel_draw_field(const char *field, const char *value, void *ctx_v)
Definition area.cc:3959
static void area_draw_azone(short, short, short, short)
Corner widgets use for dragging and splitting the view.
Definition area.cc:197
void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
Definition area.cc:687
static void region_azone_scrollbar_init(ScrArea *area, ARegion *region, AZScrollDirection direction)
Definition area.cc:1319
void ED_area_tag_region_size_update(ScrArea *area, ARegion *changed_region)
Definition area.cc:750
static void region_visible_rect_calc(ARegion *region, rcti *rect)
Definition area.cc:4069
static void region_clear_fully_transparent(const bContext *C)
Definition area.cc:2942
static void region_azones_add(const bScreen *screen, ScrArea *area, ARegion *region)
Definition area.cc:1375
void ED_region_visibility_change_update(bContext *C, ScrArea *area, ARegion *region)
Definition area.cc:2355
void ED_region_do_layout(bContext *C, ARegion *region)
Definition area.cc:479
void ED_region_tag_redraw_cursor(ARegion *region)
Definition area.cc:652
void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_region_exit)
Definition area.cc:2693
void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
Definition area.cc:4142
void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src)
Definition area.cc:2415
static void region_draw_status_text(ScrArea *, ARegion *region)
Definition area.cc:345
static bool region_background_is_transparent(const ScrArea *area, const ARegion *region)
Definition area.cc:1156
void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2050
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:743
static bool region_azone_edge_poll(const ScrArea *area, const ARegion *region, const bool is_fullscreen)
Definition area.cc:1255
void ED_region_info_draw_multiline(ARegion *region, const char *text_array[], const float fill_color[4], const bool full_redraw)
Definition area.cc:3870
int ED_region_global_size_y()
Definition area.cc:3865
static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region)
Definition area.cc:1217
static void ed_default_handlers(wmWindowManager *wm, ScrArea *area, ARegion *region, ListBase *handlers, int flag)
Definition area.cc:1946
static short region_alignment_from_header_and_tool_header_state(const RegionTypeAlignInfo *region_align_info, const short fallback)
Definition area.cc:2477
void ED_area_do_refresh(bContext *C, ScrArea *area)
Definition area.cc:169
static void region_align_info_to_area_for_headers(const RegionTypeAlignInfo *region_align_info_src, const RegionTypeAlignInfo *region_align_info_dst, ARegion *region_by_type[RGN_TYPE_NUM])
Definition area.cc:2524
void ED_region_panels_layout(const bContext *C, ARegion *region)
Definition area.cc:3403
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:3473
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1040
static void area_init_type_fallback(ScrArea *area, eSpace_Type space_type)
Definition area.cc:2097
void ED_region_image_metadata_panel_draw(ImBuf *ibuf, uiLayout *layout)
Definition area.cc:3967
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:675
static void region_draw_azone_tab_arrow(ScrArea *area, ARegion *region, AZone *az)
Definition area.cc:261
static void region_update_rect(ARegion *region)
Definition area.cc:2291
int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
Definition area.cc:2886
void ED_region_info_draw(ARegion *region, const char *text, const float fill_color[4], const bool full_redraw)
Definition area.cc:3946
void ED_region_visibility_change_update_ex(bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
Definition area.cc:2336
static void area_offscreen_init(ScrArea *area)
Definition area.cc:2229
static constexpr float STATUS_BEFORE_TEXT
Definition area.cc:947
void ED_area_do_msg_notify_tag_refresh(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
Definition area.cc:407
static void ed_workspace_status_item(WorkSpace *workspace, std::string text, const int icon, const float space_factor=0.0f, const bool inverted=false)
Definition area.cc:909
void ED_region_do_draw(bContext *C, ARegion *region)
Definition area.cc:502
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:639
static void region_align_info_to_area(ScrArea *area, const RegionTypeAlignInfo region_align_info_src[RGN_TYPE_NUM])
Definition area.cc:2639
void ED_region_message_subscribe(wmRegionMessageSubscribeParams *params)
Definition area.cc:4202
int ED_area_footersize()
Definition area.cc:3780
void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, float y0)
Definition area.cc:3974
static ThemeColorID region_background_color_id(const bContext *, const ARegion *region)
Definition area.cc:2914
static void fullscreen_azone_init(ScrArea *area, ARegion *region)
Definition area.cc:1124
void ED_area_prevspace(bContext *C, ScrArea *area)
Definition area.cc:2860
static void area_draw_azone_fullscreen(short, short, short x2, short y2, float alpha)
Corner widget use for quitting full-screen.
Definition area.cc:181
static bool area_is_pseudo_minimized(const ScrArea *area)
Definition area.cc:474
static void region_rect_recursive(ScrArea *area, ARegion *region, rcti *remainder, rcti *overlap_remainder, int quad)
Definition area.cc:1537
void ED_region_panels_ex(const bContext *C, ARegion *region, wmOperatorCallContext op_context, const char *contexts[])
Definition area.cc:3455
static void draw_azone_arrow(float x1, float y1, float x2, float y2, AZEdge edge)
Edge widgets to show hidden panels such as the toolbar and headers.
Definition area.cc:205
static void region_azones_scrollbars_init(ScrArea *area, ARegion *region)
Definition area.cc:1341
static void region_azones_add_edge(ScrArea *area, ARegion *region, const int alignment, const bool is_fullscreen)
Definition area.cc:1354
void ED_region_panels_draw(const bContext *C, ARegion *region)
Definition area.cc:3409
static int rct_fits(const rcti *rect, const eScreenAxis dir_axis, int size)
Definition area.cc:1402
void ED_region_header_layout(const bContext *C, ARegion *region)
Definition area.cc:3637
static void ed_panel_draw(const bContext *C, ARegion *region, ListBase *lb, PanelType *pt, Panel *panel, int w, int em, char *unique_panel_str, const char *search_filter, wmOperatorCallContext op_context)
Definition area.cc:2969
int pad[32 - sizeof(int)]
#define U
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
static RandomNumberGenerator from_random_seed()
Definition rand.cc:288
void range(std::string text, int icon1, int icon2)
Definition area.cc:986
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:995
WorkspaceStatus(bContext *C)
Definition area.cc:933
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:979
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
Definition area.cc:1005
#define floorf(x)
#define fabsf(x)
#define str(s)
uint pos
blender::gpu::Batch * quad
VecBase< float, 4 > float4
constexpr T sign(T) RET
#define abs
#define printf(...)
#define MEM_SAFE_FREE(v)
uint padding(uint offset, uint alignment)
BLI_INLINE float fb(float length, float L)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
format
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define G(x, y, z)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
Definition msgfmt.cc:222
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool area_regions_poll(bContext *C, const bScreen *screen, ScrArea *area)
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
void screen_area_spacelink_add(const Scene *scene, ScrArea *area, eSpace_Type space_type)
eScreenAxis
@ SCREEN_AXIS_V
@ SCREEN_AXIS_H
#define AZONEFADEOUT
void(* draw)(const bContext *C, ARegion *region)
void(* layout)(const bContext *C, ARegion *region)
struct ARegion * prev
ARegionRuntimeHandle * runtime
struct ARegion * next
ListBase panels
ListBase ui_lists
float alpha
AZEdge edge
ARegion * region
AZScrollDirection direction
uiLayout * layout
HeaderType * type
struct LinkNode * next
void * last
void * first
void(* draw)(const bContext *C, Panel *panel)
char idname[BKE_ST_MAXNAME]
bool(* poll)(const bContext *C, PanelType *pt)
char context[BKE_ST_MAXNAME]
char owner_id[128]
ListBase children
char category[BKE_ST_MAXNAME]
void(* draw_header_preset)(const bContext *C, Panel *panel)
PanelType * parent
void(* draw_header)(const bContext *C, Panel *panel)
LayoutPanels layout_panels
struct PanelType * type
short labelofs
struct Panel_Runtime * runtime
struct uiLayout * layout
ListBase children
struct RegionTypeAlignInfo::@113301254371260256226373027053106207230173330073 by_type[RGN_TYPE_NUM]
ListBase areabase
struct bToolRef * tool
ListBase handlers
ScrVert * v2
ListBase actionzones
ListBase spacedata
short butspacetype_subtype
struct SpaceType * type
ScrArea_Runtime runtime
ScrVert * v1
struct ScrArea * next
ListBase regionbase
ScrGlobalAreaData * global
ScrVert * v4
void(* free)(SpaceLink *sl)
Definition BKE_screen.hh:95
void(* refresh)(const bContext *C, ScrArea *area)
int(* space_subtype_get)(ScrArea *area)
SpaceLink *(* create)(const ScrArea *area, const Scene *scene)
Definition BKE_screen.hh:93
void(* exit)(wmWindowManager *wm, ScrArea *area)
void(* init)(wmWindowManager *wm, ScrArea *area)
Definition BKE_screen.hh:98
void(* space_subtype_item_extend)(bContext *C, EnumPropertyItem **item, int *totitem)
void(* space_subtype_set)(ScrArea *area, int value)
unsigned char header[4]
char alpha_vert
short keepofs
WorkSpaceRuntimeHandle * runtime
ListBase areabase
ThemeSpace space_view3d
float x
float y
float xmax
float xmin
float ymax
float ymin
int ymin
int ymax
int xmin
int xmax
void label(blender::StringRef name, int icon)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
uiLayout & row(bool align)
short panelspace
uiFontStyle widget
short y
short x
int xy[2]
Definition WM_types.hh:758
unsigned int data
Definition WM_types.hh:355
unsigned int category
Definition WM_types.hh:355
struct wmWindow * parent
WindowRuntimeHandle * runtime
struct wmEvent * eventstate
ScrAreaMap global_areas
struct WorkSpaceInstanceHook * workspace_hook
i
Definition text_draw.cc:230
bool ED_time_scrub_event_in_region_poll(const wmWindow *, const ScrArea *, const ARegion *region, const wmEvent *event)
void WM_cursor_set(wmWindow *win, int curs)
bool WM_cursor_set_from_tool(wmWindow *win, const ScrArea *area, const ARegion *region)
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:15
ListBase * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
static ListBase dropboxes
bool WM_region_use_viewport(ScrArea *area, ARegion *region)
Definition wm_draw.cc:564
void WM_draw_region_free(ARegion *region)
Definition wm_draw.cc:1643
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes)
wmEventHandler_Keymap * WM_event_add_keymap_handler_poll(ListBase *handlers, wmKeyMap *keymap, EventHandlerPoll poll)
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
bool WM_event_handler_region_marker_poll(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event)
void WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
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)
wmEventHandler_Keymap * WM_event_add_keymap_handler_dynamic(ListBase *handlers, wmEventHandler_KeymapDynamicFn keymap_fn, void *user_data)
ScrArea * WM_window_status_area_find(wmWindow *win, bScreen *screen)
void WM_event_get_keymap_from_toolsystem_with_gizmos(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
void WM_event_remove_handlers(bContext *C, ListBase *handlers)
void WM_event_add_mousemove(wmWindow *win)
PointerRNA * ptr
Definition wm_files.cc:4227
wmOperatorType * ot
Definition wm_files.cc:4226
bool WM_gizmomap_cursor_set(const wmGizmoMap *gzmap, wmWindow *win)
void WM_gizmomap_add_handlers(ARegion *region, wmGizmoMap *gzmap)
void WM_gizmomap_message_subscribe(const bContext *C, wmGizmoMap *gzmap, ARegion *region, wmMsgBus *mbus)
wmGizmoMap * WM_gizmomap_new_from_type(const wmGizmoMapType_Params *gzmap_params)
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:893
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value)
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct)
void wmOrtho2_region_pixelspace(const ARegion *region)
bool WM_toolsystem_refresh_screen_area(WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
bool WM_window_is_fullscreen(const wmWindow *win)
int WM_window_native_pixel_x(const wmWindow *win)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
eWM_CapabilitiesFlag WM_capabilities_flag()
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
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)
void WM_window_title(wmWindowManager *wm, wmWindow *win, const char *title)
Definition wm_window.cc:489
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bScreen * WM_window_get_active_screen(const wmWindow *win)
uint8_t flag
Definition wm_window.cc:139