Skip to content

Instantly share code, notes, and snippets.

@robn
Created September 15, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robn/23cc9325be36d7606905 to your computer and use it in GitHub Desktop.
Save robn/23cc9325be36d7606905 to your computer and use it in GitHub Desktop.
Clutter-perl gravity transition test (port of clutter image-content sample)
#!/usr/bin/env perl
use 5.020;
use warnings;
use strict;
use Clutter;
use Imager;
my @gravities = qw(
top-left top top-right
left center right
bottom-left bottom bottom-right
resize-fill resize-aspect
);
my $cur_gravity = 0;
Clutter::init;
my $stage = Clutter::Stage->new;
$stage->set_name("Stage");
$stage->set_title("Content Box");
$stage->set_user_resizable(1);
$stage->set_margin_top(12);
$stage->set_margin_right(12);
$stage->set_margin_bottom(12);
$stage->set_margin_left(12);
$stage->show;
my $imgfile = Imager->new(file => "/home/robn/amazingsponsors.jpg");
my $imgraw;
$imgfile->write(type => "raw", data => \$imgraw);
my @bytes = unpack "C*", $imgraw;
my $image = Clutter::Image::new;
$image->set_data(
\@bytes,
"rgb-888",
$imgfile->getwidth,
$imgfile->getheight,
$imgfile->getwidth * 3,
);
$stage->set_content_scaling_filters("trilinear", "linear");
$stage->set_content_gravity($gravities[$#gravities]);
$stage->set_content($image);
my $text = Clutter::Text->new;
$text->set_text("Content gravity: $gravities[$#gravities]");
$text->set_color([Clutter::Color::from_string("red")]->[1]);
$text->add_constraint(Clutter::AlignConstraint->new($stage, "both", 0.5));
$stage->add_child($text);
my $action = Clutter::TapAction->new;
$action->signal_connect("tap", sub {
$stage->save_easing_state;
$stage->set_content_gravity($gravities[$cur_gravity]);
$stage->restore_easing_state;
$text->set_text("Content gravity: $gravities[$cur_gravity]");
$cur_gravity = ($cur_gravity+1) % @gravities;
});
$stage->add_action($action);
Clutter::main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment