return rect; Region r = Region.create(rect); int pTyp = (int) (part / 100); int pPos = part - pTyp * 100; int pRow = (int) (pPos / 10); int pCol = pPos - pRow * 10; r.setRaster(pTyp, pTyp); if (pTyp == 3) { return r.getCell(pRow, pCol).getRect(); return r.getCol(pCol).getRect(); } else if (pCol > 1) { return r.getRow(pRow).getRect(); return r.getCell(pRow, pCol).getRect(); return r.getCell(1, 1).union(r.getCell(2, 2)).getRect(); return r.getCell(0, 1).union(r.getCell(3, 2)).getRect(); } else if (pCol > 3) { return r.getCell(1, 0).union(r.getCell(2, 3)).getRect(); return r.getCell(pRow, pCol).getRect();
/** * divide the region in n columns and select column c as new Region * * @param c the column to select counting from 0 or negative to count from the end * @param n how many columns to devide in * @return the selected part or the region itself, if parameters are invalid */ public Region getCol(int c, int n) { Region r = new Region(this); r.setCols(n); return r.getCol(c); }
/** * create a region above the top side with same width<br> the new region extends to the top screen border<br> use * grow() to include the current region * * @return the new region */ public Region above() { int distToAboveScreenBorder = getY() - getScreen().getY(); return above(distToAboveScreenBorder); }
public Region newRegion(int x, int y, int w, int h) { Region reg = Region.create(x, y, w, h); reg.setOtherScreen(this); return reg; }
/** * left click at the region's last successful match <br>use center if no lastMatch <br>if region is a match: click * targetOffset * * @return 1 if possible, 0 otherwise */ public int click() { try { // needed to cut throw chain for FindFailed return click(checkMatch(), 0); } catch (FindFailed ex) { return 0; } }
private static Region asRegion(Rectangle r) { if (r != null) { return Region.create(r); } else { return null; } }
private boolean checkPatterns(ScreenImage simg) { log(lvl + 1, "update: checking patterns"); if (!observedRegion.isObserving()) { return false; long now = 0; if (!Settings.UseImageFinder && Settings.CheckLastSeen && null != img.getLastSeen()) { Region r = Region.create(img.getLastSeen()); if (observedRegion.contains(r)) { lastSearchTime = (new Date()).getTime(); Finder f = new Finder(new Screen().capture(r), r); if (f.hasNext()) { log(lvl + 1, "checkLastSeen: still there"); match = new Match(new Region(img.getLastSeen()), img.getLastSeenScore()); match.setTimes(0, (new Date()).getTime() - lastSearchTime); hasMatch = true; eventMatches.put(name, match); log(lvl + 1, "(%s): %s match: %s in:%s", eventTypes.get(name), ptn.toString(), match.toStringShort(), observedRegion.toStringShort()); } else if (eventStates.get(ptn) == State.FIRST) { log(lvl + 1, "(%s): %s match: %s in:%s", eventTypes.get(name), ptn.toString(), match.toStringShort(), observedRegion.toStringShort()); eventStates.put(name, State.UNKNOWN); callEventObserver(name, eventMatches.get(name), now); if (shouldStopOnFirstEvent) { observedRegion.stopObserver();
private Finder doCheckLastSeenAndCreateFinder(ScreenImage base, Image img, double findTimeout, Pattern ptn) { if (base == null) { base = getScreen().capture(this); Region r = Region.create(img.getLastSeen()); if (this.contains(r)) { Finder f = new Finder(base.getSub(r.getRect()), r); if (Debug.shouldHighlight()) { if (this.scr.getW() > w + 10 && this.scr.getH() > h + 10) { highlight(2, "#000255000"); log(lvl, "checkLastSeen: still there"); return f; log(lvl, "checkLastSeen: not there");
/** * @return the center pixel location of the region */ public Location getCenter() { return checkAndSetRemote(new Location(getX() + getW() / 2, getY() + getH() / 2)); }
/** * Create a region from another region<br>including the region's settings * * @param r the region * @return then new region */ public static Region create(Region r) { Region reg = Region.create(r.x, r.y, r.w, r.h, r.getScreen()); reg.autoWaitTimeout = r.autoWaitTimeout; reg.findFailedResponse = r.findFailedResponse; reg.throwException = r.throwException; return reg; }
public Region get(int part) { return Region.create(getRectangle(getRect(), part)); }
/** * create a region below the bottom side with same width<br> the new region extends to the bottom screen border<br> * use grow() to include the current region * * @return the new region */ public Region below() { int distToBelowScreenBorder = getScreen().getY() + getScreen().getH() - (getY() + getH()); return below(distToBelowScreenBorder); }
/** * create a region that is the intersection of the given regions * * @param ir the region to intersect with like AWT Rectangle API * @return the new region */ public Region intersection(Region ir) { Rectangle r = getRect().intersection(ir.getRect()); return Region.create(r.x, r.y, r.width, r.height, scr); }
simg = getScreen().capture(this); f = repeating._finder; f.setScreenImage(simg); f.findRepeat(); } else { s = getScreen(); lastFindTime = (new Date()).getTime(); if (ptn instanceof String) { if (img.isValid()) { lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, null); if (!f.hasNext()) { runFinder(f, img); log(lvl, "doFind: Switching to TextSearch"); if (TextRecognizer.getInstance() != null) { f = new Finder(getScreen().capture(x, y, w, h), this); lastSearchTime = (new Date()).getTime(); f.findText(someText); if (img.isValid()) { lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, (Pattern) ptn); if (!f.hasNext()) { runFinder(f, ptn); if (img.isValid()) {
@Override public Visual setScale(float scale) { this.scale = scale; if (scale == 0) { int x = (int) (getTarget().getCenter().x - image.getWidth()/2); int y = (int) (getTarget().getCenter().y - image.getHeight()/2); setTarget(Region.create(x, y, image.getWidth(), image.getHeight())); } else { w = (int) (scale * image.getWidth()); h = (int) (scale * image.getHeight()); } return this; }
/** * * @return the Region, the iamge was created from */ public Region getRegion() { return new Region(_roi); }
/** * @return bottom right corner Location */ public Location getBottomRight() { return checkAndSetRemote(new Location(x + w - 1, y + h - 1)); }
/** * A function only for backward compatibility - Only makes sense with Screen objects * * @return the Region being the current ROI of the containing Screen */ public Region getROI() { IScreen screen = getScreen(); Rectangle screenRect = screen.getRect(); return new Region(screenRect.x, screenRect.y, screenRect.width, screenRect.height, screen); }
/** * double click at the region's last successful match <br>use center if no lastMatch <br>if region is a match: click * targetOffset * * @return 1 if possible, 0 otherwise */ public int doubleClick() { try { // needed to cut throw chain for FindFailed return doubleClick(checkMatch(), 0); } catch (FindFailed ex) { return 0; } }