!7 concept Grab { new Ref screenshot; Pt point; new L sizes; } p-substance-thread { db(); awt { showControls(jCenteredLine( jbutton("Grab", "grab"), jbutton("Find", rThread("find")))); } } svoid grab { trackOneClick(voidfunc(final Point p) { thread { sleep(500); // allow screen behind red dot to be repainted Grab grab = cnew(Grab, screenshot := new PNGFile(shootScreenBufferedImage()), point := new Pt(p) ); infoBox("Grabbed! " + grab.id); } }); } svoid find { float ppt = 0.1f; // per pixel tolerance RGBImage imgB = rgbShootScreen(); int w = imgB.w(), h = imgB.h(); for (Grab grab) { print ("Searching " + grab.id + " (todo)..."); RGBImage imgA = new RGBImage(grab.screenshot->getImage()); Pt p = grab.point; int col = imgA.getInt(p.x, p.y); new HashSet matches; for y to h: for x to w: if (rgbDiff(col, imgB.getInt(x, y)) <= ppt) { Rect r1 = new Rect(p.x, p.y, 1, 1); Rect r2 = new Rect(x, y, 1, 1); Rect r = translateRect(rgbExpandMatch(imgA, imgB, r1, r2, ppt), -p.x, -p.y); matches.add(r); } print(n(matches, "matches") + ": " + struct(matches)); } }