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

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

use wxSTAY_ON_TOP on preview.

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             wxSTAY_ON_TOP
35         /;
36
37__PACKAGE__->mk_accessors( 
38    qw/
39          image
40          image_size
41          caption
42      / 
43);
44use Data::Dumper;
45use Wx::Event qw/
46   EVT_PAINT
47   EVT_SIZE
48/;
49
50sub new {
51    my( $class, $params ) = @_;
52    my( $self ) = $class->SUPER::new(
53        undef,
54        -1,
55        $params->{caption},
56        wxDefaultPosition,
57        [400,300],
58             wxMAXIMIZE_BOX|
59             wxMINIMIZE_BOX|
60             wxRESIZE_BORDER|
61             wxDEFAULT_DIALOG_STYLE|
62             wxDIALOG_NO_PARENT|
63             wxSTAY_ON_TOP
64    );
65
66    $self->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
67
68    Wx::InitAllImageHandlers();
69
70    EVT_SIZE($self, sub {
71            my ( $this, $event ) = @_;
72   
73            $this->Refresh;
74            $event->Skip();
75        }
76    );
77
78
79  EVT_PAINT(
80      $self, 
81      sub { 
82          my ( $this, $event ) = @_;
83
84          my $dc = Wx::AutoBufferedPaintDC->new($this);
85          if($this->image){
86     
87              my ($w, $h) = $this->GetSizeWH;
88              my $p_prop = $w / $h;
89     
90              # calculation made to keep aspect           
91              # ratio and maximize image size
92     
93              my $scale;
94              my ($img_w, $img_h) = @{$this->image_size};
95              return unless $img_w;
96              return unless $img_h;
97
98              my $img_prop = $img_w / $img_h;
99     
100              $scale = ($p_prop > $img_prop)
101              ? ($h / $img_h)
102              : ($w / $img_w);
103     
104              $scale = 1 if($scale > 1);
105     
106              my ($sw, $sh) = map({$_ * $scale} $img_w, $img_h);
107              my $bmp = Wx::Bitmap->new($this->image->Scale($sw, $sh, wxIMAGE_QUALITY_HIGH));
108              my $xoff = ($w - $sw) / 2;
109              my $yoff = ($h - $sh) / 2;
110              $dc->DrawBitmap($bmp, $xoff, $yoff, $dc->Clear ? 1:1);
111          }
112          else{
113              $dc->Clear;
114          }
115      }
116  );
117
118 
119  $self;
120}
121
122
1231;
Note: See TracBrowser for help on using the repository browser.