summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MainWindow.cpp26
-rw-r--r--MainWindow.h11
2 files changed, 27 insertions, 10 deletions
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 3cc0439..20f7a8c 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -986,27 +986,33 @@ MainWindow::on_mouse_move(FXObject *sender, FXSelector sel, void *ptr)
FXEvent* event = (FXEvent*)ptr;
if (lmouse_down && !dragging_link && selected_gate)
{
- selected_gate->set_x(event->last_x-selected_gate->get_width()/2);
- selected_gate->set_y(event->last_y-selected_gate->get_height()/2);
+ Coord currentPos { event->last_x, event->last_y };
+ auto diff = currentPos - lastPos;
+
+ selected_gate->set_x(selected_gate->get_x() + diff.X);
+ selected_gate->set_y(selected_gate->get_y() + diff.Y);
}
else if (lmouse_down && !dragging_link && !selected_gates.empty())
{
+ Coord currentPos { event->last_x, event->last_y };
+ auto diff = currentPos - lastPos;
+
/* moving multiple gates */
- Gate *gate;
- for (auto g = selected_gates.begin(); g != selected_gates.end(); ++g)
+ for (auto* gate : selected_gates)
{
- gate = (*g);
- int gx, gy;
- gx = gate->get_x();
- gy = gate->get_y();
- gate->set_x(event->last_x + (event->last_x - gx));
- gate->set_y(event->last_y + (event->last_y - gy));
+ int gx = gate->get_x();
+ int gy = gate->get_y();
+ gate->set_x(diff.X + gx);
+ gate->set_y(diff.Y + gy);
}
}
if (lmouse_down)
draw();
+
+ lastPos = { event->last_x, event->last_y };
+
return 1;
}
diff --git a/MainWindow.h b/MainWindow.h
index 1110806..3623a1f 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -95,6 +95,16 @@ class MainWindow : public FXMainWindow
MainWindow(){}
private:
+ struct Coord {
+ int X;
+ int Y;
+
+ Coord operator-(const Coord& other) const
+ {
+ return { X - other.X, Y - other.Y };
+ }
+ };
+
void create_ui();
void draw();
void update_gate_state(Gate *gate);
@@ -161,6 +171,7 @@ class MainWindow : public FXMainWindow
int rubberband_starty;
int multiple_move_startx;
int multiple_move_starty;
+ Coord lastPos;
/* keyboard */
bool lshift_down = false;