Class Transform

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Transform extends ProxyInstance

Describes a 3D transform.

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 Details

    • Transform

      public Transform(MemorySegment address)
      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

      public static @Nullable Type getType()
      Get the GType of the Transform class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • parse

      public static boolean parse(String string, Out<Transform> outTransform)

      Parses a given into a transform.

      Strings printed via toString() can be read in again successfully using this function.

      If string does not describe a valid transform, false is returned and NULL is put in outTransform.

      Parameters:
      string - the string to parse
      outTransform - return location for the transform
      Returns:
      true if string described a valid transform
    • 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 TransformCategory getCategory()
      Returns the category this transform belongs to.
      Returns:
      The category of the transform
    • invert

      public @Nullable Transform invert()

      Inverts the given transform.

      If this Transform 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 this Transform is not NULL before calling this function.

      This function consumes self. Use ref() first if you want to keep it around.

      Returns:
      The inverted transform
    • matrix

      public Transform matrix(Matrix matrix)

      Multiplies this Transform with the given matrix.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      matrix - the matrix to multiply this Transform with
      Returns:
      The new transform
    • matrix2d

      public @Nullable Transform matrix2d(float xx, float yx, float xy, float yy, float dx, float dy)

      Multiplies this Transform with the matrix Gsk.Transform.to_2d on the returned Gsk.Transform should match the input passed to this function.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      xx - the xx member
      yx - the yx member
      xy - the xy member
      yy - the yy member
      dx - the x0 member
      dy - the y0 member
      Returns:
      The new transform
      Since:
      4.20
    • 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.

      This function consumes next. 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

      public void print(String string)

      Converts the transform into a human-readable representation.

      The result of this function can later be parsed with parse(String, Out).

      Parameters:
      string - The string to print into
    • ref

      public @Nullable Transform ref()
      Acquires a reference on the given transform.
      Returns:
      the transform with an additional reference
    • rotate

      public @Nullable Transform rotate(float angle)

      Rotates this Transform by an angle around the Z axis.

      The rotation happens around the origin point of (0, 0).

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      angle - the rotation angle, in degrees (clockwise)
      Returns:
      The new transform
    • rotate3d

      public @Nullable Transform rotate3d(float angle, Vec3 axis)

      Rotates this Transform angle degrees around axis.

      For a rotation in 2D space, use rotate(float)

      This function consumes next. 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

      public @Nullable Transform scale(float factorX, float factorY)

      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. Use ref() first if you want to keep it around.

      Parameters:
      factorX - scaling factor on the X axis
      factorY - scaling factor on the Y axis
      Returns:
      The new transform
    • scale3d

      public @Nullable Transform scale3d(float factorX, float factorY, float factorZ)

      Scales this Transform by the given factors.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      factorX - scaling factor on the X axis
      factorY - scaling factor on the Y axis
      factorZ - scaling factor on the Z axis
      Returns:
      The new transform
    • skew

      public @Nullable Transform skew(float skewX, float skewY)

      Applies a skew transform.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      skewX - skew factor, in degrees, on the X axis
      skewY - 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(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 GskTransform and a matrix type from other 2D drawing libraries, in particular Cairo.

      Parameters:
      outXx - return location for the xx member
      outYx - return location for the yx member
      outXy - return location for the xy member
      outYy - return location for the yy member
      outDx - return location for the x0 member
      outDy - 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 direction
      outSkewY - return location for the skew factor in the y direction
      outScaleX - return location for the scale factor in the x direction
      outScaleY - return location for the scale factor in the y direction
      outAngle - return location for the rotation angle
      outDx - return location for the translation in the x direction
      outDy - 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 direction
      outScaleY - return location for the scale factor in the y direction
      outDx - return location for the translation in the x direction
      outDy - return location for the translation in the y direction
    • toMatrix

      public void toMatrix(Matrix outMatrix)

      Computes the 4x4 matrix for the transform.

      The previous value of outMatrix will be ignored.

      Parameters:
      outMatrix - return location for the matrix
    • toString

      public String toString()

      Converts the transform into a human-readable string.

      The resulting string can be parsed with parse(String, Out).

      This is a wrapper around print(String).

      Overrides:
      toString in class Object
      Returns:
      A new string for this Transform
    • toTranslate

      public void toTranslate(Out<Float> outDx, Out<Float> outDy)

      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 direction
      outDy - return location for the translation in the y direction
    • transform

      public @Nullable Transform transform(@Nullable Transform other)

      Applies all the operations from other to next.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      other - transform to apply
      Returns:
      The new transform
    • transformBounds

      public void transformBounds(Rect rect, Rect outRect)

      Transforms a rectangle using the given transform.

      The result is the bounding box containing the coplanar quad.

      The input and output rect may point to the same rectangle.

      Parameters:
      rect - the rectangle to transform
      outRect - return location for the bounds of the transformed rectangle
    • transformPoint

      public void transformPoint(Point point, Point outPoint)
      Transforms a point using the given transform.
      Parameters:
      point - the point to transform
      outPoint - return location for the transformed point
    • translate

      public @Nullable Transform translate(Point point)

      Translates this Transform in 2-dimensional space by point.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      point - the point to translate the transform by
      Returns:
      The new transform
    • translate3d

      public @Nullable Transform translate3d(Point3D point)

      Translates this Transform by point.

      This function consumes next. Use ref() first if you want to keep it around.

      Parameters:
      point - the point to translate the transform by
      Returns:
      The new transform
    • 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.