diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-12-06 19:45:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-12-06 22:03:00 +0300 |
commit | 6ffcddc10afa07b073ce01c25884e23fc2b661df (patch) | |
tree | 86e7ddb017474083890bf16fac4876175a923e57 /source/blender/editors/transform | |
parent | 7465078e637b729e8b36a4f4b73a50a347052df4 (diff) |
Tool System: experimental fallback tool support
Implement T66304 as an experimental option,
available under the preferences "Experimental" section.
- When enabled most tools in the 3D view have a gizmo.
- Dragging outside the gizmo uses the 'fallback' tool.
- The fallback tool can be changed or disabled in the tool options
or from a pie menu (Alt-W).
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r-- | source/blender/editors/transform/transform_gizmo_3d.c | 41 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_gizmo_extrude_3d.c | 66 |
2 files changed, 99 insertions, 8 deletions
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 237bf50be7c..bb47f40d84f 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -1322,6 +1322,17 @@ static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, } } + { + extern PropertyRNA rna_ToolSettings_workspace_tool_type; + const PropertyRNA *props[] = { + &rna_ToolSettings_workspace_tool_type, + }; + for (int i = 0; i < ARRAY_SIZE(props); i++) { + WM_msg_subscribe_rna( + mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__); + } + } + PointerRNA view3d_ptr; RNA_pointer_create(&screen->id, &RNA_SpaceView3D, sa->spacedata.first, &view3d_ptr); @@ -1818,6 +1829,13 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) for (int i = MAN_AXIS_RANGE_ROT_START; i < MAN_AXIS_RANGE_ROT_END; i++) { ggd->gizmos[i]->select_bias = rotate_select_bias; } + + if (scene->toolsettings->workspace_tool_type == SCE_WORKSPACE_TOOL_FALLBACK) { + gzgroup->use_fallback_keymap = true; + } + else { + gzgroup->use_fallback_keymap = false; + } } static void WIDGETGROUP_gizmo_message_subscribe(const bContext *C, @@ -2028,7 +2046,7 @@ void VIEW3D_GGT_xform_gizmo(wmGizmoGroupType *gzgt) gzgt->name = "3D View: Transform Gizmo"; gzgt->idname = "VIEW3D_GGT_xform_gizmo"; - gzgt->flag = WM_GIZMOGROUPTYPE_3D; + gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP; gzgt->gzmap_params.spaceid = SPACE_VIEW3D; gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; @@ -2062,7 +2080,8 @@ void VIEW3D_GGT_xform_gizmo_context(wmGizmoGroupType *gzgt) gzgt->name = "3D View: Transform Gizmo Context"; gzgt->idname = "VIEW3D_GGT_xform_gizmo_context"; - gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_PERSISTENT; + gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_PERSISTENT | + WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP; gzgt->poll = WIDGETGROUP_gizmo_poll_context; gzgt->setup = WIDGETGROUP_gizmo_setup; @@ -2212,6 +2231,13 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr /* Needed to test view orientation changes. */ copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv); + + if (scene->toolsettings->workspace_tool_type == SCE_WORKSPACE_TOOL_FALLBACK) { + gzgroup->use_fallback_keymap = true; + } + else { + gzgroup->use_fallback_keymap = false; + } } static void WIDGETGROUP_xform_cage_message_subscribe(const bContext *C, @@ -2263,7 +2289,7 @@ void VIEW3D_GGT_xform_cage(wmGizmoGroupType *gzgt) gzgt->name = "Transform Cage"; gzgt->idname = "VIEW3D_GGT_xform_cage"; - gzgt->flag |= WM_GIZMOGROUPTYPE_3D; + gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP; gzgt->gzmap_params.spaceid = SPACE_VIEW3D; gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; @@ -2385,6 +2411,13 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg /* Needed to test view orientation changes. */ copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv); + + if (scene->toolsettings->workspace_tool_type == SCE_WORKSPACE_TOOL_FALLBACK) { + gzgroup->use_fallback_keymap = true; + } + else { + gzgroup->use_fallback_keymap = false; + } } static void WIDGETGROUP_xform_shear_message_subscribe(const bContext *C, @@ -2446,7 +2479,7 @@ void VIEW3D_GGT_xform_shear(wmGizmoGroupType *gzgt) gzgt->name = "Transform Shear"; gzgt->idname = "VIEW3D_GGT_xform_shear"; - gzgt->flag |= WM_GIZMOGROUPTYPE_3D; + gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP; gzgt->gzmap_params.spaceid = SPACE_VIEW3D; gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; diff --git a/source/blender/editors/transform/transform_gizmo_extrude_3d.c b/source/blender/editors/transform/transform_gizmo_extrude_3d.c index 513a8afa9b6..da6b0285a5c 100644 --- a/source/blender/editors/transform/transform_gizmo_extrude_3d.c +++ b/source/blender/editors/transform/transform_gizmo_extrude_3d.c @@ -55,9 +55,10 @@ enum { static const float extrude_button_scale = 0.15f; static const float extrude_button_offset_scale = 1.5f; -static const float extrude_arrow_scale = 1.0f; -static const float extrude_arrow_xyz_axis_scale = 1.0f; -static const float extrude_arrow_normal_axis_scale = 1.0f; +static const float extrude_outer_scale = 1.2f; +static const float extrude_arrow_scale = 0.7f; +static const float extrude_arrow_xyz_axis_scale = 0.6666f; +static const float extrude_arrow_normal_axis_scale = 0.6666f; static const float extrude_dial_scale = 0.2; static const uchar shape_plus[] = { @@ -69,6 +70,8 @@ typedef struct GizmoExtrudeGroup { /* XYZ & normal. */ wmGizmo *invoke_xyz_no[4]; + /* Only visible when 'drag' tool option is disabled. */ + wmGizmo *invoke_view; /* Constrained & unconstrained (arrow & circle). */ wmGizmo *adjust[2]; int adjust_axis; @@ -126,12 +129,20 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup) ggd->adjust[0] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); ggd->adjust[1] = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL); + RNA_enum_set(ggd->adjust[1]->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT); + for (int i = 0; i < 4; i++) { ggd->invoke_xyz_no[i] = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL); ggd->invoke_xyz_no[i]->flag |= WM_GIZMO_DRAW_OFFSET_SCALE; } { + ggd->invoke_view = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL); + ggd->invoke_view->select_bias = -2.0f; + RNA_enum_set(ggd->invoke_view->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT); + } + + { PropertyRNA *prop = RNA_struct_find_property(ggd->invoke_xyz_no[3]->ptr, "shape"); for (int i = 0; i < 4; i++) { RNA_property_string_set_bytes( @@ -170,6 +181,8 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup) UI_GetThemeColor3fv(TH_AXIS_X + i, ggd->invoke_xyz_no[i]->color); } UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->invoke_xyz_no[3]->color); + ggd->invoke_view->color[3] = 0.5f; + for (int i = 0; i < 2; i++) { UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->adjust[i]->color); } @@ -177,6 +190,9 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup) for (int i = 0; i < 4; i++) { WM_gizmo_set_scale(ggd->invoke_xyz_no[i], extrude_button_scale); } + WM_gizmo_set_scale(ggd->invoke_view, extrude_outer_scale); + ggd->invoke_view->line_width = 2.0f; + WM_gizmo_set_scale(ggd->adjust[0], extrude_arrow_scale); WM_gizmo_set_scale(ggd->adjust[1], extrude_dial_scale); ggd->adjust[1]->line_width = 2.0f; @@ -193,6 +209,15 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup) } } + { + PointerRNA *ptr = WM_gizmo_operator_set(ggd->invoke_view, 0, ggd->ot_extrude, NULL); + PointerRNA macroptr = RNA_pointer_get(ptr, "TRANSFORM_OT_translate"); + RNA_boolean_set(¯optr, "release_confirm", true); + + bool constraint[3] = {0, 0, 0}; + RNA_boolean_set_array(¯optr, "constraint_axis", constraint); + } + /* Adjust extrude. */ for (int i = 0; i < 2; i++) { wmGizmo *gz = ggd->adjust[i]; @@ -211,6 +236,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) for (int i = 0; i < 4; i++) { WM_gizmo_set_flag(ggd->invoke_xyz_no[i], WM_GIZMO_HIDDEN, true); } + WM_gizmo_set_flag(ggd->invoke_view, WM_GIZMO_HIDDEN, true); for (int i = 0; i < 2; i++) { WM_gizmo_set_flag(ggd->adjust[i], WM_GIZMO_HIDDEN, true); } @@ -303,6 +329,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) for (int i = 0; i < axis_len_used; i++) { WM_gizmo_set_matrix_location(ggd->invoke_xyz_no[i], tbounds.center); } + WM_gizmo_set_matrix_location(ggd->invoke_view, tbounds.center); /* Un-hide. */ for (int i = 0; i < axis_len_used; i++) { WM_gizmo_set_flag(ggd->invoke_xyz_no[i], WM_GIZMO_HIDDEN, false); @@ -351,6 +378,15 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) WM_gizmo_set_flag(ggd->invoke_xyz_no[3], WM_GIZMO_HIDDEN, true); break; } + + if (scene->toolsettings->workspace_tool_type == SCE_WORKSPACE_TOOL_FALLBACK) { + WM_gizmo_set_flag(ggd->invoke_view, WM_GIZMO_HIDDEN, false); + gzgroup->use_fallback_keymap = true; + } + else { + WM_gizmo_set_flag(ggd->invoke_view, WM_GIZMO_HIDDEN, true); + gzgroup->use_fallback_keymap = false; + } } static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) @@ -380,6 +416,11 @@ static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzg copy_v3_v3(ggd->adjust[1]->matrix_basis[1], rv3d->viewinv[1]); copy_v3_v3(ggd->adjust[1]->matrix_basis[2], rv3d->viewinv[2]); } + if ((ggd->invoke_view->flag & WM_GIZMO_HIDDEN) == 0) { + copy_v3_v3(ggd->invoke_view->matrix_basis[0], rv3d->viewinv[0]); + copy_v3_v3(ggd->invoke_view->matrix_basis[1], rv3d->viewinv[1]); + copy_v3_v3(ggd->invoke_view->matrix_basis[2], rv3d->viewinv[2]); + } } } @@ -400,6 +441,9 @@ static void gizmo_mesh_extrude_invoke_prepare(const bContext *UNUSED(C), } RNA_float_set_array(¯optr, "value", ggd->redo_xform.value); } + else if (gz == ggd->invoke_view) { + /* pass */ + } else { /* Workaround for extrude action modifying normals. */ const int i = BLI_array_findindex(ggd->invoke_xyz_no, ARRAY_SIZE(ggd->invoke_xyz_no), &gz); @@ -449,6 +493,20 @@ static void gizmo_mesh_extrude_message_subscribe(const bContext *C, }, &msg_sub_value_gz_tag_refresh, __func__); + + { + Scene *scene = CTX_data_scene(C); + PointerRNA toolsettings_ptr; + RNA_pointer_create(&scene->id, &RNA_ToolSettings, scene->toolsettings, &toolsettings_ptr); + extern PropertyRNA rna_ToolSettings_workspace_tool_type; + const PropertyRNA *props[] = { + &rna_ToolSettings_workspace_tool_type, + }; + for (int i = 0; i < ARRAY_SIZE(props); i++) { + WM_msg_subscribe_rna( + mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__); + } + } } void VIEW3D_GGT_xform_extrude(struct wmGizmoGroupType *gzgt) @@ -456,7 +514,7 @@ void VIEW3D_GGT_xform_extrude(struct wmGizmoGroupType *gzgt) gzgt->name = "3D View Extrude"; gzgt->idname = "VIEW3D_GGT_xform_extrude"; - gzgt->flag = WM_GIZMOGROUPTYPE_3D; + gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP; gzgt->gzmap_params.spaceid = SPACE_VIEW3D; gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; |