Kevin Trometer 8 rokov pred
rodič
commit
b1e407034f
2 zmenil súbory, kde vykonal 40 pridanie a 10 odobranie
  1. 1 1
      src/ui/view/GUI.java
  2. 39 9
      src/ui/view/UnitGraph.java

+ 1 - 1
src/ui/view/GUI.java

@@ -441,7 +441,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 				}
-				tree.setRowHeight(controller.getScale());
+				tree.setRowHeight(model.getScale());
 				if (hasFocus) {
 					label.setForeground(new Color(0, 0, 255));
 					label.setOpaque(true);

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

@@ -50,7 +50,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	private boolean pointDrag = false;
 	private boolean init = false;
-	private Point tempP = null;
+	private Point tempP = null, p1 = null, p2 = null;
 	private double x = 0, y = 0;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
 
@@ -349,10 +349,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	public void fillArrayofValue() {
 		for (int i = 0; i < arrayOfValue.length; i++) {
-			arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * this.getWidth() / (model.getIterations() - 1))));
+			arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
 		}
 	}
-	
+
 	/**
 	 * 
 	 * @param xVal,
@@ -373,7 +373,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		}
 		return 0;
 	}
-	
+
 	/**
 	 * 
 	 * @param xVal,
@@ -383,17 +383,47 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	public float getYValueAt_2(int xVal) {
 		for (int i = 0; i < pointList.size() - 1; i++) {
 			// get the Points
-			if (xVal <= pointList.get(i + 1).getX()) {
+			if (xVal >= pointList.get(i).getX()) {
 				// Curve erstellen
 				c = buildCurve(pointList.get(i), pointList.get(i + 1));
-				for (int j = 0; j < height; j++) {
-					if (c.contains(xVal, j)) {
-						return j;
+				c.subdivide(cl, cr);
+				// Teil der Kurve aussuchen
+				if (cl.getX1() <= xVal * scaleX && cl.getX2() > xVal * scaleX) {
+					c = cl;
+					//Kurve Links von "unten"
+					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
+						for (int j = (int) (height - 1); j >= 0; j--) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					} else {//Kurve Links von "oben"
+						for (int j = 0; j < height; j++) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					}
+				} else {
+					c = cr;
+					//Kurve Links von "unten"
+					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
+						for (int j = 0; j < height; j++) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					} else {//Kurve Links von "oben"
+						for (int j = (int) (height - 1); j >= 0; j--) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
 					}
 				}
 			}
 		}
-		return 0;
+		return getYValueAt(xVal);
 	}
 
 	public Point getIntersectionPoint(Line2D l1, Line2D l2) {