GdkRectangle, again



hot on the heels of the change i made last week, i have another proposed
change to the same thing now that i've gotten to more code using it.

i'm considering using a blessed hash instead of a list for GdkRectangle.  i
need your opinions, please!




old gtk-perl treated GdkRectangle as a 4-element list in perl.  this made it
very easy to manipulate the contents of the rectangle in perl, and i switched
to this because dealing with a boxed type from perl via member accessor
functions is clumsy.

however, the code is not very readable... you wind up with this:

  $pixmap->draw_rectangle ($gc, TRUE,
                           $event->area->[0], # x,
                           $event->area->[1], # y,
                           $event->area->[2], # width,
                           $event->area->[3]); # height

as opposed to

  $pixmap->draw_rectangle ($gc, TRUE,
                           $update_rect->{x},
                           $update_rect->{y},
                           $update_rect->{width},
                           $update_rect->{height});

if the rectangle is treated as a hash.

granted, the first one could be abbreviated as

   $pixmap->draw_rectangle ($gc, TRUE, @{$event->area});

which is nice, but you can't always do that, and getting to the members via
indices is a little creepy.


in either case it would also be advantageous to bless the GdkRectangle, so you
can use methods like

    $isec = $rect->intersect ($otherrect);

instead of class static functions like

    $isec = Gtk2::Gdk::Rectangle->intersect ($r1, $r2);



-- 
muppet <scott at asofyet dot org>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]