App-PLab

 view release on metacpan or  search on metacpan

bin/PrAverB  view on Meta::CPAN

      ( $_[0] == $_[2]) &&
      ( $_[6] == $_[4]) &&
      ( $_[1] == $_[7]) &&
      ( $_[5] == $_[3]);
   return $self;
}

sub destroy
{
   my $me = $_[0];
   my $w = $_[0]->{owner};
   $w-> {selectedRect} = undef if $w-> {selectedRect} && $_[0] == $w-> {selectedRect};
   my $i = 0;
   for ( @{$w->{rects}}) {
      last if $_ == $me;
      $i++
   };
   splice( @{$w->{rects}}, $i, 1) if $i <= scalar @{$w->{rects}};
   $me-> {IV}-> repaint;
}

sub rect2boundary
{
   my ( $self, @r) = @_;
   my @b;
   $b[0] = $b[2] = $r[0];
   my $i;
   for ( $i = 2; $i < scalar @r; $i += 2) {
      $b[0] = $r[$i] if $b[0] > $r[$i];
      $b[2] = $r[$i] if $b[2] < $r[$i];
   }
   $b[1] = $b[3] = $r[1];
   for ( $i = 1; $i < scalar @r; $i+=2) {
      $b[1] = $r[$i] if $b[1] > $r[$i];
      $b[3] = $r[$i] if $b[3] < $r[$i];
   }
   return @b;
}


sub get_screen_bounds
{
   my @b = $_[0]-> {IV}-> point2screen( @{$_[0]-> {bounds}});
   $b[0]-=5;
   $b[1]-=5;
   $b[2]+=5;
   $b[3]+=5;
   return @b;
}


sub on_mousedown
{
   my ( $me, $w, $self, $btn, $mod, $x, $y, $ax, $ay) = @_;
   my @r = $me-> get_screen_bounds;

   if ( $x >= $r[0] && $x < $r[2] && $y >= $r[1] && $y < $r[3]) {
      $me-> {lastStateSelected} = $me-> selected;
      $me-> select;
      if ( $btn == mb::Right) {
         $w-> FigurePopup-> popup( $w-> pointerPos);
         $w-> iv_cancelmode( $self);
         return 1;
      }

      return 0 if  $btn != mb::Left;

      $self-> {savePointer} = $self-> pointer;
      my $part = $me-> xy2part( $x, $y);
      if ( $part eq q(client)) {
         $me-> open_transaction( tran::move, $x, $y, $ax, $ay);
         $self-> pointer( cr::Move);
         $w-> sb_text("Drag region");
      } elsif ( $part =~ /^Size/) {
         $part =~ s/^Size//;
         if ( $me->{state} == 0) {
            my ( $xa, $ya) = ( 0,0);
            if    ( $part eq q(S))   { ( $xa, $ya) = ( 0,-1); }
            elsif ( $part eq q(N))   { ( $xa, $ya) = ( 0, 1); }
            elsif ( $part eq q(W))   { ( $xa, $ya) = (-1, 0); }
            elsif ( $part eq q(E))   { ( $xa, $ya) = ( 1, 0); }
            elsif ( $part eq q(SW)) { ( $xa, $ya) = (-1,-1); }
            elsif ( $part eq q(NE)) { ( $xa, $ya) = ( 1, 1); }
            elsif ( $part eq q(NW)) { ( $xa, $ya) = (-1, 1); }
            elsif ( $part eq q(SE)) { ( $xa, $ya) = ( 1,-1); }
            $self-> {dirData} = [$xa, $ya];
            $me-> open_transaction( tran::size, $x, $y, $ax, $ay);
            $w-> sb_text("Scale region");
            $self-> {oldRect} = [ @{$self-> { xorData}}];
         } else {
            my ( $xa, $ya) = ( 0,0);
            if    ( $part eq q(S))   { ( $xa, $ya) = ( 0,-1); }
            elsif ( $part eq q(N))   { ( $xa, $ya) = ( 0, 1); }
            elsif ( $part eq q(W))   { ( $xa, $ya) = (-1, 0); }
            elsif ( $part eq q(E))   { ( $xa, $ya) = ( 1, 0); }
            if ( $xa != 0 || $ya != 0) {
               $self-> {dirData} = [$xa, $ya];
               $me-> open_transaction( tran::skew, $x, $y, $ax, $ay);
               $w-> sb_text("Skew region");
               return 1;
            }
            my @r =  $self-> point2screen( @{$me-> {bounds}});
            my @cn = (($r[2] + $r[0] + 1)/2, ($r[3] + $r[1] + 1)/2);
            $self-> {anchor}  = atan2( $y - $cn[1], $x - $cn[0]);
            $self-> {dirData} = [@cn];
            $me-> open_transaction( tran::rotate, $x, $y, $ax, $ay);
            $self-> {oldRect} = [ @{$self-> { xorData}}];
            $w-> sb_text("Rotate region");
         }
      }
      return 1;
   }
   return 0;
}


sub xy2part
{
   my ( $me, $x, $y) = @_;
   my @r = $me-> get_screen_bounds;
   $_ -= $r[0] for ( $r[2], $x);



( run in 0.812 second using v1.01-cache-2.11-cpan-364913b4093 )