merged save_window_pos / restore_window_pos from @alexrj Slic3r.
This commit is contained in:
parent
38e713c23c
commit
632bf56f29
3 changed files with 29 additions and 18 deletions
|
@ -404,4 +404,29 @@ sub scan_serial_ports {
|
|||
return grep !/Bluetooth|FireFly/, @ports;
|
||||
}
|
||||
|
||||
sub save_window_pos {
|
||||
my ($self, $window, $name) = @_;
|
||||
|
||||
$Settings->{_}{"${name}_pos"} = join ',', $window->GetScreenPositionXY;
|
||||
$Settings->{_}{"${name}_size"} = join ',', $window->GetSizeWH;
|
||||
$Settings->{_}{"${name}_maximized"} = $window->IsMaximized;
|
||||
$self->save_settings;
|
||||
}
|
||||
|
||||
sub restore_window_pos {
|
||||
my ($self, $window, $name) = @_;
|
||||
|
||||
if (defined $Settings->{_}{"${name}_pos"}) {
|
||||
my $size = [ split ',', $Settings->{_}{"${name}_size"}, 2 ];
|
||||
$window->SetSize($size);
|
||||
|
||||
my $display = Wx::Display->new->GetClientArea();
|
||||
my $pos = [ split ',', $Settings->{_}{"${name}_pos"}, 2 ];
|
||||
if (($pos->[0] + $size->[0]/2) < $display->GetRight && ($pos->[1] + $size->[1]/2) < $display->GetBottom) {
|
||||
$window->Move($pos);
|
||||
}
|
||||
$window->Maximize(1) if $Settings->{_}{"${name}_maximized"};
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -60,19 +60,8 @@ sub new {
|
|||
$self->SetSizer($sizer);
|
||||
$self->Fit;
|
||||
$self->SetMinSize([760, 490]);
|
||||
if (defined $Slic3r::GUI::Settings->{_}{main_frame_size}) {
|
||||
my $size = [ split ',', $Slic3r::GUI::Settings->{_}{main_frame_size}, 2 ];
|
||||
$self->SetSize($size);
|
||||
|
||||
my $display = Wx::Display->new->GetClientArea();
|
||||
my $pos = [ split ',', $Slic3r::GUI::Settings->{_}{main_frame_pos}, 2 ];
|
||||
if (($pos->[X] + $size->[X]/2) < $display->GetRight && ($pos->[Y] + $size->[Y]/2) < $display->GetBottom) {
|
||||
$self->Move($pos);
|
||||
}
|
||||
$self->Maximize(1) if $Slic3r::GUI::Settings->{_}{main_frame_maximized};
|
||||
} else {
|
||||
$self->SetSize($self->GetMinSize);
|
||||
}
|
||||
$self->SetSize($self->GetMinSize);
|
||||
wxTheApp->restore_window_pos($self, "main_frame");
|
||||
$self->Show;
|
||||
$self->Layout;
|
||||
}
|
||||
|
@ -87,10 +76,7 @@ sub new {
|
|||
}
|
||||
|
||||
# save window size
|
||||
$Slic3r::GUI::Settings->{_}{main_frame_pos} = join ',', $self->GetScreenPositionXY;
|
||||
$Slic3r::GUI::Settings->{_}{main_frame_size} = join ',', $self->GetSizeWH;
|
||||
$Slic3r::GUI::Settings->{_}{main_frame_maximized} = $self->IsMaximized;
|
||||
wxTheApp->save_settings;
|
||||
wxTheApp->save_window_pos($self, "main_frame");
|
||||
|
||||
# propagate event
|
||||
$event->Skip;
|
||||
|
|
|
@ -7,7 +7,7 @@ use strict;
|
|||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Wx qw(:dialog :id :misc :sizer :systemsettings :notebook wxTAB_TRAVERSAL);
|
||||
use Wx qw(:dialog :id :misc :sizer :systemsettings :notebook wxTAB_TRAVERSAL wxTheApp);
|
||||
use Wx::Event qw(EVT_BUTTON);
|
||||
use base 'Wx::Dialog';
|
||||
|
||||
|
|
Loading…
Reference in a new issue