App-GUI-Harmonograph

 view release on metacpan or  search on metacpan

lib/App/GUI/Wx/Widget/Custom/Canvas.pm  view on Meta::CPAN


# area to draw on and safe it into files

package App::GUI::Wx::Widget::Custom::Canvas;
use v5.12;
use warnings;
use Wx;
use base qw/Wx::Panel/;
use App::GUI::Harmonograph::Compute::Drawing;

sub new {
    my ( $class, $parent, $x, $y ) = @_;
    my $self = $class->SUPER::new( $parent, -1, [-1,-1], [$x, $y] );
    $self->{'menu_size'} = 27;
    $self->{'size'}{'x'} = $x;
    $self->{'size'}{'y'} = $y;
    $self->{'center'}{'x'} = $x / 2;
    $self->{'center'}{'y'} = $y / 2;
    $self->{'dc'} = Wx::MemoryDC->new( );
    $self->{'bmp'} = Wx::Bitmap->new( $self->{'size'}{'x'} + 10, $self->{'size'}{'y'} +10 + $self->{'menu_size'}, 24);
    $self->{'dc'}->SelectObject( $self->{'bmp'} );
    $self->{'tab'}{'constraint'} = '';

    Wx::Event::EVT_PAINT( $self, sub {
        my( $self, $event ) = @_;

        return unless ref $self->{'settings'};
        $self->{'x_pos'} = $self->GetPosition->x;
        $self->{'y_pos'} = $self->GetPosition->y;

        if (exists $self->{'flag'}{'new'}) {
            $self->{'dc'}->Blit (0, 0, $self->{'size'}{'x'} + $self->{'x_pos'},
                                       $self->{'size'}{'y'} + $self->{'y_pos'} + $self->{'menu_size'},
                                       $self->paint( Wx::PaintDC->new( $self ), $self->{'size'}{'x'}, $self->{'size'}{'y'} ), 0, 0);
        } else {
            Wx::PaintDC->new( $self )->Blit (0, 0, $self->{'size'}{'x'},
                                                   $self->{'size'}{'y'} + $self->{'menu_size'},
                                                   $self->{'dc'},
                                                   $self->{'x_pos'} , $self->{'y_pos'} + $self->{'menu_size'} );
        }
        1;
    }); # Blit
    #  Wx::Event::EVT_ENTER_WINDOW( $self, sub {  });
    #  Wx::Event::EVT_LEFT_DOWN( $self, sub { });
    #  Wx::Event::EVT_MOTION( $self, sub { });
    Wx::Event::EVT_LEFT_DOWN( $self, sub {
        #~ my $dx = ($pos->x / $self->{'center'}{'x'} ) - 1;
        #~ my $dy = ($pos->y / $self->{'center'}{'y'} ) - 1;
    });
    Wx::Event::EVT_LEFT_DCLICK( $self, sub {
        #~ my $dx = ($pos->x / $self->{'center'}{'x'} ) - 1;
        #~ my $dy = ($pos->y / $self->{'center'}{'y'} ) - 1;
    });
    Wx::Event::EVT_RIGHT_DOWN( $self, sub {
        #~ my $dx = ($pos->x / $self->{'center'}{'x'} ) - 1;
        #~ my $dy = ($pos->y / $self->{'center'}{'y'} ) - 1;
    });
    Wx::Event::EVT_MIDDLE_DOWN( $self, sub {
        #~ my $dx = ($pos->x / $self->{'center'}{'x'} ) - 1;
        #~ my $dy = ($pos->y / $self->{'center'}{'y'} ) - 1;

    });

    return $self;
}

sub connect_constrains_tab {
    my ($self, $ref) = @_;
    return unless ref $ref eq 'App::GUI::Spirograph::Frame::Tab::Constraints';
    $self->{'tab'}{'constraint'} = $ref;
}

sub draw {



( run in 1.003 second using v1.01-cache-2.11-cpan-98e64b0badf )