xref: /petsc/src/sys/classes/draw/interface/dmouse.c (revision 66c9fbdd036b1e887ebf0d2bef6dbdcafd086d45)
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 /*@
8     PetscDrawGetMouseButton - Returns location of mouse and which button was
9     pressed. Waits for button to be pressed.
10 
11     Collective
12 
13     Input Parameter:
14 .   draw - the window to be used
15 
16     Output Parameters:
17 +   button - one of `PETSC_BUTTON_LEFT`, `PETSC_BUTTON_CENTER`, `PETSC_BUTTON_RIGHT`, `PETSC_BUTTON_WHEEL_UP`, `PETSC_BUTTON_WHEEL_DOWN`
18 .   x_user - horizontal user coordinate of location (user may pass in NULL).
19 .   y_user - vertical user coordinate of location (user may pass in NULL).
20 .   x_phys - horizontal window coordinate (user may pass in NULL).
21 -   y_phys - vertical window coordinate (user may pass in NULL).
22 
23     Note:
24     Only processor 0 actually waits for the button to be pressed.
25 
26     Level: intermediate
27 
28 .seealso: `PetscDraw`, `PetscDrawButton`
29 @*/
30 PetscErrorCode PetscDrawGetMouseButton(PetscDraw draw, PetscDrawButton *button, PetscReal *x_user, PetscReal *y_user, PetscReal *x_phys, PetscReal *y_phys)
31 {
32   PetscReal bcast[4] = {0, 0, 0, 0};
33 
34   PetscFunctionBegin;
35   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
36   PetscValidPointer(button, 2);
37   *button = PETSC_BUTTON_NONE;
38   if (!draw->ops->getmousebutton) PetscFunctionReturn(0);
39 
40   PetscUseTypeMethod(draw, getmousebutton, button, x_user, y_user, x_phys, y_phys);
41 
42   PetscCallMPI(MPI_Bcast((PetscEnum *)button, 1, MPIU_ENUM, 0, PetscObjectComm((PetscObject)draw)));
43   if (x_user) bcast[0] = *x_user;
44   if (y_user) bcast[1] = *y_user;
45   if (x_phys) bcast[2] = *x_phys;
46   if (y_phys) bcast[3] = *y_phys;
47   PetscCallMPI(MPI_Bcast(bcast, 4, MPIU_REAL, 0, PetscObjectComm((PetscObject)draw)));
48   if (x_user) *x_user = bcast[0];
49   if (y_user) *y_user = bcast[1];
50   if (x_phys) *x_phys = bcast[2];
51   if (y_phys) *y_phys = bcast[3];
52   PetscFunctionReturn(0);
53 }
54