source: extensions/pLoader/trunk/src/Uploader/GUI/wxImagePreview.pm @ 5538

Last change on this file since 5538 was 5538, checked in by ronosman, 14 years ago

Feature 1562 : remove STAY_ON_TOP attribute.

File size: 3.7 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::GUI::wxImagePreview;
21use strict;
22use base qw/Wx::Dialog Class::Accessor::Fast/;
23use Wx qw/
24             wxDefaultPosition
25             wxDefaultSize
26             wxBG_STYLE_CUSTOM
27             wxIMAGE_QUALITY_HIGH
28             wxRESIZE_BORDER
29             wxDIALOG_EX_METAL
30             wxDIALOG_NO_PARENT
31             wxDEFAULT_DIALOG_STYLE
32             wxMAXIMIZE_BOX
33             wxMINIMIZE_BOX
34         /;
35
36__PACKAGE__->mk_accessors( 
37    qw/
38          image
39          image_size
40          caption
41      / 
42);
43use Data::Dumper;
44use Wx::Event qw/
45   EVT_PAINT
46   EVT_SIZE
47/;
48
49sub new {
50    my( $class, $params ) = @_;
51    my( $self ) = $class->SUPER::new(
52        undef,
53        -1,
54        $params->{caption},
55        wxDefaultPosition,
56        [400,300],
57             wxMAXIMIZE_BOX|
58             wxMINIMIZE_BOX|
59             wxRESIZE_BORDER|
60             wxDEFAULT_DIALOG_STYLE|
61             wxDIALOG_NO_PARENT
62    );
63
64    $self->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
65
66    Wx::InitAllImageHandlers();
67
68    EVT_SIZE($self, sub {
69            my ( $this, $event ) = @_;
70   
71            $this->Refresh;
72            $event->Skip();
73        }
74    );
75
76
77  EVT_PAINT(
78      $self, 
79      sub { 
80          my ( $this, $event ) = @_;
81
82          my $dc = Wx::AutoBufferedPaintDC->new($this);
83          if($this->image){
84     
85              my ($w, $h) = $this->GetSizeWH;
86              my $p_prop = $w / $h;
87     
88              # calculation made to keep aspect           
89              # ratio and maximize image size
90     
91              my $scale;
92              my ($img_w, $img_h) = @{$this->image_size};
93              return unless $img_w;
94              return unless $img_h;
95
96              my $img_prop = $img_w / $img_h;
97     
98              $scale = ($p_prop > $img_prop)
99              ? ($h / $img_h)
100              : ($w / $img_w);
101     
102              $scale = 1 if($scale > 1);
103     
104              my ($sw, $sh) = map({$_ * $scale} $img_w, $img_h);
105              my $bmp = Wx::Bitmap->new($this->image->Scale($sw, $sh, wxIMAGE_QUALITY_HIGH));
106              my $xoff = ($w - $sw) / 2;
107              my $yoff = ($h - $sh) / 2;
108              $dc->DrawBitmap($bmp, $xoff, $yoff, $dc->Clear ? 1:1);
109          }
110          else{
111              $dc->Clear;
112          }
113      }
114  );
115
116 
117  $self;
118}
119
120
1211;
Note: See TracBrowser for help on using the repository browser.