Re: Dragging a window



 Hi,
Take a look at that code

// http://paste.org/42104
// GTKmm 2.4

#include <gtkmm.h>

using namespace Gtk;

class window : public Window
{
public:

    window()
    {
        set_title("Example");
        show_all_children();

        add_events(Gdk::BUTTON_PRESS_MASK);
        add_events(Gdk::POINTER_MOTION_MASK);
    }

private:
    int mouse_beg_x, mouse_beg_y;
    int win_pos_beg_x, win_pos_beg_y;

    bool on_button_press_event(GdkEventButton* event)
    {
        mouse_beg_x = event->x_root;
        mouse_beg_y = event->y_root;

        get_position(win_pos_beg_x, win_pos_beg_y);

        return true;
    }

    bool on_motion_notify_event(GdkEventMotion* event)
    {
        if (event->state & GDK_BUTTON1_MASK)
        {
            int x = win_pos_beg_x + (event->x_root - mouse_beg_x);
            int y = win_pos_beg_y + (event->y_root - mouse_beg_y);

            move(x, y);
        }
        return true;
    }
};

int main(int argc, char **argv)
{
    Gtk::Main kit(argc, argv);

    window win;
    Gtk::Main::run(win);

    return 0;
}


Good luck
Adam


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