Skip to content

Commit

Permalink
Improve behavior of click/drag near margin of winrate graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed May 25, 2018
1 parent 7bc86f7 commit 9f84e48
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/wagner/stephanie/lizzie/gui/WinrateGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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 = ...
Expand Down

0 comments on commit 9f84e48

Please sign in to comment.