package Strip; # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU GPL 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 General Public License for more details. # # You should have received a copy of the GNU 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/gpl.html # use strict; use vars qw /@ISA/; use MTools; use MTools::MGroup; use MTools::Widget::MToggleBouton; use MTools::Comp::MMover; use MTools::Comp::MReconizer; use MTools::Comp::MInertie; BEGIN { @ISA = qw /MTools::MGroup/; } sub new { my ($class, $parent, %options) = @_; my $self = new MTools::MGroup ($parent); bless $self, $class; $self -> recordEvent ('SET_FOCUS'); $self -> recordEvent ('GET_FOCUS'); $self -> recordProperty ('x', 0); $self -> recordProperty ('y', 0); my $gp1 = new MTools::MGroup ($self); my $gp2 = new MTools::MGroup ($self); my $gp3 = new MTools::MGroup ($self); my $gp4 = new MTools::MGroup ($self); # Instanciation d'un petit bouton rouge qui aura pour objectif # de fixer ou non le strip (desactiver le comportement de mover) my $bouton1 = new MTools::Widget::MToggleBouton ( parent => $self, g_on => 'strip.svg#alarme_on', g_off => 'strip.svg#alarme_off', e_press => 'ALARME_PRESS', e_release => 'ALARME_RELEASE' ); # Instanciation des objets textes situe sur la premiere partie du strip # Disparaitra lorsque le strip est shoote minstanciate ('strip.svg#vitesse', $gp2); minstanciate ('strip.svg#fl', $gp2); # Instanciation des objets textes situ? sur la deuxieme partie du strip # Disparaitra lorsque le strip est deplace minstanciate ('strip.svg#balise1', $gp3); minstanciate ('strip.svg#fl1', $gp3); minstanciate ('strip.svg#balise2', $gp3); minstanciate ('strip.svg#fl2', $gp3); # Instanciation du callsign toujours visible my $callsign = minstanciate ('strip.svg#callsign', $self); mconfigure ($callsign, -text => $options {callsign}); # Instanciation de la fleche de tendance qui peut avoir trois etat different $self -> {evolution} = new MTools::MSwitch ( $gp2, stable => ['strip.svg#evolution_stable'], montee => ['strip.svg#evolution_monte'], descente => ['strip.svg#evolution_descend'], ); $self -> {evolution} -> mconfigure (state => 'montee'); # Definition des trois etats des strips $self -> {strip} = new MTools::MSwitch ( $gp1, grand => ['strip.svg#strip_grand', $gp2, $gp3, $callsign, $bouton1], mini => ['strip.svg#strip_mini', $gp2, $callsign, $bouton1], shoote => ['strip.svg#strip_shoote', $callsign], ); $self -> {strip} -> setState ('grand'); # Instanciation du comportement de prehensible $self -> {mover} = my $mover = new MTools::Comp::MMover($self -> {strip}, $self, 1, x_min => 0, y_min => 0, x_max => 700, y_max => 300, ); # Instanciation du comportement d'inertie new MTools::Comp::MInertie ($self -> {mover}); # On modifie la valeur des propriete x et y sur deplacement $mover -> binding ('MOVED', sub { my ($x, $y) = @_; mconfigure ($self, x => $x); mconfigure ($self, y => $y); }); # Instanciation des mask pour la reco de geste $self -> {mask} = new MTools::MSwitch ( $gp4, grand => ['strip.svg#mask_grand'], mini => ['strip.svg#mask_mini'], shoote => [], ); $self -> {mask} -> setState ('grand'); # Lorsque la propriete y est modifiee, on appel la fonction 'moved' # Cette fonction modifiera l'etat du strip en fonction de la position de celui-ci $self -> plisten ('y', ['moved', $self]); # Instanciation de la reco de geste new MTools::Comp::MReconizer ($self -> {mask}, 1, callback => [$self, \&geste_reconnu]); # Activation et desactivation du comportement prehensible sur pression sur le petit bouton rouge $bouton1 -> binding ('ALARME_PRESS', sub { $mover -> mconfigure (-visible => 0); }); $bouton1 -> binding ('ALARME_RELEASE', sub { $mover -> mconfigure (-visible => 1); }); # Feedback de selection $self -> {selected} = new MTools::MSwitch ( $self, selected => ['strip.svg#selected'], unselected => [], ); $self -> {selected} -> setState ('unselected'); # Mise ? jour du focus sur pression (capt?e par le MMover) $mover -> binding ('PRESSED', sub { $self -> {selected} -> setState ('selected'); $self -> notify ('GET_FOCUS', $self); }); # Mise ? jour du focus par message externe $self -> binding ('SET_FOCUS', sub { $self -> {selected} -> setState ('unselected'); }); return $self; } sub geste_reconnu { my ($self, $geste) = @_; print "geste : $geste\n"; } sub moved { my ($self) = @_; my $x = $self -> mget ('x'); my $y = $self -> mget ('y'); if ($x < 50) { $self -> {strip} -> setState ('grand'); $self -> {mask} -> setState ('grand'); $self -> {evolution} -> setState ('montee'); } if (($x >= 50) && ($x < 100)) { $self -> {strip} -> setState ('grand'); $self -> {mask} -> setState ('grand'); $self -> {evolution} -> setState ('stable'); } if (($x >= 100) && ($x < 300)) { $self -> {strip} -> setState ('mini'); $self -> {mask} -> setState ('mini'); $self -> {evolution} -> setState ('stable'); } if (($x >= 300) && ($x < 600)) { $self -> {strip} -> setState ('mini'); $self -> {mask} -> setState ('mini'); $self -> {evolution} -> setState ('descente'); } if (($x >= 600) && ($x < 700)) { $self -> {strip} -> setState ('shoote'); $self -> {mask} -> setState ('shoote'); $self -> {evolution} -> setState ('descente'); } } 1;