| 1 | # | ||
| 2 | |||
| 3 | package App::GUI::Juliagraph::Frame::Tab::Constraints; | ||
| 4 | 1 | ▶ | use v5.12; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use Wx; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use base qw/Wx::Panel/; | ||
| 8 | use App::GUI::Juliagraph::Widget::SliderStep; | ||
| 9 | use App::GUI::Juliagraph::Widget::SliderCombo; | ||
| 10 | |||
| 11 | my $default_settings = { | ||
| 12 | type => 'Mandelbrot', coordinates_use => 'constant', | ||
| 13 | zoom => 1, center_x => 0, center_y => 0, | ||
| 14 | const_a => 0, const_b => 0, start_a => 0, start_b => 0, | ||
| 15 | stop_nr => 6, stop_value => 3, stop_metric => '|var|' | ||
| 16 | }; | ||
| 17 | |||
| 18 | sub new { | ||
| 19 | my ( $class, $parent) = @_; | ||
| 20 | my $self = $class->SUPER::new( $parent, -1); | ||
| 21 | $self->{'callback'} = sub {}; | ||
| 22 | $self->{'tab'}{'polynome'} = ''; | ||
| 23 | $self->{'tab'}{'mapping'} = ''; | ||
| 24 | |||
| 25 | my $coor_lbl = Wx::StaticText->new($self, -1, 'P i x e l C o o r d i n a t e s : ' ); | ||
| 26 | my $zoom_lbl = Wx::StaticText->new($self, -1, 'Z o o m : ' ); | ||
| 27 | my $pos_lbl = Wx::StaticText->new($self, -1, 'P o s i t i o n : ' ); | ||
| 28 | my $x_lbl = Wx::StaticText->new($self, -1, 'X : ' ); | ||
| 29 | my $y_lbl = Wx::StaticText->new($self, -1, 'Y : ' ); | ||
| 30 | $self->{'lbl_const'} = Wx::StaticText->new($self, -1, 'C o n s t a n t : ' ); | ||
| 31 | $self->{'lbl_consta'} = Wx::StaticText->new($self, -1, 'A : ' ); | ||
| 32 | $self->{'lbl_constb'} = Wx::StaticText->new($self, -1, 'B : ' ); | ||
| 33 | $self->{'lbl_starta'} = Wx::StaticText->new($self, -1, 'A : ' ); | ||
| 34 | $self->{'lbl_startb'} = Wx::StaticText->new($self, -1, 'B : ' ); | ||
| 35 | $self->{'lbl_start'} = Wx::StaticText->new($self, -1, 'S t a r t V a l u e : ' ); | ||
| 36 | my $stop_lbl = Wx::StaticText->new($self, -1, 'I t e r a t i o n S t o p : ' ); | ||
| 37 | my $metric_lbl = Wx::StaticText->new($self, -1, 'M e t r i c : ' ); | ||
| 38 | $coor_lbl->SetToolTip("Which role play pixel coordinates in computation:\n - as start value of the iteration (z_0)\n - added as constant at any iteration \n - as factor of one monomial on next page (numbered from top to bottom)"); | ||
| 39 | $zoom_lbl->SetToolTip('zoom factor: the larger the more you zoom in'); | ||
| 40 | $pos_lbl->SetToolTip('center coordinates of visible sector'); | ||
| 41 | $self->{'lbl_const'}->SetToolTip('complex constant that will be used according settings in first paragraph'); | ||
| 42 | $self->{'lbl_start'}->SetToolTip('value of iteration variable Z before first iteration'); | ||
| 43 | $stop_lbl->SetToolTip('conditions that stop the iteration (computation of pixel color)'); | ||
| 44 | $metric_lbl->SetToolTip('metric for computing stop value (|var| = sqrt(z.re**2 + z.i**2), x = z.real, y = z.im'); | ||
| 45 | |||
| 46 | $self->{'type'} = Wx::RadioBox->new( $self, -1, ' T y p e ', [-1,-1], [-1, -1], ['Mandelbrot', 'Julia', 'Any'] ); | ||
| 47 | $self->{'type'}->SetToolTip( "Choose fractal type: \njulia uses position as init value of iterator var and constant as such, mandelbrot is vice versa\nany means no such restrictions." ); | ||
| 48 | $self->{'coor_as_start'} = Wx::CheckBox->new( $self, -1, ' Start Value', [-1,-1], [-1, -1]); | ||
| 49 | $self->{'coor_as_const'} = Wx::CheckBox->new( $self, -1, ' Constant', [-1,-1], [-1, -1]); | ||
| 50 | $self->{'coor_as_monom'} = Wx::CheckBox->new( $self, -1, ' Monomial', [-1,-1], [-1, -1]); | ||
| 51 | $self->{'coor_as_start'}->SetToolTip( "Use current pixel coordinates as iteration start value, or add them to it." ); | ||
| 52 | $self->{'coor_as_const'}->SetToolTip( "Use current pixel coordinates as constant added at every iteration." ); | ||
| 53 | $self->{'coor_as_monom'}->SetToolTip( "Use current pixel coordinates as monomial factor in the next tab page." ); | ||
| 54 | |||
| 55 | $self->{'zoom'} = Wx::TextCtrl->new( $self, -1, 1, [-1,-1], [ 80, -1] ); | ||
| 56 | $self->{'center_x'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 57 | $self->{'center_y'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 58 | $self->{'const_a'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 59 | $self->{'const_b'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 60 | $self->{'start_a'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 61 | $self->{'start_b'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [100, -1] ); | ||
| 62 | $self->{'reset_zoom'} = Wx::Button->new( $self, -1, 1, [-1,-1], [ 30, -1] ); | ||
| 63 | $self->{'reset_center_x'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 64 | $self->{'reset_center_y'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 65 | $self->{'reset_const_a'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 66 | $self->{'reset_const_b'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 67 | $self->{'reset_start_a'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 68 | $self->{'reset_start_b'} = Wx::Button->new( $self, -1, 0, [-1,-1], [ 30, -1] ); | ||
| 69 | $self->{'button_zoom'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 0.3, 2, 2); | ||
| 70 | $self->{'button_x'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 1 , 7, 3); | ||
| 71 | $self->{'button_y'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 1 , 7, 3); | ||
| 72 | $self->{'button_ca'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 0.3, 3, 3); | ||
| 73 | $self->{'button_cb'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 0.3, 3, 3); | ||
| 74 | $self->{'button_sa'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 0.3, 3, 3); | ||
| 75 | $self->{'button_sb'} = App::GUI::Juliagraph::Widget::SliderStep->new( $self, 150, 3, 0.3, 3, 3); | ||
| 76 | |||
| 77 | $self->{'button_zoom'}->SetToolTip('zoom factor: the larger the more you zoom in'); | ||
| 78 | $self->{'button_zoom'}->SetCallBack(sub { $self->{'zoom'}->SetValue( $self->{'zoom'}->GetValue + shift ) }); | ||
| 79 | $self->{'button_x'}->SetCallBack( sub { my $value = shift;$self->{'center_x'}->SetValue( $self->{'center_x'}->GetValue + ($value * $self->zoom_size) ) }); | ||
| 80 | $self->{'button_y'}->SetCallBack( sub { my $value = shift;$self->{'center_y'}->SetValue( $self->{'center_y'}->GetValue + ($value * $self->zoom_size) ) }); | ||
| 81 | $self->{'button_ca'}->SetCallBack(sub { $self->{'const_a'}->SetValue( $self->{'const_a'}->GetValue + shift ) }); | ||
| 82 | $self->{'button_cb'}->SetCallBack(sub { $self->{'const_b'}->SetValue( $self->{'const_b'}->GetValue + shift ) }); | ||
| 83 | $self->{'button_sa'}->SetCallBack(sub { $self->{'start_a'}->SetValue( $self->{'start_a'}->GetValue + shift ) }); | ||
| 84 | $self->{'button_sb'}->SetCallBack(sub { $self->{'start_b'}->SetValue( $self->{'start_b'}->GetValue + shift ) }); | ||
| 85 | |||
| 86 | $self->{'reset_zoom'}->SetToolTip('Reset zoom level to one !'); | ||
| 87 | $self->{'stop_nr'} = App::GUI::Juliagraph::Widget::SliderCombo->new( $self, 365, 'Count:', "Square root of maximal amount of iterations run on one pixel coordinates", 3, 120, 5, 0.25); | ||
| 88 | $self->{'stop_nr'}->SetCallBack( sub { $self->{'callback'}->() }); | ||
| 89 | $self->{'stop_value'} = App::GUI::Juliagraph::Widget::SliderCombo->new( $self, 200, 'Value:', "Square root of value that triggeres bailout / iteration stop", 1, 120, 5, 0.25); | ||
| 90 | $self->{'stop_value'}->SetCallBack( sub { $self->{'callback'}->() }); | ||
| 91 | $self->{'stop_metric'} = Wx::ComboBox->new( $self, -1, '|var|', [-1,-1],[95, -1], ['|var|', '|x|+|y|', '|x|', '|y|', '|x+y|', 'x+y', 'x-y', 'y-x', 'x*y', '|x*y|']); | ||
| 92 | $self->{'stop_metric'}->SetToolTip('metric for computing stop value (|var| = sqrt(z.re**2 + z.i**2), x = z.real, y = z.im'); | ||
| 93 | |||
| 94 | $self->{'const_widgets'} = [qw/const_a const_b button_ca button_cb lbl_const lbl_consta lbl_constb reset_const_a reset_const_b /]; | ||
| 95 | $self->{'start_widgets'} = [qw/start_a start_b button_sa button_sb lbl_start lbl_starta lbl_startb reset_start_a reset_start_b /]; | ||
| 96 | |||
| 97 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_zoom'}, sub { $self->{'zoom'}->SetValue(1) }); | ||
| 98 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_center_x'}, sub { $self->{'center_x'}->SetValue(0) }); | ||
| 99 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_center_y'}, sub { $self->{'center_y'}->SetValue(0) }); | ||
| 100 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_const_a'}, sub { $self->{'const_a'}->SetValue(0) }); | ||
| 101 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_const_b'}, sub { $self->{'const_b'}->SetValue(0) }); | ||
| 102 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_start_a'}, sub { $self->{'start_a'}->SetValue(0) }); | ||
| 103 | Wx::Event::EVT_BUTTON( $self, $self->{'reset_start_b'}, sub { $self->{'start_b'}->SetValue(0) }); | ||
| 104 | Wx::Event::EVT_RADIOBOX( $self, $self->{'type'}, sub { | ||
| 105 | $self->set_type( $self->{'type'}->GetStringSelection ); $self->{'callback'}->(); | ||
| 106 | }); | ||
| 107 | Wx::Event::EVT_CHECKBOX( $self, $self->{'coor_as_monom'}, sub { | ||
| 108 | $self->set_coordinates_as_factor( $self->{'coor_as_monom'}->GetValue ); | ||
| 109 | $self->freeze_last_coor_option(); $self->{'callback'}->(); | ||
| 110 | }); | ||
| 111 | Wx::Event::EVT_CHECKBOX( $self, $self->{'coor_as_const'}, sub { | ||
| 112 | $self->freeze_last_coor_option(); $self->{'callback'}->(); | ||
| 113 | }); | ||
| 114 | Wx::Event::EVT_CHECKBOX( $self, $self->{'coor_as_start'}, sub { | ||
| 115 | $self->freeze_last_coor_option(); $self->{'callback'}->(); | ||
| 116 | }); | ||
| 117 | $self->{'stop_nr'}->SetCallBack( sub { $self->update_iter_count(); $self->{'callback'}->(); }); | ||
| 118 | $self->{'stop_value'}->SetCallBack( sub { $self->{'callback'}->(); }); | ||
| 119 | |||
| 120 | Wx::Event::EVT_TEXT( $self, $self->{$_}, sub { $self->{'callback'}->() }) for qw/zoom center_x center_y const_a const_b start_a start_b/; | ||
| 121 | Wx::Event::EVT_COMBOBOX( $self, $self->{$_}, sub { $self->{'callback'}->() }) for qw/stop_metric/; | ||
| 122 | |||
| 123 | my $std = &Wx::wxALIGN_LEFT | &Wx::wxALIGN_CENTER_VERTICAL | &Wx::wxGROW; | ||
| 124 | my $box = $std | &Wx::wxTOP | &Wx::wxBOTTOM; | ||
| 125 | my $item = $std | &Wx::wxLEFT; | ||
| 126 | my $row = $std | &Wx::wxTOP; | ||
| 127 | my $all = $std | &Wx::wxALL; | ||
| 128 | |||
| 129 | my $left_margin = 20; | ||
| 130 | my $coor_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); | ||
| 131 | $coor_sizer->Add( $self->{'coor_as_start'}, 0, $box, 2); | ||
| 132 | $coor_sizer->Add( $self->{'coor_as_const'}, 0, $box, 2); | ||
| 133 | $coor_sizer->Add( $self->{'coor_as_monom'}, 0, $box, 2); | ||
| 134 | |||
| 135 | my $type_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 136 | $type_sizer->AddSpacer( $left_margin ); | ||
| 137 | $type_sizer->Add( $self->{'type'}, 0, $box, 16); | ||
| 138 | $type_sizer->AddSpacer( 40 ); | ||
| 139 | $type_sizer->Add( $coor_lbl, 0, $row, 32); | ||
| 140 | $type_sizer->Add( $coor_sizer, 0, $item, 30); | ||
| 141 | $type_sizer->AddStretchSpacer( ); | ||
| 142 | |||
| 143 | my $zoom_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 144 | $zoom_sizer->AddSpacer( $left_margin ); | ||
| 145 | $zoom_sizer->Add( $self->{'zoom'}, 1, $box, 5); | ||
| 146 | $zoom_sizer->Add( $self->{'button_zoom'}, 0, $box, 5); | ||
| 147 | $zoom_sizer->Add( $self->{'reset_zoom'}, 0, $box, 5); | ||
| 148 | $zoom_sizer->AddSpacer( $left_margin ); | ||
| 149 | |||
| 150 | my $x_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 151 | $x_sizer->AddSpacer( $left_margin ); | ||
| 152 | $x_sizer->Add( $x_lbl, 0, $row, 12); | ||
| 153 | $x_sizer->AddSpacer( 10 ); | ||
| 154 | $x_sizer->Add( $self->{'center_x'}, 1, $box, 5); | ||
| 155 | $x_sizer->Add( $self->{'button_x'}, 0, $box, 5); | ||
| 156 | $x_sizer->Add( $self->{'reset_center_x'}, 0, $box, 5); | ||
| 157 | $x_sizer->AddSpacer( $left_margin ); | ||
| 158 | |||
| 159 | my $y_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 160 | $y_sizer->AddSpacer( $left_margin ); | ||
| 161 | $y_sizer->Add( $y_lbl, 0, $row, 12); | ||
| 162 | $y_sizer->AddSpacer( 10 ); | ||
| 163 | $y_sizer->Add( $self->{'center_y'}, 1, $box, 5); | ||
| 164 | $y_sizer->Add( $self->{'button_y'}, 0, $box, 5); | ||
| 165 | $y_sizer->Add( $self->{'reset_center_y'}, 0, $box, 5); | ||
| 166 | $y_sizer->AddSpacer( $left_margin ); | ||
| 167 | |||
| 168 | my $const_a_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 169 | $const_a_sizer->AddSpacer( $left_margin ); | ||
| 170 | $const_a_sizer->Add( $self->{'lbl_consta'}, 0, $row, 12); | ||
| 171 | $const_a_sizer->AddSpacer( 10 ); | ||
| 172 | $const_a_sizer->Add( $self->{'const_a'}, 1, $box, 5); | ||
| 173 | $const_a_sizer->Add( $self->{'button_ca'}, 0, $box, 5); | ||
| 174 | $const_a_sizer->Add( $self->{'reset_const_a'}, 0, $box, 5); | ||
| 175 | $const_a_sizer->AddSpacer( $left_margin ); | ||
| 176 | |||
| 177 | my $const_b_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 178 | $const_b_sizer->AddSpacer( $left_margin ); | ||
| 179 | $const_b_sizer->Add( $self->{'lbl_constb'}, 0, $row, 12); | ||
| 180 | $const_b_sizer->AddSpacer( 10 ); | ||
| 181 | $const_b_sizer->Add( $self->{'const_b'}, 1, $box, 5); | ||
| 182 | $const_b_sizer->Add( $self->{'button_cb'}, 0, $box, 5); | ||
| 183 | $const_b_sizer->Add( $self->{'reset_const_b'},0, $box, 5); | ||
| 184 | $const_b_sizer->AddSpacer( $left_margin ); | ||
| 185 | |||
| 186 | my $start_a_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 187 | $start_a_sizer->AddSpacer( $left_margin ); | ||
| 188 | $start_a_sizer->Add( $self->{'lbl_starta'}, 0, $row, 12); | ||
| 189 | $start_a_sizer->AddSpacer( 10 ); | ||
| 190 | $start_a_sizer->Add( $self->{'start_a'}, 1, $box, 5); | ||
| 191 | $start_a_sizer->Add( $self->{'button_sa'}, 0, $box, 5); | ||
| 192 | $start_a_sizer->Add( $self->{'reset_start_a'}, 0, $box, 5); | ||
| 193 | $start_a_sizer->AddSpacer( $left_margin ); | ||
| 194 | |||
| 195 | my $start_b_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 196 | $start_b_sizer->AddSpacer( $left_margin ); | ||
| 197 | $start_b_sizer->Add( $self->{'lbl_startb'}, 0, $row, 12); | ||
| 198 | $start_b_sizer->AddSpacer( 10 ); | ||
| 199 | $start_b_sizer->Add( $self->{'start_b'}, 1, $box, 5); | ||
| 200 | $start_b_sizer->Add( $self->{'button_sb'}, 0, $box, 5); | ||
| 201 | $start_b_sizer->Add( $self->{'reset_start_b'}, 0, $box, 5); | ||
| 202 | $start_b_sizer->AddSpacer( $left_margin ); | ||
| 203 | |||
| 204 | my $stop_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 205 | $stop_sizer->AddSpacer( $left_margin ); | ||
| 206 | $stop_sizer->Add( $self->{'stop_nr'}, 1, $box, 5); | ||
| 207 | #$stop_sizer->AddSpacer( $left_margin - 10 ); | ||
| 208 | |||
| 209 | my $stop2_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 210 | $stop2_sizer->AddSpacer( $left_margin ); | ||
| 211 | $stop2_sizer->Add( $self->{'stop_value'}, 1, $box, 5); | ||
| 212 | $stop2_sizer->AddSpacer( 20 ); | ||
| 213 | $stop2_sizer->Add( $metric_lbl, 0, $box, 12); | ||
| 214 | $stop2_sizer->AddSpacer( 5 ); | ||
| 215 | $stop2_sizer->Add( $self->{'stop_metric'}, 0, $box, 5); | ||
| 216 | $stop2_sizer->AddSpacer( $left_margin ); | ||
| 217 | |||
| 218 | my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); | ||
| 219 | $sizer->Add( $type_sizer, 0, $row, 10); | ||
| 220 | $sizer->AddSpacer( 3 ); | ||
| 221 | $sizer->Add( Wx::StaticLine->new( $self, -1), 0, $box, 10 ); | ||
| 222 | $sizer->Add( $zoom_lbl, 0, $item, $left_margin); | ||
| 223 | $sizer->Add( $zoom_sizer, 0, $row, 2); | ||
| 224 | $sizer->AddSpacer( 5 ); | ||
| 225 | $sizer->Add( $pos_lbl, 0, $item, $left_margin); | ||
| 226 | $sizer->Add( $x_sizer, 0, $row, 6); | ||
| 227 | $sizer->Add( $y_sizer, 0, $row, 0); | ||
| 228 | $sizer->Add( Wx::StaticLine->new( $self, -1), 0, $box, 10 ); | ||
| 229 | $sizer->Add( $self->{'lbl_const'}, 0, $item, $left_margin); | ||
| 230 | $sizer->Add( $const_a_sizer, 0, $row, 6); | ||
| 231 | $sizer->Add( $const_b_sizer, 0, $row, 0); | ||
| 232 | $sizer->Add( Wx::StaticLine->new( $self, -1), 0, $box, 10 ); | ||
| 233 | $sizer->Add( $self->{'lbl_start'}, 0, $item, $left_margin); | ||
| 234 | $sizer->Add( $start_a_sizer, 0, $row, 6); | ||
| 235 | $sizer->Add( $start_b_sizer, 0, $row, 0); | ||
| 236 | $sizer->Add( Wx::StaticLine->new( $self, -1), 0, $box, 10 ); | ||
| 237 | $sizer->Add( $stop_lbl, 0, $item, $left_margin); | ||
| 238 | $sizer->Add( $stop_sizer, 0, $row, 10); | ||
| 239 | $sizer->Add( $stop2_sizer, 0, $row, 6); | ||
| 240 | $sizer->AddSpacer( $left_margin ); | ||
| 241 | $self->SetSizer($sizer); | ||
| 242 | |||
| 243 | $self->init(); | ||
| 244 | $self; | ||
| 245 | } | ||
| 246 | |||
| 247 | sub init { $_[0]->set_settings ( $default_settings ) } | ||
| 248 | sub set_settings { | ||
| 249 | my ( $self, $settings ) = @_; | ||
| 250 | return 0 unless ref $settings eq 'HASH' and exists $settings->{'type'}; | ||
| 251 | $self->PauseCallBack(); | ||
| 252 | for my $key (qw/coor_as_start coor_as_const coor_as_monom | ||
| 253 | const_a const_b start_a start_b center_x center_y zoom stop_nr stop_value/){ | ||
| 254 | next unless exists $settings->{$key} and exists $self->{$key}; | ||
| 255 | $self->{$key}->SetValue( $settings->{$key} ); | ||
| 256 | } | ||
| 257 | for my $key (qw/stop_metric/){ | ||
| 258 | next unless exists $settings->{$key} and exists $self->{$key}; | ||
| 259 | $self->{$key}->SetSelection( $self->{$key}->FindString($settings->{$key}) ); | ||
| 260 | } | ||
| 261 | $self->set_coordinates_as_factor( $settings->{'coor_as_monom'} ); | ||
| 262 | $self->set_type( $settings->{'type'} ); | ||
| 263 | $self->update_iter_count(); | ||
| 264 | $self->RestoreCallBack(); | ||
| 265 | 1; | ||
| 266 | } | ||
| 267 | sub get_settings { | ||
| 268 | my ( $self ) = @_; | ||
| 269 | return { | ||
| 270 | coor_as_start => int $self->{'coor_as_start'}->GetValue, | ||
| 271 | coor_as_const => int $self->{'coor_as_const'}->GetValue, | ||
| 272 | coor_as_monom => int $self->{'coor_as_monom'}->GetValue, | ||
| 273 | zoom => $self->{'zoom'}->GetValue + 0, | ||
| 274 | center_x => $self->{'center_x'}->GetValue + 0, | ||
| 275 | center_y => $self->{'center_y'}->GetValue + 0, | ||
| 276 | const_a => $self->{'const_a'}->GetValue + 0, | ||
| 277 | const_b => $self->{'const_b'}->GetValue + 0, | ||
| 278 | start_a => $self->{'start_a'}->GetValue + 0, | ||
| 279 | start_b => $self->{'start_b'}->GetValue + 0, | ||
| 280 | type => $self->{'type'}->GetStringSelection, | ||
| 281 | stop_nr => $self->{'stop_nr'}->GetValue, | ||
| 282 | stop_value => $self->{'stop_value'}->GetValue, | ||
| 283 | stop_metric => $self->{'stop_metric'}->GetStringSelection, | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | sub set_type { | ||
| 288 | my ( $self, $type ) = @_; | ||
| 289 | return unless defined $type; | ||
| 290 | $type = ucfirst lc $type; | ||
| 291 | my $selection_nr = $self->{'type'}->FindString( $type ); | ||
| 292 | return if $selection_nr == -1; | ||
| 293 | my $paused = $self->CallBackiIsPaused; | ||
| 294 | $self->PauseCallBack(); | ||
| 295 | $self->{'type'}->SetSelection( $selection_nr ); | ||
| 296 | if ($type eq 'Mandelbrot'){ | ||
| 297 | $self->{$_}->SetValue( 0 ) for qw/const_a const_b start_a start_b/; | ||
| 298 | $self->{$_}->Enable( 0 ) for @{$self->{'const_widgets'}}; | ||
| 299 | $self->{'coor_as_start'}->SetValue( 0 ); | ||
| 300 | $self->{'coor_as_const'}->SetValue( 1 ); | ||
| 301 | } elsif ($type eq 'Julia') { | ||
| 302 | $self->{$_}->SetValue( 0 ) for qw/start_a start_b/; | ||
| 303 | $self->{$_}->Enable( 1 ) for @{$self->{'const_widgets'}}; | ||
| 304 | $self->{'coor_as_start'}->SetValue( 1 ); | ||
| 305 | $self->{'coor_as_const'}->SetValue( 0 ); | ||
| 306 | } | ||
| 307 | if ($type eq 'Any') { | ||
| 308 | $self->{$_}->Enable(1) for @{$self->{'const_widgets'}}, @{$self->{'start_widgets'}}, | ||
| 309 | qw/coor_as_start coor_as_const coor_as_monom/; | ||
| 310 | $self->freeze_last_coor_option; | ||
| 311 | } else { | ||
| 312 | $self->{$_}->Enable(0) for @{$self->{'start_widgets'}}, | ||
| 313 | qw/coor_as_start coor_as_const coor_as_monom/; | ||
| 314 | $self->{'coor_as_monom'}->SetValue( 0 ); | ||
| 315 | $self->{'tab'}{'polynome'}->init() if ref $self->{'tab'}{'polynome'}; | ||
| 316 | } | ||
| 317 | $self->RestoreCallBack() unless $paused; | ||
| 318 | } | ||
| 319 | sub set_coordinates_as_factor { | ||
| 320 | my ( $self, $on ) = @_; | ||
| 321 | $on //= $self->{'coor_as_monom'}->GetValue; | ||
| 322 | $self->{'coor_as_monom'}->SetValue( $on ); | ||
| 323 | $self->{'tab'}{'polynome'}->enable_coor( $on ) if ref $self->{'tab'}{'polynome'}; | ||
| 324 | } | ||
| 325 | |||
| 326 | sub freeze_last_coor_option { # keep always one option chosen | ||
| 327 | my ( $self ) = @_; | ||
| 328 | my %val = (s => int($self->{'coor_as_start'}->GetValue), | ||
| 329 | c => int($self->{'coor_as_const'}->GetValue), | ||
| 330 | m => int($self->{'coor_as_monom'}->GetValue), | ||
| 331 | ); | ||
| 332 | if ($val{'s'} + $val{'c'} + $val{'m'} == 1){ | ||
| 333 | $self->{'coor_as_start'}->Enable(0) if $val{'s'}; | ||
| 334 | $self->{'coor_as_const'}->Enable(0) if $val{'c'}; | ||
| 335 | $self->{'coor_as_monom'}->Enable(0) if $val{'m'}; | ||
| 336 | } else { | ||
| 337 | $self->{$_}->Enable(1) for qw/coor_as_start coor_as_const coor_as_monom/; | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | sub move_center_position { # after mouse click | ||
| 342 | my ( $self, $delta_x_percent, $delta_y_percent, $zoom_dir ) = @_; | ||
| 343 | $self->PauseCallBack; | ||
| 344 | my $zoom = $self->{'zoom'}->GetValue; | ||
| 345 | my $cx = $self->{'center_x'}->GetValue; | ||
| 346 | my $cy = $self->{'center_y'}->GetValue; | ||
| 347 | my $d = sqrt( $delta_x_percent**2 + $delta_y_percent**2 ); | ||
| 348 | if ($zoom_dir){ | ||
| 349 | $self->{'zoom'}->SetValue( $zoom + (0.1 * $zoom_dir * $zoom) ); | ||
| 350 | } else { | ||
| 351 | my $new_x = ($delta_x_percent / 2 / $zoom ) + $cx; | ||
| 352 | my $new_y = -($delta_y_percent / 2 / $zoom ) + $cy; | ||
| 353 | $self->{'center_x'}->SetValue( $new_x ); | ||
| 354 | $self->{'center_y'}->SetValue( $new_y ); | ||
| 355 | } | ||
| 356 | $self->RestoreCallBack; | ||
| 357 | $self->RunCallBack; | ||
| 358 | } | ||
| 359 | |||
| 360 | sub update_iter_count { | ||
| 361 | my ( $self ) = @_; | ||
| 362 | $self->{'tab'}{'mapping'}{'scale_max'}->SetValue( int $self->{'stop_nr'}->GetValue**2 ) if ref $self->{'tab'}{'mapping'}; | ||
| 363 | } | ||
| 364 | |||
| 365 | sub zoom_size { 0.1 / ($_[0]->{'zoom'}->GetValue ** 2) } | ||
| 366 | |||
| 367 | sub connect_polynome_tab { | ||
| 368 | my ($self, $ref) = @_; | ||
| 369 | return unless ref $ref eq 'App::GUI::Juliagraph::Frame::Tab::Polynomial'; | ||
| 370 | $self->{'tab'}{'polynome'} = $ref; | ||
| 371 | } | ||
| 372 | |||
| 373 | sub connect_mapping_tab { | ||
| 374 | my ($self, $ref) = @_; | ||
| 375 | return unless ref $ref eq 'App::GUI::Juliagraph::Frame::Tab::Mapping'; | ||
| 376 | $self->{'tab'}{'mapping'} = $ref; | ||
| 377 | $self->{'tab'}{'mapping'}{'scale_max'}->SetValue( $self->{'stop_nr'}->GetValue ); | ||
| 378 | $self->update_iter_count(); | ||
| 379 | } | ||
| 380 | |||
| 381 | sub SetCallBack { | ||
| 382 | my ($self, $code) = @_; | ||
| 383 | return unless ref $code eq 'CODE'; | ||
| 384 | $self->{'callback'} = $code; | ||
| 385 | } | ||
| 386 | sub PauseCallBack { | ||
| 387 | my ($self) = @_; | ||
| 388 | return if $self->CallBackiIsPaused; | ||
| 389 | $self->{'paused_call'} = $self->{'callback'}; | ||
| 390 | $self->{'callback'} = sub {}; | ||
| 391 | } | ||
| 392 | sub CallBackiIsPaused { exists $_[0]->{'paused_call'} } | ||
| 393 | sub RunCallBack { $_[0]->{'callback'}->() } | ||
| 394 | sub RestoreCallBack { | ||
| 395 | my ($self) = @_; | ||
| 396 | return unless $self->CallBackiIsPaused; | ||
| 397 | $self->{'callback'} = $self->{'paused_call'}; | ||
| 398 | delete $self->{'paused_call'}; | ||
| 399 | } | ||
| 400 | |||
| 401 | 1; | ||