Use "enum class" for input enums

This commit is contained in:
Aaron Franke
2021-08-13 16:31:57 -05:00
parent 4f85cad013
commit 3c0fdcc8ac
154 changed files with 3482 additions and 3392 deletions
@@ -151,19 +151,19 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
switch (p_button) {
case DOM_BUTTON_LEFT:
ev->set_button_index(MOUSE_BUTTON_LEFT);
ev->set_button_index(MouseButton::LEFT);
break;
case DOM_BUTTON_MIDDLE:
ev->set_button_index(MOUSE_BUTTON_MIDDLE);
ev->set_button_index(MouseButton::MIDDLE);
break;
case DOM_BUTTON_RIGHT:
ev->set_button_index(MOUSE_BUTTON_RIGHT);
ev->set_button_index(MouseButton::RIGHT);
break;
case DOM_BUTTON_XBUTTON1:
ev->set_button_index(MOUSE_BUTTON_XBUTTON1);
ev->set_button_index(MouseButton::MB_XBUTTON1);
break;
case DOM_BUTTON_XBUTTON2:
ev->set_button_index(MOUSE_BUTTON_XBUTTON2);
ev->set_button_index(MouseButton::MB_XBUTTON2);
break;
default:
return false;
@@ -176,7 +176,7 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
if (diff < 400 && Point2(ds->last_click_pos).distance_to(ev->get_position()) < 5) {
ds->last_click_ms = 0;
ds->last_click_pos = Point2(-100, -100);
ds->last_click_button_index = -1;
ds->last_click_button_index = MouseButton::NONE;
ev->set_double_click(true);
}
@@ -190,11 +190,11 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
}
}
int mask = Input::get_singleton()->get_mouse_button_mask();
int button_flag = 1 << (ev->get_button_index() - 1);
MouseButton mask = Input::get_singleton()->get_mouse_button_mask();
MouseButton button_flag = mouse_button_to_mask(ev->get_button_index());
if (ev->is_pressed()) {
mask |= button_flag;
} else if (mask & button_flag) {
} else if ((mask & button_flag) != MouseButton::NONE) {
mask &= ~button_flag;
} else {
// Received release event, but press was outside the canvas, so ignore.
@@ -215,11 +215,12 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
}
void DisplayServerJavaScript::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
int input_mask = Input::get_singleton()->get_mouse_button_mask();
MouseButton input_mask = Input::get_singleton()->get_mouse_button_mask();
// For motion outside the canvas, only read mouse movement if dragging
// started inside the canvas; imitating desktop app behaviour.
if (!get_singleton()->cursor_inside_canvas && !input_mask)
if (!get_singleton()->cursor_inside_canvas && input_mask == MouseButton::NONE) {
return;
}
Ref<InputEventMouseMotion> ev;
ev.instantiate();
@@ -412,19 +413,19 @@ int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double p_del
ev->set_position(input->get_mouse_position());
ev->set_global_position(ev->get_position());
ev->set_shift_pressed(input->is_key_pressed(KEY_SHIFT));
ev->set_alt_pressed(input->is_key_pressed(KEY_ALT));
ev->set_ctrl_pressed(input->is_key_pressed(KEY_CTRL));
ev->set_meta_pressed(input->is_key_pressed(KEY_META));
ev->set_shift_pressed(input->is_key_pressed(Key::SHIFT));
ev->set_alt_pressed(input->is_key_pressed(Key::ALT));
ev->set_ctrl_pressed(input->is_key_pressed(Key::CTRL));
ev->set_meta_pressed(input->is_key_pressed(Key::META));
if (p_delta_y < 0) {
ev->set_button_index(MOUSE_BUTTON_WHEEL_UP);
ev->set_button_index(MouseButton::WHEEL_UP);
} else if (p_delta_y > 0) {
ev->set_button_index(MOUSE_BUTTON_WHEEL_DOWN);
ev->set_button_index(MouseButton::WHEEL_DOWN);
} else if (p_delta_x > 0) {
ev->set_button_index(MOUSE_BUTTON_WHEEL_LEFT);
ev->set_button_index(MouseButton::WHEEL_LEFT);
} else if (p_delta_x < 0) {
ev->set_button_index(MOUSE_BUTTON_WHEEL_RIGHT);
ev->set_button_index(MouseButton::WHEEL_RIGHT);
} else {
return false;
}
@@ -432,7 +433,7 @@ int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double p_del
// Different browsers give wildly different delta values, and we can't
// interpret deltaMode, so use default value for wheel events' factor.
int button_flag = 1 << (ev->get_button_index() - 1);
MouseButton button_flag = mouse_button_to_mask(ev->get_button_index());
ev->set_pressed(true);
ev->set_button_mask(input->get_mouse_button_mask() | button_flag);
@@ -509,12 +510,12 @@ void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_c
k.instantiate();
k->set_pressed(true);
k->set_echo(false);
k->set_keycode(KEY_RIGHT);
k->set_keycode(Key::RIGHT);
input->parse_input_event(k);
k.instantiate();
k->set_pressed(false);
k->set_echo(false);
k->set_keycode(KEY_RIGHT);
k->set_keycode(Key::RIGHT);
input->parse_input_event(k);
}
}
@@ -557,12 +558,12 @@ void DisplayServerJavaScript::process_joypads() {
for (int b = 0; b < s_btns_num; b++) {
float value = s_btns[b];
// Buttons 6 and 7 in the standard mapping need to be
// axis to be handled as JOY_AXIS_TRIGGER by Godot.
// axis to be handled as JoyAxis::TRIGGER by Godot.
if (s_standard && (b == 6 || b == 7)) {
Input::JoyAxisValue joy_axis;
joy_axis.min = 0;
joy_axis.value = value;
JoyAxis a = b == 6 ? JOY_AXIS_TRIGGER_LEFT : JOY_AXIS_TRIGGER_RIGHT;
JoyAxis a = b == 6 ? JoyAxis::TRIGGER_LEFT : JoyAxis::TRIGGER_RIGHT;
input->joy_axis(idx, a, joy_axis);
} else {
input->joy_button(idx, (JoyButton)b, value);
@@ -67,7 +67,7 @@ private:
CursorShape cursor_shape = CURSOR_ARROW;
Point2i last_click_pos = Point2(-100, -100); // TODO check this again.
uint64_t last_click_ms = 0;
int last_click_button_index = -1;
MouseButton last_click_button_index = MouseButton::NONE;
bool swap_cancel_ok = false;
+13 -13
View File
@@ -34,7 +34,7 @@
Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], bool p_physical) {
#define DOM2GODOT(p_str, p_godot_code) \
if (memcmp((const void *)p_str, (void *)p_code, strlen(p_str) + 1) == 0) { \
return KEY_##p_godot_code; \
return Key::p_godot_code; \
}
// Numpad section.
@@ -105,16 +105,16 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("BracketLeft", BRACKETLEFT);
DOM2GODOT("BracketRight", BRACKETRIGHT);
DOM2GODOT("Comma", COMMA);
DOM2GODOT("Digit0", 0);
DOM2GODOT("Digit1", 1);
DOM2GODOT("Digit2", 2);
DOM2GODOT("Digit3", 3);
DOM2GODOT("Digit4", 4);
DOM2GODOT("Digit5", 5);
DOM2GODOT("Digit6", 6);
DOM2GODOT("Digit7", 7);
DOM2GODOT("Digit8", 8);
DOM2GODOT("Digit9", 9);
DOM2GODOT("Digit0", KEY_0);
DOM2GODOT("Digit1", KEY_1);
DOM2GODOT("Digit2", KEY_2);
DOM2GODOT("Digit3", KEY_3);
DOM2GODOT("Digit4", KEY_4);
DOM2GODOT("Digit5", KEY_5);
DOM2GODOT("Digit6", KEY_6);
DOM2GODOT("Digit7", KEY_7);
DOM2GODOT("Digit8", KEY_8);
DOM2GODOT("Digit9", KEY_9);
DOM2GODOT("Equal", EQUAL);
DOM2GODOT("IntlBackslash", BACKSLASH);
//DOM2GODOT("IntlRo", UNKNOWN);
@@ -170,7 +170,7 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("Tab", TAB);
// ControlPad section.
DOM2GODOT("Delete", DELETE);
DOM2GODOT("Delete", KEY_DELETE);
DOM2GODOT("End", END);
DOM2GODOT("Help", HELP);
DOM2GODOT("Home", HOME);
@@ -227,6 +227,6 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("AudioVolumeMute", VOLUMEMUTE);
DOM2GODOT("AudioVolumeUp", VOLUMEUP);
//DOM2GODOT("WakeUp", UNKNOWN);
return KEY_UNKNOWN;
return Key::UNKNOWN;
#undef DOM2GODOT
}