App-GUI-Cellgraph
view release on metacpan or search on metacpan
lib/App/GUI/Cellgraph/Frame/Tab/Color.pm view on Meta::CPAN
# color selection page
package App::GUI::Cellgraph::Frame::Tab::Color;
use base qw/Wx::Panel/;
use v5.12;
use warnings;
use Wx;
use App::GUI::Cellgraph::Frame::Panel::ColorBrowser;
use App::GUI::Cellgraph::Frame::Panel::ColorPicker;
use App::GUI::Cellgraph::Frame::Panel::ColorSetPicker;
use App::GUI::Cellgraph::Widget::ColorDisplay;
use App::GUI::Cellgraph::Widget::PositionMarker;
use Graphics::Toolkit::Color qw/color/;
our $default_color_def = $App::GUI::Cellgraph::Frame::Panel::ColorSetPicker::default_color;
sub new {
my ( $class, $parent, $config ) = @_;
my $self = $class->SUPER::new( $parent, -1);
$self->{'set_back'} = sub {};
$self->{'config'} = $config;
$self->{'rule_square_size'} = 34;
$self->{'last_state'} = 8; # max pos
$self->{'state_count'} = 2; # nr of currently used
$self->{'current_state'} = 1;
$self->{'state_colors'} = [ color('white')->gradient( to => 'black', steps => $self->{'state_count'}) ];
$self->{'state_colors'}[$_] = color( $default_color_def ) for $self->{'state_count'} .. $self->{'last_state'};
$self->{'state_marker'} = [ map { App::GUI::Cellgraph::Widget::PositionMarker->new($self, $self->{'rule_square_size'}, 20, $_, '', $default_color_def) } 0 ..$self->{'last_state'} ];
$self->{'state_pic'}[$_] = App::GUI::Cellgraph::Widget::ColorDisplay->new
($self, $self->{'rule_square_size'}, $self->{'rule_square_size'}-5,
$_, $self->{'state_colors'}[$_]->values(as => 'hash') ) for 0 .. $self->{'last_state'};
$self->{'state_pic'}[$_]->SetToolTip("select state color number $_ to change (marked by arrow - crosses mark currently passive colors)") for 0 .. $self->{'last_state'};
$self->{'state_marker'}[$_]->SetToolTip("select state color number $_ to change (marked by arrow - crosses mark currently passive colors)") for 0 .. $self->{'last_state'};
$self->{'color_set_store_lbl'}= Wx::StaticText->new($self, -1, 'Color Set Store' );
$self->{'color_set_f_lbl'} = Wx::StaticText->new($self, -1, 'Colors Set Function' );
$self->{'state_color_lbl'} = Wx::StaticText->new($self, -1, 'Currently Used State Colors' );
$self->{'curr_color_lbl'} = Wx::StaticText->new($self, -1, 'Selected State Color' );
$self->{'color_store_lbl'} = Wx::StaticText->new($self, -1, 'Color Store' );
$self->{'widget'}{'tilt'} = Wx::ComboBox->new( $self, -1, 1, [-1,-1],[75, -1], [ 0.2, 0.25, 0.33, 0.4, 0.5, 0.66, 0.7, 0.83, 0.9, 1, 1.2, 1.5, 2, 2.5, 3, 4 ]);
$self->{'widget'}{'delta_S'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [50,-1], &Wx::wxTE_RIGHT);
$self->{'widget'}{'delta_L'} = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [50,-1], &Wx::wxTE_RIGHT);
$self->{'btn'}{'gray'} = Wx::Button->new( $self, -1, 'Gray', [-1,-1], [45, 17] );
$self->{'btn'}{'gradient'} = Wx::Button->new( $self, -1, 'Gradient', [-1,-1], [70, 17] );
$self->{'btn'}{'complement'} = Wx::Button->new( $self, -1, 'Complement', [-1,-1], [90, 17] );
$self->{'btn'}{'gray'}->SetToolTip("reset to default grey scale color pallet. Adheres to count of needed colors and current tilt settings.");
$self->{'btn'}{'gradient'}->SetToolTip("create gradient between first and current color. Adheres to tilt settings.");
$self->{'btn'}{'complement'}->SetToolTip("Create color set from first up to current color as complementary colors. Adheres to both delta values.");
$self->{'widget'}{'tilt'}->SetToolTip("tilt of gradient (0 = linear) and also of gray scale");
$self->{'widget'}{'delta_S'}->SetToolTip("max. satuaration deviation when computing complement colors ( -100 .. 100)");
$self->{'widget'}{'delta_L'}->SetToolTip("max. lightness deviation when computing complement colors ( -100 .. 100)");
$self->{'picker'} = App::GUI::Cellgraph::Frame::Panel::ColorPicker->new( $self, $config->get_value('color') );
$self->{'setpicker'} = App::GUI::Cellgraph::Frame::Panel::ColorSetPicker->new( $self, $config->get_value('color_set'));
$self->{'browser'} = App::GUI::Cellgraph::Frame::Panel::ColorBrowser->new( $self, 'state', {red => 0, green => 0, blue => 0} );
$self->{'browser'}->SetCallBack( sub { $self->set_current_color( $_[0] ) });
Wx::Event::EVT_LEFT_DOWN( $self->{'state_pic'}[$_], sub { $self->select_state( $_[0]->get_nr ) }) for 0 .. $self->{'last_state'};
Wx::Event::EVT_LEFT_DOWN( $self->{'state_marker'}[$_], sub { $self->select_state( $_[0]->get_nr ) }) for 0 .. $self->{'last_state'};
Wx::Event::EVT_BUTTON( $self, $self->{'btn'}{'gray'}, sub {
$self->set_all_colors( color('white')->gradient( to => 'black', steps => $self->{'state_count'}, tilt => $self->{'widget'}{'tilt'}->GetValue) );
});
Wx::Event::EVT_BUTTON( $self, $self->{'btn'}{'gradient'}, sub {
my @c = $self->get_all_colors;
my @new_colors = $c[0]->gradient( to => $c[ $self->{'current_state'} ], in => 'RGB', steps => $self->{'current_state'}+1, tilt => $self->{'widget'}{'tilt'}->GetValue);
$self->set_all_colors( @new_colors );
});
Wx::Event::EVT_BUTTON( $self, $self->{'btn'}{'complement'}, sub {
my @c = $self->get_all_colors;
my @new_colors = $c[ $self->{'current_state'} ]->complement( steps => $self->{'current_state'}+1,
targe => {
s => $self->{'widget'}{'delta_S'}->GetValue,
( run in 0.554 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )