Snap Cursor: split 'ED_view3d_cursor_snap_data_get'

Split 'ED_view3d_cursor_snap_data_get' into 'update' and 'get' functions

Sometimes we just want to update and sometimes we just get the result.

Make it clear.
This commit is contained in:
Germano Cavalcante 2022-04-28 11:28:22 -03:00
parent 17769489d9
commit 22f5c05cb3
5 changed files with 38 additions and 36 deletions

View File

@ -81,13 +81,13 @@ bool ED_gizmotypes_snap_3d_flag_test(struct wmGizmo *UNUSED(gz), int flag)
bool ED_gizmotypes_snap_3d_invert_snap_get(struct wmGizmo *UNUSED(gz))
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
return snap_data->is_snap_invert;
}
bool ED_gizmotypes_snap_3d_is_enabled(const wmGizmo *UNUSED(gz))
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
return snap_data->is_enabled;
}
@ -98,7 +98,6 @@ void ED_gizmotypes_snap_3d_data_get(const struct bContext *C,
int r_elem_index[3],
int *r_snap_elem)
{
V3DSnapCursorData *snap_data = NULL;
if (C) {
/* Snap values are updated too late at the cursor. Be sure to update ahead of time. */
wmWindowManager *wm = CTX_wm_manager(C);
@ -107,12 +106,12 @@ void ED_gizmotypes_snap_3d_data_get(const struct bContext *C,
ARegion *region = CTX_wm_region(C);
int x = event->xy[0] - region->winrct.xmin;
int y = event->xy[1] - region->winrct.ymin;
snap_data = ED_view3d_cursor_snap_data_get(NULL, C, x, y);
ED_view3d_cursor_snap_data_update(NULL, C, x, y);
}
}
if (!snap_data) {
snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
}
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
if (r_loc) {
copy_v3_v3(r_loc, snap_data->loc);
@ -171,7 +170,7 @@ static void gizmo_snap_rna_location_get_fn(struct PointerRNA *UNUSED(ptr),
struct PropertyRNA *UNUSED(prop),
float *values)
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
copy_v3_v3(values, snap_data->loc);
}
@ -179,7 +178,7 @@ static void gizmo_snap_rna_location_set_fn(struct PointerRNA *UNUSED(ptr),
struct PropertyRNA *UNUSED(prop),
const float *values)
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
copy_v3_v3(snap_data->loc, values);
}
@ -187,7 +186,7 @@ static void gizmo_snap_rna_normal_get_fn(struct PointerRNA *UNUSED(ptr),
struct PropertyRNA *UNUSED(prop),
float *values)
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
copy_v3_v3(values, snap_data->nor);
}
@ -195,7 +194,7 @@ static void gizmo_snap_rna_snap_elem_index_get_fn(struct PointerRNA *UNUSED(ptr)
struct PropertyRNA *UNUSED(prop),
int *values)
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
copy_v3_v3_int(values, snap_data->elem_index);
}
@ -246,7 +245,8 @@ static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
y = mval[1];
}
}
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(snap_gizmo->snap_state, C, x, y);
ED_view3d_cursor_snap_data_update(snap_gizmo->snap_state, C, x, y);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
if (snap_data->snap_elem) {
return 0;

View File

@ -332,10 +332,11 @@ V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void);
V3DSnapCursorState *ED_view3d_cursor_snap_active(void);
void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state);
void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3]);
V3DSnapCursorData *ED_view3d_cursor_snap_data_get(V3DSnapCursorState *state,
const struct bContext *C,
int x,
int y);
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state,
const struct bContext *C,
int x,
int y);
V3DSnapCursorData *ED_view3d_cursor_snap_data_get(void);
struct SnapObjectContext *ED_view3d_cursor_snap_context_ensure(struct Scene *scene);
void ED_view3d_cursor_snap_draw_util(struct RegionView3D *rv3d,
const float loc_prev[3],

View File

@ -692,8 +692,7 @@ static void view3d_ob_drop_matrix_from_snap(V3DSnapCursorState *snap_state,
Object *ob,
float obmat_final[4][4])
{
V3DSnapCursorData *snap_data;
snap_data = ED_view3d_cursor_snap_data_get(snap_state, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
BLI_assert(snap_state->draw_box || snap_state->draw_plane);
copy_m4_m3(obmat_final, snap_data->plane_omat);
copy_v3_v3(obmat_final[3], snap_data->loc);

View File

@ -956,28 +956,30 @@ void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float
}
}
V3DSnapCursorData *ED_view3d_cursor_snap_data_get(V3DSnapCursorState *state,
const bContext *C,
const int x,
const int y)
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state,
const bContext *C,
const int x,
const int y)
{
SnapCursorDataIntern *data_intern = &g_data_intern;
if (C) {
wmWindowManager *wm = CTX_wm_manager(C);
if (v3d_cursor_eventstate_has_changed(data_intern, state, wm, x, y)) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = DEG_get_input_scene(depsgraph);
ScrArea *area = CTX_wm_area(C);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
View3D *v3d = CTX_wm_view3d(C);
wmWindowManager *wm = CTX_wm_manager(C);
if (v3d_cursor_eventstate_has_changed(data_intern, state, wm, x, y)) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = DEG_get_input_scene(depsgraph);
ScrArea *area = CTX_wm_area(C);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
View3D *v3d = CTX_wm_view3d(C);
if (!state) {
state = ED_view3d_cursor_snap_state_get();
}
v3d_cursor_snap_update(state, C, wm, depsgraph, scene, region, v3d, x, y);
if (!state) {
state = ED_view3d_cursor_snap_state_get();
}
v3d_cursor_snap_update(state, C, wm, depsgraph, scene, region, v3d, x, y);
}
}
V3DSnapCursorData *ED_view3d_cursor_snap_data_get()
{
SnapCursorDataIntern *data_intern = &g_data_intern;
return &data_intern->snap_data;
}

View File

@ -684,7 +684,7 @@ static bool view3d_interactive_add_calc_snap(bContext *UNUSED(C),
bool *r_is_enabled,
bool *r_is_snap_invert)
{
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(NULL, NULL, 0, 0);
V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
copy_v3_v3(r_co_src, snap_data->loc);
if (r_matrix_orient) {
copy_m3_m3(r_matrix_orient, snap_data->plane_omat);
@ -741,7 +741,7 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
/* Be sure to also compute the #V3DSnapCursorData.plane_omat. */
snap_state->draw_plane = true;
ED_view3d_cursor_snap_data_get(snap_state_new, C, mval[0], mval[1]);
ED_view3d_cursor_snap_data_update(snap_state_new, C, mval[0], mval[1]);
snap_state_new->flag = flag_orig;
}
}