App-GUI-Juliagraph
view release on metacpan or search on metacpan
lib/App/GUI/Juliagraph/Frame/Tab/Color.pm view on Meta::CPAN
# color selection page
package App::GUI::Juliagraph::Frame::Tab::Color;
use base qw/Wx::Panel/;
use v5.12;
use warnings;
use Wx;
use App::GUI::Juliagraph::Frame::Panel::ColorBrowser;
use App::GUI::Juliagraph::Frame::Panel::ColorPicker;
use App::GUI::Juliagraph::Frame::Panel::ColorSetPicker;
use App::GUI::Juliagraph::Widget::ColorDisplay;
use App::GUI::Juliagraph::Widget::PositionMarker;
use Graphics::Toolkit::Color qw/color/;
our $default_color_def = $App::GUI::Juliagraph::Frame::Panel::ColorSetPicker::default_color;
my $default_settings = { 1=> 'black', 2=> 'red', 3=> 'orange', 4 => 'blue',
tilt => 0, delta_S => 0, delta_L => 0 };
sub new {
my ( $class, $parent, $config, $size ) = @_;
my $self = $class->SUPER::new( $parent, -1);
$self->{'call_back'} = sub {};
$self->{'config'} = $config;
$self->{'color_count'} = $size; # number of displayed colors
$self->{'active_color_count'} = 4; # nr of currently used colors, overwritten on init
$self->{'current_color_nr'} = 0; # index starts from 0
$self->{'display_size'} = 30;
$self->{'used_colors'} = [ color('blue')->gradient( to => 'red', steps => $self->{'active_color_count'}) ];
$self->{'used_colors'}[$_] = color( $default_color_def ) for $self->{'active_color_count'} .. $self->{'color_count'}-1;
$self->{'color_marker'} = [ map { App::GUI::Juliagraph::Widget::PositionMarker->new
($self, $self->{'display_size'}, 20, $_, '', $default_color_def) } 0 .. $self->{'color_count'}-1 ];
$self->{'color_display'}[$_] = App::GUI::Juliagraph::Widget::ColorDisplay->new
($self, $self->{'display_size'}-2, $self->{'display_size'},
$_, $self->{'used_colors'}[$_]->values(as => 'hash') ) for 0 .. $self->{'color_count'}-1;
$self->{'color_marker'}[$_-1]->SetToolTip("color $_, to change (marked by arrow - crosses mark currently passive colors)") for 1 .. $self->{'color_count'}-1;
$self->{'color_display'}[$_-1]->SetToolTip("color $_, to change (marked by arrow - crosses mark currently passive colors)") for 1 .. $self->{'color_count'}-1;
$self->{'color_marker'}[$size-1]->SetToolTip("lost color, often background color, shown where values do not converge");
$self->{'color_display'}[$size-1]->SetToolTip("last color, often background color, shown where values do not converge");
$self->{'label'}{'color_set_store'} = Wx::StaticText->new($self, -1, 'Color Set Store' );
$self->{'label'}{'color_set_funct'} = Wx::StaticText->new($self, -1, 'Colors Set Function' );
$self->{'label'}{'used_colors'} = Wx::StaticText->new($self, -1, 'Currently Used Colors' );
$self->{'label'}{'selected_color'} = Wx::StaticText->new($self, -1, 'Selected Color' );
$self->{'label'}{'color_store'} = Wx::StaticText->new($self, -1, 'Color Store' );
$self->{'widget'}{'tilt'} = Wx::ComboBox->new( $self, -1, 1, [-1,-1], [80, -1], [ -6, -5, -4, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 4, 5, 6]);
$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->{'button'}{'gradient'} = Wx::Button->new( $self, -1, 'Gradient', [-1,-1], [ 75, 17] );
$self->{'button'}{'complement'} = Wx::Button->new( $self, -1, 'Complement', [-1,-1], [100, 17] );
$self->{'button'}{'left'} = Wx::Button->new( $self, -1, '<', [-1,-1], [30, 17] );
$self->{'button'}{'right'} = Wx::Button->new( $self, -1, '>', [-1,-1], [30, 17] );
$self->{'button'}{'left'}->SetToolTip("Move currently selected color to the left.");
$self->{'button'}{'right'}->SetToolTip("Move currently selected color to the left.");
$self->{'button'}{'gradient'}->SetToolTip("Create gradient between first and current color. Adheres to tilt settings.");
$self->{'button'}{'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::Juliagraph::Frame::Panel::ColorPicker->new( $self, $config->get_value('color') );
$self->{'setpicker'} = App::GUI::Juliagraph::Frame::Panel::ColorSetPicker->new( $self, $config->get_value('color_set'), $self->{'color_count'});
$self->{'browser'} = App::GUI::Juliagraph::Frame::Panel::ColorBrowser->new( $self, 'selected', {red => 0, green => 0, blue => 0} );
$self->{'browser'}->SetCallBack( sub { $self->set_current_color( $_[0] ) });
Wx::Event::EVT_LEFT_DOWN( $self->{'color_display'}[$_], sub { $self->set_current_color_nr( $_[0]->get_nr ) }) for 0 .. $self->{'color_count'}-1;
Wx::Event::EVT_LEFT_DOWN( $self->{'color_marker'}[$_], sub { $self->set_current_color_nr( $_[0]->get_nr ) }) for 0 .. $self->{'color_count'}-1;
Wx::Event::EVT_BUTTON( $self, $self->{'button'}{'gradient'}, sub {
my @c = $self->get_all_colors;
my @new_colors = $c[0]->gradient( to => $c[ $self->{'current_color_nr'} ], in => 'RGB',
steps => $self->{'current_color_nr'}+1,
tilt => $self->{'widget'}{'tilt'}->GetValue );
$self->set_all_colors( @new_colors );
});
Wx::Event::EVT_BUTTON( $self, $self->{'button'}{'complement'}, sub {
my @c = $self->get_all_colors;
my @new_colors = $c[ $self->{'current_color_nr'} ]->complement( steps => $self->{'current_color_nr'}+1,
target => {
s => $self->{'widget'}{'delta_S'}->GetValue,
l => $self->{'widget'}{'delta_L'}->GetValue
},);
$self->set_all_colors( @new_colors );
});
Wx::Event::EVT_BUTTON( $self, $self->{'button'}{'left'}, sub {
my $pos = $self->get_current_color_nr;
my @colors = $self->get_all_colors;
my $selected = splice @colors, $pos, 1;
$pos--;
$pos = $self->{'color_count'} - 1 if $pos < 0;
splice @colors, $pos, 0, $selected;
$self->set_all_colors( @colors );
$self->set_current_color_nr( $pos );
});
Wx::Event::EVT_BUTTON( $self, $self->{'button'}{'right'}, sub {
( run in 0.669 second using v1.01-cache-2.11-cpan-f56aa216473 )