From 91c33c8b99520b6b094265a826cd391929a81716 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 12 Oct 2021 17:05:56 -0300 Subject: Cleanup: Snap Context Refactor Move runtime parameters out of context creation. Not being able to choose another region and v3d limits the use of the snap API. --- .../editors/gizmo_library/gizmo_types/move3d_gizmo.c | 5 +++-- .../editors/gizmo_library/gizmo_types/snap3d_gizmo.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/gizmo_library') diff --git a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c index 68322ed56af..ec4837aec3c 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c @@ -289,6 +289,8 @@ static int gizmo_move_modal(bContext *C, if (ED_transform_snap_object_project_view3d( inter->snap_context_v3d, CTX_data_ensure_evaluated_depsgraph(C), + region, + CTX_wm_view3d(C), (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE), &(const struct SnapObjectParams){ .snap_select = SNAP_ALL, @@ -381,8 +383,7 @@ static int gizmo_move_invoke(bContext *C, wmGizmo *gz, const wmEvent *event) if (area) { switch (area->spacetype) { case SPACE_VIEW3D: { - inter->snap_context_v3d = ED_transform_snap_object_context_create_view3d( - CTX_data_scene(C), 0, CTX_wm_region(C), CTX_wm_view3d(C)); + inter->snap_context_v3d = ED_transform_snap_object_context_create(CTX_data_scene(C), 0); break; } default: diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c index ae2cc05c01b..f673d3e85ef 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c @@ -278,15 +278,11 @@ void ED_gizmotypes_snap_3d_draw_util(RegionView3D *rv3d, immUnbindProgram(); } -SnapObjectContext *ED_gizmotypes_snap_3d_context_ensure(Scene *scene, - const ARegion *region, - const View3D *v3d, - wmGizmo *gz) +SnapObjectContext *ED_gizmotypes_snap_3d_context_ensure(Scene *scene, wmGizmo *gz) { SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz; if (snap_gizmo->snap_context_v3d == NULL) { - snap_gizmo->snap_context_v3d = ED_transform_snap_object_context_create_view3d( - scene, 0, region, v3d); + snap_gizmo->snap_context_v3d = ED_transform_snap_object_context_create(scene, 0); } return snap_gizmo->snap_context_v3d; } @@ -387,6 +383,8 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz, snap_elem = ED_transform_snap_object_project_view3d_ex( snap_gizmo->snap_context_v3d, depsgraph, + region, + v3d, snap_elements, &(const struct SnapObjectParams){ .snap_select = snap_select, @@ -576,8 +574,12 @@ static void snap_gizmo_setup(wmGizmo *gz) #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz; - snap_gizmo->keymap = WM_modalkeymap_find(gz->parent_gzgroup->type->keyconf, - "Generic Gizmo Tweak Modal Map"); + wmKeyConfig *keyconf = gz->parent_gzgroup->type->keyconf; + if (!keyconf) { + /* It can happen when gizmogrouptype is not linked at startup. */ + keyconf = ((wmWindowManager *)G.main->wm.first)->defaultconf; + } + snap_gizmo->keymap = WM_modalkeymap_find(keyconf, "Generic Gizmo Tweak Modal Map"); RNA_enum_value_from_id(snap_gizmo->keymap->modal_items, "SNAP_ON", &snap_gizmo->snap_on); #endif } -- cgit v1.2.3