[Bf-blender-cvs] [08dff7b40bc] master: Gizmo: add per gizmo keymaps
Campbell Barton
noreply at git.blender.org
Mon May 27 18:42:18 CEST 2019
Commit: 08dff7b40bc6a93b4826f6abf8bdc2b9a8bae12e
Author: Campbell Barton
Date: Tue May 28 02:14:31 2019 +1000
Branches: master
https://developer.blender.org/rB08dff7b40bc6a93b4826f6abf8bdc2b9a8bae12e
Gizmo: add per gizmo keymaps
Remove click-drag support for tweak gizmo,
rely on keymap events instead.
This is needed for some gizmos to use modifiers keys
without having all gizmos use all modifier keys (see: T63996).
===================================================================
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M source/blender/editors/interface/interface_region_tooltip.c
M source/blender/editors/space_view3d/view3d_gizmo_navigate.c
M source/blender/windowmanager/gizmo/WM_gizmo_types.h
M source/blender/windowmanager/gizmo/intern/wm_gizmo.c
M source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
M source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
M source/blender/windowmanager/intern/wm_event_system.c
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index fb549fb3a14..fc6a3573275 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -208,6 +208,13 @@ def _template_items_gizmo_tweak_value():
]
+def _template_items_gizmo_tweak_value_click_drag():
+ return [
+ ("gizmogroup.gizmo_tweak", {"type": 'LEFTMOUSE', "value": 'CLICK', "any": True}, None),
+ ("gizmogroup.gizmo_tweak", {"type": 'EVT_TWEAK_L', "value": 'ANY', "any": True}, None),
+ ]
+
+
def _template_items_gizmo_tweak_modal():
return [
("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None),
@@ -4724,6 +4731,15 @@ def km_generic_gizmos(_params):
return keymap
+def km_generic_gizmos_click_drag(_params):
+ keymap = (
+ "Generic Gizmos Click Drag",
+ {"space_type": 'EMPTY', "region_type": 'WINDOW'},
+ {"items": _template_items_gizmo_tweak_value_click_drag()},
+ )
+
+ return keymap
+
def km_generic_gizmos_tweak_modal_map(_params):
keymap = (
"Generic Gizmos Tweak Modal Map",
@@ -5838,6 +5854,7 @@ def generate_keymaps(params=None):
# Gizmos.
km_generic_gizmos(params),
+ km_generic_gizmos_click_drag(params),
km_generic_gizmos_tweak_modal_map(params),
km_generic_gizmos_select(params),
km_generic_gizmos_select_tweak_modal_map(params),
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 5b205de21b8..c47f35c8edd 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -883,20 +883,25 @@ static uiTooltipData *ui_tooltip_data_from_gizmo(bContext *C, wmGizmo *gz)
/* Operator Actions */
{
- bool use_drag = gz->drag_part != -1 && gz->highlight_part != gz->drag_part;
-
const struct {
int part;
const char *prefix;
} gzop_actions[] = {
- {
- .part = gz->highlight_part,
- .prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Click") : NULL,
- },
- {
- .part = use_drag ? gz->drag_part : -1,
- .prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Drag") : NULL,
- },
+#if 0
+ {
+ .part = gz->highlight_part,
+ .prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Click") : NULL,
+ },
+ {
+ .part = use_drag ? gz->drag_part : -1,
+ .prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Drag") : NULL,
+ },
+#else
+ {
+ .part = gz->highlight_part,
+ .prefix = NULL,
+ },
+#endif
};
for (int i = 0; i < ARRAY_SIZE(gzop_actions); i++) {
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
index 5af6fd8b04b..ef4d0683818 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
@@ -131,7 +131,7 @@ static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType *UNUSE
return true;
}
-static void WIDGETGROUP_navigate_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
+static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
struct NavigateWidgetGroup *navgroup = MEM_callocN(sizeof(struct NavigateWidgetGroup), __func__);
@@ -225,14 +225,33 @@ static void WIDGETGROUP_navigate_setup(const bContext *UNUSED(C), wmGizmoGroup *
PointerRNA *ptr = WM_gizmo_operator_set(gz, part_index + 1, ot_view_axis, NULL);
RNA_enum_set(ptr, "type", mapping[part_index]);
}
+ }
- /* When dragging an axis, use this instead. */
- gz->drag_part = 0;
+ {
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmGizmo *gz = navgroup->gz_array[GZ_INDEX_ROTATE];
+ gz->keymap = WM_keymap_ensure(
+ wm->defaultconf, "Generic Gizmos Click Drag", SPACE_EMPTY, RGN_TYPE_WINDOW);
}
gzgroup->customdata = navgroup;
}
+static void WIDGETGROUP_navigate_invoke_prepare(const bContext *UNUSED(C),
+ wmGizmoGroup *gzgroup,
+ wmGizmo *gz,
+ const wmEvent *event)
+{
+ struct NavigateWidgetGroup *navgroup = gzgroup->customdata;
+ wmGizmo *gz_rotate = navgroup->gz_array[GZ_INDEX_ROTATE];
+ if (gz_rotate == gz) {
+ if (ISTWEAK(event->type)) {
+ /* When dragging an axis, use this instead. */
+ gz->highlight_part = 0;
+ }
+ }
+}
+
static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
{
struct NavigateWidgetGroup *navgroup = gzgroup->customdata;
@@ -326,6 +345,7 @@ void VIEW3D_GGT_navigate(wmGizmoGroupType *gzgt)
gzgt->poll = WIDGETGROUP_navigate_poll;
gzgt->setup = WIDGETGROUP_navigate_setup;
+ gzgt->invoke_prepare = WIDGETGROUP_navigate_invoke_prepare;
gzgt->draw_prepare = WIDGETGROUP_navigate_draw_prepare;
}
diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h
index 7d38194db1b..5398c262c72 100644
--- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h
+++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h
@@ -182,6 +182,9 @@ struct wmGizmo {
/** Pointer back to group this gizmo is in (just for quick access). */
struct wmGizmoGroup *parent_gzgroup;
+ /** Optional keymap to use for this gizmo (overrides #wmGizmoGroupType.keymap) */
+ struct wmKeyMap *keymap;
+
void *py_instance;
/** Rna pointer to access properties. */
@@ -195,8 +198,6 @@ struct wmGizmo {
/** Optional ID for highlighting different parts of this gizmo.
* -1 when unset, otherwise a valid index. (Used as index to 'op_data'). */
int highlight_part;
- /** For single click button gizmos, use a different part as a fallback, -1 when unused. */
- int drag_part;
/** Distance to bias this gizmo above others when picking
* (in worldspace, scaled by the gizmo scale - when used). */
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c
index b05865aa7bb..534112edcc7 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c
@@ -90,8 +90,6 @@ static wmGizmo *wm_gizmo_create(const wmGizmoType *gzt, PointerRNA *properties)
unit_m4(gz->matrix_basis);
unit_m4(gz->matrix_offset);
- gz->drag_part = -1;
-
return gz;
}
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
index 03e8717012c..e0501d9abee 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
@@ -59,10 +59,6 @@
# include "BPY_extern.h"
#endif
-/* Allow gizmo part's to be single click only,
- * dragging falls back to activating their 'drag_part' action. */
-#define USE_DRAG_DETECT
-
/* -------------------------------------------------------------------- */
/** \name wmGizmoGroup
*
@@ -351,22 +347,6 @@ typedef struct GizmoTweakData {
int init_event; /* initial event type */
int flag; /* tweak flags */
-#ifdef USE_DRAG_DETECT
- /* True until the mouse is moved (only use when the operator has no modal).
- * this allows some gizmos to be click-only. */
- enum {
- /* Don't detect dragging. */
- DRAG_NOP = 0,
- /* Detect dragging (wait until a drag or click is detected). */
- DRAG_DETECT,
- /* Drag has started, idle until there is no active modal operator.
- * This is needed because finishing the modal operator also exits
- * the modal gizmo state (un-grabbs the cursor).
- * Ideally this workaround could be removed later. */
- DRAG_IDLE,
- } drag_state;
-#endif
-
} GizmoTweakData;
static bool gizmo_tweak_start(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event)
@@ -380,6 +360,10 @@ static bool gizmo_tweak_start(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const
static bool gizmo_tweak_start_and_finish(
bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event, bool *r_is_modal)
{
+ if (gz->parent_gzgroup->type->invoke_prepare) {
+ gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz, event);
+ }
+
wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part);
if (r_is_modal) {
*r_is_modal = false;
@@ -410,9 +394,6 @@ static bool gizmo_tweak_start_and_finish(
}
}
else {
- if (gz->parent_gzgroup->type->invoke_prepare) {
- gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz, event);
- }
/* Allow for 'button' gizmos, single click to run an action. */
WM_gizmo_operator_invoke(C, gz, gzop);
}
@@ -451,47 +432,6 @@ static int gizmo_tweak_modal(bContext *C, wmOperator *op, const wmEvent *event)
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
}
-#ifdef USE_DRAG_DETECT
- wmGizmoMap *gzmap = mtweak->gzmap;
- if (mtweak->drag_state == DRAG_DETECT) {
- if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
- if (len_manhattan_v2v2_int(&event->x, gzmap->gzmap_context.event_xy) >=
- WM_EVENT_CURSOR_CLICK_DRAG_THRESHOLD) {
- mtweak->drag_state = DRAG_IDLE;
- gz->highlight_part = gz->drag_part;
- }
- }
- else if (event->type == mtweak->init_event && event->val == KM_RELEASE) {
- mtweak->drag_state = DRAG_NOP;
- retval = OPERATOR_FINISHED;
- }
-
- if (mtweak->drag_state != DRAG_DETECT) {
- /* Follow logic in 'gizmo_tweak_invoke' */
- bool is_modal = false;
- if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, &is_modal)) {
- if (is_modal) {
- clear_modal = false;
- }
- }
- else {
- if (!gizmo_tweak_start(C, gzmap, gz, event)) {
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list