### ----------------------------------------------------
### -- Gnome::Cairo
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: lib/Gnome/Cairo/Pattern.rakumod
### ----------------------------------------------------
### -- Chunk 1 of 3
#TL:4:Gnome::Cairo::Pattern:

use v6;
#-------------------------------------------------------------------------------
=begin pod

=head1 Gnome::Cairo::Pattern

Sources for drawing

=comment ![](images/X.png)

=head1 Description

B<cairo_pattern_t> is the paint with which cairo draws. The primary use of patterns is as the source for all cairo drawing operations, although they can also be used as masks, that is, as the brush too.

A cairo pattern is created by using one of the many constructors in the form of C<new(:rgb())> for example.


=head2 See Also

B<cairo_t>, B<cairo_surface_t>


=head1 Synopsis
=head2 Declaration

  unit class Gnome::Cairo::Pattern;
  also is Gnome::N::TopLevelClassSupport;

=comment head2 Example

=end pod
#-------------------------------------------------------------------------------
use NativeCall;

use Gnome::N::X:api<1>;
use Gnome::N::NativeLib:api<1>;
use Gnome::N::TopLevelClassSupport:api<1>;
use Gnome::N::GlibToRakuTypes:api<1>;

use Gnome::Cairo::Types:api<1>;
use Gnome::Cairo::Enums:api<1>;

#-------------------------------------------------------------------------------
unit class Gnome::Cairo::Pattern:auth<github:MARTIMM>:api<1>;
also is Gnome::N::TopLevelClassSupport;

#-------------------------------------------------------------------------------
=begin pod
=head1 Methods
=head2 new

=head3 new ( :rgb( red, green, blue) )

Creates a new B<cairo_pattern_t> corresponding to an opaque color. The color components are floating point numbers in the range 0 to 1. If the values passed in are outside that range, they will be clamped. Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory.

The caller owns the returned object and should call C<clear-object()> when finished with it. This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use C<status()>.

A translucent colored pattern is created when also an alpha value is defined.

  multi method new ( :rgb( Num() $red, Num() $green, Num() $blue) )

=item $red; red color from 0 to 1
=item $green; green color from 0 to 1
=item $blue; blue color from 0 to 1

=head3 new ( )

Creates a new B<cairo_pattern_t> as if :rgb( 1, 1, 1) is used. This is a white colored pattern.

  multi method new ( )


=head3 new ( :rgba( red, green, blue, alpha) )

Creates a new B<cairo_pattern_t> corresponding to a color with added transparency.

The caller owns the returned object and should call C<clear-object()> when finished with it. This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use C<status()>.

  multi method new (
    :rgba( Num() $red, Num() $green, Num() $blue, Num() $alpha)
  )

=item $red; red color from 0 to 1
=item $green; green color from 0 to 1
=item $blue; blue color from 0 to 1
=item $alpha; transparency from 0 to 1 (opaque)


=head3 new ( :surface )

Create a new B<cairo_pattern_t> for the given surface. The caller owns the returned object and should call C<clear-object()> when finished with it. This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use C<status()>.

  multi method new ( cairo_surface_t :$surface! )


=head3 new ( :linear( x0, y0, x1, y1) )

Create a new linear gradient B<cairo_pattern_t> along the line defined by (x0, y0) and (x1, y1).  Before using the gradient pattern, a number of color stops should be defined using C<add-color-stop-rgb()> or C<add-color-stop-rgba()>.  Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<set-matrix()>.

The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error.  To inspect the status of a pattern use C<status()>.

  method new ( :linear( Num() $x0, Num() $y0, Num() $x1, Num() $y1) )

=item $x0; x coordinate of the start point
=item $y0; y coordinate of the start point
=item $x1; x coordinate of the end point
=item $y1; y coordinate of the end point


=head3 new ( :radial( cx0, cy0, radius0, cx1, cy1, radius1) )

Creates a new radial gradient B<cairo_pattern_t> between the two circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1).  Before using the gradient pattern, a number of color stops should be defined using C<add-color-stop-rgb()> or C<add-color-stop-rgba()>.  Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<set-matrix()>.

The caller owns the returned object and should call C<clear-object()> when finished with it. To inspect the status of a pattern use C<status()>.

  multi method new (
    :radial(
      Num() $cx0, Num() $cy0, Num() $radius0,
      Num() $cx1, Num() $cy1, Num() $radius1
    )
  )

=item $cx0; x coordinate for the center of the start circle
=item $cy0; y coordinate for the center of the start circle
=item $radius0; radius of the start circle
=item $cx1; x coordinate for the center of the end circle
=item $cy1; y coordinate for the center of the end circle
=item $radius1; radius of the end circle


=head3 new( :mesh )

Create a new mesh pattern.

Mesh patterns are tensor-product patch meshes (type 7 shadings in PDF). Mesh patterns may also be used to create other types of shadings that are special cases of tensor-product patch meshes such as Coons patch meshes (type 6 shading in PDF) and Gouraud-shaded triangle meshes (type 4 and 5 shadings in PDF).

Mesh patterns consist of one or more tensor-product patches, which should be defined before using the mesh pattern. Using a mesh pattern with a partially defined patch as source or mask will put the context in an error status with a status of C<CAIRO_STATUS_INVALID_MESH_CONSTRUCTION>.

A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, 3) and by 4 additional control points (P0, P1, P2, P3) that provide further control over the patch and complete the definition of the tensor-product patch. The corner C0 is the first point of the patch.

Degenerate sides are permitted so straight lines may be used. A zero length line on one side may be used to create 3 sided patches.

=begin code
        C1     Side 1      C2
          +---------------+
          |               |
          |  P1       P2  |
          |               |
  Side 0  |               | Side 2
          |               |
          |               |
          |  P0       P3  |
          |               |
          +---------------+
        C0     Side 3      C3
=end code

Each patch is constructed by first calling C<mesh-begin-patch()>, then C<mesh-move-to()> to specify the first point in the patch (C0). Then the sides are specified with calls to C<mesh-curve-to()> and C<mesh-line-to()>.

The four additional control points (P0, P1, P2, P3) in a patch can be specified with C<mesh-set-control-point()>.  At each corner of the patch (C0, C1, C2, C3) a color may be specified with C<mesh-set-corner-color-rgb()> or C<mesh-set-corner-color-rgba()>. Any corner whose color is not explicitly specified defaults to transparent black.  A Coons patch is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch. The default value for any control point not specified is the implicit value for a Coons patch, i.e. if no control points are specified the patch is a Coons patch.  A triangle is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch, all the sides are lines and one of them has length 0, i.e. if the patch is specified using just 3 lines, it is a triangle. If the corners connected by the 0-length side have the same color, the patch is a Gouraud-shaded triangle.  Patches may be oriented differently to the above diagram. For example the first point could be at the top left. The diagram only shows the relationship between the sides, corners and control points. Regardless of where the first point is located, when specifying colors, corner 0 will always be the first point, corner 1 the point between side 0 and side 1 etc.

Calling C<mesh-end-patch()> completes the current patch. If less than 4 sides have been defined, the first missing side is defined as a line from the current point to the first point of the patch (C0) and the other sides are degenerate lines from C0 to C0. The corners between the added sides will all be coincident with C0 of the patch and their color will be set to be the same as the color of C0.

Additional patches may be added with additional calls to C<mesh-begin-patch()>/C<mesh-end-patch()>.

  my Gnome::Cairo $pattern .= new(:mesh);

  # Add a Coons patch
  $pattern.mesh-begin-patch( $pattern);
  $pattern.mesh-move-to( 0, 0);
  $pattern.mesh-curve-to( 30, -30,  60,  30, 100, 0);
  $pattern.mesh-curve-to( 60,  30, 130,  60, 100, 100);
  $pattern.mesh-curve-to( 60,  70,  30, 130,   0, 100);
  $pattern.mesh-curve-to( 30,  70, -30,  30,   0, 0);
  $pattern.mesh-set-corner-color-rgb( $pattern, 0, 1, 0, 0);
  $pattern.mesh-set-corner-color-rgb( 1, 0, 1, 0);
  $pattern.mesh-set-corner-color-rgb( 2, 0, 0, 1);
  $pattern.mesh-set-corner-color-rgb( 3, 1, 1, 0);
  $pattern.mesh-end-patch;

  # Add a Gouraud-shaded triangle
  $pattern.mesh-begin-patch;
  $pattern.mesh-move-to( 100, 100);
  $pattern.mesh-line-to( 130, 130);
  $pattern.mesh-line-to( 130,  70);
  $pattern.mesh-set-corner-color-rgb( 0, 1, 0, 0);
  $pattern.mesh-set-corner-color-rgb( 1, 0, 1, 0);
  $pattern.mesh-set-corner-color-rgb( 2, 0, 0, 1);
  $pattern.mesh-end-patch;

When two patches overlap, the last one that has been added is drawn over the first one.

When a patch folds over itself, points are sorted depending on their parameter coordinates inside the patch. The v coordinate ranges from 0 to 1 when moving from side 3 to side 1; the u coordinate ranges from 0 to 1 when going from side 0 to side 2. Points with higher v coordinate hide points with lower v coordinate. When two points have the same v coordinate, the one with higher u coordinate is above. This means that points nearer to side 1 are above points nearer to side 3; when this is not sufficient to decide which point is above (for example when both points belong to side 1 or side 3) points nearer to side 2 are above points nearer to side 0.  For a complete definition of tensor-product patches, see the PDF specification (ISO32000), which describes the parametrization in detail.

Note: The coordinates are always in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<pattern-set-matrix()>.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory. The caller owns the returned object and should call C<pattern-destroy()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use C<pattern-status()>.

  multi method new ( :mesh! )


=end pod

#TM:1:new():
#TM:1:new(:rgb):
#TM:1:new(:rgba):
#TM:1:new(:linear):
#TM:1:new(:radial):
#TM:1:new(:surface):
#TM:1:new(:mesh):
#TM:4:new(:native-object):Gnome::N::TopLevelClassSupport
submethod BUILD ( *%options ) {

  # prevent creating wrong native-objects
  if self.^name eq 'Gnome::Cairo::Pattern' #`{{ or %options<CairoPattern> }} {

    # check if native object is set by a parent class
    if self.is-valid { }

    # process all options

    # check if common options are handled by some parent
    elsif %options<native-object>:exists { }

    else {
      my $no;

      # set rgba
      if %options<rgb>:exists {
        my @nums = |%options<rgb>;
        die X::Gnome.new(
          :message(':rgb needs 3 values')
        ) unless @nums.elems == 3;

        $no = _cairo_pattern_create_rgb(
          @nums[0].Num, @nums[1].Num, @nums[2].Num
        );
      }

      # set rgb
      elsif %options<rgba>:exists {
        my @nums = |%options<rgba>;
        die X::Gnome.new(
          :message(':rgb needs 4 values')
        ) unless @nums.elems == 4;

        $no = _cairo_pattern_create_rgba(
          @nums[0].Num, @nums[1].Num, @nums[2].Num, @nums[3].Num
        );
      }

      # linear gradient
      elsif %options<linear>:exists {
        my @linear = map { ($_//0).Num }, %options<linear>[^4];
        $no = _cairo_pattern_create_linear(|@linear);
      }

      # radial gradient
      elsif %options<radial>:exists {
        my @radial = map { ($_//0).Num }, %options<radial>[^6];
        $no = _cairo_pattern_create_radial(|@radial);
      }

      # surface
      elsif %options<surface>:exists {
        $no = %options<surface>;
        $no .= _get-native-object-no-reffing
          if $no.^can('_get-native-object-no-reffing');
        $no = _cairo_pattern_create_for_surface($no);
      }

      # mesh
      elsif %options<mesh>:exists {
        $no = _cairo_pattern_create_mesh;
      }

#      #`{{ use this when the module is not made inheritable
      # check if there are unknown options
      elsif %options.elems {
        die X::Gnome.new(
          :message(
            'Unsupported, undefined, incomplete or wrongly typed options for ' ~
            self.^name ~ ': ' ~ %options.keys.join(', ')
          )
        );
      }
#      }}

      #`{{ when there are no defaults use this
      # check if there are any options
      elsif %options.elems == 0 {
        die X::Gnome.new(:message('No options specified ' ~ self.^name));
      }
      }}

#      #`{{ when there are defaults use this instead
      # create default object
      else {
        $no = _cairo_pattern_create_rgb( 1e0, 1e0, 1e0);
      }
#      }}

      self._set-native-object($no);
    }

    # only after creating the native-object
#    self._set-class-info('CairoPattern');
  }
}

#-------------------------------------------------------------------------------
# no pod. user does not have to know about it.
method _fallback ( $native-sub is copy --> Callable ) {

  my Str $new-patt = $native-sub.subst( '_', '-', :g);

  my Callable $s;
  try { $s = &::("cairo_pattern_$native-sub"); };
  if ?$s {
    Gnome::N::deprecate(
      "cairo_pattern_$native-sub", $new-patt, '0.2.8', '0.3.0'
    );
  }

  else {
    try { $s = &::("cairo_$native-sub"); } unless ?$s;
    if ?$s {
      Gnome::N::deprecate(
        "cairo_$native-sub", $new-patt.subst('pattern-'),
        '0.2.8', '0.3.0'
      );
    }

    else {
      try { $s = &::($native-sub); } if !$s and $native-sub ~~ m/^ 'cairo_' /;
      if ?$s {
        Gnome::N::deprecate(
          "$native-sub", $new-patt.subst('cairo-pattern-'),
          '0.2.8', '0.3.0'
        );
      }
    }
  }

#  self._set-class-name-of-sub('CairoPattern');
  $s = callsame unless ?$s;

  $s;
}

#-------------------------------------------------------------------------------
method native-object-ref ( $no ) {
  _cairo_pattern_reference($no)
}

#-------------------------------------------------------------------------------
method native-object-unref ( $no ) {
  _cairo_pattern_destroy($no)
}


#-------------------------------------------------------------------------------
#TM:0:add-color-stop-rgb:
=begin pod
=head2 add-color-stop-rgb

Adds an opaque color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (x0,y0) to (x1,y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.  The color is specified in the same way as in C<set-source-rgb()>.  If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.   Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of C<CAIRO_STATUS_PATTERN_TYPE_MISMATCH>.

  method add-color-stop-rgb ( Num $offset, Num $red, Num $green, Num $blue )

=item $offset; an offset in the range [0.0 .. 1.0]
=item $red; red component of color
=item $green; green component of color
=item $blue; blue component of color
=end pod

method add-color-stop-rgb ( Num $offset, Num $red, Num $green, Num $blue ) {

  cairo_pattern_add_color_stop_rgb(
    self._get-native-object-no-reffing, $offset, $red, $green, $blue
  )
}

sub cairo_pattern_add_color_stop_rgb (
  cairo_pattern_t $pattern, gdouble $offset, gdouble $red, gdouble $green, gdouble $blue
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:add-color-stop-rgba:
=begin pod
=head2 add-color-stop-rgba

Adds a translucent color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (x0,y0) to (x1,y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.  The color is specified in the same way as in C<set-source-rgba()>.  If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.  Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of C<CAIRO_STATUS_PATTERN_TYPE_MISMATCH>.

  method add-color-stop-rgba ( Num $offset, Num $red, Num $green, Num $blue, Num $alpha )

=item $offset; an offset in the range [0.0 .. 1.0]
=item $red; red component of color
=item $green; green component of color
=item $blue; blue component of color
=item $alpha; alpha component of color
=end pod

method add-color-stop-rgba ( Num $offset, Num $red, Num $green, Num $blue, Num $alpha ) {

  cairo_pattern_add_color_stop_rgba(
    self._get-native-object-no-reffing, $offset, $red, $green, $blue, $alpha
  )
}

sub cairo_pattern_add_color_stop_rgba (
  cairo_pattern_t $pattern, gdouble $offset, gdouble $red, gdouble $green, gdouble $blue, gdouble $alpha
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_pattern_create_for_surface:
#`{{
=begin pod
=head2 create-for-surface

Create a new B<cairo_pattern_t> for the given surface.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory.  The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error.  To inspect the status of a pattern use C<status()>.

  method create-for-surface ( cairo_surface_t $surface --> cairo_pattern_t )

=item cairo_surface_t $surface;  cairo_pattern_create_for_surface:
=end pod

method create-for-surface ( cairo_surface_t $surface --> cairo_pattern_t ) {

  cairo_pattern_create_for_surface(
    self._get-native-object-no-reffing, $surface
  )
}
}}

sub _cairo_pattern_create_for_surface (
  cairo_surface_t $surface --> cairo_pattern_t
) is native(&cairo-lib)
  is symbol('cairo_pattern_create_for_surface')
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_pattern_create_linear:
#`{{
=begin pod
=head2 create-linear

Create a new linear gradient B<cairo_pattern_t> along the line defined by (x0, y0) and (x1, y1).  Before using the gradient pattern, a number of color stops should be defined using C<add-color-stop-rgb()> or C<add-color-stop-rgba()>.  Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<set-matrix()>.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory.  The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error.  To inspect the status of a pattern use C<status()>.

  method create-linear ( Num $x0, Num $y0, Num $x1, Num $y1 --> cairo_pattern_t )

=item Num $x0;  cairo_pattern_create_linear:
=item Num $y0; x coordinate of the start point
=item Num $x1; y coordinate of the start point
=item Num $y1; x coordinate of the end point
=end pod

method create-linear ( Num $x0, Num $y0, Num $x1, Num $y1 --> cairo_pattern_t ) {

  cairo_pattern_create_linear(
    self._get-native-object-no-reffing, $x0, $y0, $x1, $y1
  )
}
}}

sub _cairo_pattern_create_linear (
  gdouble $x0, gdouble $y0, gdouble $x1, gdouble $y1 --> cairo_pattern_t
) is native(&cairo-lib)
  is symbol('cairo_pattern_create_linear')
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_pattern_create_mesh:
#`{{
=begin pod
=head2 create-mesh

Create a new mesh pattern.  Mesh patterns are tensor-product patch meshes (type 7 shadings in PDF). Mesh patterns may also be used to create other types of shadings that are special cases of tensor-product patch meshes such as Coons patch meshes (type 6 shading in PDF) and Gouraud-shaded triangle meshes (type 4 and 5 shadings in PDF).  Mesh patterns consist of one or more tensor-product patches, which should be defined before using the mesh pattern. Using a mesh pattern with a partially defined patch as source or mask will put the context in an error status with a status of C<CAIRO_STATUS_INVALID_MESH_CONSTRUCTION>.  A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, 3) and by 4 additional control points (P0, P1, P2, P3) that provide further control over the patch and complete the definition of the tensor-product patch. The corner C0 is the first point of the patch.  Degenerate sides are permitted so straight lines may be used. A zero length line on one side may be used to create 3 sided patches.

 C1     Side 1       C2 +---------------+ |               | |  P1       P2  | |               | Side 0 |               | Side 2 |               | |               | |  P0       P3  | |               | +---------------+ C0     Side 3        C3

   Each patch is constructed by first calling C<mesh-begin-patch()>, then C<mesh-move-to()> to specify the first point in the patch (C0). Then the sides are specified with calls to C<mesh-curve-to()> and C<mesh-line-to()>.  The four additional control points (P0, P1, P2, P3) in a patch can be specified with C<mesh-set-control-point()>.  At each corner of the patch (C0, C1, C2, C3) a color may be specified with C<mesh-set-corner-color-rgb()> or C<mesh-set-corner-color-rgba()>. Any corner whose color is not explicitly specified defaults to transparent black.  A Coons patch is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch. The default value for any control point not specified is the implicit value for a Coons patch, i.e. if no control points are specified the patch is a Coons patch.  A triangle is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch, all the sides are lines and one of them has length 0, i.e. if the patch is specified using just 3 lines, it is a triangle. If the corners connected by the 0-length side have the same color, the patch is a Gouraud-shaded triangle.  Patches may be oriented differently to the above diagram. For example the first point could be at the top left. The diagram only shows the relationship between the sides, corners and control points. Regardless of where the first point is located, when specifying colors, corner 0 will always be the first point, corner 1 the point between side 0 and side 1 etc.  Calling C<mesh-end-patch()> completes the current patch. If less than 4 sides have been defined, the first missing side is defined as a line from the current point to the first point of the patch (C0) and the other sides are degenerate lines from C0 to C0. The corners between the added sides will all be coincident with C0 of the patch and their color will be set to be the same as the color of C0.  Additional patches may be added with additional calls to C<mesh-begin-patch()>/C<mesh-end-patch()>.

 cairo_pattern_t *pattern = C<create-mesh()>;  /&ast; Add a Coons patch &ast;/ cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 0, 0); cairo_mesh_pattern_curve_to (pattern, 30, -30,  60,  30, 100, 0); cairo_mesh_pattern_curve_to (pattern, 60,  30, 130,  60, 100, 100); cairo_mesh_pattern_curve_to (pattern, 60,  70,  30, 130,   0, 100); cairo_mesh_pattern_curve_to (pattern, 30,  70, -30,  30,   0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern);  /&ast; Add a Gouraud-shaded triangle &ast;/ cairo_mesh_pattern_begin_patch (pattern) cairo_mesh_pattern_move_to (pattern, 100, 100); cairo_mesh_pattern_line_to (pattern, 130, 130); cairo_mesh_pattern_line_to (pattern, 130,  70); cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); cairo_mesh_pattern_end_patch (pattern)

   When two patches overlap, the last one that has been added is drawn over the first one.  When a patch folds over itself, points are sorted depending on their parameter coordinates inside the patch. The v coordinate ranges from 0 to 1 when moving from side 3 to side 1; the u coordinate ranges from 0 to 1 when going from side 0 to side 2. Points with higher v coordinate hide points with lower v coordinate. When two points have the same v coordinate, the one with higher u coordinate is above. This means that points nearer to side 1 are above points nearer to side 3; when this is not sufficient to decide which point is above (for example when both points belong to side 1 or side 3) points nearer to side 2 are above points nearer to side 0.  For a complete definition of tensor-product patches, see the PDF specification (ISO32000), which describes the parametrization in detail.  Note: The coordinates are always in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<set-matrix()>.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory. The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use C<status()>.

  method create-mesh ( --> cairo_pattern_t )

=end pod

method create-mesh ( --> cairo_pattern_t ) {

  cairo_pattern_create_mesh(
    self._get-native-object-no-reffing,
  )
}
}}

sub _cairo_pattern_create_mesh (
   --> cairo_pattern_t
) is native(&cairo-lib)
  is symbol('cairo_pattern_create_mesh')
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_pattern_create_radial:
#`{{
=begin pod
=head2 create-radial

Creates a new radial gradient B<cairo_pattern_t> between the two circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1).  Before using the gradient pattern, a number of color stops should be defined using C<add-color-stop-rgb()> or C<add-color-stop-rgba()>.  Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with C<set-matrix()>.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory.  The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error.  To inspect the status of a pattern use C<status()>.

  method create-radial ( Num $cx0, Num $cy0, Num $radius0, Num $cx1, Num $cy1, Num $radius1 --> cairo_pattern_t )

=item Num $cx0;  cairo_pattern_create_radial:
=item Num $cy0; x coordinate for the center of the start circle
=item Num $radius0; y coordinate for the center of the start circle
=item Num $cx1; radius of the start circle
=item Num $cy1; x coordinate for the center of the end circle
=item Num $radius1; y coordinate for the center of the end circle
=end pod

method create-radial ( Num $cx0, Num $cy0, Num $radius0, Num $cx1, Num $cy1, Num $radius1 --> cairo_pattern_t ) {

  cairo_pattern_create_radial(
    self._get-native-object-no-reffing, $cx0, $cy0, $radius0, $cx1, $cy1, $radius1
  )
}
}}

sub _cairo_pattern_create_radial (
  gdouble $cx0, gdouble $cy0, gdouble $radius0, gdouble $cx1, gdouble $cy1, gdouble $radius1 --> cairo_pattern_t
) is native(&cairo-lib)
  is symbol('cairo_pattern_create_radial')
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_pattern_create_rgb:
#`{{
=begin pod
=head2 create-rgb

Creates a new B<cairo_pattern_t> corresponding to an opaque color.  The color components are floating point numbers in the range 0 to 1. If the values passed in are outside that range, they will be clamped.  Return value: the newly created B<cairo_pattern_t> if successful, or an error pattern in case of no memory.  The caller owns the returned object and should call C<clear-object()> when finished with it.  This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error.  To inspect the status of a pattern use C<status()>.

  method create-rgb ( Num $red, Num $green, Num $blue --> cairo_pattern_t )

=item Num $red;  cairo_pattern_create_rgb:
=item Num $green; red component of the color
=item Num $blue; green component of the color
=end pod

method create-rgb ( Num $red, Num $green, Num $blue --> cairo_pattern_t ) {

  cairo_pattern_create_rgb(
    self._get-native-object-no-reffing, $red, $green, $blue
  )
}
}}

sub _cairo_pattern_create_rgb (
  gdouble $red, gdouble $green, gdouble $blue --> cairo_pattern_t
) is native(&cairo-lib)
  is symbol('cairo_pattern_create_rgb')
  { * }

#-------------------------------------------------------------------------------
#