App-GUI-Juliagraph
view release on metacpan or search on metacpan
lib/App/GUI/Juliagraph/Frame/Tab/Constraints.pm view on Meta::CPAN
stop_value => $self->{'stop_value'}->GetValue,
stop_metric => $self->{'stop_metric'}->GetStringSelection,
}
}
sub set_type {
my ( $self, $type ) = @_;
return unless defined $type;
$type = ucfirst lc $type;
my $selection_nr = $self->{'type'}->FindString( $type );
return if $selection_nr == -1;
my $paused = $self->CallBackiIsPaused;
$self->PauseCallBack();
$self->{'type'}->SetSelection( $selection_nr );
if ($type eq 'Mandelbrot'){
$self->{$_}->SetValue( 0 ) for qw/const_a const_b start_a start_b/;
$self->{$_}->Enable( 0 ) for @{$self->{'const_widgets'}};
$self->{'coor_as_start'}->SetValue( 0 );
$self->{'coor_as_const'}->SetValue( 1 );
} elsif ($type eq 'Julia') {
$self->{$_}->SetValue( 0 ) for qw/start_a start_b/;
$self->{$_}->Enable( 1 ) for @{$self->{'const_widgets'}};
$self->{'coor_as_start'}->SetValue( 1 );
$self->{'coor_as_const'}->SetValue( 0 );
}
if ($type eq 'Any') {
$self->{$_}->Enable(1) for @{$self->{'const_widgets'}}, @{$self->{'start_widgets'}},
qw/coor_as_start coor_as_const coor_as_monom/;
$self->freeze_last_coor_option;
} else {
$self->{$_}->Enable(0) for @{$self->{'start_widgets'}},
qw/coor_as_start coor_as_const coor_as_monom/;
$self->{'coor_as_monom'}->SetValue( 0 );
$self->{'tab'}{'polynome'}->init() if ref $self->{'tab'}{'polynome'};
}
$self->RestoreCallBack() unless $paused;
}
sub set_coordinates_as_factor {
my ( $self, $on ) = @_;
$on //= $self->{'coor_as_monom'}->GetValue;
$self->{'coor_as_monom'}->SetValue( $on );
$self->{'tab'}{'polynome'}->enable_coor( $on ) if ref $self->{'tab'}{'polynome'};
}
sub freeze_last_coor_option { # keep always one option chosen
my ( $self ) = @_;
my %val = (s => int($self->{'coor_as_start'}->GetValue),
c => int($self->{'coor_as_const'}->GetValue),
m => int($self->{'coor_as_monom'}->GetValue),
);
if ($val{'s'} + $val{'c'} + $val{'m'} == 1){
$self->{'coor_as_start'}->Enable(0) if $val{'s'};
$self->{'coor_as_const'}->Enable(0) if $val{'c'};
$self->{'coor_as_monom'}->Enable(0) if $val{'m'};
} else {
$self->{$_}->Enable(1) for qw/coor_as_start coor_as_const coor_as_monom/;
}
}
sub move_center_position { # after mouse click
my ( $self, $delta_x_percent, $delta_y_percent, $zoom_dir ) = @_;
$self->PauseCallBack;
my $zoom = $self->{'zoom'}->GetValue;
my $cx = $self->{'center_x'}->GetValue;
my $cy = $self->{'center_y'}->GetValue;
my $d = sqrt( $delta_x_percent**2 + $delta_y_percent**2 );
if ($zoom_dir){
$self->{'zoom'}->SetValue( $zoom + (0.1 * $zoom_dir * $zoom) );
} else {
my $new_x = ($delta_x_percent / 2 / $zoom ) + $cx;
my $new_y = -($delta_y_percent / 2 / $zoom ) + $cy;
$self->{'center_x'}->SetValue( $new_x );
$self->{'center_y'}->SetValue( $new_y );
}
$self->RestoreCallBack;
$self->RunCallBack;
}
sub update_iter_count {
my ( $self ) = @_;
$self->{'tab'}{'mapping'}{'scale_max'}->SetValue( int $self->{'stop_nr'}->GetValue**2 ) if ref $self->{'tab'}{'mapping'};
}
sub zoom_size { 0.1 / ($_[0]->{'zoom'}->GetValue ** 2) }
sub connect_polynome_tab {
my ($self, $ref) = @_;
return unless ref $ref eq 'App::GUI::Juliagraph::Frame::Tab::Polynomial';
$self->{'tab'}{'polynome'} = $ref;
}
sub connect_mapping_tab {
my ($self, $ref) = @_;
return unless ref $ref eq 'App::GUI::Juliagraph::Frame::Tab::Mapping';
$self->{'tab'}{'mapping'} = $ref;
$self->{'tab'}{'mapping'}{'scale_max'}->SetValue( $self->{'stop_nr'}->GetValue );
$self->update_iter_count();
}
sub SetCallBack {
my ($self, $code) = @_;
return unless ref $code eq 'CODE';
$self->{'callback'} = $code;
}
sub PauseCallBack {
my ($self) = @_;
return if $self->CallBackiIsPaused;
$self->{'paused_call'} = $self->{'callback'};
$self->{'callback'} = sub {};
}
sub CallBackiIsPaused { exists $_[0]->{'paused_call'} }
sub RunCallBack { $_[0]->{'callback'}->() }
sub RestoreCallBack {
my ($self) = @_;
return unless $self->CallBackiIsPaused;
$self->{'callback'} = $self->{'paused_call'};
delete $self->{'paused_call'};
}
1;
( run in 1.611 second using v1.01-cache-2.11-cpan-39bf76dae61 )