Help language development. Donate to The Perl Foundation

Gnome::Cairo cpan:MARTIMM last updated on 2022-02-20

t/Pattern.rakutest
use v6;
use NativeCall;
use Test;

use Gnome::Cairo::Pattern;
use Gnome::Cairo::ImageSurface;
use Gnome::Cairo::Types;
use Gnome::Cairo::Enums;
use Gnome::Cairo;
#use Gnome::Cairo::Matrix;

#use Gnome::N::X;
#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