Class RegionBuilder
java.lang.Object
io.github.jspinak.brobot.model.element.RegionBuilder
Builder for creating Region objects with screen-size awareness and flexible adjustments.
This builder provides multiple ways to define regions:
- Absolute coordinates and dimensions
- Percentage-based positioning relative to screen size
- Anchor-based positioning (center, corners, edges)
- Adjustments to existing regions
- Screen-relative sizing with aspect ratio preservation
Example usage:
// Create a region in the center of the screen, 50% of screen size
Region centerRegion = new RegionBuilder()
.withScreenPercentage(0.5, 0.5)
.centerOnScreen()
.build();
// Create a region with specific coordinates
Region searchArea = new RegionBuilder()
.x(100).y(100)
.width(200).height(150)
.build();
// Create a region with adjustments
Region expanded = new RegionBuilder()
.fromRegion(existingRegion)
.adjustX(10)
.adjustY(-5)
.adjustWidth(20)
.adjustHeight(20)
.build();
- Since:
- 1.2.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RegionBuilder with current screen dimensions detected. -
Method Summary
Modifier and TypeMethodDescriptionadjustBy
(int x, int y, int width, int height) Adds adjustments to all dimensions.adjustHeight
(int adjustment) Adds an adjustment to the height.adjustWidth
(int adjustment) Adds an adjustment to the width.adjustX
(int adjustment) Adds an adjustment to the x-coordinate.adjustY
(int adjustment) Adds an adjustment to the y-coordinate.Positions the region at the bottom-center of the screen.Creates a region for the bottom half of the screen.Positions the region at the bottom-left of the screen.Positions the region at the bottom-right of the screen.build()
Builds the Region with all specified parameters.Centers the region on the screen.constrainToScreen
(boolean constrain) Ensures the region stays within screen bounds.expand
(int pixels) Expands or contracts the region by the specified amount on all sides.fromRegion
(Region region) Creates a builder from an existing region.Creates a region covering the full screen.Positions the region at the left-center of the screen.leftHalf()
Creates a region for the left half of the screen.maintainAspectRatio
(boolean maintain) Maintains the aspect ratio when resizing.positionRelativeTo
(Region referenceRegion, Position position) Positions this region relative to another region using a Position.positionRelativeTo
(Region referenceRegion, Positions.Name positionName) Positions this region relative to another region using a named position.Positions the region at the right-center of the screen.Creates a region for the right half of the screen.Positions the region at the top-center of the screen.topHalf()
Creates a region for the top half of the screen.topLeft()
Positions the region at the top-left of the screen.topRight()
Positions the region at the top-right of the screen.withAnchor
(Position position) Sets the anchor point using a custom Position.withAnchor
(Positions.Name anchorName) Sets the anchor point using Positions.Name enum.withHeight
(int height) Sets the height directly.withPosition
(int x, int y) Sets the position using absolute coordinates.withPosition
(Position position) Creates a region at a specific position within the screen using Position percentages.withPosition
(Positions.Name positionName) Creates a region at a named position on the screen.withRegion
(int x, int y, int width, int height) Sets the base region using absolute coordinates.withScreenPercentage
(double widthPercent, double heightPercent) Convenience method to set size using screen percentage.withScreenPercentage
(double xPercent, double yPercent, double widthPercent, double heightPercent) Sets both position and size using screen percentages.withScreenPercentagePosition
(double xPercent, double yPercent) Sets the position using screen percentage (0.0 to 1.0).withScreenPercentageSize
(double widthPercent, double heightPercent) Sets the size using screen percentage (0.0 to 1.0).withSize
(int width, int height) Sets the size using absolute dimensions.withWidth
(int width) Sets the width directly.
-
Constructor Details
-
RegionBuilder
public RegionBuilder()Creates a new RegionBuilder with current screen dimensions detected.
-
-
Method Details
-
withRegion
Sets the base region using absolute coordinates.- Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the height- Returns:
- this builder
-
fromRegion
Creates a builder from an existing region.- Parameters:
region
- the source region- Returns:
- this builder
-
withPosition
Sets the position using absolute coordinates.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- this builder
-
withSize
Sets the size using absolute dimensions.- Parameters:
width
- the widthheight
- the height- Returns:
- this builder
-
withWidth
Sets the width directly.- Parameters:
width
- the width- Returns:
- this builder
-
withHeight
Sets the height directly.- Parameters:
height
- the height- Returns:
- this builder
-
withScreenPercentagePosition
Sets the position using screen percentage (0.0 to 1.0).- Parameters:
xPercent
- x position as percentage of screen widthyPercent
- y position as percentage of screen height- Returns:
- this builder
-
withScreenPercentageSize
Sets the size using screen percentage (0.0 to 1.0).- Parameters:
widthPercent
- width as percentage of screen widthheightPercent
- height as percentage of screen height- Returns:
- this builder
-
withScreenPercentage
public RegionBuilder withScreenPercentage(double xPercent, double yPercent, double widthPercent, double heightPercent) Sets both position and size using screen percentages.- Parameters:
xPercent
- x position as percentageyPercent
- y position as percentagewidthPercent
- width as percentageheightPercent
- height as percentage- Returns:
- this builder
-
withScreenPercentage
Convenience method to set size using screen percentage.- Parameters:
widthPercent
- width as percentage of screenheightPercent
- height as percentage of screen- Returns:
- this builder
-
adjustX
Adds an adjustment to the x-coordinate.- Parameters:
adjustment
- pixels to add (negative to subtract)- Returns:
- this builder
-
adjustY
Adds an adjustment to the y-coordinate.- Parameters:
adjustment
- pixels to add (negative to subtract)- Returns:
- this builder
-
adjustWidth
Adds an adjustment to the width.- Parameters:
adjustment
- pixels to add (negative to subtract)- Returns:
- this builder
-
adjustHeight
Adds an adjustment to the height.- Parameters:
adjustment
- pixels to add (negative to subtract)- Returns:
- this builder
-
adjustBy
Adds adjustments to all dimensions.- Parameters:
x
- x adjustmenty
- y adjustmentwidth
- width adjustmentheight
- height adjustment- Returns:
- this builder
-
expand
Expands or contracts the region by the specified amount on all sides.- Parameters:
pixels
- pixels to expand (negative to contract)- Returns:
- this builder
-
withAnchor
Sets the anchor point using Positions.Name enum.- Parameters:
anchorName
- the anchor point from Positions.Name- Returns:
- this builder
-
withAnchor
Sets the anchor point using a custom Position.- Parameters:
position
- the custom position for anchoring (0.0 to 1.0 relative positioning)- Returns:
- this builder
-
positionRelativeTo
Positions this region relative to another region using a Position. The Position determines where in the reference region this region's anchor point will be placed.- Parameters:
referenceRegion
- the region to position relative toposition
- the position within the reference region (0.0 to 1.0 relative positioning)- Returns:
- this builder
-
positionRelativeTo
Positions this region relative to another region using a named position.- Parameters:
referenceRegion
- the region to position relative topositionName
- the named position from Positions.Name- Returns:
- this builder
-
withPosition
Creates a region at a specific position within the screen using Position percentages.- Parameters:
position
- the position defining where to place the region (0.0 to 1.0 scale)- Returns:
- this builder
-
withPosition
Creates a region at a named position on the screen.- Parameters:
positionName
- the named position from Positions.Name- Returns:
- this builder
-
centerOnScreen
Centers the region on the screen.- Returns:
- this builder
-
topLeft
Positions the region at the top-left of the screen.- Returns:
- this builder
-
topRight
Positions the region at the top-right of the screen.- Returns:
- this builder
-
bottomLeft
Positions the region at the bottom-left of the screen.- Returns:
- this builder
-
bottomRight
Positions the region at the bottom-right of the screen.- Returns:
- this builder
-
topCenter
Positions the region at the top-center of the screen.- Returns:
- this builder
-
bottomCenter
Positions the region at the bottom-center of the screen.- Returns:
- this builder
-
leftCenter
Positions the region at the left-center of the screen.- Returns:
- this builder
-
rightCenter
Positions the region at the right-center of the screen.- Returns:
- this builder
-
constrainToScreen
Ensures the region stays within screen bounds.- Parameters:
constrain
- true to constrain to screen- Returns:
- this builder
-
maintainAspectRatio
Maintains the aspect ratio when resizing.- Parameters:
maintain
- true to maintain aspect ratio- Returns:
- this builder
-
fullScreen
Creates a region covering the full screen.- Returns:
- this builder
-
topHalf
Creates a region for the top half of the screen.- Returns:
- this builder
-
bottomHalf
Creates a region for the bottom half of the screen.- Returns:
- this builder
-
leftHalf
Creates a region for the left half of the screen.- Returns:
- this builder
-
rightHalf
Creates a region for the right half of the screen.- Returns:
- this builder
-
build
Builds the Region with all specified parameters.- Returns:
- the constructed Region
-