| 1 | |||
| 2 | # part of a polynomial tab | ||
| 3 | |||
| 4 | package App::GUI::Juliagraph::Frame::Panel::Monomial; | ||
| 5 | 1 | ▶ | use v5.12; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Wx; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use base qw/Wx::Panel/; | ||
| 9 | use App::GUI::Juliagraph::Widget::SliderStep; | ||
| 10 | |||
| 11 | sub new { | ||
| 12 | my ( $class, $parent, $initial_exp, $std_margin ) = @_; | ||
| 13 | |||
| 14 | my $self = $class->SUPER::new( $parent, -1 ); | ||
| 15 | $self->{'init_exp'} = $initial_exp // 0; | ||
| 16 | $self->{'callback'} = sub {}; | ||
| 17 | |||
| 18 | $self->{'active'} = Wx::CheckBox->new( $self, -1, ' On', [-1,-1], [ 60, -1]); | ||
| 19 | $self->{'active'}->SetToolTip("switch usage of this polynome on or off"); | ||
| 20 | $self->{'use_minus'} = Wx::CheckBox->new( $self, -1, ' -', [-1,-1], [ 50, -1]); | ||
| 21 | $self->{'use_minus'}->SetToolTip('if on, this monomial will be subtracted instead of added'); | ||
| 22 | $self->{'use_log'} = Wx::CheckBox->new( $self, -1, ' log', [-1,-1], [ 60, -1]); | ||
| 23 | $self->{'use_log'}->SetToolTip(' if on, you put a logarithm in front of this monomial term as in: z_n+1 = log( factor * z_n**exponent )'); | ||
| 24 | $self->{'use_factor'} = Wx::CheckBox->new( $self, -1, ' Factor', [-1,-1], [ 70, -1]); | ||
| 25 | $self->{'use_factor'}->SetToolTip('if on, you employ the complex factor from the text boxes below (Re and Im) in formula z_n+1 = factor * z_n**exponent'); | ||
| 26 | $self->{'use_coor'} = Wx::CheckBox->new( $self, -1, ' Coor.', [-1,-1], [ 70, -1]); | ||
| 27 | $self->{'use_coor'}->SetToolTip('if on, the complex factor or 1 gets multiplied with current complex pixel coordinates'); | ||
| 28 | |||
| 29 | |||
| 30 | my $exp_txt = "exponent above iterator variable z_n+1 = z_n**exponent * factor\nzero turns factor into constant"; | ||
| 31 | $self->{'lbl_exponent'} = Wx::StaticText->new($self, -1, 'E x p o n e n t :' ); | ||
| 32 | $self->{'lbl_exponent'}->SetToolTip($exp_txt); | ||
| 33 | $self->{'exponent'} = Wx::ComboBox->new( $self, -1, 2, [-1,-1],[75, 35], [1 .. 16]); | ||
| 34 | $self->{'exponent'}->SetToolTip($exp_txt); | ||
| 35 | |||
| 36 | $self->{'lbl_rf'} = Wx::StaticText->new($self, -1, 'Re : ' ); | ||
| 37 | $self->{'lbl_if'} = Wx::StaticText->new($self, -1, 'Im : ' ); | ||
| 38 | $self->{'lbl_rf'}->SetToolTip('real value part of factor'); | ||
| 39 | $self->{'lbl_if'}->SetToolTip('imaginary value part of factor'); | ||
| 40 | |||
| 41 | $self->{'factor_r'} = Wx::TextCtrl->new( $self, -1, 0, [-1, -1], [-1, 30] ); | ||
| 42 | $self->{'factor_i'} = Wx::TextCtrl->new( $self, -1, 0, [-1, -1], [-1, 30] ); | ||
| 43 | $self->{'factor_r'}->SetToolTip('real value part of factor'); | ||
| 44 | $self->{'factor_i'}->SetToolTip('imaginary value part of factor'); | ||
| 45 | $self->{'button_r'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 160, 3, 0.3, 4, 2 ); | ||
| 46 | $self->{'button_i'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 160, 3, 0.3, 4, 2, ); | ||
| 47 | |||
| 48 | $self->{'button_r'}->SetCallBack(sub { $self->{'factor_r'}->SetValue( $self->{'factor_r'}->GetValue + shift ) }); | ||
| 49 | $self->{'button_i'}->SetCallBack(sub { $self->{'factor_i'}->SetValue( $self->{'factor_i'}->GetValue + shift ) }); | ||
| 50 | |||
| 51 | |||
| 52 | Wx::Event::EVT_CHECKBOX( $self, $self->{'active'}, sub { $self->enable_monomial( $self->{'active'}->GetValue ); $self->{'callback'}->() }); | ||
| 53 | Wx::Event::EVT_CHECKBOX( $self, $self->{'use_factor'}, sub { $self->enable_factor( $self->{'use_factor'}->GetValue ); $self->{'callback'}->(); }); | ||
| 54 | Wx::Event::EVT_CHECKBOX( $self, $self->{$_}, sub { $self->{'callback'}->() }) for qw/use_minus use_log use_coor/; | ||
| 55 | Wx::Event::EVT_COMBOBOX( $self, $self->{$_}, sub { $self->{'callback'}->() }) for qw/exponent/; | ||
| 56 | Wx::Event::EVT_TEXT( $self, $self->{$_}, sub { $self->{'callback'}->() }) for qw/factor_r factor_i/; | ||
| 57 | |||
| 58 | $std_margin //= 10; | ||
| 59 | my $std = &Wx::wxALIGN_LEFT | &Wx::wxALIGN_CENTER_VERTICAL | &Wx::wxGROW; | ||
| 60 | my $box = $std | &Wx::wxTOP | &Wx::wxBOTTOM; | ||
| 61 | my $item = $std | &Wx::wxLEFT | &Wx::wxRIGHT; | ||
| 62 | my $row = $std | &Wx::wxTOP; | ||
| 63 | my $first_sizer = Wx::BoxSizer->new( &Wx::wxHORIZONTAL ); | ||
| 64 | $first_sizer->AddSpacer( $std_margin ); | ||
| 65 | $first_sizer->Add( $self->{'active'}, 0, $box, 5); | ||
| 66 | $first_sizer->AddSpacer( $std_margin - 1 ); | ||
| 67 | $first_sizer->Add( $self->{'use_minus'}, 0, $box, 5); | ||
| 68 | $first_sizer->AddSpacer( $std_margin - 9); | ||
| 69 | $first_sizer->Add( $self->{'use_factor'}, 0, $box, 5); | ||
| 70 | $first_sizer->AddSpacer( $std_margin + 7); | ||
| 71 | $first_sizer->Add( $self->{'use_coor'}, 0, $box, 5); | ||
| 72 | $first_sizer->AddSpacer( $std_margin + 1); | ||
| 73 | $first_sizer->Add( $self->{'use_log'}, 0, $box, 5); | ||
| 74 | $first_sizer->AddStretchSpacer( ); | ||
| 75 | $first_sizer->Add( $self->{'lbl_exponent'}, 0, $box, 13); | ||
| 76 | $first_sizer->AddSpacer( 10 ); | ||
| 77 | $first_sizer->Add( $self->{'exponent'}, 0, $box, 5); | ||
| 78 | $first_sizer->AddSpacer( $std_margin+2 ); | ||
| 79 | |||
| 80 | my $r_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 81 | $r_sizer->AddSpacer( $std_margin ); | ||
| 82 | $r_sizer->Add( $self->{'lbl_rf'}, 0, $box, 12); | ||
| 83 | $r_sizer->AddSpacer( 5 ); | ||
| 84 | $r_sizer->Add( $self->{'factor_r'}, 1, $box, 5); | ||
| 85 | $r_sizer->Add( $self->{'button_r'}, 0, $box, 5); | ||
| 86 | $r_sizer->AddSpacer( $std_margin ); | ||
| 87 | |||
| 88 | my $i_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 89 | $i_sizer->AddSpacer( $std_margin ); | ||
| 90 | $i_sizer->Add( $self->{'lbl_if'}, 0, $box, 12); | ||
| 91 | $i_sizer->AddSpacer( 5 ); | ||
| 92 | $i_sizer->Add( $self->{'factor_i'}, 1, $box, 5); | ||
| 93 | $i_sizer->Add( $self->{'button_i'}, 0, $box, 5); | ||
| 94 | $i_sizer->AddSpacer( $std_margin ); | ||
| 95 | |||
| 96 | my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); | ||
| 97 | $sizer->Add( $first_sizer, 0, $row, 0 ); | ||
| 98 | $sizer->Add( $r_sizer, 0, $row, 10 ); | ||
| 99 | $sizer->Add( $i_sizer, 0, $row, 5 ); | ||
| 100 | $sizer->AddSpacer( 10 ); | ||
| 101 | $self->SetSizer($sizer); | ||
| 102 | $self; | ||
| 103 | } | ||
| 104 | |||
| 105 | sub init { | ||
| 106 | my ( $self ) = @_; | ||
| 107 | $self->set_settings ({ active => $self->{'init_exp'} == 2, # only second is on by default | ||
| 108 | use_log => 0, use_factor => 1, use_minus => 0, use_coor => 0, | ||
| 109 | factor_r => 1, factor_i => 1, exponent => $self->{'init_exp'}, } ); | ||
| 110 | } | ||
| 111 | sub get_settings { | ||
| 112 | my ( $self ) = @_; | ||
| 113 | { | ||
| 114 | active => $self->{'active'}->GetValue ? $self->{'active'}->GetValue : 0, | ||
| 115 | use_log => $self->{'use_log'}->GetValue ? $self->{'use_log'}->GetValue : 0, | ||
| 116 | use_minus => $self->{'use_minus'}->GetValue ? $self->{'use_minus'}->GetValue : 0, | ||
| 117 | use_factor => $self->{'use_factor'}->GetValue ? $self->{'use_factor'}->GetValue : 0, | ||
| 118 | use_coor => $self->{'use_coor'}->GetValue ? $self->{'use_coor'}->GetValue : 0, | ||
| 119 | factor_r => $self->{'factor_r'}->GetValue ? $self->{'factor_r'}->GetValue : 0, | ||
| 120 | factor_i => $self->{'factor_i'}->GetValue ? $self->{'factor_i'}->GetValue : 0, | ||
| 121 | exponent => $self->{'exponent'}->GetStringSelection, | ||
| 122 | } | ||
| 123 | } | ||
| 124 | sub set_settings { | ||
| 125 | my ( $self, $settings ) = @_; | ||
| 126 | return 0 unless ref $settings eq 'HASH'; | ||
| 127 | $self->PauseCallBack(); | ||
| 128 | for my $key (qw/active use_log use_minus use_factor use_coor factor_r factor_i/){ | ||
| 129 | next unless exists $settings->{$key}; | ||
| 130 | $self->{$key}->SetValue( $settings->{$key} ); | ||
| 131 | } | ||
| 132 | for my $key (qw/exponent/){ | ||
| 133 | next unless exists $settings->{$key}; | ||
| 134 | $self->{$key}->SetSelection( $self->{$key}->FindString( $settings->{$key}) ); | ||
| 135 | } | ||
| 136 | $self->enable_factor( $settings->{'use_factor'} ); | ||
| 137 | $self->enable_monomial( $settings->{'active'} ); | ||
| 138 | $self->RestoreCallBack(); | ||
| 139 | 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | sub enable_monomial { | ||
| 143 | my ( $self, $on ) = @_; | ||
| 144 | $self->{$_}->Enable( $on ) for qw/use_minus use_log use_factor | ||
| 145 | lbl_rf lbl_if factor_r factor_i button_r button_i lbl_exponent exponent/; | ||
| 146 | $self->enable_factor if int $on; | ||
| 147 | $self->{'use_coor'}->Enable(1) if $on and $self->{'enable_coor'}; | ||
| 148 | } | ||
| 149 | |||
| 150 | sub enable_factor { | ||
| 151 | my ( $self, $on ) = @_; | ||
| 152 | $on //= $self->{'use_factor'}->GetValue; | ||
| 153 | $self->{$_}->Enable( $on ) for qw/factor_r factor_i button_r button_i lbl_rf lbl_if/; | ||
| 154 | $self->{'use_factor'}->SetValue( $on ) unless int $self->{'use_factor'}->GetValue == int $on; | ||
| 155 | } | ||
| 156 | |||
| 157 | sub enable_coor { | ||
| 158 | my ( $self, $on ) = @_; | ||
| 159 | $self->{'enable_coor'} = $on; | ||
| 160 | if ($on){ | ||
| 161 | $self->{'use_coor'}->Enable( 1 ) if $self->{'active'}->GetValue; | ||
| 162 | } else { | ||
| 163 | $self->{'use_coor'}->SetValue( 0 ); | ||
| 164 | $self->{'use_coor'}->Enable( 0 ); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | sub SetCallBack { | ||
| 169 | my ($self, $code) = @_; | ||
| 170 | return unless ref $code eq 'CODE'; | ||
| 171 | $self->{'callback'} = $code; | ||
| 172 | } | ||
| 173 | sub PauseCallBack { | ||
| 174 | my ($self) = @_; | ||
| 175 | $self->{'pause'} = $self->{'callback'}; | ||
| 176 | $self->{'callback'} = sub {}; | ||
| 177 | } | ||
| 178 | sub RestoreCallBack { | ||
| 179 | my ($self) = @_; | ||
| 180 | return unless exists $self->{'pause'}; | ||
| 181 | $self->{'callback'} = $self->{'pause'}; | ||
| 182 | delete $self->{'pause'}; | ||
| 183 | } | ||
| 184 | |||
| 185 | 1; | ||