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