diff --git a/src/Core/GuiDialog.cpp b/src/Core/GuiDialog.cpp index ef5a9527..af1b0db8 100644 --- a/src/Core/GuiDialog.cpp +++ b/src/Core/GuiDialog.cpp @@ -118,7 +118,7 @@ void DialogData::onMousePress(MousePress& evt) { stopCapturingMouse(); recti r = rect_; if (isMouseOver()) { - if (evt.button == Mouse::LMB && evt.unhandled()) { + if (evt.button == Mouse::LMB && !evt.handled) { auto actionType = GetAction(evt.x, evt.y); if (actionType != ACT_NONE || IsInside(r, evt.x, evt.y)) { @@ -138,7 +138,7 @@ void DialogData::onMousePress(MousePress& evt) { request_pin_ = true; } } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Core/Input.cpp b/src/Core/Input.cpp index 4c7f9165..03f2138b 100644 --- a/src/Core/Input.cpp +++ b/src/Core/Input.cpp @@ -351,18 +351,4 @@ void InputHandler::handleInputs(InputEvents& events) { } } -// ================================================================================================ -// InputHandler :: events structs. - -void MousePress::setHandled() { handled = true; } - -MousePress::MousePress(Mouse::Code code, int x, int y, int keyflags, - bool doubleClick, bool handled) - : button(code), - x(x), - y(y), - keyflags(keyflags), - doubleClick(doubleClick), - handled(handled) {} - } // namespace Vortex diff --git a/src/Core/Input.h b/src/Core/Input.h index 790955a2..94e2914c 100644 --- a/src/Core/Input.h +++ b/src/Core/Input.h @@ -187,18 +187,12 @@ struct MouseMove { /// Contains data from a mouse button press event. struct MousePress { - MousePress(Mouse::Code code, int x, int y, int keyflags, bool doubleClick, - bool handled); Mouse::Code button; ///< The mouse button that was pressed. int x, y; ///< The position of the mouse cursor. int keyflags; ///< Keyflag values of modifier keys that were down. bool doubleClick; ///< True if the press is the second press of a double ///< click. - bool unhandled() const { return !handled; } - void setHandled(); - - private: - bool handled; ///< Used to track if the event is handled. + bool handled; ///< Used to track if the event is handled. }; /// Contains data from a mouse button release event. diff --git a/src/Core/WidgetsColor.cpp b/src/Core/WidgetsColor.cpp index 26428b85..1865be90 100644 --- a/src/Core/WidgetsColor.cpp +++ b/src/Core/WidgetsColor.cpp @@ -227,21 +227,21 @@ void WgColorPicker::onMousePress(MousePress& evt) { evt.button == Mouse::LMB) { colorpicker_expanded_->startDrag(evt.x, evt.y); startCapturingMouse(); - evt.setHandled(); + evt.handled = true; } else { delete colorpicker_expanded_; colorpicker_expanded_ = nullptr; stopCapturingFocus(); } } else if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); startCapturingFocus(); colorpicker_expanded_ = new Expanded; colorpicker_expanded_->tick(rect_, gui_); } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Core/WidgetsScroll.cpp b/src/Core/WidgetsScroll.cpp index a7dd0340..76d66b1f 100644 --- a/src/Core/WidgetsScroll.cpp +++ b/src/Core/WidgetsScroll.cpp @@ -109,7 +109,7 @@ void WgScrollbar::setPage(int size) { scrollbar_page_ = size; } void WgScrollbar::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { uint32_t action = GetScrollbarActionAtPosition(evt.x, evt.y); if (action) { startCapturingMouse(); @@ -127,7 +127,7 @@ void WgScrollbar::onMousePress(MousePress& evt) { scrollbar_action_ = ACT_DRAGGING_V; } } - evt.setHandled(); + evt.handled = true; } } @@ -228,7 +228,7 @@ void WgScrollRegion::onMouseScroll(MouseScroll& evt) { void WgScrollRegion::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { uint32_t action = getScrollRegionActionAt_(evt.x, evt.y); if (action) { startCapturingMouse(); @@ -248,7 +248,7 @@ void WgScrollRegion::onMousePress(MousePress& evt) { scroll_region_action_ = ACT_DRAGGING_V; } } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Core/WidgetsSelect.cpp b/src/Core/WidgetsSelect.cpp index cef70802..845e8f52 100644 --- a/src/Core/WidgetsSelect.cpp +++ b/src/Core/WidgetsSelect.cpp @@ -36,7 +36,7 @@ void WgSelectList::clearItems() { selectlist_items_.clear(); } void WgSelectList::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); // Handle interaction with the item list. @@ -49,7 +49,7 @@ void WgSelectList::onMousePress(MousePress& evt) { } } } - evt.setHandled(); + evt.handled = true; } } @@ -177,12 +177,12 @@ void WgDroplist::onMousePress(MousePress& evt) { recti r = selectlist_widget_->getRect(); if (evt.button == Mouse::RMB || !IsInside(r, evt.x, evt.y)) { CloseDroplist(); - evt.setHandled(); + evt.handled = true; } } else if (isMouseOver()) { int numItems = droplist_items_.size(); if (isEnabled() && numItems && evt.button == Mouse::LMB && - evt.unhandled()) { + !evt.handled) { int h = std::min(numItems * gSystem->applyScaleFactor(18) + 8, gSystem->applyScaleFactor(128)); recti r = {rect_.x, rect_.y + rect_.h, rect_.w, h}; @@ -201,7 +201,7 @@ void WgDroplist::onMousePress(MousePress& evt) { startCapturingMouse(); startCapturingFocus(); } - evt.setHandled(); + evt.handled = true; } } @@ -312,7 +312,7 @@ void WgCycleButton::onMousePress(MousePress& evt) { int numItems = cycle_items_.size(); if (isMouseOver()) { if (numItems > 1 && isEnabled() && evt.button == Mouse::LMB && - evt.unhandled()) { + !evt.handled) { stopCapturingText(); startCapturingMouse(); if (evt.x > CenterX(rect_)) { @@ -322,7 +322,7 @@ void WgCycleButton::onMousePress(MousePress& evt) { } onChange.call(); } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Core/WidgetsSimple.cpp b/src/Core/WidgetsSimple.cpp index 165e13b1..b866e0ac 100644 --- a/src/Core/WidgetsSimple.cpp +++ b/src/Core/WidgetsSimple.cpp @@ -49,13 +49,13 @@ WgButton::WgButton(GuiContext* gui) : GuiWidget(gui) {} void WgButton::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); isDown.set(true); counter.set(counter.get() + 1); onPress.call(); } - evt.setHandled(); + evt.handled = true; } } @@ -98,12 +98,12 @@ WgCheckbox::WgCheckbox(GuiContext* gui) : GuiWidget(gui) {} void WgCheckbox::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); value.set(!value.get()); onChange.call(); } - evt.setHandled(); + evt.handled = true; } } @@ -161,11 +161,11 @@ void WgSlider::setRange(double begin, double end) { void WgSlider::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); SliderDrag(evt.x, evt.y); } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Core/WidgetsText.cpp b/src/Core/WidgetsText.cpp index 0db6a6f4..205c5403 100644 --- a/src/Core/WidgetsText.cpp +++ b/src/Core/WidgetsText.cpp @@ -126,7 +126,7 @@ void WgLineEdit::onKeyRelease(KeyRelease& evt) { void WgLineEdit::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { if (isCapturingText() && evt.doubleClick) { lineedit_cursor_.x = 0; lineedit_cursor_.y = static_cast(lineedit_text_.length()); @@ -149,7 +149,7 @@ void WgLineEdit::onMousePress(MousePress& evt) { startCapturingMouse(); lineedit_blink_time_ = 0.f; - evt.setHandled(); + evt.handled = true; } } else deselect(); @@ -381,7 +381,7 @@ WgSpinner::WgSpinner(GuiContext* gui) : GuiWidget(gui) { void WgSpinner::onMousePress(MousePress& evt) { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { spinner_lineedit_->deselect(); startCapturingMouse(); recti r = SpinnerButtonRect(); @@ -390,7 +390,7 @@ void WgSpinner::onMousePress(MousePress& evt) { SpinnerUpdateValue(value.get() + spinner_step_size_ * sign); spinner_repeat_timer_ = 0.5f; } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Dialogs/ChartList.cpp b/src/Dialogs/ChartList.cpp index ba547588..f833b708 100644 --- a/src/Dialogs/ChartList.cpp +++ b/src/Dialogs/ChartList.cpp @@ -28,11 +28,11 @@ struct DialogChartList::ChartButton : public GuiWidget { void onMousePress(MousePress& evt) override { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); gSimfile->openChart(myChartIndex); } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Dialogs/LabelBreakdown.cpp b/src/Dialogs/LabelBreakdown.cpp index 081dabbd..219c2841 100644 --- a/src/Dialogs/LabelBreakdown.cpp +++ b/src/Dialogs/LabelBreakdown.cpp @@ -35,11 +35,11 @@ struct DialogLabelBreakdown::LabelButton : public GuiWidget { void onMousePress(MousePress& evt) override { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { startCapturingMouse(); gView->setCursorRow(myRow); } - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Dialogs/TempoBreakdown.cpp b/src/Dialogs/TempoBreakdown.cpp index a8ebeec9..78242fb9 100644 --- a/src/Dialogs/TempoBreakdown.cpp +++ b/src/Dialogs/TempoBreakdown.cpp @@ -71,11 +71,11 @@ struct DialogTempoBreakdown::TempoList : public WgScrollRegion { void onMousePress(MousePress& evt) override { if (isMouseOver()) { - if (isEnabled() && evt.button == Mouse::LMB && evt.unhandled()) { + if (isEnabled() && evt.button == Mouse::LMB && !evt.handled) { auto seg = getSegmentUnderMouse(gui_->getMousePos()); if (seg) { gView->setCursorRow(seg->row); - evt.setHandled(); + evt.handled = true; } } } diff --git a/src/Editor/Editing.cpp b/src/Editor/Editing.cpp index 00d30689..0824caa7 100755 --- a/src/Editor/Editing.cpp +++ b/src/Editor/Editing.cpp @@ -326,9 +326,9 @@ struct EditingImpl : public Editing { // Finish tweaking. int mode = gTempo->getTweakMode(); if ((evt.button == Mouse::LMB || evt.button == Mouse::RMB) && mode && - evt.unhandled()) { + !evt.handled) { gTempo->stopTweaking(evt.button == Mouse::LMB); - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Editor/Menubar.cpp b/src/Editor/Menubar.cpp index 74a40505..2ddb708b 100644 --- a/src/Editor/Menubar.cpp +++ b/src/Editor/Menubar.cpp @@ -862,7 +862,7 @@ struct MenuBarImpl : public Menubar { void onMousePress(MousePress& evt) override { #ifdef GL_MENU_BAR - if (evt.button != Mouse::LMB || !evt.unhandled()) return; + if (evt.button != Mouse::LMB || evt.handled) return; auto handle_menu = [&](MenuItem* menu) { int i = 0; for (auto it : menu->getMenuData()) { @@ -876,7 +876,7 @@ struct MenuBarImpl : public Menubar { else { Action::perform(it.action); } - evt.setHandled(); + evt.handled = true; return false; } return true; diff --git a/src/Editor/Minimap.cpp b/src/Editor/Minimap.cpp index 82ba2da4..53e7b788 100755 --- a/src/Editor/Minimap.cpp +++ b/src/Editor/Minimap.cpp @@ -315,11 +315,11 @@ struct MinimapImpl : public Minimap { void onMousePress(MousePress& evt) override { if (evt.button == Mouse::LMB && !gTextOverlay->isOpen() && - evt.unhandled()) { + !evt.handled) { if (IsInside(rect_, evt.x, evt.y)) { gView->setCursorOffset(myGetMapOffset(evt.y)); myIsDragging = true; - evt.setHandled(); + evt.handled = true; } } } diff --git a/src/Editor/Selection.cpp b/src/Editor/Selection.cpp index 4d4eb21d..196cc63f 100755 --- a/src/Editor/Selection.cpp +++ b/src/Editor/Selection.cpp @@ -95,19 +95,19 @@ struct SelectionImpl : public Selection { void onMousePress(MousePress& evt) override { // Start dragging a selection box. - if (evt.button == Mouse::LMB && evt.unhandled()) { + if (evt.button == Mouse::LMB && !evt.handled) { myIsDraggingSelection = true; myDragSelectionX = evt.x; myDragSelectionTor = gView->yToOffset(evt.y); - evt.setHandled(); + evt.handled = true; } // Clear selection. - if (evt.button == Mouse::RMB && evt.unhandled()) { + if (evt.button == Mouse::RMB && !evt.handled) { gNotes->deselectAll(); gTempoBoxes->deselectAll(); this->setRegion(0, 0); - evt.setHandled(); + evt.handled = true; } } diff --git a/src/Editor/TextOverlay.cpp b/src/Editor/TextOverlay.cpp index 12907f24..deef1bcc 100644 --- a/src/Editor/TextOverlay.cpp +++ b/src/Editor/TextOverlay.cpp @@ -521,8 +521,8 @@ struct TextOverlayImpl : public TextOverlay { gSystem->setCursor(Cursor::HAND); MousePress* mp = nullptr; if (gSystem->getEvents().next(mp)) { - if (mp->unhandled()) { - mp->setHandled(); + if (!mp->handled) { + mp->handled = true; gSystem->openWebpage( reinterpret_cast(supportLink)); } @@ -533,8 +533,8 @@ struct TextOverlayImpl : public TextOverlay { gSystem->setCursor(Cursor::HAND); MousePress* mp = nullptr; if (gSystem->getEvents().next(mp)) { - if (mp->unhandled()) { - mp->setHandled(); + if (!mp->handled) { + mp->handled = true; gSystem->openWebpage( reinterpret_cast(githubLink)); } diff --git a/src/Editor/View.cpp b/src/Editor/View.cpp index 018ddf0e..3628e0e0 100755 --- a/src/Editor/View.cpp +++ b/src/Editor/View.cpp @@ -131,23 +131,23 @@ struct ViewImpl : public View, public InputHandler { void onMousePress(MousePress& evt) override { // Dragging the preview receptors. if (evt.button == Mouse::LMB && - isMouseOverReceptorsPreview(evt.x, evt.y) && evt.unhandled()) { + isMouseOverReceptorsPreview(evt.x, evt.y) && !evt.handled) { myIsDraggingReceptorsPreview = true; - evt.setHandled(); + evt.handled = true; } // Dragging the receptors. else if (evt.button == Mouse::LMB && - isMouseOverReceptors(evt.x, evt.y) && evt.unhandled()) { + isMouseOverReceptors(evt.x, evt.y) && !evt.handled) { myIsDraggingReceptors = true; - evt.setHandled(); + evt.handled = true; } - if (evt.unhandled() && evt.button == Mouse::MMB) { + if (!evt.handled && evt.button == Mouse::MMB) { Vortex::vec2i mouse_pos = gSystem->getMousePos(); Vortex::ChartOffset ofs = gView->yToOffset(mouse_pos.y); setCursorRow(snapRow(offsetToRow(ofs), SnapDir::SNAP_CLOSEST)); - evt.setHandled(); + evt.handled = true; } } diff --git a/src/System/System.cpp b/src/System/System.cpp index 5b031377..db06d458 100644 --- a/src/System/System.cpp +++ b/src/System/System.cpp @@ -802,32 +802,39 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { } break; } - case SDL_EVENT_MOUSE_BUTTON_DOWN: - if (event->button.button == SDL_BUTTON_LEFT) { + case SDL_EVENT_MOUSE_BUTTON_DOWN: { + mc = event->button.button; + if (mc >= SDL_BUTTON_LEFT && mc <= SDL_BUTTON_RIGHT) { SDL_CaptureMouse(true); if (myIsInsideMessageLoop) { - myMousePos = - windowMouseToApp(event->button.x, event->button.y); - myEvents.addMousePress(Mouse::LMB, myMousePos.x, + auto mdc = mcodes[mc]; + float x, y; + SDL_GetMouseState(&x, &y); + myMousePos = windowMouseToApp(x, y); + myEvents.addMousePress(mcodes[mc], myMousePos.x, myMousePos.y, gSystem->getKeyFlags(), - false); - myMouseState.set(Mouse::LMB); + event->button.clicks >= 2); + myMouseState.set(mcodes[mc]); } } break; - case SDL_EVENT_MOUSE_BUTTON_UP: - if (event->button.button == SDL_BUTTON_LEFT) { + } + case SDL_EVENT_MOUSE_BUTTON_UP: { + mc = event->button.button; + if (mc >= SDL_BUTTON_LEFT && mc <= SDL_BUTTON_RIGHT) { SDL_CaptureMouse(false); if (myIsInsideMessageLoop) { - myMousePos = - windowMouseToApp(event->button.x, event->button.y); - myEvents.addMouseRelease(Mouse::LMB, myMousePos.x, + float x, y; + SDL_GetMouseState(&x, &y); + myMousePos = windowMouseToApp(x, y); + myEvents.addMouseRelease(mcodes[mc], myMousePos.x, myMousePos.y, gSystem->getKeyFlags()); - myMouseState.reset(Mouse::LMB); + myMouseState.reset(mcodes[mc]); } } break; + } case SDL_EVENT_TEXT_INPUT: { const char* wp = event->text.text; const char n = '\n';