1 2 #include <petscdraw.h> /*I "petscdraw.h" I*/ 3 4 #undef __FUNCT__ 5 #define __FUNCT__ "PetscDrawZoom" 6 /*@C 7 PetscDrawZoom - Allows one to create a graphic that users may zoom into. 8 9 Collective on PetscDraw 10 11 Input Parameters: 12 + draw - the window where the graph will be made. 13 . func - users function that draws the graphic 14 - ctx - pointer to any user required data 15 16 Level: advanced 17 18 Concepts: graphics^zooming 19 Concepts: drawing^zooming 20 Concepts: zooming^in graphics 21 22 .seealso: 23 @*/ 24 PetscErrorCode PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void*),void *ctx) 25 { 26 PetscErrorCode ierr; 27 PetscDrawButton button; 28 PetscReal dpause,xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax; 29 PetscBool isnull; 30 31 PetscFunctionBegin; 32 ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); 33 if (isnull) PetscFunctionReturn(0); 34 35 ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); 36 ierr = PetscDrawSynchronizedClear(draw);CHKERRQ(ierr); 37 ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); 38 ierr = (*func)(draw,ctx);CHKERRQ(ierr); 39 ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); 40 ierr = PetscDrawSynchronizedFlush(draw);CHKERRQ(ierr); 41 42 ierr = PetscDrawGetPause(draw,&dpause);CHKERRQ(ierr); 43 if (dpause >= 0) { 44 ierr = PetscSleep(dpause);CHKERRQ(ierr); 45 goto theend; 46 } 47 if (dpause != -1) goto theend; 48 49 ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); 50 ierr = PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);CHKERRQ(ierr); 51 ierr = PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);CHKERRQ(ierr); 52 w = xr - xl; xmin = xl; xmax = xr; 53 h = yr - yl; ymin = yl; ymax = yr; 54 55 while (button != PETSC_BUTTON_NONE && button != PETSC_BUTTON_RIGHT) { 56 ierr = PetscDrawSynchronizedClear(draw);CHKERRQ(ierr); 57 if (button == PETSC_BUTTON_LEFT) scale = .5; 58 else if (button == PETSC_BUTTON_CENTER) scale = 2.; 59 xl = scale*(xl + w - xc) + xc - w*scale; 60 xr = scale*(xr - w - xc) + xc + w*scale; 61 yl = scale*(yl + h - yc) + yc - h*scale; 62 yr = scale*(yr - h - yc) + yc + h*scale; 63 w *= scale; h *= scale; 64 ierr = PetscDrawSetCoordinates(draw,xl,yl,xr,yr);CHKERRQ(ierr); 65 ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); 66 ierr = (*func)(draw,ctx);CHKERRQ(ierr); 67 ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); 68 ierr = PetscDrawSynchronizedFlush(draw);CHKERRQ(ierr); 69 ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); 70 ierr = PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);CHKERRQ(ierr); 71 } 72 ierr = PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);CHKERRQ(ierr); 73 theend: 74 PetscFunctionReturn(0); 75 } 76 77