| Next | February 2001 | Slide #44 |
package Widget;
sub expose {
my ($self) = @_;
$self->redraw;
my @subwidgets = @{$self->subwidgets};
for my $sw (@subwidgets) {
$sw->expose;
}
}
When a window is exposed, it first redraws itself
Then it finds out what its subwidgets are
It notifies its subwidgets that they have also been exposed
The subwidgets then do whatever is appropriate
Now each Widget object only needs to know how to draw itself
For example:
package Button;
sub redraw {
my $self = shift;
draw_rounded_box($self->size, $self->position, 0.03);
}
# Drawing the button's label is taken care of by Widget::expose
The Canvas object delegates the drawing to its subobjects
| Next | ![]() |
Copyright © 2001 M-J. Dominus |