From ad0b3abf539bbb358f799d3f36649b5d46f222c8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 24 Feb 2022 22:48:34 +1100 Subject: Cleanup: use flags for wmEvent modifier keys Using flags makes checking multiple modifiers at once more convenient and avoids macros/functions such as IS_EVENT_MOD & WM_event_modifier_flag which have been removed. It also simplifies checking if modifier keys have changed. --- .../interface/interface_eyedropper_gpencil_color.c | 6 +- .../blender/editors/interface/interface_handlers.c | 175 ++++++++++----------- .../blender/editors/interface/interface_layout.c | 4 +- source/blender/editors/interface/interface_panel.c | 19 ++- source/blender/editors/interface/interface_query.c | 2 +- .../editors/interface/interface_region_tooltip.c | 2 +- .../editors/interface/interface_templates.c | 6 +- 7 files changed, 108 insertions(+), 106 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c index d6f529f9f94..f3c70e6a96a 100644 --- a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c +++ b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c @@ -222,9 +222,9 @@ static void eyedropper_add_palette_color(bContext *C, const float col_conv[4]) static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, EyedropperGPencil *eye) { - const bool only_stroke = ((!event->ctrl) && (!event->shift)); - const bool only_fill = ((!event->ctrl) && (event->shift)); - const bool both = ((event->ctrl) && (event->shift)); + const bool only_stroke = (event->modifier & (KM_CTRL | KM_SHIFT)) == 0; + const bool only_fill = ((event->modifier & KM_CTRL) == 0 && (event->modifier & KM_SHIFT)); + const bool both = ((event->modifier & KM_CTRL) && (event->modifier & KM_SHIFT)); float col_conv[4]; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 9dcee73f6bb..3d92cd6c397 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -275,7 +275,7 @@ static void ui_selectcontext_apply(bContext *C, const double value, const double value_orig); -# define IS_ALLSELECT_EVENT(event) ((event)->alt != 0) +# define IS_ALLSELECT_EVENT(event) (((event)->modifier & KM_ALT) != 0) /** just show a tinted color so users know its activated */ # define UI_BUT_IS_SELECT_CONTEXT UI_BUT_NODE_ACTIVE @@ -708,7 +708,8 @@ enum eSnapType { static enum eSnapType ui_event_to_snap(const wmEvent *event) { - return (event->ctrl) ? (event->shift) ? SNAP_ON_SMALL : SNAP_ON : SNAP_OFF; + return (event->modifier & KM_CTRL) ? (event->modifier & KM_SHIFT) ? SNAP_ON_SMALL : SNAP_ON : + SNAP_OFF; } static bool ui_event_is_snap(const wmEvent *event) @@ -1937,7 +1938,7 @@ static void ui_selectcontext_apply(bContext *C, /* could check for 'handle_layer_buttons' */ but->func) { wmWindow *win = CTX_wm_window(C); - if (!win->eventstate->shift) { + if ((win->eventstate->modifier & KM_SHIFT) == 0) { const int len = RNA_property_array_length(&but->rnapoin, prop); bool *tmparray = MEM_callocN(sizeof(bool) * len, __func__); @@ -3747,11 +3748,11 @@ static void ui_do_but_textedit( case EVT_XKEY: case EVT_CKEY: #if defined(__APPLE__) - if ((event->oskey && !IS_EVENT_MOD(event, shift, alt, ctrl)) || - (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey))) { + if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) #else - if (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey)) { + if (event->modifier == KM_CTRL) #endif + { if (event->type == EVT_VKEY) { changed = ui_textedit_copypaste(but, data, UI_TEXTEDIT_PASTE); } @@ -3769,16 +3770,16 @@ static void ui_do_but_textedit( ui_textedit_move(but, data, STRCUR_DIR_NEXT, - event->shift != 0, - event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + event->modifier & KM_SHIFT, + (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case EVT_LEFTARROWKEY: ui_textedit_move(but, data, STRCUR_DIR_PREV, - event->shift != 0, - event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + event->modifier & KM_SHIFT, + (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case WHEELDOWNMOUSE: @@ -3795,7 +3796,7 @@ static void ui_do_but_textedit( } ATTR_FALLTHROUGH; case EVT_ENDKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift != 0, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->modifier & KM_SHIFT, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case WHEELUPMOUSE: @@ -3812,7 +3813,7 @@ static void ui_do_but_textedit( } ATTR_FALLTHROUGH; case EVT_HOMEKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift != 0, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_PREV, event->modifier & KM_SHIFT, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case EVT_PADENTER: @@ -3822,13 +3823,13 @@ static void ui_do_but_textedit( break; case EVT_DELKEY: changed = ui_textedit_delete( - but, data, 1, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + but, data, 1, (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case EVT_BACKSPACEKEY: changed = ui_textedit_delete( - but, data, 0, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + but, data, 0, (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; @@ -3837,10 +3838,9 @@ static void ui_do_but_textedit( /* Ctrl-A: Select all. */ #if defined(__APPLE__) /* OSX uses Command-A system-wide, so add it. */ - if ((event->oskey && !IS_EVENT_MOD(event, shift, alt, ctrl)) || - (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey))) + if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) #else - if (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey)) + if (event->modifier == KM_CTRL) #endif { ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_ALL); @@ -3859,9 +3859,9 @@ static void ui_do_but_textedit( button_activate_state(C, but, BUTTON_STATE_EXIT); } } - else if (!IS_EVENT_MOD(event, ctrl, alt, oskey)) { + else if ((event->modifier & (KM_CTRL | KM_ALT | KM_OSKEY)) == 0) { /* Use standard keys for cycling through buttons Tab, Shift-Tab to reverse. */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { ui_textedit_prev_but(block, but, data); } else { @@ -3874,12 +3874,12 @@ static void ui_do_but_textedit( case EVT_ZKEY: { /* Ctrl-Z or Ctrl-Shift-Z: Undo/Redo (allowing for OS-Key on Apple). */ - const bool is_redo = (event->shift != 0); + const bool is_redo = (event->modifier & KM_SHIFT); if ( #if defined(__APPLE__) - (event->oskey && !IS_EVENT_MOD(event, alt, ctrl)) || + ((event->modifier & KM_OSKEY) && ((event->modifier & (KM_ALT | KM_CTRL)) == 0)) || #endif - (event->ctrl && !IS_EVENT_MOD(event, alt, oskey))) { + ((event->modifier & KM_CTRL) && ((event->modifier & (KM_ALT | KM_OSKEY)) == 0))) { int undo_pos; const char *undo_str = ui_textedit_undo( data->undo_stack_text, is_redo ? 1 : -1, &undo_pos); @@ -4542,19 +4542,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C, } /* always set */ - but->modifier_key = 0; - if (event->shift) { - but->modifier_key |= KM_SHIFT; - } - if (event->alt) { - but->modifier_key |= KM_ALT; - } - if (event->ctrl) { - but->modifier_key |= KM_CTRL; - } - if (event->oskey) { - but->modifier_key |= KM_OSKEY; - } + but->modifier_key = event->modifier; ui_but_update(but); ED_region_tag_redraw(data->region); @@ -4633,7 +4621,8 @@ static int ui_do_but_TAB( const int rna_type = but->rnaprop ? RNA_property_type(but->rnaprop) : 0; if (is_property && ELEM(rna_type, PROP_POINTER, PROP_STRING) && (but->custom_data != NULL) && - (event->type == LEFTMOUSE) && ((event->val == KM_DBL_CLICK) || event->ctrl)) { + (event->type == LEFTMOUSE) && + ((event->val == KM_DBL_CLICK) || (event->modifier & KM_CTRL))) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); return WM_UI_HANDLER_BREAK; } @@ -4666,7 +4655,8 @@ static int ui_do_but_TEX( if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && (!UI_but_is_utf8(but))) { /* pass - allow filesel, enter to execute */ } - else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && !event->ctrl) { + else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && + ((event->modifier & KM_CTRL) == 0)) { /* pass */ } else { @@ -4735,7 +4725,7 @@ static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, cons button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { /* Support Ctrl-Wheel to cycle values on expanded enum rows. */ if (but->type == UI_BTYPE_ROW) { int type = event->type; @@ -5325,24 +5315,24 @@ static int ui_do_but_NUM( } /* XXX hardcoded keymap check.... */ - if (type == MOUSEPAN && event->ctrl) { + if (type == MOUSEPAN && (event->modifier & KM_CTRL)) { /* allow accumulating values, otherwise scrolling gets preference */ retval = WM_UI_HANDLER_BREAK; } - else if (type == WHEELDOWNMOUSE && event->ctrl) { + else if (type == WHEELDOWNMOUSE && (event->modifier & KM_CTRL)) { mx = but->rect.xmin; but->drawflag &= ~UI_BUT_ACTIVE_RIGHT; but->drawflag |= UI_BUT_ACTIVE_LEFT; click = 1; } - else if (type == WHEELUPMOUSE && event->ctrl) { + else if ((type == WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmax; but->drawflag &= ~UI_BUT_ACTIVE_LEFT; but->drawflag |= UI_BUT_ACTIVE_RIGHT; click = 1; } else if (event->val == KM_PRESS) { - if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->ctrl) { + if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->modifier & KM_CTRL)) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); retval = WM_UI_HANDLER_BREAK; } @@ -5402,7 +5392,7 @@ static int ui_do_but_NUM( #endif fac = 1.0f; - if (event->shift) { + if (event->modifier & KM_SHIFT) { fac /= 10.0f; } @@ -5668,27 +5658,27 @@ static int ui_do_but_SLI( } /* XXX hardcoded keymap check.... */ - if (type == MOUSEPAN && event->ctrl) { + if ((type == MOUSEPAN) && (event->modifier & KM_CTRL)) { /* allow accumulating values, otherwise scrolling gets preference */ retval = WM_UI_HANDLER_BREAK; } - else if (type == WHEELDOWNMOUSE && event->ctrl) { + else if ((type == WHEELDOWNMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmin; click = 2; } - else if (type == WHEELUPMOUSE && event->ctrl) { + else if ((type == WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmax; click = 2; } else if (event->val == KM_PRESS) { - if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->ctrl) { + if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->modifier & KM_CTRL)) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); retval = WM_UI_HANDLER_BREAK; } #ifndef USE_ALLSELECT /* alt-click on sides to get "arrows" like in UI_BTYPE_NUM buttons, * and match wheel usage above */ - else if (event->type == LEFTMOUSE && event->alt) { + else if ((event->type == LEFTMOUSE) && (event->modifier & KM_ALT)) { int halfpos = BLI_rctf_cent_x(&but->rect); click = 2; if (mx < halfpos) { @@ -5754,8 +5744,13 @@ static int ui_do_but_SLI( data->multi_data.drag_dir[0] += abs(data->draglastx - mx); data->multi_data.drag_dir[1] += abs(data->draglasty - my); #endif - if (ui_numedit_but_SLI( - but, data, mx, true, is_motion, event->ctrl != 0, event->shift != 0)) { + if (ui_numedit_but_SLI(but, + data, + mx, + true, + is_motion, + event->modifier & KM_CTRL, + event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -5981,8 +5976,8 @@ static int ui_do_but_LISTROW(bContext *C, /* hack to pass on ctrl+click and double click to overlapping text * editing field for editing list item names */ - if ((ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS && - event->ctrl) || + if ((ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->val == KM_PRESS) && + (event->modifier & KM_CTRL)) || (event->type == LEFTMOUSE && event->val == KM_DBL_CLICK)) { uiBut *labelbut = ui_but_list_row_text_activate( C, but, data, event, BUTTON_ACTIVATE_TEXT_EDITING); @@ -6023,7 +6018,8 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co return WM_UI_HANDLER_BREAK; } if (ui_but_supports_cycling(but)) { - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && + (event->modifier & KM_CTRL)) { int type = event->type; int val = event->val; @@ -6210,7 +6206,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); return WM_UI_HANDLER_BREAK; } - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { ColorPicker *cpicker = but->custom_data; float hsv_static[3] = {0.0f}; float *hsv = cpicker ? cpicker->hsv_perceptual : hsv_static; @@ -6269,7 +6265,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { if (color_but->is_pallete_color) { - if (!event->ctrl) { + if ((event->modifier & KM_CTRL) == 0) { float color[3]; Paint *paint = BKE_paint_get_active_from_context(C); Brush *brush = BKE_paint_brush(paint); @@ -6639,7 +6635,7 @@ static int ui_do_but_HSVCUBE( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -6650,7 +6646,7 @@ static int ui_do_but_HSVCUBE( const wmNDOFMotionData *ndof = event->customdata; const enum eSnapType snap = ui_event_to_snap(event); - ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->shift != 0); + ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->modifier & KM_SHIFT); button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); @@ -6702,7 +6698,7 @@ static int ui_do_but_HSVCUBE( if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); - if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -6914,7 +6910,7 @@ static int ui_do_but_HSVCIRCLE( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -6925,7 +6921,7 @@ static int ui_do_but_HSVCIRCLE( const enum eSnapType snap = ui_event_to_snap(event); const wmNDOFMotionData *ndof = event->customdata; - ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->shift != 0); + ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->modifier & KM_SHIFT); button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); @@ -6987,7 +6983,7 @@ static int ui_do_but_HSVCIRCLE( if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); - if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7037,7 +7033,7 @@ static int ui_do_but_COLORBAND( if (event->type == LEFTMOUSE && event->val == KM_PRESS) { ColorBand *coba = (ColorBand *)but->poin; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { /* insert new key on mouse location */ const float pos = ((float)(mx - but->rect.xmin)) / BLI_rctf_size_x(&but->rect); BKE_colorband_element_add(coba, pos); @@ -7237,7 +7233,7 @@ static int ui_do_but_CURVE( float dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius */ int sel = -1; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { float f_xy[2]; BLI_rctf_transform_pt_v(&cumap->curr, &but->rect, f_xy, m_xy); @@ -7301,7 +7297,7 @@ static int ui_do_but_CURVE( if (sel != -1) { /* ok, we move a point */ /* deselect all if this one is deselect. except if we hold shift */ - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { for (int a = 0; a < cuma->totpoint; a++) { cmp[a].flag &= ~CUMA_SELECT; } @@ -7336,8 +7332,8 @@ static int ui_do_but_CURVE( data, event->xy[0], event->xy[1], - event->ctrl != 0, - event->shift != 0)) { + event->modifier & KM_CTRL, + event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7350,7 +7346,7 @@ static int ui_do_but_CURVE( if (data->dragchange == false) { /* deselect all, select one */ - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { for (int a = 0; a < cuma->totpoint; a++) { cmp[a].flag &= ~CUMA_SELECT; } @@ -7539,7 +7535,7 @@ static int ui_do_but_CURVEPROFILE( if (event->type == LEFTMOUSE && event->val == KM_PRESS) { const float m_xy[2] = {mx, my}; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { float f_xy[2]; BLI_rctf_transform_pt_v(&profile->view_rect, &but->rect, f_xy, m_xy); @@ -7616,7 +7612,7 @@ static int ui_do_but_CURVEPROFILE( /* Change the flag for the point(s) if one was selected or added. */ if (i_selected != -1) { /* Deselect all if this one is deselected, except if we hold shift. */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { pts[i_selected].flag ^= selection_type; } else { @@ -7647,7 +7643,7 @@ static int ui_do_but_CURVEPROFILE( if (event->type == MOUSEMOVE) { if (mx != data->draglastx || my != data->draglasty) { if (ui_numedit_but_CURVEPROFILE( - block, but, data, mx, my, event->ctrl != 0, event->shift != 0)) { + block, but, data, mx, my, event->modifier & KM_CTRL, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7871,7 +7867,7 @@ static int ui_do_but_TRACKPREVIEW( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift != 0)) { + if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -7888,7 +7884,7 @@ static int ui_do_but_TRACKPREVIEW( } else if (event->type == MOUSEMOVE) { if (mx != data->draglastx || my != data->draglasty) { - if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift != 0)) { + if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7918,8 +7914,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * if (data->state == BUTTON_STATE_HIGHLIGHT) { /* handle copy and paste */ - bool is_press_ctrl_but_no_shift = event->val == KM_PRESS && IS_EVENT_MOD(event, ctrl, oskey) && - !event->shift; + bool is_press_ctrl_but_no_shift = (event->val == KM_PRESS) && + (event->modifier & (KM_CTRL | KM_OSKEY)) && + (event->modifier & KM_SHIFT) == 0; const bool do_copy = event->type == EVT_CKEY && is_press_ctrl_but_no_shift; const bool do_paste = event->type == EVT_VKEY && is_press_ctrl_but_no_shift; @@ -7934,12 +7931,14 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * /* do copy first, because it is the only allowed operator when disabled */ if (do_copy) { - ui_but_copy(C, but, event->alt); + ui_but_copy(C, but, event->modifier & KM_ALT); return WM_UI_HANDLER_BREAK; } /* handle menu */ - if ((event->type == RIGHTMOUSE) && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey) && + + if ((event->type == RIGHTMOUSE) && + (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0 && (event->val == KM_PRESS)) { /* For some button types that are typically representing entire sets of data, right-clicking * to spawn the context menu should also activate the item. This makes it clear which item @@ -7960,7 +7959,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } if (do_paste) { - ui_but_paste(C, but, data, event->alt); + ui_but_paste(C, but, data, event->modifier & KM_ALT); return WM_UI_HANDLER_BREAK; } @@ -8947,7 +8946,7 @@ static int ui_handle_button_over(bContext *C, const wmEvent *event, ARegion *reg if (but) { button_activate_init(C, region, but, BUTTON_ACTIVATE_OVER); - if (event->alt && but->active) { + if ((event->modifier & KM_ALT) && but->active) { /* Display tool-tips if holding Alt on mouse-over when tool-tips are disabled in the * preferences. */ but->active->tooltip_force = true; @@ -9555,9 +9554,9 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi } else if (val == KM_PRESS) { if ((ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY, EVT_LEFTARROWKEY, EVT_RIGHTARROWKEY) && - !IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) || - ((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->ctrl && - !IS_EVENT_MOD(event, shift, alt, oskey)))) { + (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0) || + ((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_CTRL) && + (event->modifier & (KM_SHIFT | KM_ALT | KM_OSKEY)) == 0))) { const int value_orig = RNA_property_int_get(&listbox->rnapoin, listbox->rnaprop); int value, min, max; @@ -9614,7 +9613,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi } retval = WM_UI_HANDLER_BREAK; } - else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->shift) { + else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_SHIFT)) { /* We now have proper grip, but keep this anyway! */ if (ui_list->list_grip < (dyn_data->visual_height_min - UI_LIST_AUTO_SIZE_THRESHOLD)) { ui_list->list_grip = dyn_data->visual_height; @@ -10268,7 +10267,7 @@ static int ui_handle_menu_event(bContext *C, /* Smooth scrolling for popovers. */ case MOUSEPAN: { - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (!ui_block_is_menu(block)) { @@ -10290,7 +10289,7 @@ static int ui_handle_menu_event(bContext *C, } case WHEELUPMOUSE: case WHEELDOWNMOUSE: { - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (!ui_block_is_menu(block)) { @@ -10313,7 +10312,7 @@ static int ui_handle_menu_event(bContext *C, case EVT_HOMEKEY: case EVT_ENDKEY: /* Arrow-keys: only handle for block_loop blocks. */ - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (inside || (block->flag & UI_BLOCK_LOOP)) { @@ -10464,7 +10463,7 @@ static int ui_handle_menu_event(bContext *C, break; } - if (event->alt) { + if (event->modifier & KM_ALT) { act += 10; } @@ -10544,7 +10543,7 @@ static int ui_handle_menu_event(bContext *C, case EVT_YKEY: case EVT_ZKEY: { if (ELEM(event->val, KM_PRESS, KM_DBL_CLICK) && - !IS_EVENT_MOD(event, shift, ctrl, oskey) && + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0) && /* Only respond to explicit press to avoid the event that opened the menu * activating an item when the key is held. */ !event->is_repeat) { @@ -11071,7 +11070,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle case EVT_YKEY: case EVT_ZKEY: { if ((ELEM(event->val, KM_PRESS, KM_DBL_CLICK)) && - !IS_EVENT_MOD(event, shift, ctrl, oskey)) { + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0)) { LISTBASE_FOREACH (uiBut *, but, &block->buttons) { if (but->menu_key == event->type) { ui_but_pie_button_activate(C, but, menu); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 54a5b496048..bd55d2d9d81 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -492,7 +492,7 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index) PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; const int index = POINTER_AS_INT(arg_index); - const int shift = win->eventstate->shift; + const bool shift = win->eventstate->modifier & KM_SHIFT; const int len = RNA_property_array_length(ptr, prop); if (!shift) { @@ -752,7 +752,7 @@ static void ui_item_enum_expand_handle(bContext *C, void *arg1, void *arg2) { wmWindow *win = CTX_wm_window(C); - if (!win->eventstate->shift) { + if ((win->eventstate->modifier & KM_SHIFT) == 0) { uiBut *but = (uiBut *)arg1; const int enum_value = POINTER_AS_INT(arg2); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 2cb0f256b71..c7f2eb230cb 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -2061,8 +2061,8 @@ static void ui_handle_panel_header(const bContext *C, const uiBlock *block, const int mx, const int event_type, - const short ctrl, - const short shift) + const bool ctrl, + const bool shift) { Panel *panel = block->panel; ARegion *region = CTX_wm_region(C); @@ -2274,7 +2274,7 @@ static int ui_handle_panel_category_cycling(const wmEvent *event, (event->mval[0] > ((PanelCategoryDyn *)region->panels_category.first)->rect.xmin)); /* If mouse is inside non-tab region, ctrl key is required. */ - if (is_mousewheel && !event->ctrl && !inside_tabregion) { + if (is_mousewheel && (event->modifier & KM_CTRL) == 0 && !inside_tabregion) { return WM_UI_HANDLER_CONTINUE; } @@ -2291,7 +2291,7 @@ static int ui_handle_panel_category_cycling(const wmEvent *event, pc_dyn = (event->type == WHEELDOWNMOUSE) ? pc_dyn->next : pc_dyn->prev; } else { - const bool backwards = event->shift; + const bool backwards = event->modifier & KM_SHIFT; pc_dyn = backwards ? pc_dyn->prev : pc_dyn->next; if (!pc_dyn) { /* Proper cyclic behavior, back to first/last category (only used for ctrl+tab). */ @@ -2349,7 +2349,7 @@ int ui_handler_panel_region(bContext *C, retval = WM_UI_HANDLER_BREAK; } } - else if ((event->type == EVT_TABKEY && event->ctrl) || + else if (((event->type == EVT_TABKEY) && (event->modifier & KM_CTRL)) || ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE)) { /* Cycle tabs. */ retval = ui_handle_panel_category_cycling(event, region, active_but); @@ -2386,9 +2386,11 @@ int ui_handler_panel_region(bContext *C, /* The panel collapse / expand key "A" is special as it takes priority over * active button handling. */ - if (event->type == EVT_AKEY && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->type == EVT_AKEY && + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0)) { retval = WM_UI_HANDLER_BREAK; - ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); + ui_handle_panel_header( + C, block, mx, event->type, event->modifier & KM_CTRL, event->modifier & KM_SHIFT); break; } } @@ -2402,7 +2404,8 @@ int ui_handler_panel_region(bContext *C, /* All mouse clicks inside panel headers should return in break. */ if (ELEM(event->type, EVT_RETKEY, EVT_PADENTER, LEFTMOUSE)) { retval = WM_UI_HANDLER_BREAK; - ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); + ui_handle_panel_header( + C, block, mx, event->type, event->modifier & KM_CTRL, event->modifier & KM_SHIFT); } else if (event->type == RIGHTMOUSE) { retval = WM_UI_HANDLER_BREAK; diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c index 8a945c8c913..4703367671d 100644 --- a/source/blender/editors/interface/interface_query.c +++ b/source/blender/editors/interface/interface_query.c @@ -310,7 +310,7 @@ uiBut *ui_but_find_mouse_over_ex(const ARegion *region, uiBut *ui_but_find_mouse_over(const ARegion *region, const wmEvent *event) { - return ui_but_find_mouse_over_ex(region, event->xy, event->ctrl != 0, NULL, NULL); + return ui_but_find_mouse_over_ex(region, event->xy, event->modifier & KM_CTRL, NULL, NULL); } uiBut *ui_but_find_rect_over(const struct ARegion *region, const rcti *rect_px) diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 09faf493ce7..29553ff65d1 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -701,7 +701,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is /* Keymap */ /* This is too handy not to expose somehow, let's be sneaky for now. */ - if ((is_label == false) && CTX_wm_window(C)->eventstate->shift) { + if ((is_label == false) && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { const char *expr_imports[] = {"bpy", "bl_ui", NULL}; char expr[256]; SNPRINTF(expr, diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index f8fbc2d01a6..32b3bb5e926 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -609,7 +609,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); RNA_property_update(C, &template_ui->ptr, template_ui->prop); - if (id && CTX_wm_window(C)->eventstate->shift) { + if (id && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { /* only way to force-remove data (on save) */ id_us_clear_real(id); id_fake_user_clear(id); @@ -635,7 +635,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) case UI_ID_LOCAL: if (id) { Main *bmain = CTX_data_main(C); - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { if (ID_IS_OVERRIDABLE_LIBRARY(id)) { /* Only remap that specific ID usage to overriding local data-block. */ ID *override_id = BKE_lib_override_library_create_from_id(bmain, id, false); @@ -5539,7 +5539,7 @@ static void handle_layer_buttons(bContext *C, void *arg1, void *arg2) uiBut *but = arg1; const int cur = POINTER_AS_INT(arg2); wmWindow *win = CTX_wm_window(C); - const int shift = win->eventstate->shift; + const bool shift = win->eventstate->modifier & KM_SHIFT; if (!shift) { const int tot = RNA_property_array_length(&but->rnapoin, but->rnaprop); -- cgit v1.2.3