Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

perl wxImagePanelDemo.pl
perl wxImagePanelDemo.pl foo.gif
#!/usr/bin/perl -- ## http://wiki.wxwidgets.org/An_image_panel use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { Wx::InitAllImageHandlers(); my( $file ) = @_; $file ||= Wx::Image->new( Wx::GetWxPerlIcon() )->Scale(240,240); my $frame = Wx::Frame->new( undef, -1, "Hello wxDC", [ 50, 50 ], [ 500, 500 ], ); my $filepane = wIP->new( $frame, $file ); my $iconpane = wIP->new( $frame, Wx::Image->new( Wx::GetWxPerlIcon +() ) ); my $sizer = Wx::BoxSizer->new( Wx::wxVERTICAL() ); my $icon_sizer = Wx::BoxSizer->new( Wx::wxHORIZONTAL() ); for( 1..3){ $icon_sizer->AddSpacer( 30 * $_ ); $icon_sizer->Add( Wx::Button->new( $iconpane, -1, "yo $_" ) ); } $iconpane->SetSizer( $icon_sizer ); $sizer->Add( $filepane, 1, Wx::wxEXPAND() ); $sizer->Add( $iconpane, 1, Wx::wxEXPAND() ); my $pthree = wIP->new( $frame, Wx::Image->new( Wx::GetWxPerlIcon() + ) ); my $pthree_sizer = Wx::BoxSizer->new( Wx::wxHORIZONTAL() ); $pthree_sizer->Add( wIP->new( $pthree, Wx::Image->new( Wx::GetWxPerlIcon() ) )->noscale, ); my $pfunk = wIP->new( $pthree, Wx::Image->new( Wx::GetWxPerlIcon() + ) ); $pthree_sizer->Add( $pfunk, 1, Wx::wxEXPAND(), ); $pthree_sizer->Add( wIP->new( $pthree, Wx::Image->new( Wx::GetWxPerlIcon() ) )->noscale, ); $pthree->SetSizer( $pthree_sizer ); $pthree_sizer->Layout; $pthree_sizer->Show(2); $pthree_sizer->Show(3); $pthree_sizer->Show(4); $sizer->Add( $pthree, 0, Wx::wxEXPAND() ); $frame->SetSizer( $sizer ); $frame->Show(); my $app = Wx::SimpleApp->new; $app->MainLoop; eval { wIP->new(undef,bless[],'purple::hedgehog') ; 1 } or warn $@ +; wIP->new(); ## purple hedgehog } ## end sub Main package wIP; use Wx; use Carp qw/ croak /; use base qw/ Wx::Panel /; sub new { my( $class, $parent, $fileOrImage ) = @_; my $self = $class->SUPER::new( $parent, -1 ); if( ref $fileOrImage ) { $fileOrImage->isa( 'Wx::Image' ) or croak "$fileOrImage not isa Wx::Image"; $self->{image} = $fileOrImage; } elsif( defined $fileOrImage and length $fileOrImage ) { $self->{file} = $fileOrImage; $self->{image} = Wx::Image->new; $self->{image}->LoadFile( $fileOrImage, Wx::wxBITMAP_TYPE_ANY( +), -1 ); } else { croak 'Usage: wIP::new( CLASS, $parent, $filenameOrImage ); '; } $self->{bitmap} = Wx::Bitmap->new( $self->{image} ); $self->{height} = -1; $self->{width} = -1; $self->{transparent} = !! ( $self->{image}->HasAlpha || $self->{image}->HasMask ); Wx::Event::EVT_SIZE( $self, \&wIP::onSize ); Wx::Event::EVT_PAINT( $self, \&wIP::onPaint ); bless $self, $class; return $self; } ## end sub new sub onSize { my( $self, $evt ) = @_; $self->Refresh; $evt->Skip; } sub onPaint { my( $self, $evt ) = @_; my $dc = Wx::PaintDC->new( $self ); my( $n_width, $n_height ) = $dc->GetSizeWH; if( $self->{width} != $n_width or $self->{height} != $n_height ) { unless( $self->{noscale} ){ $self->{bitmap} = Wx::Bitmap->new( $self->{image}->Scale( $n_width, $n_height, ) ); $self->{width} = $n_width; $self->{height} = $n_height; } $dc->DrawBitmap( $self->{bitmap}, 0, 0, $self->{transparent} ) +; } else { $dc->DrawBitmap( $self->{bitmap}, 0, 0, $self->{transparent} ) +; } } sub noscale { my( $self ) = @_; $self->{noscale} = !! 1; $self->SetMinSize( [ $self->{image}->GetWidth, $self->{image}->GetHeight, ] ); return $self; } =head1 NAME wIP - wxImagePanel - display image in a panel, autoscaled or not, back +ground image =head1 METHODS =head2 C<<< new >>> wIP->new( $parent, $filename ); wIP->new( $parent, $filenameOrImage ); wIP->new( $parent, Wx::Image->new( Wx::GetWxPerlIcon() ) ) =head2 C<<< noscale >>> wIP->new( ... )->noscale =cut

In reply to Re: wxPerl: how to display a resizing image? (wxImagePanelDemo.pl) by Anonymous Monk
in thread wxPerl: how to display a resizing image? (StaticBitmap doesn't seem to work)? by HelenCr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2014-09-22 23:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (208 votes), past polls