| 1 | 1 | ▶ | use v5.12; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 0 | ▶ | use Wx; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 4 | |||
| 5 | package App::GUI::Juliagraph::Frame::Panel::ColorSetPicker; | ||
| 6 | use base qw/Wx::Panel/; | ||
| 7 | |||
| 8 | use App::GUI::Juliagraph::Widget::ColorDisplay; | ||
| 9 | use Graphics::Toolkit::Color qw/color/; | ||
| 10 | |||
| 11 | our $default_color = {red => 225, green => 225, blue => 225}; | ||
| 12 | |||
| 13 | sub new { | ||
| 14 | my ( $class, $parent, $color_sets, $max_display_count ) = @_; | ||
| 15 | return unless ref $parent and ref $color_sets eq 'HASH'; | ||
| 16 | |||
| 17 | my $self = $class->SUPER::new( $parent, -1 ); | ||
| 18 | |||
| 19 | $self->{'sets'} = { %$color_sets }; | ||
| 20 | $self->{'set_names'} = [ sort keys %{$self->{'sets'}} ]; | ||
| 21 | $self->{'set_index'} = 1; | ||
| 22 | $self->{'max_display_count'} = $max_display_count; | ||
| 23 | |||
| 24 | my $btnw = 46; my $btnh = 17;# button width and height | ||
| 25 | $self->{'select'} = Wx::ComboBox->new( $self, -1, $self->current_set_name, [-1,-1], [170, -1], $self->{'set_names'}); | ||
| 26 | $self->{'<'} = Wx::Button->new( $self, -1, '<', [-1,-1], [ 27, $btnh] ); | ||
| 27 | $self->{'>'} = Wx::Button->new( $self, -1, '>', [-1,-1], [ 27, $btnh] ); | ||
| 28 | $self->{'load'} = Wx::Button->new( $self, -1, 'Load', [-1,-1], [$btnw, $btnh] ); | ||
| 29 | $self->{'del'} = Wx::Button->new( $self, -1, 'Del', [-1,-1], [$btnw, $btnh] ); | ||
| 30 | $self->{'save'} = Wx::Button->new( $self, -1, 'Save', [-1,-1], [$btnw, $btnh] ); | ||
| 31 | $self->{'new'} = Wx::Button->new( $self, -1, 'New', [-1,-1], [$btnw, $btnh] ); | ||
| 32 | |||
| 33 | $self->{'display'}[$_] = App::GUI::Juliagraph::Widget::ColorDisplay->new( $self, 15, 9, $_, $default_color ) for 0 .. $self->{'max_display_count'}-1; | ||
| 34 | |||
| 35 | $self->{'select'}->SetToolTip("select color set in list directly"); | ||
| 36 | $self->{'<'}->SetToolTip("go to previous color set name in list"); | ||
| 37 | $self->{'>'}->SetToolTip("go to next color set name in list"); | ||
| 38 | $self->{'load'}->SetToolTip("use displayed color on the right side as color of selected state"); | ||
| 39 | $self->{'save'}->SetToolTip("save currently used state colors under the displayed color set name"); | ||
| 40 | $self->{'del'}->SetToolTip("delete color set of displayed name from storage"); | ||
| 41 | $self->{'new'}->SetToolTip("save currently used state colors under a new set name"); | ||
| 42 | |||
| 43 | Wx::Event::EVT_COMBOBOX( $self, $self->{'select'}, sub { | ||
| 44 | my ($win, $evt) = @_; $self->{'set_index'} = $evt->GetInt; $self->update_display }); | ||
| 45 | Wx::Event::EVT_BUTTON( $self, $self->{'<'}, sub { $self->{'set_index'}--; $self->update_display }); | ||
| 46 | Wx::Event::EVT_BUTTON( $self, $self->{'>'}, sub { $self->{'set_index'}++; $self->update_display }); | ||
| 47 | Wx::Event::EVT_BUTTON( $self, $self->{'load'}, sub { $parent->set_all_colors( $self->get_current_color_set ) }); | ||
| 48 | Wx::Event::EVT_BUTTON( $self, $self->{'del'}, sub { | ||
| 49 | delete $self->{'sets'}{ $self->current_set_name }; | ||
| 50 | $self->{'set_index'}-- if $self->{'set_index'}; | ||
| 51 | $self->update_select(); | ||
| 52 | }); | ||
| 53 | Wx::Event::EVT_BUTTON( $self, $self->{'save'}, sub { | ||
| 54 | $self->{'sets'}{ $self->current_set_name } = [map { $_->name ? $_->name : $_->rgb_hex } $parent->get_all_colors]; | ||
| 55 | $self->update_display(); | ||
| 56 | }); | ||
| 57 | Wx::Event::EVT_BUTTON( $self, $self->{'new'}, sub { | ||
| 58 | my $name; | ||
| 59 | while (1){ | ||
| 60 | my $dialog = Wx::TextEntryDialog->new ( $self, "Please insert the color set name", 'Request Dialog'); | ||
| 61 | return if $dialog->ShowModal == &Wx::wxID_CANCEL; | ||
| 62 | $name = $dialog->GetValue(); | ||
| 63 | $name =~ tr/ /_/; | ||
| 64 | last unless exists $self->{'sets'}{ $name }; | ||
| 65 | } | ||
| 66 | $self->{'sets'}{ $name } = [ map { $_->name ? $_->name : $_->rgb_hex } $parent->get_all_colors ]; | ||
| 67 | $self->{'set_names'} = [ sort keys %{$self->{'sets'}} ]; | ||
| 68 | for (0 .. $#{$self->{'set_names'}}){ | ||
| 69 | $self->{'set_index'} = $_ if $name eq $self->{'set_names'}[$_]; | ||
| 70 | } | ||
| 71 | $self->update_select(); | ||
| 72 | }); | ||
| 73 | |||
| 74 | my $std_attr = &Wx::wxALIGN_LEFT | &Wx::wxALIGN_CENTER_VERTICAL| &Wx::wxGROW; | ||
| 75 | my $tb_attr = $std_attr | &Wx::wxTOP| &Wx::wxBOTTOM; | ||
| 76 | my $button_attr = &Wx::wxLEFT | $tb_attr; | ||
| 77 | my $all_attr = $std_attr | &Wx::wxALL; | ||
| 78 | my $row1 = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 79 | $row1->AddSpacer( 10 ); | ||
| 80 | $row1->Add( $self->{'del'}, 0, $button_attr, 5 ); | ||
| 81 | $row1->AddSpacer( 15 ); | ||
| 82 | $row1->Add( $self->{'select'}, 0, $tb_attr, 5 ); | ||
| 83 | $row1->Add( $self->{'<'}, 0, $tb_attr, 5 ); | ||
| 84 | $row1->Add( $self->{'>'}, 0, $tb_attr, 5 ); | ||
| 85 | $row1->AddSpacer( 10 ); | ||
| 86 | $row1->Add( $self->{'load'}, 0, $button_attr, 5 ); | ||
| 87 | $row1->AddSpacer( 10 ); | ||
| 88 | $row1->Add( $self->{'new'}, 0, $button_attr, 5 ); | ||
| 89 | $row1->AddSpacer( 10 ); | ||
| 90 | $row1->Add( $self->{'save'}, 0, $button_attr, 5 ); | ||
| 91 | $row1->Add( 0, 0, &Wx::wxEXPAND | &Wx::wxGROW); | ||
| 92 | |||
| 93 | my $row2 = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); | ||
| 94 | $row2->AddSpacer( 10 ); | ||
| 95 | $row2->Add( $self->{'display'}[$_], 0, $all_attr, 6 ) for 0 .. $self->{'max_display_count'}-1; | ||
| 96 | $row2->Add( 0, 0, &Wx::wxEXPAND | &Wx::wxGROW); | ||
| 97 | |||
| 98 | my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); | ||
| 99 | $sizer->Add( $row1, 0, $tb_attr, 0 ); | ||
| 100 | $sizer->AddSpacer( 5 ); | ||
| 101 | $sizer->Add( $row2, 0, $tb_attr, 0 ); | ||
| 102 | $self->SetSizer($sizer); | ||
| 103 | |||
| 104 | $self->update_display; | ||
| 105 | $self; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub current_set_name { $_[0]->{'set_names'}->[ $_[0]->{'set_index'} ] } | ||
| 109 | |||
| 110 | sub get_current_color_set { @{$_[0]->{'set_content'}} } | ||
| 111 | |||
| 112 | sub update_select { | ||
| 113 | my ( $self ) = @_; | ||
| 114 | $self->{'set_names'} = [ sort keys %{$self->{'sets'}} ]; | ||
| 115 | $self->{'select'}->Clear (); | ||
| 116 | $self->{'select'}->Append( $_) for @{$self->{'set_names'}}; | ||
| 117 | $self->update_display(); | ||
| 118 | } | ||
| 119 | |||
| 120 | sub update_display { | ||
| 121 | my ($self) = @_; | ||
| 122 | $self->{'set_index'} = $#{$self->{'set_names'}} if $self->{'set_index'} < 0; | ||
| 123 | $self->{'set_index'} = 0 if $self->{'set_index'} > $#{$self->{'set_names'}}; | ||
| 124 | $self->{'select'}->SetSelection( $self->{'set_index'} ); | ||
| 125 | my $set_name = $self->{'set_names'}[ $self->{'set_index'} ]; | ||
| 126 | my $set_length = @{ $self->{'sets'}{$set_name} }; | ||
| 127 | $self->{'set_content'} = [ map { color( $self->{'sets'}{$set_name}[ $_ ] ) } 0 .. $set_length - 1 ]; | ||
| 128 | $self->{'set_content'}[$_] = color( $default_color ) for $set_length .. $self->{'max_display_count'}-1; | ||
| 129 | $self->{'display'}[$_]->set_color( $self->{'set_content'}[ $_ ]->values(as => 'hash') ) for 0 .. $self->{'max_display_count'}-1; | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | |||
| 134 | sub get_config { $_[0]->{'sets'} } | ||
| 135 | |||
| 136 | |||
| 137 | 1; | ||