Tk

 view release on metacpan or  search on metacpan

demos/demos/widget_lib/transtile.pl  view on Meta::CPAN

# transtile.pl

use vars qw/$TOP/;

sub transtile {

    # Create a top-level window that demonstrates tiles
    # and transparent stuff.

    my($demo) = @_;
    $TOP = $MW->WidgetDemo(
        -name     => $demo,
        -text     => ['This window demonstrates tiles and transparent images. The Canvas has a yellow background, which displays for one second before it\'s overlayed with a tile of tiny camels. On top of the tile layer are three non-transparent imag...
        -title    => 'Tile and Transparent Demonstration',
        -iconname => 'transtile',
    );

    my $tile = $TOP->Photo(-file =>Tk->findINC('Camel.xpm'));

    # A tiled Canvas - the tile overlays the background color.

    my $c = $TOP->Canvas(
        -background  => 'yellow',
        -width       => 300,
        -height      => 250,
        -relief      => 'raised',
        -borderwidth => 3,
    )->grid;
    $c->update;
    $c->after(1000);
    $c->configure(-tile => $tile);

    # These images are not transparent, thus they obscure the tile
    # or background.

    my($x, $y) = (30, 30);
    foreach (qw/Xcamel.gif anim.gif icon.gif/) {
	$c->createImage($x, $y, -image => $TOP->Photo(-file => Tk->findINC($_)));
	$x += 50;
	$y += 50;
    }

    # Transparent Canvas items do not generate events.

    my $cb = sub {
	print "Over circle, args = @_!\n";
    };

    # Not filled (transparent), no events.

    my $o1 = $c->createOval(25, 25, 100, 100,
        -outline => 'red',
    );
    $c->bind($o1, '<Motion>' => $cb);

    # Filled (non-transparent), but with events.

    my $o2 = $c->createOval(155, 25, 225, 100,
        -outline => 'red',
        -fill    => 'blue',
    );
    $c->bind($o2, '<Motion>' => $cb);

    # Transparently filled, with events.

    my $o3 = $c->createOval(25, 120, 100, 195,
        -outline => 'red',
        -fill    => 'blue',
        -stipple => 'transparent',
    );
    $c->bind($o3, '<Motion>' => $cb);

    # A transparent GIF overlaying everything.

    $c->createImage(300, 300,
        -image => $TOP->Photo(-data => &encoded_gif, -format => 'gif'),
	-anchor => 'se',
    );

} # end transtile

sub encoded_gif {

    # A Base64 encoded transparent GIF.

    my $gif =  <<'END_OF_GIF';
R0lGODlh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MW6YGCiGtGj25q6TGHov+bLLKLstss2ziOWhc0gn7YXif4morhpyWxtmqrz57Z7hD
flcjq1jC+S2sM8rI7rnuLucporNyWuypmy7mbK/57stvv/7+C3DAAvd1r4S/9gnSXAe3ieKG2MJn
Im21MvwJqKPeoqeWpbpp8Z8Z3thuqCJOuy0iGmf8o70UlfswvL6m22+9A89Mc80231yXzKLKiyvJ
OieMMp/AtjcsphZ+7LGP3oqJ9K3oxSvgpRdfNrTQRe+p67uoRlsxzEFSm9ycC+/7M85mn4122mqv
zfZXbSOWM89rUez2hE4j2bTS3zK9Zt5kvmcuk1NP5dzghFlLb8lf6+2i39q2KnXfks8fCzTCIx89
ude56Vv51W9/Dnrooo9Oeummn4566g4UAAA7
END_OF_GIF

    return $gif;

} # end encoded_gif

1;



( run in 0.504 second using v1.01-cache-2.11-cpan-e93a5daba3e )