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