diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-09 08:33:26 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-09 08:33:26 +0100 |
commit | e7905f4f48c18daa948838549f2846b79d4bd1d4 (patch) | |
tree | a7e81d1d846ef21c71834fc5290ac9f24303306a /platform | |
parent | bb08997b8725780670be30afa96354e7c38586fd (diff) | |
parent | 2b815df3c19499f9fcf1575cfce1477876030e81 (diff) |
Merge pull request #71045 from reduz/use-bitfield-in-core-types
Use BitField<> in core type masks
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/android_input_handler.cpp | 40 | ||||
-rw-r--r-- | platform/android/android_input_handler.h | 12 | ||||
-rw-r--r-- | platform/android/display_server_android.cpp | 4 | ||||
-rw-r--r-- | platform/android/display_server_android.h | 2 | ||||
-rw-r--r-- | platform/android/java_godot_lib_jni.cpp | 10 | ||||
-rw-r--r-- | platform/linuxbsd/joypad_linux.cpp | 24 | ||||
-rw-r--r-- | platform/linuxbsd/joypad_linux.h | 2 | ||||
-rw-r--r-- | platform/linuxbsd/x11/display_server_x11.cpp | 14 | ||||
-rw-r--r-- | platform/linuxbsd/x11/display_server_x11.h | 6 | ||||
-rw-r--r-- | platform/macos/display_server_macos.h | 6 | ||||
-rw-r--r-- | platform/macos/display_server_macos.mm | 4 | ||||
-rw-r--r-- | platform/macos/godot_content_view.h | 2 | ||||
-rw-r--r-- | platform/macos/godot_content_view.mm | 41 | ||||
-rw-r--r-- | platform/macos/joypad_macos.cpp | 27 | ||||
-rw-r--r-- | platform/web/display_server_web.cpp | 22 | ||||
-rw-r--r-- | platform/windows/display_server_windows.cpp | 8 | ||||
-rw-r--r-- | platform/windows/display_server_windows.h | 4 | ||||
-rw-r--r-- | platform/windows/joypad_windows.cpp | 25 |
18 files changed, 136 insertions, 117 deletions
diff --git a/platform/android/android_input_handler.cpp b/platform/android/android_input_handler.cpp index cfa1046bb3..e3f93086dc 100644 --- a/platform/android/android_input_handler.cpp +++ b/platform/android/android_input_handler.cpp @@ -225,7 +225,7 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const } } -void AndroidInputHandler::_parse_mouse_event_info(MouseButton 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_double_click, bool p_source_mouse_relative) { if (!mouse_event_info.valid) { return; } @@ -242,7 +242,7 @@ void AndroidInputHandler::_parse_mouse_event_info(MouseButton event_buttons_mask hover_prev_pos = mouse_event_info.pos; } ev->set_pressed(p_pressed); - MouseButton changed_button_mask = MouseButton(buttons_state ^ event_buttons_mask); + BitField<MouseButtonMask> changed_button_mask = BitField<MouseButtonMask>(buttons_state.operator int64_t() ^ event_buttons_mask.operator int64_t()); buttons_state = event_buttons_mask; @@ -253,12 +253,12 @@ void AndroidInputHandler::_parse_mouse_event_info(MouseButton event_buttons_mask } void AndroidInputHandler::_release_mouse_event_info(bool p_source_mouse_relative) { - _parse_mouse_event_info(MouseButton::NONE, false, false, p_source_mouse_relative); + _parse_mouse_event_info(BitField<MouseButtonMask>(), false, false, p_source_mouse_relative); 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) { - MouseButton event_buttons_mask = _android_button_mask_to_godot_button_mask(p_event_android_buttons_mask); + BitField<MouseButtonMask> event_buttons_mask = _android_button_mask_to_godot_button_mask(p_event_android_buttons_mask); switch (p_event_action) { case AMOTION_EVENT_ACTION_HOVER_MOVE: // hover move case AMOTION_EVENT_ACTION_HOVER_ENTER: // hover enter @@ -342,11 +342,11 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an } } -void AndroidInputHandler::_wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor) { +void AndroidInputHandler::_wheel_button_click(BitField<MouseButtonMask> event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor) { Ref<InputEventMouseButton> evd = ev->duplicate(); _set_key_modifier_state(evd); evd->set_button_index(wheel_button); - evd->set_button_mask(MouseButton(event_buttons_mask ^ mouse_button_to_mask(wheel_button))); + evd->set_button_mask(BitField<MouseButtonMask>(event_buttons_mask.operator int64_t() ^ int64_t(mouse_button_to_mask(wheel_button)))); evd->set_factor(factor); Input::get_singleton()->parse_input_event(evd); Ref<InputEventMouseButton> evdd = evd->duplicate(); @@ -373,39 +373,39 @@ void AndroidInputHandler::process_pan(Point2 p_pos, Vector2 p_delta) { Input::get_singleton()->parse_input_event(pan_event); } -MouseButton AndroidInputHandler::_button_index_from_mask(MouseButton button_mask) { - switch (button_mask) { - case MouseButton::MASK_LEFT: +MouseButton AndroidInputHandler::_button_index_from_mask(BitField<MouseButtonMask> button_mask) { + switch (MouseButtonMask(button_mask.operator int64_t())) { + case MouseButtonMask::LEFT: return MouseButton::LEFT; - case MouseButton::MASK_RIGHT: + case MouseButtonMask::RIGHT: return MouseButton::RIGHT; - case MouseButton::MASK_MIDDLE: + case MouseButtonMask::MIDDLE: return MouseButton::MIDDLE; - case MouseButton::MASK_XBUTTON1: + case MouseButtonMask::MB_XBUTTON1: return MouseButton::MB_XBUTTON1; - case MouseButton::MASK_XBUTTON2: + case MouseButtonMask::MB_XBUTTON2: return MouseButton::MB_XBUTTON2; default: return MouseButton::NONE; } } -MouseButton AndroidInputHandler::_android_button_mask_to_godot_button_mask(int android_button_mask) { - MouseButton godot_button_mask = MouseButton::NONE; +BitField<MouseButtonMask> AndroidInputHandler::_android_button_mask_to_godot_button_mask(int android_button_mask) { + BitField<MouseButtonMask> godot_button_mask; if (android_button_mask & AMOTION_EVENT_BUTTON_PRIMARY) { - godot_button_mask |= MouseButton::MASK_LEFT; + godot_button_mask.set_flag(MouseButtonMask::LEFT); } if (android_button_mask & AMOTION_EVENT_BUTTON_SECONDARY) { - godot_button_mask |= MouseButton::MASK_RIGHT; + godot_button_mask.set_flag(MouseButtonMask::RIGHT); } if (android_button_mask & AMOTION_EVENT_BUTTON_TERTIARY) { - godot_button_mask |= MouseButton::MASK_MIDDLE; + godot_button_mask.set_flag(MouseButtonMask::MIDDLE); } if (android_button_mask & AMOTION_EVENT_BUTTON_BACK) { - godot_button_mask |= MouseButton::MASK_XBUTTON1; + godot_button_mask.set_flag(MouseButtonMask::MB_XBUTTON1); } if (android_button_mask & AMOTION_EVENT_BUTTON_FORWARD) { - godot_button_mask |= MouseButton::MASK_XBUTTON2; + godot_button_mask.set_flag(MouseButtonMask::MB_XBUTTON2); } return godot_button_mask; diff --git a/platform/android/android_input_handler.h b/platform/android/android_input_handler.h index 1b89096057..34259efd81 100644 --- a/platform/android/android_input_handler.h +++ b/platform/android/android_input_handler.h @@ -61,7 +61,7 @@ public: int index = 0; // Can be either JoyAxis or JoyButton. bool pressed = false; float value = 0; - HatMask hat = HatMask::CENTER; + BitField<HatMask> hat; }; private: @@ -70,7 +70,7 @@ private: bool control_mem = false; bool meta_mem = false; - MouseButton buttons_state = MouseButton::NONE; + BitField<MouseButtonMask> buttons_state; Vector<TouchPos> touch; MouseEventInfo mouse_event_info; @@ -78,12 +78,12 @@ private: void _set_key_modifier_state(Ref<InputEventWithModifiers> ev); - static MouseButton _button_index_from_mask(MouseButton button_mask); - static MouseButton _android_button_mask_to_godot_button_mask(int android_button_mask); + static MouseButton _button_index_from_mask(BitField<MouseButtonMask> button_mask); + static BitField<MouseButtonMask> _android_button_mask_to_godot_button_mask(int android_button_mask); - void _wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor); + void _wheel_button_click(BitField<MouseButtonMask> event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor); - void _parse_mouse_event_info(MouseButton event_buttons_mask, bool p_pressed, bool p_double_click, bool p_source_mouse_relative); + void _parse_mouse_event_info(BitField<MouseButtonMask> event_buttons_mask, bool p_pressed, bool p_double_click, bool p_source_mouse_relative); void _release_mouse_event_info(bool p_source_mouse_relative = false); diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 70370764e2..780ad4334e 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -624,8 +624,8 @@ Point2i DisplayServerAndroid::mouse_get_position() const { return Input::get_singleton()->get_mouse_position(); } -MouseButton DisplayServerAndroid::mouse_get_button_state() const { - return (MouseButton)Input::get_singleton()->get_mouse_button_mask(); +BitField<MouseButtonMask> DisplayServerAndroid::mouse_get_button_state() const { + return Input::get_singleton()->get_mouse_button_mask(); } void DisplayServerAndroid::_cursor_set_shape_helper(CursorShape p_shape, bool force) { diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h index faaa3dbd9c..b2400d81dc 100644 --- a/platform/android/display_server_android.h +++ b/platform/android/display_server_android.h @@ -207,7 +207,7 @@ public: void notify_surface_changed(int p_width, int p_height); virtual Point2i mouse_get_position() const override; - virtual MouseButton mouse_get_button_state() const override; + virtual BitField<MouseButtonMask> mouse_get_button_state() const override; void reset_swap_buffers_flag(); bool should_swap_buffers() const; diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index b502e587a7..e6cdd7932a 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -353,19 +353,19 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j AndroidInputHandler::JoypadEvent jevent; jevent.device = p_device; jevent.type = AndroidInputHandler::JOY_EVENT_HAT; - HatMask hat = HatMask::CENTER; + BitField<HatMask> hat; if (p_hat_x != 0) { if (p_hat_x < 0) { - hat |= HatMask::LEFT; + hat.set_flag(HatMask::LEFT); } else { - hat |= HatMask::RIGHT; + hat.set_flag(HatMask::RIGHT); } } if (p_hat_y != 0) { if (p_hat_y < 0) { - hat |= HatMask::UP; + hat.set_flag(HatMask::UP); } else { - hat |= HatMask::DOWN; + hat.set_flag(HatMask::DOWN); } } jevent.hat = hat; diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index 672c48addc..b77f989677 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -59,7 +59,7 @@ JoypadLinux::Joypad::~Joypad() { } void JoypadLinux::Joypad::reset() { - dpad = HatMask::CENTER; + dpad = 0; fd = -1; for (int i = 0; i < MAX_ABS; i++) { abs_map[i] = -1; @@ -485,27 +485,33 @@ void JoypadLinux::process_joypads() { case ABS_HAT0X: if (joypad_event.value != 0) { if (joypad_event.value < 0) { - joypad.dpad = (HatMask)((joypad.dpad | HatMask::LEFT) & ~HatMask::RIGHT); + joypad.dpad.set_flag(HatMask::LEFT); + joypad.dpad.clear_flag(HatMask::RIGHT); } else { - joypad.dpad = (HatMask)((joypad.dpad | HatMask::RIGHT) & ~HatMask::LEFT); + joypad.dpad.set_flag(HatMask::RIGHT); + joypad.dpad.clear_flag(HatMask::LEFT); } } else { - joypad.dpad &= ~(HatMask::LEFT | HatMask::RIGHT); + joypad.dpad.clear_flag(HatMask::LEFT); + joypad.dpad.clear_flag(HatMask::RIGHT); } - input->joy_hat(i, (HatMask)joypad.dpad); + input->joy_hat(i, joypad.dpad); break; case ABS_HAT0Y: if (joypad_event.value != 0) { if (joypad_event.value < 0) { - joypad.dpad = (HatMask)((joypad.dpad | HatMask::UP) & ~HatMask::DOWN); + joypad.dpad.set_flag(HatMask::UP); + joypad.dpad.clear_flag(HatMask::DOWN); } else { - joypad.dpad = (HatMask)((joypad.dpad | HatMask::DOWN) & ~HatMask::UP); + joypad.dpad.set_flag(HatMask::DOWN); + joypad.dpad.clear_flag(HatMask::UP); } } else { - joypad.dpad &= ~(HatMask::UP | HatMask::DOWN); + joypad.dpad.clear_flag(HatMask::UP); + joypad.dpad.clear_flag(HatMask::DOWN); } - input->joy_hat(i, (HatMask)joypad.dpad); + input->joy_hat(i, joypad.dpad); break; default: diff --git a/platform/linuxbsd/joypad_linux.h b/platform/linuxbsd/joypad_linux.h index 7926756cbe..6661abdb37 100644 --- a/platform/linuxbsd/joypad_linux.h +++ b/platform/linuxbsd/joypad_linux.h @@ -62,7 +62,7 @@ private: float curr_axis[MAX_ABS]; int key_map[MAX_KEY]; int abs_map[MAX_ABS]; - HatMask dpad = HatMask::CENTER; + BitField<HatMask> dpad; int fd = -1; String devpath; diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index ea109a8816..10fd9972e3 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -458,7 +458,7 @@ Point2i DisplayServerX11::mouse_get_position() const { return Vector2i(); } -MouseButton DisplayServerX11::mouse_get_button_state() const { +BitField<MouseButtonMask> DisplayServerX11::mouse_get_button_state() const { return last_button_state; } @@ -2843,13 +2843,13 @@ void DisplayServerX11::_get_key_modifier_state(unsigned int p_x11_state, Ref<Inp state->set_meta_pressed((p_x11_state & Mod4Mask)); } -MouseButton DisplayServerX11::_get_mouse_button_state(MouseButton p_x11_button, int p_x11_type) { - MouseButton mask = mouse_button_to_mask(p_x11_button); +BitField<MouseButtonMask> DisplayServerX11::_get_mouse_button_state(MouseButton p_x11_button, int p_x11_type) { + MouseButtonMask mask = mouse_button_to_mask(p_x11_button); if (p_x11_type == ButtonPress) { - last_button_state |= mask; + last_button_state.set_flag(mask); } else { - last_button_state &= ~mask; + last_button_state.clear_flag(mask); } return last_button_state; @@ -4171,13 +4171,13 @@ void DisplayServerX11::process_events() { if (xi.pressure_supported) { mm->set_pressure(xi.pressure); } else { - mm->set_pressure(bool(mouse_get_button_state() & MouseButton::MASK_LEFT) ? 1.0f : 0.0f); + mm->set_pressure(bool(mouse_get_button_state().has_flag(MouseButtonMask::LEFT)) ? 1.0f : 0.0f); } mm->set_tilt(xi.tilt); mm->set_pen_inverted(xi.pen_inverted); _get_key_modifier_state(event.xmotion.state, mm); - mm->set_button_mask((MouseButton)mouse_get_button_state()); + mm->set_button_mask(mouse_get_button_state()); mm->set_position(pos); mm->set_global_position(pos); mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); diff --git a/platform/linuxbsd/x11/display_server_x11.h b/platform/linuxbsd/x11/display_server_x11.h index 2fac446fcf..43a66f95b2 100644 --- a/platform/linuxbsd/x11/display_server_x11.h +++ b/platform/linuxbsd/x11/display_server_x11.h @@ -205,7 +205,7 @@ class DisplayServerX11 : public DisplayServer { Point2i last_click_pos = Point2i(-100, -100); uint64_t last_click_ms = 0; MouseButton last_click_button_index = MouseButton::NONE; - MouseButton last_button_state = MouseButton::NONE; + BitField<MouseButtonMask> last_button_state; bool app_focused = false; uint64_t time_since_no_focus = 0; @@ -234,7 +234,7 @@ class DisplayServerX11 : public DisplayServer { Rect2i _screen_get_rect(int p_screen) const; - MouseButton _get_mouse_button_state(MouseButton p_x11_button, int p_x11_type); + BitField<MouseButtonMask> _get_mouse_button_state(MouseButton p_x11_button, int p_x11_type); void _get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state); void _flush_mouse_motion(); @@ -344,7 +344,7 @@ public: virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; - virtual MouseButton mouse_get_button_state() const override; + virtual BitField<MouseButtonMask> mouse_get_button_state() const override; virtual void clipboard_set(const String &p_text) override; virtual String clipboard_get() const override; diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index 2927c67890..7f57644a4c 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -154,7 +154,7 @@ private: CGEventSourceRef event_source; MouseMode mouse_mode = MOUSE_MODE_VISIBLE; - MouseButton last_button_state = MouseButton::NONE; + BitField<MouseButtonMask> last_button_state; bool drop_events = false; bool in_dispatch_input_event = false; @@ -317,8 +317,8 @@ public: bool update_mouse_wrap(WindowData &p_wd, NSPoint &r_delta, NSPoint &r_mpos, NSTimeInterval p_timestamp); virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; - void mouse_set_button_state(MouseButton p_state); - virtual MouseButton mouse_get_button_state() const override; + void mouse_set_button_state(BitField<MouseButtonMask> p_state); + virtual BitField<MouseButtonMask> mouse_get_button_state() const override; virtual void clipboard_set(const String &p_text) override; virtual String clipboard_get() const override; diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 3bbb3e35fb..759ae03d95 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -2034,11 +2034,11 @@ Point2i DisplayServerMacOS::mouse_get_position() const { return Vector2i(); } -void DisplayServerMacOS::mouse_set_button_state(MouseButton p_state) { +void DisplayServerMacOS::mouse_set_button_state(BitField<MouseButtonMask> p_state) { last_button_state = p_state; } -MouseButton DisplayServerMacOS::mouse_get_button_state() const { +BitField<MouseButtonMask> DisplayServerMacOS::mouse_get_button_state() const { return last_button_state; } diff --git a/platform/macos/godot_content_view.h b/platform/macos/godot_content_view.h index c0fde4d765..ba7f15c32b 100644 --- a/platform/macos/godot_content_view.h +++ b/platform/macos/godot_content_view.h @@ -66,7 +66,7 @@ - (void)processScrollEvent:(NSEvent *)event button:(MouseButton)button factor:(double)factor; - (void)processPanEvent:(NSEvent *)event dx:(double)dx dy:(double)dy; -- (void)processMouseEvent:(NSEvent *)event index:(MouseButton)index mask:(MouseButton)mask pressed:(bool)pressed; +- (void)processMouseEvent:(NSEvent *)event index:(MouseButton)index pressed:(bool)pressed; - (void)setWindowID:(DisplayServer::WindowID)wid; - (void)updateLayerDelegate; - (void)cancelComposition; diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm index 50befc997d..337aa59a5e 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -371,19 +371,21 @@ ds->cursor_update_shape(); } -- (void)processMouseEvent:(NSEvent *)event index:(MouseButton)index mask:(MouseButton)mask pressed:(bool)pressed { +- (void)processMouseEvent:(NSEvent *)event index:(MouseButton)index pressed:(bool)pressed { DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); if (!ds || !ds->has_window(window_id)) { return; } DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); - MouseButton last_button_state = ds->mouse_get_button_state(); + BitField<MouseButtonMask> last_button_state = ds->mouse_get_button_state(); + + MouseButtonMask mask = mouse_button_to_mask(index); if (pressed) { - last_button_state |= mask; + last_button_state.set_flag(mask); } else { - last_button_state &= (MouseButton)~mask; + last_button_state.clear_flag(mask); } ds->mouse_set_button_state(last_button_state); @@ -407,10 +409,10 @@ - (void)mouseDown:(NSEvent *)event { if (([event modifierFlags] & NSEventModifierFlagControl)) { mouse_down_control = true; - [self processMouseEvent:event index:MouseButton::RIGHT mask:MouseButton::MASK_RIGHT pressed:true]; + [self processMouseEvent:event index:MouseButton::RIGHT pressed:true]; } else { mouse_down_control = false; - [self processMouseEvent:event index:MouseButton::LEFT mask:MouseButton::MASK_LEFT pressed:true]; + [self processMouseEvent:event index:MouseButton::LEFT pressed:true]; } } @@ -420,9 +422,9 @@ - (void)mouseUp:(NSEvent *)event { if (mouse_down_control) { - [self processMouseEvent:event index:MouseButton::RIGHT mask:MouseButton::MASK_RIGHT pressed:false]; + [self processMouseEvent:event index:MouseButton::RIGHT pressed:false]; } else { - [self processMouseEvent:event index:MouseButton::LEFT mask:MouseButton::MASK_LEFT pressed:false]; + [self processMouseEvent:event index:MouseButton::LEFT pressed:false]; } } @@ -469,7 +471,7 @@ } - (void)rightMouseDown:(NSEvent *)event { - [self processMouseEvent:event index:MouseButton::RIGHT mask:MouseButton::MASK_RIGHT pressed:true]; + [self processMouseEvent:event index:MouseButton::RIGHT pressed:true]; } - (void)rightMouseDragged:(NSEvent *)event { @@ -477,16 +479,16 @@ } - (void)rightMouseUp:(NSEvent *)event { - [self processMouseEvent:event index:MouseButton::RIGHT mask:MouseButton::MASK_RIGHT pressed:false]; + [self processMouseEvent:event index:MouseButton::RIGHT pressed:false]; } - (void)otherMouseDown:(NSEvent *)event { if ((int)[event buttonNumber] == 2) { - [self processMouseEvent:event index:MouseButton::MIDDLE mask:MouseButton::MASK_MIDDLE pressed:true]; + [self processMouseEvent:event index:MouseButton::MIDDLE pressed:true]; } else if ((int)[event buttonNumber] == 3) { - [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 mask:MouseButton::MASK_XBUTTON1 pressed:true]; + [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:true]; } else if ((int)[event buttonNumber] == 4) { - [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 mask:MouseButton::MASK_XBUTTON2 pressed:true]; + [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:true]; } else { return; } @@ -498,11 +500,11 @@ - (void)otherMouseUp:(NSEvent *)event { if ((int)[event buttonNumber] == 2) { - [self processMouseEvent:event index:MouseButton::MIDDLE mask:MouseButton::MASK_MIDDLE pressed:false]; + [self processMouseEvent:event index:MouseButton::MIDDLE pressed:false]; } else if ((int)[event buttonNumber] == 3) { - [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 mask:MouseButton::MASK_XBUTTON1 pressed:false]; + [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:false]; } else if ((int)[event buttonNumber] == 4) { - [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 mask:MouseButton::MASK_XBUTTON2 pressed:false]; + [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:false]; } else { return; } @@ -751,7 +753,8 @@ } DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); - MouseButton mask = mouse_button_to_mask(button); + MouseButtonMask mask = mouse_button_to_mask(button); + BitField<MouseButtonMask> last_button_state = ds->mouse_get_button_state(); Ref<InputEventMouseButton> sc; sc.instantiate(); @@ -763,7 +766,7 @@ sc->set_pressed(true); sc->set_position(wd.mouse_pos); sc->set_global_position(wd.mouse_pos); - MouseButton last_button_state = ds->mouse_get_button_state() | (MouseButton)mask; + last_button_state.set_flag(mask); sc->set_button_mask(last_button_state); ds->mouse_set_button_state(last_button_state); @@ -776,7 +779,7 @@ sc->set_pressed(false); sc->set_position(wd.mouse_pos); sc->set_global_position(wd.mouse_pos); - last_button_state &= (MouseButton)~mask; + last_button_state.clear_flag(mask); sc->set_button_mask(last_button_state); ds->mouse_set_button_state(last_button_state); diff --git a/platform/macos/joypad_macos.cpp b/platform/macos/joypad_macos.cpp index 4ea18916fe..b7b8e0604c 100644 --- a/platform/macos/joypad_macos.cpp +++ b/platform/macos/joypad_macos.cpp @@ -402,10 +402,10 @@ bool joypad::check_ff_features() { return false; } -static HatMask process_hat_value(int p_min, int p_max, int p_value, bool p_offset_hat) { +static BitField<HatMask> process_hat_value(int p_min, int p_max, int p_value, bool p_offset_hat) { int range = (p_max - p_min + 1); int value = p_value - p_min; - HatMask hat_value = HatMask::CENTER; + BitField<HatMask> hat_value; if (range == 4) { value *= 2; } @@ -415,31 +415,34 @@ static HatMask process_hat_value(int p_min, int p_max, int p_value, bool p_offse switch (value) { case 0: - hat_value = HatMask::UP; + hat_value.set_flag(HatMask::UP); break; case 1: - hat_value = (HatMask::UP | HatMask::RIGHT); + hat_value.set_flag(HatMask::UP); + hat_value.set_flag(HatMask::RIGHT); break; case 2: - hat_value = HatMask::RIGHT; + hat_value.set_flag(HatMask::RIGHT); break; case 3: - hat_value = (HatMask::DOWN | HatMask::RIGHT); + hat_value.set_flag(HatMask::DOWN); + hat_value.set_flag(HatMask::RIGHT); break; case 4: - hat_value = HatMask::DOWN; + hat_value.set_flag(HatMask::DOWN); break; case 5: - hat_value = (HatMask::DOWN | HatMask::LEFT); + hat_value.set_flag(HatMask::DOWN); + hat_value.set_flag(HatMask::LEFT); break; case 6: - hat_value = HatMask::LEFT; + hat_value.set_flag(HatMask::LEFT); break; case 7: - hat_value = (HatMask::UP | HatMask::LEFT); + hat_value.set_flag(HatMask::UP); + hat_value.set_flag(HatMask::LEFT); break; default: - hat_value = HatMask::CENTER; break; } return hat_value; @@ -474,7 +477,7 @@ void JoypadMacOS::process_joypads() { for (int j = 0; j < joy.hat_elements.size(); j++) { rec_element &elem = joy.hat_elements.write[j]; int value = joy.get_hid_element_state(&elem); - HatMask hat_value = process_hat_value(elem.min, elem.max, value, joy.offset_hat); + BitField<HatMask> hat_value = process_hat_value(elem.min, elem.max, value, joy.offset_hat); input->joy_hat(joy.id, hat_value); } diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index 2c69c0873d..7dd0515d3f 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -193,12 +193,12 @@ int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double } } - MouseButton mask = Input::get_singleton()->get_mouse_button_mask(); - MouseButton button_flag = mouse_button_to_mask(ev->get_button_index()); + BitField<MouseButtonMask> mask = Input::get_singleton()->get_mouse_button_mask(); + MouseButtonMask button_flag = mouse_button_to_mask(ev->get_button_index()); if (ev->is_pressed()) { - mask |= button_flag; - } else if ((mask & button_flag) != MouseButton::NONE) { - mask &= ~button_flag; + mask.set_flag(button_flag); + } else if (mask.has_flag(button_flag)) { + mask.clear_flag(button_flag); } else { // Received release event, but press was outside the canvas, so ignore. return false; @@ -218,10 +218,10 @@ int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double } void DisplayServerWeb::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) { - MouseButton input_mask = Input::get_singleton()->get_mouse_button_mask(); + BitField<MouseButtonMask> 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 behavior. - if (!get_singleton()->cursor_inside_canvas && input_mask == MouseButton::NONE) { + if (!get_singleton()->cursor_inside_canvas && input_mask.is_empty()) { return; } @@ -525,15 +525,17 @@ int DisplayServerWeb::mouse_wheel_callback(double p_delta_x, double p_delta_y) { // Different browsers give wildly different delta values, and we can't // interpret deltaMode, so use default value for wheel events' factor. - MouseButton button_flag = mouse_button_to_mask(ev->get_button_index()); + MouseButtonMask button_flag = mouse_button_to_mask(ev->get_button_index()); + BitField<MouseButtonMask> button_mask = input->get_mouse_button_mask(); + button_mask.set_flag(button_flag); ev->set_pressed(true); - ev->set_button_mask(input->get_mouse_button_mask() | button_flag); + ev->set_button_mask(button_mask); input->parse_input_event(ev); Ref<InputEventMouseButton> release = ev->duplicate(); release->set_pressed(false); - release->set_button_mask(MouseButton(input->get_mouse_button_mask() & ~button_flag)); + release->set_button_mask(input->get_mouse_button_mask()); input->parse_input_event(release); return true; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 889797ca62..99b80c2e2a 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -257,7 +257,7 @@ Point2i DisplayServerWindows::mouse_get_position() const { return Point2i(p.x, p.y) - _get_screens_origin(); } -MouseButton DisplayServerWindows::mouse_get_button_state() const { +BitField<MouseButtonMask> DisplayServerWindows::mouse_get_button_state() const { return last_button_state; } @@ -3162,9 +3162,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mb->set_alt_pressed(alt_mem); // mb->is_alt_pressed()=(wParam&MK_MENU)!=0; if (mb->is_pressed()) { - last_button_state |= mouse_button_to_mask(mb->get_button_index()); + last_button_state.set_flag(mouse_button_to_mask(mb->get_button_index())); } else { - last_button_state &= ~mouse_button_to_mask(mb->get_button_index()); + last_button_state.clear_flag(mouse_button_to_mask(mb->get_button_index())); } mb->set_button_mask(last_button_state); @@ -3205,7 +3205,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA // Send release for mouse wheel. Ref<InputEventMouseButton> mbd = mb->duplicate(); mbd->set_window_id(window_id); - last_button_state &= ~mouse_button_to_mask(mbd->get_button_index()); + last_button_state.clear_flag(mouse_button_to_mask(mbd->get_button_index())); mbd->set_button_mask(last_button_state); mbd->set_pressed(false); Input::get_singleton()->parse_input_event(mbd); diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index feed9f35ed..e9f30024b2 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -446,7 +446,7 @@ class DisplayServerWindows : public DisplayServer { bool shift_mem = false; bool control_mem = false; bool meta_mem = false; - MouseButton last_button_state = MouseButton::NONE; + BitField<MouseButtonMask> last_button_state; bool use_raw_input = false; bool drop_events = false; bool in_dispatch_input_event = false; @@ -506,7 +506,7 @@ public: virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; - virtual MouseButton mouse_get_button_state() const override; + virtual BitField<MouseButtonMask> mouse_get_button_state() const override; virtual void clipboard_set(const String &p_text) override; virtual String clipboard_get() const override; diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index aed5f5b8dc..183958cf40 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -420,38 +420,43 @@ void JoypadWindows::process_joypads() { } void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { - HatMask dpad_val = (HatMask)0; + BitField<HatMask> dpad_val; // Should be -1 when centered, but according to docs: // "Some drivers report the centered position of the POV indicator as 65,535. Determine whether the indicator is centered as follows: // BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);" // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v%3Dvs.85)#remarks if (LOWORD(p_dpad) == 0xFFFF) { - dpad_val = (HatMask)HatMask::CENTER; + // Do nothing. + // dpad_val.set_flag(HatMask::CENTER); } if (p_dpad == 0) { - dpad_val = (HatMask)HatMask::UP; + dpad_val.set_flag(HatMask::UP); } else if (p_dpad == 4500) { - dpad_val = (HatMask)(HatMask::UP | HatMask::RIGHT); + dpad_val.set_flag(HatMask::UP); + dpad_val.set_flag(HatMask::RIGHT); } else if (p_dpad == 9000) { - dpad_val = (HatMask)HatMask::RIGHT; + dpad_val.set_flag(HatMask::RIGHT); } else if (p_dpad == 13500) { - dpad_val = (HatMask)(HatMask::RIGHT | HatMask::DOWN); + dpad_val.set_flag(HatMask::RIGHT); + dpad_val.set_flag(HatMask::DOWN); } else if (p_dpad == 18000) { - dpad_val = (HatMask)HatMask::DOWN; + dpad_val.set_flag(HatMask::DOWN); } else if (p_dpad == 22500) { - dpad_val = (HatMask)(HatMask::DOWN | HatMask::LEFT); + dpad_val.set_flag(HatMask::DOWN); + dpad_val.set_flag(HatMask::LEFT); } else if (p_dpad == 27000) { - dpad_val = (HatMask)HatMask::LEFT; + dpad_val.set_flag(HatMask::LEFT); } else if (p_dpad == 31500) { - dpad_val = (HatMask)(HatMask::LEFT | HatMask::UP); + dpad_val.set_flag(HatMask::LEFT); + dpad_val.set_flag(HatMask::UP); } input->joy_hat(p_device, dpad_val); } |