| 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::Widget::ProgressBar; | ||
| 6 | use base qw/Wx::Panel/; | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my ( $class, $parent, $x, $y, $color ) = @_; | ||
| 10 | return unless ref $color eq 'ARRAY' and @{$color} == 3; | ||
| 11 | |||
| 12 | my $self = $class->SUPER::new( $parent, -1, [-1,-1], [$x, $y]); | ||
| 13 | |||
| 14 | $self->{'x'} = $x; | ||
| 15 | $self->{'y'} = $y; | ||
| 16 | $self->{'color'} = $color; | ||
| 17 | $self->{'rainbow'} = []; | ||
| 18 | |||
| 19 | Wx::Event::EVT_PAINT( $self, sub { | ||
| 20 | my( $cpanel, $event ) = @_; | ||
| 21 | my $dc = Wx::PaintDC->new( $cpanel ); | ||
| 22 | my $bg_color = Wx::Colour->new( 255, 255, 255 ); | ||
| 23 | my ($x, $y) = ( $self->GetSize->GetWidth, $self->GetSize->GetHeight ); | ||
| 24 | $dc->SetBackground( Wx::Brush->new( $bg_color, &Wx::wxBRUSHSTYLE_SOLID ) ); | ||
| 25 | $dc->Clear(); | ||
| 26 | |||
| 27 | my $l_pos = 0; | ||
| 28 | my $l_color = Wx::Colour->new( @{$self->{'color'}} ); | ||
| 29 | for my $entry (@{$self->{'rainbow'}}) { | ||
| 30 | my $r_color = Wx::Colour->new( @{$entry->{'color'}} ); | ||
| 31 | my $r_pos = $x * $entry->{'percent'} / 100; | ||
| 32 | $dc->GradientFillLinear( Wx::Rect->new( $l_pos, 0, $r_pos, $y ), $l_color, $r_color ); | ||
| 33 | $l_pos = $r_pos; | ||
| 34 | $l_color = $r_color; | ||
| 35 | } | ||
| 36 | } ); | ||
| 37 | |||
| 38 | $self; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub reset { | ||
| 42 | my ( $self, $p, $color ) = @_; | ||
| 43 | $self->{'color'} = [255, 255, 255]; | ||
| 44 | $self->{'rainbow'} = []; | ||
| 45 | $self->paint; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub set_start_color { | ||
| 49 | my ( $self, $r, $g, $b ) = @_; | ||
| 50 | return unless defined $b; | ||
| 51 | $self->{'color'} = [$r, $g, $b]; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub add_percentage { | ||
| 55 | my ( $self, $percent, $color ) = @_; | ||
| 56 | return unless defined $percent and $percent <= 100 and $percent >= 0 | ||
| 57 | and $percent > $self->get_percentage and ref $color eq 'ARRAY' and @$color == 3; | ||
| 58 | push @{$self->{'rainbow'}}, {color => $color, percent => $percent}; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub get_percentage { (@{$_[0]->{'rainbow'}}) ? $_[0]->{'rainbow'}[-1]{'percent'} : 0 } | ||
| 62 | |||
| 63 | sub paint { $_[0]->Refresh } | ||
| 64 | |||
| 65 | |||
| 66 | 1; | ||