From 0a03f7b69a882b398d5ea74cc0e5ce4a7b88bc3d Mon Sep 17 00:00:00 2001 From: drdev Date: Thu, 26 Jun 2014 01:07:25 +0000 Subject: [PATCH] Draw outline around arrow --- forge-gui-mobile/src/forge/Graphics.java | 43 ++++++++++----- .../forge/screens/match/TargetingOverlay.java | 54 +++---------------- 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/forge-gui-mobile/src/forge/Graphics.java b/forge-gui-mobile/src/forge/Graphics.java index 95dc65dd5e3..86069d2cd5a 100644 --- a/forge-gui-mobile/src/forge/Graphics.java +++ b/forge-gui-mobile/src/forge/Graphics.java @@ -136,10 +136,10 @@ public class Graphics { batch.begin(); } - public void drawArrow(float thickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) { - drawArrow(thickness, skinColor.getColor(), x1, y1, x2, y2); + public void drawArrow(float thickness, float arrowSize, FSkinColor skinColor, float x1, float y1, float x2, float y2) { + drawArrow(thickness, arrowSize, skinColor.getColor(), x1, y1, x2, y2); } - public void drawArrow(float thickness, Color color, float x1, float y1, float x2, float y2) { + public void drawArrow(float thickness, float arrowSize, Color color, float x1, float y1, float x2, float y2) { batch.end(); //must pause batch while rendering shapes if (alphaComposite < 1) { @@ -148,9 +148,23 @@ public class Graphics { Gdx.gl.glEnable(GL_BLEND); Gdx.gl.glEnable(GL_LINE_SMOOTH); - float arrowSize = 3 * thickness; float angle = new Vector2(x2 - x1, y2 - y1).angleRad(); - float rotation = (float)(Math.PI * 0.8f); + float perpRotation = (float)(Math.PI * 0.5f); + float arrowHeadRotation = (float)(Math.PI * 0.8f); + float halfThickness = thickness / 2; + + int index = 0; + float[] vertices = new float[14]; + Vector2 arrowCorner1 = new Vector2(x2 + arrowSize * (float)Math.cos(angle + arrowHeadRotation), y2 + arrowSize * (float)Math.sin(angle + arrowHeadRotation)); + Vector2 arrowCorner2 = new Vector2(x2 + arrowSize * (float)Math.cos(angle - arrowHeadRotation), y2 + arrowSize * (float)Math.sin(angle - arrowHeadRotation)); + float arrowCornerLen = (arrowCorner1.dst(arrowCorner2) - thickness) / 2; + index = addVertex(arrowCorner1.x, arrowCorner1.y, vertices, index); + index = addVertex(x2, y2, vertices, index); + index = addVertex(arrowCorner2.x, arrowCorner2.y, vertices, index); + index = addVertex(arrowCorner2.x + arrowCornerLen * (float)Math.cos(angle + perpRotation), arrowCorner2.y + arrowCornerLen * (float)Math.sin(angle + perpRotation), vertices, index); + index = addVertex(x1 + halfThickness * (float)Math.cos(angle - perpRotation), y1 + halfThickness * (float)Math.sin(angle - perpRotation), vertices, index); + index = addVertex(x1 + halfThickness * (float)Math.cos(angle + perpRotation), y1 + halfThickness * (float)Math.sin(angle + perpRotation), vertices, index); + index = addVertex(arrowCorner1.x + arrowCornerLen * (float)Math.cos(angle - perpRotation), arrowCorner1.y + arrowCornerLen * (float)Math.sin(angle - perpRotation), vertices, index); //draw arrow tail startShape(ShapeType.Filled); @@ -160,17 +174,14 @@ public class Graphics { adjustY(y2 - arrowSize * (float)Math.sin(angle) / 2, 0), thickness); //draw arrow head - shapeRenderer.triangle(adjustX(x2), adjustY(y2, 0), - adjustX(x2 + arrowSize * (float)Math.cos(angle + rotation)), - adjustY(y2 + arrowSize * (float)Math.sin(angle + rotation), 0), - adjustX(x2 + arrowSize * (float)Math.cos(angle - rotation)), - adjustY(y2 + arrowSize * (float)Math.sin(angle - rotation), 0)); + shapeRenderer.triangle(vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5]); endShape(); - /*startShape(ShapeType.Line); + //draw border around arrow + startShape(ShapeType.Line); shapeRenderer.setColor(Color.BLACK); - shapeRenderer.rectLine(adjustX(x1), adjustY(y1, 0), adjustX(x2), adjustY(y2, 0), thickness); - endShape();*/ + shapeRenderer.polygon(vertices); + endShape(); Gdx.gl.glDisable(GL_LINE_SMOOTH); Gdx.gl.glDisable(GL_BLEND); @@ -178,6 +189,12 @@ public class Graphics { batch.begin(); } + private int addVertex(float x, float y, float[] vertices, int index) { + vertices[index] = adjustX(x); + vertices[index + 1] = adjustY(y, 0); + return index + 2; + } + public void drawRoundRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h, float cornerRadius) { drawRoundRect(thickness, skinColor.getColor(), x, y, w, h, cornerRadius); } diff --git a/forge-gui-mobile/src/forge/screens/match/TargetingOverlay.java b/forge-gui-mobile/src/forge/screens/match/TargetingOverlay.java index 01ea03fa71a..f4611d1be6d 100644 --- a/forge-gui-mobile/src/forge/screens/match/TargetingOverlay.java +++ b/forge-gui-mobile/src/forge/screens/match/TargetingOverlay.java @@ -25,6 +25,7 @@ import forge.game.combat.Combat; import forge.screens.match.views.VCardDisplayArea.CardAreaPanel; import forge.screens.match.views.VPlayerPanel; import forge.toolbox.FCardPanel; +import forge.util.Utils; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; @@ -35,6 +36,9 @@ import java.util.List; import java.util.Map; public class TargetingOverlay { + private static final float ARROW_THICKNESS = Utils.scaleMax(5); + private static final float ARROW_SIZE = 3 * ARROW_THICKNESS; + private final List cardPanels = new ArrayList(); private final List arcsCombat = new ArrayList(); private final List arcsOther = new ArrayList(); @@ -183,57 +187,11 @@ public class TargetingOverlay { return cardsVisualized; } - /*private Area getArrow(float length, float bendPercent) { - float p1x = 0, p1y = 0; - float p2x = length, p2y = 0; - float cx = length / 2, cy = length / 8f * bendPercent; - - int bodyWidth = 15; - float headSize = 20; - - float adjSize, ex, ey, abs_e; - adjSize = (float) (bodyWidth / 2 / Math.sqrt(2)); - ex = p2x - cx; - ey = p2y - cy; - abs_e = (float) Math.sqrt(ex * ex + ey * ey); - ex /= abs_e; - ey /= abs_e; - GeneralPath bodyPath = new GeneralPath(); - bodyPath.moveTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize); - bodyPath.quadTo(cx, cy, p1x, p1y - bodyWidth / 2); - bodyPath.lineTo(p1x, p1y + bodyWidth / 2); - bodyPath.quadTo(cx, cy, p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize); - bodyPath.closePath(); - - adjSize = (float) (headSize / Math.sqrt(2)); - ex = p2x - cx; - ey = p2y - cy; - abs_e = (float) Math.sqrt(ex * ex + ey * ey); - ex /= abs_e; - ey /= abs_e; - GeneralPath headPath = new GeneralPath(); - headPath.moveTo(p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize); - headPath.lineTo(p2x + headSize / 2, p2y); - headPath.lineTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize); - headPath.closePath(); - - Area area = new Area(headPath); - area.add(new Area(bodyPath)); - return area; - }*/ - public void drawArcs(Graphics g, FSkinColor color, List arcs) { for (Vector2[] p : arcs) { - if (p[0] == null || p[1] == null) { - continue; + if (p[0] != null && p[1] != null) { + g.drawArrow(ARROW_THICKNESS, ARROW_SIZE, color, p[1].x, p[1].y, p[0].x, p[0].y); } - - float endX = p[0].x; - float endY = p[0].y; - float startX = p[1].x; - float startY = p[1].y; - - g.drawArrow(5, color, startX, startY, endX, endY); } }