aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorribet2007-08-22 14:57:07 +0000
committerribet2007-08-22 14:57:07 +0000
commit286c1d6086ae6e280b35c24fcbee90957fe1acb4 (patch)
tree5fc0154162c18b5590a5887e1ef61c21d5644efb /src
parent332ce0e6b8202a2b8eb07dced11bc5297528c8bf (diff)
downloadmtc-286c1d6086ae6e280b35c24fcbee90957fe1acb4.zip
mtc-286c1d6086ae6e280b35c24fcbee90957fe1acb4.tar.gz
mtc-286c1d6086ae6e280b35c24fcbee90957fe1acb4.tar.bz2
mtc-286c1d6086ae6e280b35c24fcbee90957fe1acb4.tar.xz
Extending texture capability to any pattern (any MTools object, be it text, image... or even loaded svg).
Diffstat (limited to 'src')
-rw-r--r--src/MTools/GUI/MTexture.pm37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/MTools/GUI/MTexture.pm b/src/MTools/GUI/MTexture.pm
index 13ad4aa..6362832 100644
--- a/src/MTools/GUI/MTexture.pm
+++ b/src/MTools/GUI/MTexture.pm
@@ -20,7 +20,7 @@ package MTools::GUI::MTexture;
# 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
+# * pattern : nom d'un fichier image ou objet MTools.
use strict;
@@ -38,31 +38,48 @@ BEGIN
}
sub new {
- my ($class, $parent, $target, $image_name) = @_;
+ my ($class, $parent, $target, $pattern) = @_;
my $self = new MTools::GUI::MGroup ($parent);
bless $self, $class;
chggroup ($target, $self);
- my $image = new MTools::GUI::MImage ($self, $image_name);
+ 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 ($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);
+ $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)
{
- $image = new MTools::GUI::MImage ($self, $image_name);
- $image -> translate ($x + $bb [0], $y + $bb [1]);
+ 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;
}
}