Blender V5.3
screen_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10#include <cstring>
11#include <fmt/format.h>
12#include <optional>
13
14#include "DNA_space_types.h"
15#include "MEM_guardedalloc.h"
16
17#include "BLI_build_config.hh"
18#include "BLI_listbase.hh"
20#include "BLI_math_vector_c.hh"
21#include "BLI_time.hh"
22#include "BLI_utildefines.hh"
23
24#include "BLT_translation.hh"
25
26#include "DNA_anim_types.h"
27#include "DNA_armature_types.h"
28#include "DNA_camera_types.h"
29#include "DNA_curve_types.h"
31#include "DNA_lattice_types.h"
32#include "DNA_mesh_types.h"
33#include "DNA_meta_types.h"
34#include "DNA_node_types.h"
35#include "DNA_object_types.h"
36#include "DNA_scene_types.h"
37#include "DNA_userdef_types.h"
38#include "DNA_workspace_types.h"
39
40#include "BKE_callbacks.hh"
41#include "BKE_context.hh"
42#include "BKE_editmesh.hh"
43#include "BKE_fcurve.hh"
44#include "BKE_global.hh"
45#include "BKE_icons.hh"
46#include "BKE_layer.hh"
47#include "BKE_lib_id.hh"
48#include "BKE_library.hh"
49#include "BKE_main.hh"
50#include "BKE_mask.hh"
51#include "BKE_object.hh"
52#include "BKE_report.hh"
53#include "BKE_scene.hh"
54#include "BKE_scene_context.hh"
55#include "BKE_screen.hh"
56#include "BKE_sound.hh"
57#include "BKE_workspace.hh"
58
59#include "WM_api.hh"
60#include "WM_types.hh"
61
62#include "DEG_depsgraph.hh"
64
65#include "ED_anim_api.hh"
66#include "ED_armature.hh"
67#include "ED_buttons.hh"
68#include "ED_fileselect.hh"
69#include "ED_image.hh"
71#include "ED_markers.hh"
72#include "ED_mesh.hh"
73#include "ED_object.hh"
74#include "ED_scene.hh"
75#include "ED_screen.hh"
76#include "ED_screen_types.hh"
77#include "ED_sequencer.hh"
78#include "ED_space_graph.hh"
79#include "ED_undo.hh"
80#include "ED_view3d.hh"
81
82#include "RNA_access.hh"
83#include "RNA_define.hh"
84#include "RNA_enum_types.hh"
85#include "RNA_prototypes.hh"
86
87#include "UI_interface.hh"
89#include "UI_resources.hh"
90#include "UI_view2d.hh"
91
92#include "GPU_capabilities.hh"
93
94#include "wm_window.hh"
95
96#include "screen_intern.hh" /* own module include */
97
98namespace blender {
99
100#define KM_MODAL_CANCEL 1
101#define KM_MODAL_APPLY 2
102#define KM_MODAL_SNAP_ON 3
103#define KM_MODAL_SNAP_OFF 4
104
105static wmOperatorStatus start_playback(bContext *C, int sync, int mode);
106static void stop_playback(bContext *C);
107
108/* -------------------------------------------------------------------- */
111
113{
114 if (CTX_wm_window(C) == nullptr) {
115 return false;
116 }
117 if (CTX_wm_screen(C) == nullptr) {
118 return false;
119 }
120 if (CTX_wm_region(C) == nullptr) {
121 return false;
122 }
123 return true;
124}
125
127{
128 if (CTX_wm_window(C) == nullptr) {
129 return false;
130 }
131 if (CTX_wm_screen(C) == nullptr) {
132 return false;
133 }
134 if (CTX_wm_area(C) == nullptr) {
135 return false;
136 }
137 return true;
138}
139
141{
142 if (CTX_wm_window(C) == nullptr) {
143 return false;
144 }
145 if (CTX_wm_screen(C) == nullptr) {
146 return false;
147 }
148 return true;
149}
150
152{
153 if (CTX_wm_window(C) == nullptr) {
154 return false;
155 }
156 if (CTX_wm_screen(C) == nullptr) {
157 return false;
158 }
159 /* In case of sequencer, scene may not be set. */
160 if (CTX_wm_space_seq(C) != nullptr) {
161 return CTX_data_sequencer_scene(C) != nullptr;
162 }
163 return true;
164}
165
167{
168 if (G.background) {
169 return false;
170 }
172}
173
174/* XXX added this to prevent anim state to change during renders */
176{
177 if (G.is_rendering) {
178 return false;
179 }
180 if (CTX_wm_window(C) == nullptr) {
181 return false;
182 }
183 if (CTX_wm_screen(C) == nullptr) {
184 return false;
185 }
186 return true;
187}
188
190{
191 if (CTX_wm_window(C) == nullptr) {
192 return false;
193 }
194 bScreen *screen = CTX_wm_screen(C);
195 if (screen == nullptr) {
196 return false;
197 }
198 if (screen->active_region != nullptr) {
199 return false;
200 }
201 return true;
202}
203
205{
206 Scene *scene = CTX_data_scene(C);
207 if (scene) {
208 return true;
209 }
210 return false;
211}
212
214{
216 if (scene == nullptr || !BKE_id_is_editable(CTX_data_main(C), &scene->id)) {
217 return false;
218 }
219 return true;
220}
221
223{
224 Scene *scene = CTX_data_scene(C);
225 if (scene == nullptr || !BKE_id_is_editable(CTX_data_main(C), &scene->id)) {
226 return false;
227 }
228 return true;
229}
230
232{
234 if (scene == nullptr) {
235 CTX_wm_operator_poll_msg_set(C, "Context missing sequencer scene");
236 return false;
237 }
238
239 if (!BKE_id_is_editable(CTX_data_main(C), &scene->id)) {
240 CTX_wm_operator_poll_msg_set(C, "Sequencer scene not editable");
241 return false;
242 }
243 return true;
244}
245
247{
248 Scene *scene = CTX_data_scene(C);
250
251 if (scene == nullptr || !ID_IS_EDITABLE(scene)) {
252 return false;
253 }
254 if (CTX_data_edit_object(C)) {
255 return false;
256 }
257
258 /* add a check for ob->mode too? */
259 if (obact && (obact->mode != OB_MODE_OBJECT)) {
260 return false;
261 }
262
263 return true;
264}
265
267{
269 CTX_wm_operator_poll_msg_set(C, "Only supported in object mode");
270 return false;
271 }
272
273 return true;
274}
275
277{
279 return false;
280 }
282 return false;
283 }
284 return true;
285}
286
287static bool ed_spacetype_test(bContext *C, int type)
288{
290 SpaceLink *sl = static_cast<SpaceLink *>(CTX_wm_space_data(C));
291 return sl && (sl->spacetype == type);
292 }
293 return false;
294}
295
300
302{
303 if (CTX_wm_region_view3d(C)) {
304 return true;
305 }
306
307 CTX_wm_operator_poll_msg_set(C, "Expected a view3d region");
308 return false;
309}
310
312{
313 ARegion *region = CTX_wm_region(C);
314 if (region == nullptr) {
315 return false;
316 }
317 wmGizmoMap *gzmap = region->runtime->gizmo_map;
318 if (gzmap == nullptr) {
319 return false;
320 }
321 return true;
322}
323
325{
327 SpaceLink *sl = static_cast<SpaceLink *>(CTX_wm_space_data(C));
329 return true;
330 }
331 }
332
333 CTX_wm_operator_poll_msg_set(C, "Expected a timeline/animation area to be active");
334 return false;
335}
336
338{
340 return false;
341 }
342 const ARegion *region = CTX_wm_region(C);
343 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
344 CTX_wm_operator_poll_msg_set(C, "Expected a timeline/animation region");
345 return false;
346 }
347 return true;
348}
349
354
356{
358 CTX_wm_operator_poll_msg_set(C, "Expected an active Outliner");
359 return false;
360 }
361 const ARegion *region = CTX_wm_region(C);
362 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
363 CTX_wm_operator_poll_msg_set(C, "Expected an Outliner region");
364 return false;
365 }
366 return true;
367}
368
370{
373 Object *obedit = CTX_data_edit_object(C);
374 if (ob && ob == obedit) {
375 return false;
376 }
377 return true;
378 }
379 return false;
380}
381
386
388{
390 CTX_wm_operator_poll_msg_set(C, "Expected an active File Browser");
391 return false;
392 }
393 const ARegion *region = CTX_wm_region(C);
394 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
395 CTX_wm_operator_poll_msg_set(C, "Expected a File Browser region");
396 return false;
397 }
398 return true;
399}
400
408
416
421
426
428{
430 CTX_wm_operator_poll_msg_set(C, "Expected an active Dope Sheet");
431 return false;
432 }
433 const ARegion *region = CTX_wm_region(C);
434 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
435 CTX_wm_operator_poll_msg_set(C, "Expected a Dope Sheet region");
436 return false;
437 }
438 return true;
439}
440
445
450
452{
453 SpaceNode *snode = CTX_wm_space_node(C);
454
455 if (snode && snode->edittree) {
456 return true;
457 }
458
459 return false;
460}
461
463{
464 SpaceNode *snode = CTX_wm_space_node(C);
465
466 if (snode && snode->edittree && BKE_id_is_editable(CTX_data_main(C), &snode->edittree->id)) {
467 return true;
468 }
469
470 return false;
471}
472
477
479{
481 CTX_wm_operator_poll_msg_set(C, "Expected an active Graph Editor");
482 return false;
483 }
484 const ARegion *region = CTX_wm_region(C);
485 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
486 CTX_wm_operator_poll_msg_set(C, "Expected a Graph Editor region");
487 return false;
488 }
489 return true;
490}
491
496
501
506
511
513{
515 CTX_wm_operator_poll_msg_set(C, "Expected an active Nonlinear Animation editor");
516 return false;
517 }
518 const ARegion *region = CTX_wm_region(C);
519 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
520 CTX_wm_operator_poll_msg_set(C, "Expected a Nonlinear Animation region");
521 return false;
522 }
523 return true;
524}
525
530
532{
534 CTX_wm_operator_poll_msg_set(C, "Expected an active Info editor");
535 return false;
536 }
537 const ARegion *region = CTX_wm_region(C);
538 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
539 CTX_wm_operator_poll_msg_set(C, "Expected an Info region");
540 return false;
541 }
542 return true;
543}
544
549
550static bool ed_object_hidden(const Object *ob)
551{
552 /* if hidden but in edit mode, we still display, can happen with animation */
553 return ((ob->visibility_flag & OB_HIDE_VIEWPORT) && !(ob->mode & OB_MODE_EDIT));
554}
555
557{
559 return (ob != nullptr);
560}
561
563{
565 return ((ob != nullptr) && !ed_object_hidden(ob));
566}
567
569{
571 return ((ob != nullptr) && !ed_object_hidden(ob) && (ob->mode == OB_MODE_OBJECT));
572}
573
575{
576 if (ob == nullptr) {
577 CTX_wm_operator_poll_msg_set(C, "Context missing active object");
578 return false;
579 }
580
581 if (!BKE_id_is_editable(CTX_data_main(C), id_cast<ID *>(const_cast<Object *>(ob)))) {
582 CTX_wm_operator_poll_msg_set(C, "Cannot edit library linked or non-editable override object");
583 return false;
584 }
585
586 if (ed_object_hidden(ob)) {
587 CTX_wm_operator_poll_msg_set(C, "Cannot edit hidden object");
588 return false;
589 }
590
591 return true;
592}
593
599
601{
602 Main &bmain = *CTX_data_main(C);
603 Scene *scene = CTX_data_scene(C);
604 ViewLayer *view_layer = CTX_data_view_layer(C);
605 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
606 Object *obact = BKE_view_layer_active_object_get(view_layer);
607 return (obact != nullptr);
608}
609
611{
612 Main &bmain = *CTX_data_main(C);
613 Scene *scene = CTX_data_scene(C);
614 ViewLayer *view_layer = CTX_data_view_layer(C);
615 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
616 Object *obact = BKE_view_layer_active_object_get(view_layer);
617 return ((obact != nullptr) && !ed_object_hidden(obact));
618}
619
624
630
632{
634 return ((ob != nullptr) && ID_IS_EDITABLE(ob) && !ed_object_hidden(ob) &&
635 (ob->type == OB_MESH) && ID_IS_EDITABLE(ob->data) && !ID_IS_OVERRIDE_LIBRARY(ob->data));
636}
637
639{
640 Main &bmain = *CTX_data_main(C);
641 Scene *scene = CTX_data_scene(C);
642 ViewLayer *view_layer = CTX_data_view_layer(C);
643 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
644 const Object *ob = BKE_view_layer_active_object_get(view_layer);
645 return ((ob != nullptr) && ID_IS_EDITABLE(ob) && !ed_object_hidden(ob) && (ob->type == obtype) &&
647}
648
653
655{
657 return ((ob != nullptr) && ID_IS_EDITABLE(ob) && !ed_object_hidden(ob) &&
658 (ob->type == OB_FONT) && ID_IS_EDITABLE(ob->data) && !ID_IS_OVERRIDE_LIBRARY(ob->data));
659}
660
666
668{
669 Object *obedit = CTX_data_edit_object(C);
670 if (obedit && obedit->type == OB_MESH) {
671 return nullptr != BKE_editmesh_from_object(obedit);
672 }
673 return false;
674}
675
680
682{
684 return true;
685 }
686
687 CTX_wm_operator_poll_msg_set(C, "Expected a view3d region & editmesh");
688 return false;
689}
690
692{
693 Object *obedit = CTX_data_edit_object(C);
694 if (obedit && obedit->type == OB_ARMATURE) {
695 return nullptr != (id_cast<bArmature *>(obedit->data))->edbo;
696 }
697 return false;
698}
699
708{
709 if (obact != nullptr && !(obact->mode & OB_MODE_EDIT)) {
710 if (obact == BKE_object_pose_armature_get(obact)) {
711 return true;
712 }
713 }
714
715 CTX_wm_operator_poll_msg_set(C, "No object, or not exclusively in pose mode");
716 return false;
717}
718
725
727{
729
731 return false;
732 }
733
734 if (ID_IS_OVERRIDE_LIBRARY(obact)) {
735 CTX_wm_operator_poll_msg_set(C, "Object is a local library override");
736 return false;
737 }
738
739 return true;
740}
741
743{
745
746 if (obpose && !(obpose->mode & OB_MODE_EDIT)) {
747 if (BKE_object_pose_context_check(obpose)) {
748 return true;
749 }
750 }
751
752 return false;
753}
754
756{
758
759 if (obact && !(obact->mode & OB_MODE_EDIT)) {
760 Object *obpose = BKE_object_pose_armature_get(obact);
761 if (obpose != nullptr) {
762 if ((obact == obpose) || (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)) {
763 return true;
764 }
765 }
766 }
767
768 return false;
769}
770
772{
773 if (ED_operator_posemode(C)) {
774 Main *bmain = CTX_data_main(C);
776 bArmature *arm = id_cast<bArmature *>(ob->data);
777 return (BKE_id_is_editable(bmain, &ob->id) && BKE_id_is_editable(bmain, &arm->id));
778 }
779 return false;
780}
781
783{
785 Object *obedit = CTX_data_edit_object(C);
786 return ED_space_image_show_uvedit(sima, obedit);
787}
788
790{
792 Object *obedit = CTX_data_edit_object(C);
793 return sima && ED_space_image_show_uvedit(sima, obedit);
794}
795
797{
798 Object *obedit = CTX_data_edit_object(C);
799 if (!obedit) {
800 return false;
801 }
802 if (obedit->type != OB_MESH) {
803 return false;
804 }
806 if (!em) {
807 return false;
808 }
809 const BMesh *bm = BKE_editmesh_bmesh_get(obedit);
810 if (bm->totface == 0) {
811 return false;
812 }
813 return true;
814}
815
817{
818 Object *obedit = CTX_data_edit_object(C);
819 if (obedit && ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
820 return nullptr != (id_cast<Curve *>(obedit->data))->editnurb;
821 }
822 return false;
823}
824
826{
828 return true;
829 }
830
831 CTX_wm_operator_poll_msg_set(C, "Expected a view3d region & editcurve");
832 return false;
833}
834
836{
837 Object *obedit = CTX_data_edit_object(C);
838 if (obedit && obedit->type == OB_CURVES_LEGACY) {
839 return nullptr != (id_cast<Curve *>(obedit->data))->editnurb;
840 }
841 return false;
842}
843
845{
846 Object *obedit = CTX_data_edit_object(C);
847 if (obedit && obedit->type == OB_CURVES_LEGACY) {
848 Curve *cu = id_cast<Curve *>(obedit->data);
849
850 return (cu->flag & CU_3D) && (nullptr != cu->editnurb);
851 }
852 return false;
853}
854
856{
857 Object *obedit = CTX_data_edit_object(C);
858 if (obedit && obedit->type == OB_SURF) {
859 return nullptr != (id_cast<Curve *>(obedit->data))->editnurb;
860 }
861 return false;
862}
863
865{
866 Object *obedit = CTX_data_edit_object(C);
867 if (obedit && obedit->type == OB_FONT) {
868 if ((id_cast<Curve *>(obedit->data))->editfont) {
869 return true;
870 }
871 }
872 CTX_wm_operator_poll_msg_set(C, "Expected an active edit-font object");
873 return false;
874}
875
877{
878 Object *obedit = CTX_data_edit_object(C);
879 if (obedit && obedit->type == OB_LATTICE) {
880 return nullptr != (id_cast<Lattice *>(obedit->data))->editlatt;
881 }
882 return false;
883}
884
886{
887 Object *obedit = CTX_data_edit_object(C);
888 if (obedit && obedit->type == OB_MBALL) {
889 return nullptr != (id_cast<MetaBall *>(obedit->data))->editelems;
890 }
891 return false;
892}
893
895{
896 Camera *cam = static_cast<Camera *>(CTX_data_pointer_get_type(C, "camera", RNA_Camera).data);
897 return (cam != nullptr && ID_IS_EDITABLE(cam));
898}
899
901
902/* -------------------------------------------------------------------- */
905
907{
909 /* no full window splitting allowed */
911 return false;
912 }
913 return true;
914 }
915 return false;
916}
917
923{
924 G.moving |= G_TRANSFORM_WM;
925}
926
929{
930 G.moving &= ~G_TRANSFORM_WM;
931
932 /* Full refresh after `G.moving` is cleared otherwise tool gizmos
933 * won't be refreshed with the modified flag, see: #143629. */
935}
936
938
939/* -------------------------------------------------------------------- */
942
943/* operator state vars used:
944 * none
945 *
946 * functions:
947 *
948 * apply() set action-zone event
949 *
950 * exit() free customdata
951 *
952 * callbacks:
953 *
954 * exec() never used
955 *
956 * invoke() check if in zone
957 * add customdata, put mouseco and area in it
958 * add modal handler
959 *
960 * modal() accept modal events while doing it
961 * call apply() with gesture info, active window, nonactive window
962 * call exit() and remove handler when LMB confirm
963 */
964
972
973/* quick poll to save operators to be created and handled */
975{
976 wmWindow *win = CTX_wm_window(C);
977 if (win && win->runtime->eventstate) {
979 if (screen) {
980 const int *xy = &win->runtime->eventstate->xy[0];
981
982 for (ScrArea &area : screen->areabase) {
983 for (AZone &az : area.actionzones) {
984 if (BLI_rcti_isect_pt_v(&az.rect, xy)) {
985 return true;
986 }
987 }
988 }
989 }
990 }
991 return false;
992}
993
994/* the debug drawing of the click_rect is in area_draw_azone_fullscreen, keep both in sync */
996 rcti *rect, const short /*x1*/, const short /*y1*/, const short x2, const short y2)
997{
998 BLI_rcti_init(rect, x2 - U.widget_unit, x2, y2 - U.widget_unit, y2);
999}
1000
1001static bool azone_clipped_rect_calc(const AZone *az, rcti *r_rect_clip)
1002{
1003 const ARegion *region = az->region;
1004 *r_rect_clip = az->rect;
1005 if (az->type == AZONE_REGION) {
1006 if (region->overlap && (region->v2d.keeptot != V2D_KEEPTOT_STRICT) &&
1007 /* Only when this isn't hidden (where it's displayed as an button that expands). */
1008 region->runtime->visible)
1009 {
1010 /* A floating region to be resized, clip by the visible region. */
1011 switch (az->edge) {
1013 case AE_BOTTOM_TO_TOPLEFT: {
1014 r_rect_clip->xmin = max_ii(
1015 r_rect_clip->xmin,
1016 (region->winrct.xmin +
1017 ui::view2d_view_to_region_x(&region->v2d, region->v2d.tot.xmin)) -
1019 r_rect_clip->xmax = min_ii(
1020 r_rect_clip->xmax,
1021 (region->winrct.xmin +
1022 ui::view2d_view_to_region_x(&region->v2d, region->v2d.tot.xmax)) +
1024 return true;
1025 }
1027 case AE_RIGHT_TO_TOPLEFT: {
1028 r_rect_clip->ymin = max_ii(
1029 r_rect_clip->ymin,
1030 (region->winrct.ymin +
1031 ui::view2d_view_to_region_y(&region->v2d, region->v2d.tot.ymin)) -
1033 r_rect_clip->ymax = min_ii(
1034 r_rect_clip->ymax,
1035 (region->winrct.ymin +
1036 ui::view2d_view_to_region_y(&region->v2d, region->v2d.tot.ymax)) +
1038 return true;
1039 }
1040 }
1041 }
1042 }
1043 return false;
1044}
1045
1046/* Return the azone's calculated rect. */
1047static void area_actionzone_get_rect(AZone *az, rcti *r_rect)
1048{
1049 if (az->type == AZONE_REGION_SCROLL) {
1050 const bool is_horizontal = az->direction == AZ_SCROLL_HOR;
1051 const bool is_vertical = az->direction == AZ_SCROLL_VERT;
1052 const bool is_right = is_vertical && bool(az->region->v2d.scroll & V2D_SCROLL_RIGHT);
1053 const bool is_left = is_vertical && bool(az->region->v2d.scroll & V2D_SCROLL_LEFT);
1054 const bool is_top = is_horizontal && bool(az->region->v2d.scroll & V2D_SCROLL_TOP);
1055 const bool is_bottom = is_horizontal && bool(az->region->v2d.scroll & V2D_SCROLL_BOTTOM);
1056 /* For scroll azones use the area around the region's scroll-bar location. */
1057 rcti scroller_vert = is_horizontal ? az->region->v2d.hor : az->region->v2d.vert;
1058 BLI_rcti_translate(&scroller_vert, az->region->winrct.xmin, az->region->winrct.ymin);
1059
1060 /* Pull the zone in from edge and match the visible hit zone. */
1061 const int edge_padding = int(-3.0f * UI_SCALE_FAC);
1062 r_rect->xmin = scroller_vert.xmin - (is_right ? V2D_SCROLL_HIDE_HEIGHT : edge_padding);
1063 r_rect->ymin = scroller_vert.ymin - (is_top ? V2D_SCROLL_HIDE_WIDTH : edge_padding);
1064 r_rect->xmax = scroller_vert.xmax + (is_left ? V2D_SCROLL_HIDE_HEIGHT : edge_padding);
1065 r_rect->ymax = scroller_vert.ymax + (is_bottom ? V2D_SCROLL_HIDE_WIDTH : edge_padding);
1066 }
1067 else {
1068 azone_clipped_rect_calc(az, r_rect);
1069 }
1070}
1071
1072static AZone *area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const bool test_only)
1073{
1074 AZone *az = nullptr;
1075
1076 for (az = area->actionzones.first(); az; az = az->next) {
1077 rcti az_rect;
1078 area_actionzone_get_rect(az, &az_rect);
1079 if (BLI_rcti_isect_pt_v(&az_rect, xy)) {
1080
1081 if (az->type == AZONE_AREA) {
1082 break;
1083 }
1084 if (az->type == AZONE_REGION_QUAD) {
1085 break;
1086 }
1087 if (az->type == AZONE_REGION) {
1088 const ARegion *region = az->region;
1089 const int local_xy[2] = {xy[0] - region->winrct.xmin, xy[1] - region->winrct.ymin};
1090
1091 /* Respect button sections: Clusters of buttons (separated using separator-spacers) are
1092 * drawn with a background, in-between them the region is fully transparent (if "Region
1093 * Overlap" is enabled). Only allow dragging visible edges, so at the button sections. */
1094 if (region->runtime->visible && region->overlap &&
1097 {
1098 az = nullptr;
1099 break;
1100 }
1101
1102 break;
1103 }
1104 if (az->type == AZONE_FULLSCREEN) {
1105 rcti click_rect;
1106 fullscreen_click_rcti_init(&click_rect, az->x1, az->y1, az->x2, az->y2);
1107 const bool click_isect = BLI_rcti_isect_pt_v(&click_rect, xy);
1108
1109 if (test_only) {
1110 if (click_isect) {
1111 break;
1112 }
1113 }
1114 else {
1115 if (click_isect) {
1116 az->alpha = 1.0f;
1117 }
1118 else {
1119 const int mouse_sq = square_i(xy[0] - az->x2) + square_i(xy[1] - az->y2);
1120 const int spot_sq = square_i(UI_AZONESPOTW_RIGHT);
1121 const int fadein_sq = square_i(AZONEFADEIN);
1122 const int fadeout_sq = square_i(AZONEFADEOUT);
1123
1124 if (mouse_sq < spot_sq) {
1125 az->alpha = 1.0f;
1126 }
1127 else if (mouse_sq < fadein_sq) {
1128 az->alpha = 1.0f;
1129 }
1130 else if (mouse_sq < fadeout_sq) {
1131 az->alpha = 1.0f - float(mouse_sq - fadein_sq) / float(fadeout_sq - fadein_sq);
1132 }
1133 else {
1134 az->alpha = 0.0f;
1135 }
1136
1137 /* fade in/out but no click */
1138 az = nullptr;
1139 }
1140
1141 /* XXX force redraw to show/hide the action zone */
1142 ED_area_tag_redraw(area);
1143 break;
1144 }
1145 }
1146 else if (az->type == AZONE_REGION_SCROLL && az->region->runtime->visible) {
1147 /* If the region is not visible we can ignore this scroll-bar zone. */
1148 ARegion *region = az->region;
1149 View2D *v2d = &region->v2d;
1150 int scroll_flag = 0;
1151 const int isect_value = ui::view2d_mouse_in_scrollers_ex(region, v2d, xy, &scroll_flag);
1152
1153 /* Check if we even have scroll bars. */
1154 if (((az->direction == AZ_SCROLL_HOR) && !(scroll_flag & V2D_SCROLL_HORIZONTAL)) ||
1155 ((az->direction == AZ_SCROLL_VERT) && !(scroll_flag & V2D_SCROLL_VERTICAL)))
1156 {
1157 /* No scroll-bars, do nothing. */
1158 }
1159 else if (test_only) {
1160 if (isect_value != 0) {
1161 break;
1162 }
1163 }
1164 else {
1165 bool redraw = false;
1166
1167 if (isect_value == 'h') {
1168 if (az->direction == AZ_SCROLL_HOR) {
1169 az->alpha = 1.0f;
1170 v2d->alpha_hor = 255;
1171 redraw = true;
1172 }
1173 }
1174 else if (isect_value == 'v') {
1175 if (az->direction == AZ_SCROLL_VERT) {
1176 az->alpha = 1.0f;
1177 v2d->alpha_vert = 255;
1178 redraw = true;
1179 }
1180 }
1181 else {
1182 const int local_xy[2] = {xy[0] - region->winrct.xmin, xy[1] - region->winrct.ymin};
1183 float dist_fac = 0.0f, alpha = 0.0f;
1184
1185 if (az->direction == AZ_SCROLL_HOR) {
1186 dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / V2D_SCROLL_HIDE_WIDTH;
1187 CLAMP(dist_fac, 0.0f, 1.0f);
1188 alpha = 1.0f - dist_fac;
1189
1190 v2d->alpha_hor = alpha * 255;
1191 }
1192 else if (az->direction == AZ_SCROLL_VERT) {
1193 dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / V2D_SCROLL_HIDE_HEIGHT;
1194 CLAMP(dist_fac, 0.0f, 1.0f);
1195 alpha = 1.0f - dist_fac;
1196
1197 v2d->alpha_vert = alpha * 255;
1198 }
1199 az->alpha = alpha;
1200 redraw = true;
1201 }
1202
1203 if (redraw) {
1205 }
1206 /* Don't return! */
1207 }
1208 }
1209 }
1210 else if (!test_only && !IS_EQF(az->alpha, 0.0f)) {
1211 if (az->type == AZONE_FULLSCREEN) {
1212 az->alpha = 0.0f;
1215 }
1216 else if (az->type == AZONE_REGION_SCROLL && az->region->runtime->visible) {
1217 /* If the region is not visible we can ignore this scroll-bar zone. */
1218 if (az->direction == AZ_SCROLL_VERT) {
1219 az->alpha = az->region->v2d.alpha_vert = 0;
1222 }
1223 else if (az->direction == AZ_SCROLL_HOR) {
1224 az->alpha = az->region->v2d.alpha_hor = 0;
1227 }
1228 else {
1229 BLI_assert(false);
1230 }
1231 }
1232 }
1233 }
1234
1235 return az;
1236}
1237
1238/* Finds an action-zone by position in entire screen so azones can overlap. */
1239static AZone *screen_actionzone_find_xy(bScreen *screen, const int xy[2])
1240{
1241 for (ScrArea &area : screen->areabase) {
1242 AZone *az = area_actionzone_refresh_xy(&area, xy, true);
1243 if (az != nullptr) {
1244 return az;
1245 }
1246 }
1247 return nullptr;
1248}
1249
1250/* Returns the area that the azone belongs to */
1251static ScrArea *screen_actionzone_area(bScreen *screen, const AZone *az)
1252{
1253 for (ScrArea &area : screen->areabase) {
1254 for (AZone &zone : area.actionzones) {
1255 if (&zone == az) {
1256 return &area;
1257 }
1258 }
1259 }
1260 return nullptr;
1261}
1262
1264{
1265 return area_actionzone_refresh_xy(area, xy, true);
1266}
1267
1268AZone *ED_area_azones_update(ScrArea *area, const int xy[2])
1269{
1270 return area_actionzone_refresh_xy(area, xy, false);
1271}
1272
1274{
1275 sActionzoneData *sad = static_cast<sActionzoneData *>(op->customdata);
1276 if (sad) {
1277 MEM_delete(sad);
1278 }
1279 op->customdata = nullptr;
1280
1282}
1283
1284/* send EVT_ACTIONZONE event */
1285static void actionzone_apply(bContext *C, wmOperator *op, int type)
1286{
1287 wmWindow *win = CTX_wm_window(C);
1288
1289 wmEvent event;
1290 wm_event_init_from_window(win, &event);
1291
1292 if (type == AZONE_AREA) {
1293 event.type = EVT_ACTIONZONE_AREA;
1294 }
1295 else if (type == AZONE_FULLSCREEN) {
1296 event.type = EVT_ACTIONZONE_FULLSCREEN;
1297 }
1298 else if (type == AZONE_REGION_QUAD) {
1299 event.type = EVT_ACTIONZONE_REGION_QUAD;
1300 }
1301 else {
1302 event.type = EVT_ACTIONZONE_REGION;
1303 }
1304
1305 event.val = KM_NOTHING;
1306 event.flag = eWM_EventFlag(0);
1307 event.customdata = op->customdata;
1308 event.customdata_free = true;
1309 op->customdata = nullptr;
1310
1311 WM_event_add(win, &event);
1312}
1313
1315{
1316 bScreen *screen = CTX_wm_screen(C);
1317 AZone *az = screen_actionzone_find_xy(screen, event->xy);
1318
1319 /* Quick escape - Scroll azones only hide/unhide the scroll-bars,
1320 * they have their own handling. */
1321 if (az == nullptr || ELEM(az->type, AZONE_REGION_SCROLL)) {
1322 return OPERATOR_PASS_THROUGH;
1323 }
1324
1325 /* ok we do the action-zone */
1326 sActionzoneData *sad = static_cast<sActionzoneData *>(
1327 op->customdata = MEM_new_zeroed<sActionzoneData>("sActionzoneData"));
1328 sad->sa1 = screen_actionzone_area(screen, az);
1329 sad->az = az;
1330 sad->x = event->xy[0];
1331 sad->y = event->xy[1];
1332 sad->modifier = RNA_int_get(op->ptr, "modifier");
1333
1334 /* Region azones directly react on mouse clicks. */
1336 actionzone_apply(C, op, sad->az->type);
1337 actionzone_exit(op);
1338 return OPERATOR_FINISHED;
1339 }
1340
1341 if (sad->az->type == AZONE_AREA && sad->modifier == 0) {
1342 actionzone_apply(C, op, sad->az->type);
1343 actionzone_exit(op);
1344 return OPERATOR_FINISHED;
1345 }
1346
1347 /* add modal handler */
1351}
1352
1354{
1355 bScreen *screen = CTX_wm_screen(C);
1356 sActionzoneData *sad = static_cast<sActionzoneData *>(op->customdata);
1357
1358 switch (event->type) {
1359 case MOUSEMOVE: {
1360 const int delta_x = (event->xy[0] - sad->x);
1361 const int delta_y = (event->xy[1] - sad->y);
1362
1363 /* Movement in dominant direction. */
1364 const int delta_max = max_ii(abs(delta_x), abs(delta_y));
1365
1366 /* Movement in dominant direction before action taken. */
1367 const int join_threshold = (0.6 * U.widget_unit);
1368 const int split_threshold = (1.2 * U.widget_unit);
1369 const int area_threshold = (0.1 * U.widget_unit);
1370
1371 /* Calculate gesture cardinal direction. */
1372 if (delta_y > abs(delta_x)) {
1374 }
1375 else if (delta_x >= abs(delta_y)) {
1377 }
1378 else if (delta_y < -abs(delta_x)) {
1380 }
1381 else {
1383 }
1384
1385 bool is_gesture;
1386 if (sad->az->type == AZONE_AREA) {
1387 wmWindow *win = CTX_wm_window(C);
1388
1389 rcti screen_rect;
1390 WM_window_screen_rect_calc(win, &screen_rect);
1391
1392 /* Have we dragged off the zone and are not on an edge? */
1393 if ((ED_area_actionzone_find_xy(sad->sa1, event->xy) != sad->az) &&
1395 AREAMAP_FROM_SCREEN(screen), &screen_rect, event->xy[0], event->xy[1]) ==
1396 nullptr))
1397 {
1398
1399 /* What area are we now in? */
1400 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
1401
1402 if (sad->modifier == 1) {
1403 /* Duplicate area into new window. */
1405 is_gesture = (delta_max > area_threshold);
1406 }
1407 else if (sad->modifier == 2) {
1408 /* Swap areas. */
1410 is_gesture = true;
1411 }
1412 else if (area == sad->sa1) {
1413 /* Same area, so possible split. */
1414 WM_cursor_set(win,
1417 is_gesture = (delta_max > split_threshold);
1418 }
1419 else if (!area || area->global) {
1420 /* No area or Top bar or Status bar. */
1422 is_gesture = false;
1423 }
1424 else {
1425 /* Different area, so possible join. */
1426 if (sad->gesture_dir == SCREEN_DIR_N) {
1428 }
1429 else if (sad->gesture_dir == SCREEN_DIR_S) {
1431 }
1432 else if (sad->gesture_dir == SCREEN_DIR_E) {
1434 }
1435 else {
1438 }
1439 is_gesture = (delta_max > join_threshold);
1440 }
1441 }
1442 else {
1443#if defined(__APPLE__)
1444 const int cursor = WM_CURSOR_HAND_CLOSED;
1445#else
1446 const int cursor = WM_CURSOR_MOVE;
1447#endif
1448 WM_cursor_set(win, cursor);
1449 is_gesture = false;
1450 }
1451 }
1452 else {
1453 is_gesture = (delta_max > area_threshold);
1454 }
1455
1456 /* gesture is large enough? */
1457 if (is_gesture) {
1458 /* second area, for join when (sa1 != sa2) */
1459 sad->sa2 = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
1460 /* apply sends event */
1461 actionzone_apply(C, op, sad->az->type);
1462 actionzone_exit(op);
1463
1464 return OPERATOR_FINISHED;
1465 }
1466 break;
1467 }
1468 case EVT_ESCKEY:
1469 actionzone_exit(op);
1470 return OPERATOR_CANCELLED;
1471 case LEFTMOUSE:
1472 actionzone_exit(op);
1473 return OPERATOR_CANCELLED;
1474 default: {
1475 break;
1476 }
1477 }
1478
1480}
1481
1482static void actionzone_cancel(bContext * /*C*/, wmOperator *op)
1483{
1484 actionzone_exit(op);
1485}
1486
1488{
1489 /* identifiers */
1490 ot->name = "Handle Area Action Zones";
1491 ot->description = "Handle area action zones for mouse actions/gestures";
1492 ot->idname = "SCREEN_OT_actionzone";
1493
1495 ot->modal = actionzone_modal;
1498
1499 /* flags */
1501
1502 RNA_def_int(ot->srna, "modifier", 0, 0, 2, "Modifier", "Modifier state", 0, 2);
1503}
1504
1506
1507/* -------------------------------------------------------------------- */
1510
1512 const int cursor[2],
1513 ScrArea **r_sa1,
1514 ScrArea **r_sa2)
1515{
1516 wmWindow *win = CTX_wm_window(C);
1517 bScreen *screen = CTX_wm_screen(C);
1518 rcti window_rect;
1519 WM_window_rect_calc(win, &window_rect);
1521 AREAMAP_FROM_SCREEN(screen), &window_rect, cursor[0], cursor[1]);
1522 *r_sa1 = nullptr;
1523 *r_sa2 = nullptr;
1524 if (actedge == nullptr) {
1525 return nullptr;
1526 }
1527 int borderwidth = (4 * UI_SCALE_FAC);
1528 ScrArea *sa1, *sa2;
1529 if (screen_geom_edge_is_horizontal(actedge)) {
1531 screen, SPACE_TYPE_ANY, int2{cursor[0], cursor[1] + borderwidth});
1533 screen, SPACE_TYPE_ANY, int2{cursor[0], cursor[1] - borderwidth});
1534 }
1535 else {
1537 screen, SPACE_TYPE_ANY, int2{cursor[0] + borderwidth, cursor[1]});
1539 screen, SPACE_TYPE_ANY, int2{cursor[0] - borderwidth, cursor[1]});
1540 }
1541 bool isGlobal = ((sa1 && ED_area_is_global(sa1)) || (sa2 && ED_area_is_global(sa2)));
1542 if (!isGlobal) {
1543 *r_sa1 = sa1;
1544 *r_sa2 = sa2;
1545 }
1546 return actedge;
1547}
1548
1550
1551/* -------------------------------------------------------------------- */
1554
1555/* operator state vars used:
1556 * sa1 start area
1557 * sa2 area to swap with
1558 *
1559 * functions:
1560 *
1561 * init() set custom data for operator, based on action-zone event custom data
1562 *
1563 * cancel() cancel the operator
1564 *
1565 * exit() cleanup, send notifier
1566 *
1567 * callbacks:
1568 *
1569 * invoke() gets called on Shift-LMB drag in action-zone
1570 * exec() execute without any user interaction, based on properties
1571 * call init(), add handler
1572 *
1573 * modal() accept modal events while doing it
1574 */
1575
1578};
1579
1580static bool area_swap_init(wmOperator *op, const wmEvent *event)
1581{
1582 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
1583
1584 if (sad == nullptr || sad->sa1 == nullptr) {
1585 return false;
1586 }
1587
1588 sAreaSwapData *sd = MEM_new_zeroed<sAreaSwapData>("sAreaSwapData");
1589 sd->sa1 = sad->sa1;
1590 sd->sa2 = sad->sa2;
1591 op->customdata = sd;
1592
1593 return true;
1594}
1595
1597{
1598 sAreaSwapData *sd = static_cast<sAreaSwapData *>(op->customdata);
1599 MEM_delete(sd);
1600 op->customdata = nullptr;
1601
1603 ED_workspace_status_text(C, nullptr);
1604}
1605
1607{
1608 area_swap_exit(C, op);
1609}
1610
1612{
1613 if (!area_swap_init(op, event)) {
1614 return OPERATOR_PASS_THROUGH;
1615 }
1616
1617 /* add modal handler */
1620
1622}
1623
1625{
1626 sActionzoneData *sad = static_cast<sActionzoneData *>(op->customdata);
1627
1628 switch (event->type) {
1629 case MOUSEMOVE: {
1630 /* Second area to swap with. */
1633 WorkspaceStatus status(C);
1634 status.item(IFACE_("Select Area"), ICON_MOUSE_LMB);
1635 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
1636 break;
1637 }
1638 case LEFTMOUSE: /* release LMB */
1639 if (event->val == KM_RELEASE) {
1640 if (!sad->sa2 || sad->sa1 == sad->sa2) {
1641 area_swap_cancel(C, op);
1642 return OPERATOR_CANCELLED;
1643 }
1644
1645 ED_area_tag_redraw(sad->sa1);
1646 ED_area_tag_redraw(sad->sa2);
1647
1648 ED_area_swapspace(C, sad->sa1, sad->sa2);
1649
1650 area_swap_exit(C, op);
1651
1653
1654 return OPERATOR_FINISHED;
1655 }
1656 break;
1657
1658 case EVT_ESCKEY:
1659 area_swap_cancel(C, op);
1660 return OPERATOR_CANCELLED;
1661 default: {
1662 break;
1663 }
1664 }
1666}
1667
1669{
1670 ScrArea *sa1, *sa2;
1671 int cursor[2];
1672 RNA_int_get_array(op->ptr, "cursor", cursor);
1673 screen_area_edge_from_cursor(C, cursor, &sa1, &sa2);
1674 if (sa1 == nullptr || sa2 == nullptr) {
1675 return OPERATOR_CANCELLED;
1676 }
1677 ED_area_swapspace(C, sa1, sa2);
1678 return OPERATOR_FINISHED;
1679}
1680
1682{
1683 ot->name = "Swap Areas";
1684 ot->description = "Swap selected areas screen positions";
1685 ot->idname = "SCREEN_OT_area_swap";
1686
1688 ot->modal = area_swap_modal;
1689 ot->exec = area_swap_exec;
1692
1693 ot->flag = OPTYPE_BLOCKING;
1694
1695 /* rna */
1697 ot->srna, "cursor", 2, nullptr, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX);
1698}
1699
1701
1702/* -------------------------------------------------------------------- */
1707
1709static void area_dupli_fn(bScreen * /*screen*/, ScrArea *area, void *user_data)
1710{
1711 ScrArea *area_src = static_cast<ScrArea *>(user_data);
1712 ED_area_data_copy(area, area_src, true);
1713 ED_area_tag_redraw(area);
1714}
1715
1716/* operator callback */
1717static bool area_dupli_open(bContext *C, ScrArea *area, const int2 position)
1718{
1719 const wmWindow *win = CTX_wm_window(C);
1720 const rcti window_rect = {win->posx + position.x,
1721 win->posx + position.x + area->winx,
1722 win->posy + position.y,
1723 win->posy + position.y + area->winy};
1724
1725 /* Create new window. No need to set space_type since it will be copied over. */
1726 wmWindow *newwin = WM_window_open(C,
1727 nullptr,
1728 &window_rect,
1730 false,
1731 false,
1732 false,
1734 /* Initialize area from callback. */
1736 static_cast<void *>(area));
1737 return (newwin != nullptr);
1738}
1739
1741{
1742 ScrArea *area = CTX_wm_area(C);
1743 if (event && event->customdata) {
1744 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
1745 if (sad == nullptr) {
1746 return OPERATOR_PASS_THROUGH;
1747 }
1748 area = sad->sa1;
1749 }
1750
1751 bool newwin = area_dupli_open(C, area, int2(area->totrct.xmin, area->totrct.ymin));
1752
1753 if (newwin) {
1754 /* screen, areas init */
1756 }
1757 else {
1758 BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
1759 }
1760
1761 if (event && event->customdata) {
1762 actionzone_exit(op);
1763 }
1764
1765 return newwin ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1766}
1767
1769{
1770 if (!ED_operator_areaactive(C)) {
1771 return false;
1772 }
1773
1774 if (CTX_wm_area(C)->global) {
1775 return false;
1776 }
1777
1778 if (CTX_wm_screen(C)->temp) {
1779 return false;
1780 }
1781
1782 return true;
1783}
1784
1786{
1787 ot->name = "Duplicate Area into New Window";
1788 ot->description = "Duplicate selected area into new window";
1789 ot->idname = "SCREEN_OT_area_dupli";
1790
1792 ot->poll = area_dupli_poll;
1793}
1794
1796
1797/* -------------------------------------------------------------------- */
1802
1811{
1812 bScreen *screen = CTX_wm_screen(C);
1813 ScrArea *area = CTX_wm_area(C);
1814
1815 /* This operator is script-able, so the area passed could be invalid. */
1816 if (BLI_findindex(&screen->areabase, area) == -1) {
1817 BKE_report(op->reports, RPT_ERROR, "Area not found in the active screen");
1818 return OPERATOR_CANCELLED;
1819 }
1820
1821 float inner[4] = {0.0f, 0.0f, 0.0f, 0.7f};
1823 CTX_wm_window(C), CTX_wm_screen(C), &area->totrct, inner, nullptr, AREA_CLOSE_FADEOUT);
1824
1825 if (!screen_area_close(C, op->reports, screen, area)) {
1826 BKE_report(op->reports, RPT_ERROR, "Unable to close area");
1827 return OPERATOR_CANCELLED;
1828 }
1829
1830 /* Ensure the event loop doesn't attempt to continue handling events.
1831 *
1832 * This causes execution from the Python console fail to return to the prompt as it should.
1833 * This glitch could be solved in the event loop handling as other operators may also
1834 * destructively manipulate windowing data. */
1835 CTX_wm_window_set(C, nullptr);
1836
1838
1839 return OPERATOR_FINISHED;
1840}
1841
1843{
1844 if (!ED_operator_areaactive(C)) {
1845 return false;
1846 }
1847
1848 ScrArea *area = CTX_wm_area(C);
1849
1850 if (ED_area_is_global(area)) {
1851 return false;
1852 }
1853
1854 bScreen *screen = CTX_wm_screen(C);
1855
1856 /* Can this area join with ANY other area? */
1857 for (ScrArea &ar : screen->areabase) {
1858 if (area_getorientation(&ar, area) != -1) {
1859 return true;
1860 }
1861 }
1862
1863 return false;
1864}
1865
1867{
1868 ot->name = "Close Area";
1869 ot->description = "Close selected area";
1870 ot->idname = "SCREEN_OT_area_close";
1871 ot->exec = area_close_exec;
1872 ot->poll = area_close_poll;
1873}
1874
1876
1877/* -------------------------------------------------------------------- */
1880
1881/* operator state vars used:
1882 * x, y mouse coord near edge
1883 * delta movement of edge
1884 *
1885 * functions:
1886 *
1887 * init() set default property values, find edge based on mouse coords, test
1888 * if the edge can be moved, select edges, calculate min and max movement
1889 *
1890 * apply() apply delta on selection
1891 *
1892 * exit() cleanup, send notifier
1893 *
1894 * cancel() cancel moving
1895 *
1896 * callbacks:
1897 *
1898 * exec() execute without any user interaction, based on properties
1899 * call init(), apply(), exit()
1900 *
1901 * invoke() gets called on mouse click near edge
1902 * call init(), add handler
1903 *
1904 * modal() accept modal events while doing it
1905 * call apply() with delta motion
1906 * call exit() and remove handler
1907 */
1908
1910 /* Snapping disabled */
1911 SNAP_NONE = 0, /* Snap to an invisible grid with a unit defined in AREAGRID */
1912 SNAP_AREAGRID, /* Snap to fraction (half, third.. etc) and adjacent edges. */
1913 SNAP_FRACTION_AND_ADJACENT, /* Snap to either bigger or smaller, nothing in-between (used for
1914 * global areas). This has priority over other snap types, if it is
1915 * used, toggling SNAP_FRACTION_AND_ADJACENT doesn't work. */
1917};
1918
1923 bool can_extend; /* There are other aligned edges. */
1924 bool extending; /* Currently moving multiple edges. */
1928 double end_time;
1930 void *draw_callback; /* Call #screen_draw_move_highlight */
1931};
1932
1933/* helper call to move area-edge, sets limits
1934 * need window bounds in order to get correct limits */
1936 bScreen *screen,
1937 const eScreenAxis dir_axis,
1938 int *bigger,
1939 int *smaller,
1940 bool *use_bigger_smaller_snap)
1941{
1942 /* we check all areas and test for free space with MINSIZE */
1943 *bigger = *smaller = 100000;
1944
1945 if (use_bigger_smaller_snap != nullptr) {
1946 *use_bigger_smaller_snap = false;
1947 for (ScrArea &area : win->global_areas.areabase) {
1948 int size_min = ED_area_global_min_size_y(&area) - 1;
1949 int size_max = ED_area_global_max_size_y(&area) - 1;
1950
1951 size_min = max_ii(size_min, 0);
1952 BLI_assert(size_min <= size_max);
1953
1954 /* logic here is only tested for lower edge :) */
1955 /* left edge */
1956 if (area.v1->editflag && area.v2->editflag) {
1957 *smaller = area.v4->vec.x - size_max;
1958 *bigger = area.v4->vec.x - size_min;
1959 *use_bigger_smaller_snap = true;
1960 return;
1961 }
1962 /* top edge */
1963 if (area.v2->editflag && area.v3->editflag) {
1964 *smaller = area.v1->vec.y + size_min;
1965 *bigger = area.v1->vec.y + size_max;
1966 *use_bigger_smaller_snap = true;
1967 return;
1968 }
1969 /* right edge */
1970 if (area.v3->editflag && area.v4->editflag) {
1971 *smaller = area.v1->vec.x + size_min;
1972 *bigger = area.v1->vec.x + size_max;
1973 *use_bigger_smaller_snap = true;
1974 return;
1975 }
1976 /* lower edge */
1977 if (area.v4->editflag && area.v1->editflag) {
1978 *smaller = area.v2->vec.y - size_max;
1979 *bigger = area.v2->vec.y - size_min;
1980 *use_bigger_smaller_snap = true;
1981 return;
1982 }
1983 }
1984 }
1985
1986 rcti window_rect;
1987 WM_window_rect_calc(win, &window_rect);
1988
1989 for (ScrArea &area : screen->areabase) {
1990 if (dir_axis == SCREEN_AXIS_H) {
1991 const int y1 = area.winy - ED_area_headersize();
1992 /* if top or down edge selected, test height */
1993 if (area.v1->editflag && area.v4->editflag) {
1994 *bigger = min_ii(*bigger, y1);
1995 }
1996 else if (area.v2->editflag && area.v3->editflag) {
1997 *smaller = min_ii(*smaller, y1);
1998 }
1999 }
2000 else {
2001 const int x1 = area.winx - int(AREAMINX * UI_SCALE_FAC) - 1;
2002 /* if left or right edge selected, test width */
2003 if (area.v1->editflag && area.v2->editflag) {
2004 *bigger = min_ii(*bigger, x1);
2005 }
2006 else if (area.v3->editflag && area.v4->editflag) {
2007 *smaller = min_ii(*smaller, x1);
2008 }
2009 }
2010 }
2011}
2012
2013static void area_move_draw_cb(const wmWindow *win, void *userdata)
2014{
2015 const wmOperator *op = static_cast<const wmOperator *>(userdata);
2016 const sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2017 const double now = BLI_time_now_seconds();
2018 float factor = 1.0f;
2019 if (now < md->end_time) {
2020 factor = pow((now - md->start_time) / (md->end_time - md->start_time), 2);
2021 md->screen->do_refresh = true;
2022 }
2023 screen_draw_move_highlight(win, md->screen, md->dir_axis, factor);
2024}
2025
2026static void area_move_out_draw_cb(const wmWindow *win, void *userdata)
2027{
2028 const sAreaMoveData *md = static_cast<sAreaMoveData *>(userdata);
2029 const double now = BLI_time_now_seconds();
2030 float factor = 1.0f;
2031 if (now > md->end_time) {
2033 MEM_delete(md);
2034 return;
2035 }
2036 if (now < md->end_time) {
2037 factor = 1.0f - pow((now - md->start_time) / (md->end_time - md->start_time), 2);
2038 md->screen->do_refresh = true;
2039 }
2040 screen_draw_move_highlight(win, md->screen, md->dir_axis, factor);
2041}
2042
2043/* When changing to/from edge extension we need to reinitialize
2044 * everything, including movement limits, starting positions, etc. */
2045static bool area_move_reinit(bContext *C, wmOperator *op, bool extend, const int xy[2])
2046{
2047 sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2048 bScreen *screen = CTX_wm_screen(C);
2049 wmWindow *win = CTX_wm_window(C);
2050
2051 ED_screen_verts_iter(win, screen, v1)
2052 {
2053 v1->editflag = 0;
2054 }
2055
2056 ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, xy[0], xy[1]);
2057 if (actedge == nullptr) {
2058 md->can_extend = false;
2059 md->extending = false;
2060 return false;
2061 }
2062
2063 RNA_int_set(op->ptr, "x", xy[0]);
2064 RNA_int_set(op->ptr, "y", xy[1]);
2065 if (md->dir_axis == SCREEN_AXIS_H) {
2066 md->origval = actedge->v1->vec.y;
2067 }
2068 else {
2069 md->origval = actedge->v1->vec.x;
2070 }
2071
2072 md->can_extend = screen_geom_edge_can_extend(win, actedge);
2073 if (md->can_extend && extend) {
2075 md->extending = true;
2076 }
2077 else {
2079 md->extending = false;
2080 }
2081
2082 /* Vertices with 'flag == 1' can be moved. Move this to editflag. */
2083 ED_screen_verts_iter(win, screen, v1)
2084 {
2085 v1->editflag = v1->flag;
2086 }
2087
2088 bool use_bigger_smaller_snap = false;
2090 win, screen, md->dir_axis, &md->bigger, &md->smaller, &use_bigger_smaller_snap);
2091
2094
2095 return true;
2096}
2097
2098/* validate selection inside screen, set variables OK */
2099/* return false: init failed */
2100static bool area_move_init(bContext *C, wmOperator *op, bool extend)
2101{
2102 bScreen *screen = CTX_wm_screen(C);
2103 wmWindow *win = CTX_wm_window(C);
2104 ScrArea *area = CTX_wm_area(C);
2105
2106 /* required properties */
2107 int x = RNA_int_get(op->ptr, "x");
2108 int y = RNA_int_get(op->ptr, "y");
2109 bool snap_prop = RNA_boolean_get(op->ptr, "snap");
2110
2111 /* setup */
2112 ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, x, y);
2113
2114 if (area) {
2115 /* Favor scroll bars and action zones over expanded edge zone. */
2116 const int xy[2] = {x, y};
2117 if (ED_area_actionzone_find_xy(area, xy)) {
2118 return false;
2119 }
2120 }
2121
2122 if (actedge == nullptr) {
2123 return false;
2124 }
2125
2126 sAreaMoveData *md = MEM_new_zeroed<sAreaMoveData>("sAreaMoveData");
2127 op->customdata = md;
2128
2129 const int xy[2] = {x, y};
2130 screen_area_edge_from_cursor(C, xy, &md->area1, &md->area2);
2131
2133 if (md->dir_axis == SCREEN_AXIS_H) {
2134 md->origval = actedge->v1->vec.y;
2135 }
2136 else {
2137 md->origval = actedge->v1->vec.x;
2138 }
2139
2140 md->can_extend = screen_geom_edge_can_extend(win, actedge);
2141 if (md->can_extend && extend) {
2143 md->extending = true;
2144 }
2145 else {
2147 md->extending = false;
2148 }
2149
2150 /* now all vertices with 'flag == 1' are the ones that can be moved. Move this to editflag */
2151 ED_screen_verts_iter(win, screen, v1)
2152 {
2153 v1->editflag = v1->flag;
2154 }
2155
2156 bool use_bigger_smaller_snap = false;
2158 win, screen, md->dir_axis, &md->bigger, &md->smaller, &use_bigger_smaller_snap);
2159
2160 if (snap_prop) {
2162 }
2163 else {
2164 md->snap_type = use_bigger_smaller_snap ? SNAP_BIGGER_SMALLER_ONLY : SNAP_AREAGRID;
2165 }
2166
2167 md->win = win;
2168 md->screen = screen;
2172
2173 return true;
2174}
2175
2177{
2178 if (area == nullptr) {
2179 return false;
2180 }
2181
2183 return true;
2184 }
2185
2186 if (area->spacetype == SPACE_SEQ) {
2188 if (region && region->runtime->visible) {
2189 return true;
2190 }
2191 }
2192
2193 if (area->spacetype == SPACE_CLIP) {
2195 if (region && region->runtime->visible) {
2196 return true;
2197 }
2198 }
2199
2200 return false;
2201}
2202
2204{
2205 if (area == nullptr) {
2206 return false;
2207 }
2208
2211 const bool anim_footer = (region && region->runtime->visible);
2213 const bool anim_header = (region && region->runtime->visible);
2214 return anim_footer && anim_header;
2215 }
2216
2217 return false;
2218}
2219
2220static int area_snap_calc_location(sAreaMoveData *md, const int delta)
2221{
2223 int m_cursor_final = -1;
2224 const int m_cursor = md->origval + delta;
2225 const int m_span = float(md->bigger + md->smaller);
2226 const int m_min = md->origval - md->smaller;
2227 // const int axis_max = axis_min + m_span;
2228
2229 switch (md->snap_type) {
2230 case SNAP_AREAGRID: {
2231 m_cursor_final = m_cursor;
2232 if (!ELEM(delta, md->bigger, -md->smaller)) {
2233 m_cursor_final -= (m_cursor % AREAGRID);
2234 CLAMP(m_cursor_final, md->origval - md->smaller, md->origval + md->bigger);
2235 }
2236
2237 /* Slight snap to vertical minimum and maximum. */
2238 const int snap_threshold = int(float(ED_area_headersize()) * 0.6f);
2239
2240 Vector<int> snaps;
2241 /* Minimum. */
2242 snaps.append(m_min);
2243
2244 if (md->dir_axis == SCREEN_AXIS_H) {
2245 /* Minimal snaps for editors below the cursor with time scrub areas. */
2246 int snap_pos = m_min;
2247 if (area_has_scrubbing_snap(md->area2)) {
2248 snap_pos += UI_TIME_SCRUB_MARGIN_Y;
2249 snaps.append(snap_pos);
2250 }
2251 if (area_has_playback_snap(md->area2)) {
2252 snap_pos += ED_area_footersize();
2253 snaps.append(snap_pos);
2254 }
2255
2256 /* Maximal snaps for editors above the cursor with time scrub areas. */
2257 snap_pos = md->origval + md->bigger;
2258 if (area_has_playback_snap(md->area1)) {
2259 snap_pos -= ED_area_footersize();
2260 snaps.append(snap_pos);
2261 }
2262 if (area_has_scrubbing_snap(md->area1)) {
2263 snap_pos -= UI_TIME_SCRUB_MARGIN_Y;
2264 snaps.append(snap_pos);
2265 }
2266
2267 if (md->area2 && md->area2->spacetype == SPACE_CONSOLE) {
2268 /* Minimal snap for Console below. */
2269 SpaceConsole *console = md->area2->spacedata.first_as<SpaceConsole>();
2270 snaps.append(m_min + int(float(console->line_height) * UI_SCALE_FAC * 1.5f));
2271 }
2272 if (md->area1 && md->area1->spacetype == SPACE_CONSOLE) {
2273 /* Maximal snap for Console above. */
2274 SpaceConsole *console = md->area1->spacedata.first_as<SpaceConsole>();
2275 snaps.append(md->origval + md->bigger -
2276 int(float(console->line_height) * UI_SCALE_FAC * 1.5f));
2277 }
2278 }
2279
2280 /* Maximum. */
2281 snaps.append(md->origval + md->bigger);
2282
2283 for (int i = 0; i < snaps.size(); i++) {
2284 if (abs(m_cursor_final - snaps[i]) < snap_threshold) {
2285 m_cursor_final = snaps[i];
2286 break;
2287 }
2288 }
2289 } break;
2290
2292 m_cursor_final = (m_cursor >= md->bigger) ? md->bigger : md->smaller;
2293 break;
2294
2296 const int axis = (md->dir_axis == SCREEN_AXIS_V) ? 0 : 1;
2297 int snap_dist_best = INT_MAX;
2298 {
2299 rcti screen_rect;
2300 WM_window_screen_rect_calc(md->win, &screen_rect);
2301
2302 const int screen_size = (md->dir_axis == SCREEN_AXIS_V) ? BLI_rcti_size_x(&screen_rect) :
2303 BLI_rcti_size_y(&screen_rect);
2304 const int screen_min = (md->dir_axis == SCREEN_AXIS_V) ? screen_rect.xmin :
2305 screen_rect.ymin;
2306
2307 /* Number of snap sections between the end-snap points. Minimum is 2, which
2308 * results in a single extra position at 50%. Should be even and easily divisible. */
2309 const int interior_snap_divisor = 24;
2310 /* Minimum snap helps to cull any that are too close to the endpoint snaps. */
2311 const int min_snap = int(float(screen_size) / float(interior_snap_divisor) / 4.0f);
2312
2313 Vector<int> snaps(interior_snap_divisor + 1);
2314 snaps[0] = m_min;
2315 for (int i = 1; i < interior_snap_divisor; i++) {
2316 snaps[i] = (screen_min + round_fl_to_int(screen_size * i / interior_snap_divisor));
2317 }
2318 snaps[interior_snap_divisor] = (m_min + m_span);
2319
2320 /* Test the snap to the best division. */
2321 for (int i = 0; i < snaps.size(); i++) {
2322 const int m_cursor_test = snaps[i];
2323 if (m_cursor_test < (m_min) ||
2324 (m_cursor_test > m_min && m_cursor_test < (m_min + min_snap)))
2325 {
2326 /* Ignore snaps too close to the minimum snap position. */
2327 continue;
2328 }
2329 if (m_cursor_test > (m_min + m_span) ||
2330 (m_cursor_test < (m_min + m_span) && m_cursor_test > (m_min + m_span - min_snap)))
2331 {
2332 /* Ignore snaps too close to the maximum snap position. */
2333 continue;
2334 }
2335 const int snap_dist_test = abs(m_cursor - m_cursor_test);
2336 if (snap_dist_best >= snap_dist_test) {
2337 snap_dist_best = snap_dist_test;
2338 m_cursor_final = m_cursor_test;
2339 }
2340 }
2341 }
2342
2343 for (const ScrVert &v1 : md->screen->vertbase) {
2344 if (!v1.editflag) {
2345 continue;
2346 }
2347 const int v_loc = (&v1.vec.x)[!axis];
2348
2349 for (const ScrVert &v2 : md->screen->vertbase) {
2350 if (v2.editflag) {
2351 continue;
2352 }
2353 if (v_loc == (&v2.vec.x)[!axis]) {
2354 const int v_loc2 = (&v2.vec.x)[axis];
2355 /* Do not snap to the vertices at the ends. */
2356 if ((md->origval - md->smaller) < v_loc2 && v_loc2 < (md->origval + md->bigger)) {
2357 const int snap_dist_test = abs(m_cursor - v_loc2);
2358 if (snap_dist_best >= snap_dist_test) {
2359 snap_dist_best = snap_dist_test;
2360 m_cursor_final = v_loc2;
2361 }
2362 }
2363 }
2364 }
2365 }
2366 break;
2367 }
2368 case SNAP_NONE:
2369 break;
2370 }
2371
2373 IN_RANGE_INCL(m_cursor_final, md->origval - md->smaller, md->origval + md->bigger));
2374
2375 return m_cursor_final;
2376}
2377
2378/* Moves selected screen edge amount of delta. */
2379static void area_move_apply_do(bContext *C, int delta, sAreaMoveData *md)
2380{
2381 WorkspaceStatus status(C);
2382 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
2383 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
2384 status.item_bool(IFACE_("Snap"), md->snap_type == SNAP_FRACTION_AND_ADJACENT, ICON_EVENT_CTRL);
2385 if (md->can_extend) {
2386 status.item_bool(IFACE_("Extend"), md->extending, ICON_EVENT_SHIFT);
2387 }
2388
2389 short final_loc = -1;
2390 bool doredraw = false;
2391
2393 CLAMP(delta, -md->smaller, md->bigger);
2394 }
2395
2396 if (md->snap_type == SNAP_NONE) {
2397 final_loc = md->origval + delta;
2398 }
2399 else {
2400 final_loc = area_snap_calc_location(md, delta);
2401 }
2402
2403 BLI_assert(final_loc != -1);
2404 short axis = (md->dir_axis == SCREEN_AXIS_V) ? 0 : 1;
2405
2406 ED_screen_verts_iter(md->win, md->screen, v1)
2407 {
2408 if (v1->editflag) {
2409 short oldval = (&v1->vec.x)[axis];
2410 (&v1->vec.x)[axis] = final_loc;
2411
2412 if (oldval == final_loc) {
2413 /* nothing will change to the other vertices either. */
2414 break;
2415 }
2416 doredraw = true;
2417 }
2418 }
2419
2420 /* only redraw if we actually moved a screen vert, for AREAGRID */
2421 if (doredraw) {
2422 bool redraw_all = false;
2423 ED_screen_areas_iter (md->win, md->screen, area) {
2424 if (area->v1->editflag || area->v2->editflag || area->v3->editflag || area->v4->editflag) {
2425 if (ED_area_is_global(area)) {
2426 /* Snap to minimum or maximum for global areas. */
2428 if (abs(height - area->global->size_min) < abs(height - area->global->size_max)) {
2429 area->global->cur_fixed_height = area->global->size_min;
2430 }
2431 else {
2432 area->global->cur_fixed_height = area->global->size_max;
2433 }
2434
2435 md->screen->do_refresh = true;
2436 redraw_all = true;
2437 }
2439 }
2440 }
2441 if (redraw_all) {
2442 ED_screen_areas_iter (md->win, md->screen, area) {
2443 ED_area_tag_redraw(area);
2444 }
2445 }
2446
2448
2449 WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, nullptr); /* redraw everything */
2450 /* Update preview thumbnail */
2452 }
2453}
2454
2456{
2457 sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2458 int delta = RNA_int_get(op->ptr, "delta");
2459
2460 area_move_apply_do(C, delta, md);
2461}
2462
2464{
2465 sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2466 if (md->draw_callback) {
2468 }
2469
2470 op->customdata = nullptr;
2471
2474 md->win = CTX_wm_window(C);
2476
2478 ED_workspace_status_text(C, nullptr);
2479
2481}
2482
2484{
2485 if (!area_move_init(C, op, false)) {
2486 return OPERATOR_CANCELLED;
2487 }
2488
2489 area_move_apply(C, op);
2490 area_move_exit(C, op);
2491
2492 return OPERATOR_FINISHED;
2493}
2494
2495/* interaction callback */
2497{
2498 RNA_int_set(op->ptr, "x", event->xy[0]);
2499 RNA_int_set(op->ptr, "y", event->xy[1]);
2500
2501 if (!area_move_init(C, op, event->modifier & KM_SHIFT)) {
2502 return OPERATOR_PASS_THROUGH;
2503 }
2504
2505 sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2506
2507 WorkspaceStatus status(C);
2508 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
2509 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
2510 status.item_bool(IFACE_("Snap"), md->snap_type == SNAP_FRACTION_AND_ADJACENT, ICON_EVENT_CTRL);
2511 if (md->can_extend) {
2512 status.item_bool(IFACE_("Extend"), md->extending, ICON_EVENT_SHIFT);
2513 }
2514
2515 /* add temp handler */
2518
2520}
2521
2523{
2524
2525 RNA_int_set(op->ptr, "delta", 0);
2526 area_move_apply(C, op);
2527 area_move_exit(C, op);
2528}
2529
2530/* modal callback for while moving edges */
2532{
2533 sAreaMoveData *md = static_cast<sAreaMoveData *>(op->customdata);
2534
2535 /* execute the events */
2536 switch (event->type) {
2537 case EVT_RIGHTSHIFTKEY:
2538 case EVT_LEFTSHIFTKEY: {
2539 if (!md->can_extend || !area_move_reinit(C, op, event->val == KM_PRESS, event->xy)) {
2540 md->extending = false;
2541 }
2543 break;
2544 }
2545 case MOUSEMOVE: {
2546 int x = RNA_int_get(op->ptr, "x");
2547 int y = RNA_int_get(op->ptr, "y");
2548
2549 const int delta = (md->dir_axis == SCREEN_AXIS_V) ? event->xy[0] - x : event->xy[1] - y;
2550 RNA_int_set(op->ptr, "delta", delta);
2551
2552 area_move_apply(C, op);
2553
2554 wmWindow *win = CTX_wm_window(C);
2555 bScreen *screen = CTX_wm_screen(C);
2556 if (!md->extending) {
2558 win, screen, event->xy[0], event->xy[1]);
2559 md->can_extend = actedge && screen_geom_edge_can_extend(md->win, actedge);
2560 }
2561
2562 break;
2563 }
2564 case RIGHTMOUSE: {
2565 area_move_cancel(C, op);
2566 return OPERATOR_CANCELLED;
2567 }
2568 case EVT_MODAL_MAP: {
2569 switch (event->val) {
2570 case KM_MODAL_APPLY:
2571 area_move_exit(C, op);
2572 return OPERATOR_FINISHED;
2573
2574 case KM_MODAL_CANCEL:
2575 area_move_cancel(C, op);
2576 return OPERATOR_CANCELLED;
2577
2578 case KM_MODAL_SNAP_ON:
2581 }
2582 break;
2583
2584 case KM_MODAL_SNAP_OFF:
2587 }
2588 break;
2589 }
2590 break;
2591 }
2592 default: {
2593 break;
2594 }
2595 }
2596
2597 WorkspaceStatus status(C);
2598 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
2599 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
2600 status.item_bool(IFACE_("Snap"), md->snap_type == SNAP_FRACTION_AND_ADJACENT, ICON_EVENT_CTRL);
2601 if (md->can_extend) {
2602 status.item_bool(IFACE_("Extend"), md->extending, ICON_EVENT_SHIFT);
2603 }
2604
2606}
2607
2609{
2610 PropertyRNA *prop;
2611
2612 /* identifiers */
2613 ot->name = "Move Area Edges";
2614 ot->description = "Move selected area edges";
2615 ot->idname = "SCREEN_OT_area_move";
2616
2617 ot->exec = area_move_exec;
2620 ot->modal = area_move_modal;
2621 ot->poll = ED_operator_screen_mainwinactive; /* when mouse is over area-edge */
2622
2623 /* flags */
2625
2626 /* rna */
2627 RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
2628 RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
2629 RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
2630
2631 prop = RNA_def_boolean(ot->srna, "snap", false, "Snapping", "Enable snapping");
2633}
2634
2636
2637/* -------------------------------------------------------------------- */
2640
2642{
2643 int cursor[2];
2644 RNA_int_get_array(op->ptr, "cursor", cursor);
2645
2646 bScreen *screen = CTX_wm_screen(C);
2647 wmWindow *win = CTX_wm_window(C);
2648 ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, cursor[0], cursor[1]);
2649 if (!actedge) {
2650 return OPERATOR_CANCELLED;
2651 }
2652
2653 if (!screen_geom_edge_can_extend(win, actedge)) {
2654 return OPERATOR_CANCELLED;
2655 }
2656
2657 screen_geom_edge_aligned_merge(win, actedge);
2659
2660 return OPERATOR_FINISHED;
2661}
2662
2664{
2665 PropertyRNA *prop;
2666
2667 /* identifiers */
2668 ot->name = "Merge Area Edge";
2669 ot->description = "Merge aligned area edges";
2670 ot->idname = "SCREEN_OT_edge_merge";
2673
2674 /* flags */
2675 ot->flag = OPTYPE_INTERNAL;
2676
2677 /* rna */
2678 prop = RNA_def_int_vector(
2679 ot->srna, "cursor", 2, nullptr, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX);
2681}
2682
2684
2685/* -------------------------------------------------------------------- */
2688
2689/*
2690 * operator state vars:
2691 * fac spit point
2692 * dir direction #SCREEN_AXIS_V or #SCREEN_AXIS_H
2693 *
2694 * operator customdata:
2695 * area pointer to (active) area
2696 * x, y last used mouse pos
2697 * (more, see below)
2698 *
2699 * functions:
2700 *
2701 * init() set default property values, find area based on context
2702 *
2703 * apply() split area based on state vars
2704 *
2705 * exit() cleanup, send notifier
2706 *
2707 * cancel() remove duplicated area
2708 *
2709 * callbacks:
2710 *
2711 * exec() execute without any user interaction, based on state vars
2712 * call init(), apply(), exit()
2713 *
2714 * invoke() gets called on mouse click in action-widget
2715 * call init(), add modal handler
2716 * call apply() with initial motion
2717 *
2718 * modal() accept modal events while doing it
2719 * call move-areas code with delta motion
2720 * call exit() or cancel() and remove handler
2721 */
2722
2724 int origval; /* for move areas */
2725 int bigger, smaller; /* constraints for moving new edge */
2726 int delta; /* delta move edge */
2727 int origmin, origsize; /* to calculate fac, for property storage */
2728 void *draw_callback; /* call `screen_draw_split_preview` */
2730
2731 ScrEdge *nedge; /* new edge */
2732 ScrArea *sarea; /* start area */
2733 ScrArea *narea; /* new area */
2734};
2735
2736static bool area_split_allowed(const ScrArea *area, const eScreenAxis dir_axis)
2737{
2738 if (!area || area->global) {
2739 /* Must be a non-global area. */
2740 return false;
2741 }
2742
2743 if ((dir_axis == SCREEN_AXIS_V && area->winx <= 2 * AREAMINX * UI_SCALE_FAC) ||
2744 (dir_axis == SCREEN_AXIS_H && area->winy <= 2 * ED_area_headersize()))
2745 {
2746 /* Must be at least double minimum sizes to split into two. */
2747 return false;
2748 }
2749
2750 return true;
2751}
2752
2753static void area_split_draw_cb(const wmWindow * /*win*/, void *userdata)
2754{
2755 const wmOperator *op = static_cast<const wmOperator *>(userdata);
2756
2757 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
2758 const eScreenAxis dir_axis = eScreenAxis(RNA_enum_get(op->ptr, "direction"));
2759
2760 if (area_split_allowed(sd->sarea, dir_axis)) {
2761 float fac = RNA_float_get(op->ptr, "factor");
2762 screen_draw_split_preview(sd->sarea, dir_axis, fac);
2763 }
2764}
2765
2766/* generic init, menu case, doesn't need active area */
2768{
2769 /* custom data */
2770 sAreaSplitData *sd = MEM_new_zeroed<sAreaSplitData>("op_area_split");
2771 op->customdata = sd;
2772
2773 sd->sarea = CTX_wm_area(C);
2774
2775 return true;
2776}
2777
2778/* generic init, no UI stuff here, assumes active area */
2780{
2781 ScrArea *area = CTX_wm_area(C);
2782
2783 /* required context */
2784 if (area == nullptr) {
2785 return false;
2786 }
2787
2788 /* required properties */
2789 const eScreenAxis dir_axis = eScreenAxis(RNA_enum_get(op->ptr, "direction"));
2790
2791 /* custom data */
2792 sAreaSplitData *sd = MEM_new_zeroed<sAreaSplitData>("op_area_split");
2793 op->customdata = sd;
2794
2795 sd->sarea = area;
2796 if (dir_axis == SCREEN_AXIS_V) {
2797 sd->origmin = area->v1->vec.x;
2798 sd->origsize = area->v4->vec.x - sd->origmin;
2799 }
2800 else {
2801 sd->origmin = area->v1->vec.y;
2802 sd->origsize = area->v2->vec.y - sd->origmin;
2803 }
2804
2805 return true;
2806}
2807
2808/* with area as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
2809/* used with split operator */
2811{
2812 ScrVert *sav1 = area->v1;
2813 ScrVert *sav2 = area->v2;
2814 ScrVert *sav3 = area->v3;
2815 ScrVert *sav4 = area->v4;
2816 ScrVert *sbv1 = sb->v1;
2817 ScrVert *sbv2 = sb->v2;
2818 ScrVert *sbv3 = sb->v3;
2819 ScrVert *sbv4 = sb->v4;
2820
2821 if (sav1 == sbv4 && sav2 == sbv3) { /* Area to right of sb = W. */
2822 return BKE_screen_find_edge(screen, sav1, sav2);
2823 }
2824 if (sav2 == sbv1 && sav3 == sbv4) { /* Area to bottom of sb = N. */
2825 return BKE_screen_find_edge(screen, sav2, sav3);
2826 }
2827 if (sav3 == sbv2 && sav4 == sbv1) { /* Area to left of sb = E. */
2828 return BKE_screen_find_edge(screen, sav3, sav4);
2829 }
2830 if (sav1 == sbv2 && sav4 == sbv3) { /* Area on top of sb = S. */
2831 return BKE_screen_find_edge(screen, sav1, sav4);
2832 }
2833
2834 return nullptr;
2835}
2836
2837/* do the split, return success */
2839{
2840 const wmWindow *win = CTX_wm_window(C);
2841 bScreen *screen = CTX_wm_screen(C);
2842 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
2843
2844 float fac = RNA_float_get(op->ptr, "factor");
2845 const eScreenAxis dir_axis = eScreenAxis(RNA_enum_get(op->ptr, "direction"));
2846
2847 if (!area_split_allowed(sd->sarea, dir_axis)) {
2848 return false;
2849 }
2850
2851 sd->narea = area_split(win, screen, sd->sarea, dir_axis, fac);
2852
2853 if (sd->narea == nullptr) {
2854 return false;
2855 }
2856
2857 sd->nedge = area_findsharededge(screen, sd->sarea, sd->narea);
2858
2859 /* select newly created edge, prepare for moving edge */
2860 ED_screen_verts_iter(win, screen, sv)
2861 {
2862 sv->editflag = 0;
2863 }
2864
2865 sd->nedge->v1->editflag = 1;
2866 sd->nedge->v2->editflag = 1;
2867
2868 if (dir_axis == SCREEN_AXIS_H) {
2869 sd->origval = sd->nedge->v1->vec.y;
2870 }
2871 else {
2872 sd->origval = sd->nedge->v1->vec.x;
2873 }
2874
2877
2879 /* Update preview thumbnail */
2880 BKE_icon_changed(screen->id.icon_id);
2881
2882 /* We have more than one area now, so reset window title. */
2884
2885 return true;
2886}
2887
2889{
2890 if (op->customdata) {
2891 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
2892 if (sd->sarea) {
2894 }
2895 if (sd->narea) {
2897 }
2898
2899 if (sd->draw_callback) {
2901 }
2902
2903 MEM_delete(sd);
2904 op->customdata = nullptr;
2905 }
2906
2909 ED_workspace_status_text(C, nullptr);
2910
2912
2914}
2915
2917{
2918 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
2919 const eScreenAxis dir_axis = eScreenAxis(RNA_enum_get(op->ptr, "direction"));
2920 if (area_split_allowed(sd->sarea, dir_axis)) {
2923 }
2924 else {
2926 }
2927}
2928
2929/* UI callback, adds new handler */
2931{
2932 wmWindow *win = CTX_wm_window(C);
2933 bScreen *screen = CTX_wm_screen(C);
2934
2935 /* no full window splitting allowed */
2936 BLI_assert(screen->state == SCREENNORMAL);
2937
2938 PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction");
2939 PropertyRNA *prop_factor = RNA_struct_find_property(op->ptr, "factor");
2940 PropertyRNA *prop_cursor = RNA_struct_find_property(op->ptr, "cursor");
2941
2942 eScreenAxis dir_axis;
2943 if (event->type == EVT_ACTIONZONE_AREA) {
2944 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
2945
2946 if (sad == nullptr || sad->modifier > 0) {
2947 return OPERATOR_PASS_THROUGH;
2948 }
2949
2950 /* verify *sad itself */
2951 if (sad->sa1 == nullptr || sad->az == nullptr) {
2952 return OPERATOR_PASS_THROUGH;
2953 }
2954
2955 /* is this our *sad? if areas not equal it should be passed on */
2956 if (CTX_wm_area(C) != sad->sa1 || sad->sa1 != sad->sa2) {
2957 return OPERATOR_PASS_THROUGH;
2958 }
2959
2960 /* The factor will be close to 1.0f when near the top-left and the bottom-right corners. */
2961 const float factor_v = float(event->xy[1] - sad->sa1->v1->vec.y) / float(sad->sa1->winy);
2962 const float factor_h = float(event->xy[0] - sad->sa1->v1->vec.x) / float(sad->sa1->winx);
2963 const bool is_left = factor_v < 0.5f;
2964 const bool is_bottom = factor_h < 0.5f;
2965 const bool is_right = !is_left;
2966 const bool is_top = !is_bottom;
2967 float factor;
2968
2969 /* Prepare operator state vars. */
2971 dir_axis = SCREEN_AXIS_H;
2972 factor = factor_h;
2973 }
2974 else {
2975 dir_axis = SCREEN_AXIS_V;
2976 factor = factor_v;
2977 }
2978
2979 if ((is_top && is_left) || (is_bottom && is_right)) {
2980 factor = 1.0f - factor;
2981 }
2982
2983 RNA_property_float_set(op->ptr, prop_factor, factor);
2984
2985 RNA_property_enum_set(op->ptr, prop_dir, dir_axis);
2986
2987 /* general init, also non-UI case, adds customdata, sets area and defaults */
2988 if (!area_split_init(C, op)) {
2989 return OPERATOR_PASS_THROUGH;
2990 }
2991 }
2992 else if (RNA_property_is_set(op->ptr, prop_dir)) {
2993 ScrArea *area = CTX_wm_area(C);
2994 if (area == nullptr) {
2995 return OPERATOR_CANCELLED;
2996 }
2997 dir_axis = eScreenAxis(RNA_property_enum_get(op->ptr, prop_dir));
2998 if (dir_axis == SCREEN_AXIS_H) {
3000 op->ptr, prop_factor, float(event->xy[0] - area->v1->vec.x) / float(area->winx));
3001 }
3002 else {
3004 op->ptr, prop_factor, float(event->xy[1] - area->v1->vec.y) / float(area->winy));
3005 }
3006
3007 if (!area_split_init(C, op)) {
3008 return OPERATOR_CANCELLED;
3009 }
3010 }
3011 else {
3012 int event_co[2];
3013
3014 /* retrieve initial mouse coord, so we can find the active edge */
3015 if (RNA_property_is_set(op->ptr, prop_cursor)) {
3016 RNA_property_int_get_array(op->ptr, prop_cursor, event_co);
3017 }
3018 else {
3019 copy_v2_v2_int(event_co, event->xy);
3020 }
3021
3022 rcti window_rect;
3023 WM_window_rect_calc(win, &window_rect);
3024
3026 AREAMAP_FROM_SCREEN(screen), &window_rect, event_co[0], event_co[1]);
3027 if (actedge == nullptr) {
3028 return OPERATOR_CANCELLED;
3029 }
3030
3032
3033 RNA_property_enum_set(op->ptr, prop_dir, dir_axis);
3034
3035 /* special case, adds customdata, sets defaults */
3036 if (!area_split_menu_init(C, op)) {
3037 return OPERATOR_CANCELLED;
3038 }
3039 }
3040
3041 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
3043 /* add temp handler for edge move or cancel */
3047}
3048
3049/* function to be called outside UI context, or for redo */
3051{
3052 if (!area_split_init(C, op)) {
3053 return OPERATOR_CANCELLED;
3054 }
3055
3056 area_split_apply(C, op);
3057 area_split_exit(C, op);
3058
3059 return OPERATOR_FINISHED;
3060}
3061
3063{
3064 area_split_exit(C, op);
3065}
3066
3068 const int delta,
3069 const int origval,
3070 const eScreenAxis dir_axis,
3071 const int bigger,
3072 const int smaller)
3073{
3074 int m_cursor_final = -1;
3075 const int m_cursor = origval + delta;
3076 const int m_span = float(bigger + smaller);
3077 const int m_min = origval - smaller;
3078
3079 const int axis = (dir_axis == SCREEN_AXIS_V) ? 0 : 1;
3080 int snap_dist_best = INT_MAX;
3081 {
3082 const float div_array[] = {
3083 0.0f,
3084 1.0f / 12.0f,
3085 2.0f / 12.0f,
3086 3.0f / 12.0f,
3087 4.0f / 12.0f,
3088 5.0f / 12.0f,
3089 6.0f / 12.0f,
3090 7.0f / 12.0f,
3091 8.0f / 12.0f,
3092 9.0f / 12.0f,
3093 10.0f / 12.0f,
3094 11.0f / 12.0f,
3095 1.0f,
3096 };
3097 /* Test the snap to the best division. */
3098 for (int i = 0; i < ARRAY_SIZE(div_array); i++) {
3099 const int m_cursor_test = m_min + round_fl_to_int(m_span * div_array[i]);
3100 const int snap_dist_test = abs(m_cursor - m_cursor_test);
3101 if (snap_dist_best >= snap_dist_test) {
3102 snap_dist_best = snap_dist_test;
3103 m_cursor_final = m_cursor_test;
3104 }
3105 }
3106 }
3107
3108 for (const ScrVert &v1 : screen->vertbase) {
3109 if (!v1.editflag) {
3110 continue;
3111 }
3112 const int v_loc = (&v1.vec.x)[!axis];
3113
3114 for (const ScrVert &v2 : screen->vertbase) {
3115 if (v2.editflag) {
3116 continue;
3117 }
3118 if (v_loc == (&v2.vec.x)[!axis]) {
3119 const int v_loc2 = (&v2.vec.x)[axis];
3120 /* Do not snap to the vertices at the ends. */
3121 if ((origval - smaller) < v_loc2 && v_loc2 < (origval + bigger)) {
3122 const int snap_dist_test = abs(m_cursor - v_loc2);
3123 if (snap_dist_best >= snap_dist_test) {
3124 snap_dist_best = snap_dist_test;
3125 m_cursor_final = v_loc2;
3126 }
3127 }
3128 }
3129 }
3130 }
3131
3132 BLI_assert(IN_RANGE_INCL(m_cursor_final, origval - smaller, origval + bigger));
3133
3134 return m_cursor_final;
3135}
3136
3138{
3139 sAreaSplitData *sd = static_cast<sAreaSplitData *>(op->customdata);
3140 PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction");
3141 bool update_factor = false;
3142
3143 /* execute the events */
3144 switch (event->type) {
3145 case MOUSEMOVE:
3146 update_factor = true;
3147 break;
3148
3149 case LEFTMOUSE: {
3150 float inner[4] = {1.0f, 1.0f, 1.0f, 0.1f};
3151 float outline[4] = {1.0f, 1.0f, 1.0f, 0.3f};
3154 &sd->sarea->totrct,
3155 inner,
3156 outline,
3158 area_split_apply(C, op);
3159 area_split_exit(C, op);
3160 return OPERATOR_FINISHED;
3161 break;
3162 }
3163
3164 case MIDDLEMOUSE:
3165 case EVT_TABKEY:
3166 if (event->val == KM_PRESS) {
3167 if (sd->sarea) {
3168 const eScreenAxis dir_axis = eScreenAxis(RNA_property_enum_get(op->ptr, prop_dir));
3170 op->ptr, prop_dir, (dir_axis == SCREEN_AXIS_V) ? SCREEN_AXIS_H : SCREEN_AXIS_V);
3172 update_factor = true;
3173 }
3174 }
3175 break;
3176
3177 case RIGHTMOUSE: /* cancel operation */
3178 case EVT_ESCKEY:
3179 area_split_cancel(C, op);
3180 return OPERATOR_CANCELLED;
3181
3182 case EVT_LEFTCTRLKEY:
3183 case EVT_RIGHTCTRLKEY:
3184 sd->do_snap = event->val == KM_PRESS;
3185 update_factor = true;
3186 break;
3187 default: {
3188 break;
3189 }
3190 }
3191
3192 if (update_factor) {
3193 const eScreenAxis dir_axis = eScreenAxis(RNA_property_enum_get(op->ptr, prop_dir));
3194
3195 sd->delta = (dir_axis == SCREEN_AXIS_V) ? event->xy[0] - sd->origval :
3196 event->xy[1] - sd->origval;
3197
3198 if (sd->sarea) {
3200 }
3201
3203
3204 /* area context not set */
3206
3207 if (sd->sarea) {
3208 ScrArea *area = sd->sarea;
3209 if (dir_axis == SCREEN_AXIS_V) {
3210 sd->origmin = area->v1->vec.x;
3211 sd->origsize = area->v4->vec.x - sd->origmin;
3212 }
3213 else {
3214 sd->origmin = area->v1->vec.y;
3215 sd->origsize = area->v2->vec.y - sd->origmin;
3216 }
3217
3218 if (sd->do_snap) {
3219 area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 1;
3220
3221 const int snap_loc = area_split_snap_calc_location(CTX_wm_screen(C),
3222 sd->delta,
3223 sd->origval,
3224 dir_axis,
3225 sd->origmin + sd->origsize,
3226 -sd->origmin);
3227
3228 area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 0;
3229 sd->delta = snap_loc - sd->origval;
3230 }
3231
3233 }
3234
3235 CTX_wm_screen(C)->do_draw = true;
3236
3237 float fac = float(sd->delta + sd->origval - sd->origmin) / sd->origsize;
3238 RNA_float_set(op->ptr, "factor", fac);
3239 }
3240
3242}
3243
3245 {SCREEN_AXIS_H, "HORIZONTAL", 0, "Horizontal", ""},
3246 {SCREEN_AXIS_V, "VERTICAL", 0, "Vertical", ""},
3247 {0, nullptr, 0, nullptr, nullptr},
3248};
3249
3251{
3252 ot->name = "Split Area";
3253 ot->description = "Split selected area into new windows";
3254 ot->idname = "SCREEN_OT_area_split";
3255
3256 ot->exec = area_split_exec;
3258 ot->modal = area_split_modal;
3260
3262
3263 /* flags */
3265
3266 /* rna */
3267 RNA_def_enum(ot->srna, "direction", prop_direction_items, SCREEN_AXIS_H, "Direction", "");
3268 RNA_def_float(ot->srna, "factor", 0.5f, 0.0, 1.0, "Factor", "", 0.0, 1.0);
3270 ot->srna, "cursor", 2, nullptr, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX);
3271}
3272
3274
3275/* -------------------------------------------------------------------- */
3278
3290
3291static bool is_split_edge(const int alignment, const AZEdge edge)
3292{
3293 return ((alignment == RGN_ALIGN_BOTTOM) && (edge == AE_TOP_TO_BOTTOMRIGHT)) ||
3294 ((alignment == RGN_ALIGN_TOP) && (edge == AE_BOTTOM_TO_TOPLEFT)) ||
3295 ((alignment == RGN_ALIGN_LEFT) && (edge == AE_RIGHT_TO_TOPLEFT)) ||
3296 ((alignment == RGN_ALIGN_RIGHT) && (edge == AE_LEFT_TO_TOPRIGHT));
3297}
3298
3299static void region_scale_draw_cb(const wmWindow * /*win*/, void *userdata)
3300{
3301 const wmOperator *op = static_cast<const wmOperator *>(userdata);
3302 RegionMoveData *rmd = static_cast<RegionMoveData *>(op->customdata);
3304}
3305
3307{
3308 RegionMoveData *rmd = static_cast<RegionMoveData *>(op->customdata);
3309 WM_draw_cb_exit(rmd->win, rmd->draw_callback);
3310
3311 MEM_delete(rmd);
3312 op->customdata = nullptr;
3313
3315}
3316
3318{
3319 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
3320
3321 if (event->type != EVT_ACTIONZONE_REGION) {
3322 BKE_report(op->reports, RPT_ERROR, "Can only scale region size from an action zone");
3323 return OPERATOR_CANCELLED;
3324 }
3325
3326 AZone *az = sad->az;
3327
3328 if (az->region) {
3329 RegionMoveData *rmd = MEM_new_zeroed<RegionMoveData>("RegionMoveData");
3330
3331 op->customdata = rmd;
3332
3333 rmd->az = az;
3334 /* special case for region within region - this allows the scale of
3335 * the parent region if the azone edge is not the edge splitting
3336 * both regions */
3337 if ((az->region->alignment & RGN_SPLIT_PREV) && az->region->prev &&
3339 {
3340 rmd->region = az->region->prev;
3341 }
3342 /* Flag to always forward scaling to the previous region. */
3343 else if (az->region->prev && (az->region->alignment & RGN_SPLIT_SCALE_PREV)) {
3344 rmd->region = az->region->prev;
3345 }
3346 else {
3347 rmd->region = az->region;
3348 }
3349 rmd->area = sad->sa1;
3350 rmd->edge = az->edge;
3351 copy_v2_v2_int(rmd->orig_xy, event->xy);
3352 rmd->maxsize = ED_area_max_regionsize(rmd->area, rmd->region, rmd->edge);
3353
3354 /* if not set we do now, otherwise it uses type */
3355 if (rmd->region->sizex == 0) {
3356 rmd->region->sizex = rmd->region->winx;
3357 }
3358 if (rmd->region->sizey == 0) {
3359 rmd->region->sizey = rmd->region->winy;
3360 }
3361
3362 /* Reset our saved widths if the region is hidden.
3363 * Otherwise you can't drag it out a second time. */
3364 if (rmd->region->flag & RGN_FLAG_HIDDEN) {
3366 rmd->region->winx = rmd->region->sizex = 0;
3367 }
3368 else {
3369 rmd->region->winy = rmd->region->sizey = 0;
3370 }
3371 }
3372
3373 /* Now copy to region-move-data. */
3375 rmd->origval = rmd->region->sizex;
3376 }
3377 else {
3378 rmd->origval = rmd->region->sizey;
3379 }
3380
3381 CLAMP(rmd->maxsize, 0, 1000);
3382
3383 rmd->win = CTX_wm_window(C);
3386
3387 /* add temp handler */
3390
3392 }
3393
3394 return OPERATOR_FINISHED;
3395}
3396
3398{
3399 if ((rmd->region->flag & RGN_FLAG_HIDDEN) == 0) {
3400 short *size, maxsize = -1;
3401
3403 size = &rmd->region->sizex;
3404 }
3405 else {
3406 size = &rmd->region->sizey;
3407 }
3408
3409 maxsize = rmd->maxsize - (UI_UNIT_Y / UI_SCALE_FAC);
3410
3411 if (*size > maxsize && maxsize > 0) {
3412 *size = maxsize;
3413 }
3414 }
3415}
3416
3417static void region_scale_toggle_hidden(bContext *C, RegionMoveData *rmd, bool do_fade = false)
3418{
3419 /* hidden areas may have bad 'View2D.cur' value,
3420 * correct before displaying. see #45156 */
3421 if (rmd->region->flag & RGN_FLAG_HIDDEN) {
3423 }
3424
3425 region_toggle_hidden(C, rmd->region, do_fade);
3427
3428 if ((rmd->region->flag & RGN_FLAG_HIDDEN) == 0) {
3429 if (rmd->region->regiontype == RGN_TYPE_HEADER) {
3430 ARegion *region_tool_header = BKE_area_find_region_type(rmd->area, RGN_TYPE_TOOL_HEADER);
3431 if (region_tool_header != nullptr) {
3432 if ((region_tool_header->flag & RGN_FLAG_HIDDEN_BY_USER) == 0 &&
3433 (region_tool_header->flag & RGN_FLAG_HIDDEN) != 0)
3434 {
3435 region_toggle_hidden(C, region_tool_header, do_fade);
3436 }
3437 }
3438 }
3439 }
3440}
3441
3443 const wmEvent *event,
3444 const int size_no_snap,
3445 const float aspect)
3446{
3447 if (!(rmd->region->alignment & RGN_STACK_ON_PREV) && rmd->region->next &&
3449 {
3450 return;
3451 }
3452 const bool axis_x = ELEM(rmd->edge, AE_LEFT_TO_TOPRIGHT, AE_RIGHT_TO_TOPLEFT);
3453 const ARegionType *art = rmd->region->runtime->type;
3454 const int prefsize = axis_x ? art->prefsizex : art->prefsizey;
3455 const int threshold = prefsize + (axis_x ? UI_UNIT_X : UI_UNIT_Y / 4) / aspect;
3456 ARegion *target = nullptr;
3457
3458 if (size_no_snap > threshold && !(rmd->region->flag & RGN_FLAG_HIDDEN) && rmd->region->next &&
3460 {
3461 target = rmd->region->next;
3462 }
3463 else if ((rmd->region->flag & RGN_FLAG_HIDDEN) && (rmd->region->alignment & RGN_STACK_ON_PREV)) {
3464 target = rmd->region->prev;
3465 }
3466
3467 if (target) {
3468 rmd->region = target;
3469 copy_v2_v2_int(rmd->orig_xy, event->xy);
3470 rmd->origval = axis_x ? target->sizex : target->sizey;
3471 }
3472}
3473
3475{
3476 RegionMoveData *rmd = static_cast<RegionMoveData *>(op->customdata);
3477 int delta;
3478
3479 /* execute the events */
3480 switch (event->type) {
3481 case MOUSEMOVE: {
3482 bool size_changed = false;
3483
3485 const float aspect_x = (rmd->region->v2d.flag & V2D_IS_INIT) ?
3486 (BLI_rctf_size_x(&rmd->region->v2d.cur) /
3487 (BLI_rcti_size_x(&rmd->region->v2d.mask) + 1)) :
3488 1.0f;
3489 const int snap_size_threshold_x = (U.widget_unit * 2) / aspect_x;
3490 delta = event->xy[0] - rmd->orig_xy[0];
3491 if (rmd->edge == AE_LEFT_TO_TOPRIGHT) {
3492 delta = -delta;
3493 }
3494
3495 /* region sizes now get multiplied */
3496 delta /= UI_SCALE_FAC;
3497
3498 const int size_no_snap = rmd->origval + delta;
3499 rmd->region->sizex = size_no_snap;
3500 /* Clamp before snapping, so the snapping doesn't use a size that's invalid anyway. It will
3501 * check for and respect the max-width too. */
3502 CLAMP(rmd->region->sizex, 0, rmd->maxsize);
3503
3504 if (rmd->region->runtime->type->snap_size) {
3505 short sizex_test = rmd->region->runtime->type->snap_size(
3506 rmd->region, rmd->region->sizex, 0);
3507 if ((abs(rmd->region->sizex - sizex_test) < snap_size_threshold_x) &&
3508 /* Don't snap to a new size if that would exceed the maximum width. */
3509 sizex_test <= rmd->maxsize)
3510 {
3511 rmd->region->sizex = sizex_test;
3512 }
3513 }
3514 BLI_assert(rmd->region->sizex <= rmd->maxsize);
3515 const int collapse_size = BKE_regiontype_uses_category_tabs(rmd->region->runtime->type) ?
3516 (UI_PANEL_CATEGORY_MIN_WIDTH / aspect_x) * 0.75f :
3517 UI_UNIT_X / aspect_x;
3518 if (size_no_snap < collapse_size) {
3519 rmd->region->sizex = rmd->origval;
3520 if (!(rmd->region->flag & RGN_FLAG_HIDDEN)) {
3522 }
3523 }
3524 else if (rmd->region->flag & RGN_FLAG_HIDDEN) {
3525 region_scale_toggle_hidden(C, rmd, true);
3526 }
3527
3528 /* Hiding/unhiding is handled above, but still fix the size as requested. */
3529 if (rmd->region->flag & RGN_FLAG_NO_USER_RESIZE) {
3530 rmd->region->sizex = rmd->origval;
3531 }
3532
3533 if (rmd->region->sizex != rmd->origval) {
3534 size_changed = true;
3535 }
3536 region_scale_apply_stack(rmd, event, size_no_snap, aspect_x);
3537 }
3538 else {
3539 const float aspect_y = (rmd->region->v2d.flag & V2D_IS_INIT) ?
3540 (BLI_rctf_size_y(&rmd->region->v2d.cur) /
3541 (BLI_rcti_size_y(&rmd->region->v2d.mask) + 1)) :
3542 1.0f;
3543 const int snap_size_threshold_y = (U.widget_unit * 2) / aspect_y;
3544 delta = event->xy[1] - rmd->orig_xy[1];
3545 if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) {
3546 delta = -delta;
3547 }
3548
3549 /* region sizes now get multiplied */
3550 delta /= UI_SCALE_FAC;
3551
3552 const int size_no_snap = rmd->origval + delta;
3553 rmd->region->sizey = size_no_snap;
3554 /* Clamp before snapping, so the snapping doesn't use a size that's invalid anyway. It will
3555 * check for and respect the max-height too. */
3556 CLAMP(rmd->region->sizey, 0, rmd->maxsize);
3557
3558 if (rmd->region->runtime->type->snap_size) {
3559 short sizey_test = rmd->region->runtime->type->snap_size(
3560 rmd->region, rmd->region->sizey, 1);
3561 if ((abs(rmd->region->sizey - sizey_test) < snap_size_threshold_y) &&
3562 /* Don't snap to a new size if that would exceed the maximum height. */
3563 (sizey_test <= rmd->maxsize))
3564 {
3565 rmd->region->sizey = sizey_test;
3566 }
3567 }
3568 BLI_assert(rmd->region->sizey <= rmd->maxsize);
3569
3570 /* NOTE: `UI_UNIT_Y / 4` means you need to drag the footer and execute region
3571 * almost all the way down for it to become hidden, this is done
3572 * otherwise its too easy to do this by accident. */
3573 if (size_no_snap < (UI_UNIT_Y / 4) / aspect_y) {
3574 rmd->region->sizey = rmd->origval;
3575 if (!(rmd->region->flag & RGN_FLAG_HIDDEN)) {
3577 }
3578 }
3579 else if (rmd->region->flag & RGN_FLAG_HIDDEN) {
3580 region_scale_toggle_hidden(C, rmd, true);
3581 }
3582
3583 /* Hiding/unhiding is handled above, but still fix the size as requested. */
3584 if (rmd->region->flag & RGN_FLAG_NO_USER_RESIZE) {
3585 rmd->region->sizey = rmd->origval;
3586 }
3587
3588 if (rmd->region->sizey != rmd->origval) {
3589 size_changed = true;
3590 }
3591
3592 region_scale_apply_stack(rmd, event, size_no_snap, aspect_y);
3593 }
3594 if (size_changed && rmd->region->runtime->type->on_user_resize) {
3595 rmd->region->runtime->type->on_user_resize(rmd->region);
3596 }
3597 if (size_changed) {
3600 }
3601 else {
3603 }
3604 }
3607
3608 break;
3609 }
3610 case LEFTMOUSE:
3611 if (event->val == KM_RELEASE) {
3612 if (len_manhattan_v2v2_int(event->xy, rmd->orig_xy) <= WM_event_drag_threshold(event)) {
3613 if (rmd->region->flag & RGN_FLAG_HIDDEN) {
3614 region_scale_toggle_hidden(C, rmd, true);
3615 }
3616 else if (rmd->region->flag & RGN_FLAG_TOO_SMALL) {
3618 }
3619
3622 }
3623
3624 const float aspect = (rmd->region->v2d.flag & V2D_IS_INIT) ?
3625 (BLI_rctf_size_x(&rmd->region->v2d.cur) /
3626 (BLI_rcti_size_x(&rmd->region->v2d.mask) + 1)) :
3627 1.0f;
3628 if (float(rmd->region->sizex) * aspect > UI_PANEL_CATEGORY_MIN_WIDTH) {
3629 /* Save this as new runtime preferred size. */
3630 rmd->region->runtime->type->prefsizex = int(float(rmd->region->sizex) * aspect);
3631 }
3632
3634
3635 return OPERATOR_FINISHED;
3636 }
3637 break;
3638
3639 case EVT_ESCKEY:
3642 return OPERATOR_CANCELLED;
3643 default: {
3644 break;
3645 }
3646 }
3647
3649}
3650
3651static void region_scale_cancel(bContext * /*C*/, wmOperator *op)
3652{
3654}
3655
3657{
3658 /* identifiers */
3659 ot->name = "Scale Region Size";
3660 ot->description = "Scale selected area";
3661 ot->idname = "SCREEN_OT_region_scale";
3662
3666
3668
3669 /* flags */
3671}
3672
3674
3675/* -------------------------------------------------------------------- */
3678
3682 /* Combined bounds of the four regions. */
3685};
3686
3688{
3689 QuadViewSizeData *qsd = static_cast<QuadViewSizeData *>(op->customdata);
3690 MEM_delete(qsd);
3691 op->customdata = nullptr;
3693}
3694
3696{
3697 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
3698
3699 if (event->type != EVT_ACTIONZONE_REGION_QUAD) {
3700 BKE_report(op->reports, RPT_ERROR, "Can only size Quad View from an action zone");
3701 return OPERATOR_CANCELLED;
3702 }
3703
3704 if (sad->sa1) {
3705 QuadViewSizeData *qsd = MEM_new_zeroed<QuadViewSizeData>("QuadViewSizeData");
3706 op->customdata = qsd;
3707 qsd->area = sad->sa1;
3708 qsd->region = sad->az->region;
3709
3711 for (ARegion &region : sad->sa1->regionbase) {
3712 if (region.alignment == RGN_ALIGN_QSPLIT) {
3713 BLI_rcti_do_minmax_rcti(&qsd->bounds, &region.winrct);
3714 }
3715 }
3716
3717 qsd->original_ratio[0] = float(BLI_rcti_size_x(&sad->az->region->winrct)) /
3719 qsd->original_ratio[1] = float(BLI_rcti_size_y(&sad->az->region->winrct)) /
3721
3723
3724 /* add temp handler */
3727
3729 }
3730
3731 return OPERATOR_FINISHED;
3732}
3733
3735{
3736 ED_workspace_status_text(C, nullptr);
3738}
3739
3741{
3742 QuadViewSizeData *qsd = static_cast<QuadViewSizeData *>(op->customdata);
3743 switch (event->type) {
3744 case MOUSEMOVE: {
3745 if (qsd->region->runtime->type->on_user_resize) {
3746 qsd->region->runtime->type->on_user_resize(qsd->region);
3747 }
3749 float quad_x = float(event->xy[0] - (qsd->bounds.xmin)) /
3750 float(BLI_rcti_size_x(&qsd->bounds) + 1);
3751 float quad_y = float((event->xy[1]) - (qsd->bounds.ymin)) /
3752 float(BLI_rcti_size_y(&qsd->bounds) + 1);
3753
3754 if (event->modifier & KM_CTRL) {
3755 quad_x = round(quad_x * 12.0f) / 12.0f;
3756 quad_y = round(quad_y * 12.0f) / 12.0f;
3757 }
3758
3759 /* Clamp. */
3760 qsd->area->quadview_ratio[0] = std::clamp(quad_x, 0.1f, 0.9f);
3761 qsd->area->quadview_ratio[1] = std::clamp(quad_y, 0.2f, 0.8f);
3762
3763 WorkspaceStatus status(C);
3764 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
3765 status.item_bool(IFACE_("Snap"), event->modifier & KM_CTRL, ICON_EVENT_CTRL);
3766
3769 break;
3770 }
3771 case LEFTMOUSE:
3772 if (event->val == KM_RELEASE) {
3776 return OPERATOR_FINISHED;
3777 }
3778 break;
3779
3780 case EVT_ESCKEY:
3781 qsd->area->quadview_ratio[0] = qsd->original_ratio[0];
3782 qsd->area->quadview_ratio[1] = qsd->original_ratio[1];
3786 return OPERATOR_CANCELLED;
3787 default: {
3788 break;
3789 }
3790 }
3791
3793}
3794
3796{
3797 /* identifiers */
3798 ot->name = "Quad View Resize";
3799 ot->description = "Resize Quad View areas";
3800 ot->idname = "SCREEN_OT_quadview_size";
3801
3806
3807 /* flags */
3809}
3810
3812
3813/* -------------------------------------------------------------------- */
3816
3818 eRegion_Type regiontype)
3819{
3820 return (regiontype == RGN_TYPE_WINDOW &&
3822 (spacetype == SPACE_CLIP && regiontype == RGN_TYPE_PREVIEW);
3823}
3824
3825void ED_areas_do_frame_follow(bContext *C, bool center_view)
3826{
3827 bScreen *screen_ctx = CTX_wm_screen(C);
3828 if (!(screen_ctx->redraws_flag & TIME_FOLLOW)) {
3829 return;
3830 }
3831
3832 const int current_frame = CTX_data_scene(C)->r.cfra;
3834 for (wmWindow &window : wm->windows) {
3835 const bScreen *screen = WM_window_get_active_screen(&window);
3836
3837 for (ScrArea &area : screen->areabase) {
3838 for (ARegion &region : area.regionbase) {
3839 /* Only frame/center the current-frame indicator here if editor type supports it */
3841 eRegion_Type(region.regiontype)))
3842 {
3843 continue;
3844 }
3845
3846 if ((current_frame >= region.v2d.cur.xmin) && (current_frame <= region.v2d.cur.xmax)) {
3847 /* The current-frame indicator is already in view, do nothing. */
3848 continue;
3849 }
3850
3851 const float w = BLI_rctf_size_x(&region.v2d.cur);
3852
3853 if (center_view) {
3854 region.v2d.cur.xmax = current_frame + (w / 2);
3855 region.v2d.cur.xmin = current_frame - (w / 2);
3856 continue;
3857 }
3858 if (current_frame < region.v2d.cur.xmin) {
3859 region.v2d.cur.xmax = current_frame;
3860 region.v2d.cur.xmin = region.v2d.cur.xmax - w;
3861 }
3862 else {
3863 region.v2d.cur.xmin = current_frame;
3864 region.v2d.cur.xmax = region.v2d.cur.xmin + w;
3865 }
3866 }
3867 }
3868 }
3869}
3870
3876static int wrap_frame_in_range(const int frame, const ScenePlaybackRange &range)
3877{
3878 if (range.contains(frame)) {
3879 return frame;
3880 }
3881
3882 const int range_size = range.end_frame - range.start_frame + 1;
3883 const int frames_since_start = frame - range.start_frame;
3884 int offset = frames_since_start % range_size;
3885 if (offset < 0) {
3886 offset += range_size;
3887 }
3888 return range.start_frame + offset;
3889}
3890
3891/* function to be called outside UI context, or for redo */
3893{
3895 if (!scene) {
3896 return OPERATOR_CANCELLED;
3897 }
3898
3899 int delta = RNA_int_get(op->ptr, "delta");
3900
3901 /* In order to jump from e.g. 1.5 to 1 the delta needs to be incremented by 1 since the sub-frame
3902 * is always zeroed. Otherwise it would jump to 0. */
3903 if (delta < 0 && scene->r.subframe > 0) {
3904 delta += 1;
3905 }
3906 scene->r.cfra += delta;
3907
3908 const bool wrap_timeline_navigation = scene->r.flag & SCER_WRAP_TIMELINE_NAVIGATION;
3909 if (wrap_timeline_navigation) {
3910 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(scene);
3911 scene->r.cfra = wrap_frame_in_range(scene->r.cfra, playback_range);
3912 }
3913 else {
3915 }
3916 scene->r.subframe = 0.0f;
3917
3919
3921
3923
3925
3926 return OPERATOR_FINISHED;
3927}
3928
3930{
3931 ot->name = "Frame Offset";
3932 ot->idname = "SCREEN_OT_frame_offset";
3933 ot->description = "Move current frame forward/backward by a given number";
3934
3935 ot->exec = frame_offset_exec;
3936
3939 ot->undo_group = "Frame Change";
3940
3941 /* rna */
3942 RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
3943}
3944
3946
3947/* -------------------------------------------------------------------- */
3950
3951/* function to be called outside UI context, or for redo */
3953{
3955 if (!scene) {
3956 return OPERATOR_CANCELLED;
3957 }
3958 wmTimer *animtimer = CTX_wm_screen(C)->animtimer;
3959 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(scene);
3960
3961 /* Don't change scene->r.cfra directly if animtimer is running as this can cause
3962 * first/last frame not to be actually shown (bad since for example physics
3963 * simulations aren't reset properly).
3964 */
3965 if (animtimer) {
3966 ScreenAnimData *sad = static_cast<ScreenAnimData *>(animtimer->customdata);
3967
3969
3970 if (RNA_boolean_get(op->ptr, "end")) {
3971 sad->nextfra = playback_range.end_frame;
3972 }
3973 else {
3974 sad->nextfra = playback_range.start_frame;
3975 }
3976 }
3977 else {
3978 if (RNA_boolean_get(op->ptr, "end")) {
3979 scene->r.cfra = playback_range.end_frame;
3980 }
3981 else {
3982 scene->r.cfra = playback_range.start_frame;
3983 }
3984 scene->r.subframe = 0.0f;
3985
3987
3989
3991
3993 }
3994
3995 return OPERATOR_FINISHED;
3996}
3997
3999{
4000 ot->name = "Jump to Endpoint";
4001 ot->description = "Jump to first/last frame in frame range";
4002 ot->idname = "SCREEN_OT_frame_jump";
4003
4004 ot->exec = frame_jump_exec;
4005
4008 ot->undo_group = "Frame Change";
4009
4010 /* rna */
4012 ot->srna, "end", false, "Last Frame", "Jump to the last frame of the frame range");
4013}
4014
4016
4017/* -------------------------------------------------------------------- */
4020
4021/* function to be called outside UI context, or for redo */
4023{
4025 const bool backward = RNA_boolean_get(op->ptr, "backward");
4026
4027 if (scene == nullptr) {
4028 return OPERATOR_CANCELLED;
4029 }
4030
4031 float delta = scene->r.time_jump_delta;
4032
4033 if (scene->r.time_jump_unit == SCE_TIME_JUMP_SECOND) {
4034 delta *= scene->r.frs_sec / scene->r.frs_sec_base;
4035 }
4036
4037 int step = int(delta);
4038 float fraction = delta - step;
4039 if (!(scene->r.flag & SCER_SHOW_SUBFRAME)) {
4040 step = round_fl_to_int(delta);
4041 fraction = 0.0f;
4042 }
4043
4044 if (backward) {
4045 scene->r.cfra -= step;
4046 scene->r.subframe -= fraction;
4047 }
4048 else {
4049 scene->r.cfra += step;
4050 scene->r.subframe += fraction;
4051 }
4052
4053 /* Check if subframe has a non-fractional component, and roll that into cfra. */
4054 if (scene->r.subframe < 0.0f || scene->r.subframe >= 1.0f) {
4055 const float subframe_offset = floorf(scene->r.subframe);
4056 const int frame_offset = int(subframe_offset);
4057 scene->r.cfra += frame_offset;
4058 scene->r.subframe -= subframe_offset;
4059 }
4060
4061 const bool wrap_timeline_navigation = scene->r.flag & SCER_WRAP_TIMELINE_NAVIGATION;
4062 if (wrap_timeline_navigation) {
4063 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(scene);
4064 scene->r.cfra = wrap_frame_in_range(scene->r.cfra, playback_range);
4065 }
4066 else {
4068 }
4069
4072
4074
4076
4077 return OPERATOR_FINISHED;
4078}
4079
4081{
4082 ot->name = "Jump Time by Delta";
4083 ot->description = "Jump forward/backward by a given number of frames or seconds";
4084 ot->idname = "SCREEN_OT_time_jump";
4085
4087
4090 ot->undo_group = "Frame Change";
4091
4092 /* rna */
4093 RNA_def_boolean(ot->srna, "backward", false, "Backwards", "Jump backwards in time");
4094}
4095
4097
4098/* -------------------------------------------------------------------- */
4101
4103{
4104 bAnimContext ac;
4105
4106 if (ANIM_animdata_get_context(&C, &ac) == 0) {
4107 return;
4108 }
4110 summary_to_keylist(&ac, &keylist, 0, {-FLT_MAX, FLT_MAX});
4111}
4112
4114{
4115 bAnimContext ac;
4116
4117 if (ANIM_animdata_get_context(&C, &ac) == 0) {
4118 return;
4119 }
4120
4121 ListBaseT<bAnimListElem> anim_data = ed::graph::get_editable_fcurves(ac);
4122
4123 for (bAnimListElem &ale : anim_data) {
4124 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
4125 if (!fcu->bezt) {
4126 continue;
4127 }
4128
4129 const bool use_nla_mapping = ANIM_nla_mapping_allowed(&ale);
4130 fcurve_to_keylist(ale.adt, fcu, &keylist, 0, {-FLT_MAX, FLT_MAX}, use_nla_mapping);
4131 }
4132
4133 ANIM_animdata_freelist(&anim_data);
4134}
4135
4136/* This is used for all editors where a more specific function isn't implemented. */
4138{
4139 bDopeSheet ads = {nullptr};
4140
4141 /* Speed up dummy dope-sheet context with flags to perform necessary filtering. */
4142 if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
4143 /* Only selected channels are included. */
4145 }
4146
4147 /* populate tree with keyframe nodes */
4148 scene_to_keylist(&ads, scene, &keylist, 0, {-FLT_MAX, FLT_MAX});
4149
4150 /* Return early when invoked from sequencer with sequencer scene. Objects may belong to different
4151 * scenes and are irrelevant. */
4152 if (CTX_wm_space_seq(&C) != nullptr && scene == CTX_data_sequencer_scene(&C)) {
4153 return;
4154 }
4155
4157 if (ob) {
4158 ob_to_keylist(&ads, ob, &keylist, 0, {-FLT_MAX, FLT_MAX});
4159
4160 if (ob->type == OB_GREASE_PENCIL) {
4161 const bool active_layer_only = !(scene->flag & SCE_KEYS_NO_SELONLY);
4163 nullptr, id_cast<const GreasePencil *>(ob->data), &keylist, 0, active_layer_only);
4164 }
4165 }
4166
4167 {
4169 if (mask) {
4171 mask_to_keylist(&ads, masklay, &keylist);
4172 }
4173 }
4174}
4175
4176template<typename KeyColumnIterator>
4178 const ScenePlaybackRange playback_range,
4179 KeyColumnIterator key_columns)
4180{
4181 for (const ActKeyColumn &ak_wrap : key_columns) {
4182 if (playback_range.contains(ak_wrap.cfra)) {
4183 BKE_scene_frame_set(scene, ak_wrap.cfra);
4184 return true;
4185 }
4186 }
4187 return false;
4188}
4189
4190/* function to be called outside UI context, or for redo */
4192{
4194 const bool next = RNA_boolean_get(op->ptr, "next");
4195 bool done = false;
4196
4197 /* sanity checks */
4198 if (scene == nullptr) {
4199 return OPERATOR_CANCELLED;
4200 }
4201
4202 AnimKeylist *keylist = ED_keylist_create();
4203
4204 ScrArea *area = CTX_wm_area(C);
4205 switch (area ? eSpace_Type(area->spacetype) : SPACE_EMPTY) {
4206 case SPACE_ACTION: {
4207 keylist_from_dopesheet(*C, *keylist);
4208 break;
4209 }
4210
4211 case SPACE_GRAPH:
4212 keylist_from_graph_editor(*C, *keylist);
4213 break;
4214
4215 default:
4216 keylist_fallback_for_keyframe_jump(*C, scene, *keylist);
4217 break;
4218 }
4219
4220 /* Initialize binary-tree-list for getting keyframes. */
4222
4223 const float cfra = BKE_scene_frame_get(scene);
4224
4225 const bool wrap_timeline_navigation = scene->r.flag & SCER_WRAP_TIMELINE_NAVIGATION;
4226 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(scene);
4227
4228 /* Find matching keyframe in the right direction. */
4229 const ActKeyColumn *ak;
4230
4231 if (next) {
4232 ak = ED_keylist_find_next(keylist, cfra);
4233 while ((ak != nullptr) && (done == false)) {
4234 if (wrap_timeline_navigation) {
4235 /* Ignore keyframes before playback_range. */
4236 if (ak->cfra < playback_range.start_frame) {
4237 ak = ak->next;
4238 continue;
4239 }
4240 /* No more keyframes within playback_range. */
4241 if (ak->cfra > playback_range.end_frame) {
4242 break;
4243 }
4244 }
4245
4246 if (cfra < ak->cfra) {
4247 BKE_scene_frame_set(scene, ak->cfra);
4248 done = true;
4249 }
4250 else {
4251 ak = ak->next;
4252 }
4253 }
4254
4255 /* Wrap around to the beginning of the frame range. */
4256 if (!done && wrap_timeline_navigation) {
4258 scene, playback_range, *ED_keylist_listbase(keylist));
4259 }
4260 }
4261
4262 else {
4263 ak = ED_keylist_find_prev(keylist, cfra);
4264 while ((ak != nullptr) && (done == false)) {
4265 if (wrap_timeline_navigation) {
4266 /* Ignore keyframes after playback_range. */
4267 if (ak->cfra > playback_range.end_frame) {
4268 ak = ak->prev;
4269 continue;
4270 }
4271 /* No more keyframes within playback_range. */
4272 if (ak->cfra < playback_range.start_frame) {
4273 break;
4274 }
4275 }
4276
4277 if (cfra > ak->cfra) {
4278 BKE_scene_frame_set(scene, ak->cfra);
4279 done = true;
4280 }
4281 else {
4282 ak = ak->prev;
4283 }
4284 }
4285
4286 /* Wrap around to the end of the frame range. */
4287 if (!done && wrap_timeline_navigation) {
4289 scene, playback_range, ED_keylist_listbase(keylist)->items_reversed());
4290 }
4291 }
4292
4293 /* free temp stuff */
4294 ED_keylist_free(keylist);
4295
4296 /* any success? */
4297 if (done == false) {
4298 BKE_report(op->reports, RPT_INFO, "No more keyframes to jump to in this direction");
4299
4300 return OPERATOR_CANCELLED;
4301 }
4302
4305
4307
4309
4310 return OPERATOR_FINISHED;
4311}
4312
4314{
4316}
4317
4319{
4320 ot->name = "Jump to Keyframe";
4321 ot->description = "Jump to previous/next keyframe";
4322 ot->idname = "SCREEN_OT_keyframe_jump";
4323
4325
4328 ot->undo_group = "Frame Change";
4329
4330 /* properties */
4331 RNA_def_boolean(ot->srna, "next", true, "Next Keyframe", "");
4332}
4333
4335
4336/* -------------------------------------------------------------------- */
4339
4344
4345static std::optional<int> find_marker_in_direction(
4346 const ListBaseT<TimeMarker> &markers,
4347 const int from_frame,
4348 const SearchDirection direction,
4349 const std::optional<ScenePlaybackRange> playback_range)
4350{
4351 std::optional<int> closest;
4352 for (const TimeMarker &marker : markers) {
4353 /* Ignore markers outside the playback range, when one is provided. */
4354 if (playback_range && !playback_range->contains(marker.frame)) {
4355 continue;
4356 }
4357
4358 if (direction == SearchDirection::FORWARDS) {
4359 /* Ignore frames at or before from_frame. */
4360 if (marker.frame <= from_frame) {
4361 continue;
4362 }
4363 /* Keep the earliest marker's frame. */
4364 closest = std::min(closest.value_or(marker.frame), marker.frame);
4365 }
4366 else {
4367 /* Ignore frames at or after from_frame. */
4368 if (marker.frame >= from_frame) {
4369 continue;
4370 }
4371 /* Keep the latest marker's frame. */
4372 closest = std::max(closest.value_or(marker.frame), marker.frame);
4373 }
4374 }
4375
4376 return closest;
4377}
4378
4379/* function to be called outside UI context, or for redo */
4381{
4383 if (!scene) {
4384 return OPERATOR_CANCELLED;
4385 }
4386
4387 std::optional<ScenePlaybackRange> playback_range;
4388 if (scene->r.flag & SCER_WRAP_TIMELINE_NAVIGATION) {
4389 playback_range = BKE_scene_get_playback_range(scene);
4390 }
4391
4392 const bool next = RNA_boolean_get(op->ptr, "next");
4394
4395 ListBaseT<TimeMarker> *markers = ED_scene_markers_get(C, scene);
4396 if (!markers) {
4397 BKE_report(op->reports, RPT_INFO, "No markers to jump to");
4398 return OPERATOR_CANCELLED;
4399 }
4400
4401 /* Find matching marker in the right direction. */
4402 std::optional<int> frame_to_jump_to = find_marker_in_direction(
4403 *markers, scene->r.cfra, direction, playback_range);
4404
4405 /* Wrap around playback range and try to look for markers again.
4406 * Anchor just outside the range, so a marker sitting on the boundary still passes the
4407 * strict comparison in the scan. */
4408 if (!frame_to_jump_to && playback_range) {
4409 const int from_frame = direction == SearchDirection::FORWARDS ?
4410 (playback_range->start_frame - 1) :
4411 (playback_range->end_frame + 1);
4412 frame_to_jump_to = find_marker_in_direction(*markers, from_frame, direction, playback_range);
4413 }
4414
4415 /* any success? */
4416 if (!frame_to_jump_to) {
4417 BKE_report(op->reports, RPT_INFO, "No more markers to jump to in this direction");
4418
4419 return OPERATOR_CANCELLED;
4420 }
4421
4422 scene->r.cfra = *frame_to_jump_to;
4423 scene->r.subframe = 0.0f;
4424
4426
4428
4430
4432
4433 return OPERATOR_FINISHED;
4434}
4435
4437{
4438 ot->name = "Jump to Marker";
4439 ot->description = "Jump to previous/next marker";
4440 ot->idname = "SCREEN_OT_marker_jump";
4441
4442 ot->exec = marker_jump_exec;
4443
4446 ot->undo_group = "Frame Change";
4447
4448 /* properties */
4449 RNA_def_boolean(ot->srna, "next", true, "Next Marker", "");
4450}
4451
4453
4454/* -------------------------------------------------------------------- */
4457
4458/* function to be called outside UI context, or for redo */
4460{
4461 WorkSpace *workspace = CTX_wm_workspace(C);
4462 int delta = RNA_int_get(op->ptr, "delta");
4463 if (delta == 0) [[unlikely]] { /* Avoids an assert which would step next anyway. */
4464 delta = 1;
4465 }
4466 if (ED_workspace_layout_cycle(workspace, delta, C)) {
4467 return OPERATOR_FINISHED;
4468 }
4469
4470 return OPERATOR_CANCELLED;
4471}
4472
4474{
4475 ot->name = "Set Screen";
4476 ot->description = "Cycle through available screens";
4477 ot->idname = "SCREEN_OT_screen_set";
4478
4479 ot->exec = screen_set_exec;
4481
4482 /* rna */
4483 RNA_def_int(ot->srna, "delta", 1, -1, 1, "Delta", "", -1, 1);
4484}
4485
4487
4488/* -------------------------------------------------------------------- */
4491
4492/* function to be called outside UI context, or for redo */
4494{
4495 bScreen *screen = CTX_wm_screen(C);
4496 ScrArea *area = nullptr;
4497 const bool hide_panels = RNA_boolean_get(op->ptr, "use_hide_panels");
4498
4499 BLI_assert(!screen->temp);
4500
4501 /* search current screen for 'full-screen' areas */
4502 /* prevents restoring info header, when mouse is over it */
4503 for (ScrArea &area_iter : screen->areabase) {
4504 if (area_iter.full) {
4505 area = &area_iter;
4506 break;
4507 }
4508 }
4509
4510 if (area == nullptr) {
4511 area = CTX_wm_area(C);
4512 }
4513
4514 if (hide_panels) {
4515 if (!ELEM(screen->state, SCREENNORMAL, SCREENFULL)) {
4516 return OPERATOR_CANCELLED;
4517 }
4519 }
4520 else {
4521 if (!ELEM(screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
4522 return OPERATOR_CANCELLED;
4523 }
4524 if (screen->areabase.is_single() && screen->state == SCREENNORMAL) {
4525 /* SCREENMAXIMIZED is not useful when a singleton. #144740. */
4526 return OPERATOR_CANCELLED;
4527 }
4529 }
4530
4531 return OPERATOR_FINISHED;
4532}
4533
4535{
4536 const wmWindow *win = CTX_wm_window(C);
4537 const bScreen *screen = CTX_wm_screen(C);
4538 const ScrArea *area = CTX_wm_area(C);
4540 return ED_operator_areaactive(C) &&
4541 /* Don't allow maximizing global areas but allow minimizing from them. */
4542 ((screen->state != SCREENNORMAL) || !ED_area_is_global(area)) &&
4543 /* Don't change temporary screens. */
4545 /* Don't maximize when dragging. */
4546 wm->runtime->drags.is_empty();
4547}
4548
4550{
4551 PropertyRNA *prop;
4552
4553 ot->name = "Toggle Maximize Area";
4554 ot->description = "Toggle display selected area as fullscreen/maximized";
4555 ot->idname = "SCREEN_OT_screen_full_area";
4556
4559 ot->flag = 0;
4560
4561 prop = RNA_def_boolean(
4562 ot->srna, "use_hide_panels", false, "Hide Panels", "Hide all the panels (Focus Mode)");
4564}
4565
4567
4568/* -------------------------------------------------------------------- */
4571
4572/* operator state vars used:
4573 * x1, y1 mouse coord in first area, which will disappear
4574 * x2, y2 mouse coord in 2nd area, which will become joined
4575 *
4576 * functions:
4577 *
4578 * init() find edge based on state vars
4579 * test if the edge divides two areas,
4580 * store active and nonactive area,
4581 *
4582 * apply() do the actual join
4583 *
4584 * exit() cleanup, send notifier
4585 *
4586 * callbacks:
4587 *
4588 * exec() calls init, apply, exit
4589 *
4590 * invoke() sets mouse coords in x,y
4591 * call init()
4592 * add modal handler
4593 *
4594 * modal() accept modal events while doing it
4595 * call apply() with active window and nonactive window
4596 * call exit() and remove handler when LMB confirm
4597 */
4598
4600 ScrArea *sa1; /* Potential source area (kept). */
4601 ScrArea *sa2; /* Potential target area (removed or reduced). */
4602 eScreenDir dir; /* Direction of potential join. */
4603 eScreenAxis split_dir; /* Direction of split within the source area. */
4604 AreaDockTarget dock_target; /* Position within target we are pointing to. */
4605 float factor; /* dock target size can vary. */
4606 int start_x, start_y; /* Starting mouse position. */
4607 int current_x, current_y; /* Current mouse position. */
4608 float split_fac; /* Split factor in split_dir direction. */
4609 wmWindow *win1; /* Window of source area. */
4610 wmWindow *win2; /* Window of the target area. */
4611 bScreen *screen; /* Screen of the source area. */
4612 double start_time; /* Start time of animation. */
4613 double end_time; /* End time of animation. */
4614 wmWindow *draw_dock_win; /* Window getting docking highlight. */
4615 bool close_win; /* Close the source window when done. */
4616 void *draw_callback; /* call #screen_draw_join_highlight */
4617 void *draw_dock_callback; /* call #screen_draw_dock_highlight, overlay on draw_dock_win. */
4618};
4619
4620static void area_join_draw_cb(const wmWindow *win, void *userdata)
4621{
4622 const wmOperator *op = static_cast<const wmOperator *>(userdata);
4623 sAreaJoinData *sd = static_cast<sAreaJoinData *>(op->customdata);
4624 if (!sd || !sd->sa1) {
4625 return;
4626 }
4627
4628 float factor = 1.0f;
4629 const double now = BLI_time_now_seconds();
4630 if (now < sd->end_time) {
4631 factor = pow((now - sd->start_time) / (sd->end_time - sd->start_time), 2);
4632 sd->screen->do_refresh = true;
4633 }
4634
4635 if (sd->sa1 == sd->sa2 && sd->split_fac > 0.0f) {
4637 }
4638 else if (sd->sa2 && (sd->sa1 != sd->sa2)) {
4639 screen_draw_join_highlight(win, sd->sa1, sd->sa2, sd->dir, factor);
4640 }
4641}
4642
4643static void area_join_dock_cb(const wmWindow *win, void *userdata)
4644{
4645 const wmOperator *op = static_cast<wmOperator *>(userdata);
4646 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4647 if (!jd || !jd->sa2 || jd->dir != SCREEN_DIR_NONE || jd->sa1 == jd->sa2) {
4648 return;
4649 }
4650
4651 float factor = 1.0f;
4652 const double now = BLI_time_now_seconds();
4653 if (now < jd->end_time) {
4654 factor = pow((now - jd->start_time) / (jd->end_time - jd->start_time), 2);
4655 jd->screen->do_refresh = true;
4656 }
4657
4659 win, jd->sa1, jd->sa2, jd->dock_target, jd->factor, jd->current_x, jd->current_y, factor);
4660}
4661
4663{
4664 if (jd->sa2 && jd->win2 && jd->win2 != jd->draw_dock_win) {
4665 /* Change of highlight window. */
4666 if (jd->draw_dock_callback) {
4668 /* Refresh the entire window. */
4671 {
4672 ED_area_tag_redraw(area);
4673 }
4674 }
4675 if (jd->win2) {
4676 jd->draw_dock_win = jd->win2;
4678 }
4679 }
4680}
4681
4682/* validate selection inside screen, set variables OK */
4683/* return false: init failed */
4684static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *sa2)
4685{
4686 if (sa1 == nullptr && sa2 == nullptr) {
4687 /* Get areas from cursor location if not specified. */
4688 PropertyRNA *prop;
4689 int cursor[2];
4690
4691 prop = RNA_struct_find_property(op->ptr, "source_xy");
4692 if (RNA_property_is_set(op->ptr, prop)) {
4693 RNA_property_int_get_array(op->ptr, prop, cursor);
4695 }
4696
4697 prop = RNA_struct_find_property(op->ptr, "target_xy");
4698 if (RNA_property_is_set(op->ptr, prop)) {
4699 RNA_property_int_get_array(op->ptr, prop, cursor);
4701 }
4702 }
4703 if (sa1 == nullptr) {
4704 return false;
4705 }
4706
4707 sAreaJoinData *jd = MEM_new_zeroed<sAreaJoinData>("op_area_join");
4708 jd->sa1 = sa1;
4709 jd->sa2 = sa2;
4710 jd->dir = area_getorientation(sa1, sa2);
4713 jd->screen = CTX_wm_screen(C);
4716
4717 op->customdata = jd;
4718 return true;
4719}
4720
4721/* apply the join of the areas (space types) */
4723{
4724 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4725 if (!jd || (jd->dir == SCREEN_DIR_NONE)) {
4726 return false;
4727 }
4728
4729 bScreen *screen = CTX_wm_screen(C);
4730
4731 /* Rect of the combined areas. */
4732 const bool vertical = SCREEN_DIR_IS_VERTICAL(jd->dir);
4733 rcti combined{};
4734 combined.xmin = vertical ? std::max(jd->sa1->totrct.xmin, jd->sa2->totrct.xmin) :
4735 std::min(jd->sa1->totrct.xmin, jd->sa2->totrct.xmin);
4736 combined.xmax = vertical ? std::min(jd->sa1->totrct.xmax, jd->sa2->totrct.xmax) :
4737 std::max(jd->sa1->totrct.xmax, jd->sa2->totrct.xmax);
4738 combined.ymin = vertical ? std::min(jd->sa1->totrct.ymin, jd->sa2->totrct.ymin) :
4739 std::max(jd->sa1->totrct.ymin, jd->sa2->totrct.ymin);
4740 combined.ymax = vertical ? std::max(jd->sa1->totrct.ymax, jd->sa2->totrct.ymax) :
4741 std::min(jd->sa1->totrct.ymax, jd->sa2->totrct.ymax);
4742 float inner[4] = {1.0f, 1.0f, 1.0f, 0.1f};
4743 float outline[4] = {1.0f, 1.0f, 1.0f, 0.3f};
4745 CTX_wm_window(C), screen, &combined, inner, outline, AREA_JOIN_FADEOUT);
4746
4747 if (!screen_area_join(C, op->reports, screen, jd->sa1, jd->sa2)) {
4748 return false;
4749 }
4750 if (CTX_wm_area(C) == jd->sa2) {
4751 CTX_wm_area_set(C, nullptr);
4752 CTX_wm_region_set(C, nullptr);
4753 }
4754
4755 if (screen->areabase.is_single()) {
4756 /* Areas reduced to just one, so show nicer title. */
4758 }
4759
4761
4762 return true;
4763}
4764
4765/* finish operation */
4767{
4768 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4769
4770 if (jd) {
4771 if (jd->draw_callback) {
4773 }
4774 if (jd->draw_dock_callback) {
4776 }
4777
4778 MEM_delete(jd);
4779 op->customdata = nullptr;
4780 }
4781
4782 /* this makes sure aligned edges will result in aligned grabbing */
4786
4787 ED_workspace_status_text(C, nullptr);
4788
4790}
4791
4793{
4794 if (!area_join_init(C, op, nullptr, nullptr)) {
4795 return OPERATOR_CANCELLED;
4796 }
4797
4798 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4799
4800 if (jd->sa2 == nullptr || area_getorientation(jd->sa1, jd->sa2) == SCREEN_DIR_NONE) {
4801 return OPERATOR_CANCELLED;
4802 }
4803
4805
4806 area_join_apply(C, op);
4807 area_join_exit(C, op);
4809
4810 return OPERATOR_FINISHED;
4811}
4812
4813static void area_join_update_data(bContext *C, sAreaJoinData *jd, const wmEvent *event);
4814static int area_join_cursor(sAreaJoinData *jd, const wmEvent *event);
4815
4816/* interaction callback */
4818{
4819 if (event->type == EVT_ACTIONZONE_AREA) {
4820 sActionzoneData *sad = static_cast<sActionzoneData *>(event->customdata);
4821
4822 if (sad == nullptr || sad->modifier > 0 || sad->sa1 == nullptr) {
4823 return OPERATOR_PASS_THROUGH;
4824 }
4825
4826 if (!area_join_init(C, op, sad->sa1, sad->sa2)) {
4827 return OPERATOR_CANCELLED;
4828 }
4829
4830 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4831 jd->start_x = sad->x;
4832 jd->start_y = sad->y;
4834
4837 }
4838
4839 /* Launched from menu item or keyboard shortcut. */
4840 if (!area_join_init(C, op, nullptr, nullptr)) {
4841 ScrArea *sa1 = CTX_wm_area(C);
4842 if (!sa1 || ED_area_is_global(sa1) || !area_join_init(C, op, sa1, nullptr)) {
4843 return OPERATOR_CANCELLED;
4844 }
4845 }
4846 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4847 jd->sa2 = jd->sa1;
4848 jd->start_x = jd->sa1->totrct.xmin;
4849 jd->start_y = jd->sa1->totrct.ymax;
4850 jd->current_x = event->xy[0];
4851 jd->current_y = event->xy[1];
4853 WM_cursor_set(jd->win1, area_join_cursor(jd, event));
4854 area_join_update_data(C, jd, event);
4859}
4860
4861/* Apply the docking of the area. */
4863{
4864 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
4865
4866 int offset1;
4867 int offset2;
4868 area_getoffsets(jd->sa1, jd->sa2, area_getorientation(jd->sa1, jd->sa2), &offset1, &offset2);
4869
4870 /* Check before making changes. */
4871 bool aligned_neighbors = (offset1 == 0 && offset2 == 0);
4872 bool same_area = (jd->sa1 == jd->sa2);
4873
4874 if (!(jd->dock_target == AreaDockTarget::Center)) {
4878
4879 float fac = jd->factor;
4881 fac = 1.0f - fac;
4882 }
4883
4884 ScrArea *newa = area_split(jd->win2, WM_window_get_active_screen(jd->win2), jd->sa2, dir, fac);
4885
4886 if (jd->factor <= 0.5f) {
4887 jd->sa2 = newa;
4888 }
4889 else {
4890 /* Force full rebuild. #130732 */
4891 ED_area_tag_redraw(newa);
4892 }
4893 }
4894
4895 if (same_area) {
4897 return;
4898 }
4899
4900 float inner[4] = {1.0f, 1.0f, 1.0f, 0.15f};
4901 float outline[4] = {1.0f, 1.0f, 1.0f, 0.4f};
4905 jd->win2, CTX_wm_screen(C), &jd->sa2->totrct, inner, outline, AREA_DOCK_FADEOUT);
4906
4907 if (!aligned_neighbors || !screen_area_join(C, op->reports, CTX_wm_screen(C), jd->sa1, jd->sa2))
4908 {
4909 ED_area_swapspace(C, jd->sa2, jd->sa1);
4911 jd->win1->global_areas.areabase.is_empty())
4912 {
4913 jd->close_win = true;
4914 /* Clear the active region in each screen, otherwise they are pointing
4915 * at incorrect regions and will cause errors in uiTemplateInputStatus. */
4918 }
4919 else {
4920 float inner[4] = {0.0f, 0.0f, 0.0f, 0.7f};
4922 jd->win1, CTX_wm_screen(C), &jd->sa1->totrct, inner, nullptr, AREA_CLOSE_FADEOUT);
4924 }
4925 }
4926
4927 if (jd && jd->sa2 == CTX_wm_area(C)) {
4928 CTX_wm_area_set(C, nullptr);
4929 CTX_wm_region_set(C, nullptr);
4930 }
4931}
4932
4933static int area_join_cursor(sAreaJoinData *jd, const wmEvent *event)
4934{
4935 if (!jd->sa2 && jd->dock_target == AreaDockTarget::None) {
4936 /* Mouse outside window, so can open new window. */
4937 if (event->xy[0] < 0 || event->xy[0] > jd->win1->sizex || event->xy[1] < 1 ||
4938 event->xy[1] > jd->win1->sizey)
4939 {
4940 return WM_CURSOR_PICK_AREA;
4941 }
4942 return WM_CURSOR_STOP;
4943 }
4944
4945 if (jd->win2 && jd->win2->workspace_hook) {
4947 if (screen && screen->temp) {
4948 return WM_CURSOR_STOP;
4949 }
4950 }
4951
4952 if (jd->sa1 && jd->sa1 == jd->sa2) {
4953 if (jd->split_fac >= 0.0001f) {
4954 /* Mouse inside source area, so allow splitting. */
4956 }
4957 return WM_CURSOR_EDIT;
4958 }
4959
4960 if (jd->dir != SCREEN_DIR_NONE) {
4961 /* Joining */
4962 switch (jd->dir) {
4963 case SCREEN_DIR_N:
4964 return WM_CURSOR_N_ARROW;
4965 break;
4966 case SCREEN_DIR_S:
4967 return WM_CURSOR_S_ARROW;
4968 break;
4969 case SCREEN_DIR_W:
4970 return WM_CURSOR_W_ARROW;
4971 break;
4972 default:
4973 return WM_CURSOR_E_ARROW;
4974 }
4975 }
4976
4977 if (jd->dir != SCREEN_DIR_NONE || jd->dock_target != AreaDockTarget::None) {
4978#if defined(__APPLE__)
4979 return WM_CURSOR_HAND_CLOSED;
4980#else
4981 return WM_CURSOR_MOVE;
4982#endif
4983 }
4984
4985 return WM_CURSOR_PICK_AREA;
4986}
4987
4988static float area_docking_snap(const float pos, const wmEvent *event)
4989{
4990 const bool alt = event->modifier & KM_ALT;
4991 const bool ctrl = event->modifier & KM_CTRL;
4992 const float accel = (alt || ctrl) ? 2.5f : 2.0;
4993
4994 float factor = pos * accel;
4995
4996 if (!alt) {
4997 if (factor >= 0.4375f && factor < 0.5f) {
4998 factor = 0.499999f;
4999 }
5000 else if (factor >= 0.5f && factor < 0.5625f) {
5001 factor = 0.500001f;
5002 }
5003 }
5004
5005 if (ctrl) {
5006 if (factor < 0.1875f) {
5007 factor = 0.125f;
5008 }
5009 else if (factor >= 0.1875f && factor < 0.3125f) {
5010 factor = 0.25f;
5011 }
5012 else if (factor >= 0.3125f && factor < 0.4375f) {
5013 factor = 0.375f;
5014 }
5015 else if (factor >= 0.5625f && factor < 0.6875f) {
5016 factor = 0.625f;
5017 }
5018 else if (factor >= 0.6875f && factor < 0.8125f) {
5019 factor = 0.75f;
5020 }
5021 else if (factor > 0.8125f) {
5022 factor = 0.875f;
5023 }
5024 }
5025
5026 return factor;
5027}
5028
5030{
5031 if (!jd->sa2 || !jd->win2) {
5032 return AreaDockTarget::None;
5033 }
5034
5035 if (jd->sa1 == jd->sa2) {
5036 return AreaDockTarget::None;
5037 }
5038
5039 if (jd->win2 && jd->win2->workspace_hook) {
5041 if (screen && screen->temp) {
5042 return AreaDockTarget::None;
5043 }
5044 }
5045
5046 /* Convert to local coordinates in sa2. */
5047 int win1_posx = jd->win1->posx;
5048 int win1_posy = jd->win1->posy;
5049 int win2_posx = jd->win2->posx;
5050 int win2_posy = jd->win2->posy;
5051 WM_window_native_pixel_coords(jd->win1, &win1_posx, &win1_posy);
5052 WM_window_native_pixel_coords(jd->win2, &win2_posx, &win2_posy);
5053
5054 const int x = event->xy[0] + win1_posx - win2_posx - jd->sa2->totrct.xmin;
5055 const int y = event->xy[1] + win1_posy - win2_posy - jd->sa2->totrct.ymin;
5056
5057 jd->current_x = x + jd->sa2->totrct.xmin;
5058 jd->current_y = y + jd->sa2->totrct.ymin;
5059
5060 const float fac_x = float(x) / float(jd->sa2->winx);
5061 const float fac_y = float(y) / float(jd->sa2->winy);
5062 const int min_x = 2 * AREAMINX * UI_SCALE_FAC;
5063 const int min_y = 2 * HEADERY * UI_SCALE_FAC;
5064
5065 if (ELEM(jd->dir, SCREEN_DIR_N, SCREEN_DIR_S)) {
5066 /* Up or Down to immediate neighbor. */
5067 if (event->xy[0] <= jd->sa1->totrct.xmax && event->xy[0] >= jd->sa1->totrct.xmin) {
5068 const int join_y = std::min(jd->sa2->winy * 0.25f, 5 * HEADERY * UI_SCALE_FAC);
5069 if (jd->sa2->winy < min_y || (jd->dir == SCREEN_DIR_N && y < join_y) ||
5070 (jd->dir == SCREEN_DIR_S && (jd->sa2->winy - y) < join_y))
5071 {
5072 return AreaDockTarget::None;
5073 }
5074 }
5075 }
5076
5077 if (ELEM(jd->dir, SCREEN_DIR_W, SCREEN_DIR_E)) {
5078 /* Left or Right to immediate neighbor. */
5079 if (event->xy[1] <= jd->sa1->totrct.ymax && event->xy[1] >= jd->sa1->totrct.ymin) {
5080 const int join_x = std::min(jd->sa2->winx * 0.25f, 5 * AREAMINX * UI_SCALE_FAC);
5081 if (jd->sa2->winx < min_x || (jd->dir == SCREEN_DIR_W && (jd->sa2->winx - x) < join_x) ||
5082 (jd->dir == SCREEN_DIR_E && x < join_x))
5083 {
5084 return AreaDockTarget::None;
5085 }
5086 }
5087 }
5088
5089 /* If we've made it here, then there can be no joining possible. */
5090 jd->dir = SCREEN_DIR_NONE;
5091 jd->factor = 0.5f;
5092
5093 const float min_fac_x = 1.5f * AREAMINX * UI_SCALE_FAC / float(jd->sa2->winx);
5094 const float min_fac_y = 1.5f * HEADERY * UI_SCALE_FAC / float(jd->sa2->winy);
5095
5096 /* if the area is narrow then there are only two docking targets. */
5097 if (jd->sa2->winx < (min_x * 3)) {
5098 if (fac_y > 0.4f && fac_y < 0.6f) {
5100 }
5101 if (float(y) > float(jd->sa2->winy) / 2.0f) {
5102 jd->factor = area_docking_snap(std::max(1.0f - fac_y, min_fac_y), event);
5103 return AreaDockTarget::Top;
5104 }
5105 jd->factor = area_docking_snap(std::max(fac_y, min_fac_y), event);
5107 }
5108 if (jd->sa2->winy < (min_y * 3)) {
5109 if (fac_x > 0.4f && fac_x < 0.6f) {
5111 }
5112 if (float(x) > float(jd->sa2->winx) / 2.0f) {
5113 jd->factor = area_docking_snap(std::max(1.0f - fac_x, min_fac_x), event);
5114 return AreaDockTarget::Right;
5115 }
5116 jd->factor = area_docking_snap(std::max(fac_x, min_fac_x), event);
5117 return AreaDockTarget::Left;
5118 }
5119
5120 /* Are we in the center? But not in same area! */
5121 if (fac_x > 0.4f && fac_x < 0.6f && fac_y > 0.4f && fac_y < 0.6f) {
5123 }
5124
5125 /* Area is large enough for four docking targets. */
5126 const float area_ratio = float(jd->sa2->winx) / float(jd->sa2->winy);
5127 /* Split the area diagonally from top-right to bottom-left. */
5128 const bool upper_left = float(x) / float(y + 1) < area_ratio;
5129 /* Split the area diagonally from top-left to bottom-right. */
5130 const bool lower_left = float(x) / float(jd->sa2->winy - y + 1) < area_ratio;
5131
5132 if (upper_left && !lower_left) {
5133 jd->factor = area_docking_snap(std::max(1.0f - fac_y, min_fac_y), event);
5134 return AreaDockTarget::Top;
5135 }
5136 if (!upper_left && lower_left) {
5137 jd->factor = area_docking_snap(std::max(fac_y, min_fac_y), event);
5139 }
5140 if (upper_left && lower_left) {
5141 jd->factor = area_docking_snap(std::max(fac_x, min_fac_x), event);
5142 return AreaDockTarget::Left;
5143 }
5144 if (!upper_left && !lower_left) {
5145 jd->factor = area_docking_snap(std::max(1.0f - fac_x, min_fac_x), event);
5146 return AreaDockTarget::Right;
5147 }
5148 return AreaDockTarget::None;
5149}
5150
5151static float area_split_factor(bContext *C, sAreaJoinData *jd, const wmEvent *event)
5152{
5153 float fac = (jd->split_dir == SCREEN_AXIS_V) ?
5154 float(event->xy[0] - jd->sa1->totrct.xmin) / float(jd->sa1->winx + 1) :
5155 float(event->xy[1] - jd->sa1->totrct.ymin) / float(jd->sa1->winy + 1);
5156
5157 if (event->modifier & KM_CTRL) {
5158 /* Snapping on. */
5159
5160 /* Find nearest neighboring vertex. */
5161 const int axis = (jd->split_dir == SCREEN_AXIS_V) ? 0 : 1;
5162 int dist = INT_MAX;
5163 int loc = 0;
5164 for (const ScrVert &v1 : CTX_wm_screen(C)->vertbase) {
5165 const int v_loc = (&v1.vec.x)[axis];
5166 const int v_dist = abs(v_loc - event->xy[axis]);
5167 if (v_dist < dist) {
5168 loc = v_loc;
5169 dist = v_dist;
5170 }
5171 }
5172 float near_fac = (axis) ? float(loc - jd->sa1->totrct.ymin) / float(jd->sa1->winy + 1) :
5173 float(loc - jd->sa1->totrct.xmin) / float(jd->sa1->winx + 1);
5174
5175 /* Rounded to nearest 12th. */
5176 float frac_fac = round(fac * 12.0f) / 12.0f;
5177
5178 /* Use nearest neighbor or fractional, whichever is closest. */
5179 fac = (fabs(near_fac - fac) < fabs(frac_fac - fac)) ? near_fac : frac_fac;
5180 }
5181 else {
5182 /* Slight snap to center when no modifiers are held. */
5183 if (fac >= 0.48f && fac < 0.5f) {
5184 fac = 0.499999f;
5185 }
5186 else if (fac >= 0.5f && fac < 0.52f) {
5187 fac = 0.500001f;
5188 }
5189 }
5190
5191 /* Don't allow a new area to be created that is very small. */
5192 const float min_size = float(2.0f * ED_area_headersize());
5193 const float min_fac = min_size / ((jd->split_dir == SCREEN_AXIS_V) ? float(jd->sa1->winx + 1) :
5194 float(jd->sa1->winy + 1));
5195 if (min_fac < 0.5f) {
5196 return std::clamp(fac, min_fac, 1.0f - min_fac);
5197 }
5198 return 0.5f;
5199}
5200
5201static void area_join_update_data(bContext *C, sAreaJoinData *jd, const wmEvent *event)
5202{
5203 ScrArea *area = nullptr;
5204
5205 /* TODO: The following is needed until we have linux-specific implementations of
5206 * getWindowUnderCursor. See #130242. Use active window if there are overlapping. */
5207
5208#if (OS_WINDOWS || OS_MAC)
5210#else
5211 int win_count = 0;
5212 for (wmWindow &win : CTX_wm_manager(C)->windows) {
5213 int cursor[2];
5214 if (wm_cursor_position_get(&win, &cursor[0], &cursor[1])) {
5215 rcti rect;
5216 WM_window_rect_calc(&win, &rect);
5217 if (BLI_rcti_isect_pt_v(&rect, cursor)) {
5218 win_count++;
5219 }
5220 }
5221 }
5222
5223 if (win_count > 1) {
5225 }
5226 else {
5228 }
5229#endif
5230
5232 jd->dir = SCREEN_DIR_NONE;
5234 jd->dir = area_getorientation(jd->sa1, area);
5235 jd->dock_target = area_docking_target(jd, event);
5236
5237 if (jd->sa2 != area) {
5240 }
5241
5242 if (jd->sa1 == area) {
5243 const int drag_threshold = 20 * UI_SCALE_FAC;
5244 jd->sa2 = area;
5245 if (!(abs(jd->start_x - event->xy[0]) > drag_threshold ||
5246 abs(jd->start_y - event->xy[1]) > drag_threshold))
5247 {
5248 /* We haven't moved enough to start a split. */
5249 jd->dir = SCREEN_DIR_NONE;
5250 jd->split_fac = 0.0f;
5252 return;
5253 }
5254
5255 eScreenAxis dir = (abs(event->xy[0] - jd->start_x) > abs(event->xy[1] - jd->start_y)) ?
5258 jd->split_dir = dir;
5259 jd->split_fac = area_split_factor(C, jd, event);
5260 return;
5261 }
5262
5263 jd->sa2 = area;
5265 jd->dir = area_getorientation(jd->sa1, jd->sa2);
5266 jd->dock_target = area_docking_target(jd, event);
5267}
5268
5275
5277{
5278 ui::PopupMenu *pup = ui::popup_menu_begin(C, "Area Options", ICON_NONE);
5279 ui::Layout &layout = *ui::popup_menu_layout(pup);
5281
5282 PointerRNA ptr = layout.op("SCREEN_OT_area_split",
5283 IFACE_("Horizontal Split"),
5284 ICON_SPLIT_HORIZONTAL,
5286 UI_ITEM_NONE);
5287 RNA_enum_set(&ptr, "direction", SCREEN_AXIS_H);
5288 RNA_float_set(&ptr, "factor", 0.49999f);
5289 int2 pos = {area->totrct.xmin + area->winx / 2, area->totrct.ymin + area->winy / 2};
5290 RNA_int_set_array(&ptr, "cursor", pos);
5291
5292 ptr = layout.op("SCREEN_OT_area_split",
5293 IFACE_("Vertical Split"),
5294 ICON_SPLIT_VERTICAL,
5296 UI_ITEM_NONE);
5297 RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V);
5298 RNA_float_set(&ptr, "factor", 0.49999f);
5299 RNA_int_set_array(&ptr, "cursor", pos);
5300
5301 layout.separator();
5302
5303 layout.op("SCREEN_OT_area_join", IFACE_("Move/Join/Dock Area"), ICON_AREA_DOCK);
5304
5305 layout.separator();
5306
5307 layout.op("SCREEN_OT_screen_full_area",
5308 area->full ? IFACE_("Restore Areas") : IFACE_("Maximize Area"),
5309 ICON_NONE);
5310
5311 ptr = layout.op("SCREEN_OT_screen_full_area", IFACE_("Focus Mode"), ICON_NONE);
5312 RNA_boolean_set(&ptr, "use_hide_panels", true);
5313
5314 layout.op("SCREEN_OT_area_dupli", std::nullopt, ICON_NONE);
5315 layout.separator();
5316 layout.op("SCREEN_OT_area_close", IFACE_("Close Area"), ICON_X);
5317
5318 popup_menu_end(C, pup);
5319}
5320
5321static bool is_header_azone_location(ScrArea *area, const wmEvent *event)
5322{
5323 if (event->xy[0] > (area->totrct.xmin + UI_HEADER_OFFSET)) {
5324 return false;
5325 }
5326
5328 if (!header || header->flag & RGN_FLAG_HIDDEN) {
5329 return false;
5330 }
5331
5332 const int height = ED_area_headersize();
5333 if (header->alignment == RGN_ALIGN_TOP && event->xy[1] > (area->totrct.ymax - height)) {
5334 return true;
5335 }
5336 if (header->alignment == RGN_ALIGN_BOTTOM && event->xy[1] < (area->totrct.ymin + height)) {
5337 return true;
5338 }
5339
5340 return false;
5341}
5342
5343/* modal callback while selecting area (space) that will be removed */
5345{
5346 if (event->type == WINDEACTIVATE) {
5347 /* This operator can close windows, which can cause it to be re-run. */
5348 area_join_exit(C, op);
5349 return OPERATOR_FINISHED;
5350 }
5351
5352 if (op->customdata == nullptr) {
5353 if (!area_join_init(C, op, nullptr, nullptr)) {
5354 return OPERATOR_CANCELLED;
5355 }
5356 }
5357 sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
5358 if (jd == nullptr) {
5359 return OPERATOR_CANCELLED;
5360 }
5361
5362 /* execute the events */
5363 switch (event->type) {
5364
5365 case MOUSEMOVE: {
5366 area_join_update_data(C, jd, event);
5368 WM_cursor_set(jd->win1, area_join_cursor(jd, event));
5370
5371 WorkspaceStatus status(C);
5372 if (jd->sa1 && jd->sa1 == jd->sa2) {
5373 if (jd->split_fac == 0.0f) {
5374 status.item(IFACE_("Split/Dock"), ICON_MOUSE_LMB_DRAG);
5375 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
5376 }
5377 else {
5378 status.item(IFACE_("Select Split"), ICON_MOUSE_LMB_DRAG);
5379 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
5380 status.item_bool(IFACE_("Snap"), event->modifier & KM_CTRL, ICON_EVENT_CTRL);
5381 }
5382 }
5383 else {
5384 if (jd->dock_target == AreaDockTarget::None) {
5385 status.item(IFACE_("Select Area"), ICON_MOUSE_LMB_DRAG);
5386 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
5387 }
5388 else {
5389 status.item(IFACE_("Select Location"), ICON_MOUSE_LMB_DRAG);
5390 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
5391 status.item_bool(CTX_IFACE_(BLT_I18NCONTEXT_ID_SCREEN, "Precision"),
5392 event->modifier & KM_ALT,
5393 ICON_EVENT_ALT);
5394 status.item_bool(IFACE_("Snap"), event->modifier & KM_CTRL, ICON_EVENT_CTRL);
5395 }
5396 }
5397 break;
5398 }
5399 case LEFTMOUSE:
5400 if (event->val == KM_RELEASE) {
5401 area_join_update_data(C, jd, event);
5405 if (jd->dir == SCREEN_DIR_NONE && jd->dock_target == AreaDockTarget::None &&
5406 jd->split_fac == 0.0f && is_header_azone_location(jd->sa1, event))
5407 {
5409 area_join_cancel(C, op);
5410 return OPERATOR_CANCELLED;
5411 }
5412 if (jd->sa1 && !jd->sa2) {
5413 /* Break out into new window if we are really outside the source window bounds. */
5414 if (event->xy[0] < 0 || event->xy[0] > jd->win1->sizex || event->xy[1] < 1 ||
5415 event->xy[1] > jd->win1->sizey)
5416 {
5417 /* We have to clear handlers or we get an error in wm_gizmomap_modal_get. */
5419 area_dupli_open(C, jd->sa1, int2(event->xy[0], event->xy[1] - jd->sa1->winy));
5421 {
5423 jd->win1->global_areas.areabase.is_empty())
5424 {
5425 /* We've pulled a single editor out of the window into empty space.
5426 * Close the source window so we don't end up with a duplicate. */
5427 jd->close_win = true;
5428 }
5429 }
5430 }
5431 }
5432 else if (jd->sa1 && jd->sa1 == jd->sa2) {
5433 /* Same area so split. */
5434 if (area_split_allowed(jd->sa1, jd->split_dir) && jd->split_fac > 0.0001) {
5435 float inner[4] = {1.0f, 1.0f, 1.0f, 0.1f};
5436 float outline[4] = {1.0f, 1.0f, 1.0f, 0.3f};
5438 jd->win1, CTX_wm_screen(C), &jd->sa1->totrct, inner, outline, AREA_SPLIT_FADEOUT);
5439 jd->sa2 = area_split(jd->win2,
5441 jd->sa1,
5442 jd->split_dir,
5443 jd->split_fac);
5444
5445 const bool large_v = jd->split_dir == SCREEN_AXIS_V &&
5446 ((jd->start_x < event->xy[0] && jd->split_fac > 0.5f) ||
5447 (jd->start_x > event->xy[0] && jd->split_fac < 0.5f));
5448
5449 const bool large_h = jd->split_dir == SCREEN_AXIS_H &&
5450 ((jd->start_y < event->xy[1] && jd->split_fac > 0.5f) ||
5451 (jd->start_y > event->xy[1] && jd->split_fac < 0.5f));
5452
5453 if (large_v || large_h) {
5454 /* Swap areas to follow old behavior of new area added based on starting location.
5455 * When from above the new area is above, when from below the new area is below, etc.
5456 * Note that this preserves runtime data, unlike #ED_area_swapspace. */
5457 std::swap(jd->sa1->v1, jd->sa2->v1);
5458 std::swap(jd->sa1->v2, jd->sa2->v2);
5459 std::swap(jd->sa1->v3, jd->sa2->v3);
5460 std::swap(jd->sa1->v4, jd->sa2->v4);
5461 std::swap(jd->sa1->totrct, jd->sa2->totrct);
5462 std::swap(jd->sa1->winx, jd->sa2->winx);
5463 std::swap(jd->sa1->winy, jd->sa2->winy);
5464 }
5465
5468 }
5469 }
5470 else if (jd->sa1 && jd->sa2 && jd->dock_target != AreaDockTarget::None) {
5471 /* Dock this to the new location. */
5472 area_docking_apply(C, op);
5473 }
5474 else if (jd->sa1 && jd->sa2 && jd->dir != SCREEN_DIR_NONE) {
5475 /* Join to neighbor. */
5476 area_join_apply(C, op);
5477 }
5478 else {
5479 area_join_cancel(C, op);
5480 return OPERATOR_CANCELLED;
5481 }
5482
5483 /* Areas changed, update window titles. */
5484 if (jd->win2 && jd->win2 != jd->win1) {
5486 }
5487 if (jd->win1 && !jd->close_win) {
5489 }
5490
5491 const bool do_close_win = jd->close_win;
5492 wmWindow *close_win = jd->win1;
5493 area_join_exit(C, op);
5494 if (do_close_win) {
5496 }
5497
5499 return OPERATOR_FINISHED;
5500 }
5501 break;
5502
5503 case RIGHTMOUSE:
5504 case EVT_ESCKEY:
5505 area_join_cancel(C, op);
5506 return OPERATOR_CANCELLED;
5507 default: {
5508 break;
5509 }
5510 }
5511
5513}
5514
5516{
5518 return false;
5519 }
5520
5521 bScreen *screen = CTX_wm_screen(C);
5522 if (screen->state != SCREENNORMAL || screen->temp) {
5523 return false;
5524 }
5525
5526 return true;
5527}
5528
5529/* Operator for joining two areas (space types) */
5531{
5532 /* identifiers */
5533 ot->name = "Join Area";
5534 ot->description = "Join selected areas into new window";
5535 ot->idname = "SCREEN_OT_area_join";
5536
5537 /* API callbacks. */
5538 ot->exec = area_join_exec;
5540 ot->modal = area_join_modal;
5541 ot->poll = area_join_poll;
5543
5544 /* flags */
5545 ot->flag = OPTYPE_BLOCKING;
5546
5547 /* rna */
5549 "source_xy",
5550 2,
5551 nullptr,
5552 INT_MIN,
5553 INT_MAX,
5554 "Source location",
5555 "",
5556 INT_MIN,
5557 INT_MAX);
5559 "target_xy",
5560 2,
5561 nullptr,
5562 INT_MIN,
5563 INT_MAX,
5564 "Target location",
5565 "",
5566 INT_MIN,
5567 INT_MAX);
5568}
5569
5571
5572/* -------------------------------------------------------------------- */
5575
5577 wmOperator *op,
5578 const wmEvent *event)
5579{
5580 ScrArea *sa1, *sa2;
5581 ScrEdge *edge = screen_area_edge_from_cursor(C, event->xy, &sa1, &sa2);
5582 if (!edge) {
5583 return OPERATOR_CANCELLED;
5584 }
5585
5587 C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE);
5588 ui::Layout &layout = *ui::popup_menu_layout(pup);
5589
5590 /* Vertical Split */
5591 PointerRNA ptr = layout.op("SCREEN_OT_area_split",
5592 IFACE_("Vertical Split"),
5593 ICON_SPLIT_VERTICAL,
5595 UI_ITEM_NONE);
5596 /* store initial mouse cursor position. */
5597 RNA_int_set_array(&ptr, "cursor", event->xy);
5598 RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V);
5599
5600 /* Horizontal Split */
5601 ptr = layout.op("SCREEN_OT_area_split",
5602 IFACE_("Horizontal Split"),
5603 ICON_SPLIT_HORIZONTAL,
5605 UI_ITEM_NONE);
5606 /* store initial mouse cursor position. */
5607 RNA_int_set_array(&ptr, "cursor", event->xy);
5608 RNA_enum_set(&ptr, "direction", SCREEN_AXIS_H);
5609
5610 if (sa1 && sa2) {
5611 layout.separator();
5612 }
5613
5614 /* Join needs two very similar areas. */
5615 if (sa1 && sa2) {
5616 eScreenDir dir = area_getorientation(sa1, sa2);
5617 if (dir != SCREEN_DIR_NONE) {
5618 ptr = layout.op("SCREEN_OT_area_join",
5619 ELEM(dir, SCREEN_DIR_N, SCREEN_DIR_S) ? IFACE_("Join Up") :
5620 IFACE_("Join Right"),
5621 ELEM(dir, SCREEN_DIR_N, SCREEN_DIR_S) ? ICON_AREA_JOIN_UP : ICON_AREA_JOIN,
5623 UI_ITEM_NONE);
5624 RNA_int_set_array(&ptr, "source_xy", int2{sa2->totrct.xmin, sa2->totrct.ymin});
5625 RNA_int_set_array(&ptr, "target_xy", int2{sa1->totrct.xmin, sa1->totrct.ymin});
5626
5627 ptr = layout.op(
5628 "SCREEN_OT_area_join",
5629 ELEM(dir, SCREEN_DIR_N, SCREEN_DIR_S) ? IFACE_("Join Down") : IFACE_("Join Left"),
5630 ELEM(dir, SCREEN_DIR_N, SCREEN_DIR_S) ? ICON_AREA_JOIN_DOWN : ICON_AREA_JOIN_LEFT,
5632 UI_ITEM_NONE);
5633 RNA_int_set_array(&ptr, "source_xy", int2{sa1->totrct.xmin, sa1->totrct.ymin});
5634 RNA_int_set_array(&ptr, "target_xy", int2{sa2->totrct.xmin, sa2->totrct.ymin});
5635
5636 layout.separator();
5637 }
5638 }
5639
5640 /* Swap just needs two areas. */
5641 if (sa1 && sa2) {
5642 ptr = layout.op("SCREEN_OT_area_swap",
5643 IFACE_("Swap Areas"),
5644 ICON_AREA_SWAP,
5646 UI_ITEM_NONE);
5647 RNA_int_set_array(&ptr, "cursor", event->xy);
5648 }
5649
5651 layout.separator();
5652 ptr = layout.op("SCREEN_OT_edge_merge",
5653 IFACE_("Merge Edge"),
5654 ICON_NONE,
5656 UI_ITEM_NONE);
5657 RNA_int_set_array(&ptr, "cursor", event->xy);
5658 }
5659
5660 popup_menu_end(C, pup);
5661
5662 return OPERATOR_INTERFACE;
5663}
5664
5666{
5667 /* identifiers */
5668 ot->name = "Area Edge Options";
5669 ot->description = "Operations for splitting and merging";
5670 ot->idname = "SCREEN_OT_area_options";
5671
5672 /* API callbacks. */
5674
5676
5677 /* flags */
5678 ot->flag = OPTYPE_INTERNAL;
5679}
5680
5682
5683/* -------------------------------------------------------------------- */
5686
5688{
5689 Main *bmain = CTX_data_main(C);
5690 int tot = 0;
5691
5692 for (bScreen &screen : bmain->screens) {
5693 for (ScrArea &area : screen.areabase) {
5694 if (area.spacedata.first() != area.spacedata.last()) {
5695 SpaceLink *sl = area.spacedata.first_as<SpaceLink>();
5696
5697 BLI_remlink(&area.spacedata, sl);
5698 tot += area.spacedata.count();
5700 BLI_addtail(&area.spacedata, sl);
5701 }
5702 }
5703 }
5704 BKE_reportf(op->reports, RPT_INFO, "Removed amount of editors: %d", tot);
5705
5706 return OPERATOR_FINISHED;
5707}
5708
5710{
5711 /* identifiers */
5712 ot->name = "Clean Up Space Data";
5713 ot->description = "Remove unused settings for invisible editors";
5714 ot->idname = "SCREEN_OT_spacedata_cleanup";
5715
5716 /* API callbacks. */
5719}
5720
5722
5723/* -------------------------------------------------------------------- */
5726
5728{
5730 return false;
5731 }
5733 return !wm->runtime->operators.is_empty();
5734}
5735
5737{
5739 wmOperator *lastop = wm->runtime->operators.last();
5740
5741 /* Seek last registered operator */
5742 while (lastop) {
5743 if ((lastop->type->flag & OPTYPE_REGISTER) && !(lastop->type->flag & OPTYPE_DEPENDS_ON_CURSOR))
5744 {
5745 break;
5746 }
5747 lastop = lastop->prev;
5748 }
5749
5750 if (lastop) {
5752 WM_operator_repeat_last(C, lastop);
5753 }
5754
5755 return OPERATOR_CANCELLED;
5756}
5757
5759{
5760 /* identifiers */
5761 ot->name = "Repeat Last";
5762 ot->description = "Repeat last action";
5763 ot->idname = "SCREEN_OT_repeat_last";
5764
5765 /* API callbacks. */
5766 ot->exec = repeat_last_exec;
5767
5769}
5770
5772
5773/* -------------------------------------------------------------------- */
5776
5778 wmOperator *op,
5779 const wmEvent * /*event*/)
5780{
5782
5783 int items = wm->runtime->operators.count();
5784 if (items == 0) {
5785 return OPERATOR_CANCELLED;
5786 }
5787
5789 C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE);
5790 ui::Layout &layout = *popup_menu_layout(pup);
5791
5792 wmOperator *lastop;
5793 int i;
5794 for (i = items - 1, lastop = wm->runtime->operators.last(); lastop; lastop = lastop->prev, i--) {
5795 if ((lastop->type->flag & OPTYPE_REGISTER) && WM_operator_repeat_check(C, lastop)) {
5796 PointerRNA op_ptr = layout.op(
5797 op->type, WM_operatortype_name(lastop->type, lastop->ptr), ICON_NONE);
5798 RNA_int_set(&op_ptr, "index", i);
5799 }
5800 }
5801
5802 popup_menu_end(C, pup);
5803
5804 return OPERATOR_INTERFACE;
5805}
5806
5808{
5810
5811 op = static_cast<wmOperator *>(
5812 BLI_findlink(&wm->runtime->operators, RNA_int_get(op->ptr, "index")));
5813 if (op) {
5814 /* let's put it as last operator in list */
5815 BLI_remlink(&wm->runtime->operators, op);
5816 BLI_addtail(&wm->runtime->operators, op);
5817
5818 WM_operator_repeat(C, op);
5819 }
5820
5821 return OPERATOR_FINISHED;
5822}
5823
5825{
5826 /* identifiers */
5827 ot->name = "Repeat History";
5828 ot->description = "Display menu for previous actions performed";
5829 ot->idname = "SCREEN_OT_repeat_history";
5830
5831 /* API callbacks. */
5835
5836 RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
5837}
5838
5840
5841/* -------------------------------------------------------------------- */
5844
5846 wmOperator * /*op*/,
5847 const wmEvent * /*event*/)
5848{
5850
5851 if (lastop) {
5852 WM_operator_redo_popup(C, lastop);
5853 }
5854
5855 return OPERATOR_CANCELLED;
5856}
5857
5859{
5860 /* identifiers */
5861 ot->name = "Redo Last";
5862 ot->description = "Display parameters for last action performed";
5863 ot->idname = "SCREEN_OT_redo_last";
5864
5865 /* API callbacks. */
5868}
5869
5871
5872/* -------------------------------------------------------------------- */
5875
5877{
5878 if (rv3d->localvd) {
5879 rv3d->localvd->view = rv3d->view;
5880 rv3d->localvd->view_axis_roll = rv3d->view_axis_roll;
5881 rv3d->localvd->persp = rv3d->persp;
5882 copy_qt_qt(rv3d->localvd->viewquat, rv3d->viewquat);
5883 }
5884}
5885
5887 ARegion *region,
5888 const eRegionView3D_ViewLock viewlock,
5889 const eRegionView3D_View view,
5890 const eRegionView3D_Persp persp)
5891{
5892 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
5893 rv3d->rflag &= ~RV3D_WAS_CAMOB;
5894
5895 if (persp == RV3D_CAMOB) {
5897 }
5898
5899 rv3d->viewlock = viewlock;
5901 rv3d->view = view;
5903 rv3d->persp = persp;
5904
5905 ED_view3d_lock(rv3d);
5907 if ((viewlock & RV3D_BOXCLIP) && (persp == RV3D_ORTHO)) {
5908 ED_view3d_quadview_update(area, region, true);
5909 }
5910}
5911
5912/* insert a region in the area region list */
5914{
5915 ARegion *region = CTX_wm_region(C);
5916
5917 /* some rules... */
5918 if (region->regiontype != RGN_TYPE_WINDOW) {
5919 BKE_report(op->reports, RPT_ERROR, "Only window region can be 4-split");
5920 }
5921 else if (region->alignment == RGN_ALIGN_QSPLIT) {
5922 /* Exit quad-view */
5923 bScreen *screen = CTX_wm_screen(C);
5924 ScrArea *area = CTX_wm_area(C);
5925
5926 /* keep current region */
5927 region->alignment = eRegion_Alignment{};
5928
5929 if (area->spacetype == SPACE_VIEW3D) {
5930 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
5931
5932 /* if this is a locked view, use settings from 'User' view */
5933 if (rv3d->viewlock) {
5934 View3D *v3d_user;
5935 ARegion *region_user;
5936
5937 if (ED_view3d_context_user_region(C, &v3d_user, &region_user)) {
5938 if (region != region_user) {
5939 std::swap(region->regiondata, region_user->regiondata);
5940 rv3d = static_cast<RegionView3D *>(region->regiondata);
5941 }
5942 }
5943 }
5944
5947
5948 /* FIXME: This fixes missing update to workbench TAA. (see #76216)
5949 * However, it would be nice if the tagging should be done in a more conventional way. */
5950 rv3d->rflag |= RV3D_GPULIGHT_UPDATE;
5951
5952 /* Accumulate locks, in case they're mixed. */
5953 for (ARegion &region_iter : area->regionbase) {
5954 if (region_iter.regiontype == RGN_TYPE_WINDOW) {
5955 RegionView3D *rv3d_iter = static_cast<RegionView3D *>(region_iter.regiondata);
5956 rv3d->viewlock_quad |= eRegionView3D_ViewLockQuad(int(rv3d_iter->viewlock));
5957 }
5958 }
5959 }
5960
5961 for (ARegion &region_iter : area->regionbase.items_mutable()) {
5962 if (region_iter.alignment == RGN_ALIGN_QSPLIT) {
5963 ED_region_remove(C, area, &region_iter);
5964 if (&region_iter == screen->active_region) {
5965 screen->active_region = nullptr;
5966 }
5967 }
5968 }
5969 ED_area_tag_redraw(area);
5971 }
5972 else if (region->next) {
5973 BKE_report(op->reports, RPT_ERROR, "Only last region can be 4-split");
5974 }
5975 else {
5976 /* Enter quad-view */
5977 ScrArea *area = CTX_wm_area(C);
5978
5979 region->alignment = RGN_ALIGN_QSPLIT;
5980
5981 for (int count = 0; count < 3; count++) {
5982 ARegion *new_region = BKE_area_region_copy(area->type, region);
5983 BLI_addtail(&area->regionbase, new_region);
5984 }
5985
5986 /* lock views and set them */
5987 if (area->spacetype == SPACE_VIEW3D) {
5988 View3D *v3d = area->spacedata.first_as<View3D>();
5989 int index_qsplit = 0;
5990
5991 /* run ED_view3d_lock() so the correct 'rv3d->viewquat' is set,
5992 * otherwise when restoring rv3d->localvd the 'viewquat' won't
5993 * match the 'view', set on entering localview See: #26315,
5994 *
5995 * We could avoid manipulating rv3d->localvd here if exiting
5996 * localview with a 4-split would assign these view locks */
5997 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
5998 const eRegionView3D_ViewLock viewlock = (rv3d->viewlock_quad & RV3D_VIEWLOCK_INIT) ?
6002
6004 area, region, viewlock, ED_view3d_lock_view_from_index(index_qsplit++), RV3D_ORTHO);
6006 (region = region->next),
6007 viewlock,
6008 ED_view3d_lock_view_from_index(index_qsplit++),
6009 RV3D_ORTHO);
6011 (region = region->next),
6012 viewlock,
6013 ED_view3d_lock_view_from_index(index_qsplit++),
6014 RV3D_ORTHO);
6015/* forcing camera is distracting */
6016#if 0
6017 if (v3d->camera) {
6018 region_quadview_init_rv3d(area, (region = region->next), 0, RV3D_VIEW_CAMERA, RV3D_CAMOB);
6019 }
6020 else {
6021 region_quadview_init_rv3d(area, (region = region->next), 0, RV3D_VIEW_USER, RV3D_PERSP);
6022 }
6023#else
6024 (void)v3d;
6025#endif
6026 }
6027 ED_area_tag_redraw(area);
6029 }
6030
6031 return OPERATOR_FINISHED;
6032}
6033
6035{
6036 /* identifiers */
6037 ot->name = "Toggle Quad View";
6038 ot->description = "Split selected area into camera, front, right, and top views";
6039 ot->idname = "SCREEN_OT_region_quadview";
6040
6041 /* API callbacks. */
6044 ot->flag = 0;
6045}
6046
6048
6049/* -------------------------------------------------------------------- */
6052
6054{
6055 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "region_type");
6056
6057 ARegion *region;
6058 if (RNA_property_is_set(op->ptr, prop)) {
6060 }
6061 else {
6062 region = CTX_wm_region(C);
6063 }
6064
6065 if (region && (region->alignment != RGN_ALIGN_NONE)) {
6066 ED_region_toggle_hidden(C, region);
6067 }
6068 ED_region_tag_redraw(region);
6069
6070 return OPERATOR_FINISHED;
6071}
6072
6074{
6075 ScrArea *area = CTX_wm_area(C);
6076
6077 /* Don't flip anything around in top-bar. */
6078 if (area && area->spacetype == SPACE_TOPBAR) {
6079 CTX_wm_operator_poll_msg_set(C, "Toggling regions in the Top-bar is not allowed");
6080 return false;
6081 }
6082
6083 return ED_operator_areaactive(C);
6084}
6085
6087{
6088 /* identifiers */
6089 ot->name = "Toggle Region";
6090 ot->idname = "SCREEN_OT_region_toggle";
6091 ot->description = "Hide or unhide the region";
6092
6093 /* API callbacks. */
6096 ot->flag = 0;
6097
6098 RNA_def_enum(ot->srna,
6099 "region_type",
6101 0,
6102 "Region Type",
6103 "Type of the region to toggle");
6104}
6105
6107
6108/* -------------------------------------------------------------------- */
6111
6112/* flip a region alignment */
6114{
6115 ARegion *region = CTX_wm_region(C);
6116
6117 if (!region) {
6118 return OPERATOR_CANCELLED;
6119 }
6120
6121 if (region->alignment == RGN_ALIGN_TOP) {
6122 region->alignment = RGN_ALIGN_BOTTOM;
6123 }
6124 else if (region->alignment == RGN_ALIGN_BOTTOM) {
6125 region->alignment = RGN_ALIGN_TOP;
6126 }
6127 else if (region->alignment == RGN_ALIGN_LEFT) {
6128 region->alignment = RGN_ALIGN_RIGHT;
6129 }
6130 else if (region->alignment == RGN_ALIGN_RIGHT) {
6131 region->alignment = RGN_ALIGN_LEFT;
6132 }
6133
6137
6138 return OPERATOR_FINISHED;
6139}
6140
6142{
6143 ScrArea *area = CTX_wm_area(C);
6144
6145 /* Don't flip anything around in top-bar. */
6146 if (area && area->spacetype == SPACE_TOPBAR) {
6147 CTX_wm_operator_poll_msg_set(C, "Flipping regions in the Top-bar is not allowed");
6148 return false;
6149 }
6150
6151 return ED_operator_areaactive(C);
6152}
6153
6155{
6156 /* identifiers */
6157 ot->name = "Flip Region";
6158 ot->idname = "SCREEN_OT_region_flip";
6159 ot->description = "Toggle the region's alignment (left/right or top/bottom)";
6160
6161 /* API callbacks. */
6162 ot->exec = region_flip_exec;
6163 ot->poll = region_flip_poll;
6164 ot->flag = 0;
6165}
6166
6168
6169/* -------------------------------------------------------------------- */
6172
6173/* show/hide header text menus */
6175{
6176 ScrArea *area = CTX_wm_area(C);
6177
6178 area->flag ^= HEADER_NO_PULLDOWN;
6179
6180 ED_area_tag_redraw(area);
6182
6183 return OPERATOR_FINISHED;
6184}
6185
6187{
6188 /* identifiers */
6189 ot->name = "Expand/Collapse Header Menus";
6190 ot->idname = "SCREEN_OT_header_toggle_menus";
6191 ot->description = "Expand or collapse the header pull-down menus";
6192
6193 /* API callbacks. */
6196 ot->flag = 0;
6197}
6198
6200
6201/* -------------------------------------------------------------------- */
6204
6205static void screen_area_menu_items(ScrArea *area, ui::Layout &layout)
6206{
6207 if (ED_area_is_global(area)) {
6208 return;
6209 }
6210
6211 PointerRNA ptr = layout.op("SCREEN_OT_area_join",
6212 IFACE_("Move/Split Area"),
6213 ICON_AREA_DOCK,
6215 UI_ITEM_NONE);
6216
6217 layout.separator();
6218
6219 layout.op("SCREEN_OT_screen_full_area",
6220 area->full ? IFACE_("Restore Areas") : IFACE_("Maximize Area"),
6221 ICON_NONE);
6222
6223 if (area->spacetype != SPACE_FILE && !area->full) {
6224 ptr = layout.op("SCREEN_OT_screen_full_area",
6225 IFACE_("Focus Mode"),
6226 ICON_NONE,
6228 UI_ITEM_NONE);
6229 RNA_boolean_set(&ptr, "use_hide_panels", true);
6230 }
6231
6232 layout.op("SCREEN_OT_area_dupli", std::nullopt, ICON_NONE);
6233 layout.separator();
6234 layout.op("SCREEN_OT_area_close", std::nullopt, ICON_X);
6235}
6236
6238{
6239 ScrArea *area = CTX_wm_area(C);
6240 {
6242 id_cast<ID *>(CTX_wm_screen(C)), RNA_Space, area->spacedata.first());
6243 if (!ELEM(area->spacetype, SPACE_TOPBAR)) {
6244 layout->prop(&ptr, "show_region_header", UI_ITEM_NONE, IFACE_("Show Header"), ICON_NONE);
6245 }
6246
6247 ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
6248 ui::Layout &col = layout->column(false);
6249 col.active_set((region_header->flag & RGN_FLAG_HIDDEN) == 0);
6250
6252 col.prop(
6253 &ptr, "show_region_tool_header", UI_ITEM_NONE, IFACE_("Show Tool Settings"), ICON_NONE);
6254 }
6255
6256 col.op("SCREEN_OT_header_toggle_menus",
6257 IFACE_("Show Menus"),
6258 (area->flag & HEADER_NO_PULLDOWN) ? ICON_CHECKBOX_DEHLT : ICON_CHECKBOX_HLT);
6259 }
6260
6261 if (!ELEM(area->spacetype, SPACE_TOPBAR)) {
6262 layout->separator();
6263 ED_screens_region_flip_menu_create(C, layout, nullptr);
6264 layout->separator();
6265 screen_area_menu_items(area, *layout);
6266 }
6267}
6268
6270{
6271 ScrArea *area = CTX_wm_area(C);
6272
6273 {
6275 id_cast<ID *>(CTX_wm_screen(C)), RNA_Space, area->spacedata.first());
6276 layout->prop(&ptr, "show_region_footer", UI_ITEM_NONE, IFACE_("Show Footer"), ICON_NONE);
6277 }
6278
6279 ED_screens_region_flip_menu_create(C, layout, nullptr);
6280 layout->separator();
6281 screen_area_menu_items(area, *layout);
6282}
6283
6285{
6286 const ARegion *region = CTX_wm_region(C);
6287 const short region_alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
6288 const char *but_flip_str = region_alignment == RGN_ALIGN_LEFT ? IFACE_("Flip to Right") :
6289 region_alignment == RGN_ALIGN_RIGHT ? IFACE_("Flip to Left") :
6290 region_alignment == RGN_ALIGN_BOTTOM ? IFACE_("Flip to Top") :
6291 IFACE_("Flip to Bottom");
6292
6293 /* default is wm::OpCallContext::InvokeRegionWin, which we don't want here. */
6295
6296 layout->op("SCREEN_OT_region_flip", but_flip_str, ICON_NONE);
6297}
6298
6299static void ed_screens_statusbar_menu_create(ui::Layout &layout, void * /*arg*/)
6300{
6301 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, RNA_PreferencesView, &U);
6302 layout.prop(&ptr, "show_statusbar_stats", UI_ITEM_NONE, IFACE_("Scene Statistics"), ICON_NONE);
6303 layout.prop(
6304 &ptr, "show_statusbar_scene_duration", UI_ITEM_NONE, IFACE_("Scene Duration"), ICON_NONE);
6305 layout.prop(&ptr, "show_statusbar_memory", UI_ITEM_NONE, IFACE_("System Memory"), ICON_NONE);
6307 layout.prop(&ptr, "show_statusbar_vram", UI_ITEM_NONE, IFACE_("Video Memory"), ICON_NONE);
6308 }
6309 layout.prop(
6310 &ptr, "show_extensions_updates", UI_ITEM_NONE, IFACE_("Extensions Updates"), ICON_NONE);
6311 layout.prop(&ptr, "show_statusbar_version", UI_ITEM_NONE, IFACE_("Blender Version"), ICON_NONE);
6312}
6313
6315 wmOperator * /*op*/,
6316 const wmEvent * /*event*/)
6317{
6318 const ScrArea *area = CTX_wm_area(C);
6319 const ARegion *region = CTX_wm_region(C);
6320
6321 if (area && area->spacetype == SPACE_STATUSBAR) {
6322 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Status Bar"), ICON_NONE);
6323 ui::Layout &layout = *ui::popup_menu_layout(pup);
6324 ed_screens_statusbar_menu_create(layout, nullptr);
6325 popup_menu_end(C, pup);
6326 }
6327 else if (region) {
6329 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Header"), ICON_NONE);
6330 ui::Layout *layout = ui::popup_menu_layout(pup);
6331 ED_screens_header_tools_menu_create(C, layout, nullptr);
6332 popup_menu_end(C, pup);
6333 }
6334 else if (region->regiontype == RGN_TYPE_FOOTER) {
6335 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Footer"), ICON_NONE);
6336 ui::Layout *layout = ui::popup_menu_layout(pup);
6337 ED_screens_footer_tools_menu_create(C, layout, nullptr);
6338 popup_menu_end(C, pup);
6339 }
6340 else if (region->regiontype == RGN_TYPE_NAV_BAR) {
6341 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Navigation Bar"), ICON_NONE);
6342 ui::Layout &layout = *ui::popup_menu_layout(pup);
6343
6344 /* We need wm::OpCallContext::InvokeDefault in case menu item is over another area.
6345 */
6347 layout.op("SCREEN_OT_region_toggle", IFACE_("Hide"), ICON_NONE);
6348
6349 ED_screens_region_flip_menu_create(C, &layout, nullptr);
6350 const ScrArea *area = CTX_wm_area(C);
6351 if (area && area->spacetype == SPACE_PROPERTIES) {
6352 layout.menu_fn(IFACE_("Visible Tabs"), ICON_NONE, ED_buttons_visible_tabs_menu, nullptr);
6353 }
6354 popup_menu_end(C, pup);
6355 }
6356 }
6357
6358 return OPERATOR_INTERFACE;
6359}
6360
6362{
6363 /* identifiers */
6364 ot->name = "Region";
6365 ot->description = "Display region context menu";
6366 ot->idname = "SCREEN_OT_region_context_menu";
6367
6368 /* API callbacks. */
6370}
6371
6373
6374/* -------------------------------------------------------------------- */
6379
6380static bool match_region_with_redraws(const ScrArea *area,
6381 eRegion_Type regiontype,
6382 eScreen_Redraws_Flag redraws,
6383 bool from_anim_edit)
6384{
6385 const eSpace_Type spacetype = eSpace_Type(area->spacetype);
6386 if (regiontype == RGN_TYPE_WINDOW) {
6387
6388 switch (spacetype) {
6389 case SPACE_VIEW3D:
6390 if ((redraws & TIME_ALL_3D_WIN) || from_anim_edit) {
6391 return true;
6392 }
6393 break;
6394 case SPACE_GRAPH:
6395 case SPACE_NLA:
6396 if ((redraws & TIME_ALL_ANIM_WIN) || from_anim_edit) {
6397 return true;
6398 }
6399 break;
6400 case SPACE_ACTION:
6401 /* if only 1 window or 3d windows, we do timeline too
6402 * NOTE: Now we do action editor in all these cases, since timeline is here. */
6403 if ((redraws & (TIME_ALL_ANIM_WIN | TIME_REGION | TIME_ALL_3D_WIN)) || from_anim_edit) {
6404 return true;
6405 }
6406 break;
6407 case SPACE_PROPERTIES:
6408 if (redraws & TIME_ALL_BUTS_WIN) {
6409 return true;
6410 }
6411 break;
6412 case SPACE_SEQ:
6413 if ((redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) || from_anim_edit) {
6414 return true;
6415 }
6416 break;
6417 case SPACE_NODE:
6418 if (redraws & TIME_NODES) {
6419 return true;
6420 }
6421 break;
6422 case SPACE_IMAGE:
6423 if ((redraws & TIME_ALL_IMAGE_WIN) || from_anim_edit) {
6424 return true;
6425 }
6426 break;
6427 case SPACE_CLIP:
6428 if ((redraws & TIME_CLIPS) || from_anim_edit) {
6429 return true;
6430 }
6431 break;
6432 case SPACE_SPREADSHEET:
6433 if (redraws & TIME_SPREADSHEETS) {
6434 return true;
6435 }
6436 break;
6437 default:
6438 break;
6439 }
6440 }
6441 else if (regiontype == RGN_TYPE_UI) {
6442 if (spacetype == SPACE_CLIP) {
6443 /* Track Preview button is on Properties Editor in SpaceClip,
6444 * and it's very common case when users want it be refreshing
6445 * during playback, so asking people to enable special option
6446 * for this is a bit tricky, so add exception here for refreshing
6447 * Properties Editor for SpaceClip always */
6448 return true;
6449 }
6450
6451 if (redraws & TIME_ALL_BUTS_WIN) {
6452 return true;
6453 }
6454 }
6455 else if (regiontype == RGN_TYPE_HEADER) {
6456 /* The Timeline mode of the Dope Sheet shows playback controls in the header. */
6457 if (spacetype == SPACE_ACTION) {
6458 SpaceAction *saction = area->spacedata.first_as<SpaceAction>();
6459 return saction->mode == SACTCONT_TIMELINE;
6460 }
6461 }
6462 else if (regiontype == RGN_TYPE_FOOTER) {
6463 /* The footer region in animation editors shows the current frame. */
6464 if (ELEM(spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_SEQ, SPACE_NLA)) {
6465 return true;
6466 }
6467 }
6468 else if (regiontype == RGN_TYPE_PREVIEW) {
6469 switch (spacetype) {
6470 case SPACE_SEQ:
6471 if (redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) {
6472 return true;
6473 }
6474 break;
6475 case SPACE_CLIP:
6476 return true;
6477 default:
6478 break;
6479 }
6480 }
6481 else if (regiontype == RGN_TYPE_TOOLS) {
6482 switch (spacetype) {
6483 case SPACE_SPREADSHEET:
6484 if (redraws & TIME_SPREADSHEETS) {
6485 return true;
6486 }
6487 break;
6488 default:
6489 break;
6490 }
6491 }
6492 else if (regiontype == RGN_TYPE_SCRUBBING) {
6493 return true;
6494 }
6495
6496 return false;
6497}
6498
6500 bContext *C, ScrArea *area, ARegion *region, const Scene *scene, eScreen_Redraws_Flag redraws)
6501{
6502 /* Do follow time here if editor type supports it */
6503 if ((redraws & TIME_FOLLOW) &&
6505 eRegion_Type(region->regiontype)))
6506 {
6507 float w = BLI_rctf_size_x(&region->v2d.cur);
6508 if (scene->r.cfra < region->v2d.cur.xmin) {
6509 region->v2d.cur.xmax = scene->r.cfra;
6510 region->v2d.cur.xmin = region->v2d.cur.xmax - w;
6511 ED_region_tag_redraw(region);
6512 return;
6513 }
6514 if (scene->r.cfra > region->v2d.cur.xmax) {
6515 region->v2d.cur.xmin = scene->r.cfra;
6516 region->v2d.cur.xmax = region->v2d.cur.xmin + w;
6517 ED_region_tag_redraw(region);
6518 return;
6519 }
6520 }
6521
6522 /* No need to do a full redraw as the current frame indicator is only updated.
6523 * We do need to redraw when this area is in full screen as no other areas
6524 * will be tagged for redrawing. */
6525 if (region->regiontype == RGN_TYPE_WINDOW && !area->full) {
6526 if (ELEM(area->spacetype, SPACE_NLA, SPACE_ACTION)) {
6527 return;
6528 }
6529
6530 /* Drivers Editor needs a full redraw on playback for graph_draw_driver_debug().
6531 * This will make it slower than regular graph editor during playback, but drawing this in
6532 * graph_main_region_draw_overlay() is not feasible because it requires animation filtering
6533 * which has significant overhead which needs to be avoided in the overlay which is redrawn on
6534 * every UI interaction. */
6535 if (area->spacetype == SPACE_GRAPH) {
6536 const SpaceGraph *sipo = area->spacedata.first_as<SpaceGraph>();
6537 if (sipo->mode != SIPO_MODE_DRIVERS) {
6538 return;
6539 }
6540 bAnimContext ac;
6541 if (ANIM_animdata_get_context(C, &ac) == false) {
6542 return;
6543 }
6544 if (ac.datatype != ANIMCONT_DRIVERS) {
6545 return;
6546 }
6547 }
6548
6549 if (area->spacetype == SPACE_SEQ) {
6550 if (!ed::vse::has_playback_animation(scene)) {
6551 return;
6552 }
6553 }
6554 }
6555 ED_region_tag_redraw(region);
6556}
6557
6558// #define PROFILE_AUDIO_SYNC
6559
6561 wmOperator * /*op*/,
6562 const wmEvent *event)
6563{
6564 bScreen *screen = CTX_wm_screen(C);
6565 wmTimer *wt = screen->animtimer;
6566
6567 if (!(wt && wt == event->customdata)) {
6568 return OPERATOR_PASS_THROUGH;
6569 }
6570
6571#ifdef PROFILE_AUDIO_SYNC
6572 static int old_frame = 0;
6573 int newfra_int;
6574#endif
6575
6576 Main *bmain = CTX_data_main(C);
6577 ScreenAnimData *sad = static_cast<ScreenAnimData *>(wt->customdata);
6578 Scene *scene = sad->scene;
6579 ViewLayer *view_layer = sad->view_layer;
6580 Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer);
6581 Scene *scene_eval = (depsgraph != nullptr) ? DEG_get_evaluated_scene(depsgraph) : nullptr;
6583 int sync;
6584 double time;
6585
6586 /* sync, don't sync, or follow scene setting */
6587 if (sad->flag & ANIMPLAY_FLAG_SYNC) {
6588 sync = 1;
6589 }
6590 else if (sad->flag & ANIMPLAY_FLAG_NO_SYNC) {
6591 sync = 0;
6592 }
6593 else {
6594 sync = (scene->flag & SCE_FRAME_DROP);
6595 }
6596
6597 if (scene_eval == nullptr) {
6598 /* Happens when undo/redo system is used during playback, nothing meaningful we can do here. */
6599 }
6600 else if (scene_eval->id.recalc & ID_RECALC_FRAME_CHANGE) {
6601 /* Ignore seek here, the audio will be updated to the scene frame after jump during next
6602 * dependency graph update. */
6603 }
6604 else if ((scene->audio.flag & AUDIO_SYNC) && (sad->flag & ANIMPLAY_FLAG_REVERSE) == false &&
6605 isfinite(time = BKE_sound_sync_scene(scene_eval)))
6606 {
6607 scene->r.cfra = round(time * scene->frames_per_second());
6608
6609#ifdef PROFILE_AUDIO_SYNC
6610 newfra_int = scene->r.cfra;
6611 if (newfra_int < old_frame) {
6612 printf("back -%d jump detected, frame %d!\n", old_frame - newfra_int, old_frame);
6613 }
6614 else if (newfra_int > old_frame + 1) {
6615 printf("forward +%d jump detected, frame %d!\n", newfra_int - old_frame, old_frame);
6616 }
6617 fflush(stdout);
6618 old_frame = newfra_int;
6619#endif
6620 }
6621 else {
6622 if (sync) {
6623 /* Try to keep the playback in realtime by dropping frames. */
6624
6625 /* How much time (in frames) has passed since the last frame was drawn? */
6626 double delta_frames = wt->time_delta * scene->frames_per_second();
6627
6628 /* Add the remaining fraction from the last time step. */
6629 delta_frames += sad->lagging_frame_count;
6630
6631 if (delta_frames < 1.0) {
6632 /* We can render faster than the scene frame rate. However skipping or delaying frames
6633 * here seems to in practice lead to jittery playback so just step forward a minimum of
6634 * one frame. (Even though this can lead to too fast playback, the jitteriness is more
6635 * annoying)
6636 */
6637 delta_frames = 1.0f;
6638 sad->lagging_frame_count = 0;
6639 }
6640 else {
6641 /* Extract the delta frame fractions that will be skipped when converting to int. */
6642 sad->lagging_frame_count = delta_frames - int(delta_frames);
6643 }
6644
6645 const int step = delta_frames;
6646
6647 /* skip frames */
6648 if (sad->flag & ANIMPLAY_FLAG_REVERSE) {
6649 scene->r.cfra -= step;
6650 }
6651 else {
6652 scene->r.cfra += step;
6653 }
6654 }
6655 else {
6656 /* one frame +/- */
6657 if (sad->flag & ANIMPLAY_FLAG_REVERSE) {
6658 scene->r.cfra--;
6659 }
6660 else {
6661 scene->r.cfra++;
6662 }
6663 }
6664 }
6665
6666 /* Calling stop_playback() frees the animation timer `wt`, and `sad` with it. Instead of calling
6667 * that function directly, set this boolean to `true`, which will call the function at the end of
6668 * this function. */
6669 bool do_stop_playback = false;
6670
6671 /* Handle reaching the extreme frames. */
6672 const int start_frame = scene->playback_start();
6673 const int end_frame = scene->playback_end();
6674 const bool is_playing_forward = (sad->flag & ANIMPLAY_FLAG_REVERSE) == 0;
6675 const bool is_extreme_frame = is_playing_forward ? scene->r.cfra > end_frame :
6676 scene->r.cfra < start_frame;
6677 if (is_extreme_frame) {
6678 sad->flag |= ANIMPLAY_FLAG_JUMPED;
6679
6680 switch (scene->playback_loop_mode) {
6682 do_stop_playback = true;
6685 scene->r.cfra = is_playing_forward ? start_frame : end_frame;
6686 break;
6688 /* Looping happens when playback overshoots the start/end frame. This means that this
6689 * mode will visit the last frame twice (once during playback, and once after overshoot +
6690 * clamping). If this turns out to be undesired, the `is_extreme_frame` computation will
6691 * have to take the loop mode into account. */
6692 CLAMP(scene->r.cfra, start_frame, end_frame);
6693 do_stop_playback = true;
6694 break;
6696 scene->r.cfra = sad->sfra;
6697 do_stop_playback = true;
6698 break;
6700 if (is_playing_forward) {
6701 BKE_sound_stop_scene(scene_eval);
6703 scene->r.cfra = end_frame - 1;
6704 }
6705 else {
6707 BKE_sound_play_scene(scene_eval);
6708 scene->r.cfra = start_frame + 1;
6709 }
6710 CLAMP(scene->r.cfra, start_frame, end_frame);
6711 break;
6712 }
6713 }
6714 else {
6716 }
6717
6718 /* next frame overridden by user action (pressed jump to first/last frame) */
6720 scene->r.cfra = sad->nextfra;
6722 sad->flag |= ANIMPLAY_FLAG_JUMPED;
6723 }
6724
6725 /* Always reset the subframe on animation playback. */
6726 scene->r.subframe = 0.0f;
6727
6728 if (sad->flag & ANIMPLAY_FLAG_JUMPED) {
6730#ifdef PROFILE_AUDIO_SYNC
6731 old_frame = scene->r.cfra;
6732#endif
6733 }
6734
6736
6738
6739 /* Since we follow draw-flags, we can't send notifier but tag regions ourselves. */
6740 if (depsgraph != nullptr) {
6741 ED_update_for_newframe(bmain, depsgraph);
6742
6743 /* Updating the frame, and invoking the frame pre/post hooks, can result in the current timer
6744 * being removed. For example, calling `screen.animation_cancel` inside `frame_change_post`. */
6746 return OPERATOR_FINISHED;
6747 }
6748 }
6749
6750 for (wmWindow &window : wm->windows) {
6751 bScreen *win_screen = WM_window_get_active_screen(&window);
6752
6753 for (ScrArea &area : win_screen->areabase) {
6754 for (ARegion &region : area.regionbase) {
6755 bool redraw = false;
6756 if (&region == sad->region) {
6757 redraw = true;
6758 }
6759 else if (match_region_with_redraws(&area,
6760 eRegion_Type(region.regiontype),
6762 sad->from_anim_edit))
6763 {
6764 redraw = true;
6765 }
6766
6767 if (redraw) {
6769 C, &area, &region, scene, eScreen_Redraws_Flag(sad->redraws));
6770 /* Doesn't trigger a full redraw of the screen but makes sure at least overlay drawing
6771 * (#ARegionType.draw_overlay()) is triggered, which is how the current-frame is drawn.
6772 */
6773 win_screen->do_draw = true;
6774 }
6775 }
6776 }
6777 }
6778
6779 if (U.uiflag & USER_SHOW_FPS) {
6780 /* Update frame rate info too.
6781 * NOTE: this may not be accurate enough, since we might need this after modifiers/etc.
6782 * have been calculated instead of just before updates have been done? */
6783 ED_scene_fps_average_accumulate(scene, U.playback_fps_samples, wt->time_last);
6784 }
6785
6786 /* Recalculate the time-step for the timer now that we've finished calculating this,
6787 * since the frames-per-second value may have been changed.
6788 */
6789 /* TODO: this may make evaluation a bit slower if the value doesn't change...
6790 * any way to avoid this? */
6791 wt->time_step = (1.0 / scene->frames_per_second());
6792
6793 if (do_stop_playback) {
6795 }
6796
6797 return OPERATOR_FINISHED;
6798}
6799
6801{
6802 /* identifiers */
6803 ot->name = "Animation Step";
6804 ot->description = "Step through animation by position";
6805 ot->idname = "SCREEN_OT_animation_step";
6806
6807 /* API callbacks. */
6809
6811}
6812
6814
6815/* -------------------------------------------------------------------- */
6820
6822{
6823 /* If sound was playing back when we changed any sound settings, we need to make sure that
6824 * we reinitialize the playback state properly. Audaspace pauses playback on re-initializing
6825 * the playback device, so we need to make sure we reinitialize the playback state on our
6826 * end as well. (Otherwise the sound device might be in a weird state and crashes Blender). */
6828 wmWindow *timer_win = nullptr;
6829 const bool is_playing = screen != nullptr;
6830 bool playback_sync = false;
6831 int play_direction = 0;
6832
6833 if (is_playing) {
6834 ScreenAnimData *sad = static_cast<ScreenAnimData *>(screen->animtimer->customdata);
6835 timer_win = screen->animtimer->win;
6836 /* -1 means play backwards. */
6837 play_direction = (sad->flag & ANIMPLAY_FLAG_REVERSE) ? -1 : 1;
6838 playback_sync = sad->flag & ANIMPLAY_FLAG_SYNC;
6839 /* Stop playback. */
6841 }
6842 Main *bmain = CTX_data_main(C);
6843 /* Re-initialize the audio device. */
6844 BKE_sound_init(bmain);
6845 if (is_playing) {
6846 /* We need to set the context window to the window that was playing back previously.
6847 * Otherwise we will attach the new playback timer to an other window.
6848 */
6849 wmWindow *win = CTX_wm_window(C);
6850 CTX_wm_window_set(C, timer_win);
6851 ED_screen_animation_play(C, playback_sync, play_direction);
6852 CTX_wm_window_set(C, win);
6853 }
6854}
6855
6857{
6858 for (wmWindow &win : wm->windows) {
6859 bScreen *screen = WM_window_get_active_screen(&win);
6860
6861 if (screen->animtimer) {
6862 return &win;
6863 }
6864 }
6865
6866 return nullptr;
6867}
6868
6870{
6871 for (wmWindow &win : wm->windows) {
6872 bScreen *screen = WM_window_get_active_screen(&win);
6873
6874 if (screen->animtimer || screen->scrubbing) {
6875 return screen;
6876 }
6877 }
6878
6879 return nullptr;
6880}
6881
6882Scene *ED_screen_find_playing_scene(const bScreen *screen, const bool scrub)
6883{
6884 if (!screen->animtimer) {
6885 return nullptr;
6886 }
6887 wmTimer *wt = screen->animtimer;
6888 ScreenAnimData *sad = static_cast<ScreenAnimData *>(wt->customdata);
6889 if (scrub) {
6890 if (screen->scrubbing) {
6891 return sad->scene;
6892 }
6893 return nullptr;
6894 }
6895 return sad->scene;
6896}
6897
6899{
6900 for (wmWindow &win : wm->windows) {
6901 bScreen *screen = WM_window_get_active_screen(&win);
6902
6903 if (screen->animtimer) {
6904 return screen;
6905 }
6906 }
6907
6908 return nullptr;
6909}
6910
6912{
6913 if (!screen || !screen->animtimer) {
6914 /* Allow calls without knowing whether animation is actually running or not. */
6915 return;
6916 }
6917
6918 wmTimer *wt = screen->animtimer;
6919 ScreenAnimData *sad = static_cast<ScreenAnimData *>(wt->customdata);
6920 Scene *scene = sad->scene;
6921
6922 ViewLayer *view_layer = sad->view_layer;
6923 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
6924 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
6925 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
6926
6927 /* Only stop sound playback, when playing forward, since there is no sound for reverse
6928 * playback. */
6929 if ((sad->flag & ANIMPLAY_FLAG_REVERSE) == 0) {
6930 BKE_sound_stop_scene(scene_eval);
6931 }
6932
6936
6937 /* Send a fake mouse-move event so that the active button (the one the mouse hovers over) is
6938 * updated for the change in playback buttons (Pause button disappearing, Reverse/Normal playback
6939 * buttons appearing). */
6941
6942 /* Triggers redraw of sequencer preview so that it does not show to fps anymore after stopping
6943 * playback. */
6948}
6949
6956
6957static wmOperatorStatus start_playback(bContext *C, int sync, int mode)
6958{
6959 Main *bmain = CTX_data_main(C);
6960 bScreen *screen = CTX_wm_screen(C);
6961
6963 if (!scene) {
6964 return OPERATOR_CANCELLED;
6965 }
6966
6967 /* The anim timer's 'started from' frame, which gets restored on cancelling the playback, must
6968 * be the actual current frame, not the one the STOP_END_FRAME jump below sets it to. So record
6969 * it before that jump happens, and restore it into the timer's data further down, after the
6970 * timer has been created. Note that the timer is deliberately not created here already: its
6971 * presence is used elsewhere (e.g. `ED_screen_animation_playing()`) to tell whether playback
6972 * has started, and that should not become true before the ANIMATION_PLAYBACK_PRE callback and
6973 * sound playback below have run. */
6974 const int frame_before_loop_jump = scene->r.cfra;
6975
6976 const bool is_sequencer = CTX_wm_space_seq(C) != nullptr;
6977 ViewLayer *view_layer = is_sequencer ? BKE_view_layer_default_render(scene) :
6979
6980 /* The SCE_LOOP_MODE_STOP_END_FRAME loop mode is special: playback should stop at the end frame,
6981 * but when playback starts, in this mode, already at the end frame, it should actually start
6982 * playback from the start frame. This way, you can repeatedly play back the scene, each time
6983 * ending at the last frame. */
6985 /* What are the actual start/end frames depends on whether playback is reversed or not. */
6986 const bool is_playing_forward = mode > 0;
6987 const int end_frame = is_playing_forward ? scene->playback_end() : scene->playback_start();
6988 if (scene->r.cfra == end_frame) {
6989 const int start_frame = is_playing_forward ? scene->playback_start() : scene->playback_end();
6990 scene->r.cfra = start_frame;
6991 scene->r.subframe = 0.0f;
6993 }
6994 }
6995
6996 Depsgraph *depsgraph = is_sequencer ? BKE_scene_ensure_depsgraph(bmain, scene, view_layer) :
6998 if (is_sequencer) {
6999 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
7000 }
7001 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
7002
7004
7005 /* Only play sound when playing forward. Reverse sound playback is not implemented. */
7006 if (mode == 1) {
7007 BKE_sound_play_scene(scene_eval);
7008 }
7009
7010 ED_screen_animation_timer(C, scene, view_layer, screen->redraws_flag, sync, /*enable=*/mode);
7012
7013 if (screen->animtimer) {
7014 wmTimer *wt = screen->animtimer;
7015 ScreenAnimData *sad = static_cast<ScreenAnimData *>(wt->customdata);
7016
7017 sad->region = CTX_wm_region(C);
7018 sad->sfra = frame_before_loop_jump;
7019 }
7020
7021 /* Send a fake mouse-move event so that the active button (the one the mouse hovers over) is
7022 * updated for the change in playback buttons (Pause button appearing, Reverse/Normal playback
7023 * buttons disappearing). */
7025
7026 return OPERATOR_FINISHED;
7027}
7028
7030{
7033 return OPERATOR_FINISHED;
7034 }
7035
7036 return start_playback(C, sync, mode);
7037}
7038
7039/* If any screen is playing animation, stops playback and returns its flags as a #PreScrubbingState
7040 * to resume later. always sets `screen.scrubbing` to true regardless of whether playback was
7041 * active. */
7042std::optional<PreScrubbingState> ED_screen_scrubbing_enable(bContext &C, bScreen &screen)
7043{
7044 BLI_assert_msg(!screen.scrubbing, "scrubbing should not be active yet");
7045 screen.scrubbing = true;
7046
7048 bScreen *play_screen = ED_screen_animation_no_scrub(wm);
7049
7050 if (!play_screen || !play_screen->animtimer) {
7051 return std::nullopt;
7052 }
7053
7054 const ScreenAnimData *sad = static_cast<ScreenAnimData *>(play_screen->animtimer->customdata);
7055 if (sad == nullptr) {
7056 return std::nullopt;
7057 }
7058
7059 /* Only pause playback of the scrubbed scene, so scrubbing another scene does
7060 * not interrupt playback. */
7062 return std::nullopt;
7063 }
7064
7065 PreScrubbingState resume;
7068 resume.play_sync = (sad->flag & ANIMPLAY_FLAG_SYNC) ?
7072
7074
7075 return resume;
7076}
7077
7079 bScreen &screen,
7080 const std::optional<PreScrubbingState> &resume)
7081{
7082 BLI_assert_msg(screen.scrubbing, "scrubbing should be active");
7083 screen.scrubbing = false;
7084
7085 if (resume.has_value()) {
7086 ED_screen_animation_play(&C, int(resume->play_sync), int(resume->play_mode));
7087 }
7088}
7089
7091{
7092 int mode = RNA_boolean_get(op->ptr, "reverse") ? -1 : 1;
7093 int sync = -1;
7094
7095 if (RNA_struct_property_is_set(op->ptr, "sync")) {
7096 sync = RNA_boolean_get(op->ptr, "sync");
7097 }
7098
7099 const wmOperatorStatus status = ED_screen_animation_play(C, sync, mode);
7100
7102 /* Only pushing undo step when stopping playback so that there are no undo steps that seemingly
7103 * do nothing. Creating an undo step is important though, so that undoing an action right
7104 * after playback stop doesn't also change the current frame. See #144058. However adding an
7105 * undo step would remove any redo steps so we only do it when there are none. See #157688.*/
7107 }
7108 return status;
7109}
7110
7112{
7113 PropertyRNA *prop;
7114
7115 /* identifiers */
7116 ot->name = "Play Animation";
7117 ot->description = "Play animation";
7118 ot->idname = "SCREEN_OT_animation_play";
7119
7120 /* API callbacks. */
7122
7124 ot->undo_group = "Frame Change";
7125
7126 prop = RNA_def_boolean(
7127 ot->srna, "reverse", false, "Play in Reverse", "Animation is played backwards");
7129 prop = RNA_def_boolean(ot->srna, "sync", false, "Sync", "Drop frames to maintain framerate");
7131}
7132
7134
7135/* -------------------------------------------------------------------- */
7151
7153{
7155 if (!screen) {
7156 return OPERATOR_CANCELLED;
7157 }
7159 return OPERATOR_FINISHED;
7160}
7161
7163{
7164 /* Identifiers. */
7165 ot->name = "Pause Animation";
7166 ot->description = "Pause animation, stopping at the current frame";
7167 ot->idname = "SCREEN_OT_animation_pause";
7168
7169 /* API callbacks. */
7173 ot->undo_group = "Frame Change";
7174}
7175
7177
7178/* -------------------------------------------------------------------- */
7181
7183{
7185
7186 if (screen) {
7187 bool restore_start_frame = RNA_boolean_get(op->ptr, "restore_frame") && screen->animtimer;
7188 int frame;
7189 Scene *scene;
7190 if (restore_start_frame) {
7191 ScreenAnimData *sad = static_cast<ScreenAnimData *>(screen->animtimer->customdata);
7192 frame = sad->sfra;
7193 scene = sad->scene;
7194 }
7195
7196 /* Stop playback */
7198 if (restore_start_frame) {
7199 /* reset current frame and just send a notifier to deal with the rest */
7200 scene->r.cfra = frame;
7203 }
7204 }
7205
7206 return OPERATOR_PASS_THROUGH;
7207}
7208
7210{
7211 /* identifiers */
7212 ot->name = "Cancel Animation";
7213 ot->description = "Cancel animation, returning to the original frame";
7214 ot->idname = "SCREEN_OT_animation_cancel";
7215
7216 /* API callbacks. */
7218
7220
7222 "restore_frame",
7223 true,
7224 "Restore Frame",
7225 "Restore the frame when animation was initialized");
7226}
7227
7229
7230/* -------------------------------------------------------------------- */
7233
7234/* operator state vars used: (added by default WM callbacks)
7235 * xmin, ymin
7236 * xmax, ymax
7237 *
7238 * customdata: the wmGesture pointer
7239 *
7240 * callbacks:
7241 *
7242 * exec() has to be filled in by user
7243 *
7244 * invoke() default WM function
7245 * adds modal handler
7246 *
7247 * modal() default WM function
7248 * accept modal events while doing it, calls exec(), handles ESC and border drawing
7249 *
7250 * poll() has to be filled in by user for context
7251 */
7252#if 0
7253static wmOperatorStatus box_select_exec(bContext *C, wmOperator *op)
7254{
7255 int event_type = RNA_int_get(op->ptr, "event_type");
7256
7257 if (event_type == LEFTMOUSE) {
7258 printf("box select do select\n");
7259 }
7260 else if (event_type == RIGHTMOUSE) {
7261 printf("box select deselect\n");
7262 }
7263 else {
7264 printf("box select do something\n");
7265 }
7266
7267 return 1;
7268}
7269
7270static void SCREEN_OT_box_select(wmOperatorType *ot)
7271{
7272 /* identifiers */
7273 ot->name = "Box Select";
7274 ot->idname = "SCREEN_OT_box_select";
7275
7276 /* API callbacks. */
7277 ot->exec = box_select_exec;
7278 ot->invoke = WM_gesture_box_invoke;
7279 ot->modal = WM_gesture_box_modal;
7280 ot->cancel = WM_gesture_box_cancel;
7281
7282 ot->poll = ED_operator_areaactive;
7283
7284 /* rna */
7285 RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
7287}
7288#endif
7289
7291
7292/* -------------------------------------------------------------------- */
7297
7299{
7300 bScreen *screen = CTX_wm_screen(C);
7301 ScrArea *area = nullptr;
7302
7303 /* Search current screen for 'fullscreen' areas.
7304 * Skip `SPACE_EMPTY` areas: they have no space-data to restore. */
7305 for (ScrArea &area_iter : screen->areabase) {
7306 if (area_iter.full && area_iter.spacetype != SPACE_EMPTY) {
7307 area = &area_iter;
7308 break;
7309 }
7310 }
7311 if (!area) {
7312 BKE_report(op->reports, RPT_ERROR, "No fullscreen areas were found");
7313 return OPERATOR_CANCELLED;
7314 }
7315
7317
7318 return OPERATOR_FINISHED;
7319}
7320
7322{
7323 /* identifiers */
7324 ot->name = "Back to Previous Screen";
7325 ot->description = "Revert back to the original screen layout, before fullscreen area overlay";
7326 ot->idname = "SCREEN_OT_back_to_previous";
7327
7328 /* API callbacks. */
7331}
7332
7334
7335/* -------------------------------------------------------------------- */
7338
7340{
7341 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
7342 if (prop && RNA_property_is_set(op->ptr, prop)) {
7343 /* Set active section via RNA, so it can fail properly. */
7344
7345 PointerRNA pref_ptr = RNA_pointer_create_discrete(nullptr, RNA_Preferences, &U);
7346 PropertyRNA *active_section_prop = RNA_struct_find_property(&pref_ptr, "active_section");
7347
7348 RNA_property_enum_set(&pref_ptr, active_section_prop, RNA_property_enum_get(op->ptr, prop));
7349 RNA_property_update(C, &pref_ptr, active_section_prop);
7350 }
7351
7352 /* changes context! */
7354 C, nullptr, SPACE_USERPREF, U.preferences_display_type, false))
7355 {
7356 /* The header only contains the editor switcher and looks empty.
7357 * So hiding in the temp window makes sense. */
7358 ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
7359
7360 region_header->flag |= RGN_FLAG_HIDDEN;
7361 ED_region_visibility_change_update(C, area, region_header);
7362
7363 return OPERATOR_FINISHED;
7364 }
7365 BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
7366 return OPERATOR_CANCELLED;
7367}
7368
7370 wmOperatorType * /*ot*/,
7371 PointerRNA *ptr)
7372{
7373 PropertyRNA *prop = RNA_struct_find_property(ptr, "section");
7374 if (RNA_property_is_set(ptr, prop)) {
7375 int section = RNA_property_enum_get(ptr, prop);
7376 const char *section_name;
7377 if (RNA_property_enum_name_gettexted(C, ptr, prop, section, &section_name)) {
7378 return fmt::format(fmt::runtime(TIP_("Show {} preferences")), section_name);
7379 }
7380 }
7381 /* Fall back to default. */
7382 return "";
7383}
7384
7386{
7387 PropertyRNA *prop;
7388
7389 /* identifiers */
7390 ot->name = "Open Preferences...";
7391 ot->description = "Edit user preferences and system settings";
7392 ot->idname = "SCREEN_OT_userpref_show";
7393
7394 /* API callbacks. */
7396 ot->poll = ED_operator_screenactive_nobackground; /* Not in background as this opens a window. */
7398
7399 prop = RNA_def_enum(ot->srna,
7400 "section",
7402 0,
7403 "",
7404 "Section to activate in the Preferences");
7406}
7407
7409
7410/* -------------------------------------------------------------------- */
7413
7415{
7416 /* changes context! */
7419 {
7420 /* The header only contains the editor switcher and looks empty.
7421 * So hiding in the temp window makes sense. */
7422 ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
7423
7424 region_header->flag |= RGN_FLAG_HIDDEN;
7425 ED_region_visibility_change_update(C, area, region_header);
7426
7427 /* Set the section if specified. */
7428 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
7429 if (prop && RNA_property_is_set(op->ptr, prop)) {
7430 char section_name[MAX_NAME];
7431 RNA_property_string_get(op->ptr, prop, section_name);
7432 ARegion *region_props = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
7433 if (region_props) {
7434 ui::panel_category_active_set(region_props, section_name);
7435 ED_area_tag_redraw(area);
7436 }
7437 }
7438
7439 return OPERATOR_FINISHED;
7440 }
7441 BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
7442 return OPERATOR_CANCELLED;
7443}
7444
7446{
7447 PropertyRNA *prop;
7448
7449 /* identifiers */
7450 ot->name = "Open Project Settings...";
7451 ot->description = "Create and manage projects";
7452 ot->idname = "SCREEN_OT_project_settings_show";
7453
7454 /* API callbacks. */
7456 ot->poll = ED_operator_screenactive_nobackground; /* Not in background as this opens a window. */
7457
7458 prop = RNA_def_string(ot->srna,
7459 "section",
7460 "General",
7461 MAX_NAME,
7462 "Active Section",
7463 "Section to activate in Project Settings");
7465}
7466
7468
7469/* -------------------------------------------------------------------- */
7472
7474{
7475 /* Get active property to show driver for
7476 * - Need to grab it first, or else this info disappears
7477 * after we've created the window
7478 */
7479 int index;
7480 PointerRNA ptr;
7481 PropertyRNA *prop;
7482 ui::Button *but = ui::context_active_but_prop_get(C, &ptr, &prop, &index);
7483
7484 /* changes context! */
7485 if (WM_window_open_temp(C, IFACE_("Blender Drivers Editor"), SPACE_GRAPH, false)) {
7487
7488 /* activate driver F-Curve for the property under the cursor */
7489 if (but) {
7490 bool driven, special;
7492 C, &ptr, prop, index, nullptr, nullptr, &driven, &special);
7493
7494 if (fcu) {
7495 /* Isolate this F-Curve... */
7496 bAnimContext ac;
7497 if (ANIM_animdata_get_context(C, &ac)) {
7501 ac.data,
7504 fcu,
7506 }
7507 else {
7508 /* Just blindly isolate...
7509 * This isn't the best, and shouldn't happen, but may be enough. */
7511 }
7512 }
7513 }
7514
7515 return OPERATOR_FINISHED;
7516 }
7517 BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
7518 return OPERATOR_CANCELLED;
7519}
7520
7522{
7523 /* identifiers */
7524 ot->name = "Show Drivers Editor";
7525 ot->description = "Show drivers editor in a separate window";
7526 ot->idname = "SCREEN_OT_drivers_editor_show";
7527
7528 /* API callbacks. */
7530 ot->poll = ED_operator_screenactive_nobackground; /* Not in background as this opens a window. */
7531}
7532
7534
7535/* -------------------------------------------------------------------- */
7538
7540{
7541 /* changes context! */
7542 if (WM_window_open_temp(C, IFACE_("Blender Info Log"), SPACE_INFO, false)) {
7543 return OPERATOR_FINISHED;
7544 }
7545 BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
7546 return OPERATOR_CANCELLED;
7547}
7548
7550{
7551 /* identifiers */
7552 ot->name = "Show Info Log";
7553 ot->description = "Show info log in a separate window";
7554 ot->idname = "SCREEN_OT_info_log_show";
7555
7556 /* API callbacks. */
7559}
7560
7562
7563/* -------------------------------------------------------------------- */
7566
7568{
7569 Main *bmain = CTX_data_main(C);
7570 wmWindow *win = CTX_wm_window(C);
7573
7574 WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(bmain, workspace, layout_old, win);
7575
7577
7578 return OPERATOR_FINISHED;
7579}
7580
7582{
7583 /* identifiers */
7584 ot->name = "New Screen";
7585 ot->description = "Add a new screen";
7586 ot->idname = "SCREEN_OT_new";
7587
7588 /* API callbacks. */
7589 ot->exec = screen_new_exec;
7591}
7592
7594
7595/* -------------------------------------------------------------------- */
7598
7600{
7601 bScreen *screen = CTX_wm_screen(C);
7602 WorkSpace *workspace = CTX_wm_workspace(C);
7603 WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, screen);
7604
7606
7607 return OPERATOR_FINISHED;
7608}
7609
7611{
7612 /* identifiers */
7613 ot->name = "Delete Screen";
7614 ot->description = "Delete active screen";
7615 ot->idname = "SCREEN_OT_delete";
7616
7617 /* API callbacks. */
7619}
7620
7622
7623/* -------------------------------------------------------------------- */
7631
7637
7638#define TIMEOUT 0.22f
7639#define TIMESTEP (1.0f / 60.0f)
7640
7642{
7643 /* check parent too */
7644 if (region->runtime->regiontimer == nullptr &&
7645 (region->alignment & (RGN_SPLIT_PREV | RGN_ALIGN_HIDE_WITH_PREV)) && region->prev)
7646 {
7647 region = region->prev;
7648 }
7649
7650 if (region->runtime->regiontimer) {
7651 RegionAlphaInfo *rgi = static_cast<RegionAlphaInfo *>(
7652 region->runtime->regiontimer->customdata);
7653 float alpha;
7654
7655 alpha = float(region->runtime->regiontimer->time_duration) / TIMEOUT;
7656 /* makes sure the blend out works 100% - without area redraws */
7657 if (rgi->hidden) {
7658 alpha = 0.9f - TIMESTEP - alpha;
7659 }
7660
7661 CLAMP(alpha, 0.0f, 1.0f);
7662 /* Quadratic ease-out: 1 - (1 - alpha)^2 == alpha * (2 - alpha). */
7663 const float alpha_easing = alpha * (2.0f - alpha);
7664 return alpha_easing;
7665 }
7666 return 1.0f;
7667}
7668
7669void ED_region_blend_rect(ARegion *region, rcti *r_rect)
7670{
7671 *r_rect = region->winrct;
7672 const float alpha = ED_region_blend_alpha(region);
7673 if (alpha >= 1.0f) {
7674 return;
7675 }
7676 const float ofs_x = BLI_rcti_size_x(r_rect) * (1.0f - alpha);
7677 const float ofs_y = BLI_rcti_size_y(r_rect) * (1.0f - alpha);
7678 switch (RGN_ALIGN_ENUM_FROM_MASK(region->alignment)) {
7679 case RGN_ALIGN_RIGHT:
7680 r_rect->xmin += ofs_x;
7681 break;
7682 case RGN_ALIGN_LEFT:
7683 r_rect->xmax -= ofs_x;
7684 break;
7685 case RGN_ALIGN_TOP:
7686 r_rect->ymin += ofs_y;
7687 break;
7688 case RGN_ALIGN_BOTTOM:
7689 r_rect->ymax -= ofs_y;
7690 break;
7691 default:
7692 break;
7693 }
7694}
7695
7704{
7705 for (ARegion &region_iter : area->regionbase) {
7706 region_iter.runtime->visible_rect = rcti{};
7707 }
7708}
7709
7710/* assumes region has running region-blend timer */
7711static void region_blend_end(bContext *C, ARegion *region, const bool is_running)
7712{
7713 RegionAlphaInfo *rgi = static_cast<RegionAlphaInfo *>(region->runtime->regiontimer->customdata);
7714
7715 /* always send redraw */
7716 ED_region_tag_redraw(region);
7717 if (rgi->child_region) {
7719 }
7720
7721 /* if running timer was hiding, the flag toggle went wrong */
7722 if (is_running) {
7723 if (rgi->hidden) {
7724 rgi->region->flag &= ~RGN_FLAG_HIDDEN;
7725 }
7726 }
7727 else {
7728 if (rgi->hidden) {
7729 rgi->region->flag |= rgi->hidden;
7731 }
7732 /* area decoration needs redraw in end */
7734 }
7735 WM_event_timer_remove(CTX_wm_manager(C), nullptr, region->runtime->regiontimer); /* frees rgi */
7736 region->runtime->regiontimer = nullptr;
7737}
7739{
7741 wmWindow *win = CTX_wm_window(C);
7742
7743 /* end running timer */
7744 if (region->runtime->regiontimer) {
7745
7746 region_blend_end(C, region, true);
7747 }
7748 RegionAlphaInfo *rgi = MEM_new_zeroed<RegionAlphaInfo>("RegionAlphaInfo");
7749
7750 rgi->hidden = region->flag & RGN_FLAG_HIDDEN;
7751 rgi->area = area;
7752 rgi->region = region;
7753 region->flag &= ~RGN_FLAG_HIDDEN;
7754
7755 /* blend in, reinitialize regions because it got unhidden */
7756 if (rgi->hidden == 0) {
7757 ED_area_init(C, win, area);
7758 }
7759 else {
7760 ED_region_visibility_change_update_ex(C, area, region, true, false);
7761 }
7762
7763 if (region->next) {
7765 rgi->child_region = region->next;
7766 }
7767 }
7768
7769 /* new timer */
7771 region->runtime->regiontimer->customdata = rgi;
7772
7773 /* Ensure the first redraw already reflects the animation's starting alpha,
7774 * rather than one stale frame at the pre-animation state. */
7776 ED_area_tag_redraw(area);
7777}
7778
7779/* timer runs in win->handlers, so it cannot use context to find area/region */
7781{
7782 wmTimer *timer = static_cast<wmTimer *>(event->customdata);
7783
7784 /* event type is TIMERREGION, but we better check */
7785 if (event->type != TIMERREGION || timer == nullptr) {
7786 return OPERATOR_PASS_THROUGH;
7787 }
7788
7789 RegionAlphaInfo *rgi = static_cast<RegionAlphaInfo *>(timer->customdata);
7790
7792 /* always send redraws */
7794
7795 /* end timer? */
7796 if (rgi->region->runtime->regiontimer->time_duration > double(TIMEOUT)) {
7797 region_blend_end(C, rgi->region, false);
7799 }
7800
7802}
7803
7805{
7806 /* identifiers */
7807 ot->name = "Region Alpha";
7808 ot->idname = "SCREEN_OT_region_blend";
7809 ot->description = "Blend in and out overlapping region";
7810
7811 /* API callbacks. */
7813
7814 /* flags */
7815 ot->flag = OPTYPE_INTERNAL;
7816
7817 /* properties */
7818}
7819
7821
7822/* -------------------------------------------------------------------- */
7825
7827{
7828 ScrArea *area = CTX_wm_area(C);
7829 return (area && !ELEM(area->spacetype, SPACE_TOPBAR, SPACE_STATUSBAR));
7830}
7831
7833{
7834 const int space_type = RNA_enum_get(op->ptr, "space_type");
7835
7836 ScrArea *area = CTX_wm_area(C);
7837 PointerRNA ptr = RNA_pointer_create_discrete(id_cast<ID *>(CTX_wm_screen(C)), RNA_Area, area);
7838 PropertyRNA *prop_type = RNA_struct_find_property(&ptr, "type");
7839 PropertyRNA *prop_ui_type = RNA_struct_find_property(&ptr, "ui_type");
7840
7841 if (area->spacetype != space_type) {
7842 /* Set the type. */
7843 RNA_property_enum_set(&ptr, prop_type, space_type);
7844 /* Specify that we want last-used if there are subtypes. */
7845 area->butspacetype_subtype = -1;
7846 RNA_property_update(C, &ptr, prop_type);
7847 }
7848 else {
7849 /* Types match, cycle the subtype. */
7850 const int space_type_ui = RNA_property_enum_get(&ptr, prop_ui_type);
7851 const EnumPropertyItem *item;
7852 int item_len;
7853 bool free;
7854 RNA_property_enum_items(C, &ptr, prop_ui_type, &item, &item_len, &free);
7855 int index = RNA_enum_from_value(item, space_type_ui);
7856 for (int i = 1; i < item_len; i++) {
7857 const EnumPropertyItem *item_test = &item[(index + i) % item_len];
7858 if ((item_test->value >> 16) == space_type) {
7859 RNA_property_enum_set(&ptr, prop_ui_type, item_test->value);
7860 RNA_property_update(C, &ptr, prop_ui_type);
7861 break;
7862 }
7863 }
7864 if (free) {
7865 MEM_delete(item);
7866 }
7867 }
7868
7869 return OPERATOR_FINISHED;
7870}
7871
7873{
7874 /* identifiers */
7875 ot->name = "Cycle Space Type Set";
7876 ot->description = "Set the space type or cycle subtype";
7877 ot->idname = "SCREEN_OT_space_type_set_or_cycle";
7878
7879 /* API callbacks. */
7882
7883 ot->flag = 0;
7884
7885 RNA_def_enum(ot->srna, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Type", "");
7886}
7887
7889
7890/* -------------------------------------------------------------------- */
7893
7895 {SPACE_CONTEXT_CYCLE_PREV, "PREV", 0, "Previous", ""},
7896 {SPACE_CONTEXT_CYCLE_NEXT, "NEXT", 0, "Next", ""},
7897 {0, nullptr, 0, nullptr, nullptr},
7898};
7899
7901{
7902 ScrArea *area = CTX_wm_area(C);
7903 /* area might be nullptr if called out of window bounds */
7904 return (area && ELEM(area->spacetype, SPACE_PROPERTIES, SPACE_USERPREF));
7905}
7906
7912 const ScrArea *area,
7913 PointerRNA *r_ptr,
7914 PropertyRNA **r_prop)
7915{
7916 const char *propname;
7917
7918 switch (area->spacetype) {
7919 case SPACE_PROPERTIES:
7921 &screen->id, RNA_SpaceProperties, area->spacedata.first());
7922 propname = "context";
7923 break;
7924 case SPACE_USERPREF:
7925 *r_ptr = RNA_pointer_create_discrete(nullptr, RNA_Preferences, &U);
7926 propname = "active_section";
7927 break;
7928 default:
7929 BLI_assert(0);
7930 propname = "";
7931 }
7932
7933 *r_prop = RNA_struct_find_property(r_ptr, propname);
7934}
7935
7937 wmOperator *op,
7938 const wmEvent * /*event*/)
7939{
7940 const eScreenCycle direction = eScreenCycle(RNA_enum_get(op->ptr, "direction"));
7941
7942 PointerRNA ptr;
7943 PropertyRNA *prop;
7945 const int old_context = RNA_property_enum_get(&ptr, prop);
7946 const int new_context = RNA_property_enum_step(
7947 C, &ptr, prop, old_context, direction == SPACE_CONTEXT_CYCLE_PREV ? -1 : 1);
7948 RNA_property_enum_set(&ptr, prop, new_context);
7949 RNA_property_update(C, &ptr, prop);
7950
7951 return OPERATOR_FINISHED;
7952}
7953
7955{
7956 /* identifiers */
7957 ot->name = "Cycle Space Context";
7958 ot->description = "Cycle through the editor context by activating the next/previous one";
7959 ot->idname = "SCREEN_OT_space_context_cycle";
7960
7961 /* API callbacks. */
7964
7965 ot->flag = 0;
7966
7967 RNA_def_enum(ot->srna,
7968 "direction",
7971 "Direction",
7972 "Direction to cycle through");
7973}
7974
7976
7977/* -------------------------------------------------------------------- */
7980
7982 wmOperator *op,
7983 const wmEvent * /*event*/)
7984{
7985 wmWindow *win = CTX_wm_window(C);
7986 if (WM_window_is_temp_screen(win)) {
7987 return OPERATOR_CANCELLED;
7988 }
7989
7990 Main *bmain = CTX_data_main(C);
7991 const eScreenCycle direction = eScreenCycle(RNA_enum_get(op->ptr, "direction"));
7992 WorkSpace *workspace_src = WM_window_get_active_workspace(win);
7993
7994 Vector<ID *> ordered = BKE_id_ordered_list(&bmain->workspaces.cast<ID>());
7995 if (ordered.size() == 1) {
7996 return OPERATOR_CANCELLED;
7997 }
7998
7999 const int index = ordered.first_index_of(&workspace_src->id);
8000
8001 WorkSpace *workspace_dst = nullptr;
8002 switch (direction) {
8004 workspace_dst = reinterpret_cast<WorkSpace *>(index == 0 ? ordered.last() :
8005 ordered[index - 1]);
8006 break;
8008 workspace_dst = reinterpret_cast<WorkSpace *>(
8009 index == ordered.index_range().last() ? ordered.first() : ordered[index + 1]);
8010 break;
8011 }
8012
8013 win->workspace_hook->temp_workspace_store = workspace_dst;
8015 win->workspace_hook->temp_workspace_store = nullptr;
8016
8017 return OPERATOR_FINISHED;
8018}
8019
8021{
8022 /* identifiers */
8023 ot->name = "Cycle Workspace";
8024 ot->description = "Cycle through workspaces";
8025 ot->idname = "SCREEN_OT_workspace_cycle";
8026
8027 /* API callbacks. */
8030
8031 ot->flag = 0;
8032
8033 RNA_def_enum(ot->srna,
8034 "direction",
8037 "Direction",
8038 "Direction to cycle through");
8039}
8040
8042
8043/* -------------------------------------------------------------------- */
8046
8048{
8049 /* Generic UI stuff. */
8054
8055 /* Screen tools. */
8085
8086 /* Frame changes. */
8092
8097
8098 /* New/delete. */
8101}
8102
8104
8105/* -------------------------------------------------------------------- */
8108
8109static void keymap_modal_set(wmKeyConfig *keyconf)
8110{
8111 static const EnumPropertyItem modal_items[] = {
8112 {KM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
8113 {KM_MODAL_APPLY, "APPLY", 0, "Apply", ""},
8114 {KM_MODAL_SNAP_ON, "SNAP", 0, "Snap On", ""},
8115 {KM_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Snap Off", ""},
8116 {0, nullptr, 0, nullptr, nullptr},
8117 };
8118
8119 /* Standard Modal keymap ------------------------------------------------ */
8120 wmKeyMap *keymap = WM_modalkeymap_ensure(keyconf, "Standard Modal Map", modal_items);
8121
8122 WM_modalkeymap_assign(keymap, "SCREEN_OT_area_move");
8123}
8124
8125static bool blend_file_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
8126{
8127 if (drag->type == WM_DRAG_PATH) {
8130 return true;
8131 }
8132 }
8133 return false;
8134}
8135
8136static void blend_file_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
8137{
8138 /* copy drag path to properties */
8139 RNA_string_set(drop->ptr, "filepath", WM_drag_get_single_path(drag));
8140}
8141
8142static bool screen_drop_scene_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
8143{
8144 /* Make sure we're dropping the scene outside the asset browser. */
8145 SpaceFile *sfile = CTX_wm_space_file(C);
8146 if (sfile && ED_fileselect_is_asset_browser(sfile)) {
8147 return false;
8148 }
8149 return WM_drag_is_ID_type(drag, ID_SCE);
8150}
8151
8153{
8155 if (id) {
8156 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
8157 }
8158}
8159
8160static std::string screen_drop_scene_tooltip(bContext * /*C*/,
8161 wmDrag *drag,
8162 const int /*xy*/
8163 [2],
8164 wmDropBox * /*drop*/)
8165{
8166 const std::string dragged_scene_name = WM_drag_get_item_name(drag);
8167 wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, ID_SCE);
8168 if (asset_drag) {
8169 switch (asset_drag->import_settings.method) {
8170 case ASSET_IMPORT_LINK:
8171 return fmt::format(fmt::runtime(TIP_("Link {}")), dragged_scene_name);
8172 case ASSET_IMPORT_PACK:
8173 return fmt::format(fmt::runtime(TIP_("Pack {}")), dragged_scene_name);
8175 return fmt::format(fmt::runtime(TIP_("Append {}")), dragged_scene_name);
8177 return fmt::format(fmt::runtime(TIP_("Append (Reuse) {}")), dragged_scene_name);
8178 }
8179 }
8180 return fmt::format(fmt::runtime(TIP_("Set {} as active")), dragged_scene_name);
8181}
8182
8184{
8185 /* Screen Editing ------------------------------------------------ */
8186 WM_keymap_ensure(keyconf, "Screen Editing", SPACE_EMPTY, RGN_TYPE_WINDOW);
8187
8188 /* Screen General ------------------------------------------------ */
8189 WM_keymap_ensure(keyconf, "Screen", SPACE_EMPTY, RGN_TYPE_WINDOW);
8190
8191 /* Anim Playback ------------------------------------------------ */
8192 WM_keymap_ensure(keyconf, "Frames", SPACE_EMPTY, RGN_TYPE_WINDOW);
8193
8194 /* dropbox for entire window */
8195 ListBaseT<wmDropBox> *lb = WM_dropboxmap_find("Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
8197 lb, "WM_OT_drop_blend_file", blend_file_drop_poll, blend_file_drop_copy, nullptr, nullptr);
8199 lb, "UI_OT_drop_color", ui::drop_color_poll, ui::drop_color_copy, nullptr, nullptr);
8200 WM_dropbox_add(lb,
8201 "SCENE_OT_drop_scene_asset",
8206
8207 keymap_modal_set(keyconf);
8208}
8209
8211
8212} // namespace blender
General operations, lookup, etc. for blender objects.
#define ATTR_FALLTHROUGH
Platform independent time functions.
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_ID_SCREEN
#define IFACE_(msgid)
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define MAX_NAME
Definition DNA_defs.h:63
#define OB_MODE_ALL_WEIGHT_PAINT
Object is a sort of wrapper for general info.
#define HEADERY
#define RGN_ALIGN_ENUM_FROM_MASK(align)
#define AREAMAP_FROM_SCREEN(screen)
#define AREAMINX
#define AREAGRID
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
#define FRAMENUMBER_MIN_CLAMP(cfra)
#define ED_screen_verts_iter(win, screen, vert_name)
Definition ED_screen.hh:325
#define ED_screen_areas_iter(win, screen, area_name)
Definition ED_screen.hh:322
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_REGION_OVERLAP_MARGIN
#define UI_UNIT_Y
#define UI_PANEL_CATEGORY_MIN_WIDTH
#define UI_HEADER_OFFSET
#define UI_AZONESPOTW_RIGHT
#define UI_UNIT_X
#define UI_ITEM_NONE
#define UI_TIME_SCRUB_MARGIN_Y
Definition UI_view2d.hh:493
#define V2D_SCROLL_HIDE_WIDTH
Definition UI_view2d.hh:88
#define V2D_SCROLL_HIDE_HEIGHT
Definition UI_view2d.hh:89
#define ND_ANIMATION_PLAYBACK
Definition WM_types.hh:448
#define ND_SPACE_SEQUENCER
Definition WM_types.hh:578
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_SCREEN
Definition WM_types.hh:390
#define ND_ANIMPLAY
Definition WM_types.hh:441
#define NC_SCENE
Definition WM_types.hh:391
#define NA_EDITED
Definition WM_types.hh:634
#define ND_FRAME
Definition WM_types.hh:453
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_WORKSPACE_SET
Definition WM_types.hh:445
#define ND_LAYOUTBROWSE
Definition WM_types.hh:439
#define ND_SPACE_SPREADSHEET
Definition WM_types.hh:584
#define ND_LAYOUTDELETE
Definition WM_types.hh:440
#define NC_SPACE
Definition WM_types.hh:405
#define CLAMP(a, b, c)
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
#define IN_RANGE_INCL(a, b, c)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool closest(btVector3 &v)
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
IndexRange index_range() const
int64_t first_index_of(const T &value) const
const T & first() const
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
#define printf
#define FLT_MAX
#define INT_MAX
#define position
#define round
#define pow
#define abs
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
const int state
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
void free(Subdiv *subdiv)
Definition subdiv.cc:192
Scene * scene_or_sequencer_scene_from_context(const bContext &C)
ListBaseT< bAnimListElem > get_editable_fcurves(bAnimContext &ac)
Object * context_active_object(const bContext *C)
bool has_playback_animation(const Scene *scene)
void sync_active_scene_and_time_with_scene_strip(bContext &C)
bool region_button_sections_is_inside_x(const ARegion *region, const int mval_x)
void drop_color_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
void view2d_curRect_validate(View2D *v2d)
Definition view2d.cc:810
bool drop_color_poll(bContext *C, wmDrag *drag, const wmEvent *event)
float view2d_view_to_region_y(const View2D *v2d, float y)
Definition view2d.cc:1678
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void panel_category_active_set(ARegion *region, const char *idname)
Layout * popup_menu_layout(PopupMenu *pup)
char view2d_mouse_in_scrollers_ex(const ARegion *region, const View2D *v2d, const int xy[2], int *r_scroll) ATTR_NONNULL(1
Definition view2d.cc:1988
Button * context_active_but_prop_get(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
float view2d_view_to_region_x(const View2D *v2d, float x)
Definition view2d.cc:1673
BMesh Iterators.
bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_region)
static const EnumPropertyItem prop_direction_items[]
void WM_main_add_notifier(uint type, void *reference)
static void SCREEN_OT_workspace_cycle(wmOperatorType *ot)
static bool area_join_apply(bContext *C, wmOperator *op)
UserDef U
Definition blender.cc:58
WorkSpaceLayout * ED_workspace_layout_duplicate(Main *bmain, WorkSpace *workspace, const WorkSpaceLayout *layout_old, wmWindow *win) ATTR_NONNULL()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void SCREEN_OT_info_log_show(wmOperatorType *ot)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
const char * WM_drag_get_single_path(const wmDrag *drag)
static wmOperatorStatus area_swap_modal(bContext *C, wmOperator *op, const wmEvent *event)
void BKE_callback_exec_id_depsgraph(Main *bmain, ID *id, Depsgraph *depsgraph, eCbEvent evt)
Definition callbacks.cc:54
bool ED_operator_scene_editable(bContext *C)
void screen_stop_playback(Main *bmain, wmWindowManager *wm, wmWindow *win, bScreen *screen)
bool ED_operator_node_active(bContext *C)
bool ED_undo_has_redo_step(const bContext *C)
Definition ed_undo.cc:581
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
bool ED_operator_animview_active(bContext *C)
bool ED_operator_uvedit(bContext *C)
bool ED_operator_posemode_exclusive(bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus screen_animation_pause_exec(bContext *C, wmOperator *)
bool screen_area_close(bContext *C, ReportList *reports, bScreen *screen, ScrArea *area, ScrArea *not_area)
void ED_region_blend_rect(ARegion *region, rcti *r_rect)
static wmOperatorStatus repeat_last_exec(bContext *C, wmOperator *)
int screen_area_join(bContext *C, ReportList *reports, bScreen *screen, ScrArea *sa1, ScrArea *sa2)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
static wmOperatorStatus region_flip_exec(bContext *C, wmOperator *)
wmDropBox * WM_dropbox_add(ListBaseT< wmDropBox > *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
static void SCREEN_OT_animation_step(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void SCREEN_OT_animation_pause(wmOperatorType *ot)
void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
Definition area.cc:2628
static wmOperatorStatus screen_animation_play_exec(bContext *C, wmOperator *op)
void ED_area_tag_redraw_no_rebuild(ScrArea *area)
Definition area.cc:793
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
Scene * CTX_data_sequencer_scene(const bContext *C)
ScrEdge * screen_geom_find_active_scredge(const wmWindow *win, const bScreen *screen, const int mx, const int my)
static void area_swap_cancel(bContext *C, wmOperator *op)
void ED_screen_animation_timer(bContext *C, Scene *scene, ViewLayer *view_layer, int redraws, int sync, int enable)
static void actionzone_apply(bContext *C, wmOperator *op, int type)
static void keylist_from_dopesheet(bContext &C, AnimKeylist &keylist)
static bool screen_active_editable(bContext *C)
bool ED_operator_graphedit_active(bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static bool region_toggle_poll(bContext *C)
wmDragAsset * WM_drag_get_asset_data(const wmDrag *drag, int idcode)
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:91
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus repeat_history_exec(bContext *C, wmOperator *op)
static AZone * screen_actionzone_find_xy(bScreen *screen, const int xy[2])
void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2290
void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop)
Free asset ID imported for canceled drop.
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool screen_maximize_area_poll(bContext *C)
static wmOperatorStatus actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool ED_operator_region_nla_active(bContext *C)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
static void SCREEN_OT_marker_jump(wmOperatorType *ot)
static bool space_context_cycle_poll(bContext *C)
bool ED_operator_nla_active(bContext *C)
@ ANIMCONT_DRIVERS
static void view3d_localview_update_rv3d(RegionView3D *rv3d)
@ BKE_CB_EVT_ANIMATION_PLAYBACK_PRE
@ BKE_CB_EVT_ANIMATION_PLAYBACK_POST
int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
Definition area.cc:873
ScrArea * area_split(const wmWindow *win, bScreen *screen, ScrArea *area, const eScreenAxis dir_axis, const float fac)
Depsgraph * BKE_scene_get_depsgraph(const Scene *scene, const ViewLayer *view_layer)
Definition scene.cc:3631
static bool area_split_apply(bContext *C, wmOperator *op)
WorkSpace * CTX_wm_workspace(const bContext *C)
static void screen_area_menu_items(ScrArea *area, ui::Layout &layout)
void ED_keymap_screen(wmKeyConfig *keyconf)
bool ED_operator_editlattice(bContext *C)
void ED_region_visibility_change_update_ex(bContext *C, ScrArea *area, ARegion *region, bool is_hidden, bool do_init)
Definition area.cc:2580
int BLI_rcti_length_x(const rcti *rect, int x)
Definition rct.cc:151
void screen_draw_split_preview(ScrArea *area, const eScreenAxis dir_axis, const float factor)
void ANIM_anim_channels_select_set(bAnimContext *ac, eAnimChannels_SetFlag sel)
bool ED_operator_object_active_local_editable_ex(bContext *C, const Object *ob)
MINLINE int round_fl_to_int(float a)
static void region_quadview_init_rv3d(ScrArea *area, ARegion *region, const eRegionView3D_ViewLock viewlock, const eRegionView3D_View view, const eRegionView3D_Persp persp)
static void SCREEN_OT_edge_merge(wmOperatorType *ot)
static wmOperatorStatus area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE int square_i(int a)
static wmOperatorStatus info_log_show_exec(bContext *C, wmOperator *op)
static void screen_animation_region_tag_redraw(bContext *C, ScrArea *area, ARegion *region, const Scene *scene, eScreen_Redraws_Flag redraws)
void ED_screen_global_areas_sync(wmWindow *win)
const std::string WM_drag_get_item_name(wmDrag *drag)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
void ED_screens_footer_tools_menu_create(bContext *C, ui::Layout *layout, void *arg)
void ANIM_set_active_channel(bAnimContext *ac, void *data, eAnimCont_Types datatype, eAnimFilter_Flags filter, void *channel_data, eAnim_ChannelType channel_type)
static int area_split_snap_calc_location(const bScreen *screen, const int delta, const int origval, const eScreenAxis dir_axis, const int bigger, const int smaller)
void BKE_screen_remove_unused_scredges(bScreen *screen)
Definition screen.cc:917
static void SCREEN_OT_actionzone(wmOperatorType *ot)
void BKE_screen_remove_unused_scrverts(bScreen *screen)
Definition screen.cc:962
static void SCREEN_OT_spacedata_cleanup(wmOperatorType *ot)
static void SCREEN_OT_region_flip(wmOperatorType *ot)
static wmOperatorStatus screen_context_menu_invoke(bContext *C, wmOperator *, const wmEvent *)
bool screen_geom_edge_can_extend(const wmWindow *win, ScrEdge *edge)
static void SCREEN_OT_screen_set(wmOperatorType *ot)
bool ED_operator_buttons_active(bContext *C)
bool ED_operator_object_active_editable_font(bContext *C)
ScrArea * ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, eScreen_State state)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool ED_fileselect_is_asset_browser(const SpaceFile *sfile)
Definition filesel.cc:486
static void keymap_modal_set(wmKeyConfig *keyconf)
static bool area_close_poll(bContext *C)
static void area_swap_exit(bContext *C, wmOperator *op)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
void CTX_wm_window_set(bContext *C, wmWindow *win)
bool ED_operator_object_active_objectmode(bContext *C)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void region_scale_draw_cb(const wmWindow *, void *userdata)
void WM_cursor_modal_set(wmWindow *win, int val)
bool BKE_regiontype_uses_category_tabs(const ARegionType *region_type)
Definition screen.cc:407
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
bool ED_operator_posemode(bContext *C)
AZone * ED_area_azones_update(ScrArea *area, const int mouse_xy[2])
wmWindow * WM_window_open(bContext *C, const char *title, const rcti *rect_unscaled, int space_type, bool toplevel, bool dialog, bool temp, eWindowAlignment alignment, void(*area_setup_fn)(bScreen *screen, ScrArea *area, void *user_data), void *area_setup_user_data)
bool ED_operator_areaactive(bContext *C)
bool ED_operator_editcurve(bContext *C)
static void area_dupli_fn(bScreen *, ScrArea *area, void *user_data)
const ActKeyColumn * ED_keylist_find_prev(const AnimKeylist *keylist, const float cfra)
bool ED_operator_spreadsheet_active(bContext *C)
static void SCREEN_OT_area_close(wmOperatorType *ot)
float ED_region_blend_alpha(ARegion *region)
static bool area_move_init(bContext *C, wmOperator *op, bool extend)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void area_actionzone_get_rect(AZone *az, rcti *r_rect)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
bool ED_operator_node_editable(bContext *C)
@ WM_DRAG_PATH
Definition WM_types.hh:1302
void BLI_rcti_init_minmax(struct rcti *rect)
Definition rct.cc:488
void WM_operator_properties_border(wmOperatorType *ot)
AZone * ED_area_actionzone_find_xy(ScrArea *area, const int xy[2])
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
static bool scene_to_first_key_column_in_range(Scene *scene, const ScenePlaybackRange playback_range, KeyColumnIterator key_columns)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool ED_operator_region_gizmo_active(bContext *C)
bool ED_operator_file_active(bContext *C)
static void quadview_size_exit(wmOperator *op)
void summary_to_keylist(bAnimContext *ac, AnimKeylist *keylist, const int saction_flag, float2 range)
int ED_area_headersize()
Definition area.cc:4418
@ SCE_LOOP_MODE_STOP_START_FRAME
@ SCE_LOOP_MODE_STOP_END_FRAME
MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus space_workspace_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *)
wmWindow * CTX_wm_window(const bContext *C)
bool ED_operator_editcurve_3d(bContext *C)
ID * WM_drag_get_local_ID_or_import_from_asset(const bContext *C, const wmDrag *drag, int idcode)
bool ED_operator_outliner_active(bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ ACHANNEL_SETFLAG_CLEAR
int WM_event_drag_threshold(const wmEvent *event)
bool ED_operator_editarmature(bContext *C)
MINLINE int max_ii(int a, int b)
static wmOperatorStatus screen_animation_step_invoke(bContext *C, wmOperator *, const wmEvent *event)
static void region_scale_exit(wmOperator *op)
static void SCREEN_OT_back_to_previous(wmOperatorType *ot)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
static void SCREEN_OT_redo_last(wmOperatorType *ot)
bool ED_operator_editsurfcurve_region_view3d(bContext *C)
static AZone * area_actionzone_refresh_xy(ScrArea *area, const int xy[2], const bool test_only)
bool ANIM_nla_mapping_allowed(const bAnimListElem *ale)
Definition anim_draw.cc:279
bool ED_operator_asset_browsing_active(bContext *C)
bool ED_operator_outliner_active_no_editobject(bContext *C)
static void SCREEN_OT_area_join(wmOperatorType *ot)
@ ANIMTYPE_FCURVE
static wmOperatorStatus frame_offset_exec(bContext *C, wmOperator *op)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bool ED_operator_object_active_local_editable(bContext *C)
@ WIN_ALIGN_ABSOLUTE
Definition WM_api.hh:484
void ED_screen_animation_timer_remove(wmWindowManager *wm, wmWindow *win)
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
Definition area.cc:2893
static wmOperatorStatus spacedata_cleanup_exec(bContext *C, wmOperator *op)
static void keylist_from_graph_editor(bContext &C, AnimKeylist &keylist)
bool ED_operator_scene(bContext *C)
bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
static void SCREEN_OT_userpref_show(wmOperatorType *ot)
bool ED_operator_camera_poll(bContext *C)
bool ED_operator_sequencer_active_editable(bContext *C)
const ActKeyColumn * ED_keylist_find_next(const AnimKeylist *keylist, const float cfra)
static std::optional< int > find_marker_in_direction(const ListBaseT< TimeMarker > &markers, const int from_frame, const SearchDirection direction, const std::optional< ScenePlaybackRange > playback_range)
ARegion * BKE_area_region_copy(const SpaceType *st, const ARegion *region)
Definition screen.cc:479
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2600
SpaceSeq * CTX_wm_space_seq(const bContext *C)
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
double BKE_sound_sync_scene(Scene *scene)
void ED_scene_fps_average_accumulate(Scene *scene, short fps_samples, double ltime) ATTR_NONNULL(1)
Definition scene_fps.cc:57
wmOperatorStatus ED_screen_animation_play(bContext *C, int sync, int mode)
static int area_snap_calc_location(sAreaMoveData *md, const int delta)
static void SCREEN_OT_frame_jump(wmOperatorType *ot)
static void area_docking_apply(bContext *C, wmOperator *op)
WorkSpace * BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:633
Object * ED_pose_object_from_context(bContext *C)
Definition pose_edit.cc:62
@ RGN_ALIGN_HIDE_WITH_PREV
ListBaseT< TimeMarker > * ED_scene_markers_get(const bContext *C, Scene *scene)
ScenePlaybackRange BKE_scene_get_playback_range(const Scene *scene)
Definition scene.cc:2607
static void SCREEN_OT_region_toggle(wmOperatorType *ot)
@ EVT_ACTIONZONE_FULLSCREEN
@ EVT_ACTIONZONE_REGION_QUAD
@ EVT_ACTIONZONE_REGION
bool GPU_mem_stats_supported()
static void SCREEN_OT_region_blend(wmOperatorType *ot)
static void quadview_size_cancel(bContext *C, wmOperator *op)
Global G
Definition blender.cc:57
bool ED_operator_action_active(bContext *C)
bool RNA_property_enum_name_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
static void SCREEN_OT_frame_offset(wmOperatorType *ot)
static bool area_dupli_poll(bContext *C)
void WM_draw_cb_exit(wmWindow *win, void *handle)
Definition wm_draw.cc:652
static void area_move_apply(bContext *C, wmOperator *op)
static void SCREEN_OT_area_dupli(wmOperatorType *ot)
static void context_cycle_prop_get(bScreen *screen, const ScrArea *area, PointerRNA *r_ptr, PropertyRNA **r_prop)
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:561
void SCREEN_OT_screenshot_area(wmOperatorType *ot)
static wmOperatorStatus userpref_show_exec(bContext *C, wmOperator *op)
static void region_scale_validate_size(RegionMoveData *rmd)
static void SCREEN_OT_region_context_menu(wmOperatorType *ot)
static wmOperatorStatus quadview_size_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus space_type_set_or_cycle_exec(bContext *C, wmOperator *op)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
int ED_area_global_min_size_y(const ScrArea *area)
Definition area.cc:4434
static void area_move_out_draw_cb(const wmWindow *win, void *userdata)
bool ED_operator_objectmode_poll_msg(bContext *C)
bool ED_operator_region_animview_active(bContext *C)
static void SCREEN_OT_region_scale(wmOperatorType *ot)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool ED_operator_editmesh(bContext *C)
void fcurve_to_keylist(AnimData *adt, FCurve *fcu, AnimKeylist *keylist, const int saction_flag, float2 range, const bool use_nla_remapping)
wmWindow * WM_window_find_by_area(wmWindowManager *wm, const ScrArea *area)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
static void SCREEN_OT_area_options(wmOperatorType *ot)
static bool azone_clipped_rect_calc(const AZone *az, rcti *r_rect_clip)
int BLI_rcti_length_y(const rcti *rect, int y)
Definition rct.cc:162
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
bool ED_operator_sequencer_scene_editable(bContext *C)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
static void region_scale_toggle_hidden(bContext *C, RegionMoveData *rmd, bool do_fade=false)
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
static void area_move_exit(bContext *C, wmOperator *op)
void ED_region_visibility_change_update_animated(bContext *C, ScrArea *area, ARegion *region)
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
void BKE_icon_changed(int icon_id)
Definition icons.cc:215
VecBase< int32_t, 2 > int2
static void SCREEN_OT_area_split(wmOperatorType *ot)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus start_playback(bContext *C, int sync, int mode)
void ED_operatortypes_screen()
std::optional< PreScrubbingState > ED_screen_scrubbing_enable(bContext &C, bScreen &screen)
@ ASSET_IMPORT_APPEND
@ ASSET_IMPORT_APPEND_REUSE
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_NODUPLIS
static void SCREEN_OT_animation_cancel(wmOperatorType *ot)
static wmOperatorStatus area_close_exec(bContext *C, wmOperator *op)
static bool repeat_history_poll(bContext *C)
bool ED_operator_object_active_from_view_layer(bContext *C)
static wmOperatorStatus screen_delete_exec(bContext *C, wmOperator *)
void grease_pencil_data_block_to_keylist(AnimData *adt, const GreasePencil *grease_pencil, AnimKeylist *keylist, const int saction_flag, const bool active_layer_only)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void copy_qt_qt(float q[4], const float a[4])
static ScrEdge * screen_area_edge_from_cursor(const bContext *C, const int cursor[2], ScrArea **r_sa1, ScrArea **r_sa2)
void DEG_id_tag_update(ID *id, unsigned int flags)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
@ SNAP_BIGGER_SMALLER_ONLY
@ SNAP_FRACTION_AND_ADJACENT
void BKE_sound_play_scene(Scene *scene)
static wmOperatorStatus actionzone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
bool ED_operator_preferences_active(bContext *C)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
static bool area_swap_init(wmOperator *op, const wmEvent *event)
static wmOperatorStatus area_move_exec(bContext *C, wmOperator *op)
static void SCREEN_OT_new(wmOperatorType *ot)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
static void region_blend_end(bContext *C, ARegion *region, const bool is_running)
wmWindowManager * CTX_wm_manager(const bContext *C)
wmOperatorStatus WM_operator_repeat(bContext *C, wmOperator *op)
void ED_region_remove(bContext *C, ScrArea *area, ARegion *region)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static wmOperatorStatus region_toggle_exec(bContext *C, wmOperator *op)
bool ED_operator_object_active_only_from_view_layer(bContext *C)
static wmOperatorStatus region_blend_invoke(bContext *C, wmOperator *, const wmEvent *event)
Object * CTX_data_edit_object(const bContext *C)
@ SPACE_CONTEXT_CYCLE_NEXT
Definition ED_screen.hh:868
@ SPACE_CONTEXT_CYCLE_PREV
Definition ED_screen.hh:867
static wmOperatorStatus marker_jump_exec(bContext *C, wmOperator *op)
bool ED_operator_object_active_only(bContext *C)
static void SCREEN_OT_space_context_cycle(wmOperatorType *ot)
bool ED_operator_object_active_editable_obdata_from_view_layer_ex(bContext *C, short obtype)
void wm_window_close_request(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:483
static bool is_header_azone_location(ScrArea *area, const wmEvent *event)
static void keylist_fallback_for_keyframe_jump(bContext &C, Scene *scene, AnimKeylist &keylist)
static wmOperatorStatus area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
static bool ed_spacetype_test(bContext *C, int type)
static void screen_modal_action_begin()
bool ED_operator_posemode_context(bContext *C)
static wmOperatorStatus redo_last_invoke(bContext *C, wmOperator *, const wmEvent *)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
ScrEdge * screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map, const rcti *bounds_rect, const int mx, const int my, int safety)
void screen_draw_dock_preview(const wmWindow *win, ScrArea *source, ScrArea *target, AreaDockTarget dock_target, float factor, int x, int y, float anim_factor)
MaskLayer * BKE_mask_layer_active(Mask *mask)
static wmOperatorStatus project_settings_show_exec(bContext *C, wmOperator *op)
static bool screen_animation_region_supports_time_follow(eSpace_Type spacetype, eRegion_Type regiontype)
static wmOperatorStatus screen_set_exec(bContext *C, wmOperator *op)
bool ED_operator_sequencer_scene(bContext *C)
void WM_cursor_modal_restore(wmWindow *win)
bool ED_operator_region_info_active(bContext *C)
void WM_operator_free_all_after(wmWindowManager *wm, wmOperator *op)
Definition wm.cc:312
static bool space_type_set_or_cycle_poll(bContext *C)
@ AE_RIGHT_TO_TOPLEFT
@ AE_BOTTOM_TO_TOPLEFT
@ AE_LEFT_TO_TOPRIGHT
@ AE_TOP_TO_BOTTOMRIGHT
void ED_keylist_prepare_for_direct_access(AnimKeylist *keylist)
bool ED_operator_editable_mesh(bContext *C)
static wmOperatorStatus drivers_editor_show_exec(bContext *C, wmOperator *op)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool ED_operator_editsurfcurve(bContext *C)
@ WM_TIMER_TAGGED_FOR_REMOVAL
Definition WM_types.hh:1018
static wmOperatorStatus area_swap_exec(bContext *C, wmOperator *op)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
static wmOperatorStatus area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool ED_operator_regionactive(bContext *C)
static bool area_split_init(bContext *C, wmOperator *op)
bool ED_operator_console_active(bContext *C)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
wmOperatorStatus WM_operator_redo_popup(bContext *C, wmOperator *op)
SpaceNode * CTX_wm_space_node(const bContext *C)
bool ED_operator_view3d_active(bContext *C)
AnimKeylist * ED_keylist_create()
static void area_split_cancel(bContext *C, wmOperator *op)
ScrEdge * BKE_screen_find_edge(const bScreen *screen, ScrVert *v1, ScrVert *v2)
Definition screen.cc:840
bool screen_geom_edge_is_horizontal(ScrEdge *se)
int ED_area_footersize()
Definition area.cc:4424
Mask * CTX_data_edit_mask(const bContext *C)
void ED_screens_header_tools_menu_create(bContext *C, ui::Layout *layout, void *arg)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
bool ED_operator_object_active(bContext *C)
static bool area_split_menu_init(bContext *C, wmOperator *op)
static wmOperatorStatus screen_new_exec(bContext *C, wmOperator *)
bool ED_workspace_layout_cycle(WorkSpace *workspace, short direction, bContext *C) ATTR_NONNULL()
static void fullscreen_click_rcti_init(rcti *rect, const short, const short, const short x2, const short y2)
static wmOperatorStatus region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
static ScrEdge * area_findsharededge(bScreen *screen, ScrArea *area, ScrArea *sb)
eRegionView3D_View ED_view3d_lock_view_from_index(int index)
Vector< ID * > BKE_id_ordered_list(const ListBaseT< ID > *lb)
Definition lib_id.cc:2835
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void area_join_update_data(bContext *C, sAreaJoinData *jd, const wmEvent *event)
ScrArea * ED_screen_temp_space_open(bContext *C, const char *title, eSpace_Type space_type, int display_type, bool dialog) ATTR_NONNULL(1)
bool ED_operator_object_active_local_editable_posemode_exclusive(bContext *C)
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2623
bool ED_operator_object_active_editable(bContext *C)
void area_getoffsets(ScrArea *sa_a, ScrArea *sa_b, const eScreenDir dir, int *r_offset1, int *r_offset2)
static void actionzone_exit(wmOperator *op)
static wmOperatorStatus frame_jump_exec(bContext *C, wmOperator *op)
static bool region_flip_poll(bContext *C)
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
Definition screen.cc:1226
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
static void area_split_exit(bContext *C, wmOperator *op)
static void region_scale_apply_stack(RegionMoveData *rmd, const wmEvent *event, const int size_no_snap, const float aspect)
bool ED_operator_objectmode_with_view3d_poll_msg(bContext *C)
static wmOperatorStatus area_move_modal(bContext *C, wmOperator *op, const wmEvent *event)
void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip)
bool ED_operator_region_file_active(bContext *C)
void BKE_sound_init(Main *bmain)
static void actionzone_cancel(bContext *, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool ED_operator_uvedit_space_image(bContext *C)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void ob_to_keylist(bDopeSheet *ads, Object *ob, AnimKeylist *keylist, const int saction_flag, float2 range)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static wmOperatorStatus region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool ED_operator_screenactive_nobackground(bContext *C)
bool ED_operator_editfont(bContext *C)
@ SCER_WRAP_TIMELINE_NAVIGATION
static void area_join_cancel(bContext *C, wmOperator *op)
void scene_to_keylist(bDopeSheet *ads, Scene *sce, AnimKeylist *keylist, const int saction_flag, float2 range)
void BKE_spacedata_freelist(ListBaseT< SpaceLink > *lb)
Definition screen.cc:434
void ED_reset_audio_device(bContext *C)
wmWindow * WM_window_open_temp(bContext *C, const char *title, int space_type, bool dialog)
bool ED_fileselect_is_file_browser(const SpaceFile *sfile)
Definition filesel.cc:481
int RNA_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
void screen_geom_select_connected_edge(const wmWindow *win, ScrEdge *edge)
bool ED_operator_uvmap(bContext *C)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
static void SCREEN_OT_drivers_editor_show(wmOperatorType *ot)
int WM_drag_get_path_file_type(const wmDrag *drag)
static wmOperatorStatus area_swap_invoke(bContext *C, wmOperator *op, const wmEvent *event)
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
bool ED_operator_region_action_active(bContext *C)
static void area_move_apply_do(bContext *C, int delta, sAreaMoveData *md)
wmEvent * WM_event_add(wmWindow *win, const wmEvent *event_to_add)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
const EnumPropertyItem rna_enum_region_type_items[]
Definition rna_screen.cc:28
SpaceImage * CTX_wm_space_image(const bContext *C)
static void area_join_exit(bContext *C, wmOperator *op)
SpaceLink * CTX_wm_space_data(const bContext *C)
@ V2D_SCROLL_HORIZONTAL
static bool area_split_allowed(const ScrArea *area, const eScreenAxis dir_axis)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
Mesh * ED_mesh_context(bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
void ED_areas_do_frame_follow(bContext *C, bool center_view)
void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
static float area_split_factor(bContext *C, sAreaJoinData *jd, const wmEvent *event)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void screen_animate_area_highlight(wmWindow *win, bScreen *screen, const rcti *rect, float inner[4], float outline[4], float seconds)
const EnumPropertyItem rna_enum_preference_section_items[]
bool ED_operator_objectmode(bContext *C)
bool ED_view3d_lock(RegionView3D *rv3d)
static void SCREEN_OT_time_jump(wmOperatorType *ot)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ WM_CURSOR_HAND_CLOSED
Definition wm_cursors.hh:25
@ WM_CURSOR_MOVE
Definition wm_cursors.hh:23
@ WM_CURSOR_Y_MOVE
Definition wm_cursors.hh:42
@ WM_CURSOR_H_SPLIT
Definition wm_cursors.hh:43
@ WM_CURSOR_E_ARROW
Definition wm_cursors.hh:51
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:21
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
@ WM_CURSOR_SWAP_AREA
Definition wm_cursors.hh:40
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
@ WM_CURSOR_STOP
Definition wm_cursors.hh:20
@ WM_CURSOR_X_MOVE
Definition wm_cursors.hh:41
@ WM_CURSOR_PICK_AREA
Definition wm_cursors.hh:64
@ WM_CURSOR_S_ARROW
Definition wm_cursors.hh:50
@ WM_CURSOR_W_ARROW
Definition wm_cursors.hh:52
@ WM_CURSOR_V_SPLIT
Definition wm_cursors.hh:44
@ WM_CURSOR_N_ARROW
Definition wm_cursors.hh:49
static void screen_modal_action_end()
@ USER_TEMP_SPACE_DISPLAY_WINDOW
static void area_move_set_limits(wmWindow *win, bScreen *screen, const eScreenAxis dir_axis, int *bigger, int *smaller, bool *use_bigger_smaller_snap)
bool WM_operator_winactive(bContext *C)
static bool is_split_edge(const int alignment, const AZEdge edge)
static int area_join_cursor(sAreaJoinData *jd, const wmEvent *event)
void ED_screen_full_prevspace(bContext *C, ScrArea *area)
void ED_area_init(bContext *C, const wmWindow *win, ScrArea *area)
Definition area.cc:2383
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
static void SCREEN_OT_area_move(wmOperatorType *ot)
static bool screen_drop_scene_poll(bContext *C, wmDrag *drag, const wmEvent *)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
bool ED_operator_posemode_local(bContext *C)
static ScrArea * screen_actionzone_area(bScreen *screen, const AZone *az)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
static void SCREEN_OT_repeat_history(wmOperatorType *ot)
void screen_geom_select_extended_edge(const wmWindow *win, ScrEdge *edge)
static void SCREEN_OT_region_quadview(wmOperatorType *ot)
static void area_move_cancel(bContext *C, wmOperator *op)
bool ED_operator_active_screen_and_scene(bContext *C)
static const EnumPropertyItem space_context_cycle_direction[]
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
static void SCREEN_OT_animation_play(wmOperatorType *ot)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
static void area_split_preview_update_cursor(bContext *C, wmOperator *op)
static int wrap_frame_in_range(const int frame, const ScenePlaybackRange &range)
static wmOperatorStatus space_context_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool blend_file_drop_poll(bContext *, wmDrag *drag, const wmEvent *)
@ ANIMPLAY_FLAG_REVERSE
@ ANIMPLAY_FLAG_USE_NEXT_FRAME
@ ANIMPLAY_FLAG_NO_SYNC
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static wmOperatorStatus area_move_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmWindow * ED_window_animation_playing_no_scrub(const wmWindowManager *wm)
bool ED_operator_region_view3d_active(bContext *C)
static wmOperatorStatus area_edge_merge_exec(bContext *C, wmOperator *op)
static std::string userpref_show_get_description(bContext *C, wmOperatorType *, PointerRNA *ptr)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
void ED_drivers_editor_init(bContext *C, ScrArea *area)
bool ED_operator_screen_mainwinactive(bContext *C)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
static wmOperatorStatus frame_jump_delta_exec(bContext *C, wmOperator *op)
bool ED_operator_info_active(bContext *C)
bool ED_operator_editmesh_region_view3d(bContext *C)
Scene * ED_screen_find_playing_scene(const bScreen *screen, bool scrub=false)
@ FILE_TYPE_BLENDER_BACKUP
static void SCREEN_OT_repeat_last(wmOperatorType *ot)
void screen_draw_join_highlight(const wmWindow *win, ScrArea *sa1, ScrArea *sa2, eScreenDir dir, float anim_factor)
wmOperator * WM_operator_last_redo(const bContext *C)
bool WM_operator_repeat_check(const bContext *, wmOperator *op)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
void BKE_sound_stop_scene(Scene *scene)
@ G_TRANSFORM_WM
@ KM_NOTHING
Definition WM_types.hh:323
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
double BLI_time_now_seconds()
Definition time.cc:30
void mask_to_keylist(bDopeSheet *, MaskLayer *masklay, AnimKeylist *keylist)
static void screen_area_touch_menu_create(bContext *C, ScrArea *area)
void ED_view3d_lastview_store(RegionView3D *rv3d)
WorkSpaceLayout * BKE_workspace_active_layout_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:657
void ED_keylist_free(AnimKeylist *keylist)
static wmOperatorStatus screen_animation_cancel_exec(bContext *C, wmOperator *op)
SpaceFile * CTX_wm_space_file(const bContext *C)
static void SCREEN_OT_area_swap(wmOperatorType *ot)
static bool area_join_poll(bContext *C)
bool void ED_scene_fps_average_clear(Scene *scene) ATTR_NONNULL(1)
Definition scene_fps.cc:48
static wmOperatorStatus screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void WM_cursor_set(wmWindow *win, int curs)
int screen_geom_area_height(const ScrArea *area)
void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
bool ED_operator_editmesh_view3d(bContext *C)
void ED_screens_region_flip_menu_create(bContext *C, ui::Layout *layout, void *arg)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
static bool match_region_with_redraws(const ScrArea *area, eRegion_Type regiontype, eScreen_Redraws_Flag redraws, bool from_anim_edit)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
static wmOperatorStatus area_join_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO_GROUPED
Definition WM_types.hh:215
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
@ RGN_FLAG_NO_USER_RESIZE
@ RGN_FLAG_HIDDEN_BY_USER
@ RGN_FLAG_RESIZE_RESPECT_BUTTON_SECTIONS
static void SCREEN_OT_project_settings_show(wmOperatorType *ot)
static void SCREEN_OT_screen_full_area(wmOperatorType *ot)
void ED_screen_scrubbing_disable(bContext &C, bScreen &screen, const std::optional< PreScrubbingState > &resume)
FCurve * BKE_fcurve_find_by_rna_context_ui(bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **r_animdata, bAction **r_action, bool *r_driven, bool *r_special)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
const ListBaseT< ActKeyColumn > * ED_keylist_listbase(const AnimKeylist *keylist)
static void SCREEN_OT_keyframe_jump(wmOperatorType *ot)
static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *sa2)
static bool keyframe_jump_poll(bContext *C)
bool ED_operator_sequencer_active(bContext *C)
static bool area_dupli_open(bContext *C, ScrArea *area, const int2 position)
static wmOperatorStatus screen_maximize_area_exec(bContext *C, wmOperator *op)
static void area_join_dock_cb(const wmWindow *win, void *userdata)
void * WM_draw_cb_activate(wmWindow *win, void(*draw)(const wmWindow *win, void *customdata), void *customdata)
Definition wm_draw.cc:639
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus repeat_history_invoke(bContext *C, wmOperator *op, const wmEvent *)
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
static bool actionzone_area_poll(bContext *C)
bool ED_operator_editsurf(bContext *C)
void ED_buttons_visible_tabs_menu(bContext *C, ui::Layout *layout, void *)
void region_toggle_hidden(bContext *C, ARegion *region, const bool do_fade)
Definition area.cc:2606
static void SCREEN_OT_quadview_size(wmOperatorType *ot)
static bool area_has_scrubbing_snap(ScrArea *area)
void WM_event_add_mousemove(wmWindow *win)
static void screen_drop_scene_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
bool ED_operator_object_active_editable_mesh_from_view_layer(bContext *C)
bool ED_operator_region_outliner_active(bContext *C)
bool ED_operator_image_active(bContext *C)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
static wmOperatorStatus area_split_exec(bContext *C, wmOperator *op)
ViewLayer * BKE_view_layer_default_render(const Scene *scene)
bool ED_operator_object_active_editable_mesh(bContext *C)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
static bool operator_screenactive_norender(bContext *C)
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
static void ed_screens_statusbar_menu_create(ui::Layout &layout, void *)
static void area_join_draw_cb(const wmWindow *win, void *userdata)
bScreen * WM_window_get_active_screen(const wmWindow *win)
static wmOperatorStatus keyframe_jump_exec(bContext *C, wmOperator *op)
static void region_blend_invalidate_visible_rect(ScrArea *area)
MINLINE int min_ii(int a, int b)
bool ED_operator_editmball(bContext *C)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
static void SCREEN_OT_delete(wmOperatorType *ot)
static void blend_file_drop_copy(bContext *, wmDrag *drag, wmDropBox *drop)
void screen_draw_move_highlight(const wmWindow *win, bScreen *screen, eScreenAxis dir_axis, float anim_factor)
static float area_docking_snap(const float pos, const wmEvent *event)
ARegion * CTX_wm_region(const bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static void stop_playback(bContext *C)
void SCREEN_OT_screenshot(wmOperatorType *ot)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
bool ED_space_image_show_uvedit(const SpaceImage *sima, Object *obedit)
static wmOperatorStatus fullscreen_back_exec(bContext *C, wmOperator *op)
bool ED_operator_region_graphedit_active(bContext *C)
static void area_join_dock_cb_window(sAreaJoinData *jd, wmOperator *op)
static std::string screen_drop_scene_tooltip(bContext *, wmDrag *drag, const int[2], wmDropBox *)
float RNA_float_get(PointerRNA *ptr, const char *name)
static void SCREEN_OT_space_type_set_or_cycle(wmOperatorType *ot)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
wmOperatorStatus WM_operator_repeat_last(bContext *C, wmOperator *op)
WorkSpaceLayout * BKE_workspace_layout_find(const WorkSpace *workspace, const bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition workspace.cc:499
void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other)
void wm_event_init_from_window(wmWindow *win, wmEvent *event)
static void SCREEN_OT_header_toggle_menus(wmOperatorType *ot)
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
static void region_scale_cancel(bContext *, wmOperator *op)
static wmOperatorStatus header_toggle_menus_exec(bContext *C, wmOperator *)
static bool area_move_reinit(bContext *C, wmOperator *op, bool extend, const int xy[2])
static void area_move_draw_cb(const wmWindow *win, void *userdata)
static bool ed_object_hidden(const Object *ob)
void BKE_screen_remove_double_scredges(bScreen *screen)
Definition screen.cc:901
bool WM_window_is_temp_screen(const wmWindow *win)
@ AREA_FLAG_REGION_SIZE_UPDATE
@ AREA_FLAG_ACTIONZONES_UPDATE
bool ED_area_is_global(const ScrArea *area)
Definition area.cc:4451
bool ED_operator_screenactive(bContext *C)
static bool ed_operator_posemode_exclusive_ex(bContext *C, Object *obact)
static wmOperatorStatus region_quadview_exec(bContext *C, wmOperator *op)
@ AZ_SCROLL_VERT
@ AZ_SCROLL_HOR
void screen_geom_edge_aligned_merge(const wmWindow *win, ScrEdge *edge)
void screen_draw_region_scale_highlight(ARegion *region)
static wmOperatorStatus quadview_size_modal(bContext *C, wmOperator *op, const wmEvent *event)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
bool ED_operator_file_browsing_active(bContext *C)
static AreaDockTarget area_docking_target(sAreaJoinData *jd, const wmEvent *event)
static wmOperatorStatus area_join_exec(bContext *C, wmOperator *op)
static bool area_has_playback_snap(ScrArea *area)
void void BLI_INLINE bool BLI_listbase_is_single(const ListBase *lb)
void CTX_wm_area_set(bContext *C, ScrArea *area)
bool BKE_object_pose_context_check(const Object *ob)
Definition object.cc:2498
static void area_split_draw_cb(const wmWindow *, void *userdata)
static wmOperatorStatus area_join_modal(bContext *C, wmOperator *op, const wmEvent *event)
#define floorf
#define AREA_DOCK_FADEOUT
#define AREA_MOVE_LINE_FADEIN
#define AZONEFADEIN
#define SCREEN_DIR_IS_VERTICAL(dir)
#define AREA_SPLIT_FADEOUT
#define AZONEFADEOUT
#define AREA_CLOSE_FADEOUT
#define AREA_JOIN_FADEOUT
#define AREA_DOCK_FADEIN
#define AREA_MOVE_LINE_FADEOUT
#define KM_MODAL_APPLY
#define KM_MODAL_CANCEL
#define TIMEOUT
#define KM_MODAL_SNAP_ON
#define TIMESTEP
#define KM_MODAL_SNAP_OFF
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void(*) on_user_resize(const ARegion *region)
int(*) snap_size(const ARegion *region, int size, int axis)
struct ARegion * next
bke::ARegionRuntime * runtime
struct ARegion * prev
eRegion_Alignment alignment
eRegion_Type regiontype
ARegion * region
EditNurb * editnurb
eFCurve_Flags flag
int icon_id
Definition DNA_ID.h:445
unsigned int recalc
Definition DNA_ID.h:446
ListBaseT< WorkSpace > workspaces
Definition BKE_main.hh:423
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
eObject_VisibilityFlag visibility_flag
eRegionView3D_ViewLockQuad viewlock_quad
struct RegionView3D * localvd
eRegionView3D_Flag rflag
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_ViewLock runtime_viewlock
eRegionView3D_Persp persp
eRegionView3D_ViewLock viewlock
eRegionView3D_View view
bool contains(const int frame) const
Definition BKE_scene.hh:205
eScenePlaybackLoopMode playback_loop_mode
struct RenderData r
struct AudioData audio
ListBaseT< ScrArea > areabase
ListBaseT< struct AZone > actionzones
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
ScrGlobalAreaData * global
struct SpaceType * type
eAnimEdit_Context mode
eGraphEdit_Mode mode
struct bNodeTree * edittree
eView2D_KeepTot keeptot
eView2D_Scroll scroll
struct Object * camera
eAnimCont_Types datatype
eDopeSheet_FilterFlag filterflag
eScreen_State state
struct wmTimer * animtimer
struct ARegion * active_region
ListBaseT< struct ScrVert > vertbase
ListBaseT< struct ScrArea > areabase
eScreen_Redraws_Flag redraws_flag
struct ARegionType * type
AreaDockTarget dock_target
AreaMoveSnapType snap_type
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void menu_fn(StringRefNull name, int icon, MenuCreateFunc func, void *arg)
AssetImportSettings import_settings
Definition WM_types.hh:1338
eWM_DragDataType type
Definition WM_types.hh:1424
PointerRNA * ptr
Definition WM_types.hh:1524
wmEventType type
Definition WM_types.hh:817
wmEventModifierFlag modifier
Definition WM_types.hh:834
const char * undo_group
Definition WM_types.hh:1117
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports
struct wmOperatorType * type
wmTimerFlags flags
Definition WM_types.hh:1033
wmWindow * win
Definition WM_types.hh:1026
bke::WindowRuntime * runtime
struct WorkSpaceInstanceHook * workspace_hook