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