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
|
package MTools::GUI::MTexture;
# 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
#
##################################################################
# Permet d'appliquer un texture a un objet
# Parametres :
# * parent : pere de l'objet.
# * target : group zinc ou MTools destine a contenir les images de texture
# * image_name : nom de l'image texture
use strict;
use MTools;
use MTools::GUI::MGroup;
use MTools::GUI::MImage;
use MTools::GUI::MClip;
use vars qw / @ISA /;
BEGIN
{
@ISA = qw /MTools::GUI::MGroup/;
}
sub new {
my ($class, $parent, $target, $image_name) = @_;
my $self = new MTools::GUI::MGroup ($parent);
bless $self, $class;
chggroup ($target, $self);
my $image = new MTools::GUI::MImage ($self, $image_name);
my @bb = bbox ($image);
my $img_w = $bb [2] - $bb [0];
my $img_h = $bb [3] - $bb [1];
my @bb = bbox ($target);
my $w = $bb [2] - $bb [0];
my $h = $bb [3] - $bb [1];
mdelete ($image);
my @images_list;
for (my $x = 0; $x < $w; $x += $img_w)
{
for (my $y = 0; $y < $h; $y += $img_h)
{
$image = new MTools::GUI::MImage ($self, $image_name);
$image -> translate ($x + $bb [0], $y + $bb [1]);
push @images_list, $image;
}
}
my $clip = clone ($target);
mconfigure ($clip, -visible => 0);
if (type ($clip) eq 'group') {
my $texture = new MTools::GUI::MGroup($self);
foreach (@images_list) {
chggroup($_, $texture);
}
foreach ($zinc->find('withtag', ".$clip*")) {
if (type ($_) ne 'group') {
mconfigure ($_, -visible => 0);
new MTools::GUI::MClip (clone($texture), $_);
}
}
mdelete($texture);
} else {
new MTools::GUI::MClip ($self, $clip);
}
return $self;
}
1;
|