Gizmo: Use a utility function to read snap gizmo values

No functional changes.

This makes the `ED_gizmotypes_snap_3d_update` function more specialized.
This commit is contained in:
Germano Cavalcante 2021-03-29 14:32:48 -03:00
parent d0dd85a820
commit 661e6e0966
4 changed files with 29 additions and 22 deletions

@ -319,9 +319,7 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz,
const ARegion *region, const ARegion *region,
const View3D *v3d, const View3D *v3d,
const wmWindowManager *wm, const wmWindowManager *wm,
const float mval_fl[2], const float mval_fl[2])
float r_loc[3],
float r_nor[3])
{ {
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz; SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
snap_gizmo->is_enabled = false; snap_gizmo->is_enabled = false;
@ -410,17 +408,27 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz,
copy_v3_v3(snap_gizmo->nor, no); copy_v3_v3(snap_gizmo->nor, no);
copy_v3_v3_int(snap_gizmo->elem_index, snap_elem_index); copy_v3_v3_int(snap_gizmo->elem_index, snap_elem_index);
if (r_loc) {
copy_v3_v3(r_loc, co);
}
if (r_nor) {
copy_v3_v3(r_nor, no);
}
return snap_elem; return snap_elem;
} }
void ED_gizmotypes_snap_3d_data_get(
wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], int *r_snap_elem)
{
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
if (r_loc) {
copy_v3_v3(r_loc, snap_gizmo->loc);
}
if (r_nor) {
copy_v3_v3(r_nor, snap_gizmo->nor);
}
if (r_elem_index) {
copy_v3_v3_int(r_elem_index, snap_gizmo->elem_index);
}
if (r_snap_elem) {
*r_snap_elem = snap_gizmo->snap_elem;
}
}
/** \} */ /** \} */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
@ -608,7 +616,7 @@ static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
View3D *v3d = CTX_wm_view3d(C); View3D *v3d = CTX_wm_view3d(C);
const float mval_fl[2] = {UNPACK2(mval)}; const float mval_fl[2] = {UNPACK2(mval)};
short snap_elem = ED_gizmotypes_snap_3d_update( short snap_elem = ED_gizmotypes_snap_3d_update(
gz, CTX_data_ensure_evaluated_depsgraph(C), region, v3d, wm, mval_fl, NULL, NULL); gz, CTX_data_ensure_evaluated_depsgraph(C), region, v3d, wm, mval_fl);
if (snap_elem) { if (snap_elem) {
ED_region_tag_redraw_editor_overlays(region); ED_region_tag_redraw_editor_overlays(region);

@ -271,9 +271,9 @@ short ED_gizmotypes_snap_3d_update(struct wmGizmo *gz,
const struct ARegion *region, const struct ARegion *region,
const struct View3D *v3d, const struct View3D *v3d,
const struct wmWindowManager *wm, const struct wmWindowManager *wm,
const float mval_fl[2], const float mval_fl[2]);
float r_loc[3], void ED_gizmotypes_snap_3d_data_get(
float r_nor[3]); struct wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], int *r_snap_elem);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -387,7 +387,9 @@ static bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph,
} }
ED_gizmotypes_snap_3d_update( ED_gizmotypes_snap_3d_update(
snap_gizmo, depsgraph, ruler_info->region, v3d, ruler_info->wm, mval_fl, co, NULL); snap_gizmo, depsgraph, ruler_info->region, v3d, ruler_info->wm, mval_fl);
ED_gizmotypes_snap_3d_data_get(snap_gizmo, co, NULL, NULL, NULL);
} }
return true; return true;
} }

@ -1058,9 +1058,7 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
ipd->region, ipd->region,
ipd->v3d, ipd->v3d,
G_MAIN->wm.first, G_MAIN->wm.first,
mval_fl, mval_fl);
NULL,
NULL);
} }
} }
@ -1507,9 +1505,8 @@ static int view3d_interactive_add_modal(bContext *C, wmOperator *op, const wmEve
ipd->region, ipd->region,
ipd->v3d, ipd->v3d,
G_MAIN->wm.first, G_MAIN->wm.first,
mval_fl, mval_fl)) {
ipd->snap_co, ED_gizmotypes_snap_3d_data_get(ipd->snap_gizmo, ipd->snap_co, NULL, NULL, NULL);
NULL)) {
ipd->is_snap_found = true; ipd->is_snap_found = true;
} }
ED_gizmotypes_snap_3d_toggle_clear(ipd->snap_gizmo); ED_gizmotypes_snap_3d_toggle_clear(ipd->snap_gizmo);