Hacking on Gnome2::Canvas



Hi,

I started hacking on implementing the Gnome2::Canvas tonight and
I made enough progress so that the following snippet of code works:

    my $canvas = Gnome2::Canvas->new();
    $canvas->set_size_request(256,256);
    $canvas->set_scroll_region(0,0,256,256);
    my $root = $canvas->root();
    print "root = $root\n";
    
    my $item = Gnome2::Canvas::Item->new($root,
                                     "GnomeCanvasEllipse",
                                     x1 => 50,
                                     y1 => 70,
                                     x2 => 200,
                                     y2 => 180,
                                     fill_color=>"red",
                                     outline_color=>"black"
                                    );
    $item->signal_connect(event=>sub {print "I got an event!\n"; });
         
(Note that I choose to use a string argument for providing the type of
the canvas item as opposed to using the Gnome2::Canvas::Ellipse->get_type() 
which in my opinion is ugglier. The cost is another string lookup
within Glib. If needed it should be pretty easy to support both syntaxes,
and perhaps then we can predeclare GNOME_CANVAS_ELLIPSE_TYPE etc const
subs for speed. (The string is the GLib registered type, btw)).

The main work was in implementing the Gnome2::Canvas::Item function
in which I did quite some copy and paste from the GObject.xs new 
function. Probably I should have just called it instead. If I could
have figure out how...

But, I eventully got stuck on type mapping for the GnomeCanvasLine.
One of its properties is "points" which take an argument of type
GnomeCanvasPoints. The latter should be mapped from a perl list,
but how do I do that? Where do I define the type conversion from
a perl ARRAY-ref to the GnomeCanvasPoint structure?

Right now if I do:

    $item = Gnome2::Canvas::Item->new($root,
                                      "GnomeCanvasLine",
                                      points => [50,50, 200,200]);

I get the very informative ;-) error message:

    internal nastiness: boxed wrapper contains NULL pointer at ./test-canvas line 37

And finally, may I please have cvs write access btw so that I can put
back my work there?

Regards,
Dov



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