Sure, just notice the variable "testje". In method on_mouse_movement,
the variable is NOT 12:

using Gtk;
using Goo;
using Gdk;

public class ScrapItem {

    public static bool ItemDrag = false;
    public double testje = 12;

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


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

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

                root = canvas.get_root_item();

        this.testje = 12;
        stdout.printf("%f\n", this.testje);

                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.button_press_event.connect(on_button_pressed);
                scrap_item.button_release_event.connect(on_button_released);
                scrap_item.motion_notify_event.connect(on_mouse_movement);

                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(Goo.CanvasItem Item,
Gdk.EventButton EventButton) {
        if (EventButton.button == 1)
            this.ItemDrag = true;
        return true;
    }

    private bool on_button_released(Goo.CanvasItem Item,
Gdk.EventButton EventButton) {
        this.ItemDrag = false;
        return true;
    }

    private bool on_mouse_movement(Goo.CanvasItem Item,
Gdk.EventMotion EventMotion) {

        CanvasItem Group;
        double x = 0, y = 0;

        Group = Item.get_parent();

        if (this.ItemDrag == true) {

//           this.testje is empty !?!
             stdout.printf("%f %f %f - %f %f\n", this.testje, x, y,
EventMotion.x, EventMotion.y);
             Group.translate(EventMotion.x, EventMotion.y);
        }

        x = EventMotion.x;
        y = EventMotion.y;

        return false;
    }

}


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;
    }
}


Greetz,
Fred



2011/7/25 Luca Bruno <[email protected]>:
> On Mon, Jul 25, 2011 at 01:55:41PM +0200, Fred van Zwieten wrote:
>> Hi all,
>>
>> Warning: vala noob.
>>
>> I have a instance variable and gave it a value in the class constructor.
>>
>> The variable is accessible in other methods in the same class (i.e.
>> this.foo) but it doesn't have the value set in the constructor. Why
>> not? This is also true for initial value assignment (public int foo =
>> 12)
>>
>> When I set it in another method (not the constructor) all is well.
>
> Hi, can you show a test case please?
>
> --
> http://www.debian.org - The Universal Operating System
>
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to