Class Rectangle
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Allocation
GdkRectangle
data type for representing rectangles.
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
ConstructorDescriptionAllocate 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 TypeMethodDescriptionboolean
containsPoint
(int x, int y) Returnstrue
if this Rectangle contains the point described byx
andy
.boolean
Checks if the two given rectangles are equal.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the Rectangle classboolean
Calculates the intersection of two rectangles.int
Read the value of the fieldheight
.int
Read the value of the fieldwidth
.int
readX()
Read the value of the fieldx
.int
readY()
Read the value of the fieldy
.void
Calculates the union of two rectangles.void
writeHeight
(int height) Write a value in the fieldheight
.void
writeWidth
(int width) Write a value in the fieldwidth
.void
writeX
(int x) Write a value in the fieldx
.void
writeY
(int y) Write a value in the fieldy
.Methods inherited from class io.github.jwharm.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 fieldx
y
- value for the fieldy
width
- value for the fieldwidth
height
- value for the fieldheight
arena
- 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 fieldx
y
- value for the fieldy
width
- value for the fieldwidth
height
- 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) Returnstrue
if this Rectangle contains the point described byx
andy
.- Parameters:
x
- X coordinatey
- Y coordinate- Returns:
true
if this Rectangle contains the point
-
equal
Checks if the two given rectangles are equal.- Parameters:
rect2
- aGdkRectangle
- Returns:
true
if the rectangles are equal.
-
intersect
Calculates the intersection of two rectangles.It is allowed for
dest
to be the same as either this Rectangle orsrc2
. If the rectangles do not intersect,dest
’s width 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, passnull
fordest
.- Parameters:
src2
- aGdkRectangle
dest
- return location for the intersection of this Rectangle andsrc2
- Returns:
true
if the rectangles intersect.
-
union
Calculates the union of two rectangles.The union of rectangles this Rectangle and
src2
is the smallest rectangle which includes both this Rectangle andsrc2
within it. It is allowed fordest
to 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
- aGdkRectangle
dest
- return location for the union of this Rectangle andsrc2
-