Class Transform
- All Implemented Interfaces:
Proxy
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
ConstructorsConstructorDescriptionCreates a new identity transform.Transform(MemorySegment address) Create a Transform proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks two transforms for equality.Returns the category this transform belongs to.static @Nullable TypegetType()Get the GType of the Transform class@Nullable Transforminvert()Inverts the given transform.Multiplies this Transform with the givenmatrix.@Nullable Transformmatrix2d(float xx, float yx, float xy, float yy, float dx, float dy) Multiplies this Transform with the matrix [ xx yx x0; xy yy y0; 0 0 1 ].static booleanParses a given into a transform.perspective(float depth) Applies a perspective projection transform.voidConverts the transform into a human-readable representation.@Nullable Transformref()Acquires a reference on the given transform.@Nullable Transformrotate(float angle) Rotates this Transform by an angle around the Z axis.@Nullable TransformRotates this Transformangledegrees aroundaxis.@Nullable Transformscale(float factorX, float factorY) Scales this Transform in 2-dimensional space by the given factors.@Nullable Transformscale3d(float factorX, float factorY, float factorZ) Scales this Transform by the given factors.@Nullable Transformskew(float skewX, float skewY) Applies a skew transform.voidto2d(Out<Float> outXx, Out<Float> outYx, Out<Float> outXy, Out<Float> outYy, Out<Float> outDx, Out<Float> outDy) Converts a transform to a 2D transformation matrix.voidto2dComponents(Out<Float> outSkewX, Out<Float> outSkewY, Out<Float> outScaleX, Out<Float> outScaleY, Out<Float> outAngle, Out<Float> outDx, Out<Float> outDy) Converts a transform to 2D transformation factors.voidConverts a transform to 2D affine transformation factors.voidComputes the 4x4 matrix for the transform.toString()Converts the transform into a human-readable string.voidtoTranslate(Out<Float> outDx, Out<Float> outDy) Converts a transform to a translation operation.@Nullable TransformApplies all the operations fromothertonext.voidtransformBounds(Rect rect, Rect outRect) Transforms a rectangle using the given transform.voidtransformPoint(Point point, Point outPoint) Transforms a point using the given transform.@Nullable TransformTranslates this Transform in 2-dimensional space bypoint.@Nullable Transformtranslate3d(Point3D point) Translates this Transform bypoint.voidunref()Releases a reference on the given transform.Methods inherited from class org.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 a given into a transform.Strings printed via
toString()can be read in again successfully using this function.If
stringdoes not describe a valid transform, false is returned andNULLis put inoutTransform.- Parameters:
string- the string to parseoutTransform- return location for the transform- Returns:
- true if
stringdescribed 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,
NULLis returned. Note that invertingNULLalso returnsNULL, which is the correct inverse ofNULL. If you need to differentiate between those cases, you should check this Transform is notNULLbefore calling this function.This function consumes
self.Useref()first if you want to keep it around.- Returns:
- The inverted transform
-
matrix
-
matrix2d
Multiplies this Transform with the matrix [ xx yx x0; xy yy y0; 0 0 1 ].The result of calling
to2d(org.javagi.base.Out<java.lang.Float>, org.javagi.base.Out<java.lang.Float>, org.javagi.base.Out<java.lang.Float>, org.javagi.base.Out<java.lang.Float>, org.javagi.base.Out<java.lang.Float>, org.javagi.base.Out<java.lang.Float>)on the returnedGsk.Transformshould match the input passed to this function.This function consumes
next.Useref()first if you want to keep it around.- Parameters:
xx- the xx memberyx- the yx memberxy- the xy memberyy- the yy memberdx- the x0 memberdy- the y0 member- Returns:
- The new transform
- Since:
- 4.20
-
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
next.Useref()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 the transform into a human-readable representation.The result of this function can later be parsed with
parse(java.lang.String, org.javagi.base.Out<org.gnome.gsk.Transform>).- Parameters:
string- The string to print into
-
ref
Acquires a reference on the given transform.- Returns:
- the transform with an additional reference
-
rotate
Rotates this Transform by an angle around the Z axis.The rotation happens around the origin point of (0, 0).
This function consumes
next.Useref()first if you want to keep it around.- Parameters:
angle- the rotation angle, in degrees (clockwise)- Returns:
- The new transform
-
rotate3d
Rotates this Transformangledegrees aroundaxis.For a rotation in 2D space, use
rotate(float)This function consumes
next.Useref()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
next.Useref()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
next.Useref()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
Applies a skew transform.This function consumes
next.Useref()first if you want to keep it around.- Parameters:
skewX- skew factor, in degrees, on the X axisskewY- skew factor, in degrees, on the Y axis- Returns:
- The new transform
- Since:
- 4.6
-
to2d
public void to2d(Out<Float> outXx, Out<Float> outYx, Out<Float> outXy, Out<Float> outYy, Out<Float> outDx, Out<Float> outDy) Converts a transform to a 2D transformation matrix.this Transform must be a 2D transformation. If you are not sure, use
gsk_transform_get_category() >= GSK_TRANSFORM_CATEGORY_2D
to check.
The returned values are a subset of the full 4x4 matrix that is computed by
toMatrix(org.gnome.graphene.Matrix)and 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
GskTransformand 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 a transform 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_INIT (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() >= GSK_TRANSFORM_CATEGORY_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- Since:
- 4.6
-
toAffine
public void toAffine(Out<Float> outScaleX, Out<Float> outScaleY, Out<Float> outDx, Out<Float> outDy) Converts a transform 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() >= GSK_TRANSFORM_CATEGORY_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 4x4 matrix for the transform.The previous value of
outMatrixwill be ignored.- Parameters:
outMatrix- return location for the matrix
-
toString
Converts the transform into a human-readable string.The resulting string can be parsed with
parse(java.lang.String, org.javagi.base.Out<org.gnome.gsk.Transform>).This is a wrapper around
print(java.lang.String). -
toTranslate
Converts a transform to a translation operation.this Transform must be a 2D transformation. If you are not sure, use
gsk_transform_get_category() >= GSK_TRANSFORM_CATEGORY_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 given transform.If the reference was the last, the resources associated to the this Transform are freed.
-