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);
54 $self->set_fill_color(255, 255, 255);
58 =head2 accessors get_name(), set_name()
60 Synopsis: $io -> set_name("foo")
61 Property: the name of the image element
69 $self->{name
} = shift;
74 return ($self->{name
});
77 =head2 accessors get_enclosing_rect(), set_enclosing_rect()
79 Synopsis: $io->set_enclosing_rect(10, 10, 100, 100)
80 Property: a list of coords, top left x,y and bottom right x,y
86 sub set_enclosing_rect
{
88 @
{$self->{enclosing_rect
}} = @_;
91 sub get_enclosing_rect
{
93 if (!exists($self->{enclosing_rect
})) {
94 @
{$self->{enclosing_rect
}}=(0, 0, 0, 0);
96 return @
{$self->{enclosing_rect
}};
99 =head2 accessors set_color(), get_color()
101 Synopsis: $io->set_color(255,255,0)
102 Property: the color of the element
103 Side effects: the element will be rendered in this color
110 ($self->{color
}[0], $self->{color
}[1], $self->{color
}[2]) = @_;
115 return @
{$self->{color
}};
119 =head2 accessors set_fill_color(), get_fill_color()
121 Synopsis: $io->set_color(255,255,0)
122 Property: the fill color of the element
123 Side effects: the element will be rendered filled in this color
130 ($self->{fill_color
}[0], $self->{fill_color
}[1], $self->{fill_color
}[2]) = @_;
135 return @
{$self->{fill_color
}};
138 =head2 function render()
140 Synopsis: [abstract method]
141 Arguments: an GD::Image object
143 Side effects: this should be implemented to draw the image object
154 =head2 function get_image_map()
156 Synopsis: $io->get_mage_map()
158 Returns: a string representing the html image map for the object
160 Description: a default implementation is given that should work for most
161 objects, or it may be overridden in sub-classes.
167 my $coords = join ",", ($self -> get_enclosing_rect
());
169 if ($self->get_url()) { $string = "<area name=".$self->get_name()." shape=\"rect\" coords=\"".$coords."\" href=\"".$self->get_url()."\" alt=\"".$self->get_name()."\" />";}
174 =head2 accessors get_url(), set_url()
176 Synopsis: $io->set_url("http://sgn.cornell.edu/search/unigene.pl?unigene_id=449494")
177 Property: the link this object should go to when clicked
178 Side effects: this link will be imbeded in the html image map
190 if (!exists($self->{url
}) || !defined($self->{url
})) { $self->{url
}=""; }
194 =head2 accessors set_horizontal_offset(), get_horizontal_offset()
196 Synopsis: my $offset = $chr -> get_horizontal_offset()
197 $chr->set_horizontal_offset(57)
198 Arguments: setter: the offset in pixels [integer]
199 Returns: getter: returns the horizontal offset in pixels
200 of the image element. The
202 Description: The horizontal offset can be defined in different ways
203 depending on the image. Most often, it denotes the mid-line
204 of the object (such as a chromosome) or the left boundary.
208 sub get_horizontal_offset
{
210 if (!exists($self->{horizontal_offset
}) || ! defined($self->{horizontal_offset
})) { $self->set_horizontal_offset(0); }
211 return $self->{horizontal_offset
};
214 sub set_horizontal_offset
{
216 $self->{horizontal_offset
}=shift;
219 =head2 accessors get_X(), set_X()
221 Synopsis: same as accessors for horizontal_offset(), but shorter!
231 return $self->{horizontal_offset
};
236 $self->{horizontal_offset
}=shift;
239 =head2 accessors get_vertical_offset(), set_vertical_offset()
241 Synopsis: $chr -> get_vertical_offset()
242 Arguments: setter: the vertical offset in pixels.
243 Returns: Returns the vertical offset of the image element in pixels.
245 Description: Returns the vertical offset of the image element, which
246 defines the upper limit of the image element. Certain
247 chromosome renditions will add a round edge on the top that
248 will extend the chromomsome beyond that value.
252 sub get_vertical_offset
{
254 if (!exists($self->{vertical_offset
}) || !defined($self->{vertical_offset
})) {
255 $self->{vertical_offset
}=0;
257 return $self->{vertical_offset
};
260 sub set_vertical_offset
{
262 $self->{vertical_offset
}=shift;
265 =head2 accessors get_Y(), set_Y()
267 Synopsis: same as vertical_offset accessors
277 return $self->{vertical_offset
};
282 $self->{vertical_offset
}=shift;
287 =head2 accessors get_height(), set_height()
289 Synopsis: $io->set_height(300)
290 Property: the height of the object in pixels
291 Side effects: note that changing this property does not change
292 the enclosing rect automatically. This has to be
300 if (!exists($self->{height
})) { $self->set_height(0); }
301 return $self->{height
};
306 $self->{height
}=shift;
309 =head2 accessors get_width(), set_width()
311 Synopsis: $io->set_width(100)
312 Property: the width of this object in pixels
313 Side effects: note that changing this will not change the
314 enclosing rect - this needs to be changed
322 return $self->{width
};
328 $self->{width
}=shift;
334 =head2 accessors get_font(), set_font()
336 Synopsis: $io->set_font(GD::Font->Tiny)
337 Property: the GD font to be used when drawing this object
345 return $self->{font
};
353 =head2 function round()
355 Synopsis: my $rounded = round(4.3);
356 Arguments: a real number to be rounded
359 Description: Perl does not have a round function built in (it\'s in Math::round),
360 but we need it for rounding calculation of pixels.
361 Note: works also for negative numbers, astoninglishly
367 my $int = int($value);
368 my $rest = abs($value)-abs($int);
377 #print STDERR "Rounded $value to $int\n";