Actual source code: dmouse.c

  1: /*$Id: dmouse.c,v 1.36 2001/08/10 03:28:19 bsmith Exp $*/
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
 5:  #include src/sys/src/draw/drawimpl.h

  7: #undef __FUNCT__  
  9: /*@
 10:     PetscDrawGetMouseButton - Returns location of mouse and which button was
 11:     pressed. Waits for button to be pressed.

 13:     Not collective (Use PetscDrawSynchronizedGetMouseButton() for collective)

 15:     Input Parameter:
 16: .   draw - the window to be used

 18:     Output Parameters:
 19: +   button - one of BUTTON_LEFT, BUTTON_CENTER, BUTTON_RIGHT
 20: .   x_user, y_user - user coordinates of location (user may pass in 0).
 21: -   x_phys, y_phys - window coordinates (user may pass in 0).

 23:     Level: intermediate

 25:     Notes:
 26:     Only processor 0 of the communicator used to create the PetscDraw may call this routine.

 28: .seealso: PetscDrawSynchronizedGetMouseButton()
 29: @*/
 30: int PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
 31: {
 32:   int        ierr;
 33:   PetscTruth isnull;

 37:   *button = BUTTON_NONE;
 38:   PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
 39:   if (isnull) return(0);
 40:   if (!draw->ops->getmousebutton) return(0);
 41:   (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);
 42:   return(0);
 43: }

 45: #undef __FUNCT__  
 47: /*@
 48:     PetscDrawSynchronizedGetMouseButton - Returns location of mouse and which button was
 49:     pressed. Waits for button to be pressed.

 51:     Collective over PetscDraw

 53:     Input Parameter:
 54: .   draw - the window to be used

 56:     Output Parameters:
 57: +   button - one of BUTTON_LEFT, BUTTON_CENTER, BUTTON_RIGHT
 58: .   x_user, y_user - user coordinates of location (user may pass in 0).
 59: -   x_phys, y_phys - window coordinates (user may pass in 0).

 61:     Level: intermediate

 63: .seealso: PetscDrawGetMouseButton()
 64: @*/
 65: int PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
 66: {
 67:   PetscReal bcast[4];
 68:   int       ierr,rank;

 72:   MPI_Comm_rank(draw->comm,&rank);
 73:   if (!rank) {
 74:     PetscDrawGetMouseButton(draw,button,x_user,y_user,x_phys,y_phys);
 75:   }
 76:   if (button) {
 77:      MPI_Bcast(button,1,MPI_INT,0,draw->comm);
 78:   }
 79:   if (x_user) bcast[0] = *x_user;
 80:   if (y_user) bcast[1] = *y_user;
 81:   if (x_phys) bcast[2] = *x_phys;
 82:   if (y_phys) bcast[3] = *y_phys;
 83:   MPI_Bcast(bcast,4,MPIU_REAL,0,draw->comm);
 84:   if (x_user) *x_user = bcast[0];
 85:   if (y_user) *y_user = bcast[1];
 86:   if (x_phys) *x_phys = bcast[2];
 87:   if (y_phys) *y_phys = bcast[3];
 88:   return(0);
 89: }