Fix snap cursor still active even when gizmo is not available

The snap cursor continued to appear even when the workspace is changed for example.

So add the region to check in the cursor pool.
This commit is contained in:
Germano Cavalcante 2021-11-02 00:41:41 -03:00
parent 348d7c35a9
commit 24310441dd
Notes: blender-bot 2023-02-13 11:52:43 +01:00
Referenced by commit 56ee96349d, Fix snap cursor not active even if gizmo is available
4 changed files with 14 additions and 2 deletions

View File

@ -241,6 +241,10 @@ static void snap_gizmo_draw(const bContext *UNUSED(C), wmGizmo *UNUSED(gz))
static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
{
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
ARegion *region = CTX_wm_region(C);
/* Make sure the cursor is only drawn in the gizmo region. */
snap_gizmo->snap_state->region = region;
/* Snap Elements can change while the gizmo is active. Need to be updated somewhere. */
snap_gizmo_snap_elements_update(snap_gizmo);
@ -251,7 +255,6 @@ static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
wmWindowManager *wm = CTX_wm_manager(C);
const wmEvent *event = wm->winactive ? wm->winactive->eventstate : NULL;
if (event) {
ARegion *region = CTX_wm_region(C);
x = event->xy[0] - region->winrct.xmin;
y = event->xy[1] - region->winrct.ymin;
}

View File

@ -277,6 +277,7 @@ typedef struct V3DSnapCursorState {
uchar color_line[4];
uchar color_point[4];
uchar color_box[4];
struct ARegion *region; /* Forces the cursor to be drawn only in this specific region. */
float *prevpoint;
float box_dimensions[3];
short snap_elem_force; /* If zero, use scene settings. */

View File

@ -777,6 +777,13 @@ static bool v3d_cursor_snap_pool_fn(bContext *C)
return false;
};
V3DSnapCursorState *state = ED_view3d_cursor_snap_state_get();
if (state->region && (state->region != region)) {
/* Some gizmos are still available even when the region is not available.
* We need to disable the cursor in these cases. */
return false;
}
return true;
}

View File

@ -1515,10 +1515,11 @@ static void preview_plane_free_fn(void *customdata)
ED_view3d_cursor_snap_deactive(snap_state);
}
static void WIDGETGROUP_placement_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
static void WIDGETGROUP_placement_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_active();
if (snap_state) {
snap_state->region = CTX_wm_region(C);
snap_state->draw_plane = true;
gzgroup->customdata = snap_state;