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;