Bladeren bron

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

Jessey Widhalm 8 jaren geleden
bovenliggende
commit
20576a4b5d
1 gewijzigde bestanden met toevoegingen van 36 en 24 verwijderingen
  1. 36 24
      src/ui/view/UnitGraph.java

+ 36 - 24
src/ui/view/UnitGraph.java

@@ -82,7 +82,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			g2.drawLine((i) * this.getWidth() / (ITERATIONS - 1), MAXIMUM, (i) * this.getWidth() / (ITERATIONS - 1),
 					this.getHeight());
 		}
-		g2.drawLine(0, MAXIMUM, this.getWidth(), MAXIMUM);
+		
+		for (int i = 0; i < ITERATIONS; i++) {
+			g2.drawLine(0, (i) * this.getHeight() / (ITERATIONS - 1), this.getWidth(),
+					(i) * this.getHeight() / (ITERATIONS - 1));
+		}
 
 		// Draw the Lines
 		g2.setColor(Color.BLACK);
@@ -93,28 +97,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			 * 1).getX() * scaleX), (int) (pointList.get(i + 1).getY() *
 			 * scaleY));
 			 */
-			x1 = (int) pointList.get(i).getX();
-			y1 = (int) pointList.get(i).getY();
-			x2 = (int) pointList.get(i + 1).getX();
-			y2 = (int) pointList.get(i + 1).getY();
-			ctrlx1 = (int) pointList.get(i).getX()
-					+ ((int) pointList.get(i + 1).getX() - (int) pointList.get(i).getX()) / 2;
-			ctrlx2 = (int) pointList.get(i + 1).getX()
-					- ((int) pointList.get(i + 1).getX() - (int) pointList.get(i).getX()) / 2;
-			if (y1 < y2) {
-				ctrly1 = (int) pointList.get(i).getY()
-						+ ((int) pointList.get(i + 1).getY() - (int) pointList.get(i).getY()) / 10;
-				ctrly2 = (int) pointList.get(i + 1).getY()
-						- ((int) pointList.get(i + 1).getY() - (int) pointList.get(i).getY()) / 10;
-			} else {
-				ctrly1 = (int) pointList.get(i).getY()
-						- ((int) pointList.get(i).getY() - (int) pointList.get(i + 1).getY()) / 10;
-				ctrly2 = (int) pointList.get(i + 1).getY()
-						+ ((int) pointList.get(i).getY() - (int) pointList.get(i + 1).getY()) / 10;
-			}
-
-			c.setCurve(x1 * scaleX, y1 * scaleY, ctrlx1 * scaleX, ctrly1 * scaleY, ctrlx2 * scaleX, ctrly2 * scaleY,
-					x2 * scaleX, y2 * scaleY);
+			c = buildCurve(pointList.get(i), pointList.get(i+1));
 			g2.draw(c);
 		}
 
@@ -237,9 +220,12 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				height = this.getHeight();
 			}
 
+			scaleX = this.getWidth() / width;
+			scaleY = this.getHeight() / height;
+			
 			if (pointList.isEmpty()) {
 				pointList.addFirst(new Point(0, MAXIMUM));
-				pointList.addLast(new Point(this.getWidth(), MAXIMUM));
+				pointList.addLast(new Point((int) (this.getWidth()/scaleX), MAXIMUM));
 			}
 		}
 		scaleX = this.getWidth() / width;
@@ -300,4 +286,30 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		repaint();
 	}
 
+	public CubicCurve2D buildCurve(Point p1, Point p2){
+		x1 = (int) p1.getX();
+		y1 = (int) p1.getY();
+		x2 = (int) p2.getX();
+		y2 = (int) p2.getY();
+		ctrlx1 = (int) p1.getX()
+				+ ((int) p2.getX() - (int) p1.getX()) / 2;
+		ctrlx2 = (int) p2.getX()
+				- ((int) p2.getX() - (int) p1.getX()) / 2;
+		if (y1 < y2) {
+			ctrly1 = (int) p1.getY()
+					+ ((int) p2.getY() - (int) p1.getY()) / 10;
+			ctrly2 = (int) p2.getY()
+					- ((int) p2.getY() - (int) p1.getY()) / 10;
+		} else {
+			ctrly1 = (int) p1.getY()
+					- ((int) p1.getY() - (int) p2.getY()) / 10;
+			ctrly2 = (int) p2.getY()
+					+ ((int) p1.getY() - (int) p2.getY()) / 10;
+		}
+
+		c.setCurve(x1 * scaleX, y1 * scaleY, ctrlx1 * scaleX, ctrly1 * scaleY, ctrlx2 * scaleX, ctrly2 * scaleY,
+				x2 * scaleX, y2 * scaleY);
+		return c;
+	}
+	
 }