Class Transform

All Implemented Interfaces:
PointerInterface

public class Transform extends Record
`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.

https://docs.gtk.org/gsk4/struct.Transform.html

  • Constructor Details

    • Transform

      public Transform(PointerContainer pointer)
    • Transform

      public Transform()
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • equal

      public boolean equal(@Nullable Transform second)
      Checks two transforms for equality.
      Parameters:
      second - the second transform
      Returns:
      %TRUE if the two transforms perform the same operation
    • getCategory

      public int getCategory()
      Returns the category this transform belongs to.
      Returns:
      The category of the transform
    • invert

      public Transform invert()
      Inverts the given transform.

      If @self is not invertible, %NULL is returned.
      Note that inverting %NULL also returns %NULL, which is
      the correct inverse of %NULL. If you need to differentiate
      between those cases, you should check @self is not %NULL
      before calling this function.
      Returns:
      The inverted transform
    • matrix

      public Transform matrix(@Nonnull Matrix matrix)
      Multiplies @next with the given @matrix.
      Parameters:
      matrix - the matrix to multiply @next with
      Returns:
      The new transform
    • perspective

      public Transform perspective(float depth)
      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.
      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

      public void print(@Nonnull GString string)
      Converts @self into a human-readable string representation suitable
      for printing.

      The result of this function can later be parsed with
      [func@Gsk.Transform.parse].
      Parameters:
      string - The string to print into
    • ref

      public Transform ref()
      Acquires a reference on the given `GskTransform`.
      Returns:
      the `GskTransform` with an additional reference
    • rotate

      public Transform rotate(float angle)
      Rotates @next @angle degrees in 2D - or in 3D-speak, around the z axis.
      Parameters:
      angle - the rotation angle, in degrees (clockwise)
      Returns:
      The new transform
    • rotate3d

      public Transform rotate3d(float angle, @Nonnull Vec3 axis)
      Rotates @next @angle degrees around @axis.

      For a rotation in 2D space, use [method@Gsk.Transform.rotate]
      Parameters:
      angle - the rotation angle, in degrees (clockwise)
      axis - The rotation axis
      Returns:
      The new transform
    • scale

      public Transform scale(float factor_x, float factor_y)
      Scales @next in 2-dimensional space by the given factors.

      Use [method@Gsk.Transform.scale_3d] to scale in all 3 dimensions.
      Parameters:
      factor_x - scaling factor on the X axis
      factor_y - scaling factor on the Y axis
      Returns:
      The new transform
    • scale3d

      public Transform scale3d(float factor_x, float factor_y, float factor_z)
      Scales @next by the given factors.
      Parameters:
      factor_x - scaling factor on the X axis
      factor_y - scaling factor on the Y axis
      factor_z - scaling factor on the Z axis
      Returns:
      The new transform
    • skew

      public Transform skew(float skew_x, float skew_y)
      Applies a skew transform.
      Parameters:
      skew_x - skew factor, in degrees, on the X axis
      skew_y - skew factor, in degrees, on the Y axis
      Returns:
      The new transform
    • to2d

      public void to2d(@Nonnull Flt out_xx, @Nonnull Flt out_yx, @Nonnull Flt out_xy, @Nonnull Flt out_yy, @Nonnull Flt out_dx, @Nonnull Flt out_dy)
      Converts a `GskTransform` to a 2D transformation matrix.

      @self must be a 2D transformation. If you are not
      sure, use gsk_transform_get_category() >=
      %GSK_TRANSFORM_CATEGORY_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:
      out_xx - return location for the xx member
      out_yx - return location for the yx member
      out_xy - return location for the xy member
      out_yy - return location for the yy member
      out_dx - return location for the x0 member
      out_dy - return location for the y0 member
    • to2dComponents

      public void to2dComponents(@Nonnull Flt out_skew_x, @Nonnull Flt out_skew_y, @Nonnull Flt out_scale_x, @Nonnull Flt out_scale_y, @Nonnull Flt out_angle, @Nonnull Flt out_dx, @Nonnull Flt out_dy)
      Converts a `GskTransform` 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)

      @self must be a 2D transformation. If you are not sure, use

      gsk_transform_get_category() >= %GSK_TRANSFORM_CATEGORY_2D

      to check.
      Parameters:
      out_skew_x - return location for the skew factor in the x direction
      out_skew_y - return location for the skew factor in the y direction
      out_scale_x - return location for the scale factor in the x direction
      out_scale_y - return location for the scale factor in the y direction
      out_angle - return location for the rotation angle
      out_dx - return location for the translation in the x direction
      out_dy - return location for the translation in the y direction
    • toAffine

      public void toAffine(@Nonnull Flt out_scale_x, @Nonnull Flt out_scale_y, @Nonnull Flt out_dx, @Nonnull Flt out_dy)
      Converts a `GskTransform` 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)

      @self must be a 2D affine transformation. If you are not
      sure, use

      gsk_transform_get_category() >= %GSK_TRANSFORM_CATEGORY_2D_AFFINE

      to check.
      Parameters:
      out_scale_x - return location for the scale factor in the x direction
      out_scale_y - return location for the scale factor in the y direction
      out_dx - return location for the translation in the x direction
      out_dy - return location for the translation in the y direction
    • toMatrix

      public void toMatrix(@Nonnull Matrix out_matrix)
      Computes the actual value of @self and stores it in @out_matrix.

      The previous value of @out_matrix will be ignored.
      Parameters:
      out_matrix - The matrix to set
    • toStr

      public Str toStr()
      Converts a matrix into a string that is suitable for printing.

      The resulting string can be parsed with [func@Gsk.Transform.parse].

      This is a wrapper around [method@Gsk.Transform.print].
      Returns:
      A new string for @self
    • toTranslate

      public void toTranslate(@Nonnull Flt out_dx, @Nonnull Flt out_dy)
      Converts a `GskTransform` to a translation operation.

      @self must be a 2D transformation. If you are not
      sure, use

      gsk_transform_get_category() >= %GSK_TRANSFORM_CATEGORY_2D_TRANSLATE

      to check.
      Parameters:
      out_dx - return location for the translation in the x direction
      out_dy - return location for the translation in the y direction
    • transform

      public Transform transform(@Nullable Transform other)
      Applies all the operations from @other to @next.
      Parameters:
      other - Transform to apply
      Returns:
      The new transform
    • transformBounds

      public void transformBounds(@Nonnull Rect rect, @Nonnull Rect out_rect)
      Transforms a `graphene_rect_t` using the given transform @self.

      The result is the bounding box containing the coplanar quad.
      Parameters:
      rect - a `graphene_rect_t`
      out_rect - return location for the bounds of the transformed rectangle
    • transformPoint

      public void transformPoint(@Nonnull Point point, @Nonnull Point out_point)
      Transforms a `graphene_point_t` using the given transform @self.
      Parameters:
      point - a `graphene_point_t`
      out_point - return location for the transformed point
    • translate

      public Transform translate(@Nonnull Point point)
      Translates @next in 2-dimensional space by @point.
      Parameters:
      point - the point to translate the transform by
      Returns:
      The new transform
    • translate3d

      public Transform translate3d(@Nonnull Point3D point)
      Translates @next by @point.
      Parameters:
      point - the point to translate the transform by
      Returns:
      The new transform
    • unref

      public void unref()
      Releases a reference on the given `GskTransform`.

      If the reference was the last, the resources associated to the @self are
      freed.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()