#!/usr/bin/perl -- use strict; use warnings; use File::Spec; use Wx (); Main( @ARGV ); exit( 0 ); sub Main { TakeScreenshot( @_ ); Messup() ; TakeScreenshot( 'messup.png' ); } sub TakeScreenshot { use Wx (); Wx::InitAllImageHandlers(); my $screen = Wx::ScreenDC->new(); my( $x, $y) = $screen->GetSizeWH(); my $bitmap = Wx::Bitmap->new($x,$y,-1); my $memory = Wx::MemoryDC->new(); $memory->SelectObject( $bitmap ); $memory->Blit(0,0,$x,$y, $screen, 0, 0); #~ my $image = Wx::Image->new( $bitmap ); ## deprecated my $image = $bitmap->ConvertToImage; @_ or @_ = FileDialog(); for my $file( @_ ){ my $file = File::Spec->rel2abs( $file ); $image->SaveFile( $file ) or do { warn "Couldn't save $file : unsupported\n"; unlink $file; next; }; print "saved $file\n"; } } sub FileDialog { #~ http://docs.wxwidgets.org/trunk/classwx_file_dialog.html# wxWidgets: wxWidgets: wxFileDialog Class Reference my $fd = Wx::FileDialog->new( undef, "where to save screenshot?", "", # defaultDir "screenshot.png", # defaultFile "", # wildcard, limited on motif # style Wx::wxFD_MULTIPLE() | Wx::wxFD_SAVE() | Wx::wxFD_OVERWRITE_PROMPT() , #~ "", # pos #~ "", # size #~ "", # name ); $fd->ShowModal; $fd->GetPaths; }; sub Messup { my $screen = Wx::ScreenDC->new(); $screen->SetBackgroundMode( Wx::wxTRANSPARENT() ); $screen->SetFont(Wx::Font->new( 40, Wx::wxDECORATIVE(), Wx::wxNORMAL(), Wx::wxBOLD(), 0 )); my $mmmsss = 1; my $yoff = 100; for(1..255){ my $c = $_; $screen->SetTextForeground( Wx::Colour->newRGB(0,0,$c)); $screen->DrawRotatedText("wxPerl",100+$_ , $yoff ,$_); $screen->DrawRotatedText("wxPerl and PodMaster",100+$_ ,$yoff + 20 ,0); $screen->DrawRotatedText("are messing up your screen",100+$_ , $yoff + 50 ,0); Wx::Usleep($mmmsss); } $yoff = 200; for(1..255){ my $c = $_; $screen->SetTextForeground( Wx::Colour->newRGB(0,$c,0)); $screen->DrawRotatedText("wxPerl",40+$_ , $yoff ,$_); $screen->DrawRotatedText("wxPerl and PodMaster",40+$_ ,$yoff + 20 ,0); $screen->DrawRotatedText("are messing up your screen",40+$_ , $yoff + 50 ,0); Wx::Usleep($mmmsss) if 1 == $_ % 4; } $yoff = 300; for(1..255){ my $c = $_; my $yo = ($_/2); $yo = -$yo if $_ < 100; $screen->SetTextForeground( Wx::Colour->newRGB($c,0,0)); if( $_ == 255 ){ $screen->SetTextForeground( Wx::Colour->newRGB( 255, 208, 255 ) ); #FFD0FF } $screen->DrawRotatedText("wxPerl", 10+$_ ,$yoff+$yo ,$_); $screen->DrawRotatedText("and Anonymous Monk", 10+$_ ,$yoff+40+$yo ,0); $screen->DrawRotatedText("are messing up your screen",10+$_ ,$yoff+90+$yo ,0); Wx::Usleep($mmmsss); } return 0; }