Actual source code: dmouse.c

  1: /*
  2:        Provides the calling sequences for all the basic PetscDraw routines.
  3: */
 4:  #include src/sys/src/draw/drawimpl.h

  8: /*@
  9:     PetscDrawGetMouseButton - Returns location of mouse and which button was
 10:     pressed. Waits for button to be pressed.

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

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

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

 22:     Level: intermediate

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

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

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

 46: /*@
 47:     PetscDrawSynchronizedGetMouseButton - Returns location of mouse and which button was
 48:     pressed. Waits for button to be pressed.

 50:     Collective over PetscDraw

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

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

 60:     Level: intermediate

 62: .seealso: PetscDrawGetMouseButton()
 63: @*/
 64: PetscErrorCode PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
 65: {
 66:   PetscReal      bcast[4];
 68:   PetscMPIInt    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: }