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