2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* android_input_handler.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
#include "android_input_handler.h"
|
|
|
|
|
|
|
|
#include "android_keys_utils.h"
|
|
|
|
#include "display_server_android.h"
|
|
|
|
|
|
|
|
void AndroidInputHandler::process_joy_event(AndroidInputHandler::JoypadEvent p_event) {
|
|
|
|
switch (p_event.type) {
|
|
|
|
case JOY_EVENT_BUTTON:
|
|
|
|
Input::get_singleton()->joy_button(p_event.device, (JoyButton)p_event.index, p_event.pressed);
|
|
|
|
break;
|
|
|
|
case JOY_EVENT_AXIS:
|
2021-12-25 10:29:08 +01:00
|
|
|
Input::get_singleton()->joy_axis(p_event.device, (JoyAxis)p_event.index, p_event.value);
|
2021-08-04 21:22:11 +02:00
|
|
|
break;
|
|
|
|
case JOY_EVENT_HAT:
|
2021-08-13 23:31:57 +02:00
|
|
|
Input::get_singleton()->joy_hat(p_event.device, p_event.hat);
|
2021-08-04 21:22:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidInputHandler::_set_key_modifier_state(Ref<InputEventWithModifiers> ev) {
|
|
|
|
ev->set_shift_pressed(shift_mem);
|
|
|
|
ev->set_alt_pressed(alt_mem);
|
|
|
|
ev->set_meta_pressed(meta_mem);
|
|
|
|
ev->set_ctrl_pressed(control_mem);
|
|
|
|
}
|
|
|
|
|
2022-12-11 00:21:22 +01:00
|
|
|
void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed) {
|
2021-08-04 21:22:11 +02:00
|
|
|
static char32_t prev_wc = 0;
|
2022-07-10 13:32:01 +02:00
|
|
|
char32_t unicode = p_unicode;
|
|
|
|
if ((p_unicode & 0xfffffc00) == 0xd800) {
|
2021-08-04 21:22:11 +02:00
|
|
|
if (prev_wc != 0) {
|
|
|
|
ERR_PRINT("invalid utf16 surrogate input");
|
|
|
|
}
|
|
|
|
prev_wc = unicode;
|
|
|
|
return; // Skip surrogate.
|
|
|
|
} else if ((unicode & 0xfffffc00) == 0xdc00) {
|
|
|
|
if (prev_wc == 0) {
|
|
|
|
ERR_PRINT("invalid utf16 surrogate input");
|
|
|
|
return; // Skip invalid surrogate.
|
|
|
|
}
|
|
|
|
unicode = (prev_wc << 10UL) + unicode - ((0xd800 << 10UL) + 0xdc00 - 0x10000);
|
|
|
|
prev_wc = 0;
|
|
|
|
} else {
|
|
|
|
prev_wc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<InputEventKey> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
|
2022-07-10 13:32:01 +02:00
|
|
|
Key physical_keycode = godot_code_from_android_code(p_physical_keycode);
|
2022-12-11 00:21:22 +01:00
|
|
|
Key keycode = fix_keycode(unicode, physical_keycode);
|
2022-07-10 13:32:01 +02:00
|
|
|
|
|
|
|
switch (physical_keycode) {
|
|
|
|
case Key::SHIFT: {
|
|
|
|
shift_mem = p_pressed;
|
|
|
|
} break;
|
|
|
|
case Key::ALT: {
|
|
|
|
alt_mem = p_pressed;
|
|
|
|
} break;
|
|
|
|
case Key::CTRL: {
|
|
|
|
control_mem = p_pressed;
|
|
|
|
} break;
|
|
|
|
case Key::META: {
|
|
|
|
meta_mem = p_pressed;
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:31:57 +02:00
|
|
|
ev->set_keycode(keycode);
|
2022-07-10 13:32:01 +02:00
|
|
|
ev->set_physical_keycode(physical_keycode);
|
2022-12-11 00:21:22 +01:00
|
|
|
ev->set_key_label(fix_key_label(p_key_label, keycode));
|
|
|
|
ev->set_unicode(fix_unicode(unicode));
|
2021-08-04 21:22:11 +02:00
|
|
|
ev->set_pressed(p_pressed);
|
|
|
|
|
|
|
|
_set_key_modifier_state(ev);
|
|
|
|
|
2022-07-10 13:32:01 +02:00
|
|
|
if (p_physical_keycode == AKEYCODE_BACK) {
|
2021-08-04 21:22:11 +02:00
|
|
|
if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) {
|
|
|
|
dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
}
|
|
|
|
|
2022-10-22 16:30:46 +02:00
|
|
|
void AndroidInputHandler::_parse_all_touch(bool p_pressed, bool p_double_tap) {
|
2022-08-15 08:07:43 +02:00
|
|
|
if (touch.size()) {
|
|
|
|
//end all if exist
|
|
|
|
for (int i = 0; i < touch.size(); i++) {
|
|
|
|
Ref<InputEventScreenTouch> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
ev->set_index(touch[i].id);
|
|
|
|
ev->set_pressed(p_pressed);
|
|
|
|
ev->set_position(touch[i].pos);
|
2022-10-22 16:30:46 +02:00
|
|
|
ev->set_double_tap(p_double_tap);
|
2022-08-15 08:07:43 +02:00
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidInputHandler::_release_all_touch() {
|
2022-10-22 16:30:46 +02:00
|
|
|
_parse_all_touch(false, false);
|
2022-08-15 08:07:43 +02:00
|
|
|
touch.clear();
|
|
|
|
}
|
|
|
|
|
2022-10-22 16:30:46 +02:00
|
|
|
void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const Vector<TouchPos> &p_points, bool p_double_tap) {
|
2021-08-04 21:22:11 +02:00
|
|
|
switch (p_event) {
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN: { //gesture begin
|
2022-08-15 08:07:43 +02:00
|
|
|
// Release any remaining touches or mouse event
|
|
|
|
_release_mouse_event_info();
|
|
|
|
_release_all_touch();
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
touch.resize(p_points.size());
|
|
|
|
for (int i = 0; i < p_points.size(); i++) {
|
|
|
|
touch.write[i].id = p_points[i].id;
|
|
|
|
touch.write[i].pos = p_points[i].pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
//send touch
|
2022-10-22 16:30:46 +02:00
|
|
|
_parse_all_touch(true, p_double_tap);
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE: { //motion
|
2022-08-15 08:07:43 +02:00
|
|
|
if (touch.size() != p_points.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < touch.size(); i++) {
|
|
|
|
int idx = -1;
|
|
|
|
for (int j = 0; j < p_points.size(); j++) {
|
|
|
|
if (touch[i].id == p_points[j].id) {
|
|
|
|
idx = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_CONTINUE(idx == -1);
|
|
|
|
|
2022-02-16 13:56:32 +01:00
|
|
|
if (touch[i].pos == p_points[idx].pos) {
|
|
|
|
continue; // Don't move unnecessarily.
|
|
|
|
}
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
Ref<InputEventScreenDrag> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
ev->set_index(touch[i].id);
|
|
|
|
ev->set_position(p_points[idx].pos);
|
|
|
|
ev->set_relative(p_points[idx].pos - touch[i].pos);
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
touch.write[i].pos = p_points[idx].pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
case AMOTION_EVENT_ACTION_UP: { //release
|
2022-08-15 08:07:43 +02:00
|
|
|
_release_all_touch();
|
2021-08-04 21:22:11 +02:00
|
|
|
} break;
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN: { // add touch
|
|
|
|
for (int i = 0; i < p_points.size(); i++) {
|
|
|
|
if (p_points[i].id == p_pointer) {
|
|
|
|
TouchPos tp = p_points[i];
|
|
|
|
touch.push_back(tp);
|
|
|
|
|
|
|
|
Ref<InputEventScreenTouch> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
|
|
|
|
ev->set_index(tp.id);
|
|
|
|
ev->set_pressed(true);
|
|
|
|
ev->set_position(tp.pos);
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP: { // remove touch
|
|
|
|
for (int i = 0; i < touch.size(); i++) {
|
|
|
|
if (touch[i].id == p_pointer) {
|
|
|
|
Ref<InputEventScreenTouch> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
ev->set_index(touch[i].id);
|
|
|
|
ev->set_pressed(false);
|
|
|
|
ev->set_position(touch[i].pos);
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
2021-07-04 00:17:03 +02:00
|
|
|
touch.remove_at(i);
|
2021-08-04 21:22:11 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 00:55:54 +01:00
|
|
|
void AndroidInputHandler::_parse_mouse_event_info(BitField<MouseButtonMask> event_buttons_mask, bool p_pressed, bool p_double_click, bool p_source_mouse_relative) {
|
2022-08-15 08:07:43 +02:00
|
|
|
if (!mouse_event_info.valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<InputEventMouseButton> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
_set_key_modifier_state(ev);
|
|
|
|
if (p_source_mouse_relative) {
|
|
|
|
ev->set_position(hover_prev_pos);
|
|
|
|
ev->set_global_position(hover_prev_pos);
|
|
|
|
} else {
|
|
|
|
ev->set_position(mouse_event_info.pos);
|
|
|
|
ev->set_global_position(mouse_event_info.pos);
|
|
|
|
hover_prev_pos = mouse_event_info.pos;
|
|
|
|
}
|
|
|
|
ev->set_pressed(p_pressed);
|
2023-01-08 00:55:54 +01:00
|
|
|
BitField<MouseButtonMask> changed_button_mask = BitField<MouseButtonMask>(buttons_state.operator int64_t() ^ event_buttons_mask.operator int64_t());
|
2022-08-15 08:07:43 +02:00
|
|
|
|
|
|
|
buttons_state = event_buttons_mask;
|
|
|
|
|
|
|
|
ev->set_button_index(_button_index_from_mask(changed_button_mask));
|
|
|
|
ev->set_button_mask(event_buttons_mask);
|
|
|
|
ev->set_double_click(p_double_click);
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidInputHandler::_release_mouse_event_info(bool p_source_mouse_relative) {
|
2023-01-08 00:55:54 +01:00
|
|
|
_parse_mouse_event_info(BitField<MouseButtonMask>(), false, false, p_source_mouse_relative);
|
2022-08-15 08:07:43 +02:00
|
|
|
mouse_event_info.valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_android_buttons_mask, Point2 p_event_pos, Vector2 p_delta, bool p_double_click, bool p_source_mouse_relative) {
|
2023-01-08 00:55:54 +01:00
|
|
|
BitField<MouseButtonMask> event_buttons_mask = _android_button_mask_to_godot_button_mask(p_event_android_buttons_mask);
|
2022-08-15 08:07:43 +02:00
|
|
|
switch (p_event_action) {
|
2021-08-04 21:22:11 +02:00
|
|
|
case AMOTION_EVENT_ACTION_HOVER_MOVE: // hover move
|
|
|
|
case AMOTION_EVENT_ACTION_HOVER_ENTER: // hover enter
|
|
|
|
case AMOTION_EVENT_ACTION_HOVER_EXIT: { // hover exit
|
2022-08-15 08:07:43 +02:00
|
|
|
// https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_HOVER_ENTER
|
2021-08-04 21:22:11 +02:00
|
|
|
Ref<InputEventMouseMotion> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
_set_key_modifier_state(ev);
|
2022-08-15 08:07:43 +02:00
|
|
|
ev->set_position(p_event_pos);
|
|
|
|
ev->set_global_position(p_event_pos);
|
|
|
|
ev->set_relative(p_event_pos - hover_prev_pos);
|
2021-08-04 21:22:11 +02:00
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
2022-08-15 08:07:43 +02:00
|
|
|
hover_prev_pos = p_event_pos;
|
2021-08-04 21:22:11 +02:00
|
|
|
} break;
|
|
|
|
|
2022-08-15 08:07:43 +02:00
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_BUTTON_PRESS: {
|
|
|
|
// Release any remaining touches or mouse event
|
|
|
|
_release_mouse_event_info();
|
|
|
|
_release_all_touch();
|
2021-08-04 21:22:11 +02:00
|
|
|
|
2022-08-15 08:07:43 +02:00
|
|
|
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);
|
|
|
|
} break;
|
2021-08-04 21:22:11 +02:00
|
|
|
|
2022-08-15 08:07:43 +02:00
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
case AMOTION_EVENT_ACTION_BUTTON_RELEASE: {
|
|
|
|
_release_mouse_event_info(p_source_mouse_relative);
|
2021-08-04 21:22:11 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE: {
|
2022-08-15 08:07:43 +02:00
|
|
|
if (!mouse_event_info.valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-04 21:22:11 +02:00
|
|
|
Ref<InputEventMouseMotion> ev;
|
|
|
|
ev.instantiate();
|
|
|
|
_set_key_modifier_state(ev);
|
2022-08-15 08:07:43 +02:00
|
|
|
if (p_source_mouse_relative) {
|
2021-08-04 21:22:11 +02:00
|
|
|
ev->set_position(hover_prev_pos);
|
|
|
|
ev->set_global_position(hover_prev_pos);
|
2022-08-15 08:07:43 +02:00
|
|
|
ev->set_relative(p_event_pos);
|
|
|
|
} else {
|
|
|
|
ev->set_position(p_event_pos);
|
|
|
|
ev->set_global_position(p_event_pos);
|
|
|
|
ev->set_relative(p_event_pos - hover_prev_pos);
|
|
|
|
mouse_event_info.pos = p_event_pos;
|
|
|
|
hover_prev_pos = p_event_pos;
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
ev->set_button_mask(event_buttons_mask);
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
|
} break;
|
2022-08-15 08:07:43 +02:00
|
|
|
|
2021-08-04 21:22:11 +02:00
|
|
|
case AMOTION_EVENT_ACTION_SCROLL: {
|
|
|
|
Ref<InputEventMouseButton> ev;
|
|
|
|
ev.instantiate();
|
2022-08-15 08:07:43 +02:00
|
|
|
_set_key_modifier_state(ev);
|
|
|
|
if (p_source_mouse_relative) {
|
2021-08-04 21:22:11 +02:00
|
|
|
ev->set_position(hover_prev_pos);
|
|
|
|
ev->set_global_position(hover_prev_pos);
|
2022-08-15 08:07:43 +02:00
|
|
|
} else {
|
|
|
|
ev->set_position(p_event_pos);
|
|
|
|
ev->set_global_position(p_event_pos);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
ev->set_pressed(true);
|
|
|
|
buttons_state = event_buttons_mask;
|
2022-08-15 08:07:43 +02:00
|
|
|
if (p_delta.y > 0) {
|
|
|
|
_wheel_button_click(event_buttons_mask, ev, MouseButton::WHEEL_UP, p_delta.y);
|
|
|
|
} else if (p_delta.y < 0) {
|
|
|
|
_wheel_button_click(event_buttons_mask, ev, MouseButton::WHEEL_DOWN, -p_delta.y);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
|
2022-08-15 08:07:43 +02:00
|
|
|
if (p_delta.x > 0) {
|
|
|
|
_wheel_button_click(event_buttons_mask, ev, MouseButton::WHEEL_RIGHT, p_delta.x);
|
|
|
|
} else if (p_delta.x < 0) {
|
|
|
|
_wheel_button_click(event_buttons_mask, ev, MouseButton::WHEEL_LEFT, -p_delta.x);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 00:55:54 +01:00
|
|
|
void AndroidInputHandler::_wheel_button_click(BitField<MouseButtonMask> event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor) {
|
2021-08-04 21:22:11 +02:00
|
|
|
Ref<InputEventMouseButton> evd = ev->duplicate();
|
|
|
|
_set_key_modifier_state(evd);
|
|
|
|
evd->set_button_index(wheel_button);
|
2023-01-08 00:55:54 +01:00
|
|
|
evd->set_button_mask(BitField<MouseButtonMask>(event_buttons_mask.operator int64_t() ^ int64_t(mouse_button_to_mask(wheel_button))));
|
2021-08-04 21:22:11 +02:00
|
|
|
evd->set_factor(factor);
|
|
|
|
Input::get_singleton()->parse_input_event(evd);
|
|
|
|
Ref<InputEventMouseButton> evdd = evd->duplicate();
|
|
|
|
evdd->set_pressed(false);
|
|
|
|
evdd->set_button_mask(event_buttons_mask);
|
|
|
|
Input::get_singleton()->parse_input_event(evdd);
|
|
|
|
}
|
|
|
|
|
2022-08-15 08:07:43 +02:00
|
|
|
void AndroidInputHandler::process_magnify(Point2 p_pos, float p_factor) {
|
|
|
|
Ref<InputEventMagnifyGesture> magnify_event;
|
|
|
|
magnify_event.instantiate();
|
|
|
|
_set_key_modifier_state(magnify_event);
|
|
|
|
magnify_event->set_position(p_pos);
|
|
|
|
magnify_event->set_factor(p_factor);
|
|
|
|
Input::get_singleton()->parse_input_event(magnify_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidInputHandler::process_pan(Point2 p_pos, Vector2 p_delta) {
|
|
|
|
Ref<InputEventPanGesture> pan_event;
|
|
|
|
pan_event.instantiate();
|
|
|
|
_set_key_modifier_state(pan_event);
|
|
|
|
pan_event->set_position(p_pos);
|
|
|
|
pan_event->set_delta(p_delta);
|
|
|
|
Input::get_singleton()->parse_input_event(pan_event);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
|
2023-01-08 00:55:54 +01:00
|
|
|
MouseButton AndroidInputHandler::_button_index_from_mask(BitField<MouseButtonMask> button_mask) {
|
|
|
|
switch (MouseButtonMask(button_mask.operator int64_t())) {
|
|
|
|
case MouseButtonMask::LEFT:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::LEFT;
|
2023-01-08 00:55:54 +01:00
|
|
|
case MouseButtonMask::RIGHT:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::RIGHT;
|
2023-01-08 00:55:54 +01:00
|
|
|
case MouseButtonMask::MIDDLE:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::MIDDLE;
|
2023-01-08 00:55:54 +01:00
|
|
|
case MouseButtonMask::MB_XBUTTON1:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::MB_XBUTTON1;
|
2023-01-08 00:55:54 +01:00
|
|
|
case MouseButtonMask::MB_XBUTTON2:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::MB_XBUTTON2;
|
2021-08-04 21:22:11 +02:00
|
|
|
default:
|
2021-08-13 23:31:57 +02:00
|
|
|
return MouseButton::NONE;
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 00:55:54 +01:00
|
|
|
BitField<MouseButtonMask> AndroidInputHandler::_android_button_mask_to_godot_button_mask(int android_button_mask) {
|
|
|
|
BitField<MouseButtonMask> godot_button_mask;
|
2021-08-04 21:22:11 +02:00
|
|
|
if (android_button_mask & AMOTION_EVENT_BUTTON_PRIMARY) {
|
2023-01-08 00:55:54 +01:00
|
|
|
godot_button_mask.set_flag(MouseButtonMask::LEFT);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
if (android_button_mask & AMOTION_EVENT_BUTTON_SECONDARY) {
|
2023-01-08 00:55:54 +01:00
|
|
|
godot_button_mask.set_flag(MouseButtonMask::RIGHT);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
if (android_button_mask & AMOTION_EVENT_BUTTON_TERTIARY) {
|
2023-01-08 00:55:54 +01:00
|
|
|
godot_button_mask.set_flag(MouseButtonMask::MIDDLE);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
if (android_button_mask & AMOTION_EVENT_BUTTON_BACK) {
|
2023-01-08 00:55:54 +01:00
|
|
|
godot_button_mask.set_flag(MouseButtonMask::MB_XBUTTON1);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
2021-08-16 18:49:12 +02:00
|
|
|
if (android_button_mask & AMOTION_EVENT_BUTTON_FORWARD) {
|
2023-01-08 00:55:54 +01:00
|
|
|
godot_button_mask.set_flag(MouseButtonMask::MB_XBUTTON2);
|
2021-08-04 21:22:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return godot_button_mask;
|
|
|
|
}
|