Fix background logo on wxMSW.

Wx::StaticText + Wx::StaticBitmap does not support transparent backgrounds on wxMSW; fixed by using a custom paint routine instead.
This commit is contained in:
Henrik Brix Andersen 2012-07-08 19:41:13 +02:00
parent 0982203f76
commit cd7ea418e2

View File

@ -136,8 +136,8 @@ sub new {
} }
package Slic3r::GUI::ConfigWizard::Index; package Slic3r::GUI::ConfigWizard::Index;
use Wx qw(:bitmap :font :misc :sizer :systemsettings :window); use Wx qw(:bitmap :dc :font :misc :sizer :systemsettings :window);
use Wx::Event qw(EVT_ERASE_BACKGROUND); use Wx::Event qw(EVT_ERASE_BACKGROUND EVT_PAINT);
use base 'Wx::Panel'; use base 'Wx::Panel';
sub new { sub new {
@ -145,60 +145,68 @@ sub new {
my ($parent, $title) = @_; my ($parent, $title) = @_;
my $self = $class->SUPER::new($parent); my $self = $class->SUPER::new($parent);
$self->{sizer} = Wx::FlexGridSizer->new(0, 2, 5, 0); push @{$self->{titles}}, $title;
$self->SetSizer($self->{sizer}); $self->{own_index} = 0;
my $bitmap = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new("$Slic3r::var/bullet_blue.png", wxBITMAP_TYPE_PNG)); $self->{bullets}->{before} = Wx::Bitmap->new("$Slic3r::var/bullet_black.png", wxBITMAP_TYPE_PNG);
$self->{sizer}->Add($bitmap, 0, wxALIGN_CENTER_VERTICAL, 0); $self->{bullets}->{own} = Wx::Bitmap->new("$Slic3r::var/bullet_blue.png", wxBITMAP_TYPE_PNG);
$self->{bullets}->{after} = Wx::Bitmap->new("$Slic3r::var/bullet_white.png", wxBITMAP_TYPE_PNG);
my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize);
$self->{sizer}->Add($text, 0, wxALIGN_CENTER_VERTICAL, 0);
$self->SetBackgroundStyle(wxBG_STYLE_CUSTOM) if &Wx::wxGTK;
$self->{background} = Wx::Bitmap->new("$Slic3r::var/Slic3r_192px_transparent.png", wxBITMAP_TYPE_PNG); $self->{background} = Wx::Bitmap->new("$Slic3r::var/Slic3r_192px_transparent.png", wxBITMAP_TYPE_PNG);
$self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight)); $self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight));
EVT_ERASE_BACKGROUND($self, \&on_erase_background);
EVT_PAINT($self, \&repaint);
return $self; return $self;
} }
sub on_erase_background { sub repaint {
my ($self, $event) = @_; my ($self, $event) = @_;
my $size = $self->GetClientSize;
my $gab = 5;
my $dc = $event->GetDC; my $dc = Wx::PaintDC->new($self);
unless (defined $dc) { $dc->SetBackgroundMode(wxTRANSPARENT);
$dc = Wx::ClientDC->new($self); $dc->SetFont($self->GetFont);
my $rect = $self->GetUpdateRegion->GetBox; $dc->SetTextForeground($self->GetForegroundColour);
$dc->SetClippingRect($rect);
my $background_h = $self->{background}->GetHeight;
my $background_w = $self->{background}->GetWidth;
$dc->DrawBitmap($self->{background}, ($size->GetWidth - $background_w) / 2, ($size->GetHeight - $background_h) / 2, 1);
my $label_h = $self->{bullets}->{own}->GetHeight;
$label_h = $dc->GetCharHeight if $dc->GetCharHeight > $label_h;
my $label_w = $size->GetWidth;
my $i = 0;
foreach (@{$self->{titles}}) {
my $bullet = $self->{bullets}->{own};
$bullet = $self->{bullets}->{before} if $i < $self->{own_index};
$bullet = $self->{bullets}->{after} if $i > $self->{own_index};
$dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index};
$dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gab), $label_w, $label_h));
$i++;
} }
my $size = $self->GetClientSize; $event->Skip;
my $h = $self->{background}->GetHeight;
my $w = $self->{background}->GetWidth;
$dc->DrawBitmap($self->{background}, ($size->GetWidth - $w) / 2, ($size->GetHeight - $h) / 2, 1);
} }
sub prepend_title { sub prepend_title {
my $self = shift; my $self = shift;
my ($title) = @_; my ($title) = @_;
my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize); unshift @{$self->{titles}}, $title;
$self->{sizer}->Prepend($text, 0, wxALIGN_CENTER_VERTICAL, 0); $self->{own_index}++;
$self->Refresh;
my $bitmap = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new("$Slic3r::var/bullet_black.png", wxBITMAP_TYPE_PNG));
$self->{sizer}->Prepend($bitmap, 0, wxALIGN_CENTER_VERTICAL, 0);
} }
sub append_title { sub append_title {
my $self = shift; my $self = shift;
my ($title) = @_; my ($title) = @_;
my $bitmap = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new("$Slic3r::var/bullet_white.png", wxBITMAP_TYPE_PNG)); push @{$self->{titles}}, $title;
$self->{sizer}->Add($bitmap, 0, wxALIGN_CENTER_VERTICAL, 0); $self->Refresh;
my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize);
$text->SetForegroundColour(Wx::Colour->new(128, 128, 128));
$self->{sizer}->Add($text, 0, wxALIGN_CENTER_VERTICAL, 0);
} }
package Slic3r::GUI::ConfigWizard::Page; package Slic3r::GUI::ConfigWizard::Page;