Kevin Trometer 7 years ago
parent
commit
8e04777649
2 changed files with 31 additions and 12 deletions
  1. BIN
      bin/ui/view/MyCanvas.class
  2. 31 12
      src/ui/view/MyCanvas.java

BIN
bin/ui/view/MyCanvas.class


+ 31 - 12
src/ui/view/MyCanvas.java

@@ -73,11 +73,17 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	 */
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
+		
+		//Selection
 		if(selectRect != null){
 			g.setColor(new Color(100, 255, 100));
 		    g.fillRect((int)selectRect.getX(), (int)selectRect.getY(), (int)selectRect.getWidth(), (int)selectRect.getHeight());
 		}
 		
+		//Edges
+		//g.drawLine(x1, y1, x2, y2);
+		
+		//Objects
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
 			g.drawImage(img, cps.getPos().x, cps.getPos().y, GlobalVariables.SCALE, GlobalVariables.SCALE, null);
@@ -109,6 +115,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		int cx;
 		int cy;
 		tempCps = null;
+		//Object Selection
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPos().x;
 			cy = cps.getPos().y;
@@ -116,16 +123,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 				tempCps = cps;
 			}
 		}
-		//Object Selection
-		if(tempCps != null){
-			selectRect.setBounds(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20), GlobalVariables.SCALE+GlobalVariables.SCALE/10, GlobalVariables.SCALE+GlobalVariables.SCALE/10);
-			controller.setSelectedObjectID(tempCps.getID());
-			System.out.println("Select");
-		}else {
-			controller.setSelectedObjectID(0);
-			selectRect.setRect(0, 0, 0, 0);
-			System.out.println("Unselect");
-		}
+		//Object Selection Highlighting ( selectRect)
+		objectSelectionHighlighting();
+		
 		repaint();		
 	}
 
@@ -147,7 +147,6 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 				itemDelete.setEnabled(false);
 			}
 			popmenu.show(e.getComponent(), e.getX(), e.getY());
-
 		}
 	}
 
@@ -172,14 +171,34 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		y = e.getY();
 		int cx;
 		int cy;
+		boolean on = false;
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPos().x;
 			cy = cps.getPos().y;
 			if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
-				objectTT.setEnabled(true);
 				objectTT.setTipText(cps.getName());
 				objectTT.setLocation(cx, cy);
+				on = true;
 			}
 		}
+		if(!on){
+			objectTT.setLocation(-200, -200);
+			objectTT.setTipText("");
+		}
+	}
+	
+	/**
+	 * Sets the Highlighting of the Selected Object
+	 */
+	private void objectSelectionHighlighting() {
+		if(tempCps != null){
+			selectRect.setBounds(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20), GlobalVariables.SCALE+GlobalVariables.SCALE/10, GlobalVariables.SCALE+GlobalVariables.SCALE/10);
+			controller.setSelectedObjectID(tempCps.getID());
+			System.out.println("Select");
+		}else {
+			controller.setSelectedObjectID(0);
+			selectRect.setRect(0, 0, 0, 0);
+			System.out.println("Unselect");
+		}
 	}
 }