Blender V5.3
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.hh"
18#include "BLI_listbase.hh"
19#include "BLI_math_vector_c.hh"
20#include "BLI_rand.hh"
21#include "BLI_string.hh"
22#include "BLI_string_utf8.hh"
23#include "BLI_string_utils.hh"
24#include "BLI_utildefines.hh"
25
26#include "BKE_context.hh"
27#include "BKE_global.hh"
28#include "BKE_screen.hh"
29#include "BKE_workspace.hh"
30
31#include "RNA_access.hh"
32
33#include "WM_api.hh"
34#include "WM_message.hh"
35#include "WM_toolsystem.hh"
36#include "WM_types.hh"
37
38#include "ED_asset_shelf.hh"
39#include "ED_buttons.hh"
40#include "ED_image.hh"
41#include "ED_ime.hh"
42#include "ED_screen.hh"
43#include "ED_screen_types.hh"
44#include "ED_space_api.hh"
45#include "ED_time_scrub_ui.hh"
46#include "ED_userpref.hh"
47#include "ED_view3d.hh"
48
49#include "GPU_framebuffer.hh"
50#include "GPU_immediate.hh"
51#include "GPU_immediate_util.hh"
52#include "GPU_matrix.hh"
53#include "GPU_platform.hh"
54#include "GPU_state.hh"
55
56#include "BLF_api.hh"
57
58#include "IMB_metadata.hh"
59
60#include "UI_interface.hh"
61#include "UI_interface_c.hh"
62#include "UI_interface_icons.hh"
64#include "UI_resources.hh"
65#include "UI_view2d.hh"
66
67#include "screen_intern.hh"
68
69namespace blender {
70
71/* -------------------------------------------------------------------- */
74
75static void region_draw_gradient(const ARegion *region)
76{
77 if (region->v2d.cur.xmax >= region->v2d.tot.xmax) {
78 /* No overflow. */
79 return;
80 }
81
82 float opaque[4];
84 float transparent[4];
86 transparent[3] = 0.0f;
87
88 rctf rect{};
89 rect.xmax = BLI_rcti_size_x(&region->winrct) + 1;
90 rect.xmin = rect.xmax - (25.0f * UI_SCALE_FAC);
91 rect.ymin = 0.0f;
92 rect.ymax = BLI_rcti_size_y(&region->winrct) + 1;
93 ui::draw_roundbox_4fv_ex(&rect, opaque, transparent, 0.0f, nullptr, 0.0f, 0.0f);
94}
95
101
103{
104 ARegion *region = params->region;
105 const wmNotifier *notifier = params->notifier;
106
107 /* generic notes first */
108 switch (notifier->category) {
109 case NC_WM:
110 if (notifier->data == ND_FILEREAD) {
111 ED_region_tag_redraw(region);
112 }
113 break;
114 case NC_WINDOW:
115 ED_region_tag_redraw(region);
116 break;
117 case NC_UI:
118 if (notifier->data == ND_UI_FONT) {
120 ED_region_tag_redraw(region);
121 }
122 break;
123 }
124
125 if (region->runtime->type && region->runtime->type->listener) {
126 region->runtime->type->listener(params);
127 }
128
129 for (ui::Block &block : region->runtime->uiblocks) {
130 block_listen(&block, params);
131 }
132
133 for (uiList &list : region->ui_lists) {
134 if (list.type && list.type->listener) {
135 list.type->listener(&list, params);
136 }
137 }
138}
139
141{
142 /* no generic notes? */
143 if (params->area->type && params->area->type->listener) {
144 params->area->type->listener(params);
145 }
146}
147
149{
150 /* no generic notes? */
151 if (area->type && area->type->refresh) {
152 area->type->refresh(C, area);
153 }
154 area->do_refresh = false;
155}
156
158
159/* -------------------------------------------------------------------- */
162
166static void area_draw_azone_fullscreen(short /*x1*/, short /*y1*/, short x2, short y2, float alpha)
167{
168 ui::icon_draw_ex(x2 - U.widget_unit,
169 y2 - U.widget_unit,
170 ICON_FULLSCREEN_EXIT,
172 min_ff(alpha, 0.75f),
173 0.0f,
174 nullptr,
175 false,
177}
178
182static void area_draw_azone(ScrArea *area, ARegion *region, AZone *az)
183{
184 if (region->regiontype != RGN_TYPE_HEADER || !(U.uiflag & USER_AREA_CORNER_HANDLE)) {
185 return;
186 }
187
188 if (az->x1 < area->totrct.xmin + 1) {
189 if ((region->alignment == RGN_ALIGN_TOP && az->y2 > area->totrct.ymax - 1) ||
190 (region->alignment == RGN_ALIGN_BOTTOM && az->y1 < area->totrct.ymin + 1))
191 {
193 float(az->x1) + UI_SCALE_FAC, float(az->y1) + (6.0f * UI_SCALE_FAC), ICON_GRIP_V, 0.4f);
194 }
195 }
196}
197
201static void draw_azone_arrow(float x1, float y1, float x2, float y2, AZEdge edge)
202{
203 const float size = 0.2f * U.widget_unit;
204 const float l = 1.0f; /* arrow length */
205 const float s = 0.25f; /* arrow thickness */
206 const float hl = l / 2.0f;
207 const float points[6][2] = {
208 {0, -hl}, {l, hl}, {l - s, hl + s}, {0, s + s - hl}, {s - l, hl + s}, {-l, hl}};
209 const float center[2] = {(x1 + x2) / 2, (y1 + y2) / 2};
210
211 int axis;
212 int sign;
213 switch (edge) {
215 axis = 0;
216 sign = 1;
217 break;
219 axis = 0;
220 sign = -1;
221 break;
223 axis = 1;
224 sign = 1;
225 break;
227 axis = 1;
228 sign = -1;
229 break;
230 default:
231 BLI_assert(0);
232 return;
233 }
234
235 GPUVertFormat *format = immVertexFormat();
236 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
237
240 float color[4];
242 color[3] = 0.6f;
244
246 for (int i = 0; i < 6; i++) {
247 if (axis == 0) {
248 immVertex2f(pos, center[0] + points[i][0] * size, center[1] + points[i][1] * sign * size);
249 }
250 else {
251 immVertex2f(pos, center[0] + points[i][1] * sign * size, center[1] + points[i][0] * size);
252 }
253 }
254 immEnd();
255
258}
259
260static void region_draw_azone_tab_arrow(ScrArea *area, ARegion *region, AZone *az)
261{
263
264 /* add code to draw region hidden as 'too small' */
265 switch (az->edge) {
268 break;
271 break;
274 break;
277 break;
278 }
279
280 /* Workaround for different color spaces between normal areas and the ones using GPUViewports. */
281 float alpha = WM_region_use_viewport(area, region) ? 0.6f : 0.4f;
282 float color[4];
284 color[3] = std::max(color[3], alpha);
285
286 rctf rect{};
287 /* Hit size is a bit larger than visible background. */
288 rect.xmin = float(az->x1) + U.pixelsize;
289 rect.xmax = float(az->x2) - U.pixelsize;
290 rect.ymin = float(az->y1) + U.pixelsize;
291 rect.ymax = float(az->y2) - U.pixelsize;
292 ui::draw_roundbox_aa(&rect, true, 4.0f, color);
293
294 draw_azone_arrow(float(az->x1), float(az->y1), float(az->x2), float(az->y2), az->edge);
295}
296
298{
300}
301
302static void region_draw_azones(ScrArea *area, ARegion *region)
303{
304 if (!area) {
305 return;
306 }
307
308 GPU_line_width(1.0f);
310
312 GPU_matrix_translate_2f(-region->winrct.xmin, -region->winrct.ymin);
313
314 for (AZone &az : area->actionzones) {
315 /* test if action zone is over this region */
316 rcti azrct;
317 BLI_rcti_init(&azrct, az.x1, az.x2, az.y1, az.y2);
318
319 if (BLI_rcti_isect(&region->runtime->drawrct, &azrct, nullptr)) {
320 if (az.type == AZONE_AREA) {
321 area_draw_azone(area, region, &az);
322 }
323 else if (az.type == AZONE_REGION) {
324 if (az.region && !(az.region->flag & RGN_FLAG_POLL_FAILED)) {
325 /* only display tab or icons when the region is hidden */
327 region_draw_azone_tab_arrow(area, region, &az);
328 }
329 }
330 }
331 else if (az.type == AZONE_FULLSCREEN) {
332 if (az.alpha > 0.0f) {
333 area_draw_azone_fullscreen(az.x1, az.y1, az.x2, az.y2, az.alpha);
334 }
335 }
336 }
337 if (!IS_EQF(az.alpha, 0.0f) && ELEM(az.type, AZONE_FULLSCREEN, AZONE_REGION_SCROLL)) {
339 }
340 }
341
343
345}
346
347static void region_draw_status_text(ScrArea * /*area*/, ARegion *region)
348{
349 float header_color[4];
350 ui::theme::get_color_4fv(TH_HEADER, header_color);
351
352 /* Clear the region from the buffer. */
353 GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
354
355 /* Fill with header color when the region is not overlapped. */
356 if (!region->overlap) {
357 const rctf rect = {0.0f, float(region->winx), 0.0f, float(region->winy)};
358 ui::draw_roundbox_3fv_alpha(&rect, true, 0.0f, header_color, 1.0f);
359 }
360
361 const int fontid = BLF_set_default();
362 float x = 12.0f * UI_SCALE_FAC;
363 const float y = 0.4f * UI_UNIT_Y;
364 const float width = BLF_width(fontid, region->runtime->headerstr, BLF_DRAW_STR_DUMMY_MAX);
366
367 /* Center the text horizontally. */
368 x = (region->winx - width) / 2.0f;
369 const float pad = 5.0f * UI_SCALE_FAC;
370 const float x1 = x - pad;
371 const float x2 = x + width + pad;
372 const float y1 = 3.0f * UI_SCALE_FAC;
373 const float y2 = region->winy - (4.0f * UI_SCALE_FAC);
374 /* Ensure header_color is not too transparent. */
375 header_color[3] = std::max(header_color[3], 0.6f);
376 if (region->overlap) {
377 /* Draw a background behind the text for extra contrast. */
378 draw_roundbox_corner_set(ui::CNR_ALL);
379 const rctf rect = {x1, x2, y1, y2};
380 ui::draw_roundbox_4fv(&rect, true, 4.0f * UI_SCALE_FAC, header_color);
381 }
382
384 BLF_position(fontid, x, y, 0.0f);
386}
387
389
390/* -------------------------------------------------------------------- */
393
395 /* Follow wmMsgNotifyFn spec */
396 bContext * /*C*/,
397 wmMsgSubscribeKey * /*msg_key*/,
398 wmMsgSubscribeValue *msg_val)
399{
400 ARegion *region = static_cast<ARegion *>(msg_val->owner);
401 ED_region_tag_redraw(region);
402
403 /* This avoids _many_ situations where header/properties control display settings.
404 * the common case is space properties in the header */
406 while (region && region->prev) {
407 region = region->prev;
408 }
409 for (; region; region = region->next) {
411 ED_region_tag_redraw(region);
412 }
413 }
414 }
415}
416
418 /* Follow wmMsgNotifyFn spec */
419 bContext * /*C*/,
420 wmMsgSubscribeKey * /*msg_key*/,
421 wmMsgSubscribeValue *msg_val)
422{
423 ScrArea *area = static_cast<ScrArea *>(msg_val->user_data);
425}
426
428{
429 wmMsgBus *mbus = params->message_bus;
430 WorkSpace *workspace = params->workspace;
431 ARegion *region = params->region;
432
434 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
435 msg_sub_value_region_tag_redraw.owner = region;
436 msg_sub_value_region_tag_redraw.user_data = region;
437 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
439 mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
440}
441
443{
444 wmMsgBus *mbus = params->message_bus;
445 WorkSpace *workspace = params->workspace;
446 ARegion *region = params->region;
447
449 const char *panel_category_tool = "Tool";
450 const char *category = ui::panel_category_active_get(region, false);
451
452 bool update_region = false;
453 if (category && STREQ(category, panel_category_tool)) {
454 update_region = true;
455 }
456 else {
457 /* Check if a tool category panel is pinned and visible in another category. */
458 for (Panel &panel : region->panels) {
459 if (ui::panel_is_active(&panel) && panel.flag & PNL_PIN &&
460 STREQ(panel.type->category, panel_category_tool))
461 {
462 update_region = true;
463 break;
464 }
465 }
466 }
467
468 if (update_region) {
469 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
470 msg_sub_value_region_tag_redraw.owner = region;
471 msg_sub_value_region_tag_redraw.user_data = region;
472 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
474 mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
475 }
476}
477
479
480/* -------------------------------------------------------------------- */
483
490static bool area_is_pseudo_minimized(const ScrArea *area)
491{
492 return (area->winx < 3) || (area->winy < 3);
493}
494
496{
497 /* This is optional, only needed for dynamically sized regions. */
498 ScrArea *area = CTX_wm_area(C);
499 ARegionType *at = region->runtime->type;
500
501 if (!at->layout) {
502 return;
503 }
504
505 if (at->do_lock || (area && area_is_pseudo_minimized(area))) {
506 return;
507 }
508
509 region->runtime->do_draw |= RGN_DRAWING;
510
511 ui::theme::theme_set(area ? area->spacetype : 0, at->regionid);
512 at->layout(C, region);
513}
514
516{
517 wmWindow *win = CTX_wm_window(C);
518 ScrArea *area = CTX_wm_area(C);
519 ARegionType *at = region->runtime->type;
520
521 /* see BKE_spacedata_draw_locks() */
522 if (at->do_lock) {
523 return;
524 }
525
526 region->runtime->do_draw |= RGN_DRAWING;
527
528 /* Set viewport, scissor, ortho and region->runtime->drawrct. */
529 wmPartialViewport(&region->runtime->drawrct, &region->winrct, &region->runtime->drawrct);
530
532
533 ui::theme::theme_set(area ? area->spacetype : 0, at->regionid);
534
535 if (area && area_is_pseudo_minimized(area)) {
537 return;
538 }
539 /* optional header info instead? */
540 if (region->runtime->headerstr) {
541 region_draw_status_text(area, region);
542 }
543 else if (at->draw) {
544 at->draw(C, region);
545 }
546
547#ifdef WITH_INPUT_IME
548 /* Evaluated by the refresh below, reused by the preview so `cursor_ime` runs once per draw. */
549 ARegionIMECursor ime_cursor;
550 bool ime_cursor_is_set = false;
551
552 /* Manage the IME candidate window for the active region based on `cursor_ime`,
553 * see #ARegionIMECursorState for how each result is handled.
554 * Deferred during animation playback, keeping `do_ime` set for when it stops. */
555 if (at->cursor_ime && region->runtime->do_ime) {
556 const bScreen *screen = WM_window_get_active_screen(win);
557 if (!screen->animtimer && !screen->scrubbing && region == screen->active_region) {
558 ime_cursor_is_set = WM_window_IME_region_refresh(win, area, region, true, &ime_cursor);
559 region->runtime->do_ime = false;
560 }
561 }
562#endif
563
564 /* XXX test: add convention to end regions always in pixel space,
565 * for drawing of borders/gestures etc */
566 ED_region_pixelspace(region);
567
568 /* Remove sRGB override by rebinding the framebuffer. */
571
572#ifdef WITH_INPUT_IME
573 /* Draw over the region contents, using the pixel space set up above.
574 * Skipped whenever the refresh above was, e.g. during animation playback. */
575 if (ime_cursor_is_set) {
576 ed::ime::region_overlay_draw(win, region, U.pixelsize, ime_cursor);
577 }
578#endif
579
581
582 region_draw_azones(area, region);
583
584 /* for debugging unneeded area redraws and partial redraw */
585 if (G.debug_value == 888) {
587 GPUVertFormat *format = immVertexFormat();
588 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
591 immUniformColor4f(rng.get_float(), rng.get_float(), rng.get_float(), 0.1f);
592 immRectf(pos,
593 region->runtime->drawrct.xmin - region->winrct.xmin,
594 region->runtime->drawrct.ymin - region->winrct.ymin,
595 region->runtime->drawrct.xmax - region->winrct.xmin,
596 region->runtime->drawrct.ymax - region->winrct.ymin);
599 }
600
601 region->runtime->drawrct = rcti{};
602
604
605 if (area) {
606 const bScreen *screen = WM_window_get_active_screen(win);
607
608 /* Only region gradient for Top Bar. */
609 if ((screen->state != SCREENFULL) && area->spacetype == SPACE_TOPBAR &&
610 region->regiontype == RGN_TYPE_HEADER)
611 {
612 region_draw_gradient(region);
613 }
614 else if ((region->regiontype == RGN_TYPE_WINDOW) && (region->alignment == RGN_ALIGN_QSPLIT)) {
615
616 /* draw separating lines between the quad views */
617
618 float color[4] = {0.0f, 0.0f, 0.0f, 0.8f};
620 GPUVertFormat *format = immVertexFormat();
621 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
624 GPU_line_width(1.0f);
626 0,
627 0,
628 region->winrct.xmax - region->winrct.xmin + 1,
629 region->winrct.ymax - region->winrct.ymin + 1);
631 }
632 }
633
634 /* We may want to detach message-subscriptions from drawing. */
635 {
636 WorkSpace *workspace = CTX_wm_workspace(C);
639 Scene *scene = CTX_data_scene(C);
640 wmMsgBus *mbus = wm->runtime->message_bus;
641 WM_msgbus_clear_by_owner(mbus, region);
642
643 /* Cheat, always subscribe to this space type properties.
644 *
645 * This covers most cases and avoids copy-paste similar code for each space type.
646 */
648 {
649 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
650
651 PointerRNA ptr = RNA_pointer_create_discrete(&screen->id, RNA_Space, sl);
652
653 /* All properties for this space type. */
654 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
655 msg_sub_value_region_tag_redraw.owner = region;
656 msg_sub_value_region_tag_redraw.user_data = region;
657 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
658 WM_msg_subscribe_rna(mbus, &ptr, nullptr, &msg_sub_value_region_tag_redraw, __func__);
659 }
660
661 wmRegionMessageSubscribeParams message_subscribe_params{};
662 message_subscribe_params.context = C;
663 message_subscribe_params.message_bus = mbus;
664 message_subscribe_params.workspace = workspace;
665 message_subscribe_params.scene = scene;
666 message_subscribe_params.screen = screen;
667 message_subscribe_params.area = area;
668 message_subscribe_params.region = region;
669 ED_region_message_subscribe(&message_subscribe_params);
670 }
671}
672
674
675/* -------------------------------------------------------------------- */
678
679/* Maybe silly, but let's try for now to keep these tags protected. */
680
682{
683 /* don't tag redraw while drawing, it shouldn't happen normally
684 * but python scripts can cause this to happen indirectly */
685 if (region && !(region->runtime->do_draw & RGN_DRAWING)) {
686 /* zero region means full region redraw */
689 region->runtime->do_draw |= RGN_DRAW;
690 /* Also refresh the IME cursor position on the next draw. */
691 region->runtime->do_ime = true;
692 region->runtime->drawrct = rcti{};
693 }
694}
695
697 ARegion *region,
698 const void *data,
699 StringRefNull prop_name)
700{
701 /* Try first to open the button, otherwise try after region redraw. */
702 if (!(region->runtime->do_draw & (RGN_DRAW | RGN_DRAWING)) &&
703 ui::textbutton_activate_rna(C, region, data, prop_name.data()))
704 {
705 return;
706 }
707 region->runtime->post_block_layout_fns.append(
708 [data, prop_name = std::string(prop_name), found = false](const bContext &C,
709 ui::Block &block) mutable {
710 ARegion *region = CTX_wm_region(&C);
711 found = found || ui::textbutton_activate_rna(&C, region, data, prop_name.c_str(), block);
712 });
713
714 if (region->flag & RGN_FLAG_HIDDEN) {
715 ED_region_toggle_hidden(C, region);
716 }
717 ED_region_tag_redraw(region);
718}
719
721{
722 if (region) {
724 }
725}
726
728{
729 if (region && !(region->runtime->do_draw & (RGN_DRAWING | RGN_DRAW))) {
732 /* Also refresh the IME cursor position on the next draw. */
733 region->runtime->do_ime = true;
734 region->runtime->drawrct = rcti{};
735 }
736}
737
739{
740 if (region) {
741 region->runtime->do_draw |= RGN_REFRESH_UI;
742 }
743}
744
746{
747 if (region && !(region->runtime->do_draw & (RGN_DRAWING | RGN_DRAW))) {
748 if (region->runtime->do_draw & RGN_DRAW_PARTIAL) {
749 ED_region_tag_redraw(region);
750 }
751 else {
753 }
754 }
755}
756
757void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
758{
759 if (region && !(region->runtime->do_draw & RGN_DRAWING)) {
760 if (region->runtime->do_draw & RGN_DRAW_PARTIAL) {
761 /* Partial redraw already set, expand region. */
762 BLI_rcti_union(&region->runtime->drawrct, rct);
763 if (rebuild) {
765 }
766 }
767 else if (region->runtime->do_draw & (RGN_DRAW | RGN_DRAW_NO_REBUILD)) {
768 /* Full redraw already requested. */
769 if (rebuild) {
771 }
772 }
773 else {
774 /* No redraw set yet, set partial region. */
775 region->runtime->drawrct = *rct;
776 region->runtime->do_draw |= RGN_DRAW_PARTIAL;
777 if (!rebuild) {
779 }
780 }
781 }
782}
783
785{
786 if (area) {
787 for (ARegion &region : area->regionbase) {
788 ED_region_tag_redraw(&region);
789 }
790 }
791}
792
794{
795 if (area) {
796 for (ARegion &region : area->regionbase) {
798 }
799 }
800}
801
802void ED_area_tag_redraw_regiontype(ScrArea *area, int regiontype)
803{
804 if (area) {
805 for (ARegion &region : area->regionbase) {
806 if (region.regiontype == regiontype) {
807 ED_region_tag_redraw(&region);
808 }
809 }
810 }
811}
812
814{
815 if (area) {
816 area->do_refresh = true;
817 }
818}
819
821{
822 if (!area || (area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
823 return;
824 }
825
827
828 /* Floating regions don't affect other regions, so the following can be skipped. */
829 if (changed_region->alignment == RGN_ALIGN_FLOAT) {
830 return;
831 }
832
833 /* Tag the following regions for redraw, since the size change of this region may affect the
834 * available space for them. */
835 for (ARegion *following_region = changed_region->next; following_region;
836 following_region = following_region->next)
837 {
838 /* Overlapping and non-overlapping regions don't affect each others space. So layout changes
839 * of one don't require redrawing the other. */
840 if (changed_region->overlap != following_region->overlap) {
841 continue;
842 }
843 /* Floating regions don't affect space of other regions. */
844 if (following_region->alignment == RGN_ALIGN_FLOAT) {
845 continue;
846 }
847 ED_region_tag_redraw(following_region);
848 }
849}
850
852 ARegion *changed_region,
853 const bool set_padding)
854{
856 if (hud_region == nullptr) {
857 return;
858 }
859
860 if (set_padding != bool(hud_region->runtime->flag & bke::ARegionRuntimeFlag::HUD_PADDING)) {
862 hud_region->runtime->flag, set_padding, bke::ARegionRuntimeFlag::HUD_PADDING);
863 ED_area_tag_region_size_update(area, changed_region);
864 }
865}
866
868
869/* -------------------------------------------------------------------- */
872
873int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
874{
875 int dist;
876
877 /* regions in regions. */
878 if (scale_region->alignment & RGN_SPLIT_PREV) {
879 const int align = RGN_ALIGN_ENUM_FROM_MASK(scale_region->alignment);
880
881 if (ELEM(align, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
882 ARegion *region = scale_region->prev;
883 dist = region->winy + scale_region->winy - U.pixelsize;
884 }
885 else /* if (ELEM(align, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) */ {
886 ARegion *region = scale_region->prev;
887 dist = region->winx + scale_region->winx - U.pixelsize;
888 }
889 }
890 else {
892 dist = BLI_rcti_size_x(&area->totrct);
893 }
894 else { /* AE_BOTTOM_TO_TOPLEFT, AE_TOP_TO_BOTTOMRIGHT */
895 dist = BLI_rcti_size_y(&area->totrct);
896 }
897
898 /* Subtract the width of regions on opposite side
899 * prevents dragging regions into other opposite regions. */
900 for (ARegion &region : area->regionbase) {
901 if (&region == scale_region) {
902 continue;
903 }
904
905 if (scale_region->alignment == RGN_ALIGN_LEFT && region.alignment == RGN_ALIGN_RIGHT) {
906 dist -= region.winx;
907 }
908 else if (scale_region->alignment == RGN_ALIGN_RIGHT && region.alignment == RGN_ALIGN_LEFT) {
909 dist -= region.winx;
910 }
911 else if (scale_region->alignment == RGN_ALIGN_TOP &&
912 (region.alignment == RGN_ALIGN_BOTTOM || ELEM(region.regiontype,
917 {
918 dist -= region.winy;
919 }
920 else if (scale_region->alignment == RGN_ALIGN_BOTTOM &&
921 (region.alignment == RGN_ALIGN_TOP || ELEM(region.regiontype,
926 {
927 dist -= region.winy;
928 }
929 }
930 }
931
932 dist /= UI_SCALE_FAC;
933 return dist;
934}
935
936const char *ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region)
937{
939 return region->runtime->search_filter.c_str();
940 }
941 if (area->spacetype == SPACE_PROPERTIES) {
942 SpaceProperties *sbuts = area->spacedata.first_as<SpaceProperties>();
943 if (region->regiontype == RGN_TYPE_WINDOW) {
944 return ED_buttons_search_string_get(sbuts);
945 }
946 }
947 else if (area->spacetype == SPACE_USERPREF) {
948 SpaceUserPref *sprefs = area->spacedata.first_as<SpaceUserPref>();
949 if (region->regiontype == RGN_TYPE_WINDOW) {
950 return ED_userpref_search_string_get(sprefs);
951 }
952 }
953
954 return nullptr;
955}
956
958{
960
961 const char *search_filter = ED_area_region_search_filter_get(area, region);
962 SET_FLAG_FROM_TEST(region->flag,
964 region->regiontype == RGN_TYPE_WINDOW) &&
965 search_filter && search_filter[0] != '\0',
967}
968
970
971/* -------------------------------------------------------------------- */
974
975void ED_area_status_text(ScrArea *area, const char *str)
976{
977 /* happens when running transform operators in background mode */
978 if (area == nullptr) {
979 return;
980 }
981
982 ARegion *ar = nullptr;
983
984 for (ARegion &region : area->regionbase) {
985 if (region.regiontype == RGN_TYPE_HEADER && region.runtime->visible) {
986 ar = &region;
987 }
988 else if (region.regiontype == RGN_TYPE_TOOL_HEADER && region.runtime->visible) {
989 /* Prefer tool header when we also have a header. */
990 ar = &region;
991 break;
992 }
993 }
994
995 if (ar) {
996 if (str) {
997 if (ar->runtime->headerstr == nullptr) {
999 }
1002 }
1003 else {
1004 MEM_SAFE_DELETE(ar->runtime->headerstr);
1005 }
1007 }
1008}
1009
1011 std::string text,
1012 const int icon,
1013 const float space_factor = 0.0f,
1014 const bool inverted = false)
1015{
1016 /* Can be nullptr when running operators in background mode. */
1017 if (workspace == nullptr) {
1018 return;
1019 }
1020
1022 item.text = std::move(text);
1023 item.icon = icon;
1024 item.space_factor = space_factor;
1025 item.inverted = inverted;
1026 workspace->runtime->status.append(std::move(item));
1027}
1028
1029static void ed_workspace_status_space(WorkSpace *workspace, const float space_factor)
1030{
1031 ed_workspace_status_item(workspace, {}, ICON_NONE, space_factor);
1032}
1033
1035{
1036 workspace_ = CTX_wm_workspace(C);
1037 wm_ = CTX_wm_manager(C);
1038 if (workspace_) {
1039 BKE_workspace_status_clear(workspace_);
1040 }
1042}
1043
1044static constexpr float STATUS_BEFORE_TEXT = 0.17f;
1045static constexpr float STATUS_AFTER_TEXT = 0.90f;
1046static constexpr float STATUS_MOUSE_ICON_PAD = -0.68f;
1047
1048static void ed_workspace_status_text_item(WorkSpace *workspace, std::string text)
1049{
1050 if (!text.empty()) {
1052 ed_workspace_status_item(workspace, std::move(text), ICON_NONE);
1054 }
1055}
1056
1058 const int icon,
1059 const bool inverted = false)
1060{
1061 if (icon) {
1062 ed_workspace_status_item(workspace, {}, icon, 0.0f, inverted);
1063 if (icon >= ICON_MOUSE_LMB && icon <= ICON_MOUSE_MMB_SCROLL) {
1064 /* Negative space after narrow mice icons. */
1066 }
1067 }
1068}
1069
1071
1072/* -------------------------------------------------------------------- */
1075
1076void WorkspaceStatus::item(std::string text, const int icon1, const int icon2)
1077{
1078 ed_workspace_status_icon_item(workspace_, icon1);
1079 ed_workspace_status_icon_item(workspace_, icon2);
1080 ed_workspace_status_text_item(workspace_, std::move(text));
1081}
1082
1084{
1085 ed_workspace_status_space(workspace_, factor);
1086}
1087
1088void WorkspaceStatus::range(std::string text, const int icon1, const int icon2)
1089{
1090 ed_workspace_status_item(workspace_, {}, icon1);
1091 ed_workspace_status_item(workspace_, "-", ICON_NONE);
1092 ed_workspace_status_space(workspace_, -0.5f);
1093 ed_workspace_status_item(workspace_, {}, icon2);
1094 ed_workspace_status_text_item(workspace_, std::move(text));
1095}
1096
1097void WorkspaceStatus::item_bool(std::string text,
1098 const bool inverted,
1099 const int icon1,
1100 const int icon2)
1101{
1102 ed_workspace_status_icon_item(workspace_, icon1, inverted);
1103 ed_workspace_status_icon_item(workspace_, icon2, inverted);
1104 ed_workspace_status_text_item(workspace_, std::move(text));
1105}
1106
1107void WorkspaceStatus::opmodal(std::string text,
1108 const wmOperatorType *ot,
1109 const int propvalue,
1110 const bool inverted)
1111{
1112 const wmKeyMap *keymap = WM_keymap_active(wm_, ot->modalkeymap);
1113 if (keymap == nullptr) {
1114 return;
1115 }
1116 this->modal_keymap(std::move(text), *keymap, propvalue, inverted);
1117}
1118
1119void WorkspaceStatus::modal_keymap(std::string text,
1120 const wmKeyMap &keymap,
1121 const int propvalue,
1122 const bool inverted)
1123{
1124 const wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(&keymap, propvalue);
1125 if (kmi == nullptr) {
1126 return;
1127 }
1128
1129#ifdef WITH_HEADLESS
1130 int icon = 0;
1131#else
1132 int icon = ui::icon_from_event_type(kmi->type, kmi->val);
1133#endif
1134 if (kmi->shift == KM_MOD_HELD) {
1135 ed_workspace_status_item(workspace_, {}, ICON_EVENT_SHIFT, 0.0f, inverted);
1136 }
1137 if (kmi->ctrl == KM_MOD_HELD) {
1138 ed_workspace_status_item(workspace_, {}, ICON_EVENT_CTRL, 0.0f, inverted);
1139 }
1140 if (kmi->alt == KM_MOD_HELD) {
1141 ed_workspace_status_item(workspace_, {}, ICON_EVENT_ALT, 0.0f, inverted);
1142 }
1143 if (kmi->oskey == KM_MOD_HELD) {
1144 ed_workspace_status_item(workspace_, {}, ICON_EVENT_OS, 0.0f, inverted);
1145 }
1146 if (!ELEM(kmi->hyper, KM_NOTHING, KM_ANY)) {
1147 ed_workspace_status_item(workspace_, {}, ICON_EVENT_HYPER, 0.0f, inverted);
1148 }
1149 ed_workspace_status_icon_item(workspace_, icon, inverted);
1150 ed_workspace_status_text_item(workspace_, std::move(text));
1151}
1152
1154{
1155 WorkspaceStatus status(C);
1156 status.item(str ? str : "", ICON_NONE);
1157}
1158
1160
1161/* -------------------------------------------------------------------- */
1164
1165static void area_azone_init(const wmWindow *win, const bScreen *screen, ScrArea *area)
1166{
1167 /* reinitialize entirely, regions and full-screen add azones too */
1168 area->actionzones.free_no_destruct();
1169
1170 if (screen->state != SCREENNORMAL) {
1171 return;
1172 }
1173
1174 if (U.app_flag & USER_APP_LOCK_CORNER_SPLIT) {
1175 return;
1176 }
1177
1178 if (ED_area_is_global(area)) {
1179 return;
1180 }
1181
1182 if (screen->temp) {
1183 return;
1184 }
1185
1186 /* Use a taller zone on the left side, the height of
1187 * the header, to make them easier to hit. The others
1188 * on the right are shorter to not interfere with
1189 * scroll bars. */
1190
1191 const float coords[4][4] = {
1192 /* Bottom-left. */
1193 {area->totrct.xmin - U.pixelsize,
1194 area->totrct.ymin - U.pixelsize,
1196 float(area->totrct.ymin + ED_area_headersize())},
1197 /* Bottom-right. */
1199 area->totrct.ymin - U.pixelsize,
1200 area->totrct.xmax + U.pixelsize,
1201 area->totrct.ymin + UI_AZONESPOTH},
1202 /* Top-left. */
1203 {area->totrct.xmin - U.pixelsize,
1206 area->totrct.ymax + U.pixelsize},
1207 /* Top-right. */
1209 area->totrct.ymax - UI_AZONESPOTH,
1210 area->totrct.xmax + U.pixelsize,
1211 area->totrct.ymax + U.pixelsize},
1212 };
1213
1214 for (int i = 0; i < 4; i++) {
1215 /* can't click on bottom corners on OS X, already used for resizing */
1216#ifdef __APPLE__
1217 if (!WM_window_is_fullscreen(win) &&
1218 ((coords[i][0] == 0 && coords[i][1] == 0) ||
1219 (coords[i][0] == WM_window_native_pixel_x(win) && coords[i][1] == 0)))
1220 {
1221 continue;
1222 }
1223#else
1224 (void)win;
1225#endif
1226
1227 /* set area action zones */
1228 AZone *az = MEM_new<AZone>("actionzone");
1229 BLI_addtail(&(area->actionzones), az);
1230 az->type = AZONE_AREA;
1231 az->x1 = coords[i][0];
1232 az->y1 = coords[i][1];
1233 az->x2 = coords[i][2];
1234 az->y2 = coords[i][3];
1235 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1236 }
1237}
1238
1239static void fullscreen_azone_init(ScrArea *area, ARegion *region)
1240{
1242 return;
1243 }
1244
1245 AZone *az = MEM_new<AZone>("fullscreen action zone");
1246 BLI_addtail(&(area->actionzones), az);
1247 az->type = AZONE_FULLSCREEN;
1248 az->region = region;
1249 az->alpha = 0.0f;
1250
1251 if (U.uiflag2 & USER_REGION_OVERLAP) {
1252 const rcti *rect_visible = ED_region_visible_rect(region);
1253 az->x2 = region->winrct.xmin + rect_visible->xmax;
1254 az->y2 = region->winrct.ymin + rect_visible->ymax;
1255 }
1256 else {
1257 az->x2 = region->winrct.xmax;
1258 az->y2 = region->winrct.ymax;
1259 }
1260 az->x1 = az->x2 - AZONEFADEOUT;
1261 az->y1 = az->y2 - AZONEFADEOUT;
1262
1263 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1264}
1265
1266static void quadview_azone_init(ScrArea *area, ARegion *region)
1267{
1268 AZone *az = MEM_new_zeroed<AZone>("Quad View action zone");
1269 BLI_addtail(&(area->actionzones), az);
1270 az->type = AZONE_REGION_QUAD;
1271 az->region = region;
1272 const int half_line = int(floor(U.pixelsize / 2.0f));
1273 const int padding = int((UI_SCALE_FAC + U.pixelsize) * 2.0f) + half_line;
1274 az->x1 = region->winrct.xmax - padding + 1;
1275 az->y1 = region->winrct.ymax - padding + 1;
1276 az->x2 = region->winrct.xmax + padding + 1;
1277 az->y2 = region->winrct.ymax + padding + 1;
1278 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1279}
1280
1286static bool region_background_is_transparent(const ScrArea *area, const ARegion *region)
1287{
1288 /* Ensure the right theme is active, may not be the case on startup, for example. */
1289 ui::theme::bThemeState theme_state;
1290 ui::theme::theme_store(&theme_state);
1292
1293 uchar back[4];
1295
1296 ui::theme::theme_restore(&theme_state);
1297
1298 return back[3] < 50;
1299}
1300
1301static void region_azone_edge(const ScrArea *area, AZone *az, const ARegion *region)
1302{
1303 /* Narrow regions like headers need a smaller hit-space that
1304 * does not interfere with content. */
1305 const bool is_narrow = RGN_TYPE_IS_HEADER_ANY(region->regiontype);
1306 const bool transparent = !is_narrow && region->overlap &&
1308
1309 /* Only scale the padding inside the region, not outside. */
1310 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
1311 (BLI_rcti_size_y(&region->v2d.mask) + 1);
1312
1313 /* Different padding inside and outside the region. */
1314 const int pad_out = (is_narrow ? 2.0f : 3.0f) * UI_SCALE_FAC;
1315 const int pad_in = (is_narrow ? 1.0f : (transparent ? 8.0f : 4.0f)) * UI_SCALE_FAC / aspect;
1316
1317 switch (az->edge) {
1319 az->x1 = region->winrct.xmin;
1320 az->y1 = region->winrct.ymax + pad_out;
1321 az->x2 = region->winrct.xmax;
1322 az->y2 = region->winrct.ymax - pad_in;
1323 break;
1325 az->x1 = region->winrct.xmin;
1326 az->y1 = region->winrct.ymin + pad_out;
1327 az->x2 = region->winrct.xmax;
1328 az->y2 = region->winrct.ymin - pad_in;
1329 break;
1331 az->x1 = region->winrct.xmin - pad_out;
1332 az->y1 = region->winrct.ymin;
1333 az->x2 = region->winrct.xmin + pad_in;
1334 az->y2 = region->winrct.ymax;
1335 break;
1337 az->x1 = region->winrct.xmax - pad_in;
1338 az->y1 = region->winrct.ymin;
1339 az->x2 = region->winrct.xmax + pad_out;
1340 az->y2 = region->winrct.ymax;
1341 break;
1342 }
1343 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1344}
1345
1346/* region already made zero sized, in shape of edge */
1347static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region)
1348{
1349 float edge_offset = 1.0f;
1350 const float tab_size_x = 1.0f * U.widget_unit;
1351 const float tab_size_y = 0.5f * U.widget_unit;
1352
1353 switch (az->edge) {
1354 case AE_TOP_TO_BOTTOMRIGHT: {
1355 int add = (region->winrct.ymax == area->totrct.ymin) ? 1 : 0;
1356 az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x);
1357 az->y1 = region->winrct.ymax - U.pixelsize;
1358 az->x2 = region->winrct.xmax - (edge_offset * tab_size_x);
1359 az->y2 = region->winrct.ymax - add + tab_size_y;
1360 break;
1361 }
1363 az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x);
1364 az->y1 = region->winrct.ymin - tab_size_y;
1365 az->x2 = region->winrct.xmax - (edge_offset * tab_size_x);
1366 az->y2 = region->winrct.ymin + U.pixelsize;
1367 break;
1369 az->x1 = region->winrct.xmin - tab_size_y;
1370 az->y1 = region->winrct.ymax - ((edge_offset + 1.0f) * tab_size_x);
1371 az->x2 = region->winrct.xmin + U.pixelsize;
1372 az->y2 = region->winrct.ymax - (edge_offset * tab_size_x);
1373 break;
1375 az->x1 = region->winrct.xmax - U.pixelsize;
1376 az->y1 = region->winrct.ymax - ((edge_offset + 1.0f) * tab_size_x);
1377 az->x2 = region->winrct.xmax + tab_size_y;
1378 az->y2 = region->winrct.ymax - (edge_offset * tab_size_x);
1379 break;
1380 }
1381 /* rect needed for mouse pointer test */
1382 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
1383}
1384
1385static bool region_azone_edge_poll(const ScrArea *area,
1386 const ARegion *region,
1387 const bool is_fullscreen)
1388{
1389 if (region->flag & RGN_FLAG_POLL_FAILED) {
1390 return false;
1391 }
1392
1393 if (area->winy < int(float(ED_area_headersize()) * 1.5f)) {
1394 return false;
1395 }
1396
1397 /* Don't use edge if the region hides with previous region which is now hidden. See #116196. */
1398 if ((region->alignment & (RGN_SPLIT_PREV | RGN_ALIGN_HIDE_WITH_PREV) && region->prev) &&
1400 {
1401 return false;
1402 }
1403
1404 const bool is_hidden = (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1405
1406 if (is_hidden && is_fullscreen) {
1407 return false;
1408 }
1409 if (!is_hidden && ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) {
1410 return false;
1411 }
1412 if (!is_hidden && region->regiontype == RGN_TYPE_NAV_BAR && area->spacetype == SPACE_PROPERTIES)
1413 {
1414 return false;
1415 }
1416
1417 if (is_hidden && (U.app_flag & USER_APP_HIDE_REGION_TOGGLE)) {
1418 return false;
1419 }
1420
1421 if (!is_hidden && (U.app_flag & USER_APP_LOCK_EDGE_RESIZE)) {
1422 return false;
1423 }
1424
1425 return true;
1426}
1427
1429 ARegion *region,
1430 AZEdge edge,
1431 const bool is_fullscreen)
1432{
1433 const bool is_hidden = (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1434
1435 if (!region_azone_edge_poll(area, region, is_fullscreen)) {
1436 return;
1437 }
1438
1439 AZone *az = MEM_new<AZone>("actionzone");
1440 BLI_addtail(&(area->actionzones), az);
1441 az->type = AZONE_REGION;
1442 az->region = region;
1443 az->edge = edge;
1444
1445 if (is_hidden) {
1446 region_azone_tab_plus(area, az, region);
1447 }
1448 else {
1449 region_azone_edge(area, az, region);
1450 }
1451}
1452
1454 ARegion *region,
1455 AZScrollDirection direction)
1456{
1457 AZone *az = MEM_new<AZone>(__func__);
1458
1459 BLI_addtail(&area->actionzones, az);
1461 az->region = region;
1462 az->direction = direction;
1463
1464 if (direction == AZ_SCROLL_VERT) {
1465 az->region->v2d.alpha_vert = 0;
1466 }
1467 else if (direction == AZ_SCROLL_HOR) {
1468 az->region->v2d.alpha_hor = 0;
1469 }
1470
1471 /* No need to specify rect for scrollbar az. For intersection we'll test against the area around
1472 * the region's scroller instead, in `area_actionzone_get_rect`. */
1473}
1474
1476{
1477 const View2D *v2d = &region->v2d;
1478
1479 if (v2d->scroll & V2D_SCROLL_VERTICAL) {
1481 }
1482 if (v2d->scroll & V2D_SCROLL_HORIZONTAL) {
1484 }
1485}
1486
1488 ARegion *region,
1489 const int alignment,
1490 const bool is_fullscreen)
1491{
1492
1493 /* edge code (t b l r) is along which area edge azone will be drawn */
1494 if (alignment == RGN_ALIGN_TOP) {
1495 region_azone_edge_init(area, region, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
1496 }
1497 else if (alignment == RGN_ALIGN_BOTTOM) {
1498 region_azone_edge_init(area, region, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
1499 }
1500 else if (alignment == RGN_ALIGN_RIGHT) {
1501 region_azone_edge_init(area, region, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
1502 }
1503 else if (alignment == RGN_ALIGN_LEFT) {
1504 region_azone_edge_init(area, region, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
1505 }
1506}
1507
1508static void region_azones_add(const bScreen *screen, ScrArea *area, ARegion *region)
1509{
1510 const bool is_fullscreen = screen->state == SCREENFULL;
1511
1512 /* Only display tab or icons when the header region is hidden
1513 * (not the tool header - they overlap). */
1514 if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
1515 return;
1516 }
1517
1518 /* Quad View center resizing zone. */
1519 if (region->alignment == RGN_ALIGN_QSPLIT &&
1521 {
1522 quadview_azone_init(area, region);
1523 }
1524
1525 region_azones_add_edge(area, region, RGN_ALIGN_ENUM_FROM_MASK(region->alignment), is_fullscreen);
1526
1527 /* For a split region also continue the azone edge from the next region if this region is aligned
1528 * with the next */
1529 if ((region->alignment & RGN_SPLIT_PREV) && region->prev) {
1531 area, region, RGN_ALIGN_ENUM_FROM_MASK(region->prev->alignment), is_fullscreen);
1532 }
1533
1534 if (is_fullscreen) {
1535 fullscreen_azone_init(area, region);
1536 }
1537
1538 region_azones_scrollbars_init(area, region);
1539}
1540
1542
1543/* -------------------------------------------------------------------- */
1546
1547/* dir is direction to check, not the splitting edge direction! */
1548static int rct_fits(const rcti *rect, const eScreenAxis dir_axis, int size)
1549{
1550 if (dir_axis == SCREEN_AXIS_H) {
1551 return BLI_rcti_size_x(rect) + 1 - size;
1552 }
1553 /* Vertical. */
1554 return BLI_rcti_size_y(rect) + 1 - size;
1555}
1556
1557/* Only for internal area management functions that act before #ARegionRuntime.visible is
1558 * updated. */
1559static bool region_is_hidden(const ARegion *region)
1560{
1561 if (region->flag & RGN_FLAG_HIDDEN) {
1562 return true;
1563 }
1564 if (region->alignment & RGN_ALIGN_HIDE_WITH_PREV) {
1565 return region->prev && (region->prev->flag & RGN_FLAG_HIDDEN);
1566 }
1567 return false;
1568}
1569
1570/* region should be overlapping */
1571/* function checks if some overlapping region was defined before - on same place */
1572static void region_overlap_fix(ScrArea *area, ARegion *region)
1573{
1574 /* find overlapping previous region on same place */
1575 ARegion *region_iter;
1576 int align1 = 0;
1577 const int align = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
1578 for (region_iter = region->prev; region_iter; region_iter = region_iter->prev) {
1579 if (region_is_hidden(region_iter)) {
1580 continue;
1581 }
1582 if (region_iter->flag & RGN_FLAG_POLL_FAILED) {
1583 continue;
1584 }
1585 if (!region_iter->overlap || (region_iter->alignment & RGN_SPLIT_PREV)) {
1586 continue;
1587 }
1588
1589 const int align_iter = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
1590 if (ELEM(align_iter, RGN_ALIGN_FLOAT)) {
1591 continue;
1592 }
1593
1594 align1 = align_iter;
1595 if (BLI_rcti_isect(&region_iter->winrct, &region->winrct, nullptr)) {
1596 if (align1 != align) {
1597 /* Left overlapping right or vice-versa, forbid this! */
1598 region->flag |= RGN_FLAG_TOO_SMALL;
1599 return;
1600 }
1601 /* Else, we have our previous region on same side. */
1602 break;
1603 }
1604 }
1605
1606 /* Guard against flags slipping through that would have to be masked out in usages below. */
1607 BLI_assert(align1 == RGN_ALIGN_ENUM_FROM_MASK(align1));
1608
1609 /* translate or close */
1610 if (region_iter) {
1611 if (align1 == RGN_ALIGN_LEFT) {
1612 if (region->winrct.xmax + region_iter->winx > area->winx - U.widget_unit) {
1613 region->flag |= RGN_FLAG_TOO_SMALL;
1614 return;
1615 }
1616 BLI_rcti_translate(&region->winrct, region_iter->winx, 0);
1617 }
1618 else if (align1 == RGN_ALIGN_RIGHT) {
1619 if (region->winrct.xmin - region_iter->winx < U.widget_unit) {
1620 region->flag |= RGN_FLAG_TOO_SMALL;
1621 return;
1622 }
1623 BLI_rcti_translate(&region->winrct, -region_iter->winx, 0);
1624 }
1625 }
1626
1627 /* At this point, 'region' is in its final position and still open.
1628 * Make a final check it does not overlap any previous 'other side' region. */
1629 for (region_iter = region->prev; region_iter; region_iter = region_iter->prev) {
1630 if (region_is_hidden(region_iter)) {
1631 continue;
1632 }
1633 if (region_iter->flag & RGN_FLAG_POLL_FAILED) {
1634 continue;
1635 }
1636 if (!region_iter->overlap || (region_iter->alignment & RGN_SPLIT_PREV)) {
1637 continue;
1638 }
1639
1640 const int align_iter = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
1641 if (ELEM(align_iter, RGN_ALIGN_FLOAT)) {
1642 continue;
1643 }
1644
1645 if ((align_iter != align) && BLI_rcti_isect(&region_iter->winrct, &region->winrct, nullptr)) {
1646 /* Left overlapping right or vice-versa, forbid this! */
1647 region->flag |= RGN_FLAG_TOO_SMALL;
1648 return;
1649 }
1650 }
1651}
1652
1653bool ED_region_is_overlap(const int spacetype, const int regiontype)
1654{
1655 if (regiontype == RGN_TYPE_HUD) {
1656 return true;
1657 }
1658 if ((U.uiflag2 & USER_REGION_OVERLAP) == 0) {
1659 return false;
1660 }
1661
1662 switch (spacetype) {
1663 case SPACE_NODE:
1664 return ELEM(regiontype,
1669
1670 case SPACE_VIEW3D:
1671 if (regiontype == RGN_TYPE_HEADER) {
1672 /* Only treat as overlapped if there is transparency. */
1673 const bTheme *theme = ui::theme::theme_get();
1674 return theme->space_view3d.header[3] != 255;
1675 }
1676 return ELEM(regiontype,
1684
1685 case SPACE_IMAGE:
1686 return ELEM(regiontype,
1694
1695 default:
1696 /* Most editors do not support any region overlap. It is fine if newly-added space types also
1697 * default to not having region overlap; this 'switch' doesn't have to be religiously updated
1698 * for every newly added type. */
1699 return false;
1700 }
1701}
1702
1704 ScrArea *area, ARegion *region, rcti *remainder, rcti *overlap_remainder, int quad)
1705{
1706 using namespace blender::ed;
1707 rcti *remainder_prev = remainder;
1708
1709 if (region == nullptr) {
1710 return;
1711 }
1712
1713 int prev_winx = region->winx;
1714 int prev_winy = region->winy;
1715
1716 /* no returns in function, winrct gets set in the end again */
1717 BLI_rcti_init(&region->winrct, 0, 0, 0, 0);
1718
1719 /* for test; allow split of previously defined region */
1720 if (region->alignment & RGN_SPLIT_PREV) {
1721 if (region->prev) {
1722 remainder = &region->prev->winrct;
1723 }
1724 }
1725
1726 int alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
1727 const bool is_hidden = region_is_hidden(region);
1728
1729 /* set here, assuming userpref switching forces to call this again */
1730 region->overlap = ED_region_is_overlap(area->spacetype, region->regiontype);
1731
1732 /* clear state flags first */
1734 /* user errors */
1735 if ((region->next == nullptr) && !ELEM(alignment, RGN_ALIGN_QSPLIT, RGN_ALIGN_FLOAT)) {
1736 alignment = RGN_ALIGN_NONE;
1737 }
1738
1739 /* If both the #ARegion.sizex/y and the #ARegionType.prefsizex/y are 0, the region is tagged as
1740 * too small, even before the layout for dynamically sized regions is created.
1741 * #wm_draw_window_offscreen() allows the layout to be created despite the #RGN_FLAG_TOO_SMALL
1742 * flag being set. But there may still be regions that don't have a separate #ARegionType.layout
1743 * callback. For those, set a default #ARegionType.prefsizex/y so they can become visible. */
1744 if ((region->flag & RGN_FLAG_DYNAMIC_SIZE) && !(region->runtime->type->layout)) {
1745 if ((region->sizex == 0) && (region->runtime->type->prefsizex == 0)) {
1746 region->runtime->type->prefsizex = AREAMINX;
1747 }
1748 if ((region->sizey == 0) && (region->runtime->type->prefsizey == 0)) {
1749 region->runtime->type->prefsizey = HEADERY;
1750 }
1751 }
1752
1753 /* `prefsizex/y`, taking into account DPI. */
1754 int prefsizex = UI_SCALE_FAC *
1755 ((region->sizex > 1) ? region->sizex + 0.5f : region->runtime->type->prefsizex);
1756 int prefsizey;
1757
1758 if (region->regiontype == RGN_TYPE_HEADER) {
1759 prefsizey = ED_area_headersize();
1760 }
1761 else if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
1762 prefsizey = ED_area_headersize();
1763 }
1764 else if (region->regiontype == RGN_TYPE_FOOTER) {
1765 prefsizey = ED_area_footersize();
1766 }
1767 else if (region->regiontype == RGN_TYPE_SCRUBBING) {
1768 prefsizey = 0.9f * ED_area_footersize();
1769 }
1770 else if (region->regiontype == RGN_TYPE_ASSET_SHELF) {
1771 prefsizey = region->sizey > 1 ? (UI_SCALE_FAC * (region->sizey + 0.5f)) :
1773 }
1774 else if (region->regiontype == RGN_TYPE_ASSET_SHELF_HEADER) {
1776 }
1777 else if (ED_area_is_global(area)) {
1778 prefsizey = ED_region_global_size_y();
1779 }
1780 else {
1781 prefsizey = UI_SCALE_FAC *
1782 (region->sizey > 1 ? region->sizey + 0.5f : region->runtime->type->prefsizey);
1783 }
1784
1785 if (is_hidden || (region->flag & RGN_FLAG_POLL_FAILED)) {
1786 /* hidden is user flag */
1787 }
1788 else if (alignment == RGN_ALIGN_FLOAT) {
1795 const int size_min[2] = {UI_UNIT_X, UI_UNIT_Y};
1796 rcti overlap_remainder_margin = *overlap_remainder;
1797
1798 BLI_rcti_resize(&overlap_remainder_margin,
1799 max_ii(0, BLI_rcti_size_x(overlap_remainder) - UI_UNIT_X / 2),
1800 max_ii(0, BLI_rcti_size_y(overlap_remainder) - UI_UNIT_Y / 2));
1801 region->winrct.xmin = overlap_remainder_margin.xmin + region->runtime->offset_x;
1802 region->winrct.ymin = overlap_remainder_margin.ymin + region->runtime->offset_y;
1804 region->winrct.ymin += UI_UNIT_Y;
1805 }
1806 region->winrct.xmax = region->winrct.xmin + prefsizex - 1;
1807 region->winrct.ymax = region->winrct.ymin + prefsizey - 1;
1808
1809 BLI_rcti_isect(&region->winrct, &overlap_remainder_margin, &region->winrct);
1810
1811 if (BLI_rcti_size_x(&region->winrct) != prefsizex - 1) {
1812 region->flag |= RGN_FLAG_SIZE_CLAMP_X;
1813 }
1814 if (BLI_rcti_size_y(&region->winrct) != prefsizey - 1) {
1815 region->flag |= RGN_FLAG_SIZE_CLAMP_Y;
1816 }
1817
1818 /* We need to use a test that won't have been previously clamped. */
1819 rcti winrct_test{};
1820 winrct_test.xmin = region->winrct.xmin;
1821 winrct_test.ymin = region->winrct.ymin;
1822 winrct_test.xmax = region->winrct.xmin + size_min[0];
1823 winrct_test.ymax = region->winrct.ymin + size_min[1];
1824
1825 BLI_rcti_isect(&winrct_test, &overlap_remainder_margin, &winrct_test);
1826 if (BLI_rcti_size_x(&winrct_test) < size_min[0] || BLI_rcti_size_y(&winrct_test) < size_min[1])
1827 {
1828 region->flag |= RGN_FLAG_TOO_SMALL;
1829 }
1830 }
1831 else if (rct_fits(remainder, SCREEN_AXIS_V, 1) < 0 || rct_fits(remainder, SCREEN_AXIS_H, 1) < 0)
1832 {
1833 /* remainder is too small for any usage */
1834 region->flag |= RGN_FLAG_TOO_SMALL;
1835 }
1836 else if (alignment == RGN_ALIGN_NONE) {
1837 /* typically last region */
1838 region->winrct = *remainder;
1839 BLI_rcti_init(remainder, 0, 0, 0, 0);
1840 }
1841 else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
1842 rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
1843
1844 if ((prefsizey == 0) || (rct_fits(winrct, SCREEN_AXIS_V, prefsizey) < (U.pixelsize * -2))) {
1845 region->flag |= RGN_FLAG_TOO_SMALL;
1846 }
1847 else {
1848 int fac = rct_fits(winrct, SCREEN_AXIS_V, prefsizey);
1849
1850 if (fac < 0) {
1851 prefsizey += fac;
1852 }
1853
1854 region->winrct = *winrct;
1855
1856 if (alignment == RGN_ALIGN_TOP) {
1857 region->winrct.ymin = region->winrct.ymax - prefsizey + 1;
1858 winrct->ymax = region->winrct.ymin - 1;
1859 }
1860 else {
1861 region->winrct.ymax = region->winrct.ymin + prefsizey - 1;
1862 winrct->ymin = region->winrct.ymax + 1;
1863 }
1864 BLI_rcti_sanitize(winrct);
1865 }
1866 }
1867 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
1868 rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
1869 const int width = BLI_rcti_size_x(winrct) + 1;
1870 if (prefsizex == 0) {
1871 region->flag |= RGN_FLAG_TOO_SMALL;
1872 }
1873 else if (width < prefsizex) {
1874 const float aspect = (region->v2d.flag & V2D_IS_INIT) ?
1875 (BLI_rctf_size_y(&region->v2d.cur) /
1876 (BLI_rcti_size_y(&region->v2d.mask) + 1)) :
1877 1.0f;
1878
1879 const bool has_tabs = BKE_regiontype_uses_category_tabs(region->runtime->type);
1880 const int min = int(UI_SCALE_FAC *
1882 aspect);
1883 if (width > min) {
1884 /* Adjust width to fit. */
1885 region->winrct = *winrct;
1886 BLI_rcti_sanitize(winrct);
1887 }
1888 else if (has_tabs) {
1889 /* Too narrow for content so show only the category tabs. */
1890 const int cat_min = int(UI_PANEL_CATEGORY_MIN_WIDTH * UI_SCALE_FAC / aspect);
1891 region->winrct = *winrct;
1892 if (alignment == RGN_ALIGN_RIGHT) {
1893 region->winrct.xmin = region->winrct.xmax - cat_min + 1;
1894 }
1895 else {
1896 region->winrct.xmax = region->winrct.xmin + cat_min - 1;
1897 }
1898 BLI_rcti_sanitize(winrct);
1899 }
1900 else {
1901 region->flag |= RGN_FLAG_TOO_SMALL;
1902 }
1903 }
1904 else {
1906 /* Update category tab width when #USER_UIFLAG2_PANEL_TABS_COMPACT flag is set/unset. */
1907 const float aspect = (region->v2d.flag & V2D_IS_INIT) ?
1908 (BLI_rctf_size_y(&region->v2d.cur) /
1909 (BLI_rcti_size_y(&region->v2d.mask) + 1)) :
1910 1.0f;
1911 const int tab_auto_snap_width = (UI_PANEL_CATEGORY_MIN_WIDTH + ui::PANEL_MIN_DRAW_WIDTH) *
1912 UI_SCALE_FAC / aspect;
1913 if (prefsizex < tab_auto_snap_width) {
1914 prefsizex = UI_PANEL_CATEGORY_MIN_WIDTH * UI_SCALE_FAC / aspect;
1915 }
1916 }
1917 int fac = rct_fits(winrct, SCREEN_AXIS_H, prefsizex);
1918
1919 if (fac < 0) {
1920 prefsizex += fac;
1921 }
1922
1923 region->winrct = *winrct;
1924
1925 if (alignment == RGN_ALIGN_RIGHT) {
1926 region->winrct.xmin = region->winrct.xmax - prefsizex + 1;
1927 winrct->xmax = region->winrct.xmin - 1;
1928 }
1929 else {
1930 region->winrct.xmax = region->winrct.xmin + prefsizex - 1;
1931 winrct->xmin = region->winrct.xmax + 1;
1932 }
1933 BLI_rcti_sanitize(winrct);
1934 }
1935 }
1936 else if (ELEM(alignment, RGN_ALIGN_VSPLIT, RGN_ALIGN_HSPLIT)) {
1937 /* Percentage subdiv. */
1938 region->winrct = *remainder;
1939
1940 if (alignment == RGN_ALIGN_HSPLIT) {
1941 if (rct_fits(remainder, SCREEN_AXIS_H, prefsizex) > 4) {
1942 region->winrct.xmax = BLI_rcti_cent_x(remainder);
1943 remainder->xmin = region->winrct.xmax + 1;
1944 }
1945 else {
1946 BLI_rcti_init(remainder, 0, 0, 0, 0);
1947 }
1948 }
1949 else {
1950 if (rct_fits(remainder, SCREEN_AXIS_V, prefsizey) > 4) {
1951 region->winrct.ymax = BLI_rcti_cent_y(remainder);
1952 remainder->ymin = region->winrct.ymax + 1;
1953 }
1954 else {
1955 BLI_rcti_init(remainder, 0, 0, 0, 0);
1956 }
1957 }
1958 }
1959 else if (alignment == RGN_ALIGN_QSPLIT) {
1960 region->winrct = *remainder;
1961
1962 /* test if there's still 4 regions left */
1963 if (quad == 0) {
1964 ARegion *region_test = region->next;
1965 int count = 1;
1966
1967 while (region_test) {
1968 region_test->alignment = RGN_ALIGN_QSPLIT;
1969 region_test = region_test->next;
1970 count++;
1971 }
1972
1973 if (count != 4) {
1974 /* let's stop adding regions */
1975 BLI_rcti_init(remainder, 0, 0, 0, 0);
1976 if (G.debug & G_DEBUG) {
1977 printf("region quadsplit failed\n");
1978 }
1979 }
1980 else {
1981 quad = 1;
1982 }
1983 }
1984 if (quad) {
1985 const float ratio_x = (area->quadview_ratio[0] != 0.0f) ? area->quadview_ratio[0] : 0.5f;
1986 const float ratio_y = (area->quadview_ratio[1] != 0.0f) ? area->quadview_ratio[1] : 0.5f;
1987 const int x = remainder->xmin + int(float(remainder->xmax - remainder->xmin) * ratio_x);
1988 const int y = remainder->ymin + int(float(remainder->ymax - remainder->ymin) * ratio_y);
1989
1991
1992 switch (region->runtime->quadview_index) {
1994 region->winrct.xmax = x;
1995 region->winrct.ymax = y;
1996 break;
1998 region->winrct.xmax = x;
1999 region->winrct.ymin = y + 1;
2000 break;
2002 region->winrct.xmin = x + 1;
2003 region->winrct.ymax = y;
2004 break;
2006 region->winrct.xmin = x + 1;
2007 region->winrct.ymin = y + 1;
2008 BLI_rcti_init(remainder, 0, 0, 0, 0);
2009 break;
2010 default:
2012 }
2013
2014 /* Fix any negative dimensions. This can happen when a quad split 3d view gets too small.
2015 * (see #72200). */
2016 BLI_rcti_sanitize(&region->winrct);
2017
2018 quad++;
2019 }
2020 }
2021
2022 /* for speedup */
2023 region->winx = BLI_rcti_size_x(&region->winrct) + 1;
2024 region->winy = BLI_rcti_size_y(&region->winrct) + 1;
2025
2026 if (region->winy <= U.border_width && !is_hidden) {
2027 /* Don't draw when just a couple pixels tall. #143617. */
2028 region->flag |= RGN_FLAG_TOO_SMALL;
2029 }
2030
2031 /* If region opened normally, we store this for hide/reveal usage. */
2032 /* Prevent rounding errors for UI_SCALE_FAC multiply and divide. */
2033 if (region->winx > 1) {
2034 region->sizex = (region->winx + 0.5f) / UI_SCALE_FAC;
2035 }
2036 if (region->winy > 1) {
2037 region->sizey = (region->winy + 0.5f) / UI_SCALE_FAC;
2038 }
2039
2040 /* exception for multiple overlapping regions on same spot */
2041 if (region->overlap && (alignment != RGN_ALIGN_FLOAT)) {
2042 region_overlap_fix(area, region);
2043 }
2044
2045 /* Set `region->winrct` for action-zones. */
2046 if (is_hidden || (region->flag & RGN_FLAG_TOO_SMALL)) {
2047 region->winrct = (region->overlap) ? *overlap_remainder : *remainder;
2048
2049 switch (alignment) {
2050 case RGN_ALIGN_TOP:
2051 region->winrct.ymin = region->winrct.ymax;
2052 break;
2053 case RGN_ALIGN_BOTTOM:
2054 region->winrct.ymax = region->winrct.ymin;
2055 break;
2056 case RGN_ALIGN_RIGHT:
2057 region->winrct.xmin = region->winrct.xmax;
2058 break;
2059 case RGN_ALIGN_LEFT:
2060 region->winrct.xmax = region->winrct.xmin;
2061 break;
2062 default:
2063 /* prevent winrct to be valid */
2064 region->winrct.xmax = region->winrct.xmin;
2065 break;
2066 }
2067
2068 /* Size on one axis is now 0, the other axis may still be invalid (negative) though. */
2069 BLI_rcti_sanitize(&region->winrct);
2070 }
2071
2072 /* restore prev-split exception */
2073 if (region->alignment & RGN_SPLIT_PREV) {
2074 if (region->prev) {
2075 remainder = remainder_prev;
2076 region->prev->winx = BLI_rcti_size_x(&region->prev->winrct) + 1;
2077 region->prev->winy = BLI_rcti_size_y(&region->prev->winrct) + 1;
2078 }
2079 }
2080
2081 /* After non-overlapping region, all following overlapping regions
2082 * fit within the remaining space again. */
2083 if (!region->overlap) {
2084 *overlap_remainder = *remainder;
2085 }
2086
2088
2089 region_rect_recursive(area, region->next, remainder, overlap_remainder, quad);
2090
2091 /* Tag for redraw if size changes. */
2092 if (region->winx != prev_winx || region->winy != prev_winy) {
2093 /* 3D View needs a full rebuild in case a progressive render runs. Rest can live with
2094 * no-rebuild (e.g. Outliner) */
2095 if (area->spacetype == SPACE_VIEW3D) {
2096 ED_region_tag_redraw(region);
2097 }
2098 else {
2100 }
2101 }
2102
2103 /* Clear, initialize on demand. */
2104 region->runtime->visible_rect = rcti{};
2105}
2106
2107static void area_calc_totrct(const bScreen *screen, ScrArea *area, const rcti *window_rect)
2108{
2109 /* Padding around each area, except at window edges. */
2110 const short px = short(std::max(float(U.border_width) * UI_SCALE_FAC, UI_SCALE_FAC));
2111
2112 /* Padding at window edges. Cannot be less than border width. */
2113 const short px_edge = short(std::min(UI_SCALE_FAC * 2.0f, float(U.border_width) * UI_SCALE_FAC));
2114
2115 area->totrct.xmin = area->v1->vec.x;
2116 area->totrct.xmax = area->v4->vec.x;
2117 area->totrct.ymin = area->v1->vec.y;
2118 area->totrct.ymax = area->v2->vec.y;
2119
2120 /* Scale down totrct by the border size on all sides not at window edges. */
2121 if (!ED_area_is_global(area) && screen->state != SCREENFULL && !(screen->temp) &&
2122 !screen->areabase.is_single())
2123 {
2124 area->totrct.xmin += (area->totrct.xmin > window_rect->xmin) ? px : px_edge;
2125 area->totrct.xmax -= (area->totrct.xmax < (window_rect->xmax - 1)) ? px : px_edge;
2126 area->totrct.ymin += (area->totrct.ymin > window_rect->ymin) ? px : px_edge;
2127
2128 if (area->totrct.ymax < (window_rect->ymax - 1)) {
2129 area->totrct.ymax -= px;
2130 }
2131 else if (!screen->areabase.is_single() || screen->state == SCREENMAXIMIZED) {
2132 /* Small gap below Top Bar. */
2133 area->totrct.ymax -= U.pixelsize;
2134 }
2135 else {
2136 area->totrct.ymax -= px_edge;
2137 }
2138 }
2139 /* Although the following asserts are correct they lead to a very unstable Blender.
2140 * And the asserts would fail even in 2.7x
2141 * (they were added in 2.8x as part of the top-bar commit).
2142 * For more details see #54864. */
2143#if 0
2144 BLI_assert(area->totrct.xmin >= 0);
2145 BLI_assert(area->totrct.xmax >= 0);
2146 BLI_assert(area->totrct.ymin >= 0);
2147 BLI_assert(area->totrct.ymax >= 0);
2148#endif
2149
2150 /* for speedup */
2151 area->winx = BLI_rcti_size_x(&area->totrct) + 1;
2152 area->winy = BLI_rcti_size_y(&area->totrct) + 1;
2153}
2154
2159{
2160 bool hidden = (region->flag & (RGN_FLAG_POLL_FAILED | RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) !=
2161 0;
2162
2163 if ((region->alignment & (RGN_SPLIT_PREV | RGN_ALIGN_HIDE_WITH_PREV)) && region->prev) {
2164 hidden = hidden || (region->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
2165 }
2166
2167 region->runtime->visible = !hidden;
2168}
2169
2171
2172/* -------------------------------------------------------------------- */
2175
2180 ScrArea *area,
2181 ARegion *region,
2182 ListBaseT<wmEventHandler> *handlers,
2183 int flag)
2184{
2185 BLI_assert(region ? (&region->runtime->handlers == handlers) : (&area->handlers == handlers));
2186
2187 /* NOTE: add-handler checks if it already exists. */
2188
2189 /* XXX: it would be good to have bound-box checks for some of these. */
2190 if (flag & ED_KEYMAP_UI) {
2191 wmKeyMap *keymap = WM_keymap_ensure(
2192 wm->runtime->defaultconf, "User Interface", SPACE_EMPTY, RGN_TYPE_WINDOW);
2193 WM_event_add_keymap_handler(handlers, keymap);
2194
2195 ListBaseT<wmDropBox> *dropboxes = WM_dropboxmap_find(
2196 "User Interface", SPACE_EMPTY, RGN_TYPE_WINDOW);
2197 WM_event_add_dropbox_handler(handlers, dropboxes);
2198
2199 /* user interface widgets */
2200 ui::region_handlers_add(handlers);
2201 }
2202 if (flag & ED_KEYMAP_GIZMO) {
2204 if (region) {
2205 /* Anything else is confusing, only allow this. */
2206 BLI_assert(&region->runtime->handlers == handlers);
2207 if (region->runtime->gizmo_map == nullptr) {
2208 wmGizmoMapType_Params params{};
2209 params.spaceid = area->spacetype;
2210 params.regionid = region->runtime->type->regionid;
2211 region->runtime->gizmo_map = WM_gizmomap_new_from_type(&params);
2212 }
2213 WM_gizmomap_add_handlers(region, region->runtime->gizmo_map);
2214 }
2215 }
2216 if (flag & ED_KEYMAP_VIEW2D) {
2217 /* 2d-viewport handling+manipulation */
2218 wmKeyMap *keymap = WM_keymap_ensure(
2219 wm->runtime->defaultconf, "View2D", SPACE_EMPTY, RGN_TYPE_WINDOW);
2220 WM_event_add_keymap_handler(handlers, keymap);
2221 }
2222 if (flag & ED_KEYMAP_ANIMATION) {
2223 wmKeyMap *keymap;
2224
2225 /* time-markers */
2226 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Markers", SPACE_EMPTY, RGN_TYPE_WINDOW);
2228
2229 /* time-scrub */
2230 keymap = WM_keymap_ensure(
2231 wm->runtime->defaultconf, "Time Scrub", SPACE_EMPTY, RGN_TYPE_WINDOW);
2233
2234 /* frame changing and timeline operators (for time spaces) */
2235 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Animation", SPACE_EMPTY, RGN_TYPE_WINDOW);
2236 WM_event_add_keymap_handler(handlers, keymap);
2237 }
2238 if (flag & ED_KEYMAP_TOOL) {
2239 if (flag & ED_KEYMAP_GIZMO) {
2242 }
2243 else {
2246 }
2247 }
2248 if (flag & ED_KEYMAP_FRAMES) {
2249 /* frame changing/jumping (for all spaces) */
2250 wmKeyMap *keymap = WM_keymap_ensure(
2251 wm->runtime->defaultconf, "Frames", SPACE_EMPTY, RGN_TYPE_WINDOW);
2252 WM_event_add_keymap_handler(handlers, keymap);
2253 }
2254 if (flag & ED_KEYMAP_HEADER) {
2255 /* standard keymap for headers regions */
2256 wmKeyMap *keymap = WM_keymap_ensure(
2257 wm->runtime->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2258 WM_event_add_keymap_handler(handlers, keymap);
2259 }
2260 if (flag & ED_KEYMAP_FOOTER) {
2261 /* standard keymap for footer regions */
2262 wmKeyMap *keymap = WM_keymap_ensure(
2263 wm->runtime->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2264 WM_event_add_keymap_handler(handlers, keymap);
2265 }
2266 if (flag & ED_KEYMAP_NAVBAR) {
2267 /* standard keymap for Navigation bar regions */
2268 wmKeyMap *keymap = WM_keymap_ensure(
2269 wm->runtime->defaultconf, "Region Context Menu", SPACE_EMPTY, RGN_TYPE_WINDOW);
2270 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
2271 }
2272 if (flag & ED_KEYMAP_ASSET_SHELF) {
2273 /* standard keymap for asset shelf regions */
2274 wmKeyMap *keymap = WM_keymap_ensure(
2275 wm->runtime->defaultconf, "Asset Shelf", SPACE_EMPTY, RGN_TYPE_WINDOW);
2276 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
2277 }
2278
2279 /* Keep last because of LMB/RMB handling, see: #57527. */
2280 if (flag & ED_KEYMAP_GPENCIL) {
2281 /* grease pencil */
2282 {
2283 wmKeyMap *keymap = WM_keymap_ensure(
2284 wm->runtime->defaultconf, "Grease Pencil", SPACE_EMPTY, RGN_TYPE_WINDOW);
2285 WM_event_add_keymap_handler(handlers, keymap);
2286 }
2287 }
2288}
2289
2291{
2292 if (!(area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
2293 return;
2294 }
2295 const bScreen *screen = WM_window_get_active_screen(win);
2296
2297 rcti window_rect;
2298 WM_window_screen_rect_calc(win, &window_rect);
2299 area_calc_totrct(screen, area, &window_rect);
2300
2301 /* region rect sizes */
2302 rcti rect = area->totrct;
2303 rcti overlap_rect = rect;
2304 region_rect_recursive(area, area->regionbase.first(), &rect, &overlap_rect, 0);
2305
2306 /* Dynamically sized regions may have changed region sizes, so we have to force azone update. */
2307 area_azone_init(win, screen, area);
2308
2309 for (ARegion &region : area->regionbase) {
2310 if (region.flag & RGN_FLAG_POLL_FAILED) {
2311 continue;
2312 }
2314
2315 /* region size may have changed, init does necessary adjustments */
2316 if (region.runtime->type->init) {
2317 region.runtime->type->init(wm, &region);
2318 }
2319
2320 /* Some AZones use View2D data which is only updated in region init, so call that first! */
2321 region_azones_add(screen, area, &region);
2322 }
2324
2326}
2327
2329{
2330 return area_getorientation(a, b) != -1;
2331}
2332
2336static void area_init_type_fallback(ScrArea *area, eSpace_Type space_type)
2337{
2338 BLI_assert(area->type == nullptr);
2339 area->spacetype = space_type;
2340 area->type = BKE_spacetype_from_id(area->spacetype);
2341
2342 SpaceLink *sl = nullptr;
2343 for (SpaceLink &sl_iter : area->spacedata) {
2344 if (sl_iter.spacetype == space_type) {
2345 sl = &sl_iter;
2346 break;
2347 }
2348 }
2349 if (sl) {
2350 SpaceLink *sl_old = area->spacedata.first();
2351 if (sl != sl_old) [[likely]] {
2352 BLI_remlink(&area->spacedata, sl);
2353 BLI_addhead(&area->spacedata, sl);
2354
2355 /* swap regions */
2356 sl_old->regionbase = area->regionbase;
2357 area->regionbase = sl->regionbase;
2358 sl->regionbase.clear_no_delete();
2359 }
2360 }
2361 else {
2362 screen_area_spacelink_add(nullptr, area, space_type);
2363 }
2364}
2365
2367{
2368 area->type = BKE_spacetype_from_id(area->spacetype);
2369
2370 if (area->type == nullptr) {
2372 BLI_assert(area->type != nullptr);
2373 }
2374
2375 for (ARegion &region : area->regionbase) {
2376 region.runtime->type = BKE_regiontype_from_id(area->type, region.regiontype);
2377 /* Invalid region types may be stored in files (e.g. for new files), but they should be handled
2378 * on file read already, see #BKE_screen_area_blend_read_lib(). */
2379 BLI_assert_msg(region.runtime->type != nullptr, "Region type not valid for this space type");
2380 }
2381}
2382
2383void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
2384{
2386 WorkSpace *workspace = WM_window_get_active_workspace(win);
2388 const Main *bmain = CTX_data_main(C);
2389 const Scene *scene = WM_window_get_active_scene(win);
2390 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
2391
2392 if (ED_area_is_global(area) && (area->global->flag & GLOBAL_AREA_IS_HIDDEN)) {
2393 return;
2394 }
2395
2396 rcti window_rect;
2397 WM_window_screen_rect_calc(win, &window_rect);
2398
2400
2401 /* area sizes */
2402 area_calc_totrct(screen, area, &window_rect);
2403
2404 area_regions_poll(C, screen, area);
2405
2406 /* region rect sizes */
2407 rcti rect = area->totrct;
2408 rcti overlap_rect = rect;
2409 region_rect_recursive(area, area->regionbase.first(), &rect, &overlap_rect, 0);
2411
2412 /* default area handlers */
2413 ed_default_handlers(wm, area, nullptr, &area->handlers, area->type->keymapflag);
2414 /* checks spacedata, adds own handlers */
2415 if (area->type->init) {
2416 area->type->init(wm, area);
2417 }
2418
2419 /* clear all azones, add the area triangle widgets */
2420 area_azone_init(win, screen, area);
2421
2422 /* region windows, default and own handlers */
2423 for (ARegion &region : area->regionbase) {
2425
2426 if (region.runtime->visible) {
2427 /* default region handlers */
2429 wm, area, &region, &region.runtime->handlers, region.runtime->type->keymapflag);
2430 /* own handlers */
2431 if (region.runtime->type->init) {
2432 region.runtime->type->init(wm, &region);
2433 }
2434 }
2435 else {
2436 /* prevent uiblocks to run */
2437 ui::blocklist_free(nullptr, &region);
2438 }
2439
2440 /* Some AZones use View2D data which is only updated in region init, so call that first! */
2441 region_azones_add(screen, area, &region);
2442 }
2443
2444 /* Avoid re-initializing tools while resizing areas & regions. */
2445 if ((G.moving & G_TRANSFORM_WM) == 0) {
2446 if ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) {
2447 if (WM_toolsystem_refresh_screen_area(*bmain, workspace, scene, view_layer, area) ||
2448 /* When the tool is null it may not be initialized.
2449 * This happens when switching to a new area, see: #126990.
2450 *
2451 * NOTE(@ideasman42): There is a possible down-side here: when refreshing
2452 * tools results in a null value, refreshing won't be skipped here as intended.
2453 * As it happens, spaces that use tools will practically always have a default tool. */
2454 (area->runtime.tool == nullptr))
2455 {
2456 /* Only re-initialize as needed to prevent redundant updates as they
2457 * can cause gizmos to flicker when the flag is set continuously, see: #126525. */
2459 }
2460 }
2461 else {
2462 area->runtime.tool = nullptr;
2463 area->runtime.is_tool_set = true;
2464 }
2465 }
2466}
2467
2469{
2470 area->flag |= AREA_FLAG_OFFSCREEN;
2471 area->type = BKE_spacetype_from_id(area->spacetype);
2472 /* Off screen areas are only ever created at run-time,
2473 * so there is no reason for the type to be unknown. */
2474 BLI_assert(area->type != nullptr);
2475
2476 for (ARegion &region : area->regionbase) {
2477 region.runtime->type = BKE_regiontype_from_id(area->type, region.regiontype);
2478 }
2479}
2480
2482{
2483 ScrArea *area = MEM_new<ScrArea>(__func__);
2484 area->spacetype = space_type;
2485
2487 area_offscreen_init(area);
2488
2489 return area;
2490}
2491
2493{
2494 if (area->type && area->type->exit) {
2495 area->type->exit(wm, area);
2496 }
2497
2498 for (ARegion &region : area->regionbase) {
2499 if (region.runtime->type && region.runtime->type->exit) {
2500 region.runtime->type->exit(wm, &region);
2501 }
2502
2503 WM_event_modal_handler_region_replace(win, &region, nullptr);
2504 WM_draw_region_free(&region);
2505 region.runtime->visible = false;
2506
2507 MEM_SAFE_DELETE(region.runtime->headerstr);
2508
2509 if (region.runtime->regiontimer) {
2511 region.runtime->regiontimer = nullptr;
2512 }
2513
2514 if (wm->runtime->message_bus) {
2515 WM_msgbus_clear_by_owner(wm->runtime->message_bus, &region);
2516 }
2517 }
2518
2519 WM_event_modal_handler_area_replace(win, area, nullptr);
2520}
2521
2523{
2524 area_offscreen_exit(wm, win, area);
2525
2527 MEM_delete(area);
2528}
2529
2530static void region_update_rect(ARegion *region)
2531{
2532 region->winx = BLI_rcti_size_x(&region->winrct) + 1;
2533 region->winy = BLI_rcti_size_y(&region->winrct) + 1;
2534
2535 /* v2d mask is used to subtract scrollbars from a 2d view. Needs initialize here. */
2536 BLI_rcti_init(&region->v2d.mask, 0, region->winx - 1, 0, region->winy - 1);
2537}
2538
2540{
2541 region_update_rect(region);
2542}
2543
2545{
2547
2548 /* refresh can be called before window opened */
2550
2551 region_update_rect(region);
2552}
2553
2555{
2556 if (region && region->runtime->type && region->runtime->type->do_lock) {
2558 return;
2559 }
2560
2561 if (region != nullptr) {
2562 if ((region->runtime->gizmo_map != nullptr) &&
2564 {
2565 return;
2566 }
2567 if (area && region->runtime->type && region->runtime->type->cursor) {
2568 region->runtime->type->cursor(win, area, region);
2569 return;
2570 }
2571 }
2572
2573 if (WM_cursor_set_from_tool(win, area, region)) {
2574 return;
2575 }
2576
2578}
2579
2581 bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
2582{
2583 if (is_hidden) {
2585 /* Needed to close any open pop-overs which would otherwise remain open,
2586 * crashing on attempting to refresh. See: #93410.
2587 *
2588 * When #ED_area_init frees buttons via #blocklist_free a nullptr context
2589 * is passed, causing the free not to remove menus or their handlers. */
2591 }
2592
2593 if (do_init) {
2594 ED_area_init(C, CTX_wm_window(C), area);
2595 ED_area_tag_redraw(area);
2596 }
2597}
2598
2600{
2601 const bool is_hidden = region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_POLL_FAILED);
2602 const bool do_init = true;
2603 ED_region_visibility_change_update_ex(C, area, region, is_hidden, do_init);
2604}
2605
2606void region_toggle_hidden(bContext *C, ARegion *region, const bool do_fade)
2607{
2608 ScrArea *area = CTX_wm_area(C);
2609
2610 region->flag ^= RGN_FLAG_HIDDEN;
2611
2612 if (do_fade && region->overlap && !(U.uiflag & USER_REDUCE_MOTION) &&
2613 !region->runtime->regiontimer)
2614 {
2615 /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */
2617 }
2618 else {
2620 }
2621}
2622
2624{
2625 region_toggle_hidden(C, region, true);
2626}
2627
2628void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
2629{
2630 if (do_free) {
2631 BKE_screen_area_free(area_dst);
2632 }
2633
2634 BKE_area_copy(area_dst, area_src);
2635}
2636
2637void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src)
2638{
2639 std::swap(area_dst->spacetype, area_src->spacetype);
2640 std::swap(area_dst->type, area_src->type);
2641
2642 std::swap(area_dst->spacedata, area_src->spacedata);
2643 std::swap(area_dst->regionbase, area_src->regionbase);
2644}
2645
2647
2648/* -------------------------------------------------------------------- */
2651
2660 struct {
2665 short alignment;
2669 bool hidden;
2671};
2672
2674{
2675 for (int index = 0; index < RGN_TYPE_NUM; index++) {
2676 r_align_info->by_type[index].alignment = -1;
2677 /* Default to true, when it doesn't exist - it's effectively hidden. */
2678 r_align_info->by_type[index].hidden = true;
2679 }
2680
2681 for (ARegion &region : area->regionbase) {
2682 if (region.flag & RGN_FLAG_POLL_FAILED) {
2683 continue;
2684 }
2685
2686 const int index = region.regiontype;
2687 if (uint(index) < RGN_TYPE_NUM) {
2688 r_align_info->by_type[index].alignment = RGN_ALIGN_ENUM_FROM_MASK(region.alignment);
2689 r_align_info->by_type[index].hidden = (region.flag & RGN_FLAG_HIDDEN) != 0;
2690 }
2691 }
2692}
2693
2702 const RegionTypeAlignInfo *region_align_info, const short fallback)
2703{
2704 const short header_alignment = region_align_info->by_type[RGN_TYPE_HEADER].alignment;
2705 const short tool_header_alignment = region_align_info->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2706
2707 const bool header_hidden = region_align_info->by_type[RGN_TYPE_HEADER].hidden;
2708 const bool tool_header_hidden = region_align_info->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2709
2710 if ((tool_header_alignment != -1) &&
2711 /* If tool-header is hidden, use header alignment. */
2712 ((tool_header_hidden == false) ||
2713 /* Don't prioritize the tool-header if both are hidden (behave as if both are visible).
2714 * Without this, switching to a space with headers hidden will flip the alignment
2715 * upon switching to a space with visible headers. */
2716 (header_hidden && tool_header_hidden)))
2717 {
2718 return tool_header_alignment;
2719 }
2720 if (header_alignment != -1) {
2721 return header_alignment;
2722 }
2723 return fallback;
2724}
2725
2748static void region_align_info_to_area_for_headers(const RegionTypeAlignInfo *region_align_info_src,
2749 const RegionTypeAlignInfo *region_align_info_dst,
2750 ARegion *region_by_type[RGN_TYPE_NUM])
2751{
2752 /* Abbreviate access. */
2753 const short header_alignment_src = region_align_info_src->by_type[RGN_TYPE_HEADER].alignment;
2754 const short tool_header_alignment_src =
2755 region_align_info_src->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2756
2757 const bool tool_header_hidden_src = region_align_info_src->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2758
2759 const short primary_header_alignment_src = region_alignment_from_header_and_tool_header_state(
2760 region_align_info_src, -1);
2761
2762 /* Neither alignments are usable, don't sync. */
2763 if (primary_header_alignment_src == -1) {
2764 return;
2765 }
2766
2767 const short header_alignment_dst = region_align_info_dst->by_type[RGN_TYPE_HEADER].alignment;
2768 const short tool_header_alignment_dst =
2769 region_align_info_dst->by_type[RGN_TYPE_TOOL_HEADER].alignment;
2770 const short footer_alignment_dst = region_align_info_dst->by_type[RGN_TYPE_FOOTER].alignment;
2771
2772 const bool tool_header_hidden_dst = region_align_info_dst->by_type[RGN_TYPE_TOOL_HEADER].hidden;
2773
2774 /* New synchronized alignments to set (or ignore when left as -1). */
2775 short header_alignment_sync = -1;
2776 short tool_header_alignment_sync = -1;
2777 short footer_alignment_sync = -1;
2778
2779 /* Both source/destination areas have same region configurations regarding headers.
2780 * Simply copy the values. */
2781 if (((header_alignment_src != -1) == (header_alignment_dst != -1)) &&
2782 ((tool_header_alignment_src != -1) == (tool_header_alignment_dst != -1)) &&
2783 (tool_header_hidden_src == tool_header_hidden_dst))
2784 {
2785 if (header_alignment_dst != -1) {
2786 header_alignment_sync = header_alignment_src;
2787 }
2788 if (tool_header_alignment_dst != -1) {
2789 tool_header_alignment_sync = tool_header_alignment_src;
2790 }
2791 }
2792 else {
2793 /* Not an exact match, check the space selector isn't moving. */
2794 const short primary_header_alignment_dst = region_alignment_from_header_and_tool_header_state(
2795 region_align_info_dst, -1);
2796
2797 if (primary_header_alignment_src != primary_header_alignment_dst) {
2798 if ((header_alignment_dst != -1) && (tool_header_alignment_dst != -1)) {
2799 if (header_alignment_dst == tool_header_alignment_dst) {
2800 /* Apply to both. */
2801 tool_header_alignment_sync = primary_header_alignment_src;
2802 header_alignment_sync = primary_header_alignment_src;
2803 }
2804 else {
2805 /* Keep on opposite sides. */
2806 tool_header_alignment_sync = primary_header_alignment_src;
2807 header_alignment_sync = (tool_header_alignment_sync == RGN_ALIGN_BOTTOM) ?
2810 }
2811 }
2812 else {
2813 /* Apply what we can to regions that exist. */
2814 if (header_alignment_dst != -1) {
2815 header_alignment_sync = primary_header_alignment_src;
2816 }
2817 if (tool_header_alignment_dst != -1) {
2818 tool_header_alignment_sync = primary_header_alignment_src;
2819 }
2820 }
2821 }
2822 }
2823
2824 if (footer_alignment_dst != -1) {
2825 if ((header_alignment_dst != -1) && (header_alignment_dst == footer_alignment_dst)) {
2826 /* Apply to both. */
2827 footer_alignment_sync = primary_header_alignment_src;
2828 }
2829 else {
2830 /* Keep on opposite sides. */
2831 footer_alignment_sync = (primary_header_alignment_src == RGN_ALIGN_BOTTOM) ?
2834 }
2835 }
2836
2837 /* Finally apply synchronized flags. */
2838 if (header_alignment_sync != -1) {
2839 ARegion *region = region_by_type[RGN_TYPE_HEADER];
2840 if (region != nullptr) {
2841 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(eRegion_Alignment(header_alignment_sync)) |
2843 }
2844 }
2845
2846 if (tool_header_alignment_sync != -1) {
2847 ARegion *region = region_by_type[RGN_TYPE_TOOL_HEADER];
2848 if (region != nullptr) {
2849 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(eRegion_Alignment(tool_header_alignment_sync)) |
2851 }
2852 }
2853
2854 if (footer_alignment_sync != -1) {
2855 ARegion *region = region_by_type[RGN_TYPE_FOOTER];
2856 if (region != nullptr) {
2857 region->alignment = RGN_ALIGN_ENUM_FROM_MASK(eRegion_Alignment(footer_alignment_sync)) |
2859 }
2860 }
2861}
2862
2864 ScrArea *area, const RegionTypeAlignInfo region_align_info_src[RGN_TYPE_NUM])
2865{
2866 ARegion *region_by_type[RGN_TYPE_NUM] = {nullptr};
2867 for (ARegion &region : area->regionbase) {
2868 const int index = region.regiontype;
2869 if (uint(index) < RGN_TYPE_NUM) {
2870 region_by_type[index] = &region;
2871 }
2872 }
2873
2874 RegionTypeAlignInfo region_align_info_dst;
2875 region_align_info_from_area(area, &region_align_info_dst);
2876
2877 if ((region_by_type[RGN_TYPE_HEADER] != nullptr) ||
2878 (region_by_type[RGN_TYPE_TOOL_HEADER] != nullptr))
2879 {
2881 region_align_info_src, &region_align_info_dst, region_by_type);
2882 }
2883
2884 /* Note that we could support other region types. */
2885}
2886
2888
2889/* -------------------------------------------------------------------- */
2892
2894{
2895 ScrArea *tmp = MEM_new<ScrArea>(__func__);
2896 wmWindow *win = CTX_wm_window(C);
2897
2898 ED_area_exit(C, sa1);
2899 ED_area_exit(C, sa2);
2900
2901 ED_area_data_copy(tmp, sa1, false);
2902 ED_area_data_copy(sa1, sa2, true);
2903 ED_area_data_copy(sa2, tmp, true);
2904 ED_area_init(C, win, sa1);
2905 ED_area_init(C, win, sa2);
2906
2908 MEM_delete(tmp);
2909
2910 /* The areas being swapped could be between different windows,
2911 * so clear screen active region pointers. This is set later
2912 * through regular operations. #141313. */
2914 for (wmWindow &win : wm->windows) {
2915 if (bScreen *screen = WM_window_get_active_screen(&win)) {
2916 screen->active_region = nullptr;
2917 }
2918 }
2919
2920 /* tell WM to refresh, cursor types etc */
2922
2923 ED_area_tag_redraw(sa1);
2925 ED_area_tag_redraw(sa2);
2927}
2928
2929void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_region_exit)
2930{
2931 wmWindow *win = CTX_wm_window(C);
2932 SpaceType *st = BKE_spacetype_from_id(type);
2933
2934 if (area->spacetype != type) {
2935 SpaceLink *slold = area->spacedata.first_as<SpaceLink>();
2936 /* store area->type->exit callback */
2937 void (*area_exit)(wmWindowManager *, ScrArea *) = area->type ? area->type->exit : nullptr;
2938 /* When the user switches between space-types from the type-selector,
2939 * changing the header-type is jarring (especially when using Ctrl-MouseWheel).
2940 *
2941 * However, add-on install for example, forces the header to the top which shouldn't
2942 * be applied back to the previous space type when closing - see: #57724
2943 *
2944 * Newly-created windows won't have any space data, use the alignment
2945 * the space type defaults to in this case instead
2946 * (needed for preferences to have space-type on bottom).
2947 */
2948
2949 bool sync_header_alignment = false;
2950 RegionTypeAlignInfo region_align_info[RGN_TYPE_NUM];
2951 if ((slold != nullptr) && (slold->link_flag & SPACE_FLAG_TYPE_TEMPORARY) == 0) {
2952 region_align_info_from_area(area, region_align_info);
2953 sync_header_alignment = true;
2954 }
2955
2956 /* in some cases (opening temp space) we don't want to
2957 * call area exit callback, so we temporarily unset it */
2958 if (skip_region_exit && area->type) {
2959 area->type->exit = nullptr;
2960 }
2961
2962 ED_area_exit(C, area);
2963
2964#ifdef WITH_INPUT_IME
2965 /* Will be null for newly opened windows (file selector for e.g.). */
2966 if (win->runtime && win->runtime->ghostwin) {
2967 /* End any active IME session - the old space type's cursor_ime is no longer valid. */
2968 WM_window_IME_end(win);
2969 }
2970#endif
2971
2972 /* restore old area exit callback */
2973 if (skip_region_exit && area->type) {
2974 area->type->exit = area_exit;
2975 }
2976
2977 area->spacetype = type;
2978 area->type = st;
2979
2980 /* If st->create may be called, don't use context until then. The
2981 * area->type->context() callback has changed but data may be invalid
2982 * (e.g. with properties editor) until space-data is properly created */
2983
2984 /* check previously stored space */
2985 SpaceLink *sl = nullptr;
2986 for (SpaceLink &sl_iter : area->spacedata) {
2987 if (sl_iter.spacetype == type) {
2988 sl = &sl_iter;
2989 break;
2990 }
2991 }
2992
2993 /* old spacedata... happened during work on 2.50, remove */
2994 if (sl && sl->regionbase.is_empty()) {
2995 st->free(sl);
2996 BLI_freelinkN(&area->spacedata, sl);
2997 if (slold == sl) {
2998 slold = nullptr;
2999 }
3000 sl = nullptr;
3001 }
3002
3003 if (sl) {
3004 /* swap regions */
3005 slold->regionbase = area->regionbase;
3006 area->regionbase = sl->regionbase;
3007 sl->regionbase.clear_no_delete();
3008 /* SPACE_FLAG_TYPE_WAS_ACTIVE is only used to go back to a previously active space that is
3009 * overlapped by temporary ones. It's now properly activated, so the flag should be cleared
3010 * at this point. */
3012
3013 /* put in front of list */
3014 BLI_remlink(&area->spacedata, sl);
3015 BLI_addhead(&area->spacedata, sl);
3016 }
3017 else {
3018 /* new space */
3019 if (st) {
3020 /* Don't get scene from context here which may depend on space-data. */
3021 Scene *scene = WM_window_get_active_scene(win);
3022 sl = st->create(area, scene);
3023 BLI_addhead(&area->spacedata, sl);
3024
3025 /* swap regions */
3026 if (slold) {
3027 slold->regionbase = area->regionbase;
3028 }
3029 area->regionbase = sl->regionbase;
3030 sl->regionbase.clear_no_delete();
3031 }
3032 }
3033
3034 /* Sync header alignment. */
3035 if (sync_header_alignment) {
3036 region_align_info_to_area(area, region_align_info);
3037 }
3038
3039 ED_area_init(C, win, area);
3040
3041 /* tell WM to refresh, cursor types etc */
3043
3044 /* send space change notifier */
3046
3047 ED_area_tag_refresh(area);
3048 }
3049
3050 /* Set area space subtype if applicable. */
3051 if (st && st->space_subtype_item_extend != nullptr) {
3052 if (area->butspacetype_subtype == -1) {
3053 /* Indication (probably from space_type_set_or_cycle) to ignore the
3054 * area's current subtype and use last-used, as saved in the space. */
3055 area->butspacetype_subtype = st->space_subtype_get(area);
3056 }
3057 st->space_subtype_set(area, area->butspacetype_subtype);
3058
3059 /* The sub-type sets the mode which selects the tool. */
3061 area->runtime.tool = nullptr;
3062 area->runtime.is_tool_set = false;
3064 }
3065 }
3066
3067 /* Whether setting a subtype or not we need to clear this value. Not just unneeded
3068 * but can interfere with the next change. Operations can change the type without
3069 * specifying a subtype (assumed zero) and we don't want to use the old subtype. */
3070 area->butspacetype_subtype = 0;
3071
3072 if (BLI_listbase_is_single(&CTX_wm_screen(C)->areabase)) {
3073 /* If there is only one area update the window title. */
3075 }
3076
3077 /* See #WM_capabilities_flag code-comments for details on the background check. */
3078 if (!G.background) {
3079 /* If window decoration styles are supported, send a notification to re-apply them. */
3082 }
3083 }
3084
3085 /* also redraw when re-used */
3086 ED_area_tag_redraw(area);
3087}
3088
3090{
3091 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
3092
3093 /* First toggle to the next temporary space in the list. */
3094 for (SpaceLink *sl_iter = sl->next; sl_iter; sl_iter = sl_iter->next) {
3095 if (sl_iter->link_flag & SPACE_FLAG_TYPE_TEMPORARY) {
3096 return sl_iter;
3097 }
3098 }
3099
3100 /* No temporary space, find the item marked as last active. */
3101 for (SpaceLink *sl_iter = sl->next; sl_iter; sl_iter = sl_iter->next) {
3102 if (sl_iter->link_flag & SPACE_FLAG_TYPE_WAS_ACTIVE) {
3103 return sl_iter;
3104 }
3105 }
3106
3107 /* If neither is found, we can just return to the regular previous one. */
3108 return sl->next;
3109}
3110
3112{
3113 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
3114 SpaceLink *prevspace = sl ? area_get_prevspace(area) : nullptr;
3115
3116 if (prevspace) {
3117 /* Specify that we want last-used if there are subtypes. */
3118 area->butspacetype_subtype = -1;
3119 ED_area_newspace(C, area, prevspace->spacetype, false);
3120 /* We've exited the space, so it can't be considered temporary anymore. */
3122 }
3123 else {
3124 /* no change */
3125 return;
3126 }
3127 /* If this is a stacked full-screen, changing to previous area exits it (meaning we're still in a
3128 * full-screen, but not in a stacked one). */
3130
3131 ED_area_tag_redraw(area);
3132
3133 /* send space change notifier */
3135}
3136
3138{
3139 ScrArea *area = CTX_wm_area(C);
3140 bScreen *screen = CTX_wm_screen(C);
3141 int xco = 0.4 * U.widget_unit;
3142
3143 PointerRNA areaptr = RNA_pointer_create_discrete(&(screen->id), RNA_Area, area);
3144
3145 uiDefButR(block,
3147 "",
3148 xco,
3149 yco,
3150 1.6 * U.widget_unit,
3151 U.widget_unit,
3152 &areaptr,
3153 "ui_type",
3154 0,
3155 0.0f,
3156 0.0f,
3157 "");
3158
3159 return xco + 1.7 * U.widget_unit;
3160}
3161
3163
3164/* -------------------------------------------------------------------- */
3167
3168static ThemeColorID region_background_color_id(const bContext * /*C*/, const ARegion *region)
3169{
3170 switch (region->regiontype) {
3171 case RGN_TYPE_HEADER:
3173 return TH_HEADER;
3174 case RGN_TYPE_PREVIEW:
3175 return TH_PREVIEW_BACK;
3176 default:
3177 return TH_BACK;
3178 }
3179}
3180
3181void ED_region_clear(const bContext *C, const ARegion *region, const int /*ThemeColorID*/ colorid)
3182{
3183 if (region->overlap) {
3184 /* view should be in pixelspace */
3186
3187 float back[4];
3188 ui::theme::get_color_4fv(colorid, back);
3189 GPU_clear_color(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
3190 }
3191 else {
3193 }
3194}
3195
3197{
3198 /* view should be in pixelspace */
3200
3201 GPU_clear_color(0, 0, 0, 0);
3202}
3203
3205
3206/* -------------------------------------------------------------------- */
3209
3210BLI_INLINE bool streq_array_any(const char *s, const char *arr[])
3211{
3212 for (uint i = 0; arr[i]; i++) {
3213 if (STREQ(arr[i], s)) {
3214 return true;
3215 }
3216 }
3217 return false;
3218}
3219
3229static void ed_panel_draw(const bContext *C,
3230 ARegion *region,
3231 ListBaseT<Panel> *lb,
3232 PanelType *pt,
3233 Panel *panel,
3234 int w,
3235 int em,
3236 char *unique_panel_str,
3237 const char *search_filter,
3238 wm::OpCallContext op_context)
3239{
3240 const uiStyle *style = ui::style_get_dpi();
3241
3242 /* Draw panel. */
3244 if (unique_panel_str) {
3245 /* Instanced panels should have already been added at this point. */
3246 BLI_string_join(block_name, sizeof(block_name), pt->idname, unique_panel_str);
3247 }
3248 else {
3249 STRNCPY_UTF8(block_name, pt->idname);
3250 }
3251 ui::Block *block = block_begin(C, region, block_name, ui::EmbossType::Emboss);
3252
3253 bool open;
3254 panel = panel_begin(region, lb, block, pt, panel, &open);
3255 panel->runtime->layout_panels.clear();
3256
3257 const bool search_filter_active = search_filter != nullptr && search_filter[0] != '\0';
3258
3259 /* bad fixed values */
3260 int2 co = {0, 0};
3261 int h = 0;
3262 int headerend = w - UI_UNIT_X;
3263
3265 if (pt->draw_header_preset && !(pt->flag & PANEL_TYPE_NO_HEADER)) {
3266 /* for preset menu */
3267 panel->layout = &ui::block_layout(block,
3270 0,
3271 (UI_UNIT_Y * 1.1f) + style->panelspace,
3272 UI_UNIT_Y,
3273 1,
3274 0,
3275 style);
3276
3277 panel->layout->operator_context_set(op_context);
3278
3279 pt->draw_header_preset(C, panel);
3280
3281 block_apply_search_filter(block, search_filter);
3282 co = ui::block_layout_resolve(block);
3283 block_translate(block, headerend - co.x, 0);
3284 panel->layout = nullptr;
3285 }
3286
3287 if (pt->draw_header && !(pt->flag & PANEL_TYPE_NO_HEADER)) {
3288 int labelx, labely;
3289 panel_label_offset(block, &labelx, &labely);
3290
3291 /* Unusual case: Use expanding layout (buttons stretch to available width). */
3292 if (pt->flag & PANEL_TYPE_HEADER_EXPAND) {
3293 ui::Layout &layout = ui::block_layout(block,
3296 labelx,
3297 labely,
3298 headerend - 2 * style->panelspace,
3299 1,
3300 0,
3301 style);
3302 panel->layout = &layout.row(false);
3303 }
3304 /* Regular case: Normal panel with fixed size buttons. */
3305 else {
3306 panel->layout = &ui::block_layout(block,
3309 labelx,
3310 labely,
3311 UI_UNIT_Y,
3312 1,
3313 0,
3314 style);
3315 }
3316
3317 panel->layout->operator_context_set(op_context);
3318
3319 pt->draw_header(C, panel);
3320
3321 block_apply_search_filter(block, search_filter);
3322 co = ui::block_layout_resolve(block);
3323 panel->labelofs = co.x - labelx;
3324 panel->layout = nullptr;
3325 }
3326 else {
3327 panel->labelofs = 0;
3328 }
3330
3331 if (open || search_filter_active) {
3332 ui::LayoutType panelContext;
3333
3334 /* panel context can either be toolbar region or normal panels region */
3335 if (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) {
3336 panelContext = ui::LayoutType::VerticalBar;
3337 }
3338 else if (region->regiontype == RGN_TYPE_TOOLS) {
3339 panelContext = ui::LayoutType::Toolbar;
3340 }
3341 else {
3342 panelContext = ui::LayoutType::Panel;
3343 }
3344
3345 panel->layout = &ui::block_layout(
3346 block,
3348 panelContext,
3349 (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) ? 0 : style->panelspace,
3350 0,
3351 (pt->flag & PANEL_TYPE_LAYOUT_VERT_BAR) ? 0 : w - 2 * style->panelspace,
3352 em,
3353 0,
3354 style);
3355
3356 panel->layout->operator_context_set(op_context);
3357
3358 pt->draw(C, panel);
3359
3360 const bool ends_with_layout_panel_header = uiLayoutEndsWithPanelHeader(*panel->layout);
3361
3362 block_apply_search_filter(block, search_filter);
3363 co = ui::block_layout_resolve(block);
3364 panel->layout = nullptr;
3365
3366 if (co.y != 0) {
3367 h = -co.y;
3368 h += style->panelspace;
3369 if (!ends_with_layout_panel_header) {
3370 /* Last layout panel header ends together with the panel. */
3371 h += style->panelspace;
3372 }
3373 }
3374 }
3375
3376 block_end(C, block, true);
3377
3378 /* Draw child panels. */
3379 if (open || search_filter_active) {
3380 for (LinkData &link : pt->children) {
3381 PanelType *child_pt = static_cast<PanelType *>(link.data);
3382 Panel *child_panel = ui::panel_find_by_type(&panel->children, child_pt);
3383
3384 if (child_pt->draw && (!child_pt->poll || child_pt->poll(C, child_pt))) {
3386 region,
3387 &panel->children,
3388 child_pt,
3389 child_panel,
3390 w,
3391 em,
3392 unique_panel_str,
3393 search_filter,
3394 op_context);
3395 }
3396 }
3397 }
3398
3399 ui::panel_end(panel, w, h);
3400}
3401
3405static bool panel_add_check(const bContext *C,
3406 const WorkSpace *workspace,
3407 const char *contexts[],
3408 const char *category_override,
3409 PanelType *panel_type)
3410{
3411 /* Only add top level panels. */
3412 if (panel_type->parent) {
3413 return false;
3414 }
3415 /* Check the category override first. */
3416 if (category_override) {
3417 if (!STREQ(panel_type->category, category_override)) {
3418 return false;
3419 }
3420 }
3421
3422 /* Verify context. */
3423 if (contexts != nullptr && panel_type->context[0]) {
3424 if (!streq_array_any(panel_type->context, contexts)) {
3425 return false;
3426 }
3427 }
3428
3429 /* If we're tagged, only use compatible. */
3430 if (panel_type->owner_id[0]) {
3431 if (!BKE_workspace_owner_id_check(workspace, panel_type->owner_id)) {
3432 return false;
3433 }
3434 }
3435
3436 if (panel_type->draw) [[likely]] {
3437 if (panel_type->poll && !panel_type->poll(C, panel_type)) {
3438 return false;
3439 }
3440 }
3441
3442 return true;
3443}
3444
3446 LinkNode *panel_types_stack,
3447 bool *use_categories)
3448{
3450
3451 /* gather unique categories */
3452 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
3453 PanelType *pt = static_cast<PanelType *>(pt_link->link);
3454 if (pt->category[0]) {
3455 if (!ui::panel_category_find(region, pt->category)) {
3456 ui::panel_category_add(region, pt->category, pt->icon);
3457 }
3458 }
3459 }
3460
3461 if (ui::panel_category_is_visible(region)) {
3462 return ui::panel_category_active_get(region, true);
3463 }
3464
3465 *use_categories = false;
3466 return nullptr;
3467}
3468
3470 const PanelType *panel_type,
3471 const int max_width)
3472{
3473 /* With a background, we want some extra padding. */
3474 return ui::panel_should_show_background(region, panel_type) ?
3475 max_width - round_fl_to_int(UI_PANEL_MARGIN_X * 2.0f) :
3476 max_width;
3477}
3478
3479void side_region_property_search(const bContext *C, ARegion *region);
3480
3482{
3484 return;
3485 }
3486 if (!bool(region->flag & RGN_FLAG_SEARCH_FILTER_UPDATE)) {
3487 return;
3488 }
3489 if (region->runtime->search_filter == "") {
3490 return;
3491 }
3492 if (!region->runtime->category) {
3493 return;
3494 }
3496 {
3497 return;
3498 }
3499 const char *next_active = nullptr;
3500 const char *first_active = nullptr;
3501 bool found_active = false;
3502 for (PanelCategoryDyn &pc_dyn : region->runtime->panels_category) {
3503 found_active = found_active || STREQ(pc_dyn.idname, region->runtime->category);
3504 const bool has_match = region->runtime->categories_search_match.contains(pc_dyn.idname);
3505 if (has_match && !first_active) {
3506 first_active = pc_dyn.idname;
3507 }
3508 if (has_match && found_active) {
3509 next_active = pc_dyn.idname;
3510 break;
3511 }
3512 }
3513
3514 if (next_active) {
3515 ui::panel_category_active_set(region, next_active);
3516 ui::panel_category_show_tab(*C, region, next_active);
3517 }
3518 else if (first_active) {
3519 ui::panel_category_active_set(region, first_active);
3520 ui::panel_category_show_tab(*C, region, first_active);
3521 }
3522}
3523
3525 ARegion *region,
3526 ListBaseT<PanelType> *paneltypes,
3527 wm::OpCallContext op_context,
3528 const char *contexts[],
3529 const char *category_override)
3530{
3531
3533
3534 /* collect panels to draw */
3535 WorkSpace *workspace = CTX_wm_workspace(C);
3536 LinkNode *panel_types_stack = nullptr;
3537 for (PanelType &pt : paneltypes->items_reversed()) {
3538 if (panel_add_check(C, workspace, contexts, category_override, &pt)) {
3539 BLI_linklist_prepend_alloca(&panel_types_stack, &pt);
3540 }
3541 }
3542
3543 region->runtime->category = nullptr;
3544
3545 ScrArea *area = CTX_wm_area(C);
3546 View2D *v2d = &region->v2d;
3547
3548 bool use_categories = (category_override == nullptr) &&
3550 bool use_category_tabs = (category_override == nullptr) &&
3552 /* offset panels for small vertical tab area */
3553 const char *category = nullptr;
3554 const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH;
3555 int margin_x = 0;
3556 const bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE;
3557 bool update_tot_size = true;
3558
3559 /* only allow scrolling in vertical direction */
3561 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
3562 v2d->scroll &= ~V2D_SCROLL_BOTTOM;
3563
3564 if (region->alignment & RGN_ALIGN_LEFT) {
3565 region->v2d.scroll &= ~V2D_SCROLL_RIGHT;
3566 region->v2d.scroll |= V2D_SCROLL_LEFT;
3567 }
3568 else {
3569 region->v2d.scroll &= ~V2D_SCROLL_LEFT;
3570 region->v2d.scroll |= V2D_SCROLL_RIGHT;
3571 }
3572
3573 /* collect categories */
3574 if (use_categories) {
3575 category = region_panels_collect_categories(region, panel_types_stack, &use_categories);
3576 if (!use_categories) {
3577 use_category_tabs = false;
3578 }
3579 }
3580 if (use_category_tabs) {
3581 margin_x = category_tabs_width;
3582 }
3583
3584 const int max_panel_width = round_fl_to_int(BLI_rctf_size_x(&v2d->cur)) - margin_x;
3585 /* Works out to 10 * UI_UNIT_X or 20 * UI_UNIT_X. */
3586 const int em = (region->runtime->type->prefsizex) ? 10 : 20;
3587
3588 /* create panels */
3589 ui::panels_begin(C, region);
3590
3591 /* Get search string for property search. */
3592 const char *search_filter = ED_area_region_search_filter_get(area, region);
3593
3594 /* set view2d view matrix - block_begin() stores it */
3596
3597 bool has_instanced_panel = false;
3598 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
3599 PanelType *pt = static_cast<PanelType *>(pt_link->link);
3600
3601 if (pt->flag & PANEL_TYPE_INSTANCED) {
3602 has_instanced_panel = true;
3603 continue;
3604 }
3605 Panel *panel = ui::panel_find_by_type(&region->panels, pt);
3606
3607 if (use_categories && pt->category[0] && !STREQ(category, pt->category)) {
3608 if ((panel == nullptr) || ((panel->flag & PNL_PIN) == 0)) {
3609 continue;
3610 }
3611 }
3612 const int width = panel_draw_width_from_max_width_get(region, pt, max_panel_width);
3613
3614 if (panel && ui::panel_is_dragging(panel)) {
3615 /* Prevent View2d.tot rectangle size changes while dragging panels. */
3616 update_tot_size = false;
3617 }
3618
3620 C, region, &region->panels, pt, panel, width, em, nullptr, search_filter, op_context);
3621 }
3622
3623 /* Draw "poly-instantiated" panels that don't have a 1 to 1 correspondence with their types. */
3624 if (has_instanced_panel) {
3625 for (Panel &panel : region->panels) {
3626 if (panel.type == nullptr) {
3627 continue; /* Some panels don't have a type. */
3628 }
3629 if (!(panel.type->flag & PANEL_TYPE_INSTANCED)) {
3630 continue;
3631 }
3632 if (use_categories && panel.type->category[0] && !STREQ(category, panel.type->category)) {
3633 continue;
3634 }
3635 if (!panel_add_check(C, workspace, contexts, category_override, panel.type)) {
3636 continue;
3637 }
3638
3639 const int width = panel_draw_width_from_max_width_get(region, panel.type, max_panel_width);
3640
3641 if (ui::panel_is_dragging(&panel)) {
3642 /* Prevent View2d.tot rectangle size changes while dragging panels. */
3643 update_tot_size = false;
3644 }
3645
3646 /* Use a unique identifier for instanced panels, otherwise an old block for a different
3647 * panel of the same type might be found. */
3648 char unique_panel_str[INSTANCED_PANEL_UNIQUE_STR_SIZE];
3649 ui::list_panel_unique_str(&panel, unique_panel_str);
3651 region,
3652 &region->panels,
3653 panel.type,
3654 &panel,
3655 width,
3656 em,
3657 unique_panel_str,
3658 search_filter,
3659 op_context);
3660 }
3661 }
3662
3663 /* align panels and return size */
3664 int x, y;
3665 ui::panels_end(C, region, &x, &y);
3666
3667 if (category && region->runtime->search_filter != "") {
3668 for (Panel &panel : region->panels) {
3670 region->runtime->categories_search_match.add(category);
3671 break;
3672 }
3673 }
3674 }
3675
3676 /* before setting the view */
3677 if (region_layout_based) {
3678 /* XXX, only single panel support at the moment.
3679 * Can't use x/y values calculated above because they're not using the real height of panels,
3680 * instead they calculate offsets for the next panel to start drawing. */
3681 Panel *panel = region->panels.last();
3682 if (panel != nullptr) {
3683 const int size_dyn[2] = {
3684 int(UI_UNIT_X * (ui::panel_is_closed(panel) ? 8 : 14) / UI_SCALE_FAC),
3685 int(ui::panel_size_y(panel) / UI_SCALE_FAC),
3686 };
3687 /* region size is layout based and needs to be updated */
3688 if ((region->sizex != size_dyn[0]) || (region->sizey != size_dyn[1])) {
3689 region->sizex = size_dyn[0];
3690 region->sizey = size_dyn[1];
3691 ED_area_tag_region_size_update(area, region);
3692 }
3693 y = fabsf(region->sizey * UI_SCALE_FAC - 1);
3694 }
3695 }
3696 else {
3697 /* We always keep the scroll offset -
3698 * so the total view gets increased with the scrolled away part. */
3699 if (v2d->cur.ymax < -FLT_EPSILON) {
3700 /* Clamp to lower view boundary */
3701 if (v2d->tot.ymin < -v2d->winy) {
3702 y = min_ii(y, 0);
3703 }
3704 else {
3705 y = min_ii(y, v2d->cur.ymin);
3706 }
3707 }
3708
3709 y = -y;
3710 }
3711
3713
3714 if (update_tot_size) {
3715 /* this also changes the 'cur' */
3716 ui::view2d_totRect_set(v2d, x, y);
3717 }
3718
3719 if (use_categories) {
3720 region->runtime->category = category;
3721 }
3724}
3725
3727 const ARegion *region,
3728 const rcti *mask)
3729{
3730 if (!(region->flag & RGN_FLAG_INDICATE_OVERFLOW)) {
3731 return;
3732 }
3733
3734 const bool is_overlap = ED_region_is_overlap(area->spacetype, region->regiontype);
3735 const bool is_header = ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER);
3736 const bool narrow = region->v2d.scroll & (V2D_SCROLL_VERTICAL | V2D_SCROLL_HORIZONTAL);
3737 const float gradient_width = (narrow ? 4.0f : 16.0f) * UI_SCALE_FAC;
3738 const float transition = 20.0f * UI_SCALE_FAC;
3739
3740 float opaque[4];
3741 if (narrow) {
3743 opaque[3] = 0.2f;
3744 }
3745 else {
3747 opaque[3] = 1.0f;
3748 if (!is_header) {
3749 mul_v3_fl(opaque, 0.85f);
3750 }
3751 }
3752
3753 if (!mask) {
3754 mask = &region->v2d.mask;
3755 }
3756
3757 int width = BLI_rcti_size_x(mask) + 1;
3758 int height = BLI_rcti_size_y(mask) + 1;
3759 float offset_x = mask->xmin;
3760 float offset_y = mask->ymin;
3761
3762 if (is_overlap) {
3763 if (is_header) {
3764 offset_y += 3.0f * UI_SCALE_FAC;
3765 }
3766 else if (region->panels.first_) {
3767 offset_x = UI_PANEL_MARGIN_X;
3768 width -= (2 * UI_PANEL_MARGIN_X);
3769 }
3770 }
3772 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
3773 (BLI_rcti_size_y(&region->v2d.mask) + 1);
3774 height -= UI_PANEL_SEARCH_BLOCK_MARGIN_HEIGHT / aspect;
3775 }
3776
3777 rctf rect{};
3778 float transparent[4];
3779 copy_v3_v3(transparent, opaque);
3780 transparent[3] = 0.0f;
3781 float grad_color[4];
3782
3783 if (region->v2d.cur.xmax < region->v2d.tot.xmax &&
3784 !(area->spacetype == SPACE_OUTLINER && region->regiontype == RGN_TYPE_WINDOW))
3785 {
3786 /* Right Edge. */
3787 rect.xmax = offset_x + width;
3788 rect.xmin = offset_x + rect.xmax - gradient_width;
3789 rect.ymin = offset_y;
3790 rect.ymax = height;
3791 copy_v4_v4(grad_color, opaque);
3792 grad_color[3] *= std::min((region->v2d.tot.xmax - region->v2d.cur.xmax) / transition, 1.0f);
3793 ui::draw_roundbox_4fv_ex(&rect, grad_color, transparent, 0.0f, nullptr, 0.0f, 0.0f);
3794 }
3795 if (region->v2d.cur.xmin > region->v2d.tot.xmin) {
3796 /* Left Edge. */
3797 rect.xmin = offset_x;
3798 if (is_header && (U.uiflag & USER_AREA_CORNER_HANDLE)) {
3799 rect.xmin += 12.0f * UI_SCALE_FAC;
3800 }
3801 rect.xmax = rect.xmin + gradient_width;
3802 rect.ymin = offset_y;
3803 rect.ymax = height;
3804 copy_v4_v4(grad_color, opaque);
3805 grad_color[3] *= std::min((region->v2d.cur.xmin - region->v2d.tot.xmin) / transition, 1.0f);
3806 ui::draw_roundbox_4fv_ex(&rect, transparent, grad_color, 0.0f, nullptr, 0.0f, 0.0f);
3807 if (is_header && (U.uiflag & USER_AREA_CORNER_HANDLE)) {
3808 rect.xmin = 0.0f;
3809 rect.xmax = 12.0f * UI_SCALE_FAC;
3810 ui::draw_roundbox_4fv_ex(&rect, grad_color, nullptr, 0.0f, nullptr, 0.0f, 0.0f);
3811 }
3812 }
3813 if (region->v2d.cur.ymax < region->v2d.tot.ymax) {
3814 /* Top Edge. */
3815 rect.xmin = offset_x;
3816 rect.xmax = offset_x + width;
3817 rect.ymax = offset_y + height;
3818 rect.ymin = rect.ymax - gradient_width;
3819 copy_v4_v4(grad_color, opaque);
3820 grad_color[3] *= std::min((region->v2d.tot.ymax - region->v2d.cur.ymax) / transition, 1.0f);
3821 ui::draw_roundbox_4fv_ex(&rect, grad_color, transparent, 1.0f, nullptr, 0.0f, 0.0f);
3822 }
3823 if (region->v2d.cur.ymin > region->v2d.tot.ymin) {
3824 /* Bottom Edge. */
3825 rect.xmin = offset_x;
3826 rect.xmax = offset_x + width;
3827 rect.ymin = offset_y;
3828 rect.ymax = rect.ymin + gradient_width;
3829 copy_v4_v4(grad_color, opaque);
3830 grad_color[3] *= std::min((region->v2d.cur.ymin - region->v2d.tot.ymin) / transition, 1.0f);
3831 ui::draw_roundbox_4fv_ex(&rect, transparent, grad_color, 1.0f, nullptr, 0.0f, 0.0f);
3832 }
3833}
3834
3836{
3838 region,
3839 &region->runtime->type->paneltypes,
3841 nullptr,
3842 nullptr);
3843}
3844
3846{
3848 return;
3849 }
3850 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
3852 if (region->overlap) {
3853 float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
3855 }
3856 else {
3858 }
3859
3860 immRectf(pos,
3861 region->v2d.cur.xmin,
3863 region->v2d.cur.xmax,
3864 region->v2d.cur.ymax);
3866
3867 const float categories_width = ui::panel_category_tabs_is_visible(region) ?
3869 0.0f;
3870 const uiStyle *style = ui::style_get_dpi();
3871
3872 ui::Block *block = block_begin(C, region, "panel_category_search_block", ui::EmbossType::Emboss);
3873 const int em = (region->runtime->type->prefsizex) ? 10 : 20;
3874 const int w = round_fl_to_int(BLI_rctf_size_x(&region->v2d.cur) - categories_width -
3875 2.0f * float(style->panelspace));
3876 ui::block_layout(block,
3879 style->panelspace,
3880 0,
3881 w,
3882 em,
3883 0,
3884 style);
3885
3887 id_cast<ID *>(CTX_wm_screen(C)), RNA_Region, region);
3888 ui::Button *button = ui::uiDefIconButR_prop(block,
3890 ICON_VIEWZOOM,
3891 0,
3892 0,
3893 std::max<int>(w, 0),
3894 UI_UNIT_Y,
3895 &ptr,
3896 RNA_struct_find_property(&ptr, "search_filter"),
3897 -1,
3898 0,
3899 0,
3900 "");
3903 button, "UI_OT_region_clear_filter", wm::OpCallContext::InvokeDefault, ICON_PANEL_CLOSE);
3904
3906
3907 /* Make sure the events are consumed from the search and don't reach other UI blocks since this
3908 * is drawn on top of panels. */
3909 block_flag_enable(block, ui::BLOCK_CLIP_EVENTS);
3910 block_bounds_set_normal(block, 0);
3911 block_end(C, block);
3912 block_translate(block, 0, region->v2d.cur.ymax - region->v2d.tot.ymax);
3913 block_draw(C, block);
3914}
3915
3917{
3918 View2D *v2d = &region->v2d;
3919 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
3920 (BLI_rcti_size_y(&region->v2d.mask) + 1);
3921
3922 if (region->alignment != RGN_ALIGN_FLOAT) {
3924 region,
3926 TH_BACK);
3927 }
3928
3929 /* reset line width for drawing tabs */
3930 GPU_line_width(1.0f);
3931
3932 /* set the view */
3934
3935 /* View2D matrix might have changed due to dynamic sized regions. */
3937
3938 /* draw panels if they are large enough. */
3939 const bool has_category_tabs = ui::panel_category_tabs_is_visible(region);
3940 const short min_draw_size = has_category_tabs ?
3941 short(UI_PANEL_CATEGORY_MIN_WIDTH + ui::PANEL_MIN_DRAW_WIDTH) :
3942 std::min(region->runtime->type->prefsizex,
3943 ui::PANEL_MIN_DRAW_WIDTH);
3944 if (region->winx >= (min_draw_size * UI_SCALE_FAC / aspect)) {
3945 ui::panels_draw(C, region);
3946 }
3947 /* Draw region search on top of panels. */
3949 /* restore view matrix */
3951
3952 /* Set in layout. */
3953 if (has_category_tabs && region->runtime->category) {
3955 }
3956
3957 /* scrollers */
3958 bool use_mask = false;
3959 rcti mask;
3960 const short alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
3961 if (region->runtime->category && ELEM(alignment, RGN_ALIGN_RIGHT, RGN_ALIGN_LEFT) &&
3962 has_category_tabs)
3963 {
3964 use_mask = true;
3966 const int category_width = round_fl_to_int(ui::view2d_scale_get_x(&region->v2d) *
3968 if (alignment == RGN_ALIGN_RIGHT) {
3969 mask.xmax -= category_width;
3970 }
3971 else if (alignment == RGN_ALIGN_LEFT) {
3972 mask.xmin += category_width;
3973 }
3974 }
3975
3976 ED_region_draw_overflow_indication(CTX_wm_area(C), region, use_mask ? &mask : nullptr);
3977
3978 /* Hide scrollbars below a threshold. */
3979 int min_width = has_category_tabs ? 60.0f * UI_SCALE_FAC / aspect :
3980 40.0f * UI_SCALE_FAC / aspect;
3981 if (BLI_rcti_size_x(&region->winrct) <= min_width) {
3983 }
3984
3985 ui::view2d_scrollers_draw(v2d, use_mask ? &mask : nullptr);
3986}
3987
3989 ARegion *region,
3990 wm::OpCallContext op_context,
3991 const char *contexts[])
3992{
3993 /* TODO: remove? */
3995 C, region, &region->runtime->type->paneltypes, op_context, contexts, nullptr);
3996 ED_region_panels_draw(C, region);
3997}
3998
3999void ED_region_panels(const bContext *C, ARegion *region)
4000{
4001 /* TODO: remove? */
4002 ED_region_panels_layout(C, region);
4003 ED_region_panels_draw(C, region);
4004}
4005
4007{
4008 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_PANELS_UI, region->winx, region->winy);
4009
4010 /* Place scroll bars to the left if left-aligned, right if right-aligned. */
4011 if (region->alignment & RGN_ALIGN_LEFT) {
4012 region->v2d.scroll &= ~V2D_SCROLL_RIGHT;
4013 region->v2d.scroll |= V2D_SCROLL_LEFT;
4014 }
4015 else if (region->alignment & RGN_ALIGN_RIGHT) {
4016 region->v2d.scroll &= ~V2D_SCROLL_LEFT;
4017 region->v2d.scroll |= V2D_SCROLL_RIGHT;
4018 }
4019
4020 wmKeyMap *keymap = WM_keymap_ensure(
4021 wm->runtime->defaultconf, "View2D Buttons List", SPACE_EMPTY, RGN_TYPE_WINDOW);
4022 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
4023}
4024
4026
4027/* -------------------------------------------------------------------- */
4030
4038 ARegion *region,
4039 const uiStyle *style,
4040 Panel *panel,
4041 PanelType *panel_type,
4042 const char *search_filter)
4043{
4044 ui::Block *block = block_begin(C, region, panel_type->idname, ui::EmbossType::Emboss);
4045 block_set_search_only(block, true);
4046
4047 /* Skip panels that give meaningless search results. */
4048 if (panel_type->flag & PANEL_TYPE_NO_SEARCH) {
4049 return false;
4050 }
4051
4052 if (panel == nullptr) {
4053 bool open; /* Dummy variable. */
4054 panel = panel_begin(region, &region->panels, block, panel_type, panel, &open);
4055 }
4056
4057 /* Build the layouts. Because they are only used for search,
4058 * they don't need any of the proper style or layout information. */
4059 if (panel->type->draw_header_preset != nullptr) {
4060 panel->layout = &ui::block_layout(
4061 block, ui::LayoutDirection::Horizontal, ui::LayoutType::Header, 0, 0, 0, 0, 0, style);
4062 panel_type->draw_header_preset(C, panel);
4063 }
4064 if (panel->type->draw_header != nullptr) {
4065 panel->layout = &ui::block_layout(
4066 block, ui::LayoutDirection::Horizontal, ui::LayoutType::Header, 0, 0, 0, 0, 0, style);
4067 panel_type->draw_header(C, panel);
4068 }
4069 if (panel->type->draw != nullptr) [[likely]] {
4070 panel->layout = &ui::block_layout(
4071 block, ui::LayoutDirection::Vertical, ui::LayoutType::Panel, 0, 0, 0, 0, 0, style);
4072 panel_type->draw(C, panel);
4073 }
4074
4075 ui::block_layout_free(block);
4076
4077 /* We could check after each layout to increase the likelihood of returning early,
4078 * but that probably wouldn't make much of a difference anyway. */
4079 if (block_apply_search_filter(block, search_filter)) {
4080 return true;
4081 }
4082
4083 for (LinkData &link : panel_type->children) {
4084 PanelType *panel_type_child = static_cast<PanelType *>(link.data);
4085 if (!panel_type_child->poll || panel_type_child->poll(C, panel_type_child)) {
4086 /* Search for the existing child panel here because it might be an instanced
4087 * child panel with a custom data field that will be needed to build the layout. */
4088 Panel *child_panel = ui::panel_find_by_type(&panel->children, panel_type_child);
4089 if (panel_property_search(C, region, style, child_panel, panel_type_child, search_filter)) {
4090 return true;
4091 }
4092 }
4093 }
4094
4095 return false;
4096}
4097
4098static bool side_region_search_for_context(const bContext *C, ARegion *region, StringRef category)
4099{
4100 std::array<const char *, 4> contexts = {nullptr};
4101 if (CTX_wm_space_image(C)) {
4102 contexts = ED_image_buttons_contexts(C);
4103 }
4104 else if (CTX_wm_view3d(C)) {
4105 contexts = ED_view3d_buttons_contexts(C);
4106 }
4108 C, region, &region->runtime->type->paneltypes, contexts.data(), category.data());
4109}
4110
4111static void side_region_search_all_categories(const bContext *C, ARegion *region_original)
4112{
4113 /* Avoid searching properties when region is almost collapsed. */
4114 if (ui::region_panels_fits_only_categories(region_original)) {
4115 return;
4116 }
4117 /* Use local copies of the area and duplicate the region as a mainly-paranoid protection
4118 * against changing any of the space / region data while running the search. */
4119 ScrArea *area_original = CTX_wm_area(C);
4120 ScrArea area_copy = dna::shallow_copy(*area_original);
4121 ARegion *region_copy = BKE_area_region_copy(area_copy.type, region_original);
4123 &region_original->panels_category_active);
4124 /* Set the region visible field. Otherwise some layout code thinks we're drawing in a popup.
4125 * This likely isn't necessary, but it's nice to emulate a "real" region where possible. */
4126 region_copy->runtime->visible = true;
4127
4128 region_copy->runtime->search_filter = region_original->runtime->search_filter;
4129
4130 CTX_wm_area_set(const_cast<bContext *>(C), &area_copy);
4131 CTX_wm_region_set(const_cast<bContext *>(C), region_copy);
4132 region_original->runtime->categories_search_match.clear();
4133
4134 WorkSpace *workspace = CTX_wm_workspace(C);
4135 LinkNode *panel_types_stack = nullptr;
4136 for (PanelType &pt : region_original->runtime->type->paneltypes.items_reversed()) {
4137 if (panel_add_check(C, workspace, nullptr, nullptr, &pt)) {
4138 BLI_linklist_prepend_alloca(&panel_types_stack, &pt);
4139 }
4140 }
4141 bool use_categories = true;
4143 region_original, panel_types_stack, &use_categories);
4144
4145 for (PanelCategoryDyn &pc_dyn : region_original->runtime->panels_category) {
4146 /* Handle search for the current tab in the normal layout pass. */
4147 /* Actually do the search and store the result in the bitmap. */
4148 if (category == pc_dyn.idname) {
4149 continue;
4150 }
4151 const bool found = side_region_search_for_context(C, region_copy, pc_dyn.idname);
4152 if (found) {
4153 region_original->runtime->categories_search_match.add(pc_dyn.idname);
4154 }
4155 ui::blocklist_free(C, region_copy);
4156 }
4157 BKE_area_region_free(area_copy.type, region_copy);
4158 MEM_delete(region_copy);
4159 CTX_wm_area_set(const_cast<bContext *>(C), area_original);
4160 CTX_wm_region_set(const_cast<bContext *>(C), region_original);
4161}
4162
4164{
4167 {
4168 return;
4169 }
4171}
4172
4174 ARegion *region,
4175 ListBaseT<PanelType> *paneltypes,
4176 const char *contexts[],
4177 const char *category_override)
4178{
4179 ScrArea *area = CTX_wm_area(C);
4180 WorkSpace *workspace = CTX_wm_workspace(C);
4181 const uiStyle *style = ui::style_get_dpi();
4182 const char *search_filter = ED_area_region_search_filter_get(area, region);
4183
4184 LinkNode *panel_types_stack = nullptr;
4185 for (PanelType &pt : paneltypes->items_reversed()) {
4186 if (panel_add_check(C, workspace, contexts, category_override, &pt)) {
4187 BLI_linklist_prepend_alloca(&panel_types_stack, &pt);
4188 }
4189 }
4190
4191 const char *category = category_override;
4192 bool use_categories = (category != nullptr) &&
4194 if (use_categories) {
4195 category = region_panels_collect_categories(region, panel_types_stack, &use_categories);
4196 }
4197
4198 /* Run property search for each panel, stopping if a result is found. */
4199 bool has_result = true;
4200 bool has_instanced_panel = false;
4201 for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
4202 PanelType *panel_type = static_cast<PanelType *>(pt_link->link);
4203 /* Note that these checks are duplicated from #ED_region_panels_layout_ex. */
4204 if (panel_type->flag & PANEL_TYPE_INSTANCED) {
4205 has_instanced_panel = true;
4206 continue;
4207 }
4208
4209 if (use_categories) {
4210 if (panel_type->category[0] && !STREQ(category, panel_type->category)) {
4211 continue;
4212 }
4213 }
4214
4215 /* We start property search with an empty panel list, so there's
4216 * no point in trying to find an existing panel with this type. */
4217 has_result = panel_property_search(C, region, style, nullptr, panel_type, search_filter);
4218 if (has_result) {
4219 break;
4220 }
4221 }
4222
4223 /* Run property search for instanced panels (created in the layout calls of previous panels). */
4224 if (!has_result && has_instanced_panel) {
4225 for (Panel &panel : region->panels) {
4226 /* Note that these checks are duplicated from #ED_region_panels_layout_ex. */
4227 if (panel.type == nullptr || !(panel.type->flag & PANEL_TYPE_INSTANCED)) {
4228 continue;
4229 }
4230 if (use_categories) {
4231 if (panel.type->category[0] && !STREQ(category, panel.type->category)) {
4232 continue;
4233 }
4234 }
4235
4236 has_result = panel_property_search(C, region, style, &panel, panel.type, search_filter);
4237 if (has_result) {
4238 break;
4239 }
4240 }
4241 }
4242
4243 /* Free the panels and blocks, as they are only used for search. */
4244 ui::blocklist_free(C, region);
4247
4248 return has_result;
4249}
4250
4252
4253/* -------------------------------------------------------------------- */
4256
4258{
4259 const uiStyle *style = ui::style_get_dpi();
4260 bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE;
4261 const ScrArea *area = CTX_wm_area(C);
4262 const bool is_global = area && ELEM(area->spacetype, SPACE_TOPBAR, SPACE_STATUSBAR);
4263 const int offset = is_global ? 4.0f * UI_SCALE_FAC : int(UI_HEADER_OFFSET);
4264
4265 /* Height of buttons and scaling needed to achieve it. */
4266 const int buttony = min_ii(UI_UNIT_Y, region->winy - 2 * UI_SCALE_FAC);
4267 const float buttony_scale = buttony / float(UI_UNIT_Y);
4268
4269 /* Vertically center buttons. */
4270 int2 co = {offset, buttony + (region->winy - buttony) / 2};
4271 int maxco = co.x;
4272
4273 /* set view2d view matrix for scrolling (without scrollers) */
4274 ui::view2d_view_ortho(&region->v2d);
4275
4276 /* draw all headers types */
4277 for (HeaderType &ht : region->runtime->type->headertypes) {
4278 if (ht.poll && !ht.poll(C, &ht)) {
4279 continue;
4280 }
4281
4282 ui::Block *block = block_begin(C, region, ht.idname, ui::EmbossType::Emboss);
4283 ui::Layout &layout = ui::block_layout(block,
4286 co.x,
4287 co.y,
4288 buttony,
4289 1,
4290 0,
4291 style);
4292
4293 if (buttony_scale != 1.0f) {
4294 layout.scale_y_set(buttony_scale);
4295 }
4296
4297 Header header = {nullptr};
4298 if (ht.draw) {
4299 header.type = &ht;
4300 header.layout = &layout;
4301 ht.draw(C, &header);
4302 if (ht.next) {
4303 layout.separator();
4304 }
4305
4306 /* for view2d */
4307 co.x = layout.width();
4308 maxco = std::max(co.x, maxco);
4309 }
4310
4311 co = ui::block_layout_resolve(block);
4312
4313 /* for view2d */
4314 maxco = std::max(co.x, maxco);
4315
4316 int new_sizex = (maxco + offset) / UI_SCALE_FAC;
4317
4318 if (region_layout_based && (region->sizex != new_sizex)) {
4319 /* region size is layout based and needs to be updated */
4320 ScrArea *area = CTX_wm_area(C);
4321
4322 region->sizex = new_sizex;
4323 ED_area_tag_region_size_update(area, region);
4324 }
4325
4326 block_end(C, block);
4327
4328 /* In most cases there is only ever one header, it never makes sense to draw more than one
4329 * header in the same region, this results in overlapping buttons, see: #60195. */
4330 break;
4331 }
4332
4333 if (!region_layout_based) {
4334 maxco += offset;
4335 }
4336
4337 /* Always as last. */
4338 ui::view2d_totRect_set(&region->v2d, maxco, region->winy);
4339
4340 /* Restore view matrix. */
4342}
4343
4344static void region_draw_blocks_in_view2d(const bContext *C, const ARegion *region)
4345{
4346 ui::view2d_view_ortho(&region->v2d);
4347
4348 /* View2D matrix might have changed due to dynamic sized regions. */
4350
4351 /* draw blocks */
4353
4354 /* restore view matrix */
4356}
4357
4359{
4360 /* clear */
4361 ED_region_clear(C, region, region_background_color_id(C, region));
4362
4364 {
4365 /* WORKAROUND: Driver bug. Fixes invalid glyph being rendered (see #147168). */
4367 }
4368
4371}
4372
4374 const ARegion *region,
4375 const ui::ButtonSectionsAlign align)
4376{
4377 const ThemeColorID bgcolorid = region_background_color_id(C, region);
4378
4379 /* Clear and draw button sections background when using region overlap. Otherwise clear using the
4380 * background color like normal. */
4381 if (region->overlap) {
4383 ui::region_button_sections_draw(region, bgcolorid, align);
4384 }
4385 else {
4386 ED_region_clear(C, region, bgcolorid);
4387 }
4389}
4390
4391void ED_region_header(const bContext *C, ARegion *region)
4392{
4393 /* TODO: remove? */
4394 ED_region_header_layout(C, region);
4395 ED_region_header_draw(C, region);
4396}
4397
4399 ARegion *region,
4400 const ui::ButtonSectionsAlign align)
4401{
4402 ED_region_header_layout(C, region);
4404}
4405
4407{
4408 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_HEADER, region->winx, region->winy);
4410}
4411
4413
4414/* -------------------------------------------------------------------- */
4417
4419{
4420 /* Accommodate widget and padding. */
4421 return U.widget_unit + int(UI_SCALE_FAC * HEADER_PADDING_Y);
4422}
4423
4425{
4426 return ED_area_headersize();
4427}
4428
4430{
4433}
4435{
4438}
4440{
4443}
4444
4446
4447/* -------------------------------------------------------------------- */
4450
4452{
4453 return area->global != nullptr;
4454}
4455
4456ScrArea *ED_area_find_under_cursor(const bContext *C, int spacetype, const int event_xy[2])
4457{
4458 bScreen *screen = CTX_wm_screen(C);
4459 wmWindow *win = CTX_wm_window(C);
4460
4461 ScrArea *area = nullptr;
4462
4463 if (win->parent) {
4464 /* If active window is a child, check itself first. */
4465 area = BKE_screen_find_area_xy(screen, spacetype, event_xy);
4466 }
4467
4468 if (!area) {
4469 /* Check all windows except the active one. */
4470 int event_xy_other[2];
4471 wmWindow *win_other = WM_window_find_under_cursor(win, event_xy, event_xy_other);
4472 if (win_other && win_other != win) {
4473 win = win_other;
4474 screen = WM_window_get_active_screen(win);
4475 area = BKE_screen_find_area_xy(screen, spacetype, event_xy_other);
4476 }
4477 }
4478
4479 if (!area && !win->parent) {
4480 /* If active window is a parent window, check itself last. */
4481 area = BKE_screen_find_area_xy(screen, spacetype, event_xy);
4482 }
4483
4484 return area;
4485}
4486
4488{
4489 ScrArea *global_area = win->global_areas.areabase.first();
4490
4491 if (!global_area) {
4492 return screen->areabase.first();
4493 }
4494 if ((global_area->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
4495 return global_area;
4496 }
4497 /* Find next visible area. */
4498 return ED_screen_areas_iter_next(screen, global_area);
4499}
4501{
4502 if (area->global == nullptr) {
4503 return area->next;
4504 }
4505
4506 for (ScrArea *area_iter = area->next; area_iter; area_iter = area_iter->next) {
4507 if ((area_iter->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
4508 return area_iter;
4509 }
4510 }
4511 /* No visible next global area found, start iterating over layout areas. */
4512 return screen->areabase.first();
4513}
4514
4516{
4517 return ED_area_headersize(); /* same size as header */
4518}
4519
4521
4522/* -------------------------------------------------------------------- */
4525
4527 const char *text_array[],
4528 const float fill_color[4],
4529 const bool full_redraw)
4530{
4531 const int header_height = UI_UNIT_Y;
4532 const uiStyle *style = ui::style_get_dpi();
4533 int fontid = style->widget.uifont_id;
4534 int scissor[4];
4535 int num_lines = 0;
4536
4537 /* background box */
4538 rcti rect = *ED_region_visible_rect(region);
4539
4540 /* Needed in case scripts leave the font size at an unexpected value, see: #102213. */
4541 BLF_size(fontid, style->widget.points * UI_SCALE_FAC);
4542
4543 /* Box fill entire width or just around text. */
4544 if (!full_redraw) {
4545 const char **text = &text_array[0];
4546 while (*text) {
4547 rect.xmax = min_ii(rect.xmax,
4548 rect.xmin + BLF_width(fontid, *text, BLF_DRAW_STR_DUMMY_MAX) +
4549 1.2f * U.widget_unit);
4550 text++;
4551 num_lines++;
4552 }
4553 }
4554 /* Just count the line number. */
4555 else {
4556 const char **text = &text_array[0];
4557 while (*text) {
4558 text++;
4559 num_lines++;
4560 }
4561 }
4562
4563 rect.ymin = rect.ymax - header_height * num_lines;
4564
4565 /* setup scissor */
4566 GPU_scissor_get(scissor);
4567 GPU_scissor(rect.xmin, rect.ymin, BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
4568
4570 GPUVertFormat *format = immVertexFormat();
4571 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
4573 immUniformColor4fv(fill_color);
4574 immRectf(pos, rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
4577
4578 /* text */
4580 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
4581 BLF_enable(fontid, BLF_CLIPPING);
4582 int offset = num_lines - 1;
4583 {
4584 const char **text = &text_array[0];
4585 while (*text) {
4586 BLF_position(fontid,
4587 rect.xmin + 0.6f * U.widget_unit,
4588 rect.ymin + 0.3f * U.widget_unit + offset * header_height,
4589 0.0f);
4591 text++;
4592 offset--;
4593 }
4594 }
4595
4596 BLF_disable(fontid, BLF_CLIPPING);
4597
4598 /* restore scissor as it was before */
4599 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
4600}
4601
4603 const char *text,
4604 const float fill_color[4],
4605 const bool full_redraw)
4606{
4607 const char *text_array[2] = {text, nullptr};
4608 ED_region_info_draw_multiline(region, text_array, fill_color, full_redraw);
4609}
4610
4614
4615static void metadata_panel_draw_field(const char *field, const char *value, void *ctx_v)
4616{
4617 MetadataPanelDrawContext *ctx = static_cast<MetadataPanelDrawContext *>(ctx_v);
4618 ui::Layout &row = ctx->layout->row(false);
4619 row.label(field, ICON_NONE);
4620 row.label(value, ICON_NONE);
4621}
4622
4624{
4626 ctx.layout = layout;
4628}
4629
4631
4632/* -------------------------------------------------------------------- */
4635
4636void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, float y0)
4637{
4638 /* the image is located inside (x0, y0), (x0+1, y0+1) as set by view2d */
4639 int x1, y1, x2, y2;
4640 ui::view2d_view_to_region(&region->v2d, x0, y0, &x1, &y1);
4641 ui::view2d_view_to_region(&region->v2d, x0 + 1.0f, y0 + 1.0f, &x2, &y2);
4642
4643 GPUVertFormat *format = immVertexFormat();
4644 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
4645
4646 float gridcolor[4];
4648
4650 /* To fake alpha-blending, color shading is reduced when alpha is nearing 0. */
4651 immUniformThemeColorBlendShade(TH_BACK, TH_GRID, gridcolor[3], 20 * gridcolor[3]);
4652 immRectf(pos, x1, y1, x2, y2);
4654
4655 /* gridsize adapted to zoom level */
4656 float gridsize = 0.5f * (zoomx + zoomy);
4657 float gridstep = 1.0f / 32.0f;
4658 if (gridsize <= 0.0f) {
4659 return;
4660 }
4661
4662 if (gridsize < 1.0f) {
4663 while (gridsize < 1.0f) {
4664 gridsize *= 4.0f;
4665 gridstep *= 4.0f;
4666 }
4667 }
4668 else {
4669 while (gridsize >= 4.0f) {
4670 gridsize /= 4.0f;
4671 gridstep /= 4.0f;
4672 }
4673 }
4674
4675 float blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
4676 CLAMP(blendfac, 0.0f, 1.0f);
4677
4678 int count_fine = 1.0f / gridstep;
4679 int count_large = 1.0f / (4.0f * gridstep);
4680
4681 if (count_fine > 0) {
4682 GPU_vertformat_clear(format);
4683 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
4684 uint color = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32);
4685
4687 immBegin(GPU_PRIM_LINES, 4 * count_fine + 4 * count_large);
4688
4689 float theme_color[3];
4690 ui::theme::get_color_shade_3fv(TH_GRID, int(20.0f * (1.0f - blendfac)), theme_color);
4691 float fac = 0.0f;
4692
4693 /* the fine resolution level */
4694 for (int i = 0; i < count_fine; i++) {
4695 immAttr3fv(color, theme_color);
4696 immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
4697 immAttr3fv(color, theme_color);
4698 immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
4699 immAttr3fv(color, theme_color);
4700 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
4701 immAttr3fv(color, theme_color);
4702 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
4703 fac += gridstep;
4704 }
4705
4706 if (count_large > 0) {
4707 ui::theme::get_color_3fv(TH_GRID, theme_color);
4708 fac = 0.0f;
4709
4710 /* the large resolution level */
4711 for (int i = 0; i < count_large; i++) {
4712 immAttr3fv(color, theme_color);
4713 immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
4714 immAttr3fv(color, theme_color);
4715 immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
4716 immAttr3fv(color, theme_color);
4717 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
4718 immAttr3fv(color, theme_color);
4719 immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
4720 fac += 4.0f * gridstep;
4721 }
4722 }
4723
4724 immEnd();
4726 }
4727}
4728
4730
4731/* -------------------------------------------------------------------- */
4734
4735/* If the area has overlapping regions, it returns visible rect for Region *region */
4736/* rect gets returned in local region coordinates */
4737static void region_visible_rect_calc(ARegion *region, rcti *rect)
4738{
4739 ARegion *region_iter = region;
4740
4741 /* allow function to be called without area */
4742 while (region_iter->prev) {
4743 region_iter = region_iter->prev;
4744 }
4745
4746 *rect = region->winrct;
4747
4748 /* check if a region overlaps with the current one */
4749 for (; region_iter; region_iter = region_iter->next) {
4750 if (region != region_iter && region_iter->overlap) {
4751 /* Use the region's animated rect so the visible area tracks its slide/fade animation instead
4752 * of jumping to the final size at the start or end of the animation. */
4753 rcti sibling_rect;
4754 ED_region_blend_rect(region_iter, &sibling_rect);
4755
4756 if (BLI_rcti_isect(rect, &sibling_rect, nullptr)) {
4757 int alignment = RGN_ALIGN_ENUM_FROM_MASK(region_iter->alignment);
4758
4759 if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
4760 /* Overlap left, also check 1 pixel offset (2 regions on one side). */
4761 if (abs(rect->xmin - sibling_rect.xmin) < 2) {
4762 rect->xmin = sibling_rect.xmax;
4763 }
4764
4765 /* Overlap right. */
4766 if (abs(rect->xmax - sibling_rect.xmax) < 2) {
4767 rect->xmax = sibling_rect.xmin;
4768 }
4769 }
4770 else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
4771 /* Same logic as above for vertical regions. */
4772 if (abs(rect->ymin - sibling_rect.ymin) < 2) {
4773 rect->ymin = sibling_rect.ymax;
4774 }
4775 if (abs(rect->ymax - sibling_rect.ymax) < 2) {
4776 rect->ymax = sibling_rect.ymin;
4777 }
4778 }
4779 else if (alignment == RGN_ALIGN_FLOAT) {
4780 /* Skip floating. */
4781 }
4782 else {
4783 BLI_assert_msg(0, "Region overlap with unknown alignment");
4784 }
4785 }
4786 }
4787 }
4788 BLI_rcti_translate(rect, -region->winrct.xmin, -region->winrct.ymin);
4789}
4790
4792{
4793 rcti *rect = &region->runtime->visible_rect;
4794 if (rect->xmin == 0 && rect->ymin == 0 && rect->xmax == 0 && rect->ymax == 0) {
4795 region_visible_rect_calc(region, rect);
4796 }
4797 return rect;
4798}
4799
4801
4802/* -------------------------------------------------------------------- */
4805
4807{
4808 /* Local coordinate visible rect inside region, to accommodate overlapping ui. */
4809 const rcti *rect_visible = ED_region_visible_rect(region);
4810 const int region_bottom = rect_visible->ymin;
4811
4812 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
4814 immUniformColor4ub(128, 128, 255, 64);
4815 immRectf(pos, 0, region_bottom, region->winx, region_bottom + 8 * UI_SCALE_FAC);
4817}
4818
4819void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
4820{
4821 const uiStyle *style = ui::style_get();
4822 int fontid = style->widget.uifont_id;
4823
4824 /* Format frame number. */
4825 char numstr[32];
4826 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
4827 SNPRINTF_UTF8(numstr, "%d", framenr);
4828
4829 float2 text_dims = {0.0f, 0.0f};
4830 BLF_width_and_height(fontid, numstr, sizeof(numstr), &text_dims.x, &text_dims.y);
4831 float padding = 3.0f * UI_SCALE_FAC;
4832
4833 /* Rounded corner background box. */
4834 float4 bg_color;
4836 float4 outline_color;
4837 ui::theme::get_color_shade_4fv(TH_CFRAME, 5, outline_color);
4838
4839 rctf rect{};
4840 rect.xmin = x - text_dims.x / 2 - padding;
4841 rect.xmax = x + text_dims.x / 2 + padding;
4842 rect.ymin = y;
4843 rect.ymax = y + text_dims.y + padding * 2;
4846 &rect, bg_color, nullptr, 1.0f, outline_color, U.pixelsize, 3 * UI_SCALE_FAC);
4847
4848 /* Text label. */
4850 BLF_position(fontid, x - text_dims.x * 0.5f, y + padding, 0.0f);
4851 BLF_draw(fontid, numstr, sizeof(numstr));
4852}
4853
4855 ARegion *region, const int num_segments, const int *points, const int sfra, const int efra)
4856{
4857 if (num_segments) {
4858 /* Local coordinate visible rect inside region, to accommodate overlapping ui. */
4859 const rcti *rect_visible = ED_region_visible_rect(region);
4860 const int region_bottom = rect_visible->ymin;
4861
4862 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
4864 immUniformColor4ub(128, 128, 255, 128);
4865
4866 for (int a = 0; a < num_segments; a++) {
4867 float x1 = float(points[a * 2] - sfra) / (efra - sfra + 1) * region->winx;
4868 float x2 = float(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * region->winx;
4869
4870 immRectf(pos, x1, region_bottom, x2, region_bottom + 8 * UI_SCALE_FAC);
4871 /* TODO(merwin): use primitive restart to draw multiple rects more efficiently */
4872 }
4873
4875 }
4876}
4877
4879
4880/* -------------------------------------------------------------------- */
4883
4885{
4886 ARegion *region = params->region;
4887 const bContext *C = params->context;
4888 wmMsgBus *mbus = params->message_bus;
4889
4890 if (region->runtime->gizmo_map != nullptr) {
4891 WM_gizmomap_message_subscribe(C, region->runtime->gizmo_map, region, mbus);
4892 }
4893
4894 if (!region->runtime->uiblocks.is_empty()) {
4895 ui::region_message_subscribe(region, mbus);
4896 }
4897
4898 if (region->runtime->type->message_subscribe != nullptr) {
4899 region->runtime->type->message_subscribe(params);
4900 }
4901}
4902
4904
4905/* -------------------------------------------------------------------- */
4908
4910{
4911 /* Use a larger value because toggling scrollbars can jump in size. */
4912 const int snap_match_threshold = 16;
4913 if (region->runtime->type->snap_size != nullptr) {
4914 const int snap_size_x = region->runtime->type->snap_size(region, region->sizex, 0);
4915 const int snap_size_y = region->runtime->type->snap_size(region, region->sizey, 1);
4916 return (((abs(region->sizex - snap_size_x) <= snap_match_threshold) << 0) |
4917 ((abs(region->sizey - snap_size_y) <= snap_match_threshold) << 1));
4918 }
4919 return 0;
4920}
4921
4922bool ED_region_snap_size_apply(ARegion *region, int snap_flag)
4923{
4924 bool changed = false;
4925 if (region->runtime->type->snap_size != nullptr) {
4926 if (snap_flag & (1 << 0)) {
4927 short snap_size = region->runtime->type->snap_size(region, region->sizex, 0);
4928 if (snap_size != region->sizex) {
4929 region->sizex = snap_size;
4930 changed = true;
4931 }
4932 }
4933 if (snap_flag & (1 << 1)) {
4934 short snap_size = region->runtime->type->snap_size(region, region->sizey, 1);
4935 if (snap_size != region->sizey) {
4936 region->sizey = snap_size;
4937 changed = true;
4938 }
4939 }
4940 }
4941 return changed;
4942}
4943
4945
4946} // namespace blender
#define BKE_ST_MAXNAME
Definition BKE_screen.hh:91
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLI_string_join(...)
#define HEADERY
#define RGN_ALIGN_ENUM_FROM_MASK(align)
#define AREAMINX
#define HEADER_PADDING_Y
#define RGN_TYPE_NUM
#define RGN_TYPE_IS_HEADER_ANY(regiontype)
#define RGN_ALIGN_FLAG_FROM_MASK(align)
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define REGION_DRAW_POST_PIXEL
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_PANEL_CATEGORY_MIN_SNAP_WIDTH
#define INSTANCED_PANEL_UNIQUE_STR_SIZE
#define UI_PANEL_CATEGORY_MIN_WIDTH
#define UI_PANEL_MARGIN_X
#define UI_PANEL_SEARCH_BLOCK_MARGIN_HEIGHT
#define UI_HEADER_OFFSET
#define UI_AZONESPOTW_RIGHT
#define UI_TOOLBAR_WIDTH
#define UI_PANEL_CATEGORY_MARGIN_WIDTH
#define UI_UNIT_X
#define UI_AZONESPOTW_LEFT
#define UI_AZONESPOTH
#define UI_NO_ICON_OVERLAY_TEXT
#define UI_MAX_DRAW_STR
#define WM_TOOLSYSTEM_SPACE_MASK
#define WM_TOOLSYSTEM_SPACE_MASK_MODE_FROM_SPACE
#define ND_UI_FONT
Definition WM_types.hh:602
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_FILEREAD
Definition WM_types.hh:428
#define ND_SPACE_CHANGED
Definition WM_types.hh:581
#define NC_WM
Definition WM_types.hh:387
#define NC_UI
Definition WM_types.hh:422
#define NC_SPACE
Definition WM_types.hh:405
#define KM_MOD_HELD
Definition WM_types.hh:339
int pad[32 - sizeof(int)]
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define BLI_INLINE
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
static RandomNumberGenerator from_random_seed()
Definition rand.cc:288
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
void clear()
Definition BLI_set.hh:570
constexpr const char * c_str() const
void separator(float factor=1.0f)
Definition area.cc:1083
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void modal_keymap(std::string text, const wmKeyMap &keymap, int propvalue, bool inverted=false)
Definition area.cc:1119
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
Definition area.cc:1107
void range(std::string text, int icon1, int icon2)
Definition area.cc:1088
WorkspaceStatus(bContext *C)
Definition area.cc:1034
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
constexpr const char * data() const
#define str(s)
#define FLT_EPSILON
constexpr T sign(T) RET
#define abs
#define floor
ccl_device_inline float3x3 inverted(const float3x3 m)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
void font_theme_color_set(int fontid, int colorid)
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_3fv(int colorid, float col[3])
void theme_store(bThemeState *theme_state)
void theme_set(int spacetype, int regionid)
void get_color_4fv(int colorid, float col[4])
void get_color_shade_3fv(int colorid, int offset, float col[3])
void frame_buffer_clear(int colorid)
void get_color_shade_4fv(int colorid, int offset, float col[4])
const bTheme * theme_get()
void theme_restore(const bThemeState *theme_state)
int icon_from_event_type(short event_type, short event_value)
int panel_size_y(const Panel *panel)
void panel_category_add(ARegion *region, const char *name, int icon=0)
void blocklist_free(const bContext *C, ARegion *region)
void panels_begin(const bContext *C, ARegion *region)
bool region_panels_fits_only_categories(const ARegion *region)
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void panel_category_clear_all(ARegion *region)
void view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1021
bool panel_should_show_background(const ARegion *region, const PanelType *panel_type)
void blocklist_update_window_matrix(const bContext *C, const ListBaseT< ui::Block > *lb)
const uiStyle * style_get()
void panels_draw(const bContext *C, ARegion *region)
bool textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
PanelCategoryDyn * panel_category_find(const ARegion *region, const char *idname)
void UI_region_free_active_but_all(bContext *C, ARegion *region)
void panels_do_after_block_layout_fns(const bContext *C, ARegion *region)
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
void 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, float scale=1.0f)
void view2d_mask_from_win(const View2D *v2d, rcti *r_mask)
Definition view2d.cc:111
void invalidate_text_wrap_cache(const ARegion &region)
void view2d_view_to_region(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
Definition view2d.cc:1705
void blocklist_draw(const bContext *C, const ListBaseT< ui::Block > *lb)
void panel_category_active_set(ARegion *region, const char *idname)
bool panel_is_closed(const Panel *panel)
void panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
void panel_end(Panel *panel, int width, int height)
bool panel_matches_search_filter(const Panel *panel)
const uiStyle * style_get_dpi()
Button * uiDefIconButR_prop(Block *block, ButtonType type, int icon, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void panel_header_buttons_end(Panel *panel)
void view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1487
void panel_category_show_tab(const bContext &C, ARegion *region, StringRef category)
void button_flag_enable(Button *but, int64_t flag)
void draw_roundbox_corner_set(int type)
bool panel_category_tabs_is_visible(const ARegion *region)
void blocklist_free_inactive(const bContext *C, ARegion *region)
void panels_free_instanced(const bContext *C, ARegion *region)
void region_button_sections_draw(const ARegion *region, int colorid, ButtonSectionsAlign align)
bool panel_is_active(const Panel *panel)
float view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1902
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void 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 list_panel_unique_str(Panel *panel, char *r_name)
void block_layout_free(Block *block)
int2 block_layout_resolve(Block *block)
void draw_roundbox_3fv_alpha(const rctf *rect, bool filled, float rad, const float col[3], float alpha)
void panel_header_buttons_begin(Panel *panel)
@ V2D_COMMONVIEW_HEADER
Definition UI_view2d.hh:64
@ V2D_COMMONVIEW_PANELS_UI
Definition UI_view2d.hh:66
void icon_draw_alpha(float x, float y, int icon_id, float alpha)
PointerRNA * button_extra_operator_icon_add(Button *but, StringRefNull opname, wm::OpCallContext opcontext, int icon)
void region_message_subscribe(ARegion *region, wmMsgBus *mbus)
void panel_category_tabs_draw_all(const bContext *C, ARegion *region, const char *category_id_active)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
bool panel_category_is_visible(const ARegion *region)
void region_handlers_add(ListBaseT< wmEventHandler > *handlers)
void blocklist_update_view_for_buttons(const bContext *C, const ListBaseT< ui::Block > *lb)
const char * panel_category_active_get(ARegion *region, bool set_fallback)
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
bool panel_is_dragging(const Panel *panel)
Panel * panel_find_by_type(ListBaseT< Panel > *lb, const PanelType *pt)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
static void region_visible_rect_calc(ARegion *region, rcti *rect)
Definition area.cc:4737
ScrArea * ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area)
Definition area.cc:4500
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
static constexpr float STATUS_AFTER_TEXT
Definition area.cc:1045
UserDef U
Definition blender.cc:58
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
bool BLI_rcti_is_valid(const struct rcti *rect)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void region_draw_gradient(const ARegion *region)
Definition area.cc:75
void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int offset)
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
gpu::FrameBuffer * GPU_framebuffer_active_get()
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
ScrArea * CTX_wm_area(const bContext *C)
void wmOrtho2_region_pixelspace(const ARegion *region)
bool BKE_regiontype_uses_panel_categories_search(const ARegionType *region_type)
Definition screen.cc:417
void ED_region_blend_rect(ARegion *region, rcti *r_rect)
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
Definition area.cc:2628
void ED_area_tag_redraw_no_rebuild(ScrArea *area)
Definition area.cc:793
uint padding(uint offset, uint alignment)
static void ed_workspace_status_text_item(WorkSpace *workspace, std::string text)
Definition area.cc:1048
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
void ED_region_update_rect(ARegion *region)
Definition area.cc:2539
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
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:835
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:1010
void BKE_screen_area_free(ScrArea *area)
Definition screen.cc:783
void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2290
static bool area_is_pseudo_minimized(const ScrArea *area)
Definition area.cc:490
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static const char * region_panels_collect_categories(ARegion *region, LinkNode *panel_types_stack, bool *use_categories)
Definition area.cc:3445
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void ED_region_do_listen(wmRegionListenerParams *params)
Definition area.cc:102
static bool region_azone_edge_poll(const ScrArea *area, const ARegion *region, const bool is_fullscreen)
Definition area.cc:1385
static void region_azone_edge(const ScrArea *area, AZone *az, const ARegion *region)
Definition area.cc:1301
int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
Definition area.cc:873
void GPU_clear_color(float red, float green, float blue, float alpha)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
WorkSpace * CTX_wm_workspace(const bContext *C)
const char * ED_buttons_search_string_get(SpaceProperties *sbuts)
bool WM_cursor_set_from_tool(wmWindow *win, const ScrArea *area, const ARegion *region)
void ED_region_visibility_change_update_ex(bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
Definition area.cc:2580
@ RGN_TYPE_ASSET_SHELF_HEADER
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static void area_azone_init(const wmWindow *win, const bScreen *screen, ScrArea *area)
Definition area.cc:1165
const char * ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region)
Definition area.cc:936
MINLINE int round_fl_to_int(float a)
static bool panel_add_check(const bContext *C, const WorkSpace *workspace, const char *contexts[], const char *category_override, PanelType *panel_type)
Definition area.cc:3405
static void region_azones_scrollbars_init(ScrArea *area, ARegion *region)
Definition area.cc:1475
ScrArea * WM_window_status_area_find(wmWindow *win, bScreen *screen)
void ED_region_do_layout(bContext *C, ARegion *region)
Definition area.cc:495
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
void ED_area_do_msg_notify_tag_refresh(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:417
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
BLI_INLINE float fb(float length, float L)
bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
Definition workspace.cc:607
void GPU_matrix_identity_set()
static void region_clear_fully_transparent(const bContext *C)
Definition area.cc:3196
BLI_INLINE bool streq_array_any(const char *s, const char *arr[])
Definition area.cc:3210
GPUVertFormat * immVertexFormat()
bool WM_region_use_viewport(ScrArea *area, ARegion *region)
Definition wm_draw.cc:585
static void area_azone_tag_update(ScrArea *area)
Definition area.cc:297
wmEventHandler_Keymap * WM_event_add_keymap_handler_dynamic(ListBaseT< wmEventHandler > *handlers, wmEventHandler_KeymapDynamicFn keymap_fn, void *user_data)
static void region_draw_blocks_in_view2d(const bContext *C, const ARegion *region)
Definition area.cc:4344
static ThemeColorID region_background_color_id(const bContext *, const ARegion *region)
Definition area.cc:3168
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
void BKE_area_region_free(SpaceType *st, ARegion *region)
Definition screen.cc:736
void ED_area_prevspace(bContext *C, ScrArea *area)
Definition area.cc:3111
bool BKE_regiontype_uses_category_tabs(const ARegionType *region_type)
Definition screen.cc:407
void ED_region_cache_draw_background(ARegion *region)
Definition area.cc:4806
AZone * ED_area_azones_update(ScrArea *area, const int mouse_xy[2])
static void area_offscreen_init(ScrArea *area)
Definition area.cc:2468
void ED_region_panels_ex(const bContext *C, ARegion *region, wm::OpCallContext op_context, const char *contexts[])
Definition area.cc:3988
void immBegin(GPUPrimType, uint vertex_len)
bool ED_region_property_search(const bContext *C, ARegion *region, ListBaseT< PanelType > *paneltypes, const char *contexts[], const char *category_override)
Definition area.cc:4173
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static bool region_background_is_transparent(const ScrArea *area, const ARegion *region)
Definition area.cc:1286
bool ED_region_is_overlap(int spacetype, int regiontype)
Definition area.cc:1653
@ RGN_DRAW_EDITOR_OVERLAYS
void WM_draw_region_free(ARegion *region)
Definition wm_draw.cc:1788
static void area_draw_azone(ScrArea *area, ARegion *region, AZone *az)
Corner widgets use for dragging and splitting the view.
Definition area.cc:182
void WM_gizmomap_message_subscribe(const bContext *C, wmGizmoMap *gzmap, ARegion *region, wmMsgBus *mbus)
void ED_area_newspace(bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition area.cc:2929
int ED_area_headersize()
Definition area.cc:4418
wmWindow * CTX_wm_window(const bContext *C)
void BKE_area_region_panels_free(ListBaseT< Panel > *panels)
Definition screen.cc:724
static void region_azone_edge_init(ScrArea *area, ARegion *region, AZEdge edge, const bool is_fullscreen)
Definition area.cc:1428
void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src)
Definition area.cc:2637
MINLINE int max_ii(int a, int b)
void ED_region_search_filter_update(const ScrArea *area, ARegion *region)
Definition area.cc:957
int WM_window_native_pixel_x(const wmWindow *win)
void immUniformColor4fv(const float rgba[4])
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4791
void WM_gizmomap_add_handlers(ARegion *region, wmGizmoMap *gzmap)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
static int rct_fits(const rcti *rect, const eScreenAxis dir_axis, int size)
Definition area.cc:1548
@ GPU_DRIVER_OPENSOURCE
void ED_region_header_draw(const bContext *C, ARegion *region)
Definition area.cc:4358
static void region_rect_recursive(ScrArea *area, ARegion *region, rcti *remainder, rcti *overlap_remainder, int quad)
Definition area.cc:1703
static void region_align_info_from_area(ScrArea *area, RegionTypeAlignInfo *r_align_info)
Definition area.cc:2673
bool ED_area_has_shared_border(ScrArea *a, ScrArea *b)
Definition area.cc:2328
void ED_region_tag_redraw_cursor(ARegion *region)
Definition area.cc:720
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:745
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void ED_region_do_draw(bContext *C, ARegion *region)
Definition area.cc:515
void ED_region_cache_draw_cached_segments(ARegion *region, int num_segments, const int *points, int sfra, int efra)
Definition area.cc:4854
void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
Definition area.cc:2893
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void ED_region_clear(const bContext *C, const ARegion *region, int colorid)
Definition area.cc:3181
bool ED_region_snap_size_apply(ARegion *region, int snap_flag)
Definition area.cc:4922
void immUnbindProgram()
static void area_calc_totrct(const bScreen *screen, ScrArea *area, const rcti *window_rect)
Definition area.cc:2107
static void region_update_rect(ARegion *region)
Definition area.cc:2530
void BLI_rcti_sanitize(struct rcti *rect)
Definition rct.cc:460
ARegion * BKE_area_region_copy(const SpaceType *st, const ARegion *region)
Definition screen.cc:479
void ED_area_tag_redraw_regiontype(ScrArea *area, int regiontype)
Definition area.cc:802
MINLINE void mul_v3_fl(float r[3], float f)
void GPU_line_width(float width)
Definition gpu_state.cc:151
static bool side_region_search_for_context(const bContext *C, ARegion *region, StringRef category)
Definition area.cc:4098
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ RGN_ALIGN_HIDE_WITH_PREV
Global G
Definition blender.cc:57
VecBase< float, 4 > float4
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:2748
void immAttr3fv(uint attr_id, const float data[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static void region_azones_add_edge(ScrArea *area, ARegion *region, const int alignment, const bool is_fullscreen)
Definition area.cc:1487
int ED_region_global_size_y()
Definition area.cc:4515
static void region_draw_azone_tab_arrow(ScrArea *area, ARegion *region, AZone *az)
Definition area.cc:260
void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
bool BKE_regiontype_uses_categories(const ARegionType *region_type)
Definition screen.cc:398
int ED_area_global_min_size_y(const ScrArea *area)
Definition area.cc:4434
int BLF_set_default()
void immUniformThemeColor(int color_id)
void BLF_size(int fontid, float size)
Definition blf.cc:445
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void WM_event_remove_handlers(bContext *C, ListBaseT< wmEventHandler > *handlers)
void ED_region_draw_overflow_indication(const ScrArea *area, const ARegion *region, const rcti *mask=nullptr)
Definition area.cc:3726
void ED_region_visibility_change_update_animated(bContext *C, ScrArea *area, ARegion *region)
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBaseT< wmEventHandler > *handlers, ListBaseT< wmDropBox > *dropboxes)
VecBase< int32_t, 2 > int2
Scene * WM_window_get_active_scene(const wmWindow *win)
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
void ED_region_tag_refresh_ui(ARegion *region)
Definition area.cc:738
static void region_evaluate_visibility(ARegion *region)
Definition area.cc:2158
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
static void ed_workspace_status_icon_item(WorkSpace *workspace, const int icon, const bool inverted=false)
Definition area.cc:1057
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
static void region_overlap_fix(ScrArea *area, ARegion *region)
Definition area.cc:1572
BMesh const char void * data
void ED_region_header_with_button_sections(const bContext *C, ARegion *region, ui::ButtonSectionsAlign align)
Definition area.cc:4398
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:253
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
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:4037
void ED_area_offscreen_free(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2522
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
static bool region_is_hidden(const ARegion *region)
Definition area.cc:1559
static constexpr float STATUS_MOUSE_ICON_PAD
Definition area.cc:1046
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3999
void ED_area_exit(bContext *C, ScrArea *area)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
static void ed_default_handlers(wmWindowManager *wm, ScrArea *area, ARegion *region, ListBaseT< wmEventHandler > *handlers, int flag)
Definition area.cc:2179
bool ED_time_scrub_event_in_region_poll(const wmWindow *, const ScrArea *, const ARegion *region, const wmEvent *event)
static void area_init_type_fallback(ScrArea *area, eSpace_Type space_type)
Definition area.cc:2336
void immUniformColor4f(float r, float g, float b, float a)
@ AE_RIGHT_TO_TOPLEFT
@ AE_BOTTOM_TO_TOPLEFT
@ AE_LEFT_TO_TOPRIGHT
@ AE_TOP_TO_BOTTOMRIGHT
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
static void fullscreen_azone_init(ScrArea *area, ARegion *region)
Definition area.cc:1239
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:945
int ED_area_footersize()
Definition area.cc:4424
ARegionType * BKE_regiontype_from_id(const SpaceType *st, int regionid)
Definition screen.cc:364
static void region_azone_scrollbar_init(ScrArea *area, ARegion *region, AZScrollDirection direction)
Definition area.cc:1453
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:354
void ED_area_do_refresh(bContext *C, ScrArea *area)
Definition area.cc:148
void ED_area_tag_region_size_update(ScrArea *area, ARegion *changed_region)
Definition area.cc:820
void WM_event_get_keymap_from_toolsystem_with_gizmos(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
int ED_area_global_size_y(const ScrArea *area)
Definition area.cc:4429
static void region_align_info_to_area(ScrArea *area, const RegionTypeAlignInfo region_align_info_src[RGN_TYPE_NUM])
Definition area.cc:2863
static void region_draw_status_text(ScrArea *, ARegion *region)
Definition area.cc:347
void BKE_area_copy(ScrArea *area_dst, ScrArea *area_src)
Definition screen.cc:999
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:201
void ED_area_do_mgs_subscribe_for_tool_ui(const wmRegionMessageSubscribeParams *params)
Definition area.cc:442
void ED_region_floating_init(ARegion *region)
Definition area.cc:2544
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
ScrArea * ED_screen_areas_iter_first(const wmWindow *win, const bScreen *screen)
Definition area.cc:4487
void ED_region_image_metadata_panel_draw(ImBuf *ibuf, ui::Layout *layout)
Definition area.cc:4623
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
static void side_region_search_all_categories(const bContext *C, ARegion *region_original)
Definition area.cc:4111
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2623
bool WM_gizmomap_cursor_set(const wmGizmoMap *gzmap, wmWindow *win)
const char * ED_userpref_search_string_get(SpaceUserPref *sprefs)
void GPU_matrix_translate_2f(float x, float y)
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
Definition screen.cc:1226
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBaseT< PanelType > *paneltypes, wm::OpCallContext op_context, const char *contexts[], const char *category_override)
Definition area.cc:3524
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
static int panel_draw_width_from_max_width_get(const ARegion *region, const PanelType *panel_type, const int max_width)
Definition area.cc:3469
static void side_region_search_move_next_category_with_result(const bContext *C, ARegion *region)
Definition area.cc:3481
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool WM_event_handler_region_marker_poll(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event)
@ ED_KEYMAP_UI
Definition ED_screen.hh:852
@ ED_KEYMAP_NAVBAR
Definition ED_screen.hh:861
@ ED_KEYMAP_FOOTER
Definition ED_screen.hh:859
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:858
@ ED_KEYMAP_GPENCIL
Definition ED_screen.hh:860
@ ED_KEYMAP_TOOL
Definition ED_screen.hh:854
@ ED_KEYMAP_ANIMATION
Definition ED_screen.hh:856
@ ED_KEYMAP_ASSET_SHELF
Definition ED_screen.hh:862
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:855
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:857
@ ED_KEYMAP_GIZMO
Definition ED_screen.hh:853
void ED_region_message_subscribe(wmRegionMessageSubscribeParams *params)
Definition area.cc:4884
static void area_offscreen_exit(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2492
bool area_regions_poll(bContext *C, const bScreen *screen, ScrArea *area)
wmEventHandler_Keymap * WM_event_add_keymap_handler_poll(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap, EventHandlerPoll poll)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ WM_CAPABILITY_WINDOW_DECORATION_STYLES
Definition WM_api.hh:243
ScrArea * ED_area_find_under_cursor(const bContext *C, int spacetype, const int event_xy[2])
Definition area.cc:4456
void ED_region_visibility_change_update(bContext *C, ScrArea *area, ARegion *region)
Definition area.cc:2599
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
SpaceImage * CTX_wm_space_image(const bContext *C)
@ V2D_SCROLL_HORIZONTAL
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
void ED_region_header_draw_with_button_sections(const bContext *C, const ARegion *region, ui::ButtonSectionsAlign align)
Definition area.cc:4373
void ED_area_and_region_types_init(ScrArea *area)
Definition area.cc:2366
static void quadview_azone_init(ScrArea *area, ARegion *region)
Definition area.cc:1266
void ED_region_pixelspace(const ARegion *region)
Definition area.cc:96
static short region_alignment_from_header_and_tool_header_state(const RegionTypeAlignInfo *region_align_info, const short fallback)
Definition area.cc:2701
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
static void region_draw_azones(ScrArea *area, ARegion *region)
Definition area.cc:302
void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
Definition area.cc:2383
ScrArea * ED_area_offscreen_create(wmWindow *win, eSpace_Type space_type)
Definition area.cc:2481
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BKE_workspace_status_clear(WorkSpace *workspace)
Definition workspace.cc:720
Main * CTX_data_main(const bContext *C)
void ED_region_cursor_set(wmWindow *win, ScrArea *area, ARegion *region)
Definition area.cc:2554
@ PANEL_TYPE_HEADER_EXPAND
@ PANEL_TYPE_NO_HEADER
@ PANEL_TYPE_LAYOUT_VERT_BAR
@ PANEL_TYPE_NO_SEARCH
@ PANEL_TYPE_INSTANCED
void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, float y0)
Definition area.cc:4636
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
eWM_CapabilitiesFlag WM_capabilities_flag()
std::array< const char *, 4 > ED_view3d_buttons_contexts(const bContext *C)
wmGizmoMap * WM_gizmomap_new_from_type(const wmGizmoMapType_Params *gzmap_params)
int ED_area_global_max_size_y(const ScrArea *area)
Definition area.cc:4439
void WM_window_title_refresh(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:718
void IMB_metadata_foreach(const ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
bool WM_toolsystem_refresh_screen_area(const Main &bmain, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
void ED_area_hud_region_set_padding_flag(ScrArea *area, ARegion *changed_region, const bool set_padding=false)
Definition area.cc:851
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
void BLI_str_rstrip(char *str) ATTR_NONNULL(1)
int ED_area_header_switchbutton(const bContext *C, ui::Block *block, int yco)
Definition area.cc:3137
static SpaceLink * area_get_prevspace(ScrArea *area)
Definition area.cc:3089
@ G_TRANSFORM_WM
@ KM_NOTHING
Definition WM_types.hh:323
void GPU_vertformat_clear(GPUVertFormat *)
Scene * CTX_data_scene(const bContext *C)
bool BKE_region_panel_categories_search_filter_visible(const ARegion *region)
Definition screen.cc:422
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void WM_cursor_set(wmWindow *win, int curs)
void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void ED_area_do_mgs_subscribe_for_tool_header(const wmRegionMessageSubscribeParams *params)
Definition area.cc:427
void ED_region_panels_layout(const bContext *C, ARegion *region)
Definition area.cc:3835
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ RGN_FLAG_INDICATE_OVERFLOW
@ RGN_FLAG_SEARCH_FILTER_ACTIVE
@ RGN_FLAG_SEARCH_FILTER_UPDATE
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:813
void ED_region_header_layout(const bContext *C, ARegion *region)
Definition area.cc:4257
void BLI_rcti_resize(struct rcti *rect, int x, int y)
Definition rct.cc:635
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
void ED_region_info_draw_multiline(ARegion *region, const char *text_array[], const float fill_color[4], bool full_redraw)
Definition area.cc:4526
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
static constexpr float STATUS_BEFORE_TEXT
Definition area.cc:1044
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
static void region_azones_add(const bScreen *screen, ScrArea *area, ARegion *region)
Definition area.cc:1508
void region_toggle_hidden(bContext *C, ARegion *region, const bool do_fade)
Definition area.cc:2606
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
Definition area.cc:696
void WM_event_add_mousemove(wmWindow *win)
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:822
void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
Definition area.cc:757
void GPU_matrix_pop()
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:4391
bScreen * WM_window_get_active_screen(const wmWindow *win)
static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region)
Definition area.cc:1347
static void ed_workspace_status_space(WorkSpace *workspace, const float space_factor)
Definition area.cc:1029
MINLINE int min_ii(int a, int b)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void ED_region_panels_draw(const bContext *C, ARegion *region)
Definition area.cc:3916
void side_region_property_search(const bContext *C, ARegion *region)
Definition area.cc:4163
ARegion * CTX_wm_region(const bContext *C)
void WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:4006
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
void ED_region_cache_draw_curfra_label(int framenr, float x, float y)
Definition area.cc:4819
int ED_region_snap_size_test(const ARegion *region)
Definition area.cc:4909
@ USER_APP_LOCK_CORNER_SPLIT
@ USER_APP_HIDE_REGION_TOGGLE
@ USER_APP_LOCK_EDGE_RESIZE
void ED_region_info_draw(ARegion *region, const char *text, const float fill_color[4], bool full_redraw)
Definition area.cc:4602
static void side_panel_draw_search_block(const bContext *C, ARegion *region)
Definition area.cc:3845
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
View3D * CTX_wm_view3d(const bContext *C)
@ BLF_CLIPPING
Definition BLF_enums.hh:37
void BLF_batch_discard()
Definition blf_font.cc:348
void GPU_matrix_push()
bool WM_window_is_fullscreen(const wmWindow *win)
@ AREA_FLAG_REGION_SIZE_UPDATE
@ AREA_FLAG_ACTIONZONES_UPDATE
@ AREA_FLAG_ACTIVE_TOOL_UPDATE
@ AREA_FLAG_STACKED_FULLSCREEN
bool ED_area_is_global(const ScrArea *area)
Definition area.cc:4451
static void metadata_panel_draw_field(const char *field, const char *value, void *ctx_v)
Definition area.cc:4615
@ AZ_SCROLL_VERT
@ AZ_SCROLL_HOR
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
std::array< const char *, 4 > ED_image_buttons_contexts(const bContext *C)
static void area_draw_azone_fullscreen(short, short, short x2, short y2, float alpha)
Corner widget use for quitting full-screen.
Definition area.cc:166
void ED_area_do_listen(wmSpaceTypeListenerParams *params)
Definition area.cc:140
void void BLI_INLINE bool BLI_listbase_is_single(const ListBase *lb)
void CTX_wm_area_set(bContext *C, ScrArea *area)
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
static void ed_panel_draw(const bContext *C, ARegion *region, ListBaseT< Panel > *lb, PanelType *pt, Panel *panel, int w, int em, char *unique_panel_str, const char *search_filter, wm::OpCallContext op_context)
Definition area.cc:3229
void screen_area_spacelink_add(const Scene *scene, ScrArea *area, eSpace_Type space_type)
#define floorf
#define fabsf
#define AZONEFADEOUT
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
unsigned char header[4]
ThemeSpace space_view3d
void(*) exit(wmWindowManager *wm, ARegion *region)
void(*) cursor(wmWindow *win, ScrArea *area, ARegion *region)
int(*) snap_size(const ARegion *region, int size, int axis)
void(*) message_subscribe(const wmRegionMessageSubscribeParams *params)
void(*) draw(const bContext *C, ARegion *region)
ListBaseT< HeaderType > headertypes
void(*) listener(const wmRegionListenerParams *params)
void(*) layout(const bContext *C, ARegion *region)
std::optional< ARegionIMECursorState >(*) cursor_ime(wmWindow *win, const ScrArea *area, const ARegion *region, ARegionIMECursor *r_cursor)
ListBaseT< PanelType > paneltypes
void(*) init(wmWindowManager *wm, ARegion *region)
ListBaseT< uiList > ui_lists
struct ARegion * next
ListBaseT< Panel > panels
bke::ARegionRuntime * runtime
struct ARegion * prev
eRegion_Alignment alignment
eRegion_Type regiontype
ListBaseT< PanelCategoryStack > panels_category_active
ARegion * region
HeaderType * next
bool(*) poll(const bContext *C, HeaderType *ht)
char idname[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Header *header)
ui::Layout * layout
HeaderType * type
struct LinkNode * next
PanelType * parent
ListBaseT< LinkData > children
void(*) draw_header_preset(const bContext *C, Panel *panel)
char context[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Panel *panel)
char category[BKE_ST_MAXNAME]
bool(*) poll(const bContext *C, PanelType *pt)
void(*) draw_header(const bContext *C, Panel *panel)
char idname[BKE_ST_MAXNAME]
LayoutPanels layout_panels
struct PanelType * type
ListBaseT< Panel > children
ui::Layout * layout
struct Panel_Runtime * runtime
struct blender::RegionTypeAlignInfo::@330321312102166170135030316252357105161245251177 by_type[RGN_TYPE_NUM]
ListBaseT< ScrArea > areabase
ListBaseT< struct wmEventHandler > handlers
ListBaseT< struct AZone > actionzones
ListBaseT< ARegion > regionbase
ScrArea_Runtime runtime
struct ScrArea * next
ListBaseT< SpaceLink > spacedata
ScrGlobalAreaData * global
struct SpaceType * type
int(*) space_subtype_get(ScrArea *area)
void(*) init(wmWindowManager *wm, ScrArea *area)
SpaceLink *(*) create(const ScrArea *area, const Scene *scene)
void(*) refresh(const bContext *C, ScrArea *area)
void(*) free(SpaceLink *sl)
void(*) exit(wmWindowManager *wm, ScrArea *area)
void(*) space_subtype_item_extend(bContext *C, EnumPropertyItem **item, int *totitem)
void(*) space_subtype_set(ScrArea *area, int value)
void(*) listener(const wmSpaceTypeListenerParams *params)
eView2D_KeepOfs keepofs
eView2D_Scroll scroll
bke::WorkSpaceRuntime * runtime
eScreen_State state
struct wmTimer * animtimer
struct ARegion * active_region
ListBaseT< struct ScrArea > areabase
ListBaseT< wmEventHandler > handlers
Vector< std::function< void(const bContext &C, ui::Block &Block)> > post_block_layout_fns
ListBaseT< ui::Block > uiblocks
ListBaseT< PanelCategoryDyn > panels_category
ARegionQuadviewIndex quadview_index
ARegionRuntimeFlag flag
struct ARegionType * type
Set< std::string > categories_search_match
Vector< WorkSpaceStatusItem > status
void operator_context_set(wm::OpCallContext opcontext)
void label(StringRef name, int icon)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void scale_y_set(float scale)
Layout & row(bool align)
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371
bke::WindowRuntime * runtime
struct WorkSpaceInstanceHook * workspace_hook
short panelspace
uiFontStyle widget
#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value)