From 98c304e865f87a658778781f4280107ed449091c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 10 Aug 2018 21:04:06 +1000 Subject: Gizmo: add option to catch all mouse clicks This was previously default behavior, now it's default. --- .../blender/editors/gizmo_library/CMakeLists.txt | 1 + source/blender/editors/include/ED_gizmo_library.h | 1 + source/blender/editors/space_api/spacetypes.c | 1 + .../blender/editors/transform/transform_gizmo_3d.c | 51 +++++++++++++++++++--- source/blender/makesdna/DNA_scene_types.h | 10 +++-- source/blender/makesrna/intern/rna_scene.c | 5 +++ 6 files changed, 60 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gizmo_library/CMakeLists.txt b/source/blender/editors/gizmo_library/CMakeLists.txt index 389820240e2..e1ea5c22ce5 100644 --- a/source/blender/editors/gizmo_library/CMakeLists.txt +++ b/source/blender/editors/gizmo_library/CMakeLists.txt @@ -47,6 +47,7 @@ set(SRC geometry/geom_dial_gizmo.c gizmo_types/arrow2d_gizmo.c gizmo_types/arrow3d_gizmo.c + gizmo_types/blank3d_gizmo.c gizmo_types/button2d_gizmo.c gizmo_types/cage2d_gizmo.c gizmo_types/cage3d_gizmo.c diff --git a/source/blender/editors/include/ED_gizmo_library.h b/source/blender/editors/include/ED_gizmo_library.h index 2bf3488a8d3..6471c90194b 100644 --- a/source/blender/editors/include/ED_gizmo_library.h +++ b/source/blender/editors/include/ED_gizmo_library.h @@ -40,6 +40,7 @@ void ED_gizmotypes_dial_3d(void); void ED_gizmotypes_grab_3d(void); void ED_gizmotypes_facemap_3d(void); void ED_gizmotypes_primitive_3d(void); +void ED_gizmotypes_blank_3d(void); struct wmGizmo; struct wmGizmoGroup; diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 7246812dc82..84de55a172d 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -136,6 +136,7 @@ void ED_spacetypes_init(void) ED_gizmotypes_arrow_2d(); ED_gizmotypes_arrow_3d(); ED_gizmotypes_primitive_3d(); + ED_gizmotypes_blank_3d(); ED_gizmotypes_cage_2d(); ED_gizmotypes_cage_3d(); diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 83dfa06f37d..5fe7bbbf45e 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -148,7 +148,9 @@ enum { #define MAN_AXIS_RANGE_SCALE_START MAN_AXIS_SCALE_X #define MAN_AXIS_RANGE_SCALE_END (MAN_AXIS_SCALE_ZX + 1) - MAN_AXIS_LAST = MAN_AXIS_RANGE_SCALE_END, + MAN_AXIS_APRON_C, + + MAN_AXIS_LAST = MAN_AXIS_APRON_C + 1, }; /* axis types */ @@ -162,6 +164,7 @@ enum { typedef struct GizmoGroup { bool all_hidden; int twtype; + int axis_type_default; /* Users may change the twtype, detect changes to re-setup gizmo options. */ int twtype_init; @@ -193,7 +196,7 @@ static wmGizmo *gizmo_get_axis_from_index(const GizmoGroup *man, const short axi return man->gizmos[axis_idx]; } -static short gizmo_get_axis_type(const int axis_idx) +static short gizmo_get_axis_type(const int axis_idx, const int axis_type_default) { if (axis_idx >= MAN_AXIS_RANGE_TRANS_START && axis_idx < MAN_AXIS_RANGE_TRANS_END) { return MAN_AXES_TRANSLATE; @@ -204,6 +207,9 @@ static short gizmo_get_axis_type(const int axis_idx) if (axis_idx >= MAN_AXIS_RANGE_SCALE_START && axis_idx < MAN_AXIS_RANGE_SCALE_END) { return MAN_AXES_SCALE; } + if (axis_idx == MAN_AXIS_APRON_C) { + return axis_type_default; + } BLI_assert(0); return -1; } @@ -326,6 +332,8 @@ static bool gizmo_is_axis_visible( rv3d->twdrawflag & MAN_SCALE_X && (twtype & SCE_MANIP_TRANSLATE) == 0 && (twtype & SCE_MANIP_ROTATE) == 0); + case MAN_AXIS_APRON_C: + return true; } return false; } @@ -1169,9 +1177,11 @@ static void gizmo_xform_message_subscribe( if (type_fn == TRANSFORM_GGT_gizmo) { extern PropertyRNA rna_ToolSettings_transform_pivot_point; extern PropertyRNA rna_ToolSettings_use_gizmo_mode; + extern PropertyRNA rna_ToolSettings_use_gizmo_apron; const PropertyRNA *props[] = { &rna_ToolSettings_transform_pivot_point, &rna_ToolSettings_use_gizmo_mode, + &rna_ToolSettings_use_gizmo_apron, }; 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__); @@ -1204,6 +1214,12 @@ static GizmoGroup *gizmogroup_init(wmGizmoGroup *gzgroup) const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true); const wmGizmoType *gzt_prim = WM_gizmotype_find("GIZMO_GT_primitive_3d", true); + /* Fallback action. */ + { + const wmGizmoType *gzt_mask = WM_gizmotype_find("GIZMO_GT_blank_3d", true); + man->gizmos[MAN_AXIS_APRON_C] = WM_gizmo_new_ptr(gzt_mask, gzgroup, NULL); + } + #define GIZMO_NEW_ARROW(v, draw_style) { \ man->gizmos[v] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); \ RNA_enum_set(man->gizmos[v]->ptr, "draw_style", draw_style); \ @@ -1291,9 +1307,23 @@ static void gizmogroup_init_properties_from_twtype(wmGizmoGroup *gzgroup) wmOperatorType *translate, *rotate, *trackball, *resize; } ot_store = {NULL}; GizmoGroup *man = gzgroup->customdata; + + if (man->twtype & SCE_MANIP_TRANSLATE) { + man->axis_type_default = MAN_AXES_TRANSLATE; + } + else if (man->twtype & SCE_MANIP_ROTATE) { + man->axis_type_default = MAN_AXES_ROTATE; + } + else if (man->twtype & SCE_MANIP_SCALE) { + man->axis_type_default = MAN_AXES_SCALE; + } + else { + man->axis_type_default = 0; + } + MAN_ITER_AXES_BEGIN(axis, axis_idx) { - const short axis_type = gizmo_get_axis_type(axis_idx); + const short axis_type = gizmo_get_axis_type(axis_idx, man->axis_type_default); bool constraint_axis[3] = {1, 0, 0}; PointerRNA *ptr; @@ -1356,6 +1386,9 @@ static void gizmogroup_init_properties_from_twtype(wmGizmoGroup *gzgroup) WM_gizmo_set_scale(axis, 0.2f); } break; + case MAN_AXIS_APRON_C: + WM_gizmo_set_scale(axis, 1.2f); + break; } switch (axis_type) { @@ -1472,7 +1505,7 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) MAN_ITER_AXES_BEGIN(axis, axis_idx) { - const short axis_type = gizmo_get_axis_type(axis_idx); + const short axis_type = gizmo_get_axis_type(axis_idx, man->axis_type_default); const int aidx_norm = gizmo_orientation_axis(axis_idx, NULL); WM_gizmo_set_matrix_location(axis, rv3d->twmat[3]); @@ -1537,6 +1570,7 @@ static void WIDGETGROUP_gizmo_message_subscribe( static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { + const Scene *scene = CTX_data_scene(C); GizmoGroup *man = gzgroup->customdata; // ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); @@ -1560,9 +1594,13 @@ static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgr MAN_ITER_AXES_BEGIN(axis, axis_idx) { - const short axis_type = gizmo_get_axis_type(axis_idx); + const short axis_type = gizmo_get_axis_type(axis_idx, man->axis_type_default); /* XXX maybe unset _HIDDEN flag on redraw? */ - if (gizmo_is_axis_visible(rv3d, man->twtype, idot, axis_type, axis_idx)) { + + if (axis_idx == MAN_AXIS_APRON_C) { + WM_gizmo_set_flag(axis, WM_GIZMO_HIDDEN, (scene->toolsettings->gizmo_flag & SCE_MANIP_DISABLE_APRON) != 0); + } + else if (gizmo_is_axis_visible(rv3d, man->twtype, idot, axis_type, axis_idx)) { WM_gizmo_set_flag(axis, WM_GIZMO_HIDDEN, false); } else { @@ -1580,6 +1618,7 @@ static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgr case MAN_AXIS_ROT_C: case MAN_AXIS_SCALE_C: case MAN_AXIS_ROT_T: + case MAN_AXIS_APRON_C: WM_gizmo_set_matrix_rotation_from_z_axis(axis, rv3d->viewinv[2]); break; } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 13de7f9829e..262c24164df 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -2053,9 +2053,13 @@ typedef enum eImagePaintMode { #define EDGE_MODE_TAG_FREESTYLE 5 /* ToolSettings.gizmo_flag */ -#define SCE_MANIP_TRANSLATE 1 -#define SCE_MANIP_ROTATE 2 -#define SCE_MANIP_SCALE 4 +enum { + SCE_MANIP_TRANSLATE = (1 << 0), + SCE_MANIP_ROTATE = (1 << 1), + SCE_MANIP_SCALE = (1 << 2), + + SCE_MANIP_DISABLE_APRON = (1 << 3), +}; /* ToolSettings.gpencil_flags */ typedef enum eGPencil_Flags { diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 0cd261f28bd..21731a54aa1 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2426,6 +2426,11 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Gizmo Mode", ""); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ToolSettings_gizmo_flag_update"); + prop = RNA_def_property(srna, "use_gizmo_apron", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "gizmo_flag", SCE_MANIP_DISABLE_APRON); + RNA_def_property_ui_text(prop, "Apron", "Handle input not directly over the gizmo"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); + /* Grease Pencil */ prop = RNA_def_property(srna, "use_gpencil_additive_drawing", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "gpencil_flags", GP_TOOL_FLAG_RETAIN_LAST); -- cgit v1.2.3