| 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::ColorDisplay; | ||
| 6 | use base qw/Wx::Panel/; | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my ( $class, $parent, $x, $y, $nr, $init ) = @_; | ||
| 10 | return unless ref $init eq 'HASH' and exists $init->{'red'} and exists $init->{'green'}and exists $init->{'blue'}; | ||
| 11 | |||
| 12 | my $self = $class->SUPER::new( $parent, -1, [-1,-1], [$x, $y]); | ||
| 13 | |||
| 14 | Wx::Event::EVT_PAINT( $self, sub { | ||
| 15 | my( $cpanel, $event ) = @_; | ||
| 16 | return unless exists $self->{'blue'} and exists $self->{'red'} and exists $self->{'green'}; | ||
| 17 | my $dc = Wx::PaintDC->new( $cpanel ); | ||
| 18 | my $bg_color = Wx::Colour->new( $self->{'red'}, $self->{'green'}, $self->{'blue'} ); | ||
| 19 | $dc->SetBackground( Wx::Brush->new( $bg_color, &Wx::wxBRUSHSTYLE_SOLID ) ); | ||
| 20 | $dc->Clear(); | ||
| 21 | } ); | ||
| 22 | $self->{'init'} = $init; | ||
| 23 | $self->{'nr'} = $nr; | ||
| 24 | $self->set_color( $init ); | ||
| 25 | $self; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub init { | ||
| 29 | my ($self) = @_; | ||
| 30 | $self->set_color( $self->{'init'} ); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub set_color { | ||
| 34 | my ( $self, $color ) = @_; | ||
| 35 | return unless ref $color eq 'HASH' and exists $color->{'red'} and exists $color->{'green'} and exists $color->{'blue'}; | ||
| 36 | $self->{$_} = $color->{$_} for qw/red green blue/; | ||
| 37 | $self->Refresh; | ||
| 38 | |||
| 39 | } | ||
| 40 | |||
| 41 | sub get_color { | ||
| 42 | my ( $self ) = @_; | ||
| 43 | { | ||
| 44 | red => $self->{'red'}, | ||
| 45 | green => $self->{'green'}, | ||
| 46 | blue => $self->{'blue'}, | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | sub get_nr { $_[0]->{'nr'} } | ||
| 51 | |||
| 52 | sub SetCallBack { | ||
| 53 | my ( $self, $code) = @_; | ||
| 54 | return unless ref $code eq 'CODE'; | ||
| 55 | $self->{'callback'} = $code; | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||