Blender V5.3
wm_gizmo_map.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "BLI_enum_flags.hh"
12#include "BLI_ghash.hh"
13#include "BLI_listbase.hh"
14#include "BLI_math_vector_c.hh"
16#include "BLI_rect.hh"
17#include "BLI_vector.hh"
18
19#include "BKE_context.hh"
20#include "BKE_global.hh"
21#include "BKE_main.hh"
22#include "BKE_screen.hh"
23
24#include "ED_screen.hh"
25#include "ED_select_utils.hh"
26#include "ED_view3d.hh"
27
28#include "GPU_framebuffer.hh"
29#include "GPU_matrix.hh"
30#include "GPU_select.hh"
31#include "GPU_state.hh"
32#include "GPU_viewport.hh"
33
34#include "MEM_guardedalloc.h"
35
36#include "WM_api.hh"
37#include "WM_types.hh"
38#include "wm_event_system.hh"
39
40/* For tool-tips. */
41#include "UI_interface.hh"
42
43#include "DEG_depsgraph.hh"
44
45/* Own includes. */
46#include "wm_gizmo_intern.hh"
47#include "wm_gizmo_wmapi.hh"
48
49namespace blender {
50
55static ListBaseT<wmGizmoMapType> gizmomaptypes = {nullptr, nullptr};
56
60/* So operator removal can trigger update. */
81
84
88enum {
92};
93
94/* -------------------------------------------------------------------- */
100
102{
103 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
104 if (len <= msel->len_alloc) {
105 return;
106 }
107 msel->items = static_cast<wmGizmo **>(
108 MEM_realloc_uninitialized(msel->items, sizeof(*msel->items) * len));
109 msel->len_alloc = len;
110}
111
113{
114 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
115 MEM_SAFE_DELETE(msel->items);
116 msel->len = 0;
117 msel->len_alloc = 0;
118}
119
120void wm_gizmomap_select_array_shrink(wmGizmoMap *gzmap, int len_subtract)
121{
122 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
123 msel->len -= len_subtract;
124 if (msel->len <= 0) {
126 }
127 else {
128 if (msel->len < msel->len_alloc / 2) {
129 msel->items = static_cast<wmGizmo **>(
130 MEM_realloc_uninitialized(msel->items, sizeof(*msel->items) * msel->len));
131 msel->len_alloc = msel->len;
132 }
133 }
134}
135
137{
138 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
139 BLI_assert(msel->len <= msel->len_alloc);
140 if (msel->len == msel->len_alloc) {
141 msel->len_alloc = (msel->len + 1) * 2;
142 msel->items = static_cast<wmGizmo **>(
143 MEM_realloc_uninitialized(msel->items, sizeof(*msel->items) * msel->len_alloc));
144 }
145 msel->items[msel->len++] = gz;
146}
147
149{
150 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
151 /* Remove gizmo from selected_gizmos array. */
152 for (int i = 0; i < msel->len; i++) {
153 if (msel->items[i] == gz) {
154 for (int j = i; j < (msel->len - 1); j++) {
155 msel->items[j] = msel->items[j + 1];
156 }
158 break;
159 }
160 }
161}
162
164
165/* -------------------------------------------------------------------- */
168
170{
171 gzmap->type = gzmap_type;
172 gzmap->is_init = true;
174
175 /* Create all gizmo-groups for this gizmo-map. We may create an empty one
176 * too in anticipation of gizmos from operators etc. */
177 for (wmGizmoGroupTypeRef &gzgt_ref : gzmap_type->grouptype_refs) {
178 wm_gizmogroup_new_from_type(gzmap, gzgt_ref.type);
179 }
180
181 return gzmap;
182}
183
185{
186 wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(gzmap_params);
187 wmGizmoMap *gzmap = MEM_new_zeroed<wmGizmoMap>("GizmoMap");
188 wm_gizmomap_new_from_type_ex(gzmap_type, gzmap);
189 return gzmap;
190}
191
193{
194 /* Clear first so further calls don't waste time trying to maintain correct array state. */
196
197 for (wmGizmoGroup *gzgroup = gzmap->groups.first(), *gzgroup_next; gzgroup;
198 gzgroup = gzgroup_next)
199 {
200 gzgroup_next = gzgroup->next;
201 BLI_assert(gzgroup->parent_gzmap == gzmap);
202 wm_gizmogroup_free(nullptr, gzgroup);
203 }
204 BLI_assert(gzmap->groups.is_empty());
205}
206
208{
210 MEM_delete(gzmap);
211}
212
214{
215 wmGizmoMapType *gzmap_type = gzmap->type;
217 memset(gzmap, 0x0, sizeof(*gzmap));
218 wm_gizmomap_new_from_type_ex(gzmap_type, gzmap);
219}
220
222{
223 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
224 if (gzgt) {
225 return WM_gizmomap_group_find_ptr(gzmap, gzgt);
226 }
227 return nullptr;
228}
229
231{
232 for (wmGizmoGroup &gzgroup : gzmap->groups) {
233 if (gzgroup.type == gzgt) {
234 return &gzgroup;
235 }
236 }
237 return nullptr;
238}
239
240const ListBaseT<wmGizmoGroup> *WM_gizmomap_group_list(wmGizmoMap *gzmap)
241{
242 return &gzmap->groups;
243}
244
246{
247 return gzmap->gzmap_context.select.len != 0;
248}
249
251{
252 return gzmap->gzmap_context.modal;
253}
254
256 const wmGizmoMap *gzmap, bool /*use_hidden*/, bool use_select, float r_min[3], float r_max[3])
257{
258 if (use_select) {
259 int i;
260 for (i = 0; i < gzmap->gzmap_context.select.len; i++) {
261 minmax_v3v3_v3(r_min, r_max, gzmap->gzmap_context.select.items[i]->matrix_basis[3]);
262 }
263 return i != 0;
264 }
265
266 bool ok = false;
267 BLI_assert_msg(0, "TODO");
268 return ok;
269}
270
281 wmGizmoMap *gzmap,
282 bool (*poll)(const wmGizmo *, void *),
283 void *data,
284 const eWM_GizmoFlag flag_exclude)
285{
287
288 /* Collect gizmos. */
289 for (wmGizmoGroup &gzgroup : gzmap->groups) {
290 if (WM_gizmo_group_type_poll(C, gzgroup.type)) {
291 for (wmGizmo &gz : gzgroup.gizmos) {
292 if (((flag_exclude == 0) || ((gz.flag & flag_exclude) == 0)) && (!poll || poll(&gz, data)))
293 {
294 hash.add(&gz);
295 }
296 }
297 }
298 }
299
300 return hash;
301}
302
314
316{
318 if (gzmap) {
320 /* This could be split out into a separate tagging function,
321 * in practice both when refreshing the highlight should also be updated. */
322 gzmap->tag_highlight_pending = true;
323 }
324}
325
327{
328 if (gzmap) {
329 for (int i = 0; i < WM_GIZMOMAP_DRAWSTEP_MAX; i++) {
331 }
332 /* See code-comment for #WM_gizmomap_tag_refresh_drawstep. */
333 gzmap->tag_highlight_pending = true;
334 }
335}
336
338{
339 for (wmGizmoGroup &gzgroup : gzmap->groups) {
340 if (gzgroup.hide.delay_refresh_for_tweak) {
341 return true;
342 }
343 }
344 return false;
345}
346
348 wmGizmo *gz,
349 const bContext *C,
350 ListBaseT<LinkData> *draw_gizmos,
351 const eWM_GizmoFlagMapDrawStep drawstep)
352{
353 int do_draw = wm_gizmo_is_visible(gz);
354 if (do_draw == 0) {
355 /* Skip. */
356 }
357 else {
358 /* Ensure we get RNA updates. */
359 if (do_draw & WM_GIZMO_IS_VISIBLE_UPDATE) {
360 /* Hover gizmos need updating, even if we don't draw them. */
361 wm_gizmo_update(gz, C, (gzmap->update_flag[drawstep] & GIZMOMAP_IS_PREPARE_DRAW) != 0);
362 }
363 if (do_draw & WM_GIZMO_IS_VISIBLE_DRAW) {
364 BLI_addhead(draw_gizmos, BLI_genericNodeN(gz));
365 }
366 return true;
367 }
368
369 return false;
370}
371
377 const bContext *C,
378 ListBaseT<LinkData> *draw_gizmos,
379 const eWM_GizmoFlagMapDrawStep drawstep)
380{
381 if (!gzmap || gzmap->groups.is_empty()) {
382 return;
383 }
384
385 gzmap->is_init = false;
386
387 wmGizmo *gz_modal = gzmap->gzmap_context.modal;
388
389 /* Allow refresh functions to ask to be refreshed again, clear before the loop below. */
390 const bool do_refresh = gzmap->update_flag[drawstep] & GIZMOMAP_IS_REFRESH_CALLBACK;
391 gzmap->update_flag[drawstep] &= ~GIZMOMAP_IS_REFRESH_CALLBACK;
392
393 for (wmGizmoGroup &gzgroup : gzmap->groups) {
394 /* Check group visibility - drawstep first to avoid unnecessary call of group poll callback. */
395 if (!wm_gizmogroup_is_visible_in_drawstep(&gzgroup, drawstep)) {
396 continue;
397 }
398
399 if (gz_modal && (&gzgroup == gz_modal->parent_gzgroup)) {
401 continue;
402 }
403 }
404 else { /* Don't poll modal gizmo since some poll functions unlink. */
405 if (!WM_gizmo_group_type_poll(C, gzgroup.type)) {
406 continue;
407 }
408 /* When modal only show other gizmo groups tagged with #WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL. */
409 if (gz_modal && ((gzgroup.type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0)) {
410 continue;
411 }
412 }
413
414 /* Needs to be initialized on first draw. */
415 /* XXX weak: Gizmo-group may skip refreshing if it's invisible
416 * (map gets untagged nevertheless). */
417 if (do_refresh) {
418 /* Force refresh again. */
420 }
421 /* Calls `setup`, `setup_keymap` and `refresh` if they're defined. */
422 WM_gizmogroup_ensure_init(C, &gzgroup);
423
424 /* Check after ensure which can run refresh and update this value. */
425 if (gzgroup.hide.any != 0) {
426 continue;
427 }
428
429 /* Prepare drawing. */
430 if (gzgroup.type->draw_prepare) {
431 gzgroup.type->draw_prepare(C, &gzgroup);
432 }
433
434 for (wmGizmo &gz : gzgroup.gizmos) {
435 gizmo_prepare_drawing(gzmap, &gz, C, draw_gizmos, drawstep);
436 }
437
438 if (gzgroup.type->draw_background) {
439 gzgroup.type->draw_background(C, &gzgroup);
440 }
441 }
442
443 gzmap->update_flag[drawstep] &= ~GIZMOMAP_IS_PREPARE_DRAW;
444}
445
450static void gizmos_draw_list(const wmGizmoMap *gzmap,
451 const bContext *C,
452 ListBaseT<LinkData> *draw_gizmos)
453{
454 /* Can be empty if we're dynamically added and removed. */
455 if ((gzmap == nullptr) || gzmap->groups.is_empty()) {
456 return;
457 }
458
459 /* TODO(@ideasman42): This will need its own shader probably?
460 * Don't think it can be handled from that point though. */
461 // const bool use_lighting = (U.gizmo_flag & V3D_GIZMO_SHADED) != 0;
462
463 bool is_depth_prev = false;
464
465 /* `draw_gizmos` contains all visible gizmos - draw them. */
466 for (LinkData &link : draw_gizmos->items_mutable()) {
467 wmGizmo *gz = static_cast<wmGizmo *>(link.data);
468 bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0;
469
470 /* Weak! since we don't 100% support depth yet (select ignores depth)
471 * always show highlighted. */
472 if (is_depth && (gz->state & WM_GIZMO_STATE_HIGHLIGHT)) {
473 is_depth = false;
474 }
475
476 if (is_depth == is_depth_prev) {
477 /* Pass. */
478 }
479 else {
480 if (is_depth) {
482 }
483 else {
485 }
486 is_depth_prev = is_depth;
487 }
488
489 /* XXX force AntiAlias Gizmos. */
490 GPU_line_smooth(true);
491 GPU_polygon_smooth(true);
492
493 gz->type->draw(C, gz);
494
495 GPU_line_smooth(false);
496 GPU_polygon_smooth(false);
497
498 /* Free/remove gizmo link after drawing. */
499 BLI_freelinkN(draw_gizmos, &link);
500 }
501
502 if (is_depth_prev) {
504 }
505}
506
508 const bContext *C,
509 const eWM_GizmoFlagMapDrawStep drawstep)
510{
511 if (!WM_gizmo_context_check_drawstep(C, drawstep)) {
512 return;
513 }
514
515 ListBaseT<LinkData> draw_gizmos = {nullptr};
516
517 gizmomap_prepare_drawing(gzmap, C, &draw_gizmos, drawstep);
518 gizmos_draw_list(gzmap, C, &draw_gizmos);
519 BLI_assert(draw_gizmos.is_empty());
520}
521
523 wmGizmo **visible_gizmos,
524 const int visible_gizmos_len,
525 bool *r_use_select_bias)
526{
527 /* WORKAROUND(#132196): `GPU_DEPTH_NONE` leads to issues with Intel GPU drivers on Windows
528 * where camera gizmos cannot be shifted. `glGetQueryObjectuiv` for `GL_SAMPLES_PASSED`
529 * seems to return zero in all cases. This might be due to undefined behavior of OpenGL
530 * when the depth test is disabled and rendering to a depth render target-only framebuffer.
531 * Using `GPU_DEPTH_ALWAYS` fixes the issue. */
532 const bool use_intel_gpu_workaround = true;
533
534 /* Set default depth state. */
535 GPU_depth_test(use_intel_gpu_workaround ? GPU_DEPTH_ALWAYS : GPU_DEPTH_NONE);
536 GPU_depth_mask(true);
537 bool is_depth_prev = false;
538 bool is_depth_skip_prev = false;
539
540 for (int select_id = 0; select_id < visible_gizmos_len; select_id++) {
541 wmGizmo *gz = visible_gizmos[select_id];
542 if (gz->type->draw_select == nullptr) {
543 continue;
544 }
545
546 bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0;
547 if (is_depth == is_depth_prev) {
548 /* Pass. */
549 }
550 else {
551 if (is_depth) {
553 }
554 else {
555 GPU_depth_test(use_intel_gpu_workaround ? GPU_DEPTH_ALWAYS : GPU_DEPTH_NONE);
556 }
557 is_depth_prev = is_depth;
558 }
559 bool is_depth_skip = (gz->flag & WM_GIZMO_SELECT_BACKGROUND) != 0;
560 if (is_depth_skip == is_depth_skip_prev) {
561 /* Pass. */
562 }
563 else {
564 GPU_depth_mask(!is_depth_skip);
565 is_depth_skip_prev = is_depth_skip;
566 }
567
568 if (gz->select_bias != 0.0) {
569 *r_use_select_bias = true;
570 }
571
572 /* Pass the selection id shifted by 8 bits. Last 8 bits are used for selected gizmo part id. */
573
574 gz->type->draw_select(C, gz, select_id << 8);
575 }
576
577 /* Reset depth state. */
578
579 if (is_depth_prev || use_intel_gpu_workaround) {
581 }
582 if (is_depth_skip_prev) {
583 GPU_depth_mask(true);
584 }
585}
586
587static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos,
588 const int visible_gizmos_len,
589 const bContext *C,
590 const int co[2],
591 const int hotspot)
592{
594 ScrArea *area = CTX_wm_area(C);
595 ARegion *region = CTX_wm_region(C);
596 View3D *v3d = area->spacedata.first_as<View3D>();
597 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
598 rcti rect;
599 /* Almost certainly overkill, but allow for many custom gizmos. */
600 GPUSelectBuffer buffer;
601 short hits;
602
603 BLI_rcti_init_pt_radius(&rect, co, hotspot);
604
606 wm, CTX_wm_window(C), depsgraph, CTX_data_scene(C), region, v3d, nullptr, nullptr, &rect);
607
608 bool use_select_bias = false;
609
610 /* TODO: waiting for the GPU in the middle of the event loop for every
611 * mouse move is bad for performance, we need to find a solution to not
612 * use the GPU or draw something once, see #61474. */
614 /* Do the drawing. */
615 gizmo_draw_select_3d_loop(C, visible_gizmos, visible_gizmos_len, &use_select_bias);
616
617 hits = GPU_select_end();
618
619 if (hits > 0) {
621 gizmo_draw_select_3d_loop(C, visible_gizmos, visible_gizmos_len, &use_select_bias);
623 }
624
626 wm, CTX_wm_window(C), depsgraph, CTX_data_scene(C), region, v3d, nullptr, nullptr, nullptr);
627
628 const Span<GPUSelectResult> hit_results = buffer.storage.as_span().take_front(hits);
629 if (use_select_bias && (hits > 1)) {
630 float co_direction[3];
631 float co_screen[3] = {float(co[0]), float(co[1]), 0.0f};
632 ED_view3d_win_to_vector(region, float2{float(co[0]), float(co[1])}, co_direction);
633
634 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
635 const int viewport[4] = {0, 0, region->winx, region->winy};
636 float co_3d_origin[3];
637
638 GPU_matrix_unproject_3fv(co_screen, rv3d->viewinv, rv3d->winmat, viewport, co_3d_origin);
639
640 int hit_found = -1;
641 float dot_best = FLT_MAX;
642
643 for (const GPUSelectResult &hit_result : hit_results) {
644 BLI_assert(hit_result.id != -1);
645 wmGizmo *gz = visible_gizmos[hit_result.id >> 8];
646 float co_3d[3];
647 co_screen[2] = float(double(hit_result.depth) / double(UINT_MAX));
648 GPU_matrix_unproject_3fv(co_screen, rv3d->viewinv, rv3d->winmat, viewport, co_3d);
649 float select_bias = gz->select_bias;
650 if ((gz->flag & WM_GIZMO_DRAW_NO_SCALE) == 0) {
651 /* Use the larger of the gizmo's final scale and a small minimum threshold to prevent the
652 * selection bias from collapsing when the gizmo becomes extremely small. See #100321. */
653 const float scale = std::max(gz->scale_final, 1e-2f);
654 select_bias *= scale;
655 }
656 sub_v3_v3(co_3d, co_3d_origin);
657 const float dot_test = dot_v3v3(co_3d, co_direction) - select_bias;
658 if (dot_best > dot_test) {
659 dot_best = dot_test;
660 hit_found = hit_result.id;
661 }
662 }
663 return hit_found;
664 }
665
666 const GPUSelectResult *hit_near = GPU_select_buffer_near(hit_results);
667 return hit_near ? hit_near->id : -1;
668}
669
674 const int co[2],
675 wmGizmo **visible_gizmos,
676 const int visible_gizmos_len,
677 int *r_part)
678{
679 wmGizmo *result = nullptr;
680 int visible_gizmos_len_trim = visible_gizmos_len;
681 int hit = -1;
682
683 *r_part = 0;
684
685 /* Set up view matrices. */
687
688 /* Search for 3D gizmo's that use the 2D callback for checking intersections. */
689 bool has_3d = false;
690 {
691 for (int select_id = 0; select_id < visible_gizmos_len; select_id++) {
692 wmGizmo *gz = visible_gizmos[select_id];
693 /* With both defined, favor the 3D, in case the gizmo can be used in 2D or 3D views. */
694 if (gz->type->test_select && (gz->type->draw_select == nullptr)) {
695 if ((*r_part = gz->type->test_select(C, gz, co)) != -1) {
696 hit = select_id;
697 result = gz;
698 /* Don't search past this when checking intersections. */
699 visible_gizmos_len_trim = select_id;
700 break;
701 }
702 }
703 else if (gz->type->draw_select != nullptr) {
704 has_3d = true;
705 }
706 }
707 }
708
709 /* Search for 3D intersections if they're before 2D that have been found (if any).
710 * This way we always use the first hit. */
711 if (has_3d) {
712
713 /* The depth buffer is needed for gizmos to obscure each other. */
715
716 /* When switching between modes and the mouse pointer is over a gizmo, the highlight test is
717 * performed before the viewport is fully initialized (region->runtime->draw_buffer = nullptr).
718 * When this is the case we should not use depth testing. */
719 if (viewport == nullptr) {
720 return nullptr;
721 }
722 gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport);
723 gpu::FrameBuffer *depth_read_fb = nullptr;
724 GPU_framebuffer_ensure_config(&depth_read_fb,
725 {
726 GPU_ATTACHMENT_TEXTURE(depth_tx),
728 });
729 GPU_framebuffer_bind(depth_read_fb);
730
731 /* NOTE(@ideasman42): Regarding the hit-radius:
732 *
733 * - These must remain constant for all event types
734 * since changing the radius per event types means non-motion events
735 * can cause the gizmo not to be highlighted.
736 * - A single large radius would result in gizmos that are further away from the cursor
737 * with a nearer Z-depth being highlighted.
738 * So only use the larger radius when the first (smaller) pass has no hits.
739 * - As this runs on cursor-motion, avoid doing too many tests (currently 2x).
740 */
741 const int hotspot_radii[] = {
742 /* Use a small value so it's possible to accurately pick a gizmo
743 * when multiple are overlapping. */
744 int(3.0f * UI_SCALE_FAC),
745 /* Use a larger value as a fallback so wire gizmos aren't difficult to click on. */
746 int(10.0f * UI_SCALE_FAC),
747 };
748 for (int i = 0; i < ARRAY_SIZE(hotspot_radii); i++) {
750 visible_gizmos, visible_gizmos_len_trim, C, co, hotspot_radii[i]);
751 if (hit != -1) {
752 break;
753 }
754 }
755
757 GPU_framebuffer_free(depth_read_fb);
758
759 if (hit != -1) {
760 const int select_id = hit >> 8;
761 const int select_part = hit & 0xff;
762 BLI_assert(select_id < visible_gizmos_len);
763 *r_part = select_part;
764 result = visible_gizmos[select_id];
765 }
766 }
767
768 return result;
769}
770
772{
773 return gzmap->tag_highlight_pending;
774}
776{
777 return gzmap->tag_highlight_pending = false;
778}
779
781 bContext *C,
782 const wmEvent *event,
783 int *r_part)
784{
786 wmGizmo *gz = nullptr;
787 Vector<wmGizmo *, 128> visible_3d_gizmos;
788 bool do_step[WM_GIZMOMAP_DRAWSTEP_MAX];
789
790 int mval[2];
791 if (event->val == KM_PRESS_DRAG) {
793 }
794 else {
795 copy_v2_v2_int(mval, event->mval);
796 }
797
798 for (int i = 0; i < ARRAY_SIZE(do_step); i++) {
800 }
801
802 for (wmGizmoGroup &gzgroup : gzmap->groups) {
803
804 /* If it were important we could initialize here,
805 * but this only happens when events are handled before drawing,
806 * just skip to keep code-path for initializing gizmos simple. */
807 if ((gzgroup.hide.any != 0) || ((gzgroup.init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0)) {
808 continue;
809 }
810
811 if (WM_gizmo_group_type_poll(C, gzgroup.type)) {
813 if (do_step[step]) {
815 WM_gizmo_group_refresh(C, &gzgroup);
816 /* Cleared below. */
817 }
820 wm, &gzgroup, event->modifier, &visible_3d_gizmos);
821 }
822 else if (step == WM_GIZMOMAP_DRAWSTEP_2D) {
824 wm, &gzgroup, C, event->modifier, mval, r_part)))
825 {
826 break;
827 }
828 }
829 }
830 }
831 }
832
833 if (!visible_3d_gizmos.is_empty()) {
834 /* 2D gizmos get priority. */
835 if (gz == nullptr) {
837 C, mval, visible_3d_gizmos.data(), visible_3d_gizmos.size(), r_part);
838 }
839 }
840
843
844 return gz;
845}
846
848{
849 for (wmEventHandler &handler_base : region->runtime->handlers) {
850 if (handler_base.type == WM_HANDLER_TYPE_GIZMO) {
851 wmEventHandler_Gizmo *handler = reinterpret_cast<wmEventHandler_Gizmo *>(&handler_base);
852 if (handler->gizmo_map == gzmap) {
853 return;
854 }
855 }
856 }
857
860 BLI_assert(gzmap == region->runtime->gizmo_map);
861 handler->gizmo_map = gzmap;
862 BLI_addtail(&region->runtime->handlers, handler);
863}
864
866{
867 const bool modal_running = (handler->op != nullptr);
868
869 /* Happens on render or when joining areas. */
870 if (!handler->context.region || !handler->context.region->runtime->gizmo_map) {
871 return;
872 }
873
874 wmGizmoMap *gzmap = handler->context.region->runtime->gizmo_map;
875 wmGizmo *gz = wm_gizmomap_modal_get(gzmap);
876 ScrArea *area = CTX_wm_area(C);
877 ARegion *region = CTX_wm_region(C);
878
880
881 /* Regular update for running operator. */
882 if (modal_running) {
883 wmGizmoOpElem *gzop = gz ? WM_gizmo_operator_get(gz, gz->highlight_part) : nullptr;
884 if (gz && gzop && (gzop->type != nullptr) && (gzop->type == handler->op->type)) {
885 wmGizmoFnModal modal_fn = gz->custom_modal ? gz->custom_modal : gz->type->modal;
886 if (modal_fn != nullptr) {
887 const wmOperatorStatus retval = modal_fn(C, gz, event, eWM_GizmoFlagTweak(0));
888 OPERATOR_RETVAL_CHECK(retval);
889 /* The gizmo is tried to the operator, we can't choose when to exit. */
891 UNUSED_VARS_NDEBUG(retval);
892 }
893 }
894 }
895 /* Operator not running anymore. */
896 else {
897 wm_gizmomap_highlight_set(gzmap, C, nullptr, 0);
898 if (gz) {
899 /* This isn't defined if it ends because of success of cancel, we may want to change. */
900 bool cancel = true;
901 if (gz->type->exit) {
902 gz->type->exit(C, gz, cancel);
903 }
904 wm_gizmomap_modal_set(gzmap, C, gz, nullptr, false);
905 }
906 }
907
908 /* Restore the area. */
909 CTX_wm_area_set(C, area);
910 CTX_wm_region_set(C, region);
911}
912
914{
915 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
916
917 if (msel->items == nullptr || msel->len == 0) {
918 return false;
919 }
920
921 for (int i = 0; i < msel->len; i++) {
922 wm_gizmo_select_set_ex(gzmap, msel->items[i], false, false, true);
923 }
924
926
927 /* Always return true, we already checked
928 * if there's anything to deselect. */
929 return true;
930}
931
932static bool gizmo_selectable_poll(const wmGizmo *gz, void * /*data*/)
933{
935}
936
942{
943 wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select;
944 /* GHash is used here to avoid having to loop over all gizmos twice (once to
945 * get tot_sel for allocating, once for actually selecting). Instead we collect
946 * selectable gizmos in hash table and use this to get tot_sel and do selection. */
947
950 bool changed = false;
951
953
954 for (wmGizmo *gz_iter : hash) {
955 WM_gizmo_select_set(gzmap, gz_iter, true);
956 }
957 /* Highlight first gizmo. */
958 wm_gizmomap_highlight_set(gzmap, C, msel->items[0], msel->items[0]->highlight_part);
959
960 BLI_assert(hash.size() == msel->len);
961
962 return changed;
963}
964
965bool WM_gizmomap_select_all(bContext *C, wmGizmoMap *gzmap, const int action)
966{
967 bool changed = false;
968
969 switch (action) {
970 case SEL_SELECT:
971 changed = wm_gizmomap_select_all_intern(C, gzmap);
972 break;
973 case SEL_DESELECT:
974 changed = wm_gizmomap_deselect_all(gzmap);
975 break;
976 default:
978 break;
979 }
980
981 if (changed) {
983 }
984
985 return changed;
986}
987
989{
990 bScreen *screen = CTX_wm_screen(C);
991
992 if (screen) {
993 ScrArea *area;
994
995 for (area = screen->areabase.first(); area; area = area->next) {
996 if (area == handler->context.area) {
997 break;
998 }
999 }
1000 if (area == nullptr) {
1001 /* When changing screen layouts with running modal handlers (like render display),
1002 * this is not an error to print. */
1003 }
1004 else {
1005 ARegion *region;
1006 CTX_wm_area_set(C, area);
1007 for (region = area->regionbase.first(); region; region = region->next) {
1008 if (region == handler->context.region) {
1009 break;
1010 }
1011 }
1012 /* XXX no warning print here, after full-area and back regions are remade. */
1013 if (region) {
1014 CTX_wm_region_set(C, region);
1015 }
1016 }
1017 }
1018}
1019
1021{
1022 /* Pass. */
1023}
1024
1026{
1027 wmGizmo *gz = gzmap->gzmap_context.highlight;
1028 if (gz && gz->type->cursor_get) {
1029 WM_cursor_set(win, gz->type->cursor_get(gz));
1030 return true;
1031 }
1032
1033 return false;
1034}
1035
1036bool wm_gizmomap_highlight_set(wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part)
1037{
1038 if ((gz != gzmap->gzmap_context.highlight) || (gz && part != gz->highlight_part)) {
1039 const bool init_last_cursor = !(gzmap->gzmap_context.highlight &&
1040 gzmap->gzmap_context.last_cursor != -1);
1041 if (gzmap->gzmap_context.highlight) {
1042 gzmap->gzmap_context.highlight->state &= ~WM_GIZMO_STATE_HIGHLIGHT;
1043 gzmap->gzmap_context.highlight->highlight_part = -1;
1044 }
1045
1046 gzmap->gzmap_context.highlight = gz;
1047
1048 if (gz) {
1050 gz->highlight_part = part;
1051 if (init_last_cursor) {
1052 gzmap->gzmap_context.last_cursor = -1;
1053 }
1054
1055 if (C && gz->type->cursor_get) {
1056 wmWindow *win = CTX_wm_window(C);
1057 if (init_last_cursor) {
1058 gzmap->gzmap_context.last_cursor = win->cursor;
1059 }
1060 WM_cursor_set(win, gz->type->cursor_get(gz));
1061 }
1062 }
1063 else {
1064 if (C && gzmap->gzmap_context.last_cursor != -1) {
1065 wmWindow *win = CTX_wm_window(C);
1066 WM_cursor_set(win, gzmap->gzmap_context.last_cursor);
1067 }
1068 gzmap->gzmap_context.last_cursor = -1;
1069 }
1070
1071 /* Tag the region for redraw. */
1072 if (C) {
1073 ARegion *region = CTX_wm_region(C);
1075 }
1076
1077 return true;
1078 }
1079
1080 return false;
1081}
1082
1084{
1085 return gzmap->gzmap_context.highlight;
1086}
1087
1089 wmGizmoMap *gzmap, bContext *C, wmGizmo *gz, const wmEvent *event, bool enable)
1090{
1091 bool do_refresh = false;
1092
1093 if (enable) {
1094 BLI_assert(gzmap->gzmap_context.modal == nullptr);
1095 wmWindow *win = CTX_wm_window(C);
1096
1097 WM_tooltip_clear(C, win);
1098
1099 /* Use even if we don't have invoke, so we can setup data before an operator runs. */
1101 gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz, event);
1102 }
1103
1104 if (gz->type->invoke && (gz->type->modal || gz->custom_modal)) {
1105 const wmOperatorStatus retval = gz->type->invoke(C, gz, event);
1106 OPERATOR_RETVAL_CHECK(retval);
1107
1108 if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
1109 return;
1110 }
1111 }
1112
1113 if (gzmap->gzmap_context.modal != gz) {
1114 do_refresh = true;
1115 }
1117 gzmap->gzmap_context.modal = gz;
1118
1119 if ((gz->flag & WM_GIZMO_MOVE_CURSOR) && (event->tablet.is_motion_absolute == false)) {
1120 WM_cursor_grab_enable(win, WM_CURSOR_WRAP_XY, nullptr, true);
1121 copy_v2_v2_int(gzmap->gzmap_context.event_xy, event->xy);
1122 gzmap->gzmap_context.event_grabcursor = win->grabcursor;
1123 }
1124 else {
1125 gzmap->gzmap_context.event_xy[0] = INT_MAX;
1126 }
1127
1129 if (gzop && gzop->type) {
1130 const wmOperatorStatus retval = WM_gizmo_operator_invoke(C, gz, gzop, event);
1131 OPERATOR_RETVAL_CHECK(retval);
1132
1133 if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
1134 wm_gizmomap_modal_set(gzmap, C, gz, event, false);
1135 }
1136
1137 /* We failed to hook the gizmo to the operator handler or operator was canceled, return. */
1138 if (!gzmap->gzmap_context.modal) {
1140 MEM_SAFE_DELETE_VOID(gz->interaction_data);
1141 }
1142 }
1143 }
1144 else {
1145 BLI_assert(ELEM(gzmap->gzmap_context.modal, nullptr, gz));
1146
1147 /* Deactivate, gizmo but first take care of some stuff. */
1148 if (gz) {
1150 MEM_SAFE_DELETE_VOID(gz->interaction_data);
1151 }
1152
1153 if (gzmap->gzmap_context.modal != nullptr) {
1154 do_refresh = true;
1155 }
1156 gzmap->gzmap_context.modal = nullptr;
1157
1158 if (C) {
1159 wmWindow *win = CTX_wm_window(C);
1160 if (gzmap->gzmap_context.event_xy[0] != INT_MAX) {
1161 /* Check if some other part of Blender (typically operators)
1162 * have adjusted the grab mode since it was set.
1163 * If so: warp, so we have a predictable outcome. */
1164 if (gzmap->gzmap_context.event_grabcursor == win->grabcursor) {
1165 WM_cursor_grab_disable(win, gzmap->gzmap_context.event_xy);
1166 }
1167 else {
1168 WM_cursor_warp(win, UNPACK2(gzmap->gzmap_context.event_xy));
1169 }
1170 }
1173 }
1174
1175 gzmap->gzmap_context.event_xy[0] = INT_MAX;
1176 }
1177
1178 if (do_refresh) {
1179 const int update_flag = GIZMOMAP_IS_REFRESH_CALLBACK;
1181 gz->parent_gzgroup);
1182 gzmap->update_flag[step] |= update_flag;
1183
1184 /* Ensure the update flag is set for gizmos that were hidden while modal, see #104817. */
1185 for (int i = 0; i < WM_GIZMOMAP_DRAWSTEP_MAX; i++) {
1187 if (step_iter == step) {
1188 continue;
1189 }
1190 if ((gzmap->update_flag[i] & update_flag) == update_flag) {
1191 continue;
1192 }
1193 for (wmGizmoGroup &gzgroup : gzmap->groups) {
1194 if (((gzgroup.type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0) &&
1195 wm_gizmogroup_is_visible_in_drawstep(&gzgroup, step_iter))
1196 {
1197 gzmap->update_flag[i] |= update_flag;
1198 break;
1199 }
1200 }
1201 }
1202 }
1203}
1204
1206{
1207 return gzmap->gzmap_context.modal;
1208}
1209
1210wmGizmo **wm_gizmomap_selected_get(wmGizmoMap *gzmap, int *r_selected_len)
1211{
1212 *r_selected_len = gzmap->gzmap_context.select.len;
1213 return gzmap->gzmap_context.select.items;
1214}
1215
1216ListBaseT<wmGizmoGroup> *wm_gizmomap_groups_get(wmGizmoMap *gzmap)
1217{
1218 return &gzmap->groups;
1219}
1220
1222 wmGizmoMap *gzmap,
1223 ARegion *region,
1224 wmMsgBus *mbus)
1225{
1226 for (wmGizmoGroup &gzgroup : gzmap->groups) {
1227 if ((gzgroup.hide.any != 0) || (gzgroup.init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0 ||
1228 !WM_gizmo_group_type_poll(C, gzgroup.type))
1229 {
1230 continue;
1231 }
1232 for (wmGizmo &gz : gzgroup.gizmos) {
1233 if (gz.flag & WM_GIZMO_HIDDEN) {
1234 continue;
1235 }
1236 WM_gizmo_target_property_subscribe_all(&gz, mbus, region);
1237 }
1238 if (gzgroup.type->message_subscribe != nullptr) {
1239 gzgroup.type->message_subscribe(C, &gzgroup, mbus);
1240 }
1241 }
1242}
1243 /* #wmGizmoMap. */
1245
1246/* -------------------------------------------------------------------- */
1249
1251 bContext *C, ARegion *region, int * /*r_pass*/, double * /*pass_delay*/, bool *r_exit_on_event)
1252{
1253 wmGizmoMap *gzmap = region->runtime->gizmo_map;
1254 *r_exit_on_event = false;
1255 if (gzmap) {
1256 wmGizmo *gz = gzmap->gzmap_context.highlight;
1257 if (gz) {
1258 wmGizmoGroup *gzgroup = gz->parent_gzgroup;
1259 if ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) != 0) {
1260 /* On screen area of 3D gizmos may be large, exit on cursor motion. */
1261 *r_exit_on_event = true;
1262 }
1263 return ui::tooltip_create_from_gizmo(C, gz);
1264 }
1265 }
1266 return nullptr;
1267}
1268 /* #wmGizmoMapType. */
1270
1271/* -------------------------------------------------------------------- */
1274
1276{
1277 for (wmGizmoMapType &gzmap_type : gizmomaptypes) {
1278 if (gzmap_type.spaceid == gzmap_params->spaceid &&
1279 gzmap_type.regionid == gzmap_params->regionid)
1280 {
1281 return &gzmap_type;
1282 }
1283 }
1284
1285 return nullptr;
1286}
1287
1289{
1290 wmGizmoMapType *gzmap_type = WM_gizmomaptype_find(gzmap_params);
1291
1292 if (gzmap_type) {
1293 return gzmap_type;
1294 }
1295
1296 gzmap_type = MEM_new_zeroed<wmGizmoMapType>("gizmotype list");
1297 gzmap_type->spaceid = gzmap_params->spaceid;
1298 gzmap_type->regionid = gzmap_params->regionid;
1299 BLI_addhead(&gizmomaptypes, gzmap_type);
1300
1301 return gzmap_type;
1302}
1303
1305{
1306 for (wmGizmoMapType *gzmap_type = gizmomaptypes.first(), *gzmap_type_next; gzmap_type;
1307 gzmap_type = gzmap_type_next)
1308 {
1309 gzmap_type_next = gzmap_type->next;
1310 for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first(), *gzgt_next; gzgt_ref;
1311 gzgt_ref = gzgt_next)
1312 {
1313 gzgt_next = gzgt_ref->next;
1315 }
1316 MEM_delete(gzmap_type);
1317 }
1318}
1319
1321{
1322 for (wmGizmoMapType &gzmap_type : gizmomaptypes) {
1323 for (wmGizmoGroupTypeRef &gzgt_ref : gzmap_type.grouptype_refs) {
1324 wm_gizmogrouptype_setup_keymap(gzgt_ref.type, keyconf);
1325 }
1326 }
1327
1329}
1330 /* #wmGizmoMapType. */
1332
1333/* -------------------------------------------------------------------- */
1336
1345
1355
1362
1367
1369{
1370 if (G.background) {
1371 return;
1372 }
1373
1374 if (wm_gzmap_type_update_flag == 0) {
1375 return;
1376 }
1377
1379 for (wmGizmoMapType &gzmap_type : gizmomaptypes) {
1380 if (gzmap_type.type_update_flag & WM_GIZMOMAPTYPE_UPDATE_REMOVE) {
1381 gzmap_type.type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE;
1382 for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type.grouptype_refs.first(), *gzgt_ref_next;
1383 gzgt_ref;
1384 gzgt_ref = gzgt_ref_next)
1385 {
1386 gzgt_ref_next = gzgt_ref->next;
1387 if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_UPDATE_REMOVE) {
1388 gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE;
1389 WM_gizmomaptype_group_unlink(nullptr, bmain, &gzmap_type, gzgt_ref->type);
1390 }
1391 }
1392 }
1393 }
1394
1396 }
1397
1399 for (wmGizmoMapType &gzmap_type : gizmomaptypes) {
1401 if (gzmap_type.type_update_flag & type_update_all) {
1402 gzmap_type.type_update_flag &= ~eWM_GizmoFlagMapTypeUpdateFlag(type_update_all);
1403 for (wmGizmoGroupTypeRef &gzgt_ref : gzmap_type.grouptype_refs) {
1407 }
1408
1410 WM_gizmomaptype_group_init_runtime(bmain, &gzmap_type, gzgt_ref.type);
1412 }
1413 }
1414 }
1415 }
1416
1418 }
1419
1421 for (bScreen *screen = bmain->screens.first(); screen;
1422 screen = static_cast<bScreen *>(screen->id.next))
1423 {
1424 for (ScrArea &area : screen->areabase) {
1425 for (SpaceLink &sl : area.spacedata) {
1426 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first_) ? &area.regionbase :
1427 &sl.regionbase;
1428 for (ARegion &region : *regionbase) {
1429 wmGizmoMap *gzmap = region.runtime->gizmo_map;
1430 if (gzmap != nullptr && gzmap->tag_remove_group) {
1431 gzmap->tag_remove_group = false;
1432
1433 for (wmGizmoGroup *gzgroup = gzmap->groups.first(), *gzgroup_next; gzgroup;
1434 gzgroup = gzgroup_next)
1435 {
1436 gzgroup_next = gzgroup->next;
1437 if (gzgroup->tag_remove) {
1438 wm_gizmogroup_free(nullptr, gzgroup);
1440 }
1441 }
1442 }
1443 }
1444 }
1445 }
1446 }
1448 }
1449
1453 }
1454}
1455
1457
1458/* -------------------------------------------------------------------- */
1464
1466{
1467 for (bScreen *screen = bmain->screens.first(); screen;
1468 screen = static_cast<bScreen *>(screen->id.next))
1469 {
1470 for (ScrArea &area : screen->areabase) {
1471 for (SpaceLink &sl : area.spacedata) {
1472 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first_) ? &area.regionbase :
1473 &sl.regionbase;
1474 for (ARegion &region : *regionbase) {
1475 wmGizmoMap *gzmap = region.runtime->gizmo_map;
1476 if ((gzmap != nullptr) && (gzmap->is_init == false)) {
1477 WM_gizmomap_reinit(gzmap);
1478
1479 /* Without a redraw elements can fail to activate
1480 * (such as the 2D viewport buttons). */
1481 ED_region_tag_redraw(&region);
1482 }
1483 }
1484 }
1485 }
1486 }
1487}
1488
1490
1491} // namespace blender
#define ENUM_OPERATORS(_enum_type)
#define UI_SCALE_FAC
#define OPERATOR_RETVAL_CHECK(ret)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define GPU_framebuffer_ensure_config(_fb,...)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define WM_GIZMOMAP_DRAWSTEP_MAX
#define UNPACK2(a)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define MEM_realloc_uninitialized(vmemh, len)
int64_t size() const
bool is_empty() const
Span< T > as_span() const
#define FLT_MAX
#define INT_MAX
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
#define UINT_MAX
Definition hash_md5.cc:46
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ARegion * tooltip_create_from_gizmo(bContext *C, wmGizmo *gz)
BMesh Iterators.
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
bool wm_gizmomap_highlight_pending(const wmGizmoMap *gzmap)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool wm_gizmomap_select_all_intern(bContext *C, wmGizmoMap *gzmap)
static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, const int visible_gizmos_len, const bContext *C, const int co[2], const int hotspot)
ListBaseT< wmGizmoGroup > * wm_gizmomap_groups_get(wmGizmoMap *gzmap)
ScrArea * CTX_wm_area(const bContext *C)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
static Set< wmGizmo * > WM_gizmomap_gizmo_hash_new(const bContext *C, wmGizmoMap *gzmap, bool(*poll)(const wmGizmo *, void *), void *data, const eWM_GizmoFlag flag_exclude)
void WM_gizmomaptype_group_init_runtime_keymap(const Main *bmain, wmGizmoGroupType *gzgt)
const ListBaseT< wmGizmoGroup > * WM_gizmomap_group_list(wmGizmoMap *gzmap)
static eWM_GizmoFlagGroupTypeGlobalFlag wm_gzmap_type_update_flag
void wm_gizmomap_select_array_remove(wmGizmoMap *gzmap, wmGizmo *gz)
void WM_gizmoconfig_update_tag_group_remove(wmGizmoMap *gzmap)
void GPU_framebuffer_restore()
wmGizmo * WM_gizmomap_get_modal(const wmGizmoMap *gzmap)
unsigned int uint
Definition BKE_text.h:55
void GPU_polygon_smooth(bool enable)
Definition gpu_state.cc:85
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
void GPU_framebuffer_free(gpu::FrameBuffer *fb)
wmGizmo ** wm_gizmomap_selected_get(wmGizmoMap *gzmap, int *r_selected_len)
@ WM_CURSOR_WRAP_XY
Definition WM_types.hh:242
@ GPU_SELECT_NEAREST_SECOND_PASS
Definition GPU_select.hh:25
@ GPU_SELECT_NEAREST_FIRST_PASS
Definition GPU_select.hh:24
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
wmOperatorStatus WM_gizmo_operator_invoke(bContext *C, wmGizmo *gz, wmGizmoOpElem *gzop, const wmEvent *event)
Definition wm_gizmo.cc:223
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
void WM_gizmomap_message_subscribe(const bContext *C, wmGizmoMap *gzmap, ARegion *region, wmMsgBus *mbus)
static void gizmomap_prepare_drawing(wmGizmoMap *gzmap, const bContext *C, ListBaseT< LinkData > *draw_gizmos, const eWM_GizmoFlagMapDrawStep drawstep)
static ListBaseT< wmGizmoMapType > gizmomaptypes
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:107
wmKeyMap * wm_gizmogroup_tweak_modal_keymap(wmKeyConfig *keyconf)
bool wm_gizmomap_deselect_all(wmGizmoMap *gzmap)
wmWindow * CTX_wm_window(const bContext *C)
void view3d_operator_needs_gpu(const bContext *C)
bool WM_gizmomap_select_all(bContext *C, wmGizmoMap *gzmap, const int action)
void wm_gizmos_keymap(wmKeyConfig *keyconf)
void WM_gizmomap_add_handlers(ARegion *region, wmGizmoMap *gzmap)
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
void wm_gizmomap_handler_context_op(bContext *C, wmEventHandler_Op *handler)
void WM_tooltip_clear(bContext *C, wmWindow *win)
Definition wm_tooltip.cc:84
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:745
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bool WM_gizmomap_tag_delay_refresh_for_tweak_check(wmGizmoMap *gzmap)
unsigned int GPU_select_end()
void WM_gizmo_group_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static void gizmos_draw_list(const wmGizmoMap *gzmap, const bContext *C, ListBaseT< LinkData > *draw_gizmos)
wmGizmoGroup * wm_gizmogroup_new_from_type(wmGizmoMap *gzmap, wmGizmoGroupType *gzgt)
void WM_reinit_gizmomap_all(Main *bmain)
bool wm_gizmomap_highlight_handled(wmGizmoMap *gzmap)
static bool gizmo_prepare_drawing(wmGizmoMap *gzmap, wmGizmo *gz, const bContext *C, ListBaseT< LinkData > *draw_gizmos, const eWM_GizmoFlagMapDrawStep drawstep)
static void wm_gizmomap_select_array_ensure_len_alloc(wmGizmoMap *gzmap, int len)
bool wm_gizmo_select_set_ex(wmGizmoMap *gzmap, wmGizmo *gz, bool select, bool use_array, bool use_callback)
Definition wm_gizmo.cc:356
static bool gizmo_selectable_poll(const wmGizmo *gz, void *)
bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, bool, bool use_select, float r_min[3], float r_max[3])
Global G
Definition blender.cc:57
MINLINE void sub_v3_v3(float r[3], const float a[3])
void wm_gizmomap_select_array_push_back(wmGizmoMap *gzmap, wmGizmo *gz)
wmGizmo * wm_gizmomap_highlight_find(wmGizmoMap *gzmap, bContext *C, const wmEvent *event, int *r_part)
void WM_gizmomaptype_group_init_runtime(const Main *bmain, wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
VecBase< float, 2 > float2
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
@ GPU_DEPTH_ALWAYS
Definition GPU_state.hh:133
void WM_gizmo_target_property_subscribe_all(wmGizmo *gz, wmMsgBus *mbus, ARegion *region)
void wm_gizmogroup_intersectable_gizmos_to_list(wmWindowManager *wm, wmGizmoGroup *gzgroup, const int event_modifier, Vector< wmGizmo *, 128 > *r_visible_gizmos)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
unsigned char uchar
Definition BKE_text.h:58
eWM_GizmoFlagGroupTypeGlobalFlag
@ WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE
@ WM_GIZMOTYPE_GLOBAL_UPDATE_REMOVE
@ WM_GIZMOTYPE_GLOBAL_REINIT_ALL
@ WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT
void wm_gizmogrouptype_setup_keymap(wmGizmoGroupType *gzgt, wmKeyConfig *keyconf)
void WM_cursor_grab_enable(wmWindow *win, const eWM_CursorWrapAxis wrap, const rcti *wrap_region, const bool hide)
eWM_GizmoFlagTweak
Gizmo tweak flag. Bit-flag passed to gizmo while tweaking.
void wm_gizmo_update(wmGizmo *gz, const bContext *C, const bool refresh_map)
Definition wm_gizmo.cc:489
BMesh const char void * data
int wm_gizmo_is_visible(wmGizmo *gz)
Definition wm_gizmo.cc:497
void WM_gizmomaptype_group_free(wmGizmoGroupTypeRef *gzgt_ref)
wmWindowManager * CTX_wm_manager(const bContext *C)
bool WM_gizmo_context_check_drawstep(const bContext *C, eWM_GizmoFlagMapDrawStep step)
Definition wm_gizmo.cc:725
void WM_gizmoconfig_update_tag_group_type_init(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3])
void WM_gizmoconfig_update(Main *bmain)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
wmGizmoGroup * WM_gizmomap_group_find_ptr(wmGizmoMap *gzmap, const wmGizmoGroupType *gzgt)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool wm_gizmomap_highlight_set(wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part)
void WM_gizmogroup_ensure_init(const bContext *C, wmGizmoGroup *gzgroup)
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:936
wmGizmo * wm_gizmogroup_find_intersected_gizmo(wmWindowManager *wm, const wmGizmoGroup *gzgroup, bContext *C, const int event_modifier, const int mval[2], int *r_part)
void wm_gizmogroup_free(bContext *C, wmGizmoGroup *gzgroup)
void WM_gizmomap_tag_refresh_drawstep(wmGizmoMap *gzmap, const eWM_GizmoFlagMapDrawStep drawstep)
@ WM_HANDLER_TYPE_GIZMO
void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
bool WM_gizmomap_cursor_set(const wmGizmoMap *gzmap, wmWindow *win)
eWM_GizmoFlagMapTypeUpdateFlag
@ WM_GIZMOMAPTYPE_KEYMAP_INIT
@ WM_GIZMOMAPTYPE_UPDATE_INIT
@ WM_GIZMOMAPTYPE_UPDATE_REMOVE
eWM_GizmoFlagMapDrawStep WM_gizmomap_drawstep_from_gizmo_group(const wmGizmoGroup *gzgroup)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
wmGizmo * wm_gizmomap_modal_get(wmGizmoMap *gzmap)
void wm_gizmomap_remove(wmGizmoMap *gzmap)
void wm_gizmomaptypes_free()
bool wm_gizmogroup_is_visible_in_drawstep(const wmGizmoGroup *gzgroup, const eWM_GizmoFlagMapDrawStep drawstep)
void wm_gizmomap_select_array_shrink(wmGizmoMap *gzmap, int len_subtract)
@ WM_GIZMOGROUP_INIT_REFRESH
@ WM_GIZMOGROUP_INIT_SETUP
static wmGizmoMap * wm_gizmomap_new_from_type_ex(wmGizmoMapType *gzmap_type, wmGizmoMap *gzmap)
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL
@ WM_GIZMOGROUPTYPE_DEPTH_3D
@ WM_GIZMOGROUPTYPE_SELECT
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE
@ WM_GIZMO_DRAW_NO_SCALE
@ WM_GIZMO_MOVE_CURSOR
@ WM_GIZMO_SELECT_BACKGROUND
@ WM_GIZMO_HIDDEN_SELECT
void wm_gizmomap_handler_context_gizmo(bContext *, wmEventHandler_Gizmo *)
static void wm_gizmomap_free_data(wmGizmoMap *gzmap)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
@ WM_GIZMO_STATE_MODAL
@ WM_GIZMO_STATE_HIGHLIGHT
const GPUSelectResult * GPU_select_buffer_near(const Span< GPUSelectResult > hit_results)
bool WM_gizmo_select_set(wmGizmoMap *gzmap, wmGizmo *gz, bool select)
Definition wm_gizmo.cc:396
gpu::Texture * GPU_viewport_depth_texture(GPUViewport *viewport)
void WM_gizmomap_reinit(wmGizmoMap *gzmap)
bool GPU_matrix_unproject_3fv(const float win[3], const float model_inverted[4][4], const float proj[4][4], const int view[4], float r_world[3])
wmGizmoMap * WM_gizmomap_new_from_type(const wmGizmoMapType_Params *gzmap_params)
void GPU_select_begin(GPUSelectBuffer *buffer, const rcti *input, GPUSelectMode mode, int oldhits)
void WM_gizmomap_draw(wmGizmoMap *gzmap, const bContext *C, const eWM_GizmoFlagMapDrawStep drawstep)
@ GIZMOMAP_IS_REFRESH_CALLBACK
@ GIZMOMAP_IS_PREPARE_DRAW
wmGizmoMapType * WM_gizmomaptype_find(const wmGizmoMapType_Params *gzmap_params)
wmGizmoMapType * WM_gizmomaptype_ensure(const wmGizmoMapType_Params *gzmap_params)
void WM_gizmomaptype_group_unlink(bContext *C, Main *bmain, wmGizmoMapType *gzmap_type, const wmGizmoGroupType *gzgt)
wmGizmoGroup * WM_gizmomap_group_find(wmGizmoMap *gzmap, const char *idname)
@ KM_PRESS_DRAG
Definition WM_types.hh:332
static wmGizmo * gizmo_find_intersected_3d(bContext *C, const int co[2], wmGizmo **visible_gizmos, const int visible_gizmos_len, int *r_part)
bool WM_gizmo_group_type_poll(const bContext *C, const wmGizmoGroupType *gzgt)
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)
void wm_gizmomap_select_array_clear(wmGizmoMap *gzmap)
void ED_view3d_draw_setup_view(const wmWindowManager *wm, wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d, const float viewmat[4][4], const float winmat[4][4], const rcti *rect)
ARegion * WM_gizmomap_tooltip_init(bContext *C, ARegion *region, int *, double *, bool *r_exit_on_event)
wmOperatorStatus(*)(bContext *, wmGizmo *, const wmEvent *, eWM_GizmoFlagTweak) wmGizmoFnModal
void wm_gizmomaps_handled_modal_update(bContext *C, wmEvent *event, wmEventHandler_Op *handler)
wmGizmoOpElem * WM_gizmo_operator_get(wmGizmo *gz, int part_index)
Definition wm_gizmo.cc:191
wmGizmo * wm_gizmomap_highlight_get(wmGizmoMap *gzmap)
void WM_event_add_mousemove(wmWindow *win)
void WM_gizmoconfig_update_tag_reinit_all()
void WM_cursor_warp(wmWindow *win, int x, int y)
void wm_gizmomap_modal_set(wmGizmoMap *gzmap, bContext *C, wmGizmo *gz, const wmEvent *event, bool enable)
@ WM_GIZMO_IS_VISIBLE_UPDATE
@ WM_GIZMO_IS_VISIBLE_DRAW
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
GPUViewport * WM_draw_region_get_viewport(ARegion *region)
Definition wm_draw.cc:954
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
static void gizmo_draw_select_3d_loop(const bContext *C, wmGizmo **visible_gizmos, const int visible_gizmos_len, bool *r_use_select_bias)
void WM_gizmoconfig_update_tag_group_type_remove(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
bool WM_gizmomap_is_any_selected(const wmGizmoMap *gzmap)
@ WM_GIZMOMAP_DRAWSTEP_3D
@ WM_GIZMOMAP_DRAWSTEP_2D
void CTX_wm_area_set(bContext *C, ScrArea *area)
#define hash
Definition noise_c.cc:156
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct ARegion * next
bke::ARegionRuntime * runtime
GPUSelectStorage storage
Definition GPU_select.hh:49
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
ListBaseT< ARegion > regionbase
struct ScrArea * next
ListBaseT< SpaceLink > spacedata
ListBaseT< struct ScrArea > areabase
ListBaseT< wmEventHandler > handlers
struct blender::wmEventHandler_Op::@170112141227310273104305047374063031143165303304 context
eWM_EventHandlerType type
wmTabletData tablet
Definition WM_types.hh:846
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmGizmoGroupFnMsgBusSubscribe message_subscribe
eWM_GizmoFlagMapTypeUpdateFlag type_update_flag
wmGizmoGroupFnDrawBackground draw_background
wmGizmoGroupFnInvokePrepare invoke_prepare
wmGizmoGroupFnDrawPrepare draw_prepare
eWM_GizmoFlagGroupTypeFlag flag
eWM_GizmoFlagGroupInitFlag init_flag
wmGizmoGroupType * type
ListBaseT< wmGizmo > gizmos
union blender::wmGizmoGroup::@230200225053276264314243222225366004150335145357 hide
eWM_GizmoFlagMapTypeUpdateFlag type_update_flag
ListBaseT< wmGizmoGroupTypeRef > grouptype_refs
struct blender::wmGizmoMap::@077047172235271304035100110332311133341144335100 gzmap_context
ListBaseT< wmGizmoGroup > groups
char update_flag[WM_GIZMOMAP_DRAWSTEP_MAX]
wmGizmoMapType * type
wmGizmoFnInvoke invoke
wmGizmoFnDrawSelect draw_select
wmGizmoFnCursorGet cursor_get
wmGizmoFnTestSelect test_select
const wmGizmoType * type
wmGizmoGroup * parent_gzgroup
eWM_GizmoFlag flag
wmGizmoFnModal custom_modal
eWM_GizmoFlagState state
struct wmOperatorType * type