# Map # This class holds the information needed to draw a map. This # includes the labels displayed on the map. Labels will be displayed # relative to the map, not the whole image. # package Image; use GD; use Canvas; use Carp; use Util; require Exporter; @ISA = qw( Exporter ); @EXPORT = qw(); @EXPORT_OK = qw(); use strict; my $MAGIC_NUMBER = 9234987298; sub new { my ($this, $linenum, $parent) = @_; my $canvas = new Canvas(); my $map = bless { "type" => "Image", "linenum" => $linenum, "majic" => $MAGIC_NUMBER, "x" => 0, "y" => 0, "width" => undef, "hieght" => undef, "image" => undef, "canvas" => $canvas, "image-loaded" => undef, }, $this; return $map; } sub loadCanvas() { my ($this) = @_; if (defined $this->{image}) { my $big_canvas = new Canvas($this->{image}); $this->{canvas} = $big_canvas->duplicate( $this->{width}, $this->{height}); my ($width, $height) = ($this->{width}, $this->{height}) = $this->{canvas}->getBounds(); $this->{"image-loaded"} = 1; } #print "loadCanvas:$this->{image} width:$width height:$height\n"; } sub check() { my ($this) = @_; my @missing; my $linenum = $this->{linenum}; unless (defined $this->{image}) { return "no image defined"; } return; } sub draw { my ($this,$canvas) = @_; my $image = $this->{canvas}->{IMAGE}; if (defined $image) { my ($x, $y, $width, $height) = ($this->{x}, $this->{y}, $this->{width}, $this->{height}); $canvas->{IMAGE}->copy($image, $x, $y, 0,0, $width, $height); } } ############################################################################ # Setting values ########################################################################### sub setValue { my ($this, $key, $value) = @_; if ($key eq "image") { return $this->setImage($value); } $this->{$key} = $value; return; } sub setImage($) { my ($this, $file) = @_; unless (-f $file) { return ("Unable to find file $file:$!"); } $this->{"image"} = $file; return; }