mouse motion redraws



Hi,
I'm currently writing an app in which pixmaps (Gdk, not Gtk)in a
GtkDrawingArea can be dragged by using the mouse.To achieve this, I
connect to the usual mouse signals.

My problem is that the motion of the pixmaps is sluggish. The weird
thing is, if I run the program at the same time I run "Dia" (gtk drawing
program), the motion of my program all of a sudden becomes acceptable.
I've looked through "Dia'"s source, but cannot find what it's doing.
Cheers,
Alex Mathy

here's the code:

  gtk_signal_connect (GTK_OBJECT (canvas), "motion_notify_event",
      GTK_SIGNAL_FUNC (canvas_motion_notify_event), NULL);
  gtk_signal_connect (GTK_OBJECT (canvas), "button_press_event",
      GTK_SIGNAL_FUNC (canvas_button_press_event), NULL); 
   gtk_signal_connect (GTK_OBJECT (canvas), "button_release_event",
      GTK_SIGNAL_FUNC (canvas_button_release_event), NULL);   
   gtk_widget_set_events (GTK_WIDGET (canvas), GDK_EXPOSURE_MASK
 
 									| GDK_BUTTON_PRESS_MASK
 									| GDK_BUTTON_RELEASE_MASK
 									| GDK_POINTER_MOTION_MASK
 									| GDK_POINTER_MOTION_HINT_MASK
 									| GDK_ENTER_NOTIFY_MASK 
 									| GDK_LEAVE_NOTIFY_MASK 
 								    | GDK_BUTTON_RELEASE_MASK
 									);     
.
.
.
gint
canvas_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
  if (event->button == 1){
  	
  	int i;
  	
  	for (i=0;i<*(compCount);i++){
  		circObj* component;
  		component=getComponent(components,i);  		 	
  		 if (isInComponent(component,event->x,event->y)==TRUE){
  		 	//start dragging!
  		 	   selectedObj=component;
  				dragging=TRUE;
  				xInObj=event->x-component->x;
  				yInObj=event->y-component->y;    
  				selectedType=SELECTED_COMPONENT;
  				gtk_timeout_remove(threadid);  
  		 	   return TRUE;
  		 	
  		 }	
  		 else {
  		 	
  		 }		 
  	}	
  
  } 
      return TRUE;
}

gint
canvas_button_release_event (GtkWidget *widget, GdkEventButton *event)
{
	if (event->button == 1){
		if (dragging==TRUE){
			dragging=FALSE;
			threadid=gtk_timeout_add(DELAY,circuitLoop,canvas);
			//snap to grid:
			
		
		}	
	}
	return TRUE;	
}	

gint
canvas_motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
{
  int x, y;
  GdkModifierType state;   
  if (event->is_hint) {
    gdk_window_get_pointer (event->window, &x, &y, &state);
  }
  else
    {
      x = event->x;
      y = event->y;
      state = event->state;
    }
    
   
  if (state & GDK_BUTTON1_MASK){
 	if (dragging==TRUE){
 		if (selectedType=SELECTED_COMPONENT){
 			circObj* component=(circObj*)selectedObj;
 			component->x=event->x - xInObj;
 			component->y=event->y - yInObj;
 			redrawCanvas(canvas);
 		}	
 	}	
  }	

 
  return TRUE;
}
 





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