5 CXGN::Cview::ImageObject - parent class for all image objects in Cview.
9 This class defines and implements a number of functions. Some functions, such as render(), need to be overridden in derived classes.
17 Lukas Mueller <lam87@cornell.edu>
21 This class defines the following methods:
29 package CXGN
::Cview
::ImageObject
;
44 my $self = bless $args, $class;
49 $self->set_horizontal_offset($x);
50 $self->set_vertical_offset($y);
51 $self->set_height($height);
52 $self->set_width($width);
53 $self->set_color(0,0,0);
57 =head2 accessors get_name(), set_name()
59 Synopsis: $io -> set_name("foo")
60 Property: the name of the image element
68 $self->{name
} = shift;
73 return ($self->{name
});
76 =head2 accessors get_enclosing_rect(), set_enclosing_rect()
78 Synopsis: $io->set_enclosing_rect(10, 10, 100, 100)
79 Property: a list of coords, top left x,y and bottom right x,y
85 sub set_enclosing_rect
{
87 @
{$self->{enclosing_rect
}} = @_;
90 sub get_enclosing_rect
{
92 if (!exists($self->{enclosing_rect
})) {
93 @
{$self->{enclosing_rect
}}=(0, 0, 0, 0);
95 return @
{$self->{enclosing_rect
}};
98 =head2 accessors set_color(), get_color()
100 Synopsis: $io->set_color(255,255,0)
101 Property: the color of the element
102 Side effects: the element will be rendered in this color
109 ($self->{color
}[0], $self->{color
}[1], $self->{color
}[2]) = @_;
114 return @
{$self->{color
}};
117 =head2 function render()
119 Synopsis: [abstract method]
120 Arguments: an GD::Image object
122 Side effects: this should be implemented to draw the image object
133 =head2 function get_image_map()
135 Synopsis: $io->get_mage_map()
137 Returns: a string representing the html image map for the object
139 Description: a default implementation is given that should work for most
140 objects, or it may be overridden in sub-classes.
146 my $coords = join ",", ($self -> get_enclosing_rect
());
148 if ($self->get_url()) { $string = "<area name=".$self->get_name()." shape=\"rect\" coords=\"".$coords."\" href=\"".$self->get_url()."\" alt=\"".$self->get_name()."\" />";}
153 =head2 accessors get_url(), set_url()
155 Synopsis: $io->set_url("http://sgn.cornell.edu/search/unigene.pl?unigene_id=449494")
156 Property: the link this object should go to when clicked
157 Side effects: this link will be imbeded in the html image map
169 if (!exists($self->{url
}) || !defined($self->{url
})) { $self->{url
}=""; }
173 =head2 accessors set_horizontal_offset(), get_horizontal_offset()
175 Synopsis: my $offset = $chr -> get_horizontal_offset()
176 $chr->set_horizontal_offset(57)
177 Arguments: setter: the offset in pixels [integer]
178 Returns: getter: returns the horizontal offset in pixels
179 of the image element. The
181 Description: The horizontal offset can be defined in different ways
182 depending on the image. Most often, it denotes the mid-line
183 of the object (such as a chromosome) or the left boundary.
187 sub get_horizontal_offset
{
189 if (!exists($self->{horizontal_offset
}) || ! defined($self->{horizontal_offset
})) { $self->set_horizontal_offset(0); }
190 return $self->{horizontal_offset
};
193 sub set_horizontal_offset
{
195 $self->{horizontal_offset
}=shift;
198 =head2 accessors get_X(), set_X()
200 Synopsis: same as accessors for horizontal_offset(), but shorter!
210 return $self->{horizontal_offset
};
215 $self->{horizontal_offset
}=shift;
218 =head2 accessors get_vertical_offset(), set_vertical_offset()
220 Synopsis: $chr -> get_vertical_offset()
221 Arguments: setter: the vertical offset in pixels.
222 Returns: Returns the vertical offset of the image element in pixels.
224 Description: Returns the vertical offset of the image element, which
225 defines the upper limit of the image element. Certain
226 chromosome renditions will add a round edge on the top that
227 will extend the chromomsome beyond that value.
231 sub get_vertical_offset
{
233 if (!exists($self->{vertical_offset
}) || !defined($self->{vertical_offset
})) {
234 $self->{vertical_offset
}=0;
236 return $self->{vertical_offset
};
239 sub set_vertical_offset
{
241 $self->{vertical_offset
}=shift;
244 =head2 accessors get_Y(), set_Y()
246 Synopsis: same as vertical_offset accessors
256 return $self->{vertical_offset
};
261 $self->{vertical_offset
}=shift;
266 =head2 accessors get_height(), set_height()
268 Synopsis: $io->set_height(300)
269 Property: the height of the object in pixels
270 Side effects: note that changing this property does not change
271 the enclosing rect automatically. This has to be
279 if (!exists($self->{height
})) { $self->set_height(0); }
280 return $self->{height
};
285 $self->{height
}=shift;
288 =head2 accessors get_width(), set_width()
290 Synopsis: $io->set_width(100)
291 Property: the width of this object in pixels
292 Side effects: note that changing this will not change the
293 enclosing rect - this needs to be changed
301 return $self->{width
};
307 $self->{width
}=shift;
313 =head2 accessors get_font(), set_font()
315 Synopsis: $io->set_font(GD::Font->Tiny)
316 Property: the GD font to be used when drawing this object
324 return $self->{font
};
332 =head2 function round()
334 Synopsis: my $rounded = round(4.3);
335 Arguments: a real number to be rounded
338 Description: Perl does not have a round function built in (it\'s in Math::round),
339 but we need it for rounding calculation of pixels.
340 Note: works also for negative numbers, astoninglishly
346 my $int = int($value);
347 my $rest = abs($value)-abs($int);
356 #print STDERR "Rounded $value to $int\n";