private static Region asRegion(Rectangle r) { if (r != null) { return Region.create(r); } else { return null; } }
/** * Create a region from a Rectangle on a given Screen * * @param r the Rectangle * @param parentScreen the new parent screen * @return the new region */ protected static Region create(Rectangle r, IScreen parentScreen) { return Region.create(r.x, r.y, r.width, r.height, parentScreen); }
/** * create a region with a corner at this point<br>as specified with x y<br> 0 0 top left<br> * 0 1 bottom left<br> 1 0 top right<br> 1 1 bottom right<br> * * @param CREATE_X_DIRECTION == 0 is left side !=0 is right side, see {@link Region#CREATE_X_DIRECTION_LEFT}, {@link Region#CREATE_X_DIRECTION_RIGHT} * @param CREATE_Y_DIRECTION == 0 is top side !=0 is bottom side, see {@link Region#CREATE_Y_DIRECTION_TOP}, {@link Region#CREATE_Y_DIRECTION_BOTTOM} * @param w the width * @param h the height * @return the new region */ public Region grow(int CREATE_X_DIRECTION, int CREATE_Y_DIRECTION, int w, int h) { return Region.create(this, CREATE_X_DIRECTION, CREATE_Y_DIRECTION, w, h); }
/** * Create a region with the provided top left corner and size * * @param X top left X position * @param Y top left Y position * @param W width * @param H heigth * @return then new region */ public static Region create(int X, int Y, int W, int H) { return Region.create(X, Y, W, H, null); }
/** * Create a region from a Rectangle * * @param r the Rectangle * @return the new region */ public static Region create(Rectangle r) { return Region.create(r.x, r.y, r.width, r.height, null); }
/** * create region with same size at top left corner offset * * @param loc use its x and y to set the offset * @return the new region */ public Region offset(Location loc) { return Region.create(x + loc.x, y + loc.y, w, h, scr); }
/** * create region with same size at top left corner offset * * @param x horizontal offset * @param y vertical offset * @return the new region */ public Region offset(int x, int y) { return Region.create(this.x + x, this.y + y, w, h, scr); }
/** * create a region enlarged l pixels on left and r pixels right side and t pixels at top side and b pixels a bottom * side. negative values go inside (shrink) * * @param l add to the left * @param r add to right * @param t add above * @param b add beneath * @return the new region */ public Region grow(int l, int r, int t, int b) { return Region.create(x - l, y - t, w + l + r, h + t + b, scr); }
/** * Read text from screen rectangle basing on the glyphs data. * * @param rectangle rectangle object with the coordinates * @return Recognized text as String */ public String read(Rectangle rectangle) { return this.read(Region.create(rectangle)); }
public Region newRegion(int x, int y, int w, int h) { Region reg = Region.create(x, y, w, h); reg.setOtherScreen(this); return reg; }
public Region getRegion() { return Region.create(getBounds()); }
/** * 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; }
/** * creates a region on the current screen with the given coordinate/size. The coordinate is * translated to the current screen from its relative position on the screen it would have been * created normally. * * @param loc Location * @param width value * @param height value * @return the new region */ public Region newRegion(Location loc, int width, int height) { return Region.create(loc.copyTo(this), width, height); }
private void init(Region region) { if (region != null) { targetRegion = region; } else { Debug.log(2, "SikuliGuideRectangle: targetRegion is given as null"); targetRegion = Region.create(0, 0, 2*stroke, 2*stroke); } setColor(Color.RED); }
private void init(Region region) { if (region != null) { targetRegion = region; } else { Debug.log(2, "SikuliGuideRectangle: targetRegion is given as null"); targetRegion = Region.create(0, 0, 2*stroke, 2*stroke); } setColor(Color.RED); }
/** * create a region enlarged w pixels on left and right side and h pixels at top and bottom * * @param w pixels horizontally * @param h pixels vertically * @return the new region */ public Region grow(int w, int h) { Rectangle r = getRect(); r.grow(w, h); return Region.create(r.x, r.y, r.width, r.height, scr); }
@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; }
/** * 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); }
/** * create a new region containing both regions * * @param ur region to unite with * @return the new region */ public Region union(Region ur) { Rectangle r = getRect().union(ur.getRect()); return Region.create(r.x, r.y, r.width, r.height, scr); }
/** * new region with same offset to current screen's top left on given screen * * @param screen new parent screen * @return new region */ public Region copyTo(IScreen screen) { Location o = new Location(getScreen().getBounds().getLocation()); Location n = new Location(screen.getBounds().getLocation()); return Region.create(n.x + x - o.x, n.y + y - o.y, w, h, screen); }