Arbol de plugins y clases nuevas
[DND.git] / DNDCore / CanvasLine.java
blob6c5f0d7eecfa3fe00c97f942eaee01d7d1956c6d
1 package DNDCore;
2 import java.awt.Color;
3 import java.awt.Graphics2D;
4 import java.awt.Point;
7 public class CanvasLine extends CanvasObject implements Cloneable {
9 private Point end;
10 public final int NEAR = 6;
11 private Color color;
13 public CanvasLine(Point start, Point end)
15 super(start);
16 this.end = end;
17 color = Color.BLACK;
20 public void setEnd(Point end)
22 this.end = end;
25 public Point getStart()
27 return getPosition();
30 public Point getEffectiveEnd()
32 Point effectiveEnd = new Point(0, 0);
34 effectiveEnd.x = end.x + getTranslatory().x;
35 effectiveEnd.y = end.y + getTranslatory().y;
37 return effectiveEnd;
40 public Point getEnd()
42 return end;
45 public void setColor(Color color)
47 this.color = color;
50 public Color getColor()
52 return color;
55 public void setTipo(int i) {
56 throw new UnsupportedOperationException("Not yet implemented");
59 public void setWidth(float parseFloat) {
60 throw new UnsupportedOperationException("Not yet implemented");
63 void draw(Graphics2D engine)
65 engine.setPaint(color);
66 engine.drawLine(getEffectivePosition().x, getEffectivePosition().y, getEffectiveEnd().x, getEffectiveEnd().y);
69 public boolean contains(Point position)
71 Point p[] = new Point[2];
72 p[0] = getEffectivePosition();
73 p[1] = getEffectiveEnd();
75 int denom = p[1].x - p[0].x;
76 int iMinorX = p[0].x < p[1].x ? 0 : 1;
77 int iMinorY = p[0].y < p[1].y ? 0 : 1;
78 int iMajorX = 1 - iMinorX;
79 int iMajorY = 1 - iMinorY;
81 if(denom == 0) {
82 if(Math.abs(position.x - p[0].x) <= NEAR && position.y >= p[iMinorY].y && position.y <= p[iMajorY].y)
83 return true;
84 return false;
85 } else // <diabolic>ha ha ha ha ha</diabolic>
86 if(position.x >= p[iMinorX].x && position.x <= p[iMajorX].x) {
87 int num = p[1].y - p[0].y;
88 float m = ((float)num)/denom;
89 float y = m*position.x - m*p[0].x + p[0].y;
90 if(Math.abs(y - position.y) <= NEAR)
91 return true;
93 return false;
97 public int getWidth()
99 // No son necesarios
100 return 0;
103 public int getHeight()
105 // No son necesarios
106 return 0;
108 @Override
109 public Object clone() throws CloneNotSupportedException
111 CanvasLine cl = (CanvasLine) super.clone();
112 cl.setEnd(new Point(end.x, end.y));
114 return cl;