mirrored from https://projects.blender.org/blender/blender.git
/
area.c
3814 lines (3264 loc) · 118 KB
/
area.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup edscr
*/
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
#include "BLI_linklist_stack.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_screen.h"
#include "BKE_workspace.h"
#include "RNA_access.h"
#include "RNA_types.h"
#include "WM_api.h"
#include "WM_message.h"
#include "WM_toolsystem.h"
#include "WM_types.h"
#include "ED_buttons.h"
#include "ED_screen.h"
#include "ED_screen_types.h"
#include "ED_space_api.h"
#include "ED_time_scrub_ui.h"
#include "GPU_framebuffer.h"
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "BLF_api.h"
#include "IMB_imbuf_types.h"
#include "IMB_metadata.h"
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "screen_intern.h"
enum RegionEmbossSide {
REGION_EMBOSS_LEFT = (1 << 0),
REGION_EMBOSS_TOP = (1 << 1),
REGION_EMBOSS_BOTTOM = (1 << 2),
REGION_EMBOSS_RIGHT = (1 << 3),
REGION_EMBOSS_ALL = REGION_EMBOSS_LEFT | REGION_EMBOSS_TOP | REGION_EMBOSS_RIGHT |
REGION_EMBOSS_BOTTOM,
};
/* general area and region code */
static void region_draw_emboss(const ARegion *region, const rcti *scirct, int sides)
{
/* translate scissor rect to region space */
const rcti rect = {.xmin = scirct->xmin - region->winrct.xmin,
.xmax = scirct->xmax - region->winrct.xmin,
.ymin = scirct->ymin - region->winrct.ymin,
.ymax = scirct->ymax - region->winrct.ymin};
/* set transp line */
GPU_blend(GPU_BLEND_ALPHA);
float color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
UI_GetThemeColor3fv(TH_EDITOR_OUTLINE, color);
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4fv(color);
immBeginAtMost(GPU_PRIM_LINES, 8);
/* right */
if (sides & REGION_EMBOSS_RIGHT) {
immVertex2f(pos, rect.xmax, rect.ymax);
immVertex2f(pos, rect.xmax, rect.ymin);
}
/* bottom */
if (sides & REGION_EMBOSS_BOTTOM) {
immVertex2f(pos, rect.xmax, rect.ymin);
immVertex2f(pos, rect.xmin, rect.ymin);
}
/* left */
if (sides & REGION_EMBOSS_LEFT) {
immVertex2f(pos, rect.xmin, rect.ymin);
immVertex2f(pos, rect.xmin, rect.ymax);
}
/* top */
if (sides & REGION_EMBOSS_TOP) {
immVertex2f(pos, rect.xmin, rect.ymax);
immVertex2f(pos, rect.xmax, rect.ymax);
}
immEnd();
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
}
void ED_region_pixelspace(ARegion *region)
{
wmOrtho2_region_pixelspace(region);
GPU_matrix_identity_set();
}
/* only exported for WM */
void ED_region_do_listen(wmRegionListenerParams *params)
{
ARegion *region = params->region;
wmNotifier *notifier = params->notifier;
/* generic notes first */
switch (notifier->category) {
case NC_WM:
if (notifier->data == ND_FILEREAD) {
ED_region_tag_redraw(region);
}
break;
case NC_WINDOW:
ED_region_tag_redraw(region);
break;
}
if (region->type && region->type->listener) {
region->type->listener(params);
}
}
/* only exported for WM */
void ED_area_do_listen(wmSpaceTypeListenerParams *params)
{
/* no generic notes? */
if (params->area->type && params->area->type->listener) {
params->area->type->listener(params);
}
}
/* only exported for WM */
void ED_area_do_refresh(bContext *C, ScrArea *area)
{
/* no generic notes? */
if (area->type && area->type->refresh) {
area->type->refresh(C, area);
}
area->do_refresh = false;
}
/**
* \brief Corner widget use for quitting fullscreen.
*/
static void area_draw_azone_fullscreen(
short UNUSED(x1), short UNUSED(y1), short x2, short y2, float alpha)
{
UI_icon_draw_ex(x2 - U.widget_unit,
y2 - U.widget_unit,
ICON_FULLSCREEN_EXIT,
U.inv_dpi_fac,
min_ff(alpha, 0.75f),
0.0f,
NULL,
false);
}
/**
* \brief Corner widgets use for dragging and splitting the view.
*/
static void area_draw_azone(short UNUSED(x1), short UNUSED(y1), short UNUSED(x2), short UNUSED(y2))
{
/* No drawing needed since all corners are action zone, and visually distinguishable. */
}
/**
* \brief Edge widgets to show hidden panels such as the toolbar and headers.
*/
static void draw_azone_arrow(float x1, float y1, float x2, float y2, AZEdge edge)
{
const float size = 0.2f * U.widget_unit;
const float l = 1.0f; /* arrow length */
const float s = 0.25f; /* arrow thickness */
const float hl = l / 2.0f;
const float points[6][2] = {
{0, -hl}, {l, hl}, {l - s, hl + s}, {0, s + s - hl}, {s - l, hl + s}, {-l, hl}};
const float center[2] = {(x1 + x2) / 2, (y1 + y2) / 2};
int axis;
int sign;
switch (edge) {
case AE_BOTTOM_TO_TOPLEFT:
axis = 0;
sign = 1;
break;
case AE_TOP_TO_BOTTOMRIGHT:
axis = 0;
sign = -1;
break;
case AE_LEFT_TO_TOPRIGHT:
axis = 1;
sign = 1;
break;
case AE_RIGHT_TO_TOPLEFT:
axis = 1;
sign = -1;
break;
default:
BLI_assert(0);
return;
}
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
GPU_blend(GPU_BLEND_ALPHA);
/* NOTE(fclem): There is something strange going on with Mesa and GPU_SHADER_2D_UNIFORM_COLOR
* that causes a crash on some GPUs (see T76113). Using 3D variant avoid the issue. */
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformColor4f(0.8f, 0.8f, 0.8f, 0.4f);
immBegin(GPU_PRIM_TRI_FAN, 6);
for (int i = 0; i < 6; i++) {
if (axis == 0) {
immVertex2f(pos, center[0] + points[i][0] * size, center[1] + points[i][1] * sign * size);
}
else {
immVertex2f(pos, center[0] + points[i][1] * sign * size, center[1] + points[i][0] * size);
}
}
immEnd();
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
}
static void region_draw_azone_tab_arrow(ScrArea *area, ARegion *region, AZone *az)
{
GPU_blend(GPU_BLEND_ALPHA);
/* add code to draw region hidden as 'too small' */
switch (az->edge) {
case AE_TOP_TO_BOTTOMRIGHT:
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
break;
case AE_BOTTOM_TO_TOPLEFT:
UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
break;
case AE_LEFT_TO_TOPRIGHT:
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
break;
case AE_RIGHT_TO_TOPLEFT:
UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
break;
}
/* Workaround for different color spaces between normal areas and the ones using GPUViewports. */
float alpha = WM_region_use_viewport(area, region) ? 0.6f : 0.4f;
const float color[4] = {0.05f, 0.05f, 0.05f, alpha};
UI_draw_roundbox_aa(
&(const rctf){
.xmin = (float)az->x1,
.xmax = (float)az->x2,
.ymin = (float)az->y1,
.ymax = (float)az->y2,
},
true,
4.0f,
color);
draw_azone_arrow((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, az->edge);
}
static void area_azone_tag_update(ScrArea *area)
{
area->flag |= AREA_FLAG_ACTIONZONES_UPDATE;
}
static void region_draw_azones(ScrArea *area, ARegion *region)
{
if (!area) {
return;
}
GPU_line_width(1.0f);
GPU_blend(GPU_BLEND_ALPHA);
GPU_matrix_push();
GPU_matrix_translate_2f(-region->winrct.xmin, -region->winrct.ymin);
LISTBASE_FOREACH (AZone *, az, &area->actionzones) {
/* test if action zone is over this region */
rcti azrct;
BLI_rcti_init(&azrct, az->x1, az->x2, az->y1, az->y2);
if (BLI_rcti_isect(®ion->drawrct, &azrct, NULL)) {
if (az->type == AZONE_AREA) {
area_draw_azone(az->x1, az->y1, az->x2, az->y2);
}
else if (az->type == AZONE_REGION) {
if (az->region) {
/* only display tab or icons when the region is hidden */
if (az->region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
region_draw_azone_tab_arrow(area, region, az);
}
}
}
else if (az->type == AZONE_FULLSCREEN) {
if (az->alpha > 0.0f) {
area_draw_azone_fullscreen(az->x1, az->y1, az->x2, az->y2, az->alpha);
}
}
}
if (!IS_EQF(az->alpha, 0.0f) && ELEM(az->type, AZONE_FULLSCREEN, AZONE_REGION_SCROLL)) {
area_azone_tag_update(area);
}
}
GPU_matrix_pop();
GPU_blend(GPU_BLEND_NONE);
}
static void region_draw_status_text(ScrArea *area, ARegion *region)
{
bool overlap = ED_region_is_overlap(area->spacetype, region->regiontype);
if (overlap) {
GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
}
else {
UI_ThemeClearColor(TH_HEADER);
}
int fontid = BLF_set_default();
const float width = BLF_width(fontid, region->headerstr, BLF_DRAW_STR_DUMMY_MAX);
const float x = UI_UNIT_X;
const float y = 0.4f * UI_UNIT_Y;
if (overlap) {
const float pad = 2.0f * UI_DPI_FAC;
const float x1 = x - (UI_UNIT_X - pad);
const float x2 = x + width + (UI_UNIT_X - pad);
const float y1 = pad;
const float y2 = region->winy - pad;
GPU_blend(GPU_BLEND_ALPHA);
float color[4] = {0.0f, 0.0f, 0.0f, 0.5f};
UI_GetThemeColor3fv(TH_BACK, color);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_aa(
&(const rctf){
.xmin = x1,
.xmax = x2,
.ymin = y1,
.ymax = y2,
},
true,
4.0f,
color);
UI_FontThemeColor(fontid, TH_TEXT);
}
else {
UI_FontThemeColor(fontid, TH_TEXT);
}
BLF_position(fontid, x, y, 0.0f);
BLF_draw(fontid, region->headerstr, BLF_DRAW_STR_DUMMY_MAX);
}
void ED_region_do_msg_notify_tag_redraw(
/* Follow wmMsgNotifyFn spec */
bContext *UNUSED(C),
wmMsgSubscribeKey *UNUSED(msg_key),
wmMsgSubscribeValue *msg_val)
{
ARegion *region = msg_val->owner;
ED_region_tag_redraw(region);
/* This avoids _many_ situations where header/properties control display settings.
* the common case is space properties in the header */
if (ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_UI)) {
while (region && region->prev) {
region = region->prev;
}
for (; region; region = region->next) {
if (ELEM(region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS)) {
ED_region_tag_redraw(region);
}
}
}
}
void ED_area_do_msg_notify_tag_refresh(
/* Follow wmMsgNotifyFn spec */
bContext *UNUSED(C),
wmMsgSubscribeKey *UNUSED(msg_key),
wmMsgSubscribeValue *msg_val)
{
ScrArea *area = msg_val->user_data;
ED_area_tag_refresh(area);
}
/* Follow ARegionType.message_subscribe */
void ED_area_do_mgs_subscribe_for_tool_header(const wmRegionMessageSubscribeParams *params)
{
struct wmMsgBus *mbus = params->message_bus;
WorkSpace *workspace = params->workspace;
ARegion *region = params->region;
BLI_assert(region->regiontype == RGN_TYPE_TOOL_HEADER);
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
.owner = region,
.user_data = region,
.notify = ED_region_do_msg_notify_tag_redraw,
};
WM_msg_subscribe_rna_prop(
mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
}
void ED_area_do_mgs_subscribe_for_tool_ui(const wmRegionMessageSubscribeParams *params)
{
struct wmMsgBus *mbus = params->message_bus;
WorkSpace *workspace = params->workspace;
ARegion *region = params->region;
BLI_assert(region->regiontype == RGN_TYPE_UI);
const char *panel_category_tool = "Tool";
const char *category = UI_panel_category_active_get(region, false);
bool update_region = false;
if (category && STREQ(category, panel_category_tool)) {
update_region = true;
}
else {
/* Check if a tool category panel is pinned and visible in another category. */
LISTBASE_FOREACH (Panel *, panel, ®ion->panels) {
if (UI_panel_is_active(panel) && panel->flag & PNL_PIN &&
STREQ(panel->type->category, panel_category_tool)) {
update_region = true;
break;
}
}
}
if (update_region) {
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
.owner = region,
.user_data = region,
.notify = ED_region_do_msg_notify_tag_redraw,
};
WM_msg_subscribe_rna_prop(
mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
}
}
/**
* Although there's no general support for minimizing areas, the status-bar can
* be snapped to be only a few pixels high. A few pixels rather than 0 so it
* can be un-minimized again. We consider it pseudo-minimized and don't draw
* it then.
*/
static bool area_is_pseudo_minimized(const ScrArea *area)
{
return (area->winx < 3) || (area->winy < 3);
}
/* only exported for WM */
void ED_region_do_layout(bContext *C, ARegion *region)
{
/* This is optional, only needed for dynamically sized regions. */
ScrArea *area = CTX_wm_area(C);
ARegionType *at = region->type;
if (!at->layout) {
return;
}
if (at->do_lock || (area && area_is_pseudo_minimized(area))) {
return;
}
region->do_draw |= RGN_DRAWING;
UI_SetTheme(area ? area->spacetype : 0, at->regionid);
at->layout(C, region);
/* Clear temporary update flag. */
region->flag &= ~RGN_FLAG_SEARCH_FILTER_UPDATE;
}
/* only exported for WM */
void ED_region_do_draw(bContext *C, ARegion *region)
{
wmWindow *win = CTX_wm_window(C);
ScrArea *area = CTX_wm_area(C);
ARegionType *at = region->type;
/* see BKE_spacedata_draw_locks() */
if (at->do_lock) {
return;
}
region->do_draw |= RGN_DRAWING;
/* Set viewport, scissor, ortho and region->drawrct. */
wmPartialViewport(®ion->drawrct, ®ion->winrct, ®ion->drawrct);
wmOrtho2_region_pixelspace(region);
UI_SetTheme(area ? area->spacetype : 0, at->regionid);
if (area && area_is_pseudo_minimized(area)) {
UI_ThemeClearColor(TH_EDITOR_OUTLINE);
return;
}
/* optional header info instead? */
if (region->headerstr) {
region_draw_status_text(area, region);
}
else if (at->draw) {
at->draw(C, region);
}
/* XXX test: add convention to end regions always in pixel space,
* for drawing of borders/gestures etc */
ED_region_pixelspace(region);
/* Remove sRGB override by rebinding the framebuffer. */
GPUFrameBuffer *fb = GPU_framebuffer_active_get();
GPU_framebuffer_bind(fb);
ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_PIXEL);
region_draw_azones(area, region);
/* for debugging unneeded area redraws and partial redraw */
if (G.debug_value == 888) {
GPU_blend(GPU_BLEND_ALPHA);
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4f(BLI_thread_frand(0), BLI_thread_frand(0), BLI_thread_frand(0), 0.1f);
immRectf(pos,
region->drawrct.xmin - region->winrct.xmin,
region->drawrct.ymin - region->winrct.ymin,
region->drawrct.xmax - region->winrct.xmin,
region->drawrct.ymax - region->winrct.ymin);
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
}
memset(®ion->drawrct, 0, sizeof(region->drawrct));
UI_blocklist_free_inactive(C, ®ion->uiblocks);
if (area) {
const bScreen *screen = WM_window_get_active_screen(win);
/* Only region emboss for top-bar */
if ((screen->state != SCREENFULL) && ED_area_is_global(area)) {
region_draw_emboss(region, ®ion->winrct, (REGION_EMBOSS_LEFT | REGION_EMBOSS_RIGHT));
}
else if ((region->regiontype == RGN_TYPE_WINDOW) && (region->alignment == RGN_ALIGN_QSPLIT)) {
/* draw separating lines between the quad views */
float color[4] = {0.0f, 0.0f, 0.0f, 0.8f};
UI_GetThemeColor3fv(TH_EDITOR_OUTLINE, color);
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4fv(color);
GPU_line_width(1.0f);
imm_draw_box_wire_2d(pos,
0,
0,
region->winrct.xmax - region->winrct.xmin + 1,
region->winrct.ymax - region->winrct.ymin + 1);
immUnbindProgram();
}
}
/* We may want to detach message-subscriptions from drawing. */
{
WorkSpace *workspace = CTX_wm_workspace(C);
wmWindowManager *wm = CTX_wm_manager(C);
bScreen *screen = WM_window_get_active_screen(win);
Scene *scene = CTX_data_scene(C);
struct wmMsgBus *mbus = wm->message_bus;
WM_msgbus_clear_by_owner(mbus, region);
/* Cheat, always subscribe to this space type properties.
*
* This covers most cases and avoids copy-paste similar code for each space type.
*/
if (ELEM(
region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS, RGN_TYPE_UI, RGN_TYPE_TOOLS)) {
SpaceLink *sl = area->spacedata.first;
PointerRNA ptr;
RNA_pointer_create(&screen->id, &RNA_Space, sl, &ptr);
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
.owner = region,
.user_data = region,
.notify = ED_region_do_msg_notify_tag_redraw,
};
/* All properties for this space type. */
WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_region_tag_redraw, __func__);
}
wmRegionMessageSubscribeParams message_subscribe_params = {
.context = C,
.message_bus = mbus,
.workspace = workspace,
.scene = scene,
.screen = screen,
.area = area,
.region = region,
};
ED_region_message_subscribe(&message_subscribe_params);
}
}
/* **********************************
* maybe silly, but let's try for now
* to keep these tags protected
* ********************************** */
void ED_region_tag_redraw(ARegion *region)
{
/* don't tag redraw while drawing, it shouldn't happen normally
* but python scripts can cause this to happen indirectly */
if (region && !(region->do_draw & RGN_DRAWING)) {
/* zero region means full region redraw */
region->do_draw &= ~(RGN_DRAW_PARTIAL | RGN_DRAW_NO_REBUILD | RGN_DRAW_EDITOR_OVERLAYS);
region->do_draw |= RGN_DRAW;
memset(®ion->drawrct, 0, sizeof(region->drawrct));
}
}
void ED_region_tag_redraw_cursor(ARegion *region)
{
if (region) {
region->do_draw_paintcursor = RGN_DRAW;
}
}
void ED_region_tag_redraw_no_rebuild(ARegion *region)
{
if (region && !(region->do_draw & (RGN_DRAWING | RGN_DRAW))) {
region->do_draw &= ~(RGN_DRAW_PARTIAL | RGN_DRAW_EDITOR_OVERLAYS);
region->do_draw |= RGN_DRAW_NO_REBUILD;
memset(®ion->drawrct, 0, sizeof(region->drawrct));
}
}
void ED_region_tag_refresh_ui(ARegion *region)
{
if (region) {
region->do_draw |= RGN_REFRESH_UI;
}
}
/**
* Tag editor overlays to be redrawn. If in doubt about which parts need to be redrawn (partial
* clipping rectangle set), redraw everything.
*/
void ED_region_tag_redraw_editor_overlays(struct ARegion *region)
{
if (region && !(region->do_draw & (RGN_DRAWING | RGN_DRAW))) {
if (region->do_draw & RGN_DRAW_PARTIAL) {
ED_region_tag_redraw(region);
}
else {
region->do_draw |= RGN_DRAW_EDITOR_OVERLAYS;
}
}
}
void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
{
if (region && !(region->do_draw & RGN_DRAWING)) {
if (region->do_draw & RGN_DRAW_PARTIAL) {
/* Partial redraw already set, expand region. */
BLI_rcti_union(®ion->drawrct, rct);
if (rebuild) {
region->do_draw &= ~RGN_DRAW_NO_REBUILD;
}
}
else if (region->do_draw & (RGN_DRAW | RGN_DRAW_NO_REBUILD)) {
/* Full redraw already requested. */
if (rebuild) {
region->do_draw &= ~RGN_DRAW_NO_REBUILD;
}
}
else {
/* No redraw set yet, set partial region. */
region->drawrct = *rct;
region->do_draw |= RGN_DRAW_PARTIAL;
if (!rebuild) {
region->do_draw |= RGN_DRAW_NO_REBUILD;
}
}
}
}
void ED_area_tag_redraw(ScrArea *area)
{
if (area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
ED_region_tag_redraw(region);
}
}
}
void ED_area_tag_redraw_no_rebuild(ScrArea *area)
{
if (area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
ED_region_tag_redraw_no_rebuild(region);
}
}
}
void ED_area_tag_redraw_regiontype(ScrArea *area, int regiontype)
{
if (area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
if (region->regiontype == regiontype) {
ED_region_tag_redraw(region);
}
}
}
}
void ED_area_tag_refresh(ScrArea *area)
{
if (area) {
area->do_refresh = true;
}
}
/* *************************************************************** */
/**
* Returns the search string if the space type and region type support property search.
*/
const char *ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region)
{
/* Only the properties editor has a search string for now. */
if (area->spacetype == SPACE_PROPERTIES) {
SpaceProperties *sbuts = area->spacedata.first;
if (region->regiontype == RGN_TYPE_WINDOW) {
return ED_buttons_search_string_get(sbuts);
}
}
return NULL;
}
/**
* Set the temporary update flag for property search.
*/
void ED_region_search_filter_update(const ScrArea *area, ARegion *region)
{
region->flag |= RGN_FLAG_SEARCH_FILTER_UPDATE;
const char *search_filter = ED_area_region_search_filter_get(area, region);
SET_FLAG_FROM_TEST(region->flag,
region->regiontype == RGN_TYPE_WINDOW && search_filter[0] != '\0',
RGN_FLAG_SEARCH_FILTER_ACTIVE);
}
/* *************************************************************** */
/* use NULL to disable it */
void ED_area_status_text(ScrArea *area, const char *str)
{
/* happens when running transform operators in background mode */
if (area == NULL) {
return;
}
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
if (region->regiontype == RGN_TYPE_HEADER) {
if (str) {
if (region->headerstr == NULL) {
region->headerstr = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint");
}
BLI_strncpy(region->headerstr, str, UI_MAX_DRAW_STR);
BLI_str_rstrip(region->headerstr);
}
else if (region->headerstr) {
MEM_freeN(region->headerstr);
region->headerstr = NULL;
}
ED_region_tag_redraw(region);
}
}
}
void ED_workspace_status_text(bContext *C, const char *str)
{
wmWindow *win = CTX_wm_window(C);
WorkSpace *workspace = CTX_wm_workspace(C);
/* Can be NULL when running operators in background mode. */
if (workspace == NULL) {
return;
}
if (str) {
if (workspace->status_text == NULL) {
workspace->status_text = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint");
}
BLI_strncpy(workspace->status_text, str, UI_MAX_DRAW_STR);
}
else if (workspace->status_text) {
MEM_freeN(workspace->status_text);
workspace->status_text = NULL;
}
/* Redraw status bar. */
LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) {
if (area->spacetype == SPACE_STATUSBAR) {
ED_area_tag_redraw(area);
break;
}
}
}
/* ************************************************************ */
static void area_azone_init(wmWindow *win, const bScreen *screen, ScrArea *area)
{
/* reinitialize entirely, regions and fullscreen add azones too */
BLI_freelistN(&area->actionzones);
if (screen->state != SCREENNORMAL) {
return;
}
if (U.app_flag & USER_APP_LOCK_UI_LAYOUT) {
return;
}
if (ED_area_is_global(area)) {
return;
}
if (screen->temp) {
return;
}
const float coords[4][4] = {
/* Bottom-left. */
{area->totrct.xmin - U.pixelsize,
area->totrct.ymin - U.pixelsize,
area->totrct.xmin + AZONESPOTW,
area->totrct.ymin + AZONESPOTH},
/* Bottom-right. */
{area->totrct.xmax - AZONESPOTW,
area->totrct.ymin - U.pixelsize,
area->totrct.xmax + U.pixelsize,
area->totrct.ymin + AZONESPOTH},
/* Top-left. */
{area->totrct.xmin - U.pixelsize,
area->totrct.ymax - AZONESPOTH,
area->totrct.xmin + AZONESPOTW,
area->totrct.ymax + U.pixelsize},
/* Top-right. */
{area->totrct.xmax - AZONESPOTW,
area->totrct.ymax - AZONESPOTH,
area->totrct.xmax + U.pixelsize,
area->totrct.ymax + U.pixelsize},
};
for (int i = 0; i < 4; i++) {
/* can't click on bottom corners on OS X, already used for resizing */
#ifdef __APPLE__
if (!WM_window_is_fullscreen(win) &&
((coords[i][0] == 0 && coords[i][1] == 0) ||
(coords[i][0] == WM_window_pixels_x(win) && coords[i][1] == 0))) {
continue;
}
#else
(void)win;
#endif
/* set area action zones */
AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
BLI_addtail(&(area->actionzones), az);
az->type = AZONE_AREA;
az->x1 = coords[i][0];
az->y1 = coords[i][1];
az->x2 = coords[i][2];
az->y2 = coords[i][3];
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
}
static void fullscreen_azone_init(ScrArea *area, ARegion *region)
{
if (ED_area_is_global(area) || (region->regiontype != RGN_TYPE_WINDOW)) {
return;
}
AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone");
BLI_addtail(&(area->actionzones), az);
az->type = AZONE_FULLSCREEN;
az->region = region;
az->alpha = 0.0f;
if (U.uiflag2 & USER_REGION_OVERLAP) {
const rcti *rect_visible = ED_region_visible_rect(region);
az->x2 = region->winrct.xmin + rect_visible->xmax;
az->y2 = region->winrct.ymin + rect_visible->ymax;
}
else {
az->x2 = region->winrct.xmax;
az->y2 = region->winrct.ymax;
}
az->x1 = az->x2 - AZONEFADEOUT;
az->y1 = az->y2 - AZONEFADEOUT;
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
#define AZONEPAD_EDGE (0.1f * U.widget_unit)
#define AZONEPAD_ICON (0.45f * U.widget_unit)
static void region_azone_edge(AZone *az, ARegion *region)
{
switch (az->edge) {
case AE_TOP_TO_BOTTOMRIGHT:
az->x1 = region->winrct.xmin;
az->y1 = region->winrct.ymax - AZONEPAD_EDGE;
az->x2 = region->winrct.xmax;
az->y2 = region->winrct.ymax + AZONEPAD_EDGE;
break;
case AE_BOTTOM_TO_TOPLEFT:
az->x1 = region->winrct.xmin;
az->y1 = region->winrct.ymin + AZONEPAD_EDGE;
az->x2 = region->winrct.xmax;
az->y2 = region->winrct.ymin - AZONEPAD_EDGE;
break;
case AE_LEFT_TO_TOPRIGHT:
az->x1 = region->winrct.xmin - AZONEPAD_EDGE;
az->y1 = region->winrct.ymin;
az->x2 = region->winrct.xmin + AZONEPAD_EDGE;
az->y2 = region->winrct.ymax;
break;
case AE_RIGHT_TO_TOPLEFT:
az->x1 = region->winrct.xmax + AZONEPAD_EDGE;
az->y1 = region->winrct.ymin;
az->x2 = region->winrct.xmax - AZONEPAD_EDGE;
az->y2 = region->winrct.ymax;
break;
}
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
/* region already made zero sized, in shape of edge */