diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2010-05-29 05:42:42 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2010-05-29 05:42:42 +0400 |
commit | 8a59a45342cecdc47d668488eb644a14d419a968 (patch) | |
tree | 7c27dfb8194032997ad16de7bb9d3a20f033a599 | |
parent | 8082d845dee733886f2b37cf2608bedfeb78bcf2 (diff) |
Esc as input for Key Buttons (e.g Logic Brick Keyboard Sensor)
After talking with Brecht he agreed on allowing Esc to be used as input for key input butons.
In order to let the user to cancel an input it can cancel it clicking outside the button.
Also replacing manual check by ui_mouse_inside_button in ui_text function
(patch reviewed (and helped) by Matt (but the change on ISHOTKEY, that's on my own risk ;))
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 29 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_types.h | 2 |
2 files changed, 15 insertions, 16 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index fb0822de677..4e3ffad48ae 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1659,7 +1659,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle my= event->y; ui_window_to_block(data->region, block, &mx, &my); - if ((but->y1 <= my) && (my <= but->y2) && (but->x1 <= mx) && (mx <= but->x2)) { + if (ui_mouse_inside_button(data->region, but, mx, my)) { ui_textedit_set_cursor_pos(but, data, mx); but->selsta = but->selend = but->pos; data->selstartx= mx; @@ -1999,14 +1999,17 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data if(event->type == MOUSEMOVE) return WM_UI_HANDLER_CONTINUE; - if(event->type == ESCKEY) { - /* data->cancel doesnt work, this button opens immediate */ - if(but->flag & UI_BUT_IMMEDIATE) - ui_set_but_val(but, 0); - else - data->cancel= 1; - button_activate_state(C, but, BUTTON_STATE_EXIT); - return WM_UI_HANDLER_BREAK; + if(event->type == LEFTMOUSE && event->val==KM_PRESS) { + /* only cancel if click outside the button */ + if(ui_mouse_inside_button(but->active->region, but, event->x, event->y) == 0) { + /* data->cancel doesnt work, this button opens immediate */ + if(but->flag & UI_BUT_IMMEDIATE) + ui_set_but_val(but, 0); + else + data->cancel= 1; + button_activate_state(C, but, BUTTON_STATE_EXIT); + return WM_UI_HANDLER_BREAK; + } } /* always set */ @@ -2040,15 +2043,11 @@ static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data return WM_UI_HANDLER_CONTINUE; } - static int ui_do_but_KEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event) { if(data->state == BUTTON_STATE_HIGHLIGHT) { if(ELEM3(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val==KM_PRESS) { - short event= (short)ui_get_but_val(but); - /* hardcoded prevention from editing or assigning ESC */ - if(event!=ESCKEY) - button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT); + button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT); return WM_UI_HANDLER_BREAK; } } @@ -2057,7 +2056,7 @@ static int ui_do_but_KEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, w return WM_UI_HANDLER_CONTINUE; if(event->val==KM_PRESS) { - if(event->type!=ESCKEY && WM_key_event_string(event->type)[0]) + if(WM_key_event_string(event->type)[0]) ui_set_but_val(but, event->type); else data->cancel= 1; diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 7b83e1d4179..a93214e9a54 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -226,7 +226,7 @@ #define ISTWEAK(event) (event >= EVT_TWEAK_L && event <= EVT_GESTURE) /* test whether event type is acceptable as hotkey, excluding modifiers */ -#define ISHOTKEY(event) ((ISKEYBOARD(event) || ISMOUSE(event)) && !(event>=LEFTCTRLKEY && event<=ESCKEY) && !(event>=UNKNOWNKEY && event<=GRLESSKEY)) +#define ISHOTKEY(event) ((ISKEYBOARD(event) || ISMOUSE(event)) && !(event>=LEFTCTRLKEY && event<=LEFTSHIFTKEY) && !(event>=UNKNOWNKEY && event<=GRLESSKEY)) /* **************** BLENDER GESTURE EVENTS ********************* */ |