Class Transform
- All Implemented Interfaces:
Proxy
GskTransform
is an object to describe transform matrices.
Unlike graphene_matrix_t
, GskTransform
retains the steps in how
a transform was constructed, and allows inspecting them. It is modeled
after the way CSS describes transforms.
GskTransform
objects are immutable and cannot be changed after creation.
This means code can safely expose them as properties of objects without
having to worry about others changing them.
-
Constructor Summary
ConstructorDescriptionCreates a new identity transform.Transform
(MemorySegment address) Create a Transform proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks two transforms for equality.Returns the category this transform belongs to.static Type
getType()
Get the GType of the Transform classinvert()
Inverts the given transform.Multiplies this Transform with the givenmatrix
.static boolean
Parses the givenstring
into a transform and puts it inoutTransform
.perspective
(float depth) Applies a perspective projection transform.void
Converts this Transform into a human-readable string representation suitable for printing.ref()
Acquires a reference on the givenGskTransform
.rotate
(float angle) Rotates this Transformangle
degrees in 2D - or in 3D-speak, around the Z axis.Rotates this Transformangle
degrees aroundaxis
.scale
(float factorX, float factorY) Scales this Transform in 2-dimensional space by the given factors.scale3d
(float factorX, float factorY, float factorZ) Scales this Transform by the given factors.skew
(float skewX, float skewY) Applies a skew transform.void
to2d
(Out<Float> outXx, Out<Float> outYx, Out<Float> outXy, Out<Float> outYy, Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to a 2D transformation matrix.void
to2dComponents
(Out<Float> outSkewX, Out<Float> outSkewY, Out<Float> outScaleX, Out<Float> outScaleY, Out<Float> outAngle, Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to 2D transformation factors.void
Converts aGskTransform
to 2D affine transformation factors.void
Computes the actual value of this Transform and stores it inoutMatrix
.toString()
Converts a matrix into a string that is suitable for printing.void
toTranslate
(Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to a translation operation.Applies all the operations fromother
to this Transform.void
transformBounds
(Rect rect, Rect outRect) Transforms agraphene_rect_t
using the given transform this Transform.void
transformPoint
(Point point, Point outPoint) Transforms agraphene_point_t
using the given transform this Transform.Translates this Transform in 2-dimensional space bypoint
.translate3d
(Point3D point) Translates this Transform bypoint
.void
unref()
Releases a reference on the givenGskTransform
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Transform
Create a Transform proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Transform
public Transform()Creates a new identity transform.This function is meant to be used by language bindings. For C code, this is equivalent to using
null
.
-
-
Method Details
-
getType
-
parse
Parses the givenstring
into a transform and puts it inoutTransform
.Strings printed via
toString()
can be read in again successfully using this function.If
string
does not describe a valid transform,false
is returned andnull
is put inoutTransform
.- Parameters:
string
- the string to parseoutTransform
- The location to put the transform in- Returns:
true
ifstring
described a valid transform.
-
equal
Checks two transforms for equality.- Parameters:
second
- the second transform- Returns:
true
if the two transforms perform the same operation
-
getCategory
Returns the category this transform belongs to.- Returns:
- The category of the transform
-
invert
Inverts the given transform.If this Transform is not invertible,
null
is returned. Note that invertingnull
also returnsnull
, which is the correct inverse ofnull
. If you need to differentiate between those cases, you should check this Transform is notnull
before calling this function.This function consumes this Transform. Use
ref()
first if you want to keep it around.- Returns:
- The inverted transform
-
matrix
-
perspective
Applies a perspective projection transform.This transform scales points in X and Y based on their Z value, scaling points with positive Z values away from the origin, and those with negative Z values towards the origin. Points on the z=0 plane are unchanged.
This function consumes this Transform. Use
ref()
first if you want to keep it around.- Parameters:
depth
- distance of the z=0 plane. Lower values give a more flattened pyramid and therefore a more pronounced perspective effect.- Returns:
- The new transform
-
print
Converts this Transform into a human-readable string representation suitable for printing.The result of this function can later be parsed with
parse(java.lang.String, io.github.jwharm.javagi.base.Out<org.gnome.gsk.Transform>)
.- Parameters:
string
- The string to print into
-
ref
Acquires a reference on the givenGskTransform
.- Returns:
- the
GskTransform
with an additional reference
-
rotate
Rotates this Transformangle
degrees in 2D - or in 3D-speak, around the Z axis. The rotation happens around the origin point of (0, 0).This function consumes this Transform. Use
ref()
first if you want to keep it around.- Parameters:
angle
- the rotation angle, in degrees (clockwise)- Returns:
- The new transform
-
rotate3d
Rotates this Transformangle
degrees aroundaxis
.For a rotation in 2D space, use
rotate(float)
This function consumes this Transform. Use
ref()
first if you want to keep it around.- Parameters:
angle
- the rotation angle, in degrees (clockwise)axis
- The rotation axis- Returns:
- The new transform
-
scale
Scales this Transform in 2-dimensional space by the given factors.Use
scale3d(float, float, float)
to scale in all 3 dimensions.This function consumes this Transform. Use
ref()
first if you want to keep it around.- Parameters:
factorX
- scaling factor on the X axisfactorY
- scaling factor on the Y axis- Returns:
- The new transform
-
scale3d
Scales this Transform by the given factors.This function consumes this Transform. Use
ref()
first if you want to keep it around.- Parameters:
factorX
- scaling factor on the X axisfactorY
- scaling factor on the Y axisfactorZ
- scaling factor on the Z axis- Returns:
- The new transform
-
skew
-
to2d
public void to2d(Out<Float> outXx, Out<Float> outYx, Out<Float> outXy, Out<Float> outYy, Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to a 2D transformation matrix.this Transform must be a 2D transformation. If you are not sure, use gsk_transform_get_category() >=
TransformCategory._2D
to check.The returned values have the following layout:
| xx yx | | a b 0 | | xy yy | = | c d 0 | | dx dy | | tx ty 1 |
This function can be used to convert between a
GskTransform
and a matrix type from other 2D drawing libraries, in particular Cairo.- Parameters:
outXx
- return location for the xx memberoutYx
- return location for the yx memberoutXy
- return location for the xy memberoutYy
- return location for the yy memberoutDx
- return location for the x0 memberoutDy
- return location for the y0 member
-
to2dComponents
public void to2dComponents(Out<Float> outSkewX, Out<Float> outSkewY, Out<Float> outScaleX, Out<Float> outScaleY, Out<Float> outAngle, Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to 2D transformation factors.To recreate an equivalent transform from the factors returned by this function, use
gsk_transform_skew ( gsk_transform_scale ( gsk_transform_rotate ( gsk_transform_translate (NULL, &GRAPHENE_POINT_T (dx, dy)), angle), scale_x, scale_y), skew_x, skew_y)
this Transform must be a 2D transformation. If you are not sure, use
gsk_transform_get_category() >=
TransformCategory._2D
to check.
- Parameters:
outSkewX
- return location for the skew factor in the x directionoutSkewY
- return location for the skew factor in the y directionoutScaleX
- return location for the scale factor in the x directionoutScaleY
- return location for the scale factor in the y directionoutAngle
- return location for the rotation angleoutDx
- return location for the translation in the x directionoutDy
- return location for the translation in the y direction
-
toAffine
public void toAffine(Out<Float> outScaleX, Out<Float> outScaleY, Out<Float> outDx, Out<Float> outDy) Converts aGskTransform
to 2D affine transformation factors.To recreate an equivalent transform from the factors returned by this function, use
gsk_transform_scale (gsk_transform_translate (NULL, &GRAPHENE_POINT_T (dx, dy)), sx, sy)
this Transform must be a 2D affine transformation. If you are not sure, use
gsk_transform_get_category() >=
TransformCategory._2D_AFFINE
to check.
- Parameters:
outScaleX
- return location for the scale factor in the x directionoutScaleY
- return location for the scale factor in the y directionoutDx
- return location for the translation in the x directionoutDy
- return location for the translation in the y direction
-
toMatrix
Computes the actual value of this Transform and stores it inoutMatrix
.The previous value of
outMatrix
will be ignored.- Parameters:
outMatrix
- The matrix to set
-
toString
Converts a matrix into a string that is suitable for printing.The resulting string can be parsed with
parse(java.lang.String, io.github.jwharm.javagi.base.Out<org.gnome.gsk.Transform>)
.This is a wrapper around
print(org.gnome.glib.GString)
. -
toTranslate
Converts aGskTransform
to a translation operation.this Transform must be a 2D transformation. If you are not sure, use
gsk_transform_get_category() >=
TransformCategory._2D_TRANSLATE
to check.
- Parameters:
outDx
- return location for the translation in the x directionoutDy
- return location for the translation in the y direction
-
transform
-
transformBounds
-
transformPoint
-
translate
-
translate3d
-
unref
public void unref()Releases a reference on the givenGskTransform
.If the reference was the last, the resources associated to the this Transform are freed.
-