Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve behavior of click/drag near margin of winrate graph #245

Merged
merged 1 commit into from
May 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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