Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-06-07 18:05:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-06-07 18:06:01 +0300
commitd274c64d22da51473839d87618ba0dc0a0f1fa42 (patch)
tree623183dd0c0f10e3920a637840dae62d094502b0 /source/blender/windowmanager
parentdf4525d1d9d5250b8d0bdc6370f2736c2607b044 (diff)
WM: add support for drag events
This allows for a single key to be mapped to both release and drag, useful for pie menus to share a key with a different action.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_types.h2
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c26
2 files changed, 27 insertions, 1 deletions
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 298c5184ced..8c53f5389e3 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -188,6 +188,7 @@ enum {
#define KM_RELEASE 2
#define KM_CLICK 3
#define KM_DBL_CLICK 4
+#define KM_CLICK_DRAG 5
/* ************** UI Handler ***************** */
@@ -462,6 +463,7 @@ typedef struct wmEvent {
/* set in case a KM_PRESS went by unhandled */
char check_click;
+ char check_drag;
char is_motion_absolute;
/* keymap item, set by handler (weak?) */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 83bad28ce02..f820a0a1b8d 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2221,8 +2221,30 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
if (CTX_wm_window(C) == NULL)
return action;
- if (!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE, EVENT_NONE) && !ISTIMER(event->type)) {
+ if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
+ if (event->check_drag) {
+ wmWindow *win = CTX_wm_window(C);
+ if ((abs(event->x - win->eventstate->prevclickx)) >= U.tweak_threshold ||
+ (abs(event->y - win->eventstate->prevclicky)) >= U.tweak_threshold)
+ {
+ short val = event->val;
+ short type = event->type;
+ event->val = KM_CLICK_DRAG;
+ event->type = win->eventstate->type;
+
+ CLOG_INFO(WM_LOG_HANDLERS, 1, "handling PRESS_DRAG");
+
+ action |= wm_handlers_do_intern(C, event, handlers);
+ event->val = val;
+ event->type = type;
+
+ win->eventstate->check_click = 0;
+ win->eventstate->check_drag = 0;
+ }
+ }
+ }
+ else if (!ELEM(event->type, EVENT_NONE) && !ISTIMER(event->type)) {
/* test for CLICK events */
if (wm_action_not_handled(action)) {
wmWindow *win = CTX_wm_window(C);
@@ -2232,6 +2254,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
if (win && event->val == KM_PRESS) {
win->eventstate->check_click = true;
+ win->eventstate->check_drag = true;
}
if (win && win->eventstate->prevtype == event->type) {
@@ -2253,6 +2276,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
}
else {
win->eventstate->check_click = 0;
+ win->eventstate->check_drag = 0;
}
}
else if (event->val == KM_DBL_CLICK) {