From cae97709549224a94ec71a4de5f159af1d876f0a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 16 Oct 2017 13:01:09 +1100 Subject: Cleanup: rename gesture mode to is_active Wasn't obvious what this did at a glance. --- source/blender/windowmanager/WM_types.h | 5 ++++- source/blender/windowmanager/intern/wm_gesture.c | 6 ++++-- source/blender/windowmanager/intern/wm_operators.c | 17 +++++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index f6049f10378..1c8d12973c6 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -409,11 +409,14 @@ typedef struct wmNotifier { typedef struct wmGesture { struct wmGesture *next, *prev; int event_type; /* event->type */ - int mode; /* for modal callback */ int type; /* gesture type define */ int swinid; /* initial subwindow id where it started */ int points; /* optional, amount of points stored */ int size; /* optional, maximum amount of points stored */ + + /* For modal operators which may be running idle, waiting for an event to activate the gesture. + * Typically this is set when the user is click-dragging the gesture (border and circle select for eg). */ + uint is_active : 1; void *customdata; /* customdata for border is a recti */ diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index cc48b162352..311b501a179 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -377,10 +377,12 @@ void wm_gesture_draw(wmWindow *win) else if (gt->type == WM_GESTURE_CIRCLE) wm_gesture_draw_circle(gt); else if (gt->type == WM_GESTURE_CROSS_RECT) { - if (gt->mode == 1) + if (gt->is_active) { wm_gesture_draw_rect(gt); - else + } + else { wm_gesture_draw_cross(win, gt); + } } else if (gt->type == WM_GESTURE_LINES) wm_gesture_draw_lasso(win, gt, false); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index ae5a8319b00..330a18eeda5 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2336,7 +2336,7 @@ int WM_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event->type == MOUSEMOVE) { wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy); - if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->mode == 0) { + if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { rect->xmin = rect->xmax = event->x - sx; rect->ymin = rect->ymax = event->y - sy; } @@ -2351,8 +2351,8 @@ int WM_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (event->type == EVT_MODAL_MAP) { switch (event->val) { case GESTURE_MODAL_BEGIN: - if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->mode == 0) { - gesture->mode = 1; + if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { + gesture->is_active = true; wm_gesture_tag_redraw(C); } break; @@ -2447,8 +2447,9 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event) wm_gesture_tag_redraw(C); - if (gesture->mode) + if (gesture->is_active) { gesture_circle_apply(C, op); + } } else if (event->type == EVT_MODAL_MAP) { float fac; @@ -2481,7 +2482,7 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event->val != GESTURE_MODAL_NOP) { /* apply first click */ gesture_circle_apply(C, op); - gesture->mode = 1; + gesture->is_active = true; wm_gesture_tag_redraw(C); } break; @@ -2881,7 +2882,7 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev if (event->type == MOUSEMOVE) { wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy); - if (gesture->mode == 0) { + if (gesture->is_active == false) { rect->xmin = rect->xmax = event->x - sx; rect->ymin = rect->ymax = event->y - sy; } @@ -2896,8 +2897,8 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev else if (event->type == EVT_MODAL_MAP) { switch (event->val) { case GESTURE_MODAL_BEGIN: - if (gesture->mode == 0) { - gesture->mode = 1; + if (gesture->is_active == false) { + gesture->is_active = true; wm_gesture_tag_redraw(C); } break; -- cgit v1.2.3 From 201b02f2a740290796eedfc8346fabe13e945ad2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 16 Oct 2017 13:18:50 +1100 Subject: Cleanup: simplify lasso reallocation Remove unneeded define, double allocations when increasing. --- source/blender/windowmanager/WM_types.h | 2 +- source/blender/windowmanager/intern/wm_gesture.c | 4 ++-- source/blender/windowmanager/intern/wm_operators.c | 20 ++++++++------------ source/blender/windowmanager/wm.h | 1 - 4 files changed, 11 insertions(+), 16 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 1c8d12973c6..d8ec26f55da 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -412,7 +412,7 @@ typedef struct wmGesture { int type; /* gesture type define */ int swinid; /* initial subwindow id where it started */ int points; /* optional, amount of points stored */ - int size; /* optional, maximum amount of points stored */ + int points_alloc; /* optional, maximum amount of points stored */ /* For modal operators which may be running idle, waiting for an event to activate the gesture. * Typically this is set when the user is click-dragging the gesture (border and circle select for eg). */ diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 311b501a179..f66efa72908 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -97,11 +97,11 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type) } else if (ELEM(type, WM_GESTURE_LINES, WM_GESTURE_LASSO)) { short *lasso; - gesture->customdata = lasso = MEM_callocN(2 * sizeof(short) * WM_LASSO_MIN_POINTS, "lasso points"); + gesture->points_alloc = 1024; + gesture->customdata = lasso = MEM_mallocN(sizeof(short[2]) * gesture->points_alloc, "lasso points"); lasso[0] = event->x - sx; lasso[1] = event->y - sy; gesture->points = 1; - gesture->size = WM_LASSO_MIN_POINTS; } return gesture; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 330a18eeda5..6fdc0a0a8c0 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2692,28 +2692,24 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event) switch (event->type) { case MOUSEMOVE: case INBETWEEN_MOUSEMOVE: - + wm_gesture_tag_redraw(C); - + wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy); - if (gesture->points == gesture->size) { - short *old_lasso = gesture->customdata; - gesture->customdata = MEM_callocN(2 * sizeof(short) * (gesture->size + WM_LASSO_MIN_POINTS), "lasso points"); - memcpy(gesture->customdata, old_lasso, 2 * sizeof(short) * gesture->size); - gesture->size = gesture->size + WM_LASSO_MIN_POINTS; - MEM_freeN(old_lasso); - // printf("realloc\n"); + if (gesture->points == gesture->points_alloc) { + gesture->points_alloc *= 2; + gesture->customdata = MEM_reallocN(gesture->customdata, sizeof(short[2]) * gesture->points_alloc); } { int x, y; short *lasso = gesture->customdata; - + lasso += (2 * gesture->points - 2); x = (event->x - sx - lasso[0]); y = (event->y - sy - lasso[1]); - + /* make a simple distance check to get a smoother lasso * add only when at least 2 pixels between this and previous location */ if ((x * x + y * y) > 4) { @@ -2724,7 +2720,7 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event) } } break; - + case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 1206c2b194a..cb88ca3a474 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -60,7 +60,6 @@ void wm_window_keymap(wmKeyConfig *keyconf); void wm_tweakevent_test(bContext *C, const wmEvent *event, int action); /* wm_gesture.c */ -#define WM_LASSO_MIN_POINTS 1024 void wm_gesture_draw(struct wmWindow *win); int wm_gesture_evaluate(wmGesture *gesture); void wm_gesture_tag_redraw(bContext *C); -- cgit v1.2.3 From 137586a13c758d95472c3a3eabfc7dd4b22b7502 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 16 Oct 2017 14:19:03 +1100 Subject: Event System: Prevent mouse motion in click events Don't convert mouse button events to click if they include dragging. Double-click events already checked for this. --- source/blender/windowmanager/intern/wm_event_system.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 7e7314cc0c8..a6777d40398 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -83,6 +83,9 @@ #include "RNA_enum_types.h" +/* Motion in pixels allowed before we don't consider single/double click. */ +#define WM_EVENT_CLICK_WIGGLE_ROOM 2 + static void wm_notifier_clear(wmNotifier *note); static void update_tablet_data(wmWindow *win, wmEvent *event); @@ -2204,7 +2207,9 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if ((event->val == KM_RELEASE) && (win->eventstate->prevval == KM_PRESS) && - (win->eventstate->check_click == true)) + (win->eventstate->check_click == true) && + ((abs(event->x - win->eventstate->prevclickx)) <= WM_EVENT_CLICK_WIGGLE_ROOM && + (abs(event->y - win->eventstate->prevclicky)) <= WM_EVENT_CLICK_WIGGLE_ROOM)) { event->val = KM_CLICK; @@ -3163,8 +3168,9 @@ static bool wm_event_is_double_click(wmEvent *event, const wmEvent *event_state) (event_state->prevval == KM_RELEASE) && (event->val == KM_PRESS)) { - if ((ISMOUSE(event->type) == false) || ((ABS(event->x - event_state->prevclickx)) <= 2 && - (ABS(event->y - event_state->prevclicky)) <= 2)) + if ((ISMOUSE(event->type) == false) || + ((abs(event->x - event_state->prevclickx)) <= WM_EVENT_CLICK_WIGGLE_ROOM && + (abs(event->y - event_state->prevclicky)) <= WM_EVENT_CLICK_WIGGLE_ROOM)) { if ((PIL_check_seconds_timer() - event_state->prevclicktime) * 1000 < U.dbl_click_time) { return true; -- cgit v1.2.3