Class Rectangle
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Allocation
GdkRectangle is identical to cairo_rectangle_t. Together with Cairo’s
cairo_region_t data type, these are the central types for representing
sets of pixels.
The intersection of two rectangles can be computed with
intersect(org.gnome.gdk.Rectangle, org.gnome.gdk.Rectangle); to find the union of two rectangles use
union(org.gnome.gdk.Rectangle, org.gnome.gdk.Rectangle).
The cairo_region_t type provided by Cairo is usually used for managing
non-rectangular clipping of graphical operations.
The Graphene library has a number of other data types for regions and volumes in 2D and 3D.
-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new Rectangle.Rectangle(int x, int y, int width, int height) Allocate a new Rectangle with the fields set to the provided values.Allocate a new Rectangle with the fields set to the provided values.Allocate a new Rectangle.Rectangle(MemorySegment address) Create a Rectangle proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsPoint(int x, int y) Returnstrueif this Rectangle contains the point described byxandy.booleanChecks if the two given rectangles are equal.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the Rectangle classbooleanCalculates the intersection of two rectangles.intRead the value of the fieldheight.intRead the value of the fieldwidth.intreadX()Read the value of the fieldx.intreadY()Read the value of the fieldy.voidCalculates the union of two rectangles.voidwriteHeight(int height) Write a value in the fieldheight.voidwriteWidth(int width) Write a value in the fieldwidth.voidwriteX(int x) Write a value in the fieldx.voidwriteY(int y) Write a value in the fieldy.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Rectangle
Create a Rectangle proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Rectangle
Allocate a new Rectangle.- Parameters:
arena- to control the memory allocation scope
-
Rectangle
public Rectangle()Allocate a new Rectangle. The memory is allocated withArena.ofAuto(). -
Rectangle
Allocate a new Rectangle with the fields set to the provided values.- Parameters:
x- value for the fieldxy- value for the fieldywidth- value for the fieldwidthheight- value for the fieldheightarena- to control the memory allocation scope
-
Rectangle
public Rectangle(int x, int y, int width, int height) Allocate a new Rectangle with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
x- value for the fieldxy- value for the fieldywidth- value for the fieldwidthheight- value for the fieldheight
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readX
public int readX()Read the value of the fieldx.- Returns:
- The value of the field
x
-
writeX
public void writeX(int x) Write a value in the fieldx.- Parameters:
x- The new value for the fieldx
-
readY
public int readY()Read the value of the fieldy.- Returns:
- The value of the field
y
-
writeY
public void writeY(int y) Write a value in the fieldy.- Parameters:
y- The new value for the fieldy
-
readWidth
public int readWidth()Read the value of the fieldwidth.- Returns:
- The value of the field
width
-
writeWidth
public void writeWidth(int width) Write a value in the fieldwidth.- Parameters:
width- The new value for the fieldwidth
-
readHeight
public int readHeight()Read the value of the fieldheight.- Returns:
- The value of the field
height
-
writeHeight
public void writeHeight(int height) Write a value in the fieldheight.- Parameters:
height- The new value for the fieldheight
-
containsPoint
public boolean containsPoint(int x, int y) Returnstrueif this Rectangle contains the point described byxandy.- Parameters:
x- X coordinatey- Y coordinate- Returns:
trueif this Rectangle contains the point
-
equal
Checks if the two given rectangles are equal.- Parameters:
rect2- aGdkRectangle- Returns:
trueif the rectangles are equal.
-
intersect
Calculates the intersection of two rectangles.It is allowed for
destto be the same as either this Rectangle orsrc2.If the rectangles do not intersect,dest’swidth and height is set to 0 and its x and y values are undefined. If you are only interested in whether the rectangles intersect, but not in the intersecting area itself, passnullfordest.- Parameters:
src2- aGdkRectangledest- return location for the intersection of this Rectangle andsrc2- Returns:
trueif the rectangles intersect.
-
union
Calculates the union of two rectangles.The union of rectangles this Rectangle and
src2is the smallest rectangle which includes both this Rectangle andsrc2within it. It is allowed fordestto be the same as either this Rectangle orsrc2.Note that this function does not ignore 'empty' rectangles (ie. with zero width or height).
- Parameters:
src2- aGdkRectangledest- return location for the union of this Rectangle andsrc2
-