Re: GdkRectangle, again

Guillaume Cottenceau said:
"muppet" <scott asofyet org> writes:

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.

I personally favored the orthogonality of methods in gtk2-perl,
and that's why we are (were?) using GdkRectangle like all other
Boxed types, with methods to access members. E.g.:

  $pixmap->draw_rectangle ($gc, TRUE,

E.g. even more readable than hash ref thing. There's also
->values so that you can do things like:

my (undef, undef, $w, $h) = $update_rect->values;

i appreciate this.  and using the rectangle as a boxed type makes the bindings
easier to create.

however, in trying to create a perlish mapping, i see the opaque boxed
references as somewhat alien.  thus, i want to use something that's as natural
to modify as it is to access.  the orthoganal methods are great for accessing,
but not for mutating.

in C, the rectangle is not an opaque pointer, it is a structure whose members
you are meant to use.  in perl, a structure whose members you access directly
is a hash.  that's the key of my reasoning in wanting to use a hash.

the key reason for wanting to use a list is that there's lots of existing
gtk-perl code that already does it.  however, after implementing it and
starting to write code with it i quickly remembered that i despised using 0,
1, 2, and 3 where 'x', 'y', 'width', and 'height' were more appropriate.

it would be just as easy to treat the rectangle as a hash and have helper
functions, but if we've gone to that much trouble we might as well go back to
the opaque objects and just say "if you want to change something about it,
create another rectangle with the members you want" and be done with it, e.g.,

  my ($x, $y, $width, $height) = $event->area->values;
  my $newrect = Gtk2::Gdk::Rectangle->new ($x-$pad, $y-$pad,
                                           $width+2*$pad, $height+2*$pad);
  $widget->window->invalidate_rect ($newrect, FALSE);

if that's what everybody wants (i've seen a few "i concur"s so far), i'll do

note that there will not be a distinct perl wrapper for the point and segment
objects --- there are no GDK_TYPE_* macros for them, and they are only two
values each, so they will just be pulled on and off the stack in pairs, as in
gtk-perl.  (similiarity with this was another reason for using a native perl
structure for the rectangle, but the rectangle has more and different uses
than these two...)

muppet <scott at asofyet dot org>

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