diff options
Diffstat (limited to 'exemples/Lien.pm')
-rw-r--r-- | exemples/Lien.pm | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/exemples/Lien.pm b/exemples/Lien.pm new file mode 100644 index 0000000..d8665bc --- /dev/null +++ b/exemples/Lien.pm @@ -0,0 +1,115 @@ +package Lien; +# 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 MTools; +use MTools::MGroup; +use MTools::GUI::MCurve; + +use vars qw /@ISA/; + + +BEGIN +{ + @ISA = qw /MTools::MGroup/; +} + +sub new { + my ($class, $parent, $comete_1, $comete_2, %options) = @_; + my $self = new MTools::MGroup ($parent); + bless $self, $class; + + $self -> recordProperty ('comete_1', $comete_1); + $self -> recordProperty ('comete_2', $comete_2); + $self -> recordProperty ('distance', 100); + $self -> recordProperty ('c_x', 0); + $self -> recordProperty ('c_y', 0); + $self -> recordProperty ('warning', 0); + + $self -> {__lien} = new MTools::GUI::MCurve ($self, [[0, 0], [0, 0]], + -linecolor => defined $options {color} ? $options {color} : '#243033;60', + -linestyle => 'dashed', + -linewidth => defined $options {width} ? $options {width} : 2, + -filled => 0, -visible => 1, -sensitive => 0 + ); + $self -> plisten ('warning', sub { + my ($src, $key, $val, $old) = @_; + if ($val) + { + $self -> {__lien} -> mconfigure ( + -linecolor => 'red', + -linewidth => 8, + -linestyle => 'simple', + ); + } + else + { + $self -> {__lien} -> mconfigure ( + -linecolor => '#243033;60', + -linestyle => 'dashed', + -linewidth => defined $options {width} ? $options {width} : 2, + ); + } + }); + $self -> {__c1_x} = $comete_1 -> plisten ('x', [$self, 'redraw']); + $self -> {__c1_y} = $comete_1 -> plisten ('y', [$self, 'redraw']); + $self -> {__c2_x} = $comete_2 -> plisten ('x', [$self, 'redraw']); + $self -> {__c2_y} = $comete_2 -> plisten ('y', [$self, 'redraw']); + + $comete_1 -> addRattrapage ($self); + $comete_2 -> addRattrapage ($self); + + return $self; +} + +sub mdelete { + my ($self) = @_; + my $comete_1 = $self -> mget ('comete_1'); + my $comete_2 = $self -> mget ('comete_2'); + $comete_1 -> unplisten ('x', $self -> {__c1_x}); + $comete_1 -> unplisten ('y', $self -> {__c1_y}); + $comete_2 -> unplisten ('x', $self -> {__c2_x}); + $comete_2 -> unplisten ('y', $self -> {__c2_y}); + $comete_1 -> removeRattrapage ($self); + $comete_2 -> removeRattrapage ($self); + MTools::mdelete ($self); +} + +sub redraw { + my ($self) = @_; + my $comete_1 = $self -> mget ('comete_1'); + my $comete_2 = $self -> mget ('comete_2'); + my $x0 = $comete_1 -> mget ('x'); + my $y0 = $comete_1 -> mget ('y'); + my $x1 = $comete_2 -> mget ('x'); + my $y1 = $comete_2 -> mget ('y'); + $self -> {__lien} -> coords ([$x0, $y0, $x1, $y1]); + my $cautra_x0 = $comete_1 -> mget ('cautrax'); + my $cautra_y0 = $comete_1 -> mget ('cautray'); + my $cautra_x1 = $comete_2 -> mget ('cautrax'); + my $cautra_y1 = $comete_2 -> mget ('cautray'); + my $dist = sqrt (($cautra_x1 - $cautra_x0) ** 2 + ($cautra_y1 - $cautra_y0) ** 2); + $self -> mconfigure ( + distance => int ($dist * 10) / 10, + c_x => ($x0 + $x1) / 2, + c_y => ($y0 + $y1) / 2, + ); + +} + +1; |