xref: /petsc/src/sys/classes/draw/interface/dmouse.c (revision 811af0c4b09a35de4306c442f88bd09fdc09897d)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith /*
35c6c1daeSBarry Smith        Provides the calling sequences for all the basic PetscDraw routines.
45c6c1daeSBarry Smith */
5af0996ceSBarry Smith #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/
65c6c1daeSBarry Smith 
75c6c1daeSBarry Smith /*@
85c6c1daeSBarry Smith     PetscDrawGetMouseButton - Returns location of mouse and which button was
95c6c1daeSBarry Smith     pressed. Waits for button to be pressed.
105c6c1daeSBarry Smith 
11*811af0c4SBarry Smith     Collective on draw
125c6c1daeSBarry Smith 
135c6c1daeSBarry Smith     Input Parameter:
145c6c1daeSBarry Smith .   draw - the window to be used
155c6c1daeSBarry Smith 
165c6c1daeSBarry Smith     Output Parameters:
17*811af0c4SBarry Smith +   button - one of `PETSC_BUTTON_LEFT`, `PETSC_BUTTON_CENTER`, `PETSC_BUTTON_RIGHT`, `PETSC_BUTTON_WHEEL_UP`, `PETSC_BUTTON_WHEEL_DOWN`
186b867d5aSJose E. Roman .   x_user - horizontal user coordinate of location (user may pass in NULL).
196b867d5aSJose E. Roman .   y_user - vertical user coordinate of location (user may pass in NULL).
206b867d5aSJose E. Roman .   x_phys - horizontal window coordinate (user may pass in NULL).
216b867d5aSJose E. Roman -   y_phys - vertical window coordinate (user may pass in NULL).
225c6c1daeSBarry Smith 
23*811af0c4SBarry Smith     Note:
2495452b02SPatrick Sanan     Only processor 0 actually waits for the button to be pressed.
255c6c1daeSBarry Smith 
2664f23424SLisandro Dalcin     Level: intermediate
27*811af0c4SBarry Smith 
28*811af0c4SBarry Smith .seealso: `PetscDraw`, `PetscDrawButton`
295c6c1daeSBarry Smith @*/
309371c9d4SSatish Balay PetscErrorCode PetscDrawGetMouseButton(PetscDraw draw, PetscDrawButton *button, PetscReal *x_user, PetscReal *y_user, PetscReal *x_phys, PetscReal *y_phys) {
3109440f25SLisandro Dalcin   PetscReal bcast[4] = {0, 0, 0, 0};
325c6c1daeSBarry Smith 
335c6c1daeSBarry Smith   PetscFunctionBegin;
345c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
35e118a51fSLisandro Dalcin   PetscValidPointer(button, 2);
36e118a51fSLisandro Dalcin   *button = PETSC_BUTTON_NONE;
3764f23424SLisandro Dalcin   if (!draw->ops->getmousebutton) PetscFunctionReturn(0);
38e118a51fSLisandro Dalcin 
39dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, getmousebutton, button, x_user, y_user, x_phys, y_phys);
40e118a51fSLisandro Dalcin 
419566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast((PetscEnum *)button, 1, MPIU_ENUM, 0, PetscObjectComm((PetscObject)draw)));
425c6c1daeSBarry Smith   if (x_user) bcast[0] = *x_user;
435c6c1daeSBarry Smith   if (y_user) bcast[1] = *y_user;
445c6c1daeSBarry Smith   if (x_phys) bcast[2] = *x_phys;
455c6c1daeSBarry Smith   if (y_phys) bcast[3] = *y_phys;
469566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast(bcast, 4, MPIU_REAL, 0, PetscObjectComm((PetscObject)draw)));
475c6c1daeSBarry Smith   if (x_user) *x_user = bcast[0];
485c6c1daeSBarry Smith   if (y_user) *y_user = bcast[1];
495c6c1daeSBarry Smith   if (x_phys) *x_phys = bcast[2];
505c6c1daeSBarry Smith   if (y_phys) *y_phys = bcast[3];
515c6c1daeSBarry Smith   PetscFunctionReturn(0);
525c6c1daeSBarry Smith }
53