aboutsummaryrefslogtreecommitdiff
path: root/src/MTools/Comp/MReconizer.pm
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTools/Comp/MReconizer.pm')
-rw-r--r--src/MTools/Comp/MReconizer.pm145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/MTools/Comp/MReconizer.pm b/src/MTools/Comp/MReconizer.pm
new file mode 100644
index 0000000..9605eb9
--- /dev/null
+++ b/src/MTools/Comp/MReconizer.pm
@@ -0,0 +1,145 @@
+package MTools::Comp::MReconizer;
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU LGPL Libray General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA,
+# or refer to http://www.gnu.org/copyleft/lgpl.html
+#
+##################################################################
+
+# Le composant permet de rendre un objet zinc sensible a la reco de geste
+#
+# Parametres :
+# * src : objet rendu sensible et donc source des evenements
+# * button : bouton de la souris utilise pour genere la reco de geste
+# * %options : table de hash permettant la configuration initiale des proprietes
+# Proprietes :
+# * animation_duration : duree de l'animation de disparition du feedback
+# * color : couleur du feedback
+# * callback : callback appelee sur reconnaissance
+# Evenements :
+# * START_GESTURE_RECO : evenement survenant lors du demarrage d'un geste
+# * RECONIZED : evenement survenant lorsque un geste est reconnu
+
+use strict;
+use MTools;
+use MTools::MObjet;
+use Recogestures;
+
+use MTools::Anim::MOpacity;
+
+use vars qw /@ISA/;
+
+BEGIN
+{
+ @ISA = qw /MTools::MObjet/;
+}
+
+use Tk;
+
+sub new {
+ my ($class, $src, $button, %options) = @_;
+ my $self = new MTools::MObjet ();
+ bless $self, $class;
+
+ $button = 1 if ! defined $button;
+
+ $self -> recordEvent ('RECONIZED');
+ $self -> recordEvent ('START_GESTURE_RECO');
+ $self -> recordProperty ('animation_duration', 0.5);
+ $self -> recordProperty ('color', 'blue');
+ $self -> recordProperty ('callback', undef);
+
+ $self -> mconfigure (%options);
+
+ binding ($src, "<Button-$button>", [\&__pressed, $self, Ev('x'), Ev('y')]);
+ binding ($src, "<Button$button-Motion>", [\&__moved, $self, Ev('x'), Ev('y')]);
+ binding ($src, "<ButtonRelease-$button>", [\&__released, $self, Ev('x'), Ev('y')]);
+
+ $self -> binding ('RECONIZED', sub {
+ my $methode = $self -> mget ('callback');
+ if (defined $methode)
+ {
+ executer ($methode, @_);
+ }
+ });
+ $self -> {__dessin} = undef;
+
+ $self -> {__dessin} = my $dessin = new MTools::MGroup (1);
+ $self -> {__fleche} = $zinc -> add ('curve', minstance($dessin), [[0,0],[0,0]],
+ -linecolor => 'blue',
+ -linewidth => 2,
+ -priority => 10,
+ -visible => 1,
+ -sensitive => 0,
+ );
+
+ $self -> {__anim__disparition} = new MTools::Anim::MOpacity (
+ duration => 0.8,
+ targets => $dessin,
+ from_opacity => 100,
+ to_opacity => 0,
+ );
+ binding ($self -> {__anim__disparition}, 'ANIMATION_END', [$self, \&__clear]);
+ plink ([$self, 'color'], [$self -> {__fleche}, '-linecolor']);
+ plink ([$self, 'animation_duration'], [$self -> {__anim__disparition}, 'duration']);
+
+ return $self;
+}
+
+sub __clear () {
+ my ($self, $x, $y) = @_;
+ $self -> {__points} = ();
+ $zinc -> coords ($self -> {__fleche}, 0, [[0,0],[0,0]]);
+ $self -> {__dessin} -> mconfigure (
+ -alpha => 100,
+ );
+}
+
+sub __pressed {
+ my ($self, $x, $y) = @_;
+ ($x, $y) = $zinc -> transform('device', minstance ($self -> {__dessin}), [$x, $y]);
+ if (defined $self -> {__dessin})
+ {
+ push (@{$self -> {__points}}, [$x, $y]);
+ }
+ $self -> notify ('START_GESTURE_RECO', $x, $y);
+}
+
+sub __moved {
+ my ($self, $x, $y) = @_;
+ ($x, $y) = $zinc -> transform('device', minstance ($self -> {__dessin}), [$x, $y]);
+ push (@{$self -> {trace}},$x,$y);
+
+ if (defined $self -> {__dessin})
+ {
+ push (@{$self -> {__points}}, [$x, $y]);
+ my @pts = @{$self -> {__points}};
+ $zinc -> coords ($self -> {__fleche}, 0, \@pts);
+ }
+}
+
+sub __released {
+ my ($self, $x, $y) = @_;
+
+ my ($gesture,$explanation) = AnalyzeGesture(@{$self -> {trace}});
+ $self -> {trace} = ();
+ $self -> notify ('RECONIZED', $gesture, $explanation);
+
+ if (defined $self -> {__dessin})
+ {
+ $self -> {__anim__disparition} -> start ();
+ }
+}
+
+1;
+