Cleanup: add ISMOUSE_MOTION macro
Replace verbose ELEM(..) usage, now each kind of mouse event has it's own macro.
This commit is contained in:
@@ -1162,7 +1162,7 @@ static int curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
curve_draw_event_add_first(op, event);
|
||||
}
|
||||
}
|
||||
else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
else if (ISMOUSE_MOTION(event->type)) {
|
||||
if (cdd->state == CURVE_DRAW_PAINTING) {
|
||||
const float mval_fl[2] = {UNPACK2(event->mval)};
|
||||
if (len_squared_v2v2(mval_fl, cdd->prev.mval) > square_f(STROKE_SAMPLE_DIST_MIN_PX)) {
|
||||
|
||||
@@ -1622,7 +1622,7 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
/* Check if dragging */
|
||||
if (!cpd->dragging && WM_event_drag_test(event, event->prev_press_xy)) {
|
||||
cpd->dragging = true;
|
||||
|
||||
@@ -2641,7 +2641,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
|
||||
/* handle mode-specific events */
|
||||
if (p->status == GP_STATUS_PAINTING) {
|
||||
/* handle painting mouse-movements? */
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) {
|
||||
if (ISMOUSE_MOTION(event->type) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) {
|
||||
/* handle drawing event */
|
||||
if ((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) {
|
||||
annotation_add_missing_events(C, op, event, p);
|
||||
|
||||
@@ -3755,7 +3755,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
/* handle mode-specific events */
|
||||
if (p->status == GP_STATUS_PAINTING) {
|
||||
/* handle painting mouse-movements? */
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) {
|
||||
if (ISMOUSE_MOTION(event->type) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) {
|
||||
/* handle drawing event */
|
||||
bool is_speed_guide = ((guide->use_guide) &&
|
||||
(p->brush && (p->brush->gpencil_tool == GPAINT_TOOL_DRAW)));
|
||||
|
||||
@@ -479,7 +479,7 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
else if (ISMOUSE_MOTION(event->type)) {
|
||||
if (eye->accum_start) {
|
||||
/* button is pressed so keep sampling */
|
||||
eyedropper_color_sample(C, eye, event->xy);
|
||||
|
||||
@@ -4509,7 +4509,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
|
||||
}
|
||||
}
|
||||
else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) {
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
}
|
||||
if (event->type == EVT_UNKNOWNKEY) {
|
||||
@@ -4575,7 +4575,7 @@ static int ui_do_but_KEYEVT(bContext *C,
|
||||
}
|
||||
}
|
||||
else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) {
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -8097,7 +8097,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
|
||||
#ifdef USE_DRAG_MULTINUM
|
||||
data = but->active;
|
||||
if (data) {
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) ||
|
||||
if (ISMOUSE_MOTION(event->type) ||
|
||||
/* if we started dragging, progress on any event */
|
||||
(data->multi_data.init == BUTTON_MULTI_INIT_SETUP)) {
|
||||
if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER) &&
|
||||
|
||||
@@ -2318,7 +2318,7 @@ int ui_handler_panel_region(bContext *C,
|
||||
const uiBut *active_but)
|
||||
{
|
||||
/* Mouse-move events are handled by separate handlers for dragging and drag collapsing. */
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -8692,7 +8692,7 @@ static int edbm_point_normals_modal(bContext *C, wmOperator *op, const wmEvent *
|
||||
* Free the data here, then use #point_normals_ensure to add it back on demand. */
|
||||
if (ret == OPERATOR_PASS_THROUGH) {
|
||||
/* Don't free on mouse-move, causes creation/freeing of the loop data in an inefficient way. */
|
||||
if (!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (!ISMOUSE_MOTION(event->type)) {
|
||||
point_normals_free(op);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,8 +1550,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS
|
||||
copy_v2_fl2(mouse, event->mval[0], event->mval[1]);
|
||||
paint_stroke_line_constrain(stroke, mouse);
|
||||
|
||||
if (stroke->stroke_started &&
|
||||
(first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)))) {
|
||||
if (stroke->stroke_started && (first_modal || ISMOUSE_MOTION(event->type))) {
|
||||
if ((br->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) ||
|
||||
(br->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
|
||||
copy_v2_v2(stroke->ups->last_rake, stroke->last_mouse_position);
|
||||
@@ -1561,7 +1560,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS
|
||||
}
|
||||
else if (first_modal ||
|
||||
/* regular dabs */
|
||||
(!(br->flag & BRUSH_AIRBRUSH) && (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE))) ||
|
||||
(!(br->flag & BRUSH_AIRBRUSH) && ISMOUSE_MOTION(event->type)) ||
|
||||
/* airbrush */
|
||||
((br->flag & BRUSH_AIRBRUSH) && event->type == TIMER &&
|
||||
event->customdata == stroke->timer)) {
|
||||
|
||||
@@ -659,7 +659,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event)
|
||||
if (event->type == TIMER && event->customdata == walk->timer) {
|
||||
walk->redraw = true;
|
||||
}
|
||||
else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
else if (ISMOUSE_MOTION(event->type)) {
|
||||
|
||||
#ifdef USE_TABLET_SUPPORT
|
||||
if ((walk->is_cursor_absolute == false) && event->tablet.is_motion_absolute) {
|
||||
|
||||
@@ -1327,7 +1327,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (t->redraw && !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (t->redraw && !ISMOUSE_MOTION(event->type)) {
|
||||
WM_window_status_area_tag_redraw(CTX_wm_window(t->context));
|
||||
}
|
||||
|
||||
|
||||
@@ -625,7 +625,7 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (ELEM(type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(type)) {
|
||||
if (value != KM_NOTHING) {
|
||||
BKE_report(reports, RPT_ERROR, "Value: must be 'NOTHING' for motion");
|
||||
return NULL;
|
||||
|
||||
@@ -190,7 +190,7 @@ void wm_event_free(wmEvent *event)
|
||||
printf("%s: 'is_repeat=true' for non-keyboard event, this should not happen.\n", __func__);
|
||||
WM_event_print(event);
|
||||
}
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) && (event->val != KM_NOTHING)) {
|
||||
if (ISMOUSE_MOTION(event->type) && (event->val != KM_NOTHING)) {
|
||||
printf("%s: 'val != NOTHING' for a cursor motion event, this should not happen.\n", __func__);
|
||||
WM_event_print(event);
|
||||
}
|
||||
@@ -3095,7 +3095,7 @@ static int wm_handlers_do_intern(bContext *C, wmWindow *win, wmEvent *event, Lis
|
||||
const bool do_debug_handler =
|
||||
(G.debug & G_DEBUG_HANDLERS) &&
|
||||
/* Comment this out to flood the console! (if you really want to test). */
|
||||
!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE);
|
||||
!ISMOUSE_MOTION(event->type);
|
||||
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
int action = WM_HANDLER_CONTINUE;
|
||||
@@ -3286,7 +3286,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
|
||||
return action;
|
||||
}
|
||||
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
/* Test for #KM_CLICK_DRAG events. */
|
||||
|
||||
/* NOTE(@campbellbarton): Needed so drag can be used for editors that support both click
|
||||
@@ -3821,15 +3821,14 @@ void wm_event_do_handlers(bContext *C)
|
||||
/* Active screen might change during handlers, update pointer. */
|
||||
screen = WM_window_get_active_screen(win);
|
||||
|
||||
if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) &&
|
||||
!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && !ISMOUSE_MOTION(event->type)) {
|
||||
printf("\n%s: Handling event\n", __func__);
|
||||
WM_event_print(event);
|
||||
}
|
||||
|
||||
/* Take care of pie event filter. */
|
||||
if (wm_event_pie_filter(win, event)) {
|
||||
if (!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (!ISMOUSE_MOTION(event->type)) {
|
||||
CLOG_INFO(WM_LOG_HANDLERS, 1, "event filtered due to pie button pressed");
|
||||
}
|
||||
BLI_remlink(&win->event_queue, event);
|
||||
@@ -3851,7 +3850,7 @@ void wm_event_do_handlers(bContext *C)
|
||||
|
||||
/* Clear tool-tip on mouse move. */
|
||||
if (screen->tool_tip && screen->tool_tip->exit_on_event) {
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
if (len_manhattan_v2v2_int(screen->tool_tip->event_xy, event->xy) >
|
||||
WM_EVENT_CURSOR_MOTION_THRESHOLD) {
|
||||
WM_tooltip_clear(C, win);
|
||||
|
||||
@@ -939,7 +939,7 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
return ret_value | OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
|
||||
if (ISMOUSE_MOTION(event->type)) {
|
||||
const int drag_delta[2] = {
|
||||
mval[0] - event->mval[0],
|
||||
mval[1] - event->mval[1],
|
||||
|
||||
@@ -387,16 +387,14 @@ enum {
|
||||
|
||||
/**
|
||||
* Test whether the event is any kind:
|
||||
* #ISMOUSE_BUTTON, #ISMOUSE_WHEEL, #ISMOUSE_GESTURE & motion.
|
||||
* #ISMOUSE_MOTION, #ISMOUSE_BUTTON, #ISMOUSE_WHEEL & #ISMOUSE_GESTURE.
|
||||
*
|
||||
* \note It's best to use more specific check if possible as mixing motion/buttons/gestures
|
||||
* is very broad and not necessarily obvious which kinds of events are important.
|
||||
*/
|
||||
#define ISMOUSE(event_type) ((event_type) >= _EVT_MOUSE_MIN && (event_type) <= _EVT_MOUSE_MAX)
|
||||
/** Test whether the event is a mouse wheel. */
|
||||
#define ISMOUSE_WHEEL(event_type) ((event_type) >= WHEELUPMOUSE && (event_type) <= WHEELOUTMOUSE)
|
||||
/** Test whether the event is a mouse (track-pad) gesture. */
|
||||
#define ISMOUSE_GESTURE(event_type) ((event_type) >= MOUSEPAN && (event_type) <= MOUSESMARTZOOM)
|
||||
/** Test whether the event is a mouse button (excluding mouse-wheel). */
|
||||
#define ISMOUSE_MOTION(event_type) ELEM(event_type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)
|
||||
/** Test whether the event is a mouse button (excluding mouse-wheel). */
|
||||
#define ISMOUSE_BUTTON(event_type) \
|
||||
(ELEM(event_type, \
|
||||
@@ -407,6 +405,10 @@ enum {
|
||||
BUTTON5MOUSE, \
|
||||
BUTTON6MOUSE, \
|
||||
BUTTON7MOUSE))
|
||||
/** Test whether the event is a mouse wheel. */
|
||||
#define ISMOUSE_WHEEL(event_type) ((event_type) >= WHEELUPMOUSE && (event_type) <= WHEELOUTMOUSE)
|
||||
/** Test whether the event is a mouse (track-pad) gesture. */
|
||||
#define ISMOUSE_GESTURE(event_type) ((event_type) >= MOUSEPAN && (event_type) <= MOUSESMARTZOOM)
|
||||
|
||||
/** Test whether the event is a NDOF event. */
|
||||
#define ISNDOF(event_type) ((event_type) >= _NDOF_MIN && (event_type) <= _NDOF_MAX)
|
||||
|
||||
Reference in New Issue
Block a user