aboutsummaryrefslogtreecommitdiff
path: root/exemples/Strip.pm
blob: 2997e251fead15216a2713fb2772dd8d32303372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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;