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 # * pattern : nom d'un fichier image ou objet MTools. 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, $pattern) = @_; my $self = new MTools::GUI::MGroup ($parent); bless $self, $class; chggroup ($target, $self); my ($img_w, $img_h, $offset_x, $offset_y); if (ref($pattern) eq '') { my $image = new MTools::GUI::MImage ($self, $pattern); my @bb = bbox ($image); $img_w = $bb [2] - $bb [0]; $img_h = $bb [3] - $bb [1]; mdelete ($image); } else { my @bb = bbox ($pattern); $img_w = $bb [2] - $bb [0]; $img_h = $bb [3] - $bb [1]; $offset_x = -$bb [0]; $offset_y = -$bb [1]; } my @bb = bbox ($target); my $w = $bb [2] - $bb [0]; my $h = $bb [3] - $bb [1]; $offset_x += $bb [0]; $offset_y += $bb [1]; my @images_list; my $image; for (my $x = 0; $x < $w; $x += $img_w) { for (my $y = 0; $y < $h; $y += $img_h) { if (ref($pattern) eq '') { $image = new MTools::GUI::MImage ($self, $pattern); } else { $image = clone($pattern); chggroup($image, $self); } translate ($image, $x + $offset_x, $y + $offset_y); 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;