Browse Source

Edges malen mit STRG

Kevin Trometer 8 years ago
parent
commit
6c00ae5fef
3 changed files with 29 additions and 12 deletions
  1. BIN
      bin/ui/view/MyCanvas.class
  2. 1 0
      src/classes/GlobalVariables.java
  3. 28 12
      src/ui/view/MyCanvas.java

BIN
bin/ui/view/MyCanvas.class


+ 1 - 0
src/classes/GlobalVariables.java

@@ -2,4 +2,5 @@ package classes;
 
 public class GlobalVariables {
 	public static int SCALE = 75;
+	public static int SCALE_DIVIDED2 = SCALE/2;
 }

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

@@ -1,6 +1,7 @@
 package ui.view;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.Paint;
@@ -32,12 +33,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	private Image img = null; // Contains the image to draw on MyCanvas
 	private int x = 0;
 	private int y = 0;
+	//edge Object Start Point
 	private Model model;
 	private final Control controller;
 	private int cx;
 	private int cy;
 	
 	boolean dragging = false;
+	boolean drawEdge = false;
 	boolean dropDelete = false;
 	private CpsObject tempCps = null;
 	private Rectangle selectRect = new Rectangle();
@@ -83,7 +86,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		}
 		
 		//Edges
-		//g.drawLine(x1, y1, x2, y2);
+		g.setColor(Color.BLACK);
+		if(drawEdge)g.drawLine(tempCps.getPos().x+GlobalVariables.SCALE_DIVIDED2, tempCps.getPos().y+GlobalVariables.SCALE_DIVIDED2, x, y);
 		
 		//Objects
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
@@ -122,6 +126,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			cy = cps.getPos().y;
 			if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
+				if(e.isControlDown())drawEdge = true;
 			}
 		}
 		
@@ -133,14 +138,17 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 
 	@Override
 	public void mouseReleased(MouseEvent e) {
+		if(drawEdge){
+			drawEdge = false;
+		}
+		
 		if (dragging) {
 			x = e.getX();
 			y = e.getY();
 			
 			dragging = false;
-			tempCps.setPos(e.getX() - GlobalVariables.SCALE/2, e.getY() - GlobalVariables.SCALE/2);
+			tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
 			tempCps = null;
-			repaint();
 		}
 		// Rechtsklick Liste
 		if (e.getButton() == e.BUTTON3) {
@@ -151,20 +159,28 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			}
 			popmenu.show(e.getComponent(), e.getX(), e.getY());
 		}
+		
+		repaint();
 	}
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
 		// TODO Auto-generated method stub
-			try {
-				tempCps.setPos(e.getX() - GlobalVariables.SCALE/2, e.getY() - GlobalVariables.SCALE/2);
-				dragging = true;
-				selectRect.setLocation(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20));
-				objectTT.setTipText(tempCps.getName());
-				objectTT.setLocation(tempCps.getPos().x, tempCps.getPos().y);
-				repaint();
-			} catch (Exception e2) {
-				// TODO: handle exception
+			if(drawEdge){
+			x = e.getX();
+			y = e.getY();
+			repaint();
+			}else{
+				try {
+					tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
+					dragging = true;
+					selectRect.setLocation(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20));
+					objectTT.setTipText(tempCps.getName());
+					objectTT.setLocation(tempCps.getPos().x, tempCps.getPos().y);
+					repaint();
+				} catch (Exception e2) {
+					// TODO: handle exception
+				}
 			}
 	}