Browse Source

wird noc hweiter gemacht

Kevin Trometer 8 years ago
parent
commit
7ae4a3df95
1 changed files with 19 additions and 9 deletions
  1. 19 9
      src/ui/view/UnitGraph.java

+ 19 - 9
src/ui/view/UnitGraph.java

@@ -39,6 +39,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private boolean pointDrag = false;
 	private int tempP;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
+	private double ratio = this.getHeight();
 
 	public UnitGraph(final Model model, Control control) {
 
@@ -60,6 +61,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 */
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
+		
 		g2 = (Graphics2D) g;
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
@@ -73,10 +75,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		g2.setColor(Color.BLACK);
 		g2.setStroke(new BasicStroke(2));
 		for (int i = 0; i < pointList.length - 1; i++) {
-			// g2.drawLine((int)pointList[i].getX(), (int)pointList[i].getY(),
-			// (int)pointList[i+1].getX(), (int)pointList[i+1].getY());
-			
-			//Set up the Curve
 			x1 = (int) pointList[i].getX();
 			y1 = (int) pointList[i].getY();
 			x2 = (int) pointList[i + 1].getX();
@@ -101,9 +99,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		if (pointDrag && e.getY() >= this.getHeight() / 3) {
+		if (pointDrag && e.getY() >= this.getHeight() / 3 && tempP != -1) {
 			pointList[tempP].setLocation(pointList[tempP].getX(), e.getY());
-		} else {
+			if(tempP!=0){
+				pointList[tempP-1].setLocation(pointList[tempP-1].getX(), pointList[tempP-1].getY()+(pointList[tempP].getY()-e.getY())/2);
+			}
+			if(tempP!=NUMBER-1){
+				pointList[tempP+1].setLocation(pointList[tempP+1].getX(), pointList[tempP+1].getY()+(pointList[tempP].getY()-e.getY())/2);
+			}
+		} else if(tempP != -1){
 			pointList[tempP].setLocation(pointList[tempP].getX(), this.getHeight()/3);
 		}
 		repaint();
@@ -135,8 +139,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			if (e.getX() - this.getWidth() / NUMBER / 2 <= pointList[i].getX()
 					&& e.getX() + this.getWidth() / NUMBER / 2 >= pointList[i].getX()
 					&& e.getY() - 10 < pointList[i].getY() && e.getY() + 10 > pointList[i].getY()) {
-				pointDrag = true;
 				tempP = i;
+				pointDrag = true;
 			}
 		}
 	}
@@ -145,13 +149,19 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	public void mouseReleased(MouseEvent e) {
 		if (pointDrag) {
 			pointDrag = false;
+			tempP = -1;
 		}
 	}
 
+	// resize listener
 	public void componentResized(ComponentEvent e) {
-		// resize listener
+		if(pointList[0].getY() != 0)
 		for (int i = 0; i < pointList.length; i++) {
-			pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), this.getHeight() / 3);
+			pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), (int) pointList[i].getY());
+		} else {
+			for (int i = 0; i < pointList.length; i++) {
+				pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), this.getHeight() / 3);
+			}
 		}
 		repaint();
 	}