App-GUI-Cellgraph

 view release on metacpan or  search on metacpan

lib/App/GUI/Cellgraph/Frame/Tab/Start.pm  view on Meta::CPAN

    $self->{'widget'}{'action_summary'}->GetValue
        ? $self->{'widget'}{'action_summary'}->GetValue : 0;
}
sub set_state_summary {
    my ($self, $summary) = @_;
    return unless defined $summary and length($summary) <= $self->{'cells_in_row'};
    return if $summary eq $self->get_state_summary;
    my @list = split('', $summary);
    map {return if $_ !~ /\d/ or $_ < 0 or $_ >= $self->{'state_count'}} @list;
    $self->{'widget'}{'state_summary'}->SetValue( $summary );
    $self->set_state_list( @list );
}
sub set_action_summary {
    my ($self, $summary) = @_;
    return unless defined $summary and length($summary) <= $self->{'cells_in_row'};
    return if $summary eq $self->get_action_summary;
    my @list = split('', $summary);
    map {return unless is_action_nr($_) } @list;
    $self->{'widget'}{'action_summary'}->SetValue( $summary );
    $self->set_action_list( @list );
}

sub get_state_list {
    my ($self) = @_;
    my @list = map {$self->{'state_switches'}[$_]->GetValue} @{$self->{'cells_iterator'}};
    pop @list while @list and not $list[-1];    # remove zeros in suffix
    #unless ($self->{'widget'}{'repeat_states'}->GetValue){ shift @list while @list and not $list[0] }
    @list;
}
sub get_action_list {
    my ($self) = @_;
    my @list = map {$self->{'action_switches'}[$_]->GetValue} @{$self->{'cells_iterator'}};
    pop @list while @list and not $list[-1];    # remove zeros in suffix
    #unless ($self->{'widget'}{'repeat_action'}->GetValue){ shift @list while @list and not $list[0] }
    @list;
}
sub set_state_list {
    my ($self, @list) = @_;
    @list = (0) unless @list;
    return unless @list <= $self->{'cells_in_row'};
    map {return if $_ !~ /\d/ or $_ < 0 or $_ >= $self->{'state_count'}} @list;
    $self->set_state_summary( join '', @list );
    push @list, 0 until @list == $self->{'cells_in_row'};
    map {$self->{'state_switches'}[$_]->SetValue( $list[$_] )
            if exists $list[$_] and $list[$_] ne $self->{'state_switches'}[$_]->GetValue } @{$self->{'cells_iterator'}};
    @list;
}
sub set_action_list {
    my ($self, @list) = @_;
    @list = $self->get_action_list() unless @list;
    return unless @list <= $self->{'cells_in_row'};
    map {return unless is_action_nr($_) } @list;
    $self->set_action_summary( join '', @list );
    push @list, 0 until @list == $self->{'cells_in_row'};
    map { $self->{'action_switches'}[$_]->SetValue( $list[$_] )
            if exists $list[$_] and $list[$_] ne $self->{'action_switches'}[$_]->GetValue } @{$self->{'cells_iterator'}};
    @list;
}


sub update_cell_colors {
    my ($self, @colors) = @_;
    return if @colors < 2;
    my $do_recolor = @colors == $self->{'state_count'} ? 0 : 1;
    for my $i (0 .. $#colors) {
        return unless ref $colors[$i] eq 'Graphics::Toolkit::Color';
        if (exists $self->{'state_colors'}[$i]) {
            my @rgb = $colors[$i]->rgb;
            $do_recolor += !( $rgb[$_] == $self->{'state_colors'}[$i][$_]) for 0 .. 2;
        } else { $do_recolor++ }
    }
    return unless $do_recolor;
    my @rgb = map {[$_->values('rgb')]} @colors;
    $self->{'state_switches'}[$_]->SetColors( @rgb ) for @{$self->{'cells_iterator'}};
    $self->{'state_count'} = @colors;
}

sub set_callback {
    my ($self, $code) = @_;
    return unless ref $code eq 'CODE';
    $self->{'call_back'} = $code;
}

########################################################################
sub prev_state {
    my ($self) = @_;
    my @list = $self->get_state_list;
    return $self->set_state_list( ($self->{'state_count'} - 1) x $self->{'cells_in_row'})
        if @list == 1 and $list[0] == 1;
    my $pos = 0;
    while ($pos < @list){
        $list[$pos]--;
        return $self->set_state_list(@list) if $list[$pos] >= 0;
        $list[$pos] = $self->{'state_count'} - 1;
        $pos++;
    }
    $self->set_state_list( ($self->{'state_count'} - 1) x $self->{'cells_in_row'});
}

sub next_state {
    my ($self) = @_;
    my @list = $self->get_state_list;
    my $pos = 0;
    while ($pos < @list){
        $list[$pos]++;
        return $self->set_state_list(@list) unless $list[$pos] == $self->{'state_count'};
        $list[$pos] = 0;
        $pos++;
    }
    if (@list == $self->{'cells_in_row'}) {$self->set_state_list(1) }
    else {
        push @list, 1;
        $self->set_state_list(@list);
    }
}

sub prev_action {
    my ($self) = @_;
    my @list = $self->get_action_list;
    return $self->set_action_list( (5) x $self->{'cells_in_row'})
        if @list == 1 and $list[0] == 1;



( run in 1.010 second using v1.01-cache-2.11-cpan-ceb78f64989 )