Re: moving a widget on a canvas



On Sun, 28 May 2000, Thomas Morris wrote:

> Hi,
> I've been experimenting with the Gnome Canvas a bit creating canvas
> items from widgets and haven't had any
> problems except when I try to drag a widget from one location on the
> canvas to another.  When I click on the widget
> and begin to drag him he starts jittering up and down and sideways as if
> he is fighting back. Its a cool effect but its not
> exactly what I want to use for a finished app. The code I used to
> implement the movement is basically what I found in
> Havoc's book and a few other emails in the archives.  Here is the
> movement code that I use.  I really appreciate any help
> or clues as to where my problem lies.
> 
> gnome_canvas_w2c_d (GNOME_CANVAS (dwidget->home_canvas),
>        event->button.x, event->button.y, &cx, &cy);
> 
>  switch (event->type)
>  {
>  case GDK_BUTTON_PRESS:
>   switch (event->button.button)
>   {
>   case 1:
>    /* grab the widget */
>    x = event->button.x;
>    y = event->button.y;
>    cursor = gdk_cursor_new (GDK_FLEUR);
>    retval = gdk_pointer_grab (GTK_WIDGET (dwidget)->window,
>          FALSE,
>          GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
>          NULL,
>          cursor,
>          event->button.time);

Hmmm... aren't you here grabbing widget instead of corresponding canvas
item?

>    if (!retval)
>     dragging = TRUE;
>    gdk_cursor_destroy (cursor);
>    break;
>   case 2:
>    break;
>   default:
>    break;
>   }
>   break;
>  case GDK_MOTION_NOTIFY:
>   if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
>    gnome_canvas_item_move (dwidget->this_item,
>       event->button.x - x,
>       event->button.y - y);
>    x = event->button.x;
>    y = event->button.y;
>   }
>   break;
>  case GDK_BUTTON_RELEASE:
>   if (gdk_pointer_is_grabbed ()) {
>    gdk_pointer_ungrab (event->button.time);
>    dwidget->xpos = event->button.x;
>    dwidget->ypos = event->button.y;
>    dbs_widget_save (dwidget);
>   }
>   dragging = FALSE;
>   break;
>  default:
>   break;
>  }
> 
> best regards,
> Thomas Morris.
> 





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