xref: /petsc/src/sys/classes/draw/interface/dmouse.c (revision 09440f2536211689395dd83abbfd05fbf503dd2c)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith /*
35c6c1daeSBarry Smith        Provides the calling sequences for all the basic PetscDraw routines.
45c6c1daeSBarry Smith */
5af0996ceSBarry Smith #include <petsc/private/drawimpl.h>  /*I "petscdraw.h" I*/
65c6c1daeSBarry Smith 
75c6c1daeSBarry Smith #undef __FUNCT__
85c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawGetMouseButton"
95c6c1daeSBarry Smith /*@
105c6c1daeSBarry Smith     PetscDrawGetMouseButton - Returns location of mouse and which button was
115c6c1daeSBarry Smith     pressed. Waits for button to be pressed.
125c6c1daeSBarry Smith 
135c6c1daeSBarry Smith     Collective over PetscDraw
145c6c1daeSBarry Smith 
155c6c1daeSBarry Smith     Input Parameter:
165c6c1daeSBarry Smith .   draw - the window to be used
175c6c1daeSBarry Smith 
185c6c1daeSBarry Smith     Output Parameters:
199f80f0efSLisandro Dalcin +   button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT, PETSC_BUTTON_WHEEL_UP, PETSC_BUTTON_WHEEL_DOWN
20e118a51fSLisandro Dalcin .   x_user, y_user - user coordinates of location (user may pass in NULL).
21e118a51fSLisandro Dalcin -   x_phys, y_phys - window coordinates (user may pass in NULL).
225c6c1daeSBarry Smith 
2364f23424SLisandro Dalcin     Notes: Only processor 0 actually waits for the button to be pressed.
245c6c1daeSBarry Smith 
2564f23424SLisandro Dalcin     Level: intermediate
265c6c1daeSBarry Smith @*/
2764f23424SLisandro Dalcin PetscErrorCode  PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
285c6c1daeSBarry Smith {
29*09440f25SLisandro Dalcin   PetscReal      bcast[4] = {0,0,0,0};
3064f23424SLisandro Dalcin   PetscBool      isnull;
315c6c1daeSBarry Smith   PetscMPIInt    rank;
3264f23424SLisandro Dalcin   PetscErrorCode ierr;
335c6c1daeSBarry Smith 
345c6c1daeSBarry Smith   PetscFunctionBegin;
355c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
36e118a51fSLisandro Dalcin   PetscValidPointer(button,2);
37e118a51fSLisandro Dalcin   *button = PETSC_BUTTON_NONE;
388f69470aSLisandro Dalcin   ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr);
3964f23424SLisandro Dalcin   if (isnull) PetscFunctionReturn(0);
4064f23424SLisandro Dalcin   if (!draw->ops->getmousebutton) PetscFunctionReturn(0);
41e118a51fSLisandro Dalcin 
4264f23424SLisandro Dalcin   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr);
43*09440f25SLisandro Dalcin   ierr = (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);
44d5eca3faSLisandro Dalcin   ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr);
45e118a51fSLisandro Dalcin 
46ce94432eSBarry Smith   ierr = MPI_Bcast((PetscEnum*)button,1,MPIU_ENUM,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
475c6c1daeSBarry Smith   if (x_user) bcast[0] = *x_user;
485c6c1daeSBarry Smith   if (y_user) bcast[1] = *y_user;
495c6c1daeSBarry Smith   if (x_phys) bcast[2] = *x_phys;
505c6c1daeSBarry Smith   if (y_phys) bcast[3] = *y_phys;
51ce94432eSBarry Smith   ierr = MPI_Bcast(bcast,4,MPIU_REAL,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
525c6c1daeSBarry Smith   if (x_user) *x_user = bcast[0];
535c6c1daeSBarry Smith   if (y_user) *y_user = bcast[1];
545c6c1daeSBarry Smith   if (x_phys) *x_phys = bcast[2];
555c6c1daeSBarry Smith   if (y_phys) *y_phys = bcast[3];
565c6c1daeSBarry Smith   PetscFunctionReturn(0);
575c6c1daeSBarry Smith }
585c6c1daeSBarry Smith 
595c6c1daeSBarry Smith 
605c6c1daeSBarry Smith 
615c6c1daeSBarry Smith 
625c6c1daeSBarry Smith 
635c6c1daeSBarry Smith 
64