### ----------------------------------------------------
### -- Gnome::Cairo
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: t/Pattern.rakutest
### ----------------------------------------------------
use v6;
use NativeCall;
use Test;

use Gnome::Cairo::Pattern:api<1>;
use Gnome::Cairo::ImageSurface:api<1>;
use Gnome::Cairo::Types:api<1>;
use Gnome::Cairo::Enums:api<1>;
use Gnome::Cairo;
#use Gnome::Cairo::Matrix:api<1>;

#use Gnome::N::X:api<1>;
#Gnome::N::debug(:on);

#-------------------------------------------------------------------------------
my Gnome::Cairo::Pattern $p;
my Gnome::Cairo::ImageSurface $is;
#-------------------------------------------------------------------------------
subtest 'ISA test', {
  $p .= new;
  isa-ok $p, Gnome::Cairo::Pattern, '.new()';
  ok $p.is-valid, '.is-valid()';
  $p.clear-object;
  nok $p.is-valid, '.clear-object()';

  $p .= new(:rgb( 1, 0.5, 0.5e0));
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:rgb)';

  $p .= new(:rgba( 1, 0.5, 0.5e0, '0.8'));
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:rgba)';
  $p.clear-object;

  $p .= new(:linear( 1, 5, 0.5e2, '30.4'));
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:linear)';
  $p.clear-object;

  $p .= new(:radial( 1, 1, 5, 10, 10, 5));
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:radial)';
  $p.clear-object;

  $p .= new(:mesh);
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:mesh)';
  $p.clear-object;

  $is .= new( :format(CAIRO_FORMAT_ARGB32), :width(128), :height(128));
  $p .= new(:surface($is));
  isa-ok $p, Gnome::Cairo::Pattern, '.new(:surface)';
  $p.clear-object;
}

#-------------------------------------------------------------------------------
# set environment variable 'raku-test-all' if rest must be tested too.
unless %*ENV<raku_test_all>:exists {
  done-testing;
  exit;
}

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  $p .= new(:mesh);

  $p.mesh-begin-patch;
  $p.mesh-move-to( 100e0, 100e0);
  $p.mesh-line-to( 130e0, 130e0);
  $p.mesh-line-to( 130e0,  70e0);
  $p.mesh-set-corner-color-rgb( 0, 1e0, 0e0, 0e0);
  $p.mesh-set-corner-color-rgb( 1, 0e0, 1e0, 0e0);
  $p.mesh-set-corner-color-rgb( 2, 0e0, 0e0, 1e0);
  $p.mesh-end-patch;

  is $p.get-type, CAIRO_PATTERN_TYPE_MESH, '.get-type()';

#  my Gnome::Cairo::Matrix $m .= new(:native-object($p.get-matrix));

  my ( $is2, $sts) = $p.get-surface;
  ok 1, '.get-surface(): ' ~ $sts;
#  my Gnome::Cairo $context .= new(:surface($is2));
#  $context.write-png('t/data/pattern01.png');
#  $is2.write-to-png('t/data/pattern01.png');

  $p.clear-object;
}

#-------------------------------------------------------------------------------
done-testing;

=finish


