1 2 /* 3 Provides the calling sequences for all the basic PetscDraw routines. 4 */ 5 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 6 7 #undef __FUNCT__ 8 #define __FUNCT__ "PetscDrawGetMouseButton" 9 /*@ 10 PetscDrawGetMouseButton - Returns location of mouse and which button was 11 pressed. Waits for button to be pressed. 12 13 Collective over PetscDraw 14 15 Input Parameter: 16 . draw - the window to be used 17 18 Output Parameters: 19 + button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT, PETSC_BUTTON_WHEEL_UP, PETSC_BUTTON_WHEEL_DOWN 20 . x_user, y_user - user coordinates of location (user may pass in NULL). 21 - x_phys, y_phys - window coordinates (user may pass in NULL). 22 23 Notes: Only processor 0 actually waits for the button to be pressed. 24 25 Level: intermediate 26 @*/ 27 PetscErrorCode PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys) 28 { 29 PetscReal bcast[4] = {0,0,0,0}; 30 PetscBool isnull; 31 PetscMPIInt rank; 32 PetscErrorCode ierr; 33 34 PetscFunctionBegin; 35 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 36 PetscValidPointer(button,2); 37 *button = PETSC_BUTTON_NONE; 38 ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); 39 if (isnull) PetscFunctionReturn(0); 40 if (!draw->ops->getmousebutton) PetscFunctionReturn(0); 41 42 ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr); 43 ierr = (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr); 44 ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); 45 46 ierr = MPI_Bcast((PetscEnum*)button,1,MPIU_ENUM,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr); 47 if (x_user) bcast[0] = *x_user; 48 if (y_user) bcast[1] = *y_user; 49 if (x_phys) bcast[2] = *x_phys; 50 if (y_phys) bcast[3] = *y_phys; 51 ierr = MPI_Bcast(bcast,4,MPIU_REAL,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr); 52 if (x_user) *x_user = bcast[0]; 53 if (y_user) *y_user = bcast[1]; 54 if (x_phys) *x_phys = bcast[2]; 55 if (y_phys) *y_phys = bcast[3]; 56 PetscFunctionReturn(0); 57 } 58 59 60 61 62 63 64