Gizmo: add flag to hide the gizmo group during interaction

This allows a hack to be removed that temporarily overwrote
the 3D views gizmo display flag.

Also reverse change from fb27a9bb98
that runs poll on modal gizmo groups as there is some risk
that the poll function unlinks the gizmo.
This commit is contained in:
Campbell Barton 2021-09-15 22:34:21 +10:00
parent 1bd28a5e0c
commit 5c6cc931b2
11 changed files with 37 additions and 72 deletions

View File

@ -97,7 +97,6 @@ typedef struct {
int launch_event;
float mcenter[2];
void *draw_handle_pixel;
short gizmo_flag;
short value_mode; /* Which value does mouse movement and numeric input affect? */
float segments; /* Segments as float so smooth mouse pan works in small increments */
@ -307,11 +306,6 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->draw_handle_pixel = ED_region_draw_cb_activate(
region->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
G.moving = G_TRANSFORM_EDIT;
if (v3d) {
opdata->gizmo_flag = v3d->gizmo_flag;
v3d->gizmo_flag |= V3D_GIZMO_HIDE_DEFAULT_MODAL;
}
}
return true;
@ -433,15 +427,11 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
}
if (opdata->is_modal) {
View3D *v3d = CTX_wm_view3d(C);
ARegion *region = CTX_wm_region(C);
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup);
}
ED_region_draw_cb_exit(region->type, opdata->draw_handle_pixel);
if (v3d) {
v3d->gizmo_flag = opdata->gizmo_flag;
}
G.moving = 0;
}
MEM_SAFE_FREE(opdata->ob_store);

View File

@ -72,7 +72,6 @@ typedef struct {
bool is_dirty;
} * backup;
int backup_len;
short gizmo_flag;
} BisectData;
static void mesh_bisect_interactive_calc(bContext *C,
@ -157,8 +156,6 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & OPERATOR_RUNNING_MODAL) {
View3D *v3d = CTX_wm_view3d(C);
wmGesture *gesture = op->customdata;
BisectData *opdata;
@ -181,8 +178,6 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* Misc other vars. */
G.moving = G_TRANSFORM_EDIT;
opdata->gizmo_flag = v3d->gizmo_flag;
v3d->gizmo_flag |= V3D_GIZMO_HIDE_DEFAULT_MODAL;
/* Initialize modal callout. */
ED_workspace_status_text(C, TIP_("LMB: Click and drag to draw cut line"));
@ -191,10 +186,8 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return ret;
}
static void edbm_bisect_exit(bContext *C, BisectData *opdata)
static void edbm_bisect_exit(BisectData *opdata)
{
View3D *v3d = CTX_wm_view3d(C);
v3d->gizmo_flag = opdata->gizmo_flag;
G.moving = 0;
for (int ob_index = 0; ob_index < opdata->backup_len; ob_index++) {
@ -225,7 +218,7 @@ static int mesh_bisect_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & (OPERATOR_FINISHED | OPERATOR_CANCELLED)) {
edbm_bisect_exit(C, &opdata_back);
edbm_bisect_exit(&opdata_back);
#ifdef USE_GIZMO
/* Setup gizmos */

View File

@ -76,7 +76,6 @@ typedef struct {
int launch_event;
float mcenter[2];
void *draw_handle_pixel;
short gizmo_flag;
} InsetData;
static void edbm_inset_update_header(wmOperator *op, bContext *C)
@ -177,7 +176,6 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->num_input.unit_type[1] = B_UNIT_LENGTH;
if (is_modal) {
View3D *v3d = CTX_wm_view3d(C);
ARegion *region = CTX_wm_region(C);
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
@ -189,10 +187,6 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->draw_handle_pixel = ED_region_draw_cb_activate(
region->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
G.moving = G_TRANSFORM_EDIT;
if (v3d) {
opdata->gizmo_flag = v3d->gizmo_flag;
v3d->gizmo_flag |= V3D_GIZMO_HIDE_DEFAULT_MODAL;
}
}
return true;
@ -206,15 +200,11 @@ static void edbm_inset_exit(bContext *C, wmOperator *op)
opdata = op->customdata;
if (opdata->is_modal) {
View3D *v3d = CTX_wm_view3d(C);
ARegion *region = CTX_wm_region(C);
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup);
}
ED_region_draw_cb_exit(region->type, opdata->draw_handle_pixel);
if (v3d) {
v3d->gizmo_flag = opdata->gizmo_flag;
}
G.moving = 0;
}

View File

@ -461,7 +461,7 @@ static void IMAGE_GGT_gizmo2d(wmGizmoGroupType *gzgt)
gzgt->name = "UV Transform Gizmo";
gzgt->idname = "IMAGE_GGT_gizmo2d";
gzgt->flag |= (WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
gzgt->flag |= (WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK);
gzgt->gzmap_params.spaceid = SPACE_IMAGE;
@ -475,7 +475,7 @@ static void IMAGE_GGT_gizmo2d_translate(wmGizmoGroupType *gzgt)
gzgt->name = "UV Translate Gizmo";
gzgt->idname = "IMAGE_GGT_gizmo2d_translate";
gzgt->flag |= (WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
gzgt->flag |= (WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK);
gzgt->gzmap_params.spaceid = SPACE_IMAGE;
@ -489,7 +489,7 @@ static void IMAGE_GGT_gizmo2d_resize(wmGizmoGroupType *gzgt)
gzgt->name = "UV Transform Gizmo Resize";
gzgt->idname = "IMAGE_GGT_gizmo2d_resize";
gzgt->flag |= (WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
gzgt->flag |= (WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK);
gzgt->gzmap_params.spaceid = SPACE_IMAGE;
@ -503,7 +503,7 @@ static void IMAGE_GGT_gizmo2d_rotate(wmGizmoGroupType *gzgt)
gzgt->name = "UV Transform Gizmo Resize";
gzgt->idname = "IMAGE_GGT_gizmo2d_rotate";
gzgt->flag |= (WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
gzgt->flag |= (WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK);
gzgt->gzmap_params.spaceid = SPACE_IMAGE;

View File

@ -618,9 +618,6 @@ typedef struct TransInfo {
O_SET,
} orient_curr;
/** backup from view3d, to restore on end. */
short gizmo_flag;
short prop_mode;
/** Value taken as input, either through mouse coordinates or entered as a parameter. */

View File

@ -249,12 +249,6 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->view = v3d;
t->animtimer = (animscreen) ? animscreen->animtimer : NULL;
/* turn gizmo off during transform */
if (t->flag & T_MODAL) {
t->gizmo_flag = v3d->gizmo_flag;
v3d->gizmo_flag |= V3D_GIZMO_HIDE_DEFAULT_MODAL;
}
if (t->scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) {
t->flag |= T_V3D_ALIGN;
}
@ -742,13 +736,6 @@ void postTrans(bContext *C, TransInfo *t)
}
}
}
else if (t->spacetype == SPACE_VIEW3D) {
View3D *v3d = t->area->spacedata.first;
/* restore gizmo */
if (t->flag & T_MODAL) {
v3d->gizmo_flag = t->gizmo_flag;
}
}
if (t->mouse.data) {
MEM_freeN(t->mouse.data);

View File

@ -1974,8 +1974,8 @@ void VIEW3D_GGT_xform_gizmo(wmGizmoGroupType *gzgt)
gzgt->name = "3D View: Transform Gizmo";
gzgt->idname = "VIEW3D_GGT_xform_gizmo";
gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE |
WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP | WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
@ -2216,8 +2216,8 @@ void VIEW3D_GGT_xform_cage(wmGizmoGroupType *gzgt)
gzgt->name = "Transform Cage";
gzgt->idname = "VIEW3D_GGT_xform_cage";
gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE |
WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP | WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
@ -2459,8 +2459,8 @@ void VIEW3D_GGT_xform_shear(wmGizmoGroupType *gzgt)
gzgt->name = "Transform Shear";
gzgt->idname = "VIEW3D_GGT_xform_shear";
gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP |
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE |
WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP | WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;

View File

@ -610,14 +610,6 @@ enum {
V3D_GIZMO_HIDE_TOOL = (1 << 3),
};
/**
* Hide these gizmos when modal operators are active,
* the intention is to hide all gizmos except for navigation since from a user-perspective
* these are closer to UI-level interface elements. Hiding them makes the UI flicker, also,
* the 3D view-axis can be useful to see during interactions.
*/
#define V3D_GIZMO_HIDE_DEFAULT_MODAL (V3D_GIZMO_HIDE_CONTEXT | V3D_GIZMO_HIDE_TOOL)
/** #View3d.gizmo_show_object */
enum {
V3D_GIZMO_SHOW_OBJECT_TRANSLATE = (1 << 0),

View File

@ -1402,6 +1402,11 @@ static void rna_def_gizmogroup(BlenderRNA *brna)
0,
"Show Modal All",
"Show all while interacting, as well as this group when another is being interacted with"},
{WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE,
"EXCLUDE_MODAL",
0,
"Exclude Modal",
"Show all except this group while interacting"},
{WM_GIZMOGROUPTYPE_TOOL_INIT,
"TOOL_INIT",
0,

View File

@ -120,6 +120,10 @@ typedef enum eWM_GizmoFlagGroupTypeFlag {
* Also show this group when another group is being interacted with.
*/
WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL = (1 << 5),
/** Don't draw this gizmo group when it is modal. */
WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE = (1 << 6),
/**
* When used with tool, only run when activating the tool,
* instead of linking the gizmo while the tool is active.
@ -130,7 +134,7 @@ typedef enum eWM_GizmoFlagGroupTypeFlag {
* when a tool can activate multiple operators based on the key-map.
* We could even move the options into the key-map item.
* ~ campbell. */
WM_GIZMOGROUPTYPE_TOOL_INIT = (1 << 6),
WM_GIZMOGROUPTYPE_TOOL_INIT = (1 << 7),
/**
* This gizmo type supports using the fallback tools keymap.
@ -138,7 +142,7 @@ typedef enum eWM_GizmoFlagGroupTypeFlag {
*
* Often useful in combination with #WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK
*/
WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP = (1 << 7),
WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP = (1 << 8),
/**
* Use this from a gizmos refresh callback so we can postpone the refresh operation
@ -149,14 +153,14 @@ typedef enum eWM_GizmoFlagGroupTypeFlag {
* for selection operations. This means gizmos that use this check don't interfere
* with click drag events by popping up under the cursor and catching the tweak event.
*/
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK = (1 << 8),
WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK = (1 << 9),
/**
* Cause continuous redraws, i.e. set the region redraw flag on every main loop iteration. This
* should really be avoided by using proper region redraw tagging, notifiers and the message-bus,
* however for VR it's sometimes needed.
*/
WM_GIZMOGROUPTYPE_VR_REDRAWS = (1 << 9),
WM_GIZMOGROUPTYPE_VR_REDRAWS = (1 << 10),
} eWM_GizmoFlagGroupTypeFlag;
/**

View File

@ -387,14 +387,21 @@ static void gizmomap_prepare_drawing(wmGizmoMap *gzmap,
LISTBASE_FOREACH (wmGizmoGroup *, gzgroup, &gzmap->groups) {
/* check group visibility - drawstep first to avoid unnecessary call of group poll callback */
if (!wm_gizmogroup_is_visible_in_drawstep(gzgroup, drawstep) ||
!WM_gizmo_group_type_poll(C, gzgroup->type)) {
if (!wm_gizmogroup_is_visible_in_drawstep(gzgroup, drawstep)) {
continue;
}
/* When modal only show other gizmo groups tagged with #WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL. */
if (gz_modal && (gzgroup != gz_modal->parent_gzgroup)) {
if ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0) {
if (gz_modal && (gzgroup == gz_modal->parent_gzgroup)) {
if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE) {
continue;
}
}
else { /* Don't poll modal gizmo since some poll functions unlink. */
if (!WM_gizmo_group_type_poll(C, gzgroup->type)) {
continue;
}
/* When modal only show other gizmo groups tagged with #WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL. */
if (gz_modal && ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0)) {
continue;
}
}