aboutsummaryrefslogtreecommitdiff
path: root/src/MTools
diff options
context:
space:
mode:
authorribet2007-08-30 15:39:35 +0000
committerribet2007-08-30 15:39:35 +0000
commit0790140618e92d3d10582d58b688e8d09917b370 (patch)
treea8c62bc9482d290c9e0885ce557666196af17782 /src/MTools
parent9ff3c552b819fc065bf963639bbd72b427b58dd9 (diff)
downloadmtc-0790140618e92d3d10582d58b688e8d09917b370.zip
mtc-0790140618e92d3d10582d58b688e8d09917b370.tar.gz
mtc-0790140618e92d3d10582d58b688e8d09917b370.tar.bz2
mtc-0790140618e92d3d10582d58b688e8d09917b370.tar.xz
Amélioration de la gestion de la callback en cours de déplacement. Gestion de l'interruption corrigée.
Diffstat (limited to 'src/MTools')
-rw-r--r--src/MTools/Comp/MInertie.pm36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/MTools/Comp/MInertie.pm b/src/MTools/Comp/MInertie.pm
index 9b820a0..2faa1b9 100644
--- a/src/MTools/Comp/MInertie.pm
+++ b/src/MTools/Comp/MInertie.pm
@@ -25,8 +25,7 @@ use MTools::MTimer;
use vars qw /@ISA/;
-BEGIN
-{
+BEGIN {
@ISA = qw /MTools::MObjet/;
}
@@ -50,7 +49,7 @@ sub new {
$self -> recordProperty ('target', $target);
$self -> recordProperty ('-visible', 1);
$self -> recordProperty ('rate', 0.85);
- $self -> recordProperty ('inertie_callback', 'translate');
+ $self -> recordProperty ('inertie_callback', [$target, 'translate']);
$self -> recordEvent ($msg_stopped);
$self -> mconfigure (%options);
@@ -63,6 +62,8 @@ sub new {
$self -> {__t} = 0;
$self -> {__vx} = 0;
$self -> {__vy} = 0;
+
+ $self -> {__isRunning} = 0;
$self -> {__msg_stopped} = $msg_stopped;
@@ -77,12 +78,15 @@ sub new {
sub interrupt {
my ($self) = @_;
- $self -> {timer_inertie} -> stop ();
+ if ($self -> {__isRunning}) {
+ $self -> {__isRunning} = 0;
+ $self -> {timer_inertie} -> stop ();
+ $self -> notify ($self -> {__msg_stopped});
+ }
}
sub target_pressed {
my ($self, $x, $y, $t) = @_;
- $self -> interrupt ();
$self -> {__old_x} = 0;
$self -> {__old_y} = 0;
$self -> {__old_t} = 0;
@@ -93,8 +97,7 @@ sub target_pressed {
sub target_moved {
my ($self, $x, $y, $t) = @_;
- if (!defined $t)
- {
+ if (!defined $t) {
$t = Time::HiRes::gettimeofday();
}
$self -> {__old_x} = $self -> {__x};
@@ -107,21 +110,19 @@ sub target_moved {
sub target_released {
my ($self, $x, $y, $t) = @_;
- if (!defined $t)
- {
+ if (!defined $t) {
$t = Time::HiRes::gettimeofday();
}
my $dt = $self -> {__t} - $self -> {__old_t};
my $dx = $self -> {__x} - $self -> {__old_x};
my $dy = $self -> {__y} - $self -> {__old_y};
- if ($dt && $self -> mget ('-visible'))
- {
+ if ($dt && $self -> mget ('-visible')) {
$self -> {__vx} = ($dx * 1000) / ($dt * 60);
$self -> {__vy} = ($dy * 1000) / ($dt * 60);
+ $self -> {__isRunning} = 1;
$self -> {timer_inertie} -> start();
}
- else
- {
+ else {
$self -> notify ($self -> {__msg_stopped});
}
$self -> {__old_x} = 0;
@@ -137,17 +138,16 @@ sub inertie {
my $rate = $self -> mget ('rate');
$self -> {__vx} *= $rate;
$self -> {__vy} *= $rate;
- if ((abs $self -> {__vx} <= 2) and (abs $self -> {__vy} <= 2))
- {
- $self -> notify ($self -> {__msg_stopped});
- $self -> {timer_inertie} -> stop();
+ if ((abs $self -> {__vx} <= 2) and (abs $self -> {__vy} <= 2)) {
+ $self -> interrupt ();
return;
}
my $dx = $self -> {__vx};
my $dy = $self -> {__vy};
my $target = $self -> mget ('target');
my $callback = $self -> mget ('inertie_callback');
- $target -> $callback ($dx, $dy);
+ executer ($callback, $dx, $dy);
+# $target -> $callback ($dx, $dy);
}
1;