Browse Source

Apply rack offset in ModuleWidget::get/setGridPosition() etc.

tags/v2.1.2
Andrew Belt 2 years ago
parent
commit
2cb341274a
3 changed files with 23 additions and 15 deletions
  1. +5
    -13
      include/app/ModuleWidget.hpp
  2. +16
    -0
      src/app/ModuleWidget.cpp
  3. +2
    -2
      src/app/RackWidget.cpp

+ 5
- 13
include/app/ModuleWidget.hpp View File

@@ -116,19 +116,11 @@ struct ModuleWidget : widget::OpaqueWidget {
void removeAction();
void createContextMenu();

// Returns the position in grid coordinates
math::Vec getGridPosition() {
return getPosition().div(RACK_GRID_SIZE).round();
}
void setGridPosition(math::Vec pos) {
setPosition(pos.mult(RACK_GRID_SIZE));
}
math::Vec getGridSize() {
return getSize().div(RACK_GRID_SIZE).round();
}
math::Rect getGridBox() {
return math::Rect(getGridPosition(), getGridSize());
}
// Returns the rack position in grid coordinates
math::Vec getGridPosition();
void setGridPosition(math::Vec pos);
math::Vec getGridSize();
math::Rect getGridBox();

PRIVATE math::Vec& dragOffset();
PRIVATE bool& dragEnabled();


+ 16
- 0
src/app/ModuleWidget.cpp View File

@@ -1095,6 +1095,22 @@ void ModuleWidget::createContextMenu() {
appendContextMenu(menu);
}

math::Vec ModuleWidget::getGridPosition() {
return ((getPosition() - RACK_OFFSET) / RACK_GRID_SIZE).round();
}

void ModuleWidget::setGridPosition(math::Vec pos) {
setPosition(pos * RACK_GRID_SIZE + RACK_OFFSET);
}

math::Vec ModuleWidget::getGridSize() {
return (getSize() / RACK_GRID_SIZE).round();
}

math::Rect ModuleWidget::getGridBox() {
return math::Rect(getGridPosition(), getGridSize());
}

math::Vec& ModuleWidget::dragOffset() {
return internal->dragOffset;
}


+ 2
- 2
src/app/RackWidget.cpp View File

@@ -700,7 +700,7 @@ static bool compareModuleLeft(ModuleWidget* a, ModuleWidget* b) {

void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) {
math::Rect mwBox;
mwBox.pos = pos.div(RACK_GRID_SIZE).round();
mwBox.pos = ((pos - RACK_OFFSET) / RACK_GRID_SIZE).round();
mwBox.size = mw->getGridSize();

// Collect modules to the left and right of new pos
@@ -770,7 +770,7 @@ void RackWidget::setModulePosSqueeze(ModuleWidget* mw, math::Vec pos) {

void RackWidget::squeezeModulePos(ModuleWidget* mw, math::Vec pos) {
math::Rect mwBox;
mwBox.pos = pos.div(RACK_GRID_SIZE).round();
mwBox.pos = ((pos - RACK_OFFSET) / RACK_GRID_SIZE).round();
mwBox.size = mw->getGridSize();

// Collect modules to the left and right of new pos


Loading…
Cancel
Save