diff options
author | Campbell Barton <campbell@blender.org> | 2022-03-02 07:07:00 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-03-02 07:31:50 +0300 |
commit | 4986f718482b061082936f1f6aa13929741093a2 (patch) | |
tree | 21ea0b78e1182d35b44b4955ff308b8df1148b19 /source/blender/windowmanager | |
parent | 426ff481a789017bd5810a2064ec06a298a6f2dc (diff) |
Event System: remove tweak events in favor of click-drag
Supporting two kinds of dragging is redundant, remove tweak events as
they only supported 3 mouse buttons and added complexity from using the
'value' to store directions.
Support only click-drag events (KM_CLICK_DRAG) which can be used with
any keyboard or mouse button.
Details:
- A "direction" member has been added to keymap items and events which
can be used when the event value is set to KM_CLICK_DRAG.
- Keymap items are version patched.
- Loading older key-maps are also updated.
- Currently the key-maps stored in ./release/scripts/presets/keyconfig/
still reference tweak events & need updating. For now they are updated
on load.
Note that in general this wont impact add-ons as modal operators don't
receive tweak events.
Reviewed By: brecht
Ref D14214
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_keymap.h | 63 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 5 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c | 48 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_query.c | 93 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 30 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture.c | 77 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture_ops.c | 125 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 36 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap_utils.c | 44 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/wm.h | 8 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_types.h | 20 |
14 files changed, 223 insertions, 331 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 07eaa2ab976..21d76ce93bd 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -1432,6 +1432,8 @@ bool WM_event_is_modal_drag_exit(const struct wmEvent *event, bool WM_event_is_last_mousemove(const struct wmEvent *event); bool WM_event_is_mouse_drag(const struct wmEvent *event); bool WM_event_is_mouse_drag_or_press(const wmEvent *event); +int WM_event_drag_direction(const wmEvent *event); + /** * Detect motion between selection (callers should only use this for selection picking), * typically mouse press/click events. diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 6e07fd7fb32..068dbb32be2 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -42,8 +42,13 @@ void WM_keymap_clear(struct wmKeyMap *keymap); /** * Always add item. */ -wmKeyMapItem *WM_keymap_add_item( - struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction); wmKeyMapItem *WM_keymap_add_item_copy(struct wmKeyMap *keymap, wmKeyMapItem *kmi_src); bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); @@ -80,23 +85,43 @@ bool WM_keymap_item_compare(const struct wmKeyMapItem *k1, const struct wmKeyMap /** * Menu wrapper for #WM_keymap_add_item. */ -wmKeyMapItem *WM_keymap_add_menu( - struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction); /** * Pie-menu wrapper for #WM_keymap_add_item. */ -wmKeyMapItem *WM_keymap_add_menu_pie( - struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_menu_pie(struct wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction); /** * Panel (popover) wrapper for #WM_keymap_add_item. */ -wmKeyMapItem *WM_keymap_add_panel( - struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_panel(struct wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction); /** * Tool wrapper for #WM_keymap_add_item. */ -wmKeyMapItem *WM_keymap_add_tool( - struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_tool(struct wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction); wmKeyMap *WM_keymap_guess_from_context(const struct bContext *C); @@ -128,10 +153,20 @@ wmKeyMap *WM_modalkeymap_ensure(struct wmKeyConfig *keyconf, const char *idname, const struct EnumPropertyItem *items); wmKeyMap *WM_modalkeymap_find(struct wmKeyConfig *keyconf, const char *idname); -wmKeyMapItem *WM_modalkeymap_add_item( - struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value); -wmKeyMapItem *WM_modalkeymap_add_item_str( - struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, const char *value); +wmKeyMapItem *WM_modalkeymap_add_item(struct wmKeyMap *km, + int type, + int val, + int modifier, + int keymodifier, + int direction, + int value); +wmKeyMapItem *WM_modalkeymap_add_item_str(struct wmKeyMap *km, + int type, + int val, + int modifier, + int keymodifier, + int direction, + const char *value); const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, int propvalue); void WM_modalkeymap_assign(struct wmKeyMap *km, const char *opname); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 26462402e3d..b2e214782f0 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -494,7 +494,6 @@ typedef struct wmNotifier { /* ************** Gesture Manager data ************** */ /* wmGesture->type */ -#define WM_GESTURE_TWEAK 0 #define WM_GESTURE_LINES 1 #define WM_GESTURE_RECT 2 #define WM_GESTURE_CROSS_RECT 3 @@ -504,7 +503,6 @@ typedef struct wmNotifier { /** * wmGesture is registered to #wmWindow.gesture, handled by operator callbacks. - * Tweak gesture is builtin feature. */ typedef struct wmGesture { struct wmGesture *next, *prev; @@ -660,6 +658,9 @@ typedef struct wmEvent { */ uint8_t modifier; + /** The direction (for #KM_CLICK_DRAG events only). */ + int8_t direction; + /** Raw-key modifier (allow using any key as a modifier). */ short keymodifier; diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index c46a2b6afe5..2971cdf40c3 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -640,24 +640,29 @@ wmKeyMap *wm_gizmogroup_tweak_modal_keymap(wmKeyConfig *keyconf) keymap = WM_modalkeymap_ensure(keyconf, name, modal_items); /* items for modal map */ - WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); - WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); + WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_CANCEL); + WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_CANCEL); - WM_modalkeymap_add_item(keymap, EVT_RETKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); - WM_modalkeymap_add_item(keymap, EVT_PADENTER, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); + WM_modalkeymap_add_item(keymap, EVT_RETKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_CONFIRM); + WM_modalkeymap_add_item(keymap, EVT_PADENTER, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_CONFIRM); WM_modalkeymap_add_item( - keymap, EVT_RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); + keymap, EVT_RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_PRECISION_ON); WM_modalkeymap_add_item( - keymap, EVT_RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); - WM_modalkeymap_add_item(keymap, EVT_LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); + keymap, EVT_RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, KM_ANY, TWEAK_MODAL_PRECISION_OFF); WM_modalkeymap_add_item( - keymap, EVT_LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); + keymap, EVT_LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_PRECISION_ON); + WM_modalkeymap_add_item( + keymap, EVT_LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, KM_ANY, TWEAK_MODAL_PRECISION_OFF); - WM_modalkeymap_add_item(keymap, EVT_RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); - WM_modalkeymap_add_item(keymap, EVT_RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); - WM_modalkeymap_add_item(keymap, EVT_LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); - WM_modalkeymap_add_item(keymap, EVT_LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); + WM_modalkeymap_add_item( + keymap, EVT_RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_SNAP_ON); + WM_modalkeymap_add_item( + keymap, EVT_RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, KM_ANY, TWEAK_MODAL_SNAP_OFF); + WM_modalkeymap_add_item( + keymap, EVT_LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, KM_ANY, TWEAK_MODAL_SNAP_ON); + WM_modalkeymap_add_item( + keymap, EVT_LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, KM_ANY, TWEAK_MODAL_SNAP_OFF); WM_modalkeymap_assign(keymap, "GIZMOGROUP_OT_gizmo_tweak"); @@ -709,24 +714,26 @@ static wmKeyMap *WM_gizmogroup_keymap_template_select_ex( const int select_tweak = (U.flag & USER_LMOUSESELECT) ? EVT_TWEAK_L : EVT_TWEAK_R; const int action_mouse = (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE; #else - const int select_mouse = RIGHTMOUSE; - const int select_tweak = EVT_TWEAK_R; - const int action_mouse = LEFTMOUSE; + const int select_mouse = RIGHTMOUSE, select_mouse_val = KM_PRESS; + const int select_tweak = RIGHTMOUSE, select_tweak_val = KM_CLICK_DRAG; + const int action_mouse = LEFTMOUSE, action_mouse_val = KM_PRESS; #endif if (do_init) { - WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", action_mouse, KM_PRESS, KM_ANY, 0); - WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", select_tweak, KM_ANY, 0, 0); + WM_keymap_add_item( + km, "GIZMOGROUP_OT_gizmo_tweak", action_mouse, action_mouse_val, KM_ANY, 0, KM_ANY); + WM_keymap_add_item( + km, "GIZMOGROUP_OT_gizmo_tweak", select_tweak, select_tweak_val, 0, 0, KM_ANY); } if (do_init) { wmKeyMapItem *kmi = WM_keymap_add_item( - km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, 0, 0); + km, "GIZMOGROUP_OT_gizmo_select", select_mouse, select_mouse_val, 0, 0, KM_ANY); RNA_boolean_set(kmi->ptr, "extend", false); RNA_boolean_set(kmi->ptr, "deselect", false); RNA_boolean_set(kmi->ptr, "toggle", false); kmi = WM_keymap_add_item( - km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, KM_SHIFT, 0); + km, "GIZMOGROUP_OT_gizmo_select", select_mouse, select_mouse_val, KM_SHIFT, 0, KM_ANY); RNA_boolean_set(kmi->ptr, "extend", false); RNA_boolean_set(kmi->ptr, "deselect", false); RNA_boolean_set(kmi->ptr, "toggle", true); @@ -1129,7 +1136,8 @@ void WM_gizmo_group_refresh(const bContext *C, wmGizmoGroup *gzgroup) ARegion *region = CTX_wm_region(C); BLI_assert(region->gizmo_map == gzmap); /* Check if the tweak event originated from this region. */ - if ((win->tweak != NULL) && BLI_rcti_compare(®ion->winrct, &win->tweak->winrct)) { + if ((win->eventstate != NULL) && (win->event_queue_check_drag) && + BLI_rcti_isect_pt_v(®ion->winrct, win->eventstate->prev_click_xy)) { /* We need to run refresh again. */ gzgroup->init_flag &= ~WM_GIZMOGROUP_INIT_REFRESH; WM_gizmomap_tag_refresh_drawstep(gzmap, WM_gizmomap_drawstep_from_gizmo_group(gzgroup)); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 13bf902f02c..c333d8149ed 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -156,7 +156,6 @@ static void window_manager_blend_read_data(BlendDataReader *reader, ID *id) win->gpuctx = NULL; win->eventstate = NULL; win->cursor_keymap_status = NULL; - win->tweak = NULL; #if defined(WIN32) || defined(__APPLE__) win->ime_data = NULL; #endif diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index ddca10a8382..e56d3fb3886 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -47,12 +47,7 @@ static void event_ids_from_type_and_value(const short type, RNA_enum_identifier(rna_enum_event_type_items, type, r_type_id); /* Value. */ - if (ISTWEAK(type)) { - RNA_enum_identifier(rna_enum_event_value_tweak_items, val, r_val_id); - } - else { - RNA_enum_identifier(rna_enum_event_value_all_items, val, r_val_id); - } + RNA_enum_identifier(rna_enum_event_value_items, val, r_val_id); } void WM_event_print(const wmEvent *event) @@ -160,13 +155,6 @@ bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask ma } } - /* Tweak. */ - if (mask & EVT_TYPE_MASK_TWEAK) { - if (ISTWEAK(event_type)) { - return true; - } - } - /* Action Zone. */ if (mask & EVT_TYPE_MASK_ACTIONZONE) { if (IS_EVENT_ACTIONZONE(event_type)) { @@ -192,12 +180,6 @@ bool WM_event_is_modal_drag_exit(const wmEvent *event, if (U.flag & USER_RELEASECONFIRM) { /* option on, so can exit with km-release */ if (event->val == KM_RELEASE) { - switch (init_event_type) { - case EVT_TWEAK_L: - case EVT_TWEAK_M: - case EVT_TWEAK_R: - return 1; - } if ((init_event_val == KM_CLICK_DRAG) && (event->type == init_event_type)) { return 1; } @@ -205,8 +187,7 @@ bool WM_event_is_modal_drag_exit(const wmEvent *event, else { /* If the initial event wasn't a drag event then * ignore #USER_RELEASECONFIRM setting: see T26756. */ - if ((ELEM(init_event_type, EVT_TWEAK_L, EVT_TWEAK_M, EVT_TWEAK_R) || - init_event_val == KM_CLICK_DRAG) == 0) { + if (init_event_val != KM_CLICK_DRAG) { return 1; } } @@ -234,7 +215,7 @@ bool WM_event_is_last_mousemove(const wmEvent *event) bool WM_event_is_mouse_drag(const wmEvent *event) { - return ISTWEAK(event->type) || (ISMOUSE_BUTTON(event->type) && (event->val == KM_CLICK_DRAG)); + return (ISMOUSE_BUTTON(event->type) && (event->val == KM_CLICK_DRAG)); } bool WM_event_is_mouse_drag_or_press(const wmEvent *event) @@ -243,6 +224,68 @@ bool WM_event_is_mouse_drag_or_press(const wmEvent *event) (ISMOUSE_BUTTON(event->type) && (event->val == KM_PRESS)); } +int WM_event_drag_direction(const wmEvent *event) +{ + const int delta[2] = { + event->xy[0] - event->prev_click_xy[0], + event->xy[1] - event->prev_click_xy[1], + }; + + int theta = round_fl_to_int(4.0f * atan2f((float)delta[1], (float)delta[0]) / (float)M_PI); + int val = EVT_GESTURE_W; + + if (theta == 0) { + val = EVT_GESTURE_E; + } + else if (theta == 1) { + val = EVT_GESTURE_NE; + } + else if (theta == 2) { + val = EVT_GESTURE_N; + } + else if (theta == 3) { + val = EVT_GESTURE_NW; + } + else if (theta == -1) { + val = EVT_GESTURE_SE; + } + else if (theta == -2) { + val = EVT_GESTURE_S; + } + else if (theta == -3) { + val = EVT_GESTURE_SW; + } + +#if 0 + /* debug */ + if (val == 1) { + printf("tweak north\n"); + } + if (val == 2) { + printf("tweak north-east\n"); + } + if (val == 3) { + printf("tweak east\n"); + } + if (val == 4) { + printf("tweak south-east\n"); + } + if (val == 5) { + printf("tweak south\n"); + } + if (val == 6) { + printf("tweak south-west\n"); + } + if (val == 7) { + printf("tweak west\n"); + } + if (val == 8) { + printf("tweak north-west\n"); + } +#endif + return val; +} + bool WM_cursor_test_motion_and_update(const int mval[2]) { static int mval_prev[2] = {-1, -1}; @@ -316,12 +359,6 @@ int WM_userdef_event_map(int kmitype) int WM_userdef_event_type_from_keymap_type(int kmitype) { switch (kmitype) { - case EVT_TWEAK_L: - return LEFTMOUSE; - case EVT_TWEAK_M: - return MIDDLEMOUSE; - case EVT_TWEAK_R: - return RIGHTMOUSE; case WHEELOUTMOUSE: return (U.uiflag & USER_WHEELZOOMDIR) ? WHEELUPMOUSE : WHEELDOWNMOUSE; case WHEELINMOUSE: diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index b3b99b0b7fc..017af86e401 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2029,6 +2029,14 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) } } + if (kmi->val == KM_CLICK_DRAG) { + if (kmi->direction != KM_ANY) { + if (kmi->direction != winevent->direction) { + return false; + } + } + } + const bool shift = (winevent->modifier & KM_SHIFT) != 0; const bool ctrl = (winevent->modifier & KM_CTRL) != 0; const bool alt = (winevent->modifier & KM_ALT) != 0; @@ -2775,7 +2783,7 @@ static int wm_handlers_do_gizmo_handler(bContext *C, { /* Drag events use the previous click location to highlight the gizmos, * Get the highlight again in case the user dragged off the gizmo. */ - const bool is_event_drag = ISTWEAK(event->type) || (event->val == KM_CLICK_DRAG); + const bool is_event_drag = (event->val == KM_CLICK_DRAG); const bool is_event_modifier = ISKEYMODIFIER(event->type); /* Only keep the highlight if the gizmo becomes modal as result of event handling. * Without this check, even un-handled drag events will set the highlight if the drag @@ -2886,15 +2894,10 @@ static int wm_handlers_do_gizmo_handler(bContext *C, wmEvent event_test_click_drag = *event; event_test_click_drag.val = KM_CLICK_DRAG; - wmEvent event_test_tweak = *event; - event_test_tweak.type = EVT_TWEAK_L + (event->type - LEFTMOUSE); - event_test_tweak.val = KM_ANY; - LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { if ((kmi->flag & KMI_INACTIVE) == 0) { if (wm_eventmatch(&event_test_click, kmi) || - wm_eventmatch(&event_test_click_drag, kmi) || - wm_eventmatch(&event_test_tweak, kmi)) { + wm_eventmatch(&event_test_click_drag, kmi)) { wmOperatorType *ot = WM_operatortype_find(kmi->idname, 0); if (WM_operator_poll_context(C, ot, WM_OP_INVOKE_DEFAULT)) { is_event_handle_all = true; @@ -3165,6 +3168,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if (win->event_queue_check_drag) { if (WM_event_drag_test(event, event->prev_click_xy)) { win->event_queue_check_drag_handled = true; + const int direction = WM_event_drag_direction(event); const int prev_xy[2] = {UNPACK2(event->xy)}; const short prev_val = event->val; @@ -3177,6 +3181,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) event->type = event->prev_type; event->modifier = event->prev_click_modifier; event->keymodifier = event->prev_click_keymodifier; + event->direction = direction; CLOG_INFO(WM_LOG_HANDLERS, 1, "handling PRESS_DRAG"); @@ -3184,6 +3189,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) action |= wm_handlers_do_intern(C, win, event, handlers); + event->direction = 0; event->keymodifier = prev_keymodifier; event->modifier = prev_modifier; event->val = prev_val; @@ -3712,9 +3718,7 @@ void wm_event_do_handlers(bContext *C) /* Check dragging, creates new event or frees, adds draw tag. */ wm_event_drag_and_drop_test(wm, win, event); - /* Builtin tweak, if action is break it removes tweak. */ - wm_tweakevent_test(C, event, action); - + /* Builtin drag: #KM_CLICK_DRAG. */ if (action & WM_HANDLER_BREAK) { win->event_queue_check_drag = false; } @@ -5515,15 +5519,15 @@ void WM_window_cursor_keymap_status_refresh(bContext *C, wmWindow *win) } event_data[] = { {0, 0, LEFTMOUSE, KM_PRESS}, {0, 0, LEFTMOUSE, KM_CLICK}, - {0, 1, EVT_TWEAK_L, KM_ANY}, + {0, 0, LEFTMOUSE, KM_CLICK_DRAG}, {1, 0, MIDDLEMOUSE, KM_PRESS}, {1, 0, MIDDLEMOUSE, KM_CLICK}, - {1, 1, EVT_TWEAK_M, KM_ANY}, + {1, 0, MIDDLEMOUSE, KM_CLICK_DRAG}, {2, 0, RIGHTMOUSE, KM_PRESS}, {2, 0, RIGHTMOUSE, KM_CLICK}, - {2, 1, EVT_TWEAK_R, KM_ANY}, + {2, 0, RIGHTMOUSE, KM_CLICK_DRAG}, }; for (int button_index = 0; button_index < 3; button_index++) { diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 86ada4aaf2a..a6fbad8b171 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -52,7 +52,6 @@ wmGesture *WM_gesture_new(wmWindow *window, const ARegion *region, const wmEvent if (ELEM(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, - WM_GESTURE_TWEAK, WM_GESTURE_CIRCLE, WM_GESTURE_STRAIGHTLINE)) { rcti *rect = MEM_callocN(sizeof(rcti), "gesture rect new"); @@ -83,9 +82,6 @@ wmGesture *WM_gesture_new(wmWindow *window, const ARegion *region, const wmEvent void WM_gesture_end(wmWindow *win, wmGesture *gesture) { - if (win->tweak == gesture) { - win->tweak = NULL; - } BLI_remlink(&win->gesture, gesture); MEM_freeN(gesture->customdata); WM_generic_user_data_free(&gesture->user_data); @@ -114,74 +110,6 @@ bool WM_gesture_is_modal_first(const wmGesture *gesture) return (gesture->is_active_prev == false); } -int wm_gesture_evaluate(wmGesture *gesture, const wmEvent *event) -{ - if (gesture->type == WM_GESTURE_TWEAK) { - rcti *rect = gesture->customdata; - const int delta[2] = { - BLI_rcti_size_x(rect), - BLI_rcti_size_y(rect), - }; - - if (WM_event_drag_test_with_delta(event, delta)) { - int theta = round_fl_to_int(4.0f * atan2f((float)delta[1], (float)delta[0]) / (float)M_PI); - int val = EVT_GESTURE_W; - - if (theta == 0) { - val = EVT_GESTURE_E; - } - else if (theta == 1) { - val = EVT_GESTURE_NE; - } - else if (theta == 2) { - val = EVT_GESTURE_N; - } - else if (theta == 3) { - val = EVT_GESTURE_NW; - } - else if (theta == -1) { - val = EVT_GESTURE_SE; - } - else if (theta == -2) { - val = EVT_GESTURE_S; - } - else if (theta == -3) { - val = EVT_GESTURE_SW; - } - -#if 0 - /* debug */ - if (val == 1) { - printf("tweak north\n"); - } - if (val == 2) { - printf("tweak north-east\n"); - } - if (val == 3) { - printf("tweak east\n"); - } - if (val == 4) { - printf("tweak south-east\n"); - } - if (val == 5) { - printf("tweak south\n"); - } - if (val == 6) { - printf("tweak south-west\n"); - } - if (val == 7) { - printf("tweak west\n"); - } - if (val == 8) { - printf("tweak north-west\n"); - } -#endif - return val; - } - } - return 0; -} - /* ******************* gesture draw ******************* */ static void wm_gesture_draw_line_active_side(rcti *rect, const bool flip) @@ -511,11 +439,6 @@ void wm_gesture_draw(wmWindow *win) if (gt->type == WM_GESTURE_RECT) { wm_gesture_draw_rect(gt); } -#if 0 - else if (gt->type == WM_GESTURE_TWEAK) { - wm_gesture_draw_line(gt); - } -#endif else if (gt->type == WM_GESTURE_CIRCLE) { wm_gesture_draw_circle(gt); } diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c index cd41cffe1f0..1fdc8bbe2c8 100644 --- a/source/blender/windowmanager/intern/wm_gesture_ops.c +++ b/source/blender/windowmanager/intern/wm_gesture_ops.c @@ -471,131 +471,6 @@ void WM_OT_circle_gesture(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Tweak Gesture - * \{ */ - -static void gesture_tweak_modal(bContext *C, const wmEvent *event) -{ - wmWindow *window = CTX_wm_window(C); - wmGesture *gesture = window->tweak; - rcti *rect = gesture->customdata; - bool gesture_end = false; - - switch (event->type) { - case MOUSEMOVE: - case INBETWEEN_MOUSEMOVE: { - - rect->xmax = event->xy[0] - gesture->winrct.xmin; - rect->ymax = event->xy[1] - gesture->winrct.ymin; - - const int val = wm_gesture_evaluate(gesture, event); - if (val != 0) { - wmEvent tevent; - - wm_event_init_from_window(window, &tevent); - /* We want to get coord from start of drag, - * not from point where it becomes a tweak event, see T40549. */ - tevent.xy[0] = rect->xmin + gesture->winrct.xmin; - tevent.xy[1] = rect->ymin + gesture->winrct.ymin; - if (gesture->event_type == LEFTMOUSE) { - tevent.type = EVT_TWEAK_L; - } - else if (gesture->event_type == RIGHTMOUSE) { - tevent.type = EVT_TWEAK_R; - } - else { - tevent.type = EVT_TWEAK_M; - } - tevent.val = val; - tevent.modifier = gesture->event_modifier; - tevent.keymodifier = gesture->event_keymodifier; - tevent.flag = 0; - /* mouse coords! */ - - /* important we add immediately after this event, so future mouse releases - * (which may be in the queue already), are handled in order, see T44740 */ - wm_event_add_ex(window, &tevent, event); - - gesture_end = true; - } - - break; - } - - case LEFTMOUSE: - case RIGHTMOUSE: - case MIDDLEMOUSE: - if (gesture->event_type == event->type) { - gesture_end = true; - - /* when tweak fails we should give the other keymap entries a chance */ - - /* XXX, assigning to readonly, BAD JUJU! */ - ((wmEvent *)event)->val = KM_RELEASE; - } - break; - default: - if (ISTIMER(event->type)) { - /* Ignore timers. */ - } - else if (event->type == EVENT_NONE) { - /* Ignore none events. */ - } - else if ((event->val == KM_RELEASE) && - (ISKEYMODIFIER(event->type) || (event->type == event->prev_click_keymodifier))) { - /* Support releasing modifier keys without canceling the drag event, see T89989. - * NOTE: this logic is replicated for drag events. */ - } - else { - gesture_end = true; - } - break; - } - - if (gesture_end) { - /* Frees gesture itself, and unregisters from window. */ - WM_gesture_end(window, gesture); - - /* This isn't very nice but needed to redraw gizmos which are hidden while tweaking, - * See #WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK for details. */ - ARegion *region = CTX_wm_region(C); - if ((region != NULL) && (region->gizmo_map != NULL)) { - if (WM_gizmomap_tag_delay_refresh_for_tweak_check(region->gizmo_map)) { - ED_region_tag_redraw(region); - } - } - } -} - -void wm_tweakevent_test(bContext *C, const wmEvent *event, int action) -{ - wmWindow *win = CTX_wm_window(C); - - if (win->tweak == NULL) { - const ARegion *region = CTX_wm_region(C); - - if (region) { - if (event->val == KM_PRESS) { - if (ELEM(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE)) { - win->tweak = WM_gesture_new(win, region, event, WM_GESTURE_TWEAK); - } - } - } - } - else { - /* no tweaks if event was handled */ - if (action & WM_HANDLER_BREAK) { - WM_gesture_end(win, win->tweak); - } - else { - gesture_tweak_modal(C, event); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Lasso Gesture * \{ */ diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index f7bc138f163..ffac585cde7 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -169,6 +169,7 @@ static bool wm_keymap_item_equals(wmKeyMapItem *a, wmKeyMapItem *b) return (wm_keymap_item_equals_result(a, b) && a->type == b->type && a->val == b->val && a->shift == b->shift && a->ctrl == b->ctrl && a->alt == b->alt && a->oskey == b->oskey && a->keymodifier == b->keymodifier && a->maptype == b->maptype && + ((a->val != KM_CLICK_DRAG) || (a->direction == b->direction)) && ((ISKEYBOARD(a->type) == 0) || (a->flag & KMI_REPEAT_IGNORE) == (b->flag & KMI_REPEAT_IGNORE))); } @@ -195,9 +196,6 @@ int WM_keymap_item_map_type_get(const wmKeyMapItem *kmi) if (ISKEYBOARD(kmi->type)) { return KMI_TYPE_KEYBOARD; } - if (ISTWEAK(kmi->type)) { - return KMI_TYPE_TWEAK; - } if (ISMOUSE(kmi->type)) { return KMI_TYPE_MOUSE; } @@ -459,11 +457,12 @@ bool WM_keymap_poll(bContext *C, wmKeyMap *keymap) } static void keymap_event_set( - wmKeyMapItem *kmi, short type, short val, int modifier, short keymodifier) + wmKeyMapItem *kmi, short type, short val, int modifier, short keymodifier, int direction) { kmi->type = type; kmi->val = val; kmi->keymodifier = keymodifier; + kmi->direction = direction; if (modifier == KM_ANY) { kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = KM_ANY; @@ -497,15 +496,20 @@ static void keymap_item_set_id(wmKeyMap *keymap, wmKeyMapItem *kmi) } } -wmKeyMapItem *WM_keymap_add_item( - wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) +wmKeyMapItem *WM_keymap_add_item(wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction) { wmKeyMapItem *kmi = MEM_callocN(sizeof(wmKeyMapItem), "keymap entry"); BLI_addtail(&keymap->items, kmi); BLI_strncpy(kmi->idname, idname, OP_MAX_TYPENAME); - keymap_event_set(kmi, type, val, modifier, keymodifier); + keymap_event_set(kmi, type, val, modifier, keymodifier, direction); wm_keymap_item_properties_set(kmi); keymap_item_set_id(keymap, kmi); @@ -919,14 +923,14 @@ wmKeyMap *WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname) } wmKeyMapItem *WM_modalkeymap_add_item( - wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value) + wmKeyMap *km, int type, int val, int modifier, int keymodifier, int direction, int value) { wmKeyMapItem *kmi = MEM_callocN(sizeof(wmKeyMapItem), "keymap entry"); BLI_addtail(&km->items, kmi); kmi->propvalue = value; - keymap_event_set(kmi, type, val, modifier, keymodifier); + keymap_event_set(kmi, type, val, modifier, keymodifier, direction); keymap_item_set_id(km, kmi); @@ -935,15 +939,20 @@ wmKeyMapItem *WM_modalkeymap_add_item( return kmi; } -wmKeyMapItem *WM_modalkeymap_add_item_str( - wmKeyMap *km, int type, int val, int modifier, int keymodifier, const char *value) +wmKeyMapItem *WM_modalkeymap_add_item_str(wmKeyMap *km, + int type, + int val, + int modifier, + int keymodifier, + int direction, + const char *value) { wmKeyMapItem *kmi = MEM_callocN(sizeof(wmKeyMapItem), "keymap entry"); BLI_addtail(&km->items, kmi); BLI_strncpy(kmi->propvalue_str, value, sizeof(kmi->propvalue_str)); - keymap_event_set(kmi, type, val, modifier, keymodifier); + keymap_event_set(kmi, type, val, modifier, keymodifier, direction); keymap_item_set_id(km, kmi); @@ -1730,6 +1739,9 @@ bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2) if (k1->val != k2->val) { return 0; } + if (k1->val == KM_CLICK_DRAG && (k1->direction != k2->direction)) { + return 0; + } } if (k1->shift != KM_ANY && k2->shift != KM_ANY && k1->shift != k2->shift) { diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c index 4bd5fea91e6..24c221221d1 100644 --- a/source/blender/windowmanager/intern/wm_keymap_utils.c +++ b/source/blender/windowmanager/intern/wm_keymap_utils.c @@ -29,40 +29,60 @@ /** \name Wrappers for #WM_keymap_add_item * \{ */ -wmKeyMapItem *WM_keymap_add_menu( - wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) +wmKeyMapItem *WM_keymap_add_menu(wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction) { wmKeyMapItem *kmi = WM_keymap_add_item( - keymap, "WM_OT_call_menu", type, val, modifier, keymodifier); + keymap, "WM_OT_call_menu", type, val, modifier, keymodifier, direction); RNA_string_set(kmi->ptr, "name", idname); return kmi; } -wmKeyMapItem *WM_keymap_add_menu_pie( - wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) +wmKeyMapItem *WM_keymap_add_menu_pie(wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction) { wmKeyMapItem *kmi = WM_keymap_add_item( - keymap, "WM_OT_call_menu_pie", type, val, modifier, keymodifier); + keymap, "WM_OT_call_menu_pie", type, val, modifier, keymodifier, direction); RNA_string_set(kmi->ptr, "name", idname); return kmi; } -wmKeyMapItem *WM_keymap_add_panel( - wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) +wmKeyMapItem *WM_keymap_add_panel(wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction) { wmKeyMapItem *kmi = WM_keymap_add_item( - keymap, "WM_OT_call_panel", type, val, modifier, keymodifier); + keymap, "WM_OT_call_panel", type, val, modifier, keymodifier, direction); RNA_string_set(kmi->ptr, "name", idname); /* TODO: we might want to disable this. */ RNA_boolean_set(kmi->ptr, "keep_open", false); return kmi; } -wmKeyMapItem *WM_keymap_add_tool( - wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) +wmKeyMapItem *WM_keymap_add_tool(wmKeyMap *keymap, + const char *idname, + int type, + int val, + int modifier, + int keymodifier, + int direction) { wmKeyMapItem *kmi = WM_keymap_add_item( - keymap, "WM_OT_tool_set_by_id", type, val, modifier, keymodifier); + keymap, "WM_OT_tool_set_by_id", type, val, modifier, keymodifier, direction); RNA_string_set(kmi->ptr, "name", idname); return kmi; } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 6b8f7309d80..6e0bf911555 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -911,9 +911,9 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) ret_value = op->type->exec(C, op); OPERATOR_RETVAL_CHECK(ret_value); - op->customdata = POINTER_FROM_INT((int)event->type); if (ret_value & OPERATOR_RUNNING_MODAL) { + printf("Starting modal: %s\n", op->idname); WM_event_add_modal_handler(C, op); } return ret_value | OPERATOR_PASS_THROUGH; diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 68b16d46746..172a879e118 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -74,16 +74,8 @@ void wm_gesture_draw(struct wmWindow *win); /** * Tweak and line gestures. */ -int wm_gesture_evaluate(wmGesture *gesture, const struct wmEvent *event); void wm_gesture_tag_redraw(struct wmWindow *win); -/* wm_gesture_ops.c */ - -/** - * Standard tweak, called after window handlers passed on event. - */ -void wm_tweakevent_test(bContext *C, const wmEvent *event, int action); - /* wm_jobs.c */ /** diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index c5764ad7a5e..1e907578e52 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -325,16 +325,6 @@ enum { /* NOTE: these values are saved in key-map files, do not change them but just add new ones. */ - /* Tweak events: - * Sent as additional event with the mouse coordinates - * from where the initial click was placed. */ - - /* Tweak events for L M R mouse-buttons. */ - EVT_TWEAK_L = 0x5002, /* 20482 */ - EVT_TWEAK_M = 0x5003, /* 20483 */ - EVT_TWEAK_R = 0x5004, /* 20484 */ - /* 0x5010 (and lower) should be left to add other tweak types in the future. */ - /* 0x5011 is taken, see EVT_ACTIONZONE_FULLSCREEN */ /* Misc Blender internals: 0x502x */ @@ -394,9 +384,6 @@ enum { BUTTON6MOUSE, \ BUTTON7MOUSE)) -/** Test whether the event is tweak event. */ -#define ISTWEAK(event_type) ((event_type) >= EVT_TWEAK_L && (event_type) <= EVT_TWEAK_R) - /** Test whether the event is a NDOF event. */ #define ISNDOF(event_type) ((event_type) >= _NDOF_MIN && (event_type) <= _NDOF_MAX) @@ -423,14 +410,11 @@ enum eEventType_Mask { EVT_TYPE_MASK_MOUSE = (1 << 5), /** #ISNDOF */ EVT_TYPE_MASK_NDOF = (1 << 6), - /** #ISTWEAK */ - EVT_TYPE_MASK_TWEAK = (1 << 7), /** #IS_EVENT_ACTIONZONE */ - EVT_TYPE_MASK_ACTIONZONE = (1 << 8), + EVT_TYPE_MASK_ACTIONZONE = (1 << 7), }; #define EVT_TYPE_MASK_ALL \ - (EVT_TYPE_MASK_KEYBOARD | EVT_TYPE_MASK_MOUSE | EVT_TYPE_MASK_NDOF | EVT_TYPE_MASK_TWEAK | \ - EVT_TYPE_MASK_ACTIONZONE) + (EVT_TYPE_MASK_KEYBOARD | EVT_TYPE_MASK_MOUSE | EVT_TYPE_MASK_NDOF | EVT_TYPE_MASK_ACTIONZONE) #define EVT_TYPE_MASK_HOTKEY_INCLUDE \ (EVT_TYPE_MASK_KEYBOARD | EVT_TYPE_MASK_MOUSE | EVT_TYPE_MASK_NDOF) |