Snap Gizmo: support the WM_GIZMO_HIDDEN flag
Support snap cursor removal in poll callback, this makes it possible to delay cursor removal if the gizmo is hidden.
This commit is contained in:
parent
ff86573d72
commit
442b08aac0
|
@ -226,6 +226,49 @@ static void gizmo_snap_rna_snap_elem_index_get_fn(struct PointerRNA *UNUSED(ptr)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Snap Cursor Utils
|
||||
* \{ */
|
||||
|
||||
static void snap_cursor_free(SnapGizmo3D *snap_gizmo)
|
||||
{
|
||||
if (snap_gizmo->snap_state) {
|
||||
ED_view3d_cursor_snap_deactive(snap_gizmo->snap_state);
|
||||
snap_gizmo->snap_state = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX: Delayed snap cursor removal. */
|
||||
static bool snap_cursor_poll(ARegion *region, void *data)
|
||||
{
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)data;
|
||||
if (snap_gizmo->gizmo.flag & WM_GIZMO_HIDDEN) {
|
||||
snap_cursor_free(snap_gizmo);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WM_gizmomap_group_find_ptr(region->gizmo_map, snap_gizmo->gizmo.parent_gzgroup->type)) {
|
||||
/* Wrong viewport. */
|
||||
snap_cursor_free(snap_gizmo);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void snap_cursor_init(SnapGizmo3D *snap_gizmo)
|
||||
{
|
||||
snap_gizmo->snap_state = ED_view3d_cursor_snap_active();
|
||||
snap_gizmo->snap_state->draw_point = true;
|
||||
snap_gizmo->snap_state->draw_plane = false;
|
||||
|
||||
rgba_float_to_uchar(snap_gizmo->snap_state->color_point, snap_gizmo->gizmo.color);
|
||||
|
||||
snap_gizmo->snap_state->poll = snap_cursor_poll;
|
||||
snap_gizmo->snap_state->poll_data = snap_gizmo;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name GIZMO_GT_snap_3d
|
||||
* \{ */
|
||||
|
@ -233,17 +276,15 @@ static void gizmo_snap_rna_snap_elem_index_get_fn(struct PointerRNA *UNUSED(ptr)
|
|||
static void snap_gizmo_setup(wmGizmo *gz)
|
||||
{
|
||||
gz->flag |= WM_GIZMO_NO_TOOLTIP;
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
|
||||
snap_gizmo->snap_state = ED_view3d_cursor_snap_active();
|
||||
snap_gizmo->snap_state->gzgrp_type = gz->parent_gzgroup->type;
|
||||
snap_gizmo->snap_state->draw_point = true;
|
||||
snap_gizmo->snap_state->draw_plane = false;
|
||||
|
||||
rgba_float_to_uchar(snap_gizmo->snap_state->color_point, gz->color);
|
||||
snap_cursor_init((SnapGizmo3D *)gz);
|
||||
}
|
||||
|
||||
static void snap_gizmo_draw(const bContext *UNUSED(C), wmGizmo *UNUSED(gz))
|
||||
static void snap_gizmo_draw(const bContext *UNUSED(C), wmGizmo *gz)
|
||||
{
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
|
||||
if (snap_gizmo->snap_state == NULL) {
|
||||
snap_cursor_init(snap_gizmo);
|
||||
}
|
||||
/* All drawing is handled at the paint cursor. */
|
||||
}
|
||||
|
||||
|
@ -292,10 +333,7 @@ static int snap_gizmo_invoke(bContext *UNUSED(C),
|
|||
|
||||
static void snap_gizmo_free(wmGizmo *gz)
|
||||
{
|
||||
SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
|
||||
if (snap_gizmo->snap_state) {
|
||||
ED_view3d_cursor_snap_deactive(snap_gizmo->snap_state);
|
||||
}
|
||||
snap_cursor_free((SnapGizmo3D *)gz);
|
||||
}
|
||||
|
||||
static void GIZMO_GT_snap_3d(wmGizmoType *gzt)
|
||||
|
|
|
@ -320,7 +320,6 @@ typedef struct V3DSnapCursorState {
|
|||
uchar color_line[4];
|
||||
uchar color_point[4];
|
||||
uchar color_box[4];
|
||||
struct wmGizmoGroupType *gzgrp_type; /* Force cursor to be drawn only when gizmo is available. */
|
||||
float *prevpoint;
|
||||
float box_dimensions[3];
|
||||
eSnapMode snap_elem_force; /* If SCE_SNAP_MODE_NONE, use scene settings. */
|
||||
|
@ -329,6 +328,9 @@ typedef struct V3DSnapCursorState {
|
|||
bool draw_point;
|
||||
bool draw_plane;
|
||||
bool draw_box;
|
||||
|
||||
bool (*poll)(struct ARegion *region, void *custom_poll_data);
|
||||
void *poll_data;
|
||||
} V3DSnapCursorState;
|
||||
|
||||
void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state);
|
||||
|
|
|
@ -826,14 +826,10 @@ static bool v3d_cursor_snap_poll_fn(bContext *C)
|
|||
return false;
|
||||
};
|
||||
|
||||
/* 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();
|
||||
if (state->gzgrp_type) {
|
||||
/* Check the respective gizmo group is in the region. */
|
||||
wmGizmoMap *gzmap = region->gizmo_map;
|
||||
if (WM_gizmomap_group_find_ptr(gzmap, state->gzgrp_type) == NULL) {
|
||||
/* Wrong viewport. */
|
||||
return false;
|
||||
}
|
||||
if (state->poll && !state->poll(region, state->poll_data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -959,10 +955,11 @@ void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
|
|||
/* These values are temporarily set by the tool.
|
||||
* They are not convenient as default values.
|
||||
* So reset to null. */
|
||||
g_data_intern.state_default.gzgrp_type = NULL;
|
||||
g_data_intern.state_default.prevpoint = NULL;
|
||||
g_data_intern.state_default.draw_plane = false;
|
||||
g_data_intern.state_default.draw_box = false;
|
||||
g_data_intern.state_default.poll = NULL;
|
||||
g_data_intern.state_default.poll_data = NULL;
|
||||
}
|
||||
|
||||
V3DSnapCursorState *ED_view3d_cursor_snap_active(void)
|
||||
|
|
|
@ -1515,11 +1515,21 @@ static void preview_plane_free_fn(void *customdata)
|
|||
ED_view3d_cursor_snap_deactive(snap_state);
|
||||
}
|
||||
|
||||
static bool snap_cursor_poll(ARegion *region, void *data)
|
||||
{
|
||||
if (WM_gizmomap_group_find_ptr(region->gizmo_map, (wmGizmoGroupType *)data) == NULL) {
|
||||
/* Wrong viewport. */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void WIDGETGROUP_placement_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
|
||||
{
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_active();
|
||||
if (snap_state) {
|
||||
snap_state->gzgrp_type = gzgroup->type;
|
||||
snap_state->poll = snap_cursor_poll;
|
||||
snap_state->poll_data = gzgroup->type;
|
||||
snap_state->draw_plane = true;
|
||||
|
||||
gzgroup->customdata = snap_state;
|
||||
|
|
|
@ -3573,10 +3573,10 @@ static ARegion *region_event_inside(bContext *C, const int xy[2])
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static void wm_paintcursor_tag(bContext *C, wmPaintCursor *pc, ARegion *region)
|
||||
static void wm_paintcursor_tag(bContext *C, wmWindowManager *wm, ARegion *region)
|
||||
{
|
||||
if (region) {
|
||||
for (; pc; pc = pc->next) {
|
||||
LISTBASE_FOREACH_MUTABLE (wmPaintCursor *, pc, &wm->paintcursors) {
|
||||
if (pc->poll == nullptr || pc->poll(C)) {
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
WM_paint_cursor_tag_redraw(win, region);
|
||||
|
@ -3598,7 +3598,7 @@ static void wm_paintcursor_test(bContext *C, const wmEvent *event)
|
|||
ARegion *region = CTX_wm_region(C);
|
||||
|
||||
if (region) {
|
||||
wm_paintcursor_tag(C, static_cast<wmPaintCursor *>(wm->paintcursors.first), region);
|
||||
wm_paintcursor_tag(C, wm, region);
|
||||
}
|
||||
|
||||
/* If previous position was not in current region, we have to set a temp new context. */
|
||||
|
@ -3608,8 +3608,7 @@ static void wm_paintcursor_test(bContext *C, const wmEvent *event)
|
|||
CTX_wm_area_set(C, area_event_inside(C, event->prev_xy));
|
||||
CTX_wm_region_set(C, region_event_inside(C, event->prev_xy));
|
||||
|
||||
wm_paintcursor_tag(
|
||||
C, static_cast<wmPaintCursor *>(wm->paintcursors.first), CTX_wm_region(C));
|
||||
wm_paintcursor_tag(C, wm, CTX_wm_region(C));
|
||||
|
||||
CTX_wm_area_set(C, area);
|
||||
CTX_wm_region_set(C, region);
|
||||
|
|
Loading…
Reference in New Issue