From 243aa8308a633f6b238fd2388354f664b8fca752 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 24 Oct 2017 16:38:57 -0400 Subject: [PATCH] Fixed most mouse alignment issues --- .gitignore | 5 ++++- include/app.hpp | 2 ++ src/app/ModuleWidget.cpp | 4 ++-- src/app/RackWidget.cpp | 8 ++++++-- src/app/Toolbar.cpp | 2 +- src/app/WireWidget.cpp | 4 ++-- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c7086e9b..33ec4075 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ /settings.json /plugins /build -/dep \ No newline at end of file +/dep +*.vcv +/patches +/design diff --git a/include/app.hpp b/include/app.hpp index 69124234..98c8028e 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -111,6 +111,7 @@ struct RackWidget : OpaqueWidget { // Only put WireWidgets in here WireContainer *wireContainer; std::string lastPath; + Vec lastMousePos; RackWidget(); ~RackWidget(); @@ -138,6 +139,7 @@ struct RackWidget : OpaqueWidget { void step() override; void draw(NVGcontext *vg) override; + Widget *onMouseMove(Vec pos, Vec mouseRel) override; void onMouseDownOpaque(int button) override; }; diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 493df945..77f79b46 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -192,12 +192,12 @@ Widget *ModuleWidget::onHoverKey(Vec pos, int key) { } void ModuleWidget::onDragStart() { - dragPos = gMousePos.minus(getAbsolutePos()); + dragPos = gRackWidget->lastMousePos.minus(box.pos); } void ModuleWidget::onDragMove(Vec mouseRel) { Rect newBox = box; - newBox.pos = gMousePos.minus(parent->getAbsolutePos()).minus(dragPos); + newBox.pos = gRackWidget->lastMousePos.minus(dragPos); gRackWidget->requestModuleBoxNearest(this, newBox); } diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index ad35d45f..9aea5cff 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -475,9 +475,13 @@ struct SearchModuleField : TextField { } }; +Widget *RackWidget::onMouseMove(Vec pos, Vec mouseRel) { + lastMousePos = pos; + return OpaqueWidget::onMouseMove(pos, mouseRel); +} + void RackWidget::onMouseDownOpaque(int button) { if (button == 1) { - Vec modulePos = gMousePos.minus(getAbsolutePos()); Menu *menu = gScene->createMenu(); menu->pushChild(construct(&MenuLabel::text, "Add module")); @@ -503,7 +507,7 @@ void RackWidget::onMouseDownOpaque(int button) { AddManufacturerMenuItem *item = new AddManufacturerMenuItem(); item->text = manufacturerName; item->manufacturerName = manufacturerName; - item->modulePos = modulePos; + item->modulePos = lastMousePos; menu->pushChild(item); } } diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index df526bc3..3bf8534e 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -153,7 +153,7 @@ Toolbar::Toolbar() { zoomSlider->box.size.x = 150; zoomSlider->label = "Zoom"; zoomSlider->unit = "%"; - zoomSlider->setLimits(50.0, 200.0); + zoomSlider->setLimits(25.0, 200.0); zoomSlider->setDefaultValue(100.0); addChild(zoomSlider); xPos += zoomSlider->box.size.x; diff --git a/src/app/WireWidget.cpp b/src/app/WireWidget.cpp index 21dcf940..90ef6636 100644 --- a/src/app/WireWidget.cpp +++ b/src/app/WireWidget.cpp @@ -132,7 +132,7 @@ Vec WireWidget::getOutputPos() { pos = Rect(hoveredOutputPort->getAbsolutePos(), hoveredOutputPort->box.size).getCenter(); } else { - pos = gMousePos; + return gRackWidget->lastMousePos; } return pos.minus(getAbsolutePos().minus(box.pos)); } @@ -146,7 +146,7 @@ Vec WireWidget::getInputPos() { pos = Rect(hoveredInputPort->getAbsolutePos(), hoveredInputPort->box.size).getCenter(); } else { - pos = gMousePos; + return gRackWidget->lastMousePos; } return pos.minus(getAbsolutePos().minus(box.pos)); }