Search code examples
gtkwidgetvala

Moving controls with the mouse with Gtk


I'm having trouble with moving controls on a Gtk Fixed item, with the code jittering movement and it just being generally slow. I've tried finding proper ways to do this, however all have revealed the same result.

The code I think is relevant is:

        view.button_press_event.connect( (bp) => {
            view.set_data("in_motion", true);

            int pointX = 0; int pointY = 0;
            fixed.get_pointer(out pointX, out pointY);
            int origX = 0; int origY = 0;
            view.translate_coordinates(fixed, 0,0, out origX, out origY);

            view.set_data("startx", origX + origX);
            view.set_data("starty", origY + origY);
            view.set_data("startsx", pointX);
            view.set_data("startsy", pointY);
            view.is_focus = true;
            view.has_focus = true;
            return false;
        });
        view.button_release_event.connect( (bp) => {
            view.set_data("in_motion", false);
            return false;
        });
        view.motion_notify_event.connect( (me) => {
            // TODO: Make this less glitchy somehow
            if(view.get_data<bool>("in_motion") == true){
                int x = view.get_data<int>("startx") + (int)me.x - view.get_data<int>("startsx");
                int y = view.get_data<int>("starty") + (int)me.y - view.get_data<int>("startsy");
                ((Fixed)view.parent).move(view, x,y );
            }
            return false;
        });

(The rest is on https://github.com/kennydude/diagramatic/blob/master/diagram.vala )


Solution

  • Okay, so I managed to do it, however the code base moved to python (Vala was too difficult).

    https://github.com/kennydude/diagramatic/blob/master/diagram.py