diff --git a/bin/Mouse.class b/bin/Mouse.class index 311d540..9d34f3d 100644 Binary files a/bin/Mouse.class and b/bin/Mouse.class differ diff --git a/bin/MousePathTest.class b/bin/MousePathTest.class index 0688a53..774b446 100644 Binary files a/bin/MousePathTest.class and b/bin/MousePathTest.class differ diff --git a/bin/MouseTest.class b/bin/MouseTest.class index 5bc627e..52119cc 100644 Binary files a/bin/MouseTest.class and b/bin/MouseTest.class differ diff --git a/bin/main.class b/bin/main.class index cef3839..85220e1 100644 Binary files a/bin/main.class and b/bin/main.class differ diff --git a/src/Mouse.java b/src/Mouse.java index 43283ce..9d844ad 100644 --- a/src/Mouse.java +++ b/src/Mouse.java @@ -13,14 +13,29 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Mouse { - private HashMap> gridMap; + private ArrayList>> grid; + int granularity; //private ArrayList mousePaths; + private int windowWidth; + private int windowHeight; PointerInfo pointer; - public Mouse(String path) { + public Mouse(String path, int windowWidth, int windowHeight) { + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + granularity = 10; // TODO: Is there another way to get the pointer location?? pointer = MouseInfo.getPointerInfo(); - gridMap = new HashMap>(); + + grid = new ArrayList>>(); + for (int i = 0; i < 2 * (windowWidth / granularity) + 1; i++) { + grid.add(new ArrayList>()); + for (int j = 0; j < 2 * (windowHeight / granularity) + 1; j++) { + grid.get(i).add(new ArrayList()); + } + } + + System.out.println("Grid size: " + grid.size() + "x" + grid.get(0).size()); ArrayList mousePaths = readFile(path); assignPathsToGrid(mousePaths); } @@ -29,7 +44,7 @@ public class Mouse { int[] mouseLoc = getMouseLocation(); int deltaX = endingX - mouseLoc[0]; int deltaY = endingY - mouseLoc[1]; - Integer[] gridKey = getGridMapKey(deltaX, deltaY); + int[] gridIndex = getGridIndex(deltaX, deltaY); // Fetch from map } @@ -44,36 +59,23 @@ public class Mouse { } - public Integer[] getGridMapKey(int deltaX, int deltaY) { - Integer[] gridKey = {deltaX / 100, deltaY / 100}; - return gridKey; + public int[] getGridIndex(int deltaX, int deltaY) { + int offsetX = windowWidth / granularity; + int offsetY = windowHeight / granularity; + int[] gridIndex = {deltaX / granularity + offsetX, deltaY / granularity + offsetY}; + return gridIndex; } public void assignPathsToGrid(ArrayList mousePaths) { - Integer[] key1 = getGridMapKey(0, 0); - Integer[] key2 = getGridMapKey(0, 0); - gridMap.put(key1, new ArrayList()); - if (gridMap.containsKey(key2)) { - System.out.println("same key!"); - } - if (gridMap.containsKey(key1)) { - System.out.println("Same key2!"); - } - /*for (MousePath mousePath : mousePaths) { + for (MousePath mousePath : mousePaths) { int deltaX = mousePath.getDeltaX(); int deltaY = mousePath.getDeltaY(); - Integer[] gridKey = getGridMapKey(deltaX, deltaY); - - if (gridMap.containsKey(gridKey)) { - System.out.println("Same category!"); - gridMap.get(gridKey).add(mousePath); - } - else { - ArrayList newPath = new ArrayList(); - newPath.add(mousePath); - gridMap.put(gridKey, newPath); - } - }*/ + + int[] gridIndex = getGridIndex(deltaX, deltaY); + //System.out.println(deltaX + "," + deltaY); + //System.out.println("index: " + gridIndex[0] + "," + gridIndex[1]); + grid.get(gridIndex[0]).get(gridIndex[1]).add(mousePath); + } } public ArrayList readFile(String path) { @@ -140,18 +142,13 @@ public class Mouse { public void displayPaths() { - System.out.println("Displaying paths in HashMap..."); - for (HashMap.Entry> entry : gridMap.entrySet()) { - Integer[] gridKey = entry.getKey(); - System.out.println("Key is: (" + gridKey[0] + ", " + gridKey[1] + ")"); - - ArrayList mousePaths = entry.getValue(); - System.out.println("There are " + mousePaths.size() + " paths with these deltas."); - for (MousePath path : mousePaths) { - //path.display(); - System.out.println("----------------------------------------------------------"); + for (int i = 0; i < 2 * (windowWidth / granularity) + 1; i++) { + for (int j = 0; j < 2 * (windowHeight / granularity) + 1; j++) { + if (grid.get(i).get(j).size() > 0) { + System.out.println("(" + i + "," + j + ")"); + System.out.println("There are " + grid.get(i).get(j).size() + " paths in this delta range."); + } } - System.out.println("Size of HashMap: " + gridMap.size()); } } } \ No newline at end of file diff --git a/src/main.java b/src/main.java index f6c30e8..62aefc3 100644 --- a/src/main.java +++ b/src/main.java @@ -7,7 +7,7 @@ public class main { System.out.println("Starting mouse script..."); System.out.println("Fetching mouse paths from script..."); - Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt"); + Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt", 1920, 1080); mouse.displayPaths(); System.out.println("Finished..."); }