From: Dobrica Pavlinusic Date: Wed, 19 May 2010 12:05:54 +0000 (+0200) Subject: draw dots only if mouse moved more than trashold X-Git-Url: http://git.rot13.org/?p=perl-landing-airplanes.git;a=commitdiff_plain;h=bf08ab193ba6aeed8d356123374505f543bb67a0 draw dots only if mouse moved more than trashold --- diff --git a/trace-path.pl b/trace-path.pl index 8232a2a..9a27b35 100755 --- a/trace-path.pl +++ b/trace-path.pl @@ -13,6 +13,7 @@ use Carp qw/confess/; use Data::Dump qw/dump/; my ( $w, $h ) = ( 800, 480 ); +my $mouse_trashold = 10; our $app = SDL::App->new( -width => $w, @@ -28,6 +29,8 @@ our $mouse_down = 0; our $white = SDL::Color->new( 0xff, 0xff, 0xff ); +my ( $last_x, $last_y ) = ( 0,0 ); + sub handle_events { while ( $event->wait ) { @@ -48,11 +51,16 @@ sub handle_events { warn "key up ", $event->key_name,$/; } elsif ( $type == SDL_MOUSEMOTION() ) { # warn "mouse ", $event->motion_xrel, ' ', $event->motion_yrel; - warn "mouse $mouse_down @ ", $event->motion_x, ' ', $event->motion_y; - if ( $mouse_down ) { + my ( $x, $y ) = ( $event->motion_x, $event->motion_y ); + warn "mouse $mouse_down @ $x*$y\n"; + my $dx = abs( $last_x - $x ); + my $dy = abs( $last_y - $y ); + if ( $mouse_down && ( $dx > $mouse_trashold || $dy > $mouse_trashold ) ) { my $rect = SDL::Rect->new( -x => $event->motion_x, -y => $event->motion_y, -w => 3, -h => 3 ); $app->fill( $rect, $white ); $app->update( $rect ); + $last_x = $x; + $last_y = $y; } } else { warn "unknown $type\n";