Browse Source

When Module Browser creates a module, set the ModuleWidget's dragPos to its center, so dragging is more predictable.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
5bbd32ccac
3 changed files with 9 additions and 6 deletions
  1. +3
    -3
      include/app/ModuleWidget.hpp
  2. +1
    -1
      src/app/ModuleBrowser.cpp
  3. +5
    -2
      src/app/ModuleWidget.cpp

+ 3
- 3
include/app/ModuleWidget.hpp View File

@@ -95,9 +95,9 @@ struct ModuleWidget : widget::OpaqueWidget {
*/
virtual void appendContextMenu(ui::Menu* menu) {}

math::Vec& dragPos();
math::Vec& oldPos();
engine::Module* releaseModule();
PRIVATE math::Vec& dragPos();
PRIVATE math::Vec& oldPos();
PRIVATE engine::Module* releaseModule();
};




+ 1
- 1
src/app/ModuleBrowser.cpp View File

@@ -230,7 +230,7 @@ struct ModelBox : widget::OpaqueWidget {

// Set the drag position at the center of the module
// TODO This doesn't work because ModuleWidget::onDragStart, which is called afterwards, overwrites this.
// mw->dragPos() = mw->box.size.div(2);
mw->dragPos() = mw->box.size.div(2);
}
}



+ 5
- 2
src/app/ModuleWidget.cpp View File

@@ -485,6 +485,11 @@ void ModuleWidget::onButton(const event::Button& e) {
else
OpaqueWidget::onButton(e);

// Set starting drag position even if we don't consume it
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
internal->dragPos = e.pos;
}

if (e.isConsumed())
return;

@@ -540,8 +545,6 @@ void ModuleWidget::onHoverKey(const event::HoverKey& e) {

void ModuleWidget::onDragStart(const event::DragStart& e) {
if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
internal->dragPos = APP->scene->rack->mousePos.minus(box.pos);
DEBUG("drag (%f, %f)", VEC_ARGS(internal->dragPos));
APP->scene->rack->updateModuleOldPositions();
}
}


Loading…
Cancel
Save