xref: /petsc/src/sys/classes/draw/interface/dmouse.c (revision f5f7c1b961d39659762614d2cf317c920ddf3bd2)
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     Not collective (Use PetscDrawSynchronizedGetMouseButton() for collective)
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
20 .   x_user, y_user - user coordinates of location (user may pass in 0).
21 -   x_phys, y_phys - window coordinates (user may pass in 0).
22 
23     Level: intermediate
24 
25     Notes:
26     Only processor 0 of the communicator used to create the PetscDraw may call this routine.
27 
28 .seealso: PetscDrawSynchronizedGetMouseButton()
29 @*/
30 PetscErrorCode  PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
31 {
32   PetscErrorCode ierr;
33   PetscBool  isnull;
34 
35   PetscFunctionBegin;
36   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
37   *button = PETSC_BUTTON_NONE;
38   ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr);
39   if (isnull) PetscFunctionReturn(0);
40   if (!draw->ops->getmousebutton) PetscFunctionReturn(0);
41   ierr = (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);
42   PetscFunctionReturn(0);
43 }
44 
45 #undef __FUNCT__
46 #define __FUNCT__ "PetscDrawSynchronizedGetMouseButton"
47 /*@
48     PetscDrawSynchronizedGetMouseButton - Returns location of mouse and which button was
49     pressed. Waits for button to be pressed.
50 
51     Collective over PetscDraw
52 
53     Input Parameter:
54 .   draw - the window to be used
55 
56     Output Parameters:
57 +   button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT
58 .   x_user, y_user - user coordinates of location (user may pass in 0).
59 -   x_phys, y_phys - window coordinates (user may pass in 0).
60 
61     Level: intermediate
62 
63 .seealso: PetscDrawGetMouseButton()
64 @*/
65 PetscErrorCode  PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
66 {
67   PetscReal      bcast[4];
68   PetscErrorCode ierr;
69   PetscMPIInt    rank;
70 
71   PetscFunctionBegin;
72   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
73   ierr = MPI_Comm_rank(((PetscObject)draw)->comm,&rank);CHKERRQ(ierr);
74   if (!rank) {
75     ierr = PetscDrawGetMouseButton(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);
76   }
77   if (button) {
78     ierr = MPI_Bcast((PetscEnum*)button,1,MPIU_ENUM,0,((PetscObject)draw)->comm);CHKERRQ(ierr);
79   }
80   if (x_user) bcast[0] = *x_user;
81   if (y_user) bcast[1] = *y_user;
82   if (x_phys) bcast[2] = *x_phys;
83   if (y_phys) bcast[3] = *y_phys;
84   ierr = MPI_Bcast(bcast,4,MPIU_REAL,0,((PetscObject)draw)->comm);CHKERRQ(ierr);
85   if (x_user) *x_user = bcast[0];
86   if (y_user) *y_user = bcast[1];
87   if (x_phys) *x_phys = bcast[2];
88   if (y_phys) *y_phys = bcast[3];
89   PetscFunctionReturn(0);
90 }
91 
92 
93 
94 
95 
96 
97