Actual source code: dmouse.c

petsc-3.6.1 2015-08-06
Report Typos and Errors
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc/private/drawimpl.h>  /*I "petscdraw.h" I*/

  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 PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_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: PetscErrorCode  PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
 31: {
 33:   PetscBool      isnull;

 37:   *button = PETSC_BUTTON_NONE;
 38:   PetscObjectTypeCompare((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: }

 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 PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_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: PetscErrorCode  PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
 66: {
 67:   PetscReal      bcast[4];
 69:   PetscMPIInt    rank;

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