Actual source code: zoom.c

 2:  #include petscdraw.h

  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: {
 27:   int             pause;
 28:   PetscDrawButton button;
 29:   PetscReal       xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
 30:   PetscTruth      isnull;

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

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

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

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

 52:   if (button != BUTTON_NONE) {
 53:     while (button != BUTTON_RIGHT) {

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

 65:       (*func)(draw,ctx);
 66:       PetscDrawCheckResizedWindow(draw);
 67:       PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
 68:     }
 69:   }

 71:   PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);

 73:   return(0);
 74: }