diff --git a/src/main/java/wagner/stephanie/lizzie/gui/WinrateGraph.java b/src/main/java/wagner/stephanie/lizzie/gui/WinrateGraph.java index 72b6b9675..9d0e0e398 100644 --- a/src/main/java/wagner/stephanie/lizzie/gui/WinrateGraph.java +++ b/src/main/java/wagner/stephanie/lizzie/gui/WinrateGraph.java @@ -11,6 +11,7 @@ public class WinrateGraph { private int DOT_RADIUS = 6; + private int[] origParams = {0, 0, 0, 0}; private int[] params = {0, 0, 0, 0, 0}; public void draw(Graphics2D g, int posx, int posy, int width, int height) @@ -35,6 +36,12 @@ public void draw(Graphics2D g, int posx, int posy, int width, int height) g.setPaint(original); + // record parameters (before resizing) for calculating moveNumber + origParams[0] = posx; + origParams[1] = posy; + origParams[2] = width; + origParams[3] = height; + // resize the box now so it's inside the border posx += 2*strokeRadius; posy += 2*strokeRadius; @@ -197,12 +204,17 @@ private double convertWinrate(double winrate) { public int moveNumber(int x, int y) { + int origPosx = origParams[0]; + int origPosy = origParams[1]; + int origWidth = origParams[2]; + int origHeight = origParams[3]; int posx = params[0]; int posy = params[1]; int width = params[2]; int height = params[3]; int numMoves = params[4]; - if (posx <= x && x < posx + width && posy <= y && y < posy + height) { + if (origPosx <= x && x < origPosx + origWidth && + origPosy <= y && y < origPosy + origHeight) { // x == posx + (movenum * width / numMoves) ==> movenum = ... int movenum = Math.round((x - posx) * numMoves / (float) width); // movenum == moveNumber - 1 ==> moveNumber = ...