[Vala] Problems with connectors



Hi all,
I am a complete noob on vala and I have trouble using signals and
accesing the event data. Here is the code:

using Gtk;
using Goo;
using Gdk;

public class ScrapItem {

        public ScrapItem (Canvas canvas, string GraphItem, int x, int y, int
height, int width) {

                Gdk.Pixbuf pixbuf;
                CanvasItem root;
                CanvasImage scrap_item, bg;
                CanvasRect scrap_item_border;
                CanvasGroup scrap_item_group;

                pixbuf = new Gdk.Pixbuf.from_file(GraphItem);           

                root = canvas.get_root_item();

                scrap_item_group = CanvasGroup.create(root);
                scrap_item = CanvasImage.create(scrap_item_group,pixbuf,x,y);
                
                scrap_item.scale_to_fit = true;
                scrap_item.height = height;
                scrap_item.width = width;
                
                scrap_item_border =
CanvasRect.create(scrap_item_group,scrap_item.x,scrap_item.y,scrap_item.width,scrap_item.height);
                scrap_item_border.stroke_color = "black";

                scrap_item_group.button_press_event.connect(on_button_pressed);

                scrap_item.enter_notify_event.connect(()
                =>      {
                                scrap_item_border.stroke_color = "grey";
                                return true;                                    
                        });
                scrap_item.leave_notify_event.connect(()
                =>      {
                                scrap_item_border.stroke_color = "black";
                                return true;                                    
                        });
        }

    private bool on_button_pressed(Gtk.Widget Widget, Gdk.Event event) {
//        ...
        return true;
    }

}


public class CanvasSample : Gtk.Window
{
    private const int SIZE = 30;

    public CanvasSample ()
    {
        this.title = "Canvas Vala Demo";
        this.destroy.connect (Gtk.main_quit);
        set_default_size (600, 600);
                                
                var canvas = new Canvas();
                var bg = new ScrapItem(canvas,"/home/fred/dev/vala/training/test3/paper.jpg",0,0,600,600);
                var ScrapItem1 = new
ScrapItem(canvas,"/home/fred/dev/vala/training/test3/photo1.jpg",30,30,300,300);
                var ScrapItem2 = new
ScrapItem(canvas,"/home/fred/dev/vala/training/test3/photo2.jpg",60,60,300,300);

                add (canvas);
    }

    static int main (string[] args)
    {
        Gtk.init (ref args);

        var canvas_sample = new CanvasSample ();
        canvas_sample.show_all();

        Gtk.main ();

        return 0;
    }
}


When I try to compile this I get this error:

scrapbook2.vala:29.47-29.63: error: Argument 1: Cannot convert from
`ScrapItem.on_button_pressed' to `Goo.CanvasItem.button_press_event'
                scrap_item_group.button_press_event.connect(on_button_pressed);
                                                            ^^^^^^^^^^^^^^^^^

Greetz,
Fred



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