Merge banaan en develop
This commit is contained in:
+12
-31
@@ -19,7 +19,6 @@ public abstract class DrawObject
|
||||
double rotation;
|
||||
double scale;
|
||||
private Image image;
|
||||
private Image rotateImage;
|
||||
protected boolean selected;
|
||||
private Rectangle2D rektAngle;
|
||||
private Rectangle2D upperLeftCorner;
|
||||
@@ -36,7 +35,6 @@ public abstract class DrawObject
|
||||
public DrawObject(String filename, Point2D position)
|
||||
{
|
||||
image = new ImageIcon(filename).getImage();
|
||||
rotateImage = new ImageIcon("rotate.png").getImage();
|
||||
scale = 1;
|
||||
rotation = 0;
|
||||
this.position = position;
|
||||
@@ -55,7 +53,7 @@ public abstract class DrawObject
|
||||
// image.getHeight(null)/2);
|
||||
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
|
||||
g.transform(rotate);
|
||||
//g.transform(rotate);
|
||||
g.setColor(rectangleColor);
|
||||
g.setStroke(new BasicStroke(7));
|
||||
rektAngle = new Rectangle2D.Double((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
|
||||
@@ -163,38 +161,17 @@ public abstract class DrawObject
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param corners
|
||||
* @return if there is a collision
|
||||
* Checking collision.
|
||||
* @param object. the drawObject to check collision with.
|
||||
* @return if there is a collision.
|
||||
*/
|
||||
public boolean collision(DrawObject object)
|
||||
{
|
||||
// Point2D[] ownCorners = getCorners();
|
||||
Point2D[] objectCorners = object.getCorners();
|
||||
Shape ownShape = new Rectangle2D.Double(-9, -9, image.getWidth(null) + 13, image.getHeight(null) + 13);
|
||||
ownShape = getTransformSelection().createTransformedShape(ownShape);
|
||||
// Shape otherShape = new Rectangle2D.Double(-9,
|
||||
// -9,object.getImage().getWidth(null) +
|
||||
// 13,object.getImage().getHeight(null) + 13);
|
||||
// otherShape =
|
||||
// getTransformSelection().createTransformedShape(otherShape);
|
||||
if (ownShape.contains(objectCorners[0]))
|
||||
Shape ownShape = getRectangle();
|
||||
Rectangle2D otherRectangle = object.getTransform().createTransformedShape(object.getImageRectangle()).getBounds2D();
|
||||
if(ownShape.intersects(otherRectangle))
|
||||
return true;
|
||||
else if (ownShape.contains(objectCorners[1]))
|
||||
return true;
|
||||
else if (ownShape.contains(objectCorners[2]))
|
||||
return true;
|
||||
else if (ownShape.contains(objectCorners[3]))
|
||||
return true;
|
||||
// if(otherShape.contains(ownCorners[0]))
|
||||
// return true;
|
||||
// else if(otherShape.contains(ownCorners[1]))
|
||||
// return true;
|
||||
// else if(otherShape.contains(ownCorners[2]))
|
||||
// return true;
|
||||
// else if(otherShape.contains(ownCorners[3]))
|
||||
// return true;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -305,5 +282,9 @@ public abstract class DrawObject
|
||||
{
|
||||
this.rectangleColor = rectangleColor;
|
||||
}
|
||||
|
||||
public Rectangle2D getImageRectangle() {
|
||||
return new Rectangle2D.Double(0,0, image.getWidth(null), image.getHeight(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,17 @@ public class MenuBar extends JMenuBar
|
||||
|
||||
JMenu file = new JMenu("File");
|
||||
|
||||
JMenuItem newPath = new JMenuItem("New Path");
|
||||
newPath.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().startPath();
|
||||
}
|
||||
});
|
||||
|
||||
file.add(newPath);
|
||||
|
||||
JMenuItem exit = new JMenuItem("Exit");
|
||||
exit.addActionListener(new ActionListener()
|
||||
{
|
||||
|
||||
+80
-4
@@ -2,12 +2,13 @@ package Applicatie;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.TexturePaint;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
@@ -25,6 +26,7 @@ import Listeners.MouseMotion;
|
||||
import Listeners.MouseWheel;
|
||||
import Objects.Entrance;
|
||||
import Objects.Food;
|
||||
import Objects.OldPath;
|
||||
import Objects.Path;
|
||||
import Objects.Stage;
|
||||
import Objects.Toilet;
|
||||
@@ -43,9 +45,11 @@ public class Panel extends JPanel
|
||||
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
|
||||
|
||||
ArrayList<DrawObject> objects = new ArrayList<>();
|
||||
ArrayList<Path> paths = new ArrayList<>();
|
||||
DrawObject dragObject = null;
|
||||
private DrawObject selectedObject;
|
||||
private String clickedOption = "drag";
|
||||
private Path currentPath;
|
||||
|
||||
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
|
||||
float cameraScale = 1;
|
||||
@@ -132,7 +136,7 @@ public class Panel extends JPanel
|
||||
case 2:
|
||||
return new Entrance(null);
|
||||
case 3:
|
||||
return new Path(null);
|
||||
return new OldPath(null);
|
||||
case 4:
|
||||
return new Wall(null);
|
||||
case 5:
|
||||
@@ -152,8 +156,10 @@ public class Panel extends JPanel
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 300));
|
||||
|
||||
Stroke old = g2.getStroke();
|
||||
g2.setStroke(new BasicStroke(10));
|
||||
g2.drawLine(0, 150, getWidth(), 150);
|
||||
g2.setStroke(old);
|
||||
for (BufferedImage image : panelInfo)
|
||||
{
|
||||
g2.drawImage(image, panelInfox + scrollfactor, panelInfoy, null);
|
||||
@@ -171,13 +177,23 @@ public class Panel extends JPanel
|
||||
|
||||
BasicStroke stroke = new BasicStroke(10);
|
||||
g2.setStroke(stroke);
|
||||
|
||||
for(Path path : paths) {
|
||||
path.draw(g2);
|
||||
}
|
||||
for (DrawObject o : objects)
|
||||
{
|
||||
o.draw(g2);
|
||||
}
|
||||
g2.setTransform(oldTransform);
|
||||
if(currentPath != null) { //Display text while in path making modes.
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.setFont(new Font("Verdana",Font.ITALIC,25));
|
||||
g2.drawString("Press enter to finish the path.",20,185);
|
||||
}
|
||||
|
||||
g2.setClip(null);
|
||||
g2.setTransform(oldTransform);
|
||||
|
||||
}
|
||||
|
||||
public AffineTransform getCamera()
|
||||
@@ -335,6 +351,10 @@ public class Panel extends JPanel
|
||||
this.clickedOption = clickedOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a DrawObject from the list.
|
||||
* @param o - the DrawObject you want to remove from the list.
|
||||
*/
|
||||
public void removeObject(DrawObject o)
|
||||
{
|
||||
Iterator<DrawObject> itr = objects.iterator();
|
||||
@@ -369,7 +389,63 @@ public class Panel extends JPanel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin making a new path.
|
||||
*/
|
||||
public void startPath() {
|
||||
setClickedOption("Path");
|
||||
currentPath = new Path();
|
||||
paths.add(currentPath);
|
||||
pp.setSelectedPath(currentPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current selected Path.
|
||||
* @return - the selected Path.
|
||||
*/
|
||||
public Path getCurrentPath() {
|
||||
return currentPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selected Path object.
|
||||
* @param path - the selected Path object.
|
||||
*/
|
||||
public void setcurrentPath(Path path) {
|
||||
currentPath = path;
|
||||
pp.setSelectedPath(currentPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the point is contained in one of the path's.
|
||||
* @param point - The point to check for.
|
||||
* @return if the point is contained in one of the path's.
|
||||
*/
|
||||
public boolean checkPath(Point2D point) {
|
||||
for(Path path : paths) {
|
||||
if(path.containsPoint(point)) {
|
||||
setcurrentPath(path);
|
||||
setClickedOption("Path");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path from the list.
|
||||
* @param path - the path you want to remove from the list.
|
||||
*/
|
||||
public void removePath(Path path) {
|
||||
Iterator<Path> it = paths.iterator();
|
||||
while(it.hasNext()) {
|
||||
if(it.next().equals(path)) {
|
||||
pp.clearSelected();
|
||||
setClickedOption("drag");
|
||||
currentPath = null;
|
||||
it.remove();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,20 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import Objects.Path;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PropertiesPanel extends JPanel
|
||||
{
|
||||
|
||||
DrawObject selectedObject = null;
|
||||
Path selectedPath = null;
|
||||
|
||||
Panel p = null;
|
||||
|
||||
Dimension spacerDimension = new Dimension(200, 30);
|
||||
|
||||
|
||||
JLabel nameLabel;
|
||||
|
||||
JTextField locationXField;
|
||||
@@ -84,7 +89,11 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
p.removeObject(selectedObject);
|
||||
if(selectedObject != null)
|
||||
p.removeObject(selectedObject);
|
||||
else if(selectedPath != null) {
|
||||
p.removePath(selectedPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
deletePanel.setPreferredSize(new Dimension(200, 50));
|
||||
@@ -296,6 +305,7 @@ public class PropertiesPanel extends JPanel
|
||||
public void setSelected(DrawObject drOb)
|
||||
{
|
||||
selectedObject = drOb;
|
||||
selectedPath = null;
|
||||
fillFields();
|
||||
enableComponents(this, true);
|
||||
}
|
||||
@@ -305,11 +315,13 @@ public class PropertiesPanel extends JPanel
|
||||
enableComponents(this, false);
|
||||
clearFields(this);
|
||||
selectedObject = null;
|
||||
selectedPath = null;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
fillFields();
|
||||
if(selectedObject != null)
|
||||
fillFields();
|
||||
}
|
||||
|
||||
private void enableComponents(Container container, boolean enable)
|
||||
@@ -348,21 +360,32 @@ public class PropertiesPanel extends JPanel
|
||||
|
||||
private void fillFields()
|
||||
{
|
||||
if (selectedObject != null)
|
||||
{
|
||||
|
||||
nameLabel.setText(selectedObject.getName());
|
||||
|
||||
locationXField.setText(Math.round(selectedObject.getPosition().getX()) + "");
|
||||
locationYField.setText(Math.round(selectedObject.getPosition().getY()) + "");
|
||||
scaleField.setText((double) Math.round(selectedObject.getScale() * 10) / 10 + "");
|
||||
rotationField.setText(Math.round(selectedObject.getRotation() % 360) + "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPanel(Panel p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void setSelectedPath(Path path) {
|
||||
selectedObject = null;
|
||||
selectedPath = path;
|
||||
fillPathFields();
|
||||
}
|
||||
|
||||
private void fillPathFields() {
|
||||
nameLabel.setText("Path");
|
||||
enableComponents(this, true);
|
||||
locationXField.setEnabled(false);
|
||||
locationYField.setEnabled(false);
|
||||
scaleField.setEnabled(false);
|
||||
rotationField.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ public class Window extends JFrame
|
||||
{
|
||||
private static final long serialVersionUID = -1324363758675184283L;
|
||||
|
||||
private Panel fp;
|
||||
|
||||
Window() {
|
||||
super("Festival Plannner");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
@@ -20,7 +22,7 @@ public class Window extends JFrame
|
||||
// CONTENT PANELS
|
||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||
PropertiesPanel pp = new PropertiesPanel();
|
||||
Panel fp = new Panel(pp);
|
||||
fp = new Panel(pp);
|
||||
contentPanel.add(fp, BorderLayout.CENTER);
|
||||
contentPanel.add(pp, BorderLayout.EAST);
|
||||
|
||||
@@ -35,4 +37,8 @@ public class Window extends JFrame
|
||||
setFocusable(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public Panel getPanel() {
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public class Keyboard implements KeyListener {
|
||||
if(e.getKeyCode() == e.VK_DELETE ) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.removeObject(panel.getSelectedObject());
|
||||
else if(panel.getCurrentPath() != null)
|
||||
panel.removePath(panel.getCurrentPath());
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_LEFT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
@@ -41,6 +43,17 @@ public class Keyboard implements KeyListener {
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()+5));
|
||||
panel.checkCollision();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_ENTER) {
|
||||
if(panel.getClickedOption().equals("Path")) {
|
||||
panel.setClickedOption("drag");
|
||||
panel.getCurrentPath().setTempPoint(null);
|
||||
panel.setcurrentPath(null);
|
||||
panel.getPP().clearSelected();
|
||||
}
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_P) {
|
||||
panel.startPath();
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
|
||||
+83
-76
@@ -27,93 +27,100 @@ public class Mouse extends MouseAdapter
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
if (e.getY() < 150)
|
||||
{
|
||||
int i = 0;
|
||||
int last = 0;
|
||||
for (BufferedImage image : panel.getPanelInfo())
|
||||
if(!panel.getClickedOption().equals("Path")) {
|
||||
if (e.getY() < 150)
|
||||
{
|
||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
int i = 0;
|
||||
int last = 0;
|
||||
for (BufferedImage image : panel.getPanelInfo())
|
||||
{
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if(!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
last += image.getWidth();
|
||||
}
|
||||
if (panel.getDragObject() != null)
|
||||
{
|
||||
panel.add(panel.getDragObject());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (DrawObject o : panel.getObjects())
|
||||
{
|
||||
if (o.contains(clickPoint))
|
||||
{
|
||||
if (o == selectedObject)
|
||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
{
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
boolean upperRight = o.containsCorner(clickPoint, 1);
|
||||
boolean bottomLeft = o.containsCorner(clickPoint, 2);
|
||||
boolean bottomRight = o.containsCorner(clickPoint, 3);
|
||||
boolean rotate = o.containsCorner(clickPoint, 4);
|
||||
if (upperLeft)
|
||||
{
|
||||
panel.setClickedOption("upperLeft");
|
||||
}
|
||||
else if (upperRight)
|
||||
{
|
||||
panel.setClickedOption("upperRight");
|
||||
}
|
||||
else if (bottomLeft)
|
||||
{
|
||||
panel.setClickedOption("bottomLeft");
|
||||
}
|
||||
else if (bottomRight)
|
||||
{
|
||||
panel.setClickedOption("bottomRight");
|
||||
}
|
||||
else if (rotate)
|
||||
{
|
||||
panel.setClickedOption("rotate");
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if(!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
break;
|
||||
}
|
||||
if (selectedObject != null)
|
||||
selectedObject.setSelected(false);
|
||||
o.setSelected(true);
|
||||
selectedObject = o;
|
||||
panel.setDragObject(o);
|
||||
panel.getPP().setSelected(o);
|
||||
panel.setSelectedObject(o);
|
||||
panel.setSelectionPosition(panel.getDragObject().getPosition());
|
||||
|
||||
i++;
|
||||
last += image.getWidth();
|
||||
}
|
||||
if (panel.getDragObject() != null)
|
||||
{
|
||||
panel.add(panel.getDragObject());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (DrawObject o : panel.getObjects())
|
||||
{
|
||||
if (o.contains(clickPoint))
|
||||
{
|
||||
if (o == selectedObject)
|
||||
{
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
boolean upperRight = o.containsCorner(clickPoint, 1);
|
||||
boolean bottomLeft = o.containsCorner(clickPoint, 2);
|
||||
boolean bottomRight = o.containsCorner(clickPoint, 3);
|
||||
boolean rotate = o.containsCorner(clickPoint, 4);
|
||||
if (upperLeft)
|
||||
{
|
||||
panel.setClickedOption("upperLeft");
|
||||
}
|
||||
else if (upperRight)
|
||||
{
|
||||
panel.setClickedOption("upperRight");
|
||||
}
|
||||
else if (bottomLeft)
|
||||
{
|
||||
panel.setClickedOption("bottomLeft");
|
||||
}
|
||||
else if (bottomRight)
|
||||
{
|
||||
panel.setClickedOption("bottomRight");
|
||||
}
|
||||
else if (rotate)
|
||||
{
|
||||
panel.setClickedOption("rotate");
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
}
|
||||
if (selectedObject != null)
|
||||
selectedObject.setSelected(false);
|
||||
o.setSelected(true);
|
||||
selectedObject = o;
|
||||
panel.setDragObject(o);
|
||||
panel.getPP().setSelected(o);
|
||||
panel.setSelectedObject(o);
|
||||
panel.setSelectionPosition(panel.getDragObject().getPosition());
|
||||
|
||||
}
|
||||
}
|
||||
panel.checkPath(clickPoint);
|
||||
}
|
||||
if (panel.getDragObject() == null && selectedObject != null)
|
||||
{
|
||||
selectedObject.setSelected(false);
|
||||
panel.setSelectedObject(null);
|
||||
panel.getPP().clearSelected();
|
||||
selectedObject = null;
|
||||
}
|
||||
}
|
||||
if (panel.getDragObject() == null && selectedObject != null)
|
||||
{
|
||||
selectedObject.setSelected(false);
|
||||
panel.setSelectedObject(null);
|
||||
panel.getPP().clearSelected();
|
||||
selectedObject = null;
|
||||
else { //Making path.
|
||||
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(),clickPoint.getY()));
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if(panel.getDragObject() != null) {
|
||||
|
||||
@@ -26,7 +26,6 @@ public class MouseMotion extends MouseMotionAdapter
|
||||
switch (panel.getClickedOption())
|
||||
{
|
||||
case "drag":
|
||||
boolean collision = false;
|
||||
if (panel.getDragObject() != null)
|
||||
panel.getDragObject().setPosition(new Point2D.Double((panel.getDragObject().getPosition().getX()) - ((panel.getLastClickPosition().getX() - clickPoint.getX())) / panel.getDragObject().getScale(), (panel.getDragObject().getPosition().getY()) - (panel.getLastClickPosition().getY() - clickPoint.getY()) / panel.getDragObject().getScale()));
|
||||
panel.checkCollision();
|
||||
@@ -87,14 +86,19 @@ public class MouseMotion extends MouseMotionAdapter
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.getPP().update();
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if(panel.getClickedOption().equals("Path"))
|
||||
panel.getCurrentPath().setTempPoint(panel.getClickPoint(e.getPoint()));
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
private void resizeBigger()
|
||||
{
|
||||
double scale = panel.getDragObject().getScale() + 0.05;
|
||||
|
||||
double scale = panel.getDragObject().getScale()*1 + 0.02;
|
||||
panel.getDragObject().setScale(scale);
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX(), panel.getDragObject().getPosition().getY() - 5));
|
||||
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX() -2, panel.getDragObject().getPosition().getY() - 2));
|
||||
panel.checkCollision();
|
||||
}
|
||||
|
||||
private void resizeSmaller(Point2D clickPoint)
|
||||
@@ -102,10 +106,10 @@ public class MouseMotion extends MouseMotionAdapter
|
||||
System.out.println(clickPoint.getX());
|
||||
if (panel.getDragObject().getScale() > 0.2)
|
||||
{
|
||||
double scale = panel.getDragObject().getScale() - 0.05;
|
||||
double scale = panel.getDragObject().getScale()*1 - 0.02;
|
||||
panel.getDragObject().setScale(scale);
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX() - clickPoint.getX(), panel.getDragObject().getPosition().getY() - clickPoint.getY()));
|
||||
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX() +2, panel.getDragObject().getPosition().getY() +2 ));
|
||||
panel.checkCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
|
||||
public class OldPath extends DrawObject
|
||||
{
|
||||
|
||||
public OldPath(Point2D position)
|
||||
{
|
||||
super("images/path.jpg", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Path";
|
||||
}
|
||||
|
||||
}
|
||||
+109
-13
@@ -1,21 +1,117 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.TexturePaint;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class Path extends DrawObject
|
||||
{
|
||||
/**
|
||||
* Create's a path.
|
||||
* @author Wesley de Hek
|
||||
* @version 1.2
|
||||
*/
|
||||
public class Path {
|
||||
|
||||
public Path(Point2D position)
|
||||
{
|
||||
super("images/path.jpg", position);
|
||||
private ArrayList<Point2D> points;
|
||||
private ArrayList<Shape> lines;
|
||||
private Point2D tempPoint;
|
||||
private BufferedImage pathBackground;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Path() {
|
||||
points = new ArrayList<>();
|
||||
lines = new ArrayList<>();
|
||||
try {
|
||||
pathBackground = ImageIO.read(new File("images/newPath.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Path";
|
||||
|
||||
/**
|
||||
* Draws the path.
|
||||
* @param g2 - the Graphics2D object.
|
||||
*/
|
||||
public void draw(Graphics2D g2) {
|
||||
TexturePaint paint = new TexturePaint(pathBackground,new Rectangle2D.Double(0,0,128,128));
|
||||
g2.setPaint(paint);
|
||||
g2.setStroke(new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
|
||||
if(!points.isEmpty()) {
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
Point2D point = points.get(i);
|
||||
g2.drawLine((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
}
|
||||
//Drawing line that follows the mouse:
|
||||
if(tempPoint != null) {
|
||||
Point2D lastPoint = points.get(points.size()-1);
|
||||
g2.drawLine((int) lastPoint.getX(),(int) lastPoint.getY(),(int) tempPoint.getX(),(int) tempPoint.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point.
|
||||
* @param point - the point you want to containment with.
|
||||
* @return if the path contains the point.
|
||||
*/
|
||||
public boolean containsPoint(Point2D point) {
|
||||
for(Shape line : getPath()) {
|
||||
if(line.contains(point)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array with line's from the points.
|
||||
* @return a array with all the lines of the path.
|
||||
*/
|
||||
public ArrayList<Shape> getPath() {
|
||||
lines.clear();
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
Point2D point = points.get(i);
|
||||
Line2D line = new Line2D.Double((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
BasicStroke stroke = new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
||||
lines.add(stroke.createStrokedShape(line));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the path.
|
||||
* @param point - the point you want the path to pass.
|
||||
*/
|
||||
public void addPoint(Point2D point) {
|
||||
points.add(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the path points.
|
||||
* @return all the points of the path.
|
||||
*/
|
||||
public ArrayList<Point2D> getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the temporary point, useful for following the mouse while drawing the path.
|
||||
* @param point - the point of the mouse.
|
||||
*/
|
||||
public void setTempPoint(Point2D point) {
|
||||
tempPoint = point;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user