Explorar o código

multiple drag and drop

Kevin Trometer %!s(int64=8) %!d(string=hai) anos
pai
achega
f9c838b9e6
Modificáronse 1 ficheiros con 27 adicións e 5 borrados
  1. 27 5
      src/ui/view/MyCanvas.java

+ 27 - 5
src/ui/view/MyCanvas.java

@@ -345,9 +345,12 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 		if (dragging) {
 			try {
+				float xDist, yDist; //Distance
+				
 				x = e.getX() - controller.getScaleDiv2();
 				y = e.getY() - controller.getScaleDiv2();
 
+				//Make sure its in bounds
 				if (e.getX() < controller.getScaleDiv2())
 					x = 0;
 				else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
@@ -356,16 +359,35 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					y = 0;
 				else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
 					y = this.getHeight() - controller.getScale();
-				// Drag Position
-				tempCps.setPosition(x, y);
-				// Highlighting Position
-				selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
+
+				//Distance
+				xDist = x-tempCps.getPosition().x;
+				yDist = y-tempCps.getPosition().y;
+				
+				tempCps.setPosition(x, y); // Drag Position
+				selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20)); // Highlighting-Position
+				
 				// TipText Position and name
 				objectTT.setTipText(tempCps.getName());
 				objectTT.setLocation(x, y + controller.getScale());
+				
+				//All Selected Objects
 				for (CpsObject cps : model.getSelectedCpsObjects()) {
 					if (cps != tempCps) {
-
+						x = (int) (cps.getPosition().x+xDist);
+						y = (int) (cps.getPosition().y+yDist);
+
+						//Make sure its in bounds
+						if (x < 0)
+							x = 0;
+						else if (x > this.getWidth())
+							x = this.getWidth() - controller.getScale();
+						if (y < controller.getScaleDiv2())
+							y = 0;
+						else if (y > this.getHeight())
+							y = this.getHeight() - controller.getScale();
+						
+						cps.setPosition(x, y);
 					}
 				}
 				repaint();