/** * One more constructor */ public StraightArrowPolygon(Point startPoint, Point endPoint, int width, boolean halved) { super(); this.startPoint = startPoint; this.endPoint = endPoint; this.headWidth = width + 2; this.arrowWidthAtHead = width; this.tailWidth = width; this.halved = halved; buildPointsArrays(); }
/** * Return true if the point is inside our polygon */ @Override public boolean isInside(Point point) { return attackPoly.contains(point.x - bounds.x, point.y - bounds.y); }
/** * If we have build full arrow already with single attack and have got * counter attack from our target lately - lets change arrow to halved. */ public void rebuildToHalvedPolygon() { attackPoly = new StraightArrowPolygon(a, t, (int) (8 * this.boardView1.scale), (int) (12 * this.boardView1.scale), true); // set bounds bounds = new Rectangle(attackPoly.getBounds()); bounds.setSize(bounds.getSize().width + 1, bounds.getSize().height + 1); // move poly to upper right of image attackPoly.translate(-bounds.getLocation().x, -bounds.getLocation().y); }
@Override public Rectangle getBounds() { makePoly(); // set bounds bounds = new Rectangle(attackPoly.getBounds()); bounds.setSize(bounds.getSize().width + 1, bounds.getSize().height + 1); // move poly to upper right of image attackPoly.translate(-bounds.getLocation().x, -bounds.getLocation().y); return bounds; }
private void makePoly() { // make a polygon a = bv.getHexLocation(start); t = bv.getHexLocation(end); // OK, that is actually not good. I do not like hard coded figures. // HEX_W/2 - x distance in pixels from origin of hex bounding box to // the center of hex. // HEX_H/2 - y distance in pixels from origin of hex bounding box to // the center of hex. // 18 - is actually 36/2 - we do not want arrows to start and end // directly // in the centes of hex and hiding mek under. a.x = a.x + (int) ((BoardView1.HEX_W / 2) * bv.scale) + (int) Math.round(Math.cos(an) * (int) (18 * bv.scale)); t.x = (t.x + (int) ((BoardView1.HEX_W / 2) * bv.scale)) - (int) Math.round(Math.cos(an) * (int) (18 * bv.scale)); a.y = a.y + (int) ((BoardView1.HEX_H / 2) * bv.scale) + (int) Math.round(Math.sin(an) * (int) (18 * bv.scale)); t.y = (t.y + (int) ((BoardView1.HEX_H / 2) * this.bv.scale)) - (int) Math.round(Math.sin(an) * (int) (18 * bv.scale)); movePoly = new StraightArrowPolygon(a, t, (int) (4 * bv.scale), (int) (8 * bv.scale), false); }
double sin = dY / arrowLength; double cos = dX / arrowLength; this.addPoint(startPoint.x, startPoint.y); this.addPoint((int) Math.round(startPoint.x + tailWidth * sin - tailLength * cos), (int) Math.round(startPoint.y - tailWidth this.addPoint((int) Math.round(endPoint.x - headLength * cos + arrowWidthAtHead * sin), (int) Math.round(endPoint.y - headLength * sin - arrowWidthAtHead * cos)); this.addPoint((int) Math.round(endPoint.x - headLength * cos + headWidth * sin), (int) Math.round(endPoint.y - headLength this.addPoint(endPoint.x, endPoint.y); if (!halved) { this.addPoint((int) Math.round(endPoint.x - headLength * cos - headWidth * sin), (int) Math.round(endPoint.y - headLength * sin + headWidth * cos)); this.addPoint((int) Math.round(endPoint.x - headLength * cos - arrowWidthAtHead * sin), (int) Math.round(endPoint.y - headLength * sin + arrowWidthAtHead * cos)); this.addPoint((int) Math.round(startPoint.x - tailWidth * sin - tailLength * cos), (int) Math.round(startPoint.y + tailWidth * cos - tailLength * sin));
@Override public Rectangle getBounds() { makePoly(); // set bounds bounds = new Rectangle(movePoly.getBounds()); bounds.setSize(bounds.getSize().width + 1, bounds.getSize().height + 1); // move poly to upper right of image movePoly.translate(-bounds.getLocation().x, -bounds.getLocation().y); return bounds; }
attackPoly = new StraightArrowPolygon(a, t, (int) (8 * this.boardView1.scale), (int) (12 * this.boardView1.scale), true); } else { attackPoly = new StraightArrowPolygon(a, t, (int) (4 * this.boardView1.scale), (int) (8 * this.boardView1.scale), false);
/** * Short constructor. Two points and boolean value. */ public StraightArrowPolygon(Point startPoint, Point endPoint, boolean halved) { super(); this.startPoint = startPoint; this.endPoint = endPoint; this.halved = halved; buildPointsArrays(); }
/** * Return true if the point is inside our polygon */ @Override public boolean isInside(Point point) { return movePoly.contains(point.x - bounds.x, point.y - bounds.y); }
/** * I know, it is annoying, but another constructor */ public StraightArrowPolygon(Point startPoint, Point endPoint, int width, int headWidth, boolean halved) { super(); this.startPoint = startPoint; this.endPoint = endPoint; this.headWidth = headWidth; this.arrowWidthAtHead = width; this.tailWidth = width; this.halved = halved; buildPointsArrays(); }
/** * Most extencive constructor with all paremeters given */ public StraightArrowPolygon(Point startPoint, Point endPoint, int headLength, int headWidth, int arrowWidthAtHead, int tailWidth, int tailLength, boolean halved) { super(); this.startPoint = startPoint; this.endPoint = endPoint; this.headLength = headLength; this.headWidth = headWidth; this.arrowWidthAtHead = arrowWidthAtHead; this.tailWidth = tailWidth; this.halved = halved; buildPointsArrays(); }