Re: Dragging a window



Found another way to do this (for dragging the window).

On the button event function:

    // left click -> start the drag of the window
if (event->button == 1)
    {
    Glib::RefPtr<Gdk::Window> window = get_window();

    if (window)
        {
        window->begin_move_drag( 1, event->x_root, event->y_root, event->time );
        }
    }



2011/12/11 lecas malecas <darkiiiiii gmail com>:
> when would get_window() fail?
>
> I'm calling it in on_motion_notify_event(), so there's always a
> window, otherwise the event wouldn't trigger... at least that's what I
> think.
>
> 2011/12/11 Adam Chyła <adam chyla tk>:
>> Don't do that:
>>
>>> >
>>> > get_window()->set_cursor(cursor);
>>> >
>>
>> What about error checking?
>>
>> Glib::RefPtr<Gdk::Window> window = get_window();
>>  if (window)
>>    window->set_cursor(...);
>>
>>
>> Dnia 2011-12-11, o godz. 04:50:25
>> lecas malecas <darkiiiiii gmail com> napisał(a):
>>
>>> It does work... was running the code in the wrong place, sorry :)
>>>
>>>
>>> On Sun, Dec 11, 2011 at 4:31 AM, lecas malecas <darkiiiiii gmail com>
>>> wrote:
>>> > Yep, that works. thanks!
>>> >
>>> > Just another doubt, to change the cursor of the mouse (the image).
>>> >
>>> >
>>> > I think its something like this:
>>> >
>>> > const Glib::RefPtr< Gdk::Cursor > cursor =
>>> > Gdk::Cursor::create(Gdk::HAND1);
>>> >
>>> > get_window()->set_cursor(cursor);
>>> >
>>> > but I'm getting a seg. fault in the last line :(
>>> >
>>> >
>>> > On Sun, Dec 11, 2011 at 3:30 AM, Adam Chyła <adam chyla tk> wrote:
>>> >>  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]