Actual source code: zoom.c

petsc-3.3-p7 2013-05-11
  2: #include <petscdraw.h>     /*I "petscdraw.h"  I*/

  6: /*@C
  7:     PetscDrawZoom - Allows one to create a graphic that users may zoom into.

  9:     Collective on PetscDraw

 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

 16:   Level: advanced

 18:   Concepts: graphics^zooming
 19:   Concepts: drawing^zooming
 20:   Concepts: zooming^in graphics

 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;

 32:   PetscDrawIsNull(draw,&isnull);
 33:   if (isnull) return(0);

 35:   PetscDrawSynchronizedClear(draw);
 36:   (*func)(draw,ctx);
 37:   PetscDrawSynchronizedFlush(draw);

 39:   PetscDrawGetPause(draw,&dpause);
 40:   if (dpause >= 0) {
 41:     PetscSleep(dpause);
 42:     return(0);
 43:   }

 45:   PetscDrawCheckResizedWindow(draw);
 46:   PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
 47:   PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
 48:   w    = xr - xl; xmin = xl; ymin = yl; xmax = xr; ymax = yr;
 49:   h    = yr - yl;

 51:   if (button != PETSC_BUTTON_NONE) {
 52:     while (button != PETSC_BUTTON_RIGHT) {

 54:       PetscDrawSynchronizedClear(draw);
 55:       if (button == PETSC_BUTTON_LEFT)        scale = .5;
 56:       else if (button == PETSC_BUTTON_CENTER) scale = 2.;
 57:       xl = scale*(xl + w - xc) + xc - w*scale;
 58:       xr = scale*(xr - w - xc) + xc + w*scale;
 59:       yl = scale*(yl + h - yc) + yc - h*scale;
 60:       yr = scale*(yr - h - yc) + yc + h*scale;
 61:       w *= scale; h *= scale;
 62:       PetscDrawSetCoordinates(draw,xl,yl,xr,yr);

 64:       (*func)(draw,ctx);
 65:       PetscDrawCheckResizedWindow(draw);
 66:       PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
 67:     }
 68:   }
 69:   PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
 70:   return(0);
 71: }