[Vala] DrawingArea and Vala



I am attempting a simple program for GTK+ using vala. It uses a
ScrolledWindow with a DrawingArea inside.

I am following a GTK+ example, and attempting to convert it over to vala.

It crashes right in the header to the canvas_configure method.

The gdb output and program follow. The test program is compiled with this line:
valac -g --pkg gtk+-2.0 --pkg libglade-2.0 test5.vala -o test5 -X
"-Wl,--export-dynamic" -X -rdynamic

I am trying to make use of the tutorial,
http://www.gtk.org/tutorial/x2472.html and the only thing I couldn't
figure out an analogue for  GTK_WIDGET_STATE in
widget->style->fg_gc[GTK_WIDGET_STATE (widget)]

Thank you for any help that can be provided.

The gdb output:
Starting program: /home/jdrake/Documents/Code/urbastro/test5/test5
[Thread debugging using libthread_db enabled]
[New Thread -1220498896 (LWP 29068)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1220498896 (LWP 29068)]
0x08049380 in main_window_canvas_configure (e=0x806a8d8, self=0x806a5a8)
    at /home/jdrake/Documents/Code/urbastro/test5/home/jdrake/Documents/Code/urbastro/test5/test5.vala:44
44              private bool canvas_configure(Gdk.EventConfigure e)
(gdb) bt
#0  0x08049380 in main_window_canvas_configure (e=0x806a8d8, self=0x806a5a8)
    at /home/jdrake/Documents/Code/urbastro/test5/home/jdrake/Documents/Code/urbastro/test5/test5.vala:44
#1  0xb7cdd1de in _gtk_marshal_BOOLEAN__BOXED ()
   from /usr/lib/libgtk-x11-2.0.so.0
#2  0xb773d772 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#3  0xb774e323 in ?? () from /usr/lib/libgobject-2.0.so.0
#4  0x08073b88 in ?? ()
#5  0xbfed0800 in ?? ()
#6  0x00000002 in ?? ()
#7  0xbfed08dc in ?? ()
#8  0xbfed07ec in ?? ()
#9  0x00000000 in ?? ()


The program:

using GLib;
using Gtk;
using Glade;
using Gdk;

public class MainWindow : Gtk.Window {
        Gtk.DrawingArea canvas;
        Gtk.ScrolledWindow canvas_scroll;
        Gdk.Pixmap pixmap;
        
        construct {
                title = "Urbastro";
                create_widgets();
        }

        public void create_widgets()
        {
                destroy += Gtk.main_quit;

                canvas_scroll = new Gtk.ScrolledWindow(null, null);
                                
                var canvas = new Gtk.DrawingArea();
                canvas_scroll.add_with_viewport(canvas);
                
                canvas.set_size_request(1024, 1024);
                
                canvas.configure_event += canvas_configure;
                canvas.expose_event += canvas_expose;
                
                add(canvas_scroll);             

        }
        
        //[InstanceLast]
        private bool canvas_configure(Gdk.EventConfigure e)
        {
        //      if (pixmap)
        //              pixmap.unref();
                        
                pixmap = new Gdk.Pixmap(e.window, e.width, e.height, -1);
                
                pixmap.draw_rectangle(this.style.white_gc, true, 0, 0, e.width, e.height);
                stdout.printf(" configure\n");
                return true;
        }
        
        private bool canvas_expose(Gdk.EventExpose e)
        {
                canvas.window.draw_drawable(this.style.fg_gc[0], pixmap,
                        e.area.x, e.area.y,
                        e.area.x, e.area.y,
                        e.area.width, e.area.height);
                
                return false;
                        
        
        }
        
        static int main (string[] args) {
                Gtk.init (out args);

                var window = new MainWindow ();
                window.resize(640, 480);
                window.show_all ();

                Gtk.main ();
                return 0;
        }
}



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