mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Augment the InputEvent
class with a CANCELED
state
The `InputEvent` class currently supports the `pressed` and `released` states, which given the binary nature, is represented by a `bool` field. This commit introduced the `CANCELED` state, which signals that an ongoing input event has been canceled. To represent all the states, the `InputEventState` enum is added and the `InputEvent` logic is refactored accordingly.
This commit is contained in:
parent
cf8ad12b56
commit
250749fa79
8 changed files with 83 additions and 76 deletions
|
@ -138,22 +138,19 @@ void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicod
|
|||
}
|
||||
|
||||
void AndroidInputHandler::_cancel_all_touch() {
|
||||
_parse_all_touch(false, false, true);
|
||||
_parse_all_touch(false, true);
|
||||
touch.clear();
|
||||
}
|
||||
|
||||
void AndroidInputHandler::_parse_all_touch(bool p_pressed, bool p_double_tap, bool reset_index) {
|
||||
void AndroidInputHandler::_parse_all_touch(bool p_pressed, bool p_canceled, bool p_double_tap) {
|
||||
if (touch.size()) {
|
||||
//end all if exist
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
Ref<InputEventScreenTouch> ev;
|
||||
ev.instantiate();
|
||||
if (reset_index) {
|
||||
ev->set_index(-1);
|
||||
} else {
|
||||
ev->set_index(touch[i].id);
|
||||
}
|
||||
ev->set_index(touch[i].id);
|
||||
ev->set_pressed(p_pressed);
|
||||
ev->set_canceled(p_canceled);
|
||||
ev->set_position(touch[i].pos);
|
||||
ev->set_double_tap(p_double_tap);
|
||||
Input::get_singleton()->parse_input_event(ev);
|
||||
|
@ -180,7 +177,7 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const
|
|||
}
|
||||
|
||||
//send touch
|
||||
_parse_all_touch(true, p_double_tap);
|
||||
_parse_all_touch(true, false, p_double_tap);
|
||||
|
||||
} break;
|
||||
case AMOTION_EVENT_ACTION_MOVE: { //motion
|
||||
|
@ -257,11 +254,11 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const
|
|||
|
||||
void AndroidInputHandler::_cancel_mouse_event_info(bool p_source_mouse_relative) {
|
||||
buttons_state = BitField<MouseButtonMask>();
|
||||
_parse_mouse_event_info(BitField<MouseButtonMask>(), false, false, p_source_mouse_relative);
|
||||
_parse_mouse_event_info(BitField<MouseButtonMask>(), false, true, false, p_source_mouse_relative);
|
||||
mouse_event_info.valid = false;
|
||||
}
|
||||
|
||||
void AndroidInputHandler::_parse_mouse_event_info(BitField<MouseButtonMask> event_buttons_mask, bool p_pressed, bool p_double_click, bool p_source_mouse_relative) {
|
||||
void AndroidInputHandler::_parse_mouse_event_info(BitField<MouseButtonMask> event_buttons_mask, bool p_pressed, bool p_canceled, bool p_double_click, bool p_source_mouse_relative) {
|
||||
if (!mouse_event_info.valid) {
|
||||
return;
|
||||
}
|
||||
|
@ -278,6 +275,7 @@ void AndroidInputHandler::_parse_mouse_event_info(BitField<MouseButtonMask> even
|
|||
hover_prev_pos = mouse_event_info.pos;
|
||||
}
|
||||
ev->set_pressed(p_pressed);
|
||||
ev->set_canceled(p_canceled);
|
||||
BitField<MouseButtonMask> changed_button_mask = BitField<MouseButtonMask>(buttons_state.operator int64_t() ^ event_buttons_mask.operator int64_t());
|
||||
|
||||
buttons_state = event_buttons_mask;
|
||||
|
@ -289,7 +287,7 @@ void AndroidInputHandler::_parse_mouse_event_info(BitField<MouseButtonMask> even
|
|||
}
|
||||
|
||||
void AndroidInputHandler::_release_mouse_event_info(bool p_source_mouse_relative) {
|
||||
_parse_mouse_event_info(BitField<MouseButtonMask>(), false, false, p_source_mouse_relative);
|
||||
_parse_mouse_event_info(BitField<MouseButtonMask>(), false, false, false, p_source_mouse_relative);
|
||||
mouse_event_info.valid = false;
|
||||
}
|
||||
|
||||
|
@ -318,7 +316,7 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an
|
|||
|
||||
mouse_event_info.valid = true;
|
||||
mouse_event_info.pos = p_event_pos;
|
||||
_parse_mouse_event_info(event_buttons_mask, true, p_double_click, p_source_mouse_relative);
|
||||
_parse_mouse_event_info(event_buttons_mask, true, false, p_double_click, p_source_mouse_relative);
|
||||
} break;
|
||||
|
||||
case AMOTION_EVENT_ACTION_CANCEL: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue