moving a widget on a canvas



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);
   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.

begin:vcard 
n:Morris;Thomas
tel;cell:+49 177 2857370
tel;fax:+49 631 3504738
tel;home:+49 631 3504736
tel;work:+49 631 3504736
x-mozilla-html:FALSE
url:www.linuxpro.org/thomas
adr:;;;;;;
version:2.1
email;internet:Thomas@linuxpro.org
x-mozilla-cpt:;24960
fn:Thomas Morris
end:vcard


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