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

View File

@ -319,9 +319,7 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz,
const ARegion *region,
const View3D *v3d,
const wmWindowManager *wm,
const float mval_fl[2],
float r_loc[3],
float r_nor[3])
const float mval_fl[2])
{
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
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_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;
}
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);
const float mval_fl[2] = {UNPACK2(mval)};
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) {
ED_region_tag_redraw_editor_overlays(region);

View File

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

View File

@ -387,7 +387,9 @@ static bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph,
}
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;
}

View File

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