Cleanup: use more descriptive names for snap cursor API
Inform in the name that: - the state is being edited - the active state is the one used - a state can be created and freed
This commit is contained in:
@@ -117,7 +117,7 @@ static V3DSnapCursorState *gizmo_snap_state_from_rna_get(struct PointerRNA *ptr)
|
||||
return snap_gizmo->snap_state;
|
||||
}
|
||||
|
||||
return ED_view3d_cursor_snap_state_get();
|
||||
return ED_view3d_cursor_snap_state_active_get();
|
||||
}
|
||||
|
||||
static int gizmo_snap_rna_snap_elements_force_get_fn(struct PointerRNA *ptr,
|
||||
@@ -150,7 +150,7 @@ static void gizmo_snap_rna_prevpoint_set_fn(struct PointerRNA *ptr,
|
||||
const float *values)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = gizmo_snap_state_from_rna_get(ptr);
|
||||
ED_view3d_cursor_snap_prevpoint_set(snap_state, values);
|
||||
ED_view3d_cursor_snap_state_prevpoint_set(snap_state, values);
|
||||
}
|
||||
|
||||
static void gizmo_snap_rna_location_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
@@ -194,7 +194,7 @@ static void gizmo_snap_rna_snap_elem_index_get_fn(struct PointerRNA *UNUSED(ptr)
|
||||
static void snap_cursor_free(SnapGizmo3D *snap_gizmo)
|
||||
{
|
||||
if (snap_gizmo->snap_state) {
|
||||
ED_view3d_cursor_snap_deactive(snap_gizmo->snap_state);
|
||||
ED_view3d_cursor_snap_state_free(snap_gizmo->snap_state);
|
||||
snap_gizmo->snap_state = NULL;
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ static bool snap_cursor_poll(ARegion *region, void *data)
|
||||
|
||||
static void snap_cursor_init(SnapGizmo3D *snap_gizmo)
|
||||
{
|
||||
snap_gizmo->snap_state = ED_view3d_cursor_snap_active();
|
||||
snap_gizmo->snap_state = ED_view3d_cursor_snap_state_create();
|
||||
snap_gizmo->snap_state->draw_point = true;
|
||||
snap_gizmo->snap_state->draw_plane = false;
|
||||
|
||||
@@ -255,7 +255,7 @@ static void snap_gizmo_draw(const bContext *UNUSED(C), wmGizmo *gz)
|
||||
|
||||
/* All drawing is handled at the paint cursor.
|
||||
* Therefore, make sure that the #V3DSnapCursorState is the one of the gizmo being drawn. */
|
||||
ED_view3d_cursor_snap_state_set(snap_gizmo->snap_state);
|
||||
ED_view3d_cursor_snap_state_active_set(snap_gizmo->snap_state);
|
||||
}
|
||||
|
||||
static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
|
||||
|
||||
@@ -336,11 +336,12 @@ typedef struct V3DSnapCursorState {
|
||||
} V3DSnapCursorState;
|
||||
|
||||
void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state);
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void);
|
||||
void ED_view3d_cursor_snap_state_set(V3DSnapCursorState *state);
|
||||
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]);
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_active_get(void);
|
||||
void ED_view3d_cursor_snap_state_active_set(V3DSnapCursorState *state);
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_create(void);
|
||||
void ED_view3d_cursor_snap_state_free(V3DSnapCursorState *state);
|
||||
void ED_view3d_cursor_snap_state_prevpoint_set(V3DSnapCursorState *state,
|
||||
const float prev_point[3]);
|
||||
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state,
|
||||
const struct bContext *C,
|
||||
int x,
|
||||
|
||||
@@ -519,7 +519,7 @@ static void view3d_ob_drop_draw_activate(struct wmDropBox *drop, wmDrag *drag)
|
||||
return;
|
||||
}
|
||||
|
||||
state = static_cast<V3DSnapCursorState *>(ED_view3d_cursor_snap_active());
|
||||
state = static_cast<V3DSnapCursorState *>(ED_view3d_cursor_snap_state_create());
|
||||
drop->draw_data = state;
|
||||
state->draw_plane = true;
|
||||
|
||||
@@ -547,7 +547,7 @@ static void view3d_ob_drop_draw_deactivate(struct wmDropBox *drop, wmDrag * /*dr
|
||||
{
|
||||
V3DSnapCursorState *state = static_cast<V3DSnapCursorState *>(drop->draw_data);
|
||||
if (state) {
|
||||
ED_view3d_cursor_snap_deactive(state);
|
||||
ED_view3d_cursor_snap_state_free(state);
|
||||
drop->draw_data = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -781,7 +781,7 @@ static void view3d_ob_drop_copy_local_id(bContext * /*C*/, wmDrag *drag, wmDropB
|
||||
/* Don't duplicate ID's which were just imported. Only do that for existing, local IDs. */
|
||||
BLI_assert(drag->type != WM_DRAG_ASSET);
|
||||
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
float obmat_final[4][4];
|
||||
|
||||
view3d_ob_drop_matrix_from_snap(snap_state, (Object *)id, obmat_final);
|
||||
@@ -1980,7 +1980,8 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
|
||||
Object *ob = base->object;
|
||||
/* if hidden but in edit mode, we still display, can happen with animation */
|
||||
if ((base->flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0 ||
|
||||
(ob->mode != OB_MODE_OBJECT)) {
|
||||
(ob->mode != OB_MODE_OBJECT))
|
||||
{
|
||||
CTX_data_id_pointer_set(result, &ob->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -829,7 +829,7 @@ static bool v3d_cursor_snap_poll_fn(bContext *C)
|
||||
};
|
||||
|
||||
/* Call this callback last and don't reuse the `state` as the caller can free the cursor. */
|
||||
V3DSnapCursorState *state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *state = ED_view3d_cursor_snap_state_active_get();
|
||||
if (state->poll && !state->poll(region, state->poll_data)) {
|
||||
return false;
|
||||
}
|
||||
@@ -840,7 +840,7 @@ static bool v3d_cursor_snap_poll_fn(bContext *C)
|
||||
static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void *UNUSED(customdata))
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
V3DSnapCursorState *state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *state = ED_view3d_cursor_snap_state_active_get();
|
||||
V3DSnapCursorData *snap_data = &data_intern->snap_data;
|
||||
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
@@ -902,7 +902,7 @@ static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void *UNUSED(cust
|
||||
|
||||
/** \} */
|
||||
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void)
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_active_get(void)
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
if (BLI_listbase_is_empty(&data_intern->state_intern)) {
|
||||
@@ -911,7 +911,7 @@ V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void)
|
||||
return &((SnapStateIntern *)data_intern->state_intern.last)->snap_state;
|
||||
}
|
||||
|
||||
void ED_view3d_cursor_snap_state_set(V3DSnapCursorState *state)
|
||||
void ED_view3d_cursor_snap_state_active_set(V3DSnapCursorState *state)
|
||||
{
|
||||
if (state == &g_data_intern.state_default) {
|
||||
BLI_assert_unreachable();
|
||||
@@ -984,7 +984,7 @@ void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
|
||||
g_data_intern.state_default.poll_data = NULL;
|
||||
}
|
||||
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_active(void)
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_state_create(void)
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
if (!data_intern->handle) {
|
||||
@@ -998,7 +998,7 @@ V3DSnapCursorState *ED_view3d_cursor_snap_active(void)
|
||||
return (V3DSnapCursorState *)&state_intern->snap_state;
|
||||
}
|
||||
|
||||
void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state)
|
||||
void ED_view3d_cursor_snap_state_free(V3DSnapCursorState *state)
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
if (BLI_listbase_is_empty(&data_intern->state_intern)) {
|
||||
@@ -1013,11 +1013,12 @@ void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state)
|
||||
}
|
||||
}
|
||||
|
||||
void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
|
||||
void ED_view3d_cursor_snap_state_prevpoint_set(V3DSnapCursorState *state,
|
||||
const float prev_point[3])
|
||||
{
|
||||
SnapCursorDataIntern *data_intern = &g_data_intern;
|
||||
if (!state) {
|
||||
state = ED_view3d_cursor_snap_state_get();
|
||||
state = ED_view3d_cursor_snap_state_active_get();
|
||||
}
|
||||
if (prev_point) {
|
||||
copy_v3_v3(data_intern->prevpoint_stack, prev_point);
|
||||
@@ -1043,7 +1044,7 @@ void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state,
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
|
||||
if (!state) {
|
||||
state = ED_view3d_cursor_snap_state_get();
|
||||
state = ED_view3d_cursor_snap_state_active_get();
|
||||
}
|
||||
v3d_cursor_snap_update(state, C, wm, depsgraph, scene, region, v3d, x, y);
|
||||
}
|
||||
|
||||
@@ -708,7 +708,7 @@ static bool view3d_interactive_add_calc_snap(bContext *UNUSED(C),
|
||||
|
||||
static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
|
||||
const int plane_axis = snap_state->plane_axis;
|
||||
const enum ePlace_SnapTo snap_to = RNA_enum_get(op->ptr, "snap_target");
|
||||
@@ -726,7 +726,7 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
|
||||
|
||||
ipd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
|
||||
|
||||
V3DSnapCursorState *snap_state_new = ED_view3d_cursor_snap_active();
|
||||
V3DSnapCursorState *snap_state_new = ED_view3d_cursor_snap_state_create();
|
||||
if (snap_state_new) {
|
||||
ipd->snap_state = snap_state = snap_state_new;
|
||||
|
||||
@@ -755,7 +755,7 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
|
||||
C, event, ipd->co_src, ipd->matrix_orient, &ipd->use_snap, &ipd->is_snap_invert) != 0;
|
||||
|
||||
snap_state->draw_plane = false;
|
||||
ED_view3d_cursor_snap_prevpoint_set(snap_state, ipd->co_src);
|
||||
ED_view3d_cursor_snap_state_prevpoint_set(snap_state, ipd->co_src);
|
||||
|
||||
ipd->orient_axis = plane_axis;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -910,7 +910,7 @@ static void view3d_interactive_add_exit(bContext *C, wmOperator *op)
|
||||
UNUSED_VARS(C);
|
||||
|
||||
struct InteractivePlaceData *ipd = op->customdata;
|
||||
ED_view3d_cursor_snap_deactive(ipd->snap_state);
|
||||
ED_view3d_cursor_snap_state_free(ipd->snap_state);
|
||||
|
||||
if (ipd->region != NULL) {
|
||||
if (ipd->draw_handle_view != NULL) {
|
||||
@@ -1036,7 +1036,7 @@ static int view3d_interactive_add_modal(bContext *C, wmOperator *op, const wmEve
|
||||
if (ipd->step_index == STEP_BASE) {
|
||||
if (ELEM(event->type, ipd->launch_event, LEFTMOUSE)) {
|
||||
if (event->val == KM_RELEASE) {
|
||||
ED_view3d_cursor_snap_prevpoint_set(ipd->snap_state, ipd->co_src);
|
||||
ED_view3d_cursor_snap_state_prevpoint_set(ipd->snap_state, ipd->co_src);
|
||||
|
||||
/* Set secondary plane. */
|
||||
|
||||
@@ -1265,7 +1265,7 @@ static bool view3d_interactive_add_poll(bContext *C)
|
||||
static int idp_rna_plane_axis_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop))
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
return snap_state->plane_axis;
|
||||
}
|
||||
|
||||
@@ -1273,7 +1273,7 @@ static void idp_rna_plane_axis_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop),
|
||||
int value)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
snap_state->plane_axis = (short)value;
|
||||
ED_view3d_cursor_snap_state_default_set(snap_state);
|
||||
}
|
||||
@@ -1281,7 +1281,7 @@ static void idp_rna_plane_axis_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
static int idp_rna_plane_depth_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop))
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
return snap_state->plane_depth;
|
||||
}
|
||||
|
||||
@@ -1289,7 +1289,7 @@ static void idp_rna_plane_depth_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop),
|
||||
int value)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
snap_state->plane_depth = value;
|
||||
ED_view3d_cursor_snap_state_default_set(snap_state);
|
||||
}
|
||||
@@ -1297,7 +1297,7 @@ static void idp_rna_plane_depth_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
static int idp_rna_plane_orient_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop))
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
return snap_state->plane_orient;
|
||||
}
|
||||
|
||||
@@ -1305,7 +1305,7 @@ static void idp_rna_plane_orient_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop),
|
||||
int value)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
snap_state->plane_orient = value;
|
||||
ED_view3d_cursor_snap_state_default_set(snap_state);
|
||||
}
|
||||
@@ -1313,7 +1313,7 @@ static void idp_rna_plane_orient_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
static int idp_rna_snap_target_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop))
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
if (snap_state->snap_elem_force == SCE_SNAP_MODE_NONE) {
|
||||
return PLACE_SNAP_TO_DEFAULT;
|
||||
}
|
||||
@@ -1333,7 +1333,7 @@ static void idp_rna_snap_target_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
snap_mode = SCE_SNAP_MODE_GEOM;
|
||||
}
|
||||
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
snap_state->snap_elem_force = snap_mode;
|
||||
ED_view3d_cursor_snap_state_default_set(snap_state);
|
||||
}
|
||||
@@ -1341,7 +1341,7 @@ static void idp_rna_snap_target_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
static bool idp_rna_use_plane_axis_auto_get_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop))
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
return snap_state->use_plane_axis_auto;
|
||||
}
|
||||
|
||||
@@ -1349,7 +1349,7 @@ static void idp_rna_use_plane_axis_auto_set_fn(struct PointerRNA *UNUSED(ptr),
|
||||
struct PropertyRNA *UNUSED(prop),
|
||||
bool value)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_active_get();
|
||||
snap_state->use_plane_axis_auto = value;
|
||||
ED_view3d_cursor_snap_state_default_set(snap_state);
|
||||
}
|
||||
@@ -1523,7 +1523,7 @@ void VIEW3D_OT_interactive_add(struct wmOperatorType *ot)
|
||||
static void preview_plane_free_fn(void *customdata)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = customdata;
|
||||
ED_view3d_cursor_snap_deactive(snap_state);
|
||||
ED_view3d_cursor_snap_state_free(snap_state);
|
||||
}
|
||||
|
||||
static bool snap_cursor_poll(ARegion *region, void *data)
|
||||
@@ -1537,7 +1537,7 @@ static bool snap_cursor_poll(ARegion *region, void *data)
|
||||
|
||||
static void WIDGETGROUP_placement_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_active();
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_create();
|
||||
if (snap_state) {
|
||||
snap_state->poll = snap_cursor_poll;
|
||||
snap_state->poll_data = gzgroup->type;
|
||||
|
||||
Reference in New Issue
Block a user